ripemd-0.1.3/.cargo_vcs_info.json0000644000000001440000000000100123140ustar { "git": { "sha1": "4561d6fbafeb979a797db9d40d301a1f354dbe40" }, "path_in_vcs": "ripemd" }ripemd-0.1.3/CHANGELOG.md000064400000000000000000000014341046102023000127200ustar 00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## 0.1.3 (2022-09-23) ### Added - Feature-gated OID support ([#415]) [#415]: https://github.com/RustCrypto/hashes/pull/415 ## 0.1.2 (2022-09-16) ### Added - RIPEMD-128 algorithm ([#406]) [#406]: https://github.com/RustCrypto/hashes/pull/406 ## 0.1.1 (2022-02-17) ### Fixed - Minimal versions build ([#363]) [#363]: https://github.com/RustCrypto/hashes/pull/363 ## 0.1.0 (2021-12-07) - Initial release of merged `ripemd160` and `ripemd320` crates updated to `digest` v0.10. ([#217]) [#217]: https://github.com/RustCrypto/hashes/pull/217 ripemd-0.1.3/Cargo.toml0000644000000021470000000000100103170ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "ripemd" version = "0.1.3" authors = ["RustCrypto Developers"] description = "Pure Rust implementation of the RIPEMD hash functions" documentation = "https://docs.rs/ripemd" readme = "README.md" keywords = [ "crypto", "ripemd", "hash", "digest", ] categories = [ "cryptography", "no-std", ] license = "MIT OR Apache-2.0" repository = "https://github.com/RustCrypto/hashes" [dependencies.digest] version = "0.10.4" [dev-dependencies.digest] version = "0.10.4" features = ["dev"] [dev-dependencies.hex-literal] version = "0.2.2" [features] default = ["std"] oid = ["digest/oid"] std = ["digest/std"] ripemd-0.1.3/Cargo.toml.orig000064400000000000000000000012131046102023000137710ustar 00000000000000[package] name = "ripemd" version = "0.1.3" description = "Pure Rust implementation of the RIPEMD hash functions" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" readme = "README.md" edition = "2018" documentation = "https://docs.rs/ripemd" repository = "https://github.com/RustCrypto/hashes" keywords = ["crypto", "ripemd", "hash", "digest"] categories = ["cryptography", "no-std"] [dependencies] digest = "0.10.4" [dev-dependencies] digest = { version = "0.10.4", features = ["dev"] } hex-literal = "0.2.2" [features] default = ["std"] std = ["digest/std"] oid = ["digest/oid"] # Enable OID support. WARNING: Bumps MSRV to 1.57 ripemd-0.1.3/LICENSE-APACHE000064400000000000000000000251411046102023000130340ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ripemd-0.1.3/LICENSE-MIT000064400000000000000000000020511046102023000125370ustar 00000000000000Copyright (c) 2021 RustCrypto Developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ripemd-0.1.3/README.md000064400000000000000000000034331046102023000123670ustar 00000000000000# RustCrypto: RIPEMD [![crate][crate-image]][crate-link] [![Docs][docs-image]][docs-link] ![Apache2/MIT licensed][license-image] ![Rust Version][rustc-image] [![Project Chat][chat-image]][chat-link] [![Build Status][build-image]][build-link] Pure Rust implementation of the [RIPEMD] hash functions. [Documentation][docs-link] ## Minimum Supported Rust Version Rust **1.41** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. ## SemVer Policy - All on-by-default features of this library are covered by SemVer - MSRV is considered exempt from SemVer as noted above ## License Licensed under either of: * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) * [MIT license](http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. [//]: # (badges) [crate-image]: https://img.shields.io/crates/v/ripemd.svg [crate-link]: https://crates.io/crates/ripemd [docs-image]: https://docs.rs/ripemd/badge.svg [docs-link]: https://docs.rs/ripemd/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg [rustc-image]: https://img.shields.io/badge/rustc-1.41+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260041-hashes [build-image]: https://github.com/RustCrypto/hashes/workflows/ripemd/badge.svg?branch=master [build-link]: https://github.com/RustCrypto/hashes/actions?query=workflow%3Aripemd160 [//]: # (general links) [RIPEMD]: https://en.wikipedia.org/wiki/RIPEMD ripemd-0.1.3/benches/mod.rs000064400000000000000000000013011046102023000136340ustar 00000000000000#![feature(test)] extern crate test; use digest::bench_update; use ripemd::{Ripemd128, Ripemd160, Ripemd256, Ripemd320}; use test::Bencher; bench_update!( Ripemd128::default(); ripemd128_10 10; ripemd128_100 100; ripemd128_1000 1000; ripemd128_10000 10000; ); bench_update!( Ripemd160::default(); ripemd160_10 10; ripemd160_100 100; ripemd160_1000 1000; ripemd160_10000 10000; ); bench_update!( Ripemd256::default(); ripemd256_10 10; ripemd256_100 100; ripemd256_1000 1000; ripemd256_10000 10000; ); bench_update!( Ripemd320::default(); ripemd320_10 10; ripemd320_100 100; ripemd320_1000 1000; ripemd320_10000 10000; ); ripemd-0.1.3/src/c128.rs000064400000000000000000000320431046102023000127210ustar 00000000000000use core::convert::TryInto; pub const DIGEST_BUF_LEN: usize = 4; pub const WORK_BUF_LEN: usize = 16; pub const H0: [u32; DIGEST_BUF_LEN] = [0x6745_2301, 0xefcd_ab89, 0x98ba_dcfe, 0x1032_5476]; macro_rules! round( ($a:expr, $b:expr, $c:expr, $d:expr, $x:expr, $bits:expr, $add:expr, $round:expr) => ({ $a = $a.wrapping_add($round).wrapping_add($x).wrapping_add($add); $a = $a.rotate_left($bits); }); ); macro_rules! process_block( ($h:ident, $data:expr, $( round1: h_ordering $f0:expr, $f1:expr, $f2:expr, $f3:expr; data_index $data_index1:expr; roll_shift $bits1:expr )*; $( round2: h_ordering $g0:expr, $g1:expr, $g2:expr, $g3:expr; data_index $data_index2:expr; roll_shift $bits2:expr )*; $( round3: h_ordering $h0:expr, $h1:expr, $h2:expr, $h3:expr; data_index $data_index3:expr; roll_shift $bits3:expr )*; $( round4: h_ordering $i0:expr, $i1:expr, $i2:expr, $i3:expr; data_index $data_index4:expr; roll_shift $bits4:expr )*; $( par_round1: h_ordering $pi0:expr, $pi1:expr, $pi2:expr, $pi3:expr; data_index $pdata_index1:expr; roll_shift $pbits1:expr )*; $( par_round2: h_ordering $ph0:expr, $ph1:expr, $ph2:expr, $ph3:expr; data_index $pdata_index2:expr; roll_shift $pbits2:expr )*; $( par_round3: h_ordering $pg0:expr, $pg1:expr, $pg2:expr, $pg3:expr; data_index $pdata_index3:expr; roll_shift $pbits3:expr )*; $( par_round4: h_ordering $pf0:expr, $pf1:expr, $pf2:expr, $pf3:expr; data_index $pdata_index4:expr; roll_shift $pbits4:expr )*; ) => ({ let mut bb = *$h; let mut bbb = *$h; // Round 1 $( round!(bb[$f0], bb[$f1], bb[$f2], bb[$f3], $data[$data_index1], $bits1, 0x0000_0000, bb[$f1] ^ bb[$f2] ^ bb[$f3]); )* // Round 2 $( round!(bb[$g0], bb[$g1], bb[$g2], bb[$g3], $data[$data_index2], $bits2, 0x5a82_7999, (bb[$g1] & bb[$g2]) | (!bb[$g1] & bb[$g3])); )* // Round 3 $( round!(bb[$h0], bb[$h1], bb[$h2], bb[$h3], $data[$data_index3], $bits3, 0x6ed9_eba1, (bb[$h1] | !bb[$h2]) ^ bb[$h3]); )* // Round 4 $( round!(bb[$i0], bb[$i1], bb[$i2], bb[$i3], $data[$data_index4], $bits4, 0x8f1b_bcdc, (bb[$i1] & bb[$i3]) | (bb[$i2] & !bb[$i3])); )* // Parallel rounds: these are the same as the previous five // rounds except that the constants have changed, we work // with the other buffer, and they are applied in reverse // order. // Parallel Round 1 $( round!(bbb[$pi0], bbb[$pi1], bbb[$pi2], bbb[$pi3], $data[$pdata_index1], $pbits1, 0x50a2_8be6, (bbb[$pi1] & bbb[$pi3]) | (bbb[$pi2] & !bbb[$pi3])); )* // Parallel Round 2 $( round!(bbb[$ph0], bbb[$ph1], bbb[$ph2], bbb[$ph3], $data[$pdata_index2], $pbits2, 0x5c4d_d124, (bbb[$ph1] | !bbb[$ph2]) ^ bbb[$ph3]); )* // Parallel Round 3 $( round!(bbb[$pg0], bbb[$pg1], bbb[$pg2], bbb[$pg3], $data[$pdata_index3], $pbits3, 0x6d70_3ef3, (bbb[$pg1] & bbb[$pg2]) | (!bbb[$pg1] & bbb[$pg3])); )* // Parallel Round 4 $( round!(bbb[$pf0], bbb[$pf1], bbb[$pf2], bbb[$pf3], $data[$pdata_index4], $pbits4, 0x0000_0000, bbb[$pf1] ^ bbb[$pf2] ^ bbb[$pf3]); )* // Combine results bbb[3] = bbb[3].wrapping_add($h[1]).wrapping_add(bb[2]); $h[1] = $h[2].wrapping_add(bb[3]).wrapping_add(bbb[0]); $h[2] = $h[3].wrapping_add(bb[0]).wrapping_add(bbb[1]); $h[3] = $h[0].wrapping_add(bb[1]).wrapping_add(bbb[2]); $h[0] = bbb[3]; }); ); pub fn compress(h: &mut [u32; DIGEST_BUF_LEN], data: &[u8; 64]) { let mut w = [0u32; WORK_BUF_LEN]; for (o, chunk) in w.iter_mut().zip(data.chunks_exact(4)) { *o = u32::from_le_bytes(chunk.try_into().unwrap()); } process_block!(h, w[..], // Round 1 round1: h_ordering 0, 1, 2, 3; data_index 0; roll_shift 11 round1: h_ordering 3, 0, 1, 2; data_index 1; roll_shift 14 round1: h_ordering 2, 3, 0, 1; data_index 2; roll_shift 15 round1: h_ordering 1, 2, 3, 0; data_index 3; roll_shift 12 round1: h_ordering 0, 1, 2, 3; data_index 4; roll_shift 5 round1: h_ordering 3, 0, 1, 2; data_index 5; roll_shift 8 round1: h_ordering 2, 3, 0, 1; data_index 6; roll_shift 7 round1: h_ordering 1, 2, 3, 0; data_index 7; roll_shift 9 round1: h_ordering 0, 1, 2, 3; data_index 8; roll_shift 11 round1: h_ordering 3, 0, 1, 2; data_index 9; roll_shift 13 round1: h_ordering 2, 3, 0, 1; data_index 10; roll_shift 14 round1: h_ordering 1, 2, 3, 0; data_index 11; roll_shift 15 round1: h_ordering 0, 1, 2, 3; data_index 12; roll_shift 6 round1: h_ordering 3, 0, 1, 2; data_index 13; roll_shift 7 round1: h_ordering 2, 3, 0, 1; data_index 14; roll_shift 9 round1: h_ordering 1, 2, 3, 0; data_index 15; roll_shift 8; // Round 2 round2: h_ordering 0, 1, 2, 3; data_index 7; roll_shift 7 round2: h_ordering 3, 0, 1, 2; data_index 4; roll_shift 6 round2: h_ordering 2, 3, 0, 1; data_index 13; roll_shift 8 round2: h_ordering 1, 2, 3, 0; data_index 1; roll_shift 13 round2: h_ordering 0, 1, 2, 3; data_index 10; roll_shift 11 round2: h_ordering 3, 0, 1, 2; data_index 6; roll_shift 9 round2: h_ordering 2, 3, 0, 1; data_index 15; roll_shift 7 round2: h_ordering 1, 2, 3, 0; data_index 3; roll_shift 15 round2: h_ordering 0, 1, 2, 3; data_index 12; roll_shift 7 round2: h_ordering 3, 0, 1, 2; data_index 0; roll_shift 12 round2: h_ordering 2, 3, 0, 1; data_index 9; roll_shift 15 round2: h_ordering 1, 2, 3, 0; data_index 5; roll_shift 9 round2: h_ordering 0, 1, 2, 3; data_index 2; roll_shift 11 round2: h_ordering 3, 0, 1, 2; data_index 14; roll_shift 7 round2: h_ordering 2, 3, 0, 1; data_index 11; roll_shift 13 round2: h_ordering 1, 2, 3, 0; data_index 8; roll_shift 12; // Round 3 round3: h_ordering 0, 1, 2, 3; data_index 3; roll_shift 11 round3: h_ordering 3, 0, 1, 2; data_index 10; roll_shift 13 round3: h_ordering 2, 3, 0, 1; data_index 14; roll_shift 6 round3: h_ordering 1, 2, 3, 0; data_index 4; roll_shift 7 round3: h_ordering 0, 1, 2, 3; data_index 9; roll_shift 14 round3: h_ordering 3, 0, 1, 2; data_index 15; roll_shift 9 round3: h_ordering 2, 3, 0, 1; data_index 8; roll_shift 13 round3: h_ordering 1, 2, 3, 0; data_index 1; roll_shift 15 round3: h_ordering 0, 1, 2, 3; data_index 2; roll_shift 14 round3: h_ordering 3, 0, 1, 2; data_index 7; roll_shift 8 round3: h_ordering 2, 3, 0, 1; data_index 0; roll_shift 13 round3: h_ordering 1, 2, 3, 0; data_index 6; roll_shift 6 round3: h_ordering 0, 1, 2, 3; data_index 13; roll_shift 5 round3: h_ordering 3, 0, 1, 2; data_index 11; roll_shift 12 round3: h_ordering 2, 3, 0, 1; data_index 5; roll_shift 7 round3: h_ordering 1, 2, 3, 0; data_index 12; roll_shift 5; // Round 4 round4: h_ordering 0, 1, 2, 3; data_index 1; roll_shift 11 round4: h_ordering 3, 0, 1, 2; data_index 9; roll_shift 12 round4: h_ordering 2, 3, 0, 1; data_index 11; roll_shift 14 round4: h_ordering 1, 2, 3, 0; data_index 10; roll_shift 15 round4: h_ordering 0, 1, 2, 3; data_index 0; roll_shift 14 round4: h_ordering 3, 0, 1, 2; data_index 8; roll_shift 15 round4: h_ordering 2, 3, 0, 1; data_index 12; roll_shift 9 round4: h_ordering 1, 2, 3, 0; data_index 4; roll_shift 8 round4: h_ordering 0, 1, 2, 3; data_index 13; roll_shift 9 round4: h_ordering 3, 0, 1, 2; data_index 3; roll_shift 14 round4: h_ordering 2, 3, 0, 1; data_index 7; roll_shift 5 round4: h_ordering 1, 2, 3, 0; data_index 15; roll_shift 6 round4: h_ordering 0, 1, 2, 3; data_index 14; roll_shift 8 round4: h_ordering 3, 0, 1, 2; data_index 5; roll_shift 6 round4: h_ordering 2, 3, 0, 1; data_index 6; roll_shift 5 round4: h_ordering 1, 2, 3, 0; data_index 2; roll_shift 12; // Parallel Round 1 par_round1: h_ordering 0, 1, 2, 3; data_index 5; roll_shift 8 par_round1: h_ordering 3, 0, 1, 2; data_index 14; roll_shift 9 par_round1: h_ordering 2, 3, 0, 1; data_index 7; roll_shift 9 par_round1: h_ordering 1, 2, 3, 0; data_index 0; roll_shift 11 par_round1: h_ordering 0, 1, 2, 3; data_index 9; roll_shift 13 par_round1: h_ordering 3, 0, 1, 2; data_index 2; roll_shift 15 par_round1: h_ordering 2, 3, 0, 1; data_index 11; roll_shift 15 par_round1: h_ordering 1, 2, 3, 0; data_index 4; roll_shift 5 par_round1: h_ordering 0, 1, 2, 3; data_index 13; roll_shift 7 par_round1: h_ordering 3, 0, 1, 2; data_index 6; roll_shift 7 par_round1: h_ordering 2, 3, 0, 1; data_index 15; roll_shift 8 par_round1: h_ordering 1, 2, 3, 0; data_index 8; roll_shift 11 par_round1: h_ordering 0, 1, 2, 3; data_index 1; roll_shift 14 par_round1: h_ordering 3, 0, 1, 2; data_index 10; roll_shift 14 par_round1: h_ordering 2, 3, 0, 1; data_index 3; roll_shift 12 par_round1: h_ordering 1, 2, 3, 0; data_index 12; roll_shift 6; // Parallel Round 2 par_round2: h_ordering 0, 1, 2, 3; data_index 6; roll_shift 9 par_round2: h_ordering 3, 0, 1, 2; data_index 11; roll_shift 13 par_round2: h_ordering 2, 3, 0, 1; data_index 3; roll_shift 15 par_round2: h_ordering 1, 2, 3, 0; data_index 7; roll_shift 7 par_round2: h_ordering 0, 1, 2, 3; data_index 0; roll_shift 12 par_round2: h_ordering 3, 0, 1, 2; data_index 13; roll_shift 8 par_round2: h_ordering 2, 3, 0, 1; data_index 5; roll_shift 9 par_round2: h_ordering 1, 2, 3, 0; data_index 10; roll_shift 11 par_round2: h_ordering 0, 1, 2, 3; data_index 14; roll_shift 7 par_round2: h_ordering 3, 0, 1, 2; data_index 15; roll_shift 7 par_round2: h_ordering 2, 3, 0, 1; data_index 8; roll_shift 12 par_round2: h_ordering 1, 2, 3, 0; data_index 12; roll_shift 7 par_round2: h_ordering 0, 1, 2, 3; data_index 4; roll_shift 6 par_round2: h_ordering 3, 0, 1, 2; data_index 9; roll_shift 15 par_round2: h_ordering 2, 3, 0, 1; data_index 1; roll_shift 13 par_round2: h_ordering 1, 2, 3, 0; data_index 2; roll_shift 11; // Parallel Round 3 par_round3: h_ordering 0, 1, 2, 3; data_index 15; roll_shift 9 par_round3: h_ordering 3, 0, 1, 2; data_index 5; roll_shift 7 par_round3: h_ordering 2, 3, 0, 1; data_index 1; roll_shift 15 par_round3: h_ordering 1, 2, 3, 0; data_index 3; roll_shift 11 par_round3: h_ordering 0, 1, 2, 3; data_index 7; roll_shift 8 par_round3: h_ordering 3, 0, 1, 2; data_index 14; roll_shift 6 par_round3: h_ordering 2, 3, 0, 1; data_index 6; roll_shift 6 par_round3: h_ordering 1, 2, 3, 0; data_index 9; roll_shift 14 par_round3: h_ordering 0, 1, 2, 3; data_index 11; roll_shift 12 par_round3: h_ordering 3, 0, 1, 2; data_index 8; roll_shift 13 par_round3: h_ordering 2, 3, 0, 1; data_index 12; roll_shift 5 par_round3: h_ordering 1, 2, 3, 0; data_index 2; roll_shift 14 par_round3: h_ordering 0, 1, 2, 3; data_index 10; roll_shift 13 par_round3: h_ordering 3, 0, 1, 2; data_index 0; roll_shift 13 par_round3: h_ordering 2, 3, 0, 1; data_index 4; roll_shift 7 par_round3: h_ordering 1, 2, 3, 0; data_index 13; roll_shift 5; // Parallel Round 4 par_round4: h_ordering 0, 1, 2, 3; data_index 8; roll_shift 15 par_round4: h_ordering 3, 0, 1, 2; data_index 6; roll_shift 5 par_round4: h_ordering 2, 3, 0, 1; data_index 4; roll_shift 8 par_round4: h_ordering 1, 2, 3, 0; data_index 1; roll_shift 11 par_round4: h_ordering 0, 1, 2, 3; data_index 3; roll_shift 14 par_round4: h_ordering 3, 0, 1, 2; data_index 11; roll_shift 14 par_round4: h_ordering 2, 3, 0, 1; data_index 15; roll_shift 6 par_round4: h_ordering 1, 2, 3, 0; data_index 0; roll_shift 14 par_round4: h_ordering 0, 1, 2, 3; data_index 5; roll_shift 6 par_round4: h_ordering 3, 0, 1, 2; data_index 12; roll_shift 9 par_round4: h_ordering 2, 3, 0, 1; data_index 2; roll_shift 12 par_round4: h_ordering 1, 2, 3, 0; data_index 13; roll_shift 9 par_round4: h_ordering 0, 1, 2, 3; data_index 9; roll_shift 12 par_round4: h_ordering 3, 0, 1, 2; data_index 7; roll_shift 5 par_round4: h_ordering 2, 3, 0, 1; data_index 10; roll_shift 15 par_round4: h_ordering 1, 2, 3, 0; data_index 14; roll_shift 8; ); } ripemd-0.1.3/src/c160.rs000064400000000000000000000414231046102023000127170ustar 00000000000000use core::convert::TryInto; pub const DIGEST_BUF_LEN: usize = 5; pub const WORK_BUF_LEN: usize = 16; pub const H0: [u32; DIGEST_BUF_LEN] = [ 0x6745_2301, 0xefcd_ab89, 0x98ba_dcfe, 0x1032_5476, 0xc3d2_e1f0, ]; macro_rules! round( ($a:expr, $b:expr, $c:expr, $d:expr, $e:expr, $x:expr, $bits:expr, $add:expr, $round:expr) => ({ $a = $a.wrapping_add($round).wrapping_add($x).wrapping_add($add); $a = $a.rotate_left($bits).wrapping_add($e); $c = $c.rotate_left(10); }); ); macro_rules! process_block( ($h:ident, $data:expr, $( round1: h_ordering $f0:expr, $f1:expr, $f2:expr, $f3:expr, $f4:expr; data_index $data_index1:expr; roll_shift $bits1:expr )*; $( round2: h_ordering $g0:expr, $g1:expr, $g2:expr, $g3:expr, $g4:expr; data_index $data_index2:expr; roll_shift $bits2:expr )*; $( round3: h_ordering $h0:expr, $h1:expr, $h2:expr, $h3:expr, $h4:expr; data_index $data_index3:expr; roll_shift $bits3:expr )*; $( round4: h_ordering $i0:expr, $i1:expr, $i2:expr, $i3:expr, $i4:expr; data_index $data_index4:expr; roll_shift $bits4:expr )*; $( round5: h_ordering $j0:expr, $j1:expr, $j2:expr, $j3:expr, $j4:expr; data_index $data_index5:expr; roll_shift $bits5:expr )*; $( par_round1: h_ordering $pj0:expr, $pj1:expr, $pj2:expr, $pj3:expr, $pj4:expr; data_index $pdata_index1:expr; roll_shift $pbits1:expr )*; $( par_round2: h_ordering $pi0:expr, $pi1:expr, $pi2:expr, $pi3:expr, $pi4:expr; data_index $pdata_index2:expr; roll_shift $pbits2:expr )*; $( par_round3: h_ordering $ph0:expr, $ph1:expr, $ph2:expr, $ph3:expr, $ph4:expr; data_index $pdata_index3:expr; roll_shift $pbits3:expr )*; $( par_round4: h_ordering $pg0:expr, $pg1:expr, $pg2:expr, $pg3:expr, $pg4:expr; data_index $pdata_index4:expr; roll_shift $pbits4:expr )*; $( par_round5: h_ordering $pf0:expr, $pf1:expr, $pf2:expr, $pf3:expr, $pf4:expr; data_index $pdata_index5:expr; roll_shift $pbits5:expr )*; ) => ({ let mut bb = *$h; let mut bbb = *$h; // Round 1 $( round!(bb[$f0], bb[$f1], bb[$f2], bb[$f3], bb[$f4], $data[$data_index1], $bits1, 0x0000_0000, bb[$f1] ^ bb[$f2] ^ bb[$f3]); )* // Round 2 $( round!(bb[$g0], bb[$g1], bb[$g2], bb[$g3], bb[$g4], $data[$data_index2], $bits2, 0x5a82_7999, (bb[$g1] & bb[$g2]) | (!bb[$g1] & bb[$g3])); )* // Round 3 $( round!(bb[$h0], bb[$h1], bb[$h2], bb[$h3], bb[$h4], $data[$data_index3], $bits3, 0x6ed9_eba1, (bb[$h1] | !bb[$h2]) ^ bb[$h3]); )* // Round 4 $( round!(bb[$i0], bb[$i1], bb[$i2], bb[$i3], bb[$i4], $data[$data_index4], $bits4, 0x8f1b_bcdc, (bb[$i1] & bb[$i3]) | (bb[$i2] & !bb[$i3])); )* // Round 5 $( round!(bb[$j0], bb[$j1], bb[$j2], bb[$j3], bb[$j4], $data[$data_index5], $bits5, 0xa953_fd4e, bb[$j1] ^ (bb[$j2] | !bb[$j3])); )* // Parallel rounds: these are the same as the previous five // rounds except that the constants have changed, we work // with the other buffer, and they are applied in reverse // order. // Parallel Round 1 $( round!(bbb[$pj0], bbb[$pj1], bbb[$pj2], bbb[$pj3], bbb[$pj4], $data[$pdata_index1], $pbits1, 0x50a2_8be6, bbb[$pj1] ^ (bbb[$pj2] | !bbb[$pj3])); )* // Parallel Round 2 $( round!(bbb[$pi0], bbb[$pi1], bbb[$pi2], bbb[$pi3], bbb[$pi4], $data[$pdata_index2], $pbits2, 0x5c4d_d124, (bbb[$pi1] & bbb[$pi3]) | (bbb[$pi2] & !bbb[$pi3])); )* // Parallel Round 3 $( round!(bbb[$ph0], bbb[$ph1], bbb[$ph2], bbb[$ph3], bbb[$ph4], $data[$pdata_index3], $pbits3, 0x6d70_3ef3, (bbb[$ph1] | !bbb[$ph2]) ^ bbb[$ph3]); )* // Parallel Round 4 $( round!(bbb[$pg0], bbb[$pg1], bbb[$pg2], bbb[$pg3], bbb[$pg4], $data[$pdata_index4], $pbits4, 0x7a6d_76e9, (bbb[$pg1] & bbb[$pg2]) | (!bbb[$pg1] & bbb[$pg3])); )* // Parallel Round 5 $( round!(bbb[$pf0], bbb[$pf1], bbb[$pf2], bbb[$pf3], bbb[$pf4], $data[$pdata_index5], $pbits5, 0x0000_0000, bbb[$pf1] ^ bbb[$pf2] ^ bbb[$pf3]); )* // Combine results bbb[3] = bbb[3].wrapping_add($h[1]).wrapping_add(bb[2]); $h[1] = $h[2].wrapping_add(bb[3]).wrapping_add(bbb[4]); $h[2] = $h[3].wrapping_add(bb[4]).wrapping_add(bbb[0]); $h[3] = $h[4].wrapping_add(bb[0]).wrapping_add(bbb[1]); $h[4] = $h[0].wrapping_add(bb[1]).wrapping_add(bbb[2]); $h[0] = bbb[3]; }); ); pub fn compress(h: &mut [u32; DIGEST_BUF_LEN], data: &[u8; 64]) { let mut w = [0u32; WORK_BUF_LEN]; for (o, chunk) in w.iter_mut().zip(data.chunks_exact(4)) { *o = u32::from_le_bytes(chunk.try_into().unwrap()); } process_block!(h, w[..], // Round 1 round1: h_ordering 0, 1, 2, 3, 4; data_index 0; roll_shift 11 round1: h_ordering 4, 0, 1, 2, 3; data_index 1; roll_shift 14 round1: h_ordering 3, 4, 0, 1, 2; data_index 2; roll_shift 15 round1: h_ordering 2, 3, 4, 0, 1; data_index 3; roll_shift 12 round1: h_ordering 1, 2, 3, 4, 0; data_index 4; roll_shift 5 round1: h_ordering 0, 1, 2, 3, 4; data_index 5; roll_shift 8 round1: h_ordering 4, 0, 1, 2, 3; data_index 6; roll_shift 7 round1: h_ordering 3, 4, 0, 1, 2; data_index 7; roll_shift 9 round1: h_ordering 2, 3, 4, 0, 1; data_index 8; roll_shift 11 round1: h_ordering 1, 2, 3, 4, 0; data_index 9; roll_shift 13 round1: h_ordering 0, 1, 2, 3, 4; data_index 10; roll_shift 14 round1: h_ordering 4, 0, 1, 2, 3; data_index 11; roll_shift 15 round1: h_ordering 3, 4, 0, 1, 2; data_index 12; roll_shift 6 round1: h_ordering 2, 3, 4, 0, 1; data_index 13; roll_shift 7 round1: h_ordering 1, 2, 3, 4, 0; data_index 14; roll_shift 9 round1: h_ordering 0, 1, 2, 3, 4; data_index 15; roll_shift 8; // Round 2 round2: h_ordering 4, 0, 1, 2, 3; data_index 7; roll_shift 7 round2: h_ordering 3, 4, 0, 1, 2; data_index 4; roll_shift 6 round2: h_ordering 2, 3, 4, 0, 1; data_index 13; roll_shift 8 round2: h_ordering 1, 2, 3, 4, 0; data_index 1; roll_shift 13 round2: h_ordering 0, 1, 2, 3, 4; data_index 10; roll_shift 11 round2: h_ordering 4, 0, 1, 2, 3; data_index 6; roll_shift 9 round2: h_ordering 3, 4, 0, 1, 2; data_index 15; roll_shift 7 round2: h_ordering 2, 3, 4, 0, 1; data_index 3; roll_shift 15 round2: h_ordering 1, 2, 3, 4, 0; data_index 12; roll_shift 7 round2: h_ordering 0, 1, 2, 3, 4; data_index 0; roll_shift 12 round2: h_ordering 4, 0, 1, 2, 3; data_index 9; roll_shift 15 round2: h_ordering 3, 4, 0, 1, 2; data_index 5; roll_shift 9 round2: h_ordering 2, 3, 4, 0, 1; data_index 2; roll_shift 11 round2: h_ordering 1, 2, 3, 4, 0; data_index 14; roll_shift 7 round2: h_ordering 0, 1, 2, 3, 4; data_index 11; roll_shift 13 round2: h_ordering 4, 0, 1, 2, 3; data_index 8; roll_shift 12; // Round 3 round3: h_ordering 3, 4, 0, 1, 2; data_index 3; roll_shift 11 round3: h_ordering 2, 3, 4, 0, 1; data_index 10; roll_shift 13 round3: h_ordering 1, 2, 3, 4, 0; data_index 14; roll_shift 6 round3: h_ordering 0, 1, 2, 3, 4; data_index 4; roll_shift 7 round3: h_ordering 4, 0, 1, 2, 3; data_index 9; roll_shift 14 round3: h_ordering 3, 4, 0, 1, 2; data_index 15; roll_shift 9 round3: h_ordering 2, 3, 4, 0, 1; data_index 8; roll_shift 13 round3: h_ordering 1, 2, 3, 4, 0; data_index 1; roll_shift 15 round3: h_ordering 0, 1, 2, 3, 4; data_index 2; roll_shift 14 round3: h_ordering 4, 0, 1, 2, 3; data_index 7; roll_shift 8 round3: h_ordering 3, 4, 0, 1, 2; data_index 0; roll_shift 13 round3: h_ordering 2, 3, 4, 0, 1; data_index 6; roll_shift 6 round3: h_ordering 1, 2, 3, 4, 0; data_index 13; roll_shift 5 round3: h_ordering 0, 1, 2, 3, 4; data_index 11; roll_shift 12 round3: h_ordering 4, 0, 1, 2, 3; data_index 5; roll_shift 7 round3: h_ordering 3, 4, 0, 1, 2; data_index 12; roll_shift 5; // Round 4 round4: h_ordering 2, 3, 4, 0, 1; data_index 1; roll_shift 11 round4: h_ordering 1, 2, 3, 4, 0; data_index 9; roll_shift 12 round4: h_ordering 0, 1, 2, 3, 4; data_index 11; roll_shift 14 round4: h_ordering 4, 0, 1, 2, 3; data_index 10; roll_shift 15 round4: h_ordering 3, 4, 0, 1, 2; data_index 0; roll_shift 14 round4: h_ordering 2, 3, 4, 0, 1; data_index 8; roll_shift 15 round4: h_ordering 1, 2, 3, 4, 0; data_index 12; roll_shift 9 round4: h_ordering 0, 1, 2, 3, 4; data_index 4; roll_shift 8 round4: h_ordering 4, 0, 1, 2, 3; data_index 13; roll_shift 9 round4: h_ordering 3, 4, 0, 1, 2; data_index 3; roll_shift 14 round4: h_ordering 2, 3, 4, 0, 1; data_index 7; roll_shift 5 round4: h_ordering 1, 2, 3, 4, 0; data_index 15; roll_shift 6 round4: h_ordering 0, 1, 2, 3, 4; data_index 14; roll_shift 8 round4: h_ordering 4, 0, 1, 2, 3; data_index 5; roll_shift 6 round4: h_ordering 3, 4, 0, 1, 2; data_index 6; roll_shift 5 round4: h_ordering 2, 3, 4, 0, 1; data_index 2; roll_shift 12; // Round 5 round5: h_ordering 1, 2, 3, 4, 0; data_index 4; roll_shift 9 round5: h_ordering 0, 1, 2, 3, 4; data_index 0; roll_shift 15 round5: h_ordering 4, 0, 1, 2, 3; data_index 5; roll_shift 5 round5: h_ordering 3, 4, 0, 1, 2; data_index 9; roll_shift 11 round5: h_ordering 2, 3, 4, 0, 1; data_index 7; roll_shift 6 round5: h_ordering 1, 2, 3, 4, 0; data_index 12; roll_shift 8 round5: h_ordering 0, 1, 2, 3, 4; data_index 2; roll_shift 13 round5: h_ordering 4, 0, 1, 2, 3; data_index 10; roll_shift 12 round5: h_ordering 3, 4, 0, 1, 2; data_index 14; roll_shift 5 round5: h_ordering 2, 3, 4, 0, 1; data_index 1; roll_shift 12 round5: h_ordering 1, 2, 3, 4, 0; data_index 3; roll_shift 13 round5: h_ordering 0, 1, 2, 3, 4; data_index 8; roll_shift 14 round5: h_ordering 4, 0, 1, 2, 3; data_index 11; roll_shift 11 round5: h_ordering 3, 4, 0, 1, 2; data_index 6; roll_shift 8 round5: h_ordering 2, 3, 4, 0, 1; data_index 15; roll_shift 5 round5: h_ordering 1, 2, 3, 4, 0; data_index 13; roll_shift 6; // Parallel Round 1 par_round1: h_ordering 0, 1, 2, 3, 4; data_index 5; roll_shift 8 par_round1: h_ordering 4, 0, 1, 2, 3; data_index 14; roll_shift 9 par_round1: h_ordering 3, 4, 0, 1, 2; data_index 7; roll_shift 9 par_round1: h_ordering 2, 3, 4, 0, 1; data_index 0; roll_shift 11 par_round1: h_ordering 1, 2, 3, 4, 0; data_index 9; roll_shift 13 par_round1: h_ordering 0, 1, 2, 3, 4; data_index 2; roll_shift 15 par_round1: h_ordering 4, 0, 1, 2, 3; data_index 11; roll_shift 15 par_round1: h_ordering 3, 4, 0, 1, 2; data_index 4; roll_shift 5 par_round1: h_ordering 2, 3, 4, 0, 1; data_index 13; roll_shift 7 par_round1: h_ordering 1, 2, 3, 4, 0; data_index 6; roll_shift 7 par_round1: h_ordering 0, 1, 2, 3, 4; data_index 15; roll_shift 8 par_round1: h_ordering 4, 0, 1, 2, 3; data_index 8; roll_shift 11 par_round1: h_ordering 3, 4, 0, 1, 2; data_index 1; roll_shift 14 par_round1: h_ordering 2, 3, 4, 0, 1; data_index 10; roll_shift 14 par_round1: h_ordering 1, 2, 3, 4, 0; data_index 3; roll_shift 12 par_round1: h_ordering 0, 1, 2, 3, 4; data_index 12; roll_shift 6; // Parallel Round 2 par_round2: h_ordering 4, 0, 1, 2, 3; data_index 6; roll_shift 9 par_round2: h_ordering 3, 4, 0, 1, 2; data_index 11; roll_shift 13 par_round2: h_ordering 2, 3, 4, 0, 1; data_index 3; roll_shift 15 par_round2: h_ordering 1, 2, 3, 4, 0; data_index 7; roll_shift 7 par_round2: h_ordering 0, 1, 2, 3, 4; data_index 0; roll_shift 12 par_round2: h_ordering 4, 0, 1, 2, 3; data_index 13; roll_shift 8 par_round2: h_ordering 3, 4, 0, 1, 2; data_index 5; roll_shift 9 par_round2: h_ordering 2, 3, 4, 0, 1; data_index 10; roll_shift 11 par_round2: h_ordering 1, 2, 3, 4, 0; data_index 14; roll_shift 7 par_round2: h_ordering 0, 1, 2, 3, 4; data_index 15; roll_shift 7 par_round2: h_ordering 4, 0, 1, 2, 3; data_index 8; roll_shift 12 par_round2: h_ordering 3, 4, 0, 1, 2; data_index 12; roll_shift 7 par_round2: h_ordering 2, 3, 4, 0, 1; data_index 4; roll_shift 6 par_round2: h_ordering 1, 2, 3, 4, 0; data_index 9; roll_shift 15 par_round2: h_ordering 0, 1, 2, 3, 4; data_index 1; roll_shift 13 par_round2: h_ordering 4, 0, 1, 2, 3; data_index 2; roll_shift 11; // Parallel Round 3 par_round3: h_ordering 3, 4, 0, 1, 2; data_index 15; roll_shift 9 par_round3: h_ordering 2, 3, 4, 0, 1; data_index 5; roll_shift 7 par_round3: h_ordering 1, 2, 3, 4, 0; data_index 1; roll_shift 15 par_round3: h_ordering 0, 1, 2, 3, 4; data_index 3; roll_shift 11 par_round3: h_ordering 4, 0, 1, 2, 3; data_index 7; roll_shift 8 par_round3: h_ordering 3, 4, 0, 1, 2; data_index 14; roll_shift 6 par_round3: h_ordering 2, 3, 4, 0, 1; data_index 6; roll_shift 6 par_round3: h_ordering 1, 2, 3, 4, 0; data_index 9; roll_shift 14 par_round3: h_ordering 0, 1, 2, 3, 4; data_index 11; roll_shift 12 par_round3: h_ordering 4, 0, 1, 2, 3; data_index 8; roll_shift 13 par_round3: h_ordering 3, 4, 0, 1, 2; data_index 12; roll_shift 5 par_round3: h_ordering 2, 3, 4, 0, 1; data_index 2; roll_shift 14 par_round3: h_ordering 1, 2, 3, 4, 0; data_index 10; roll_shift 13 par_round3: h_ordering 0, 1, 2, 3, 4; data_index 0; roll_shift 13 par_round3: h_ordering 4, 0, 1, 2, 3; data_index 4; roll_shift 7 par_round3: h_ordering 3, 4, 0, 1, 2; data_index 13; roll_shift 5; // Parallel Round 4 par_round4: h_ordering 2, 3, 4, 0, 1; data_index 8; roll_shift 15 par_round4: h_ordering 1, 2, 3, 4, 0; data_index 6; roll_shift 5 par_round4: h_ordering 0, 1, 2, 3, 4; data_index 4; roll_shift 8 par_round4: h_ordering 4, 0, 1, 2, 3; data_index 1; roll_shift 11 par_round4: h_ordering 3, 4, 0, 1, 2; data_index 3; roll_shift 14 par_round4: h_ordering 2, 3, 4, 0, 1; data_index 11; roll_shift 14 par_round4: h_ordering 1, 2, 3, 4, 0; data_index 15; roll_shift 6 par_round4: h_ordering 0, 1, 2, 3, 4; data_index 0; roll_shift 14 par_round4: h_ordering 4, 0, 1, 2, 3; data_index 5; roll_shift 6 par_round4: h_ordering 3, 4, 0, 1, 2; data_index 12; roll_shift 9 par_round4: h_ordering 2, 3, 4, 0, 1; data_index 2; roll_shift 12 par_round4: h_ordering 1, 2, 3, 4, 0; data_index 13; roll_shift 9 par_round4: h_ordering 0, 1, 2, 3, 4; data_index 9; roll_shift 12 par_round4: h_ordering 4, 0, 1, 2, 3; data_index 7; roll_shift 5 par_round4: h_ordering 3, 4, 0, 1, 2; data_index 10; roll_shift 15 par_round4: h_ordering 2, 3, 4, 0, 1; data_index 14; roll_shift 8; // Parallel Round 5 par_round5: h_ordering 1, 2, 3, 4, 0; data_index 12; roll_shift 8 par_round5: h_ordering 0, 1, 2, 3, 4; data_index 15; roll_shift 5 par_round5: h_ordering 4, 0, 1, 2, 3; data_index 10; roll_shift 12 par_round5: h_ordering 3, 4, 0, 1, 2; data_index 4; roll_shift 9 par_round5: h_ordering 2, 3, 4, 0, 1; data_index 1; roll_shift 12 par_round5: h_ordering 1, 2, 3, 4, 0; data_index 5; roll_shift 5 par_round5: h_ordering 0, 1, 2, 3, 4; data_index 8; roll_shift 14 par_round5: h_ordering 4, 0, 1, 2, 3; data_index 7; roll_shift 6 par_round5: h_ordering 3, 4, 0, 1, 2; data_index 6; roll_shift 8 par_round5: h_ordering 2, 3, 4, 0, 1; data_index 2; roll_shift 13 par_round5: h_ordering 1, 2, 3, 4, 0; data_index 13; roll_shift 6 par_round5: h_ordering 0, 1, 2, 3, 4; data_index 14; roll_shift 5 par_round5: h_ordering 4, 0, 1, 2, 3; data_index 0; roll_shift 15 par_round5: h_ordering 3, 4, 0, 1, 2; data_index 3; roll_shift 13 par_round5: h_ordering 2, 3, 4, 0, 1; data_index 9; roll_shift 11 par_round5: h_ordering 1, 2, 3, 4, 0; data_index 11; roll_shift 11; ); } ripemd-0.1.3/src/c256.rs000064400000000000000000000325171046102023000127310ustar 00000000000000use core::{convert::TryInto, mem::swap}; pub const DIGEST_BUF_LEN: usize = 8; pub const HALF_DIGEST_BUF_LEN: usize = DIGEST_BUF_LEN / 2; pub const WORK_BUF_LEN: usize = 16; pub const H0: [u32; DIGEST_BUF_LEN] = [ 0x6745_2301, 0xefcd_ab89, 0x98ba_dcfe, 0x1032_5476, 0x7654_3210, 0xfedc_ba98, 0x89ab_cdef, 0x0123_4567, ]; macro_rules! round( ($a:expr, $b:expr, $c:expr, $d:expr, $x:expr, $bits:expr, $add:expr, $round:expr) => ({ $a = $a.wrapping_add($round).wrapping_add($x).wrapping_add($add); $a = $a.rotate_left($bits); }); ); #[inline(always)] fn swap_idx(bb: &mut [u32; HALF_DIGEST_BUF_LEN], bbb: &mut [u32; HALF_DIGEST_BUF_LEN], idx: usize) { swap(&mut bb[idx], &mut bbb[idx]); } macro_rules! process_block( ($h:ident, $data:expr, $( round1: h_ordering $f0:expr, $f1:expr, $f2:expr, $f3:expr; data_index $data_index1:expr; roll_shift $bits1:expr )*; $( round2: h_ordering $g0:expr, $g1:expr, $g2:expr, $g3:expr; data_index $data_index2:expr; roll_shift $bits2:expr )*; $( round3: h_ordering $h0:expr, $h1:expr, $h2:expr, $h3:expr; data_index $data_index3:expr; roll_shift $bits3:expr )*; $( round4: h_ordering $i0:expr, $i1:expr, $i2:expr, $i3:expr; data_index $data_index4:expr; roll_shift $bits4:expr )*; $( par_round1: h_ordering $pi0:expr, $pi1:expr, $pi2:expr, $pi3:expr; data_index $pdata_index1:expr; roll_shift $pbits1:expr )*; $( par_round2: h_ordering $ph0:expr, $ph1:expr, $ph2:expr, $ph3:expr; data_index $pdata_index2:expr; roll_shift $pbits2:expr )*; $( par_round3: h_ordering $pg0:expr, $pg1:expr, $pg2:expr, $pg3:expr; data_index $pdata_index3:expr; roll_shift $pbits3:expr )*; $( par_round4: h_ordering $pf0:expr, $pf1:expr, $pf2:expr, $pf3:expr; data_index $pdata_index4:expr; roll_shift $pbits4:expr )*; ) => ({ let mut bb = [0u32; HALF_DIGEST_BUF_LEN]; bb.copy_from_slice(&$h[..HALF_DIGEST_BUF_LEN]); let mut bbb = [0u32; HALF_DIGEST_BUF_LEN]; bbb.copy_from_slice(&$h[HALF_DIGEST_BUF_LEN..]); // Round 1 $( round!(bb[$f0], bb[$f1], bb[$f2], bb[$f3], $data[$data_index1], $bits1, 0x0000_0000, bb[$f1] ^ bb[$f2] ^ bb[$f3]); )* // Parallel Round 1 $( round!(bbb[$pi0], bbb[$pi1], bbb[$pi2], bbb[$pi3], $data[$pdata_index1], $pbits1, 0x50a2_8be6, (bbb[$pi1] & bbb[$pi3]) | (bbb[$pi2] & !bbb[$pi3])); )* swap_idx(&mut bb, &mut bbb, 0); // Round 2 $( round!(bb[$g0], bb[$g1], bb[$g2], bb[$g3], $data[$data_index2], $bits2, 0x5a82_7999, (bb[$g1] & bb[$g2]) | (!bb[$g1] & bb[$g3])); )* // Parallel Round 2 $( round!(bbb[$ph0], bbb[$ph1], bbb[$ph2], bbb[$ph3], $data[$pdata_index2], $pbits2, 0x5c4d_d124, (bbb[$ph1] | !bbb[$ph2]) ^ bbb[$ph3]); )* swap_idx(&mut bb, &mut bbb, 1); // Round 3 $( round!(bb[$h0], bb[$h1], bb[$h2], bb[$h3], $data[$data_index3], $bits3, 0x6ed9_eba1, (bb[$h1] | !bb[$h2]) ^ bb[$h3]); )* // Parallel Round 3 $( round!(bbb[$pg0], bbb[$pg1], bbb[$pg2], bbb[$pg3], $data[$pdata_index3], $pbits3, 0x6d70_3ef3, (bbb[$pg1] & bbb[$pg2]) | (!bbb[$pg1] & bbb[$pg3])); )* swap_idx(&mut bb, &mut bbb, 2); // Round 4 $( round!(bb[$i0], bb[$i1], bb[$i2], bb[$i3], $data[$data_index4], $bits4, 0x8f1b_bcdc, (bb[$i1] & bb[$i3]) | (bb[$i2] & !bb[$i3])); )* // Parallel Round 4 $( round!(bbb[$pf0], bbb[$pf1], bbb[$pf2], bbb[$pf3], $data[$pdata_index4], $pbits4, 0x0000_0000, bbb[$pf1] ^ bbb[$pf2] ^ bbb[$pf3]); )* swap_idx(&mut bb, &mut bbb, 3); $h[0] = $h[0].wrapping_add(bb[0]); $h[1] = $h[1].wrapping_add(bb[1]); $h[2] = $h[2].wrapping_add(bb[2]); $h[3] = $h[3].wrapping_add(bb[3]); $h[4] = $h[4].wrapping_add(bbb[0]); $h[5] = $h[5].wrapping_add(bbb[1]); $h[6] = $h[6].wrapping_add(bbb[2]); $h[7] = $h[7].wrapping_add(bbb[3]); }); ); pub fn compress(h: &mut [u32; DIGEST_BUF_LEN], data: &[u8; 64]) { let mut w = [0u32; WORK_BUF_LEN]; for (o, chunk) in w.iter_mut().zip(data.chunks_exact(4)) { *o = u32::from_le_bytes(chunk.try_into().unwrap()); } process_block!(h, w[..], // Round 1 round1: h_ordering 0, 1, 2, 3; data_index 0; roll_shift 11 round1: h_ordering 3, 0, 1, 2; data_index 1; roll_shift 14 round1: h_ordering 2, 3, 0, 1; data_index 2; roll_shift 15 round1: h_ordering 1, 2, 3, 0; data_index 3; roll_shift 12 round1: h_ordering 0, 1, 2, 3; data_index 4; roll_shift 5 round1: h_ordering 3, 0, 1, 2; data_index 5; roll_shift 8 round1: h_ordering 2, 3, 0, 1; data_index 6; roll_shift 7 round1: h_ordering 1, 2, 3, 0; data_index 7; roll_shift 9 round1: h_ordering 0, 1, 2, 3; data_index 8; roll_shift 11 round1: h_ordering 3, 0, 1, 2; data_index 9; roll_shift 13 round1: h_ordering 2, 3, 0, 1; data_index 10; roll_shift 14 round1: h_ordering 1, 2, 3, 0; data_index 11; roll_shift 15 round1: h_ordering 0, 1, 2, 3; data_index 12; roll_shift 6 round1: h_ordering 3, 0, 1, 2; data_index 13; roll_shift 7 round1: h_ordering 2, 3, 0, 1; data_index 14; roll_shift 9 round1: h_ordering 1, 2, 3, 0; data_index 15; roll_shift 8; // Round 2 round2: h_ordering 0, 1, 2, 3; data_index 7; roll_shift 7 round2: h_ordering 3, 0, 1, 2; data_index 4; roll_shift 6 round2: h_ordering 2, 3, 0, 1; data_index 13; roll_shift 8 round2: h_ordering 1, 2, 3, 0; data_index 1; roll_shift 13 round2: h_ordering 0, 1, 2, 3; data_index 10; roll_shift 11 round2: h_ordering 3, 0, 1, 2; data_index 6; roll_shift 9 round2: h_ordering 2, 3, 0, 1; data_index 15; roll_shift 7 round2: h_ordering 1, 2, 3, 0; data_index 3; roll_shift 15 round2: h_ordering 0, 1, 2, 3; data_index 12; roll_shift 7 round2: h_ordering 3, 0, 1, 2; data_index 0; roll_shift 12 round2: h_ordering 2, 3, 0, 1; data_index 9; roll_shift 15 round2: h_ordering 1, 2, 3, 0; data_index 5; roll_shift 9 round2: h_ordering 0, 1, 2, 3; data_index 2; roll_shift 11 round2: h_ordering 3, 0, 1, 2; data_index 14; roll_shift 7 round2: h_ordering 2, 3, 0, 1; data_index 11; roll_shift 13 round2: h_ordering 1, 2, 3, 0; data_index 8; roll_shift 12; // Round 3 round3: h_ordering 0, 1, 2, 3; data_index 3; roll_shift 11 round3: h_ordering 3, 0, 1, 2; data_index 10; roll_shift 13 round3: h_ordering 2, 3, 0, 1; data_index 14; roll_shift 6 round3: h_ordering 1, 2, 3, 0; data_index 4; roll_shift 7 round3: h_ordering 0, 1, 2, 3; data_index 9; roll_shift 14 round3: h_ordering 3, 0, 1, 2; data_index 15; roll_shift 9 round3: h_ordering 2, 3, 0, 1; data_index 8; roll_shift 13 round3: h_ordering 1, 2, 3, 0; data_index 1; roll_shift 15 round3: h_ordering 0, 1, 2, 3; data_index 2; roll_shift 14 round3: h_ordering 3, 0, 1, 2; data_index 7; roll_shift 8 round3: h_ordering 2, 3, 0, 1; data_index 0; roll_shift 13 round3: h_ordering 1, 2, 3, 0; data_index 6; roll_shift 6 round3: h_ordering 0, 1, 2, 3; data_index 13; roll_shift 5 round3: h_ordering 3, 0, 1, 2; data_index 11; roll_shift 12 round3: h_ordering 2, 3, 0, 1; data_index 5; roll_shift 7 round3: h_ordering 1, 2, 3, 0; data_index 12; roll_shift 5; // Round 4 round4: h_ordering 0, 1, 2, 3; data_index 1; roll_shift 11 round4: h_ordering 3, 0, 1, 2; data_index 9; roll_shift 12 round4: h_ordering 2, 3, 0, 1; data_index 11; roll_shift 14 round4: h_ordering 1, 2, 3, 0; data_index 10; roll_shift 15 round4: h_ordering 0, 1, 2, 3; data_index 0; roll_shift 14 round4: h_ordering 3, 0, 1, 2; data_index 8; roll_shift 15 round4: h_ordering 2, 3, 0, 1; data_index 12; roll_shift 9 round4: h_ordering 1, 2, 3, 0; data_index 4; roll_shift 8 round4: h_ordering 0, 1, 2, 3; data_index 13; roll_shift 9 round4: h_ordering 3, 0, 1, 2; data_index 3; roll_shift 14 round4: h_ordering 2, 3, 0, 1; data_index 7; roll_shift 5 round4: h_ordering 1, 2, 3, 0; data_index 15; roll_shift 6 round4: h_ordering 0, 1, 2, 3; data_index 14; roll_shift 8 round4: h_ordering 3, 0, 1, 2; data_index 5; roll_shift 6 round4: h_ordering 2, 3, 0, 1; data_index 6; roll_shift 5 round4: h_ordering 1, 2, 3, 0; data_index 2; roll_shift 12; // Parallel Round 1 par_round1: h_ordering 0, 1, 2, 3; data_index 5; roll_shift 8 par_round1: h_ordering 3, 0, 1, 2; data_index 14; roll_shift 9 par_round1: h_ordering 2, 3, 0, 1; data_index 7; roll_shift 9 par_round1: h_ordering 1, 2, 3, 0; data_index 0; roll_shift 11 par_round1: h_ordering 0, 1, 2, 3; data_index 9; roll_shift 13 par_round1: h_ordering 3, 0, 1, 2; data_index 2; roll_shift 15 par_round1: h_ordering 2, 3, 0, 1; data_index 11; roll_shift 15 par_round1: h_ordering 1, 2, 3, 0; data_index 4; roll_shift 5 par_round1: h_ordering 0, 1, 2, 3; data_index 13; roll_shift 7 par_round1: h_ordering 3, 0, 1, 2; data_index 6; roll_shift 7 par_round1: h_ordering 2, 3, 0, 1; data_index 15; roll_shift 8 par_round1: h_ordering 1, 2, 3, 0; data_index 8; roll_shift 11 par_round1: h_ordering 0, 1, 2, 3; data_index 1; roll_shift 14 par_round1: h_ordering 3, 0, 1, 2; data_index 10; roll_shift 14 par_round1: h_ordering 2, 3, 0, 1; data_index 3; roll_shift 12 par_round1: h_ordering 1, 2, 3, 0; data_index 12; roll_shift 6; // Parallel Round 2 par_round2: h_ordering 0, 1, 2, 3; data_index 6; roll_shift 9 par_round2: h_ordering 3, 0, 1, 2; data_index 11; roll_shift 13 par_round2: h_ordering 2, 3, 0, 1; data_index 3; roll_shift 15 par_round2: h_ordering 1, 2, 3, 0; data_index 7; roll_shift 7 par_round2: h_ordering 0, 1, 2, 3; data_index 0; roll_shift 12 par_round2: h_ordering 3, 0, 1, 2; data_index 13; roll_shift 8 par_round2: h_ordering 2, 3, 0, 1; data_index 5; roll_shift 9 par_round2: h_ordering 1, 2, 3, 0; data_index 10; roll_shift 11 par_round2: h_ordering 0, 1, 2, 3; data_index 14; roll_shift 7 par_round2: h_ordering 3, 0, 1, 2; data_index 15; roll_shift 7 par_round2: h_ordering 2, 3, 0, 1; data_index 8; roll_shift 12 par_round2: h_ordering 1, 2, 3, 0; data_index 12; roll_shift 7 par_round2: h_ordering 0, 1, 2, 3; data_index 4; roll_shift 6 par_round2: h_ordering 3, 0, 1, 2; data_index 9; roll_shift 15 par_round2: h_ordering 2, 3, 0, 1; data_index 1; roll_shift 13 par_round2: h_ordering 1, 2, 3, 0; data_index 2; roll_shift 11; // Parallel Round 3 par_round3: h_ordering 0, 1, 2, 3; data_index 15; roll_shift 9 par_round3: h_ordering 3, 0, 1, 2; data_index 5; roll_shift 7 par_round3: h_ordering 2, 3, 0, 1; data_index 1; roll_shift 15 par_round3: h_ordering 1, 2, 3, 0; data_index 3; roll_shift 11 par_round3: h_ordering 0, 1, 2, 3; data_index 7; roll_shift 8 par_round3: h_ordering 3, 0, 1, 2; data_index 14; roll_shift 6 par_round3: h_ordering 2, 3, 0, 1; data_index 6; roll_shift 6 par_round3: h_ordering 1, 2, 3, 0; data_index 9; roll_shift 14 par_round3: h_ordering 0, 1, 2, 3; data_index 11; roll_shift 12 par_round3: h_ordering 3, 0, 1, 2; data_index 8; roll_shift 13 par_round3: h_ordering 2, 3, 0, 1; data_index 12; roll_shift 5 par_round3: h_ordering 1, 2, 3, 0; data_index 2; roll_shift 14 par_round3: h_ordering 0, 1, 2, 3; data_index 10; roll_shift 13 par_round3: h_ordering 3, 0, 1, 2; data_index 0; roll_shift 13 par_round3: h_ordering 2, 3, 0, 1; data_index 4; roll_shift 7 par_round3: h_ordering 1, 2, 3, 0; data_index 13; roll_shift 5; // Parallel Round 4 par_round4: h_ordering 0, 1, 2, 3; data_index 8; roll_shift 15 par_round4: h_ordering 3, 0, 1, 2; data_index 6; roll_shift 5 par_round4: h_ordering 2, 3, 0, 1; data_index 4; roll_shift 8 par_round4: h_ordering 1, 2, 3, 0; data_index 1; roll_shift 11 par_round4: h_ordering 0, 1, 2, 3; data_index 3; roll_shift 14 par_round4: h_ordering 3, 0, 1, 2; data_index 11; roll_shift 14 par_round4: h_ordering 2, 3, 0, 1; data_index 15; roll_shift 6 par_round4: h_ordering 1, 2, 3, 0; data_index 0; roll_shift 14 par_round4: h_ordering 0, 1, 2, 3; data_index 5; roll_shift 6 par_round4: h_ordering 3, 0, 1, 2; data_index 12; roll_shift 9 par_round4: h_ordering 2, 3, 0, 1; data_index 2; roll_shift 12 par_round4: h_ordering 1, 2, 3, 0; data_index 13; roll_shift 9 par_round4: h_ordering 0, 1, 2, 3; data_index 9; roll_shift 12 par_round4: h_ordering 3, 0, 1, 2; data_index 7; roll_shift 5 par_round4: h_ordering 2, 3, 0, 1; data_index 10; roll_shift 15 par_round4: h_ordering 1, 2, 3, 0; data_index 14; roll_shift 8; ); } ripemd-0.1.3/src/c320.rs000064400000000000000000000424041046102023000127150ustar 00000000000000use core::{convert::TryInto, mem::swap}; pub const HALF_DIGEST_BUF_LEN: usize = 5; pub const DIGEST_BUF_LEN: usize = 10; pub const WORK_BUF_LEN: usize = 16; pub const H0: [u32; DIGEST_BUF_LEN] = [ 0x6745_2301, 0xefcd_ab89, 0x98ba_dcfe, 0x1032_5476, 0xc3d2_e1f0, 0x7654_3210, 0xfedc_ba98, 0x89ab_cdef, 0x0123_4567, 0x3c2d_1e0f, ]; macro_rules! round( ($a:expr, $b:expr, $c:expr, $d:expr, $e:expr, $x:expr, $bits:expr, $add:expr, $round:expr) => ({ $a = $a.wrapping_add($round).wrapping_add($x).wrapping_add($add); $a = $a.rotate_left($bits).wrapping_add($e); $c = $c.rotate_left(10); }); ); #[inline(always)] fn swap_idx(bb: &mut [u32; HALF_DIGEST_BUF_LEN], bbb: &mut [u32; HALF_DIGEST_BUF_LEN], idx: usize) { swap(&mut bb[idx], &mut bbb[idx]); } macro_rules! process_block( ($h:ident, $data:expr, $( round1: h_ordering $f0:expr, $f1:expr, $f2:expr, $f3:expr, $f4:expr; data_index $data_index1:expr; roll_shift $bits1:expr )*; $( round2: h_ordering $g0:expr, $g1:expr, $g2:expr, $g3:expr, $g4:expr; data_index $data_index2:expr; roll_shift $bits2:expr )*; $( round3: h_ordering $h0:expr, $h1:expr, $h2:expr, $h3:expr, $h4:expr; data_index $data_index3:expr; roll_shift $bits3:expr )*; $( round4: h_ordering $i0:expr, $i1:expr, $i2:expr, $i3:expr, $i4:expr; data_index $data_index4:expr; roll_shift $bits4:expr )*; $( round5: h_ordering $j0:expr, $j1:expr, $j2:expr, $j3:expr, $j4:expr; data_index $data_index5:expr; roll_shift $bits5:expr )*; $( par_round1: h_ordering $pj0:expr, $pj1:expr, $pj2:expr, $pj3:expr, $pj4:expr; data_index $pdata_index1:expr; roll_shift $pbits1:expr )*; $( par_round2: h_ordering $pi0:expr, $pi1:expr, $pi2:expr, $pi3:expr, $pi4:expr; data_index $pdata_index2:expr; roll_shift $pbits2:expr )*; $( par_round3: h_ordering $ph0:expr, $ph1:expr, $ph2:expr, $ph3:expr, $ph4:expr; data_index $pdata_index3:expr; roll_shift $pbits3:expr )*; $( par_round4: h_ordering $pg0:expr, $pg1:expr, $pg2:expr, $pg3:expr, $pg4:expr; data_index $pdata_index4:expr; roll_shift $pbits4:expr )*; $( par_round5: h_ordering $pf0:expr, $pf1:expr, $pf2:expr, $pf3:expr, $pf4:expr; data_index $pdata_index5:expr; roll_shift $pbits5:expr )*; ) => ({ let mut bb = [0u32; HALF_DIGEST_BUF_LEN]; bb.copy_from_slice(&$h[..HALF_DIGEST_BUF_LEN]); let mut bbb = [0u32; HALF_DIGEST_BUF_LEN]; bbb.copy_from_slice(&$h[HALF_DIGEST_BUF_LEN..]); // Round 1 $( round!(bb[$f0], bb[$f1], bb[$f2], bb[$f3], bb[$f4], $data[$data_index1], $bits1, 0x0000_0000, bb[$f1] ^ bb[$f2] ^ bb[$f3]); )* // Parallel Round 1 $( round!(bbb[$pj0], bbb[$pj1], bbb[$pj2], bbb[$pj3], bbb[$pj4], $data[$pdata_index1], $pbits1, 0x50a2_8be6, bbb[$pj1] ^ (bbb[$pj2] | !bbb[$pj3])); )* swap_idx(&mut bb, &mut bbb, 0); // Round 2 $( round!(bb[$g0], bb[$g1], bb[$g2], bb[$g3], bb[$g4], $data[$data_index2], $bits2, 0x5a82_7999, (bb[$g1] & bb[$g2]) | (!bb[$g1] & bb[$g3])); )* // Parallel Round 2 $( round!(bbb[$pi0], bbb[$pi1], bbb[$pi2], bbb[$pi3], bbb[$pi4], $data[$pdata_index2], $pbits2, 0x5c4d_d124, (bbb[$pi1] & bbb[$pi3]) | (bbb[$pi2] & !bbb[$pi3])); )* swap_idx(&mut bb, &mut bbb, 1); // Round 3 $( round!(bb[$h0], bb[$h1], bb[$h2], bb[$h3], bb[$h4], $data[$data_index3], $bits3, 0x6ed9_eba1, (bb[$h1] | !bb[$h2]) ^ bb[$h3]); )* // Parallel Round 3 $( round!(bbb[$ph0], bbb[$ph1], bbb[$ph2], bbb[$ph3], bbb[$ph4], $data[$pdata_index3], $pbits3, 0x6d70_3ef3, (bbb[$ph1] | !bbb[$ph2]) ^ bbb[$ph3]); )* swap_idx(&mut bb, &mut bbb, 2); // Round 4 $( round!(bb[$i0], bb[$i1], bb[$i2], bb[$i3], bb[$i4], $data[$data_index4], $bits4, 0x8f1b_bcdc, (bb[$i1] & bb[$i3]) | (bb[$i2] & !bb[$i3])); )* // Parallel Round 4 $( round!(bbb[$pg0], bbb[$pg1], bbb[$pg2], bbb[$pg3], bbb[$pg4], $data[$pdata_index4], $pbits4, 0x7a6d_76e9, (bbb[$pg1] & bbb[$pg2]) | (!bbb[$pg1] & bbb[$pg3])); )* swap_idx(&mut bb, &mut bbb, 3); // Round 5 $( round!(bb[$j0], bb[$j1], bb[$j2], bb[$j3], bb[$j4], $data[$data_index5], $bits5, 0xa953_fd4e, bb[$j1] ^ (bb[$j2] | !bb[$j3])); )* // Parallel Round 5 $( round!(bbb[$pf0], bbb[$pf1], bbb[$pf2], bbb[$pf3], bbb[$pf4], $data[$pdata_index5], $pbits5, 0x0000_0000, bbb[$pf1] ^ bbb[$pf2] ^ bbb[$pf3]); )* swap_idx(&mut bb, &mut bbb, 4); $h[0] = $h[0].wrapping_add(bb[0]); $h[1] = $h[1].wrapping_add(bb[1]); $h[2] = $h[2].wrapping_add(bb[2]); $h[3] = $h[3].wrapping_add(bb[3]); $h[4] = $h[4].wrapping_add(bb[4]); $h[5] = $h[5].wrapping_add(bbb[0]); $h[6] = $h[6].wrapping_add(bbb[1]); $h[7] = $h[7].wrapping_add(bbb[2]); $h[8] = $h[8].wrapping_add(bbb[3]); $h[9] = $h[9].wrapping_add(bbb[4]); }); ); pub fn compress(h: &mut [u32; DIGEST_BUF_LEN], data: &[u8; 64]) { let mut w = [0u32; WORK_BUF_LEN]; for (o, chunk) in w.iter_mut().zip(data.chunks_exact(4)) { *o = u32::from_le_bytes(chunk.try_into().unwrap()); } process_block!(h, w[..], // Round 1 round1: h_ordering 0, 1, 2, 3, 4; data_index 0; roll_shift 11 round1: h_ordering 4, 0, 1, 2, 3; data_index 1; roll_shift 14 round1: h_ordering 3, 4, 0, 1, 2; data_index 2; roll_shift 15 round1: h_ordering 2, 3, 4, 0, 1; data_index 3; roll_shift 12 round1: h_ordering 1, 2, 3, 4, 0; data_index 4; roll_shift 5 round1: h_ordering 0, 1, 2, 3, 4; data_index 5; roll_shift 8 round1: h_ordering 4, 0, 1, 2, 3; data_index 6; roll_shift 7 round1: h_ordering 3, 4, 0, 1, 2; data_index 7; roll_shift 9 round1: h_ordering 2, 3, 4, 0, 1; data_index 8; roll_shift 11 round1: h_ordering 1, 2, 3, 4, 0; data_index 9; roll_shift 13 round1: h_ordering 0, 1, 2, 3, 4; data_index 10; roll_shift 14 round1: h_ordering 4, 0, 1, 2, 3; data_index 11; roll_shift 15 round1: h_ordering 3, 4, 0, 1, 2; data_index 12; roll_shift 6 round1: h_ordering 2, 3, 4, 0, 1; data_index 13; roll_shift 7 round1: h_ordering 1, 2, 3, 4, 0; data_index 14; roll_shift 9 round1: h_ordering 0, 1, 2, 3, 4; data_index 15; roll_shift 8; // Round 2 round2: h_ordering 4, 0, 1, 2, 3; data_index 7; roll_shift 7 round2: h_ordering 3, 4, 0, 1, 2; data_index 4; roll_shift 6 round2: h_ordering 2, 3, 4, 0, 1; data_index 13; roll_shift 8 round2: h_ordering 1, 2, 3, 4, 0; data_index 1; roll_shift 13 round2: h_ordering 0, 1, 2, 3, 4; data_index 10; roll_shift 11 round2: h_ordering 4, 0, 1, 2, 3; data_index 6; roll_shift 9 round2: h_ordering 3, 4, 0, 1, 2; data_index 15; roll_shift 7 round2: h_ordering 2, 3, 4, 0, 1; data_index 3; roll_shift 15 round2: h_ordering 1, 2, 3, 4, 0; data_index 12; roll_shift 7 round2: h_ordering 0, 1, 2, 3, 4; data_index 0; roll_shift 12 round2: h_ordering 4, 0, 1, 2, 3; data_index 9; roll_shift 15 round2: h_ordering 3, 4, 0, 1, 2; data_index 5; roll_shift 9 round2: h_ordering 2, 3, 4, 0, 1; data_index 2; roll_shift 11 round2: h_ordering 1, 2, 3, 4, 0; data_index 14; roll_shift 7 round2: h_ordering 0, 1, 2, 3, 4; data_index 11; roll_shift 13 round2: h_ordering 4, 0, 1, 2, 3; data_index 8; roll_shift 12; // Round 3 round3: h_ordering 3, 4, 0, 1, 2; data_index 3; roll_shift 11 round3: h_ordering 2, 3, 4, 0, 1; data_index 10; roll_shift 13 round3: h_ordering 1, 2, 3, 4, 0; data_index 14; roll_shift 6 round3: h_ordering 0, 1, 2, 3, 4; data_index 4; roll_shift 7 round3: h_ordering 4, 0, 1, 2, 3; data_index 9; roll_shift 14 round3: h_ordering 3, 4, 0, 1, 2; data_index 15; roll_shift 9 round3: h_ordering 2, 3, 4, 0, 1; data_index 8; roll_shift 13 round3: h_ordering 1, 2, 3, 4, 0; data_index 1; roll_shift 15 round3: h_ordering 0, 1, 2, 3, 4; data_index 2; roll_shift 14 round3: h_ordering 4, 0, 1, 2, 3; data_index 7; roll_shift 8 round3: h_ordering 3, 4, 0, 1, 2; data_index 0; roll_shift 13 round3: h_ordering 2, 3, 4, 0, 1; data_index 6; roll_shift 6 round3: h_ordering 1, 2, 3, 4, 0; data_index 13; roll_shift 5 round3: h_ordering 0, 1, 2, 3, 4; data_index 11; roll_shift 12 round3: h_ordering 4, 0, 1, 2, 3; data_index 5; roll_shift 7 round3: h_ordering 3, 4, 0, 1, 2; data_index 12; roll_shift 5; // Round 4 round4: h_ordering 2, 3, 4, 0, 1; data_index 1; roll_shift 11 round4: h_ordering 1, 2, 3, 4, 0; data_index 9; roll_shift 12 round4: h_ordering 0, 1, 2, 3, 4; data_index 11; roll_shift 14 round4: h_ordering 4, 0, 1, 2, 3; data_index 10; roll_shift 15 round4: h_ordering 3, 4, 0, 1, 2; data_index 0; roll_shift 14 round4: h_ordering 2, 3, 4, 0, 1; data_index 8; roll_shift 15 round4: h_ordering 1, 2, 3, 4, 0; data_index 12; roll_shift 9 round4: h_ordering 0, 1, 2, 3, 4; data_index 4; roll_shift 8 round4: h_ordering 4, 0, 1, 2, 3; data_index 13; roll_shift 9 round4: h_ordering 3, 4, 0, 1, 2; data_index 3; roll_shift 14 round4: h_ordering 2, 3, 4, 0, 1; data_index 7; roll_shift 5 round4: h_ordering 1, 2, 3, 4, 0; data_index 15; roll_shift 6 round4: h_ordering 0, 1, 2, 3, 4; data_index 14; roll_shift 8 round4: h_ordering 4, 0, 1, 2, 3; data_index 5; roll_shift 6 round4: h_ordering 3, 4, 0, 1, 2; data_index 6; roll_shift 5 round4: h_ordering 2, 3, 4, 0, 1; data_index 2; roll_shift 12; // Round 5 round5: h_ordering 1, 2, 3, 4, 0; data_index 4; roll_shift 9 round5: h_ordering 0, 1, 2, 3, 4; data_index 0; roll_shift 15 round5: h_ordering 4, 0, 1, 2, 3; data_index 5; roll_shift 5 round5: h_ordering 3, 4, 0, 1, 2; data_index 9; roll_shift 11 round5: h_ordering 2, 3, 4, 0, 1; data_index 7; roll_shift 6 round5: h_ordering 1, 2, 3, 4, 0; data_index 12; roll_shift 8 round5: h_ordering 0, 1, 2, 3, 4; data_index 2; roll_shift 13 round5: h_ordering 4, 0, 1, 2, 3; data_index 10; roll_shift 12 round5: h_ordering 3, 4, 0, 1, 2; data_index 14; roll_shift 5 round5: h_ordering 2, 3, 4, 0, 1; data_index 1; roll_shift 12 round5: h_ordering 1, 2, 3, 4, 0; data_index 3; roll_shift 13 round5: h_ordering 0, 1, 2, 3, 4; data_index 8; roll_shift 14 round5: h_ordering 4, 0, 1, 2, 3; data_index 11; roll_shift 11 round5: h_ordering 3, 4, 0, 1, 2; data_index 6; roll_shift 8 round5: h_ordering 2, 3, 4, 0, 1; data_index 15; roll_shift 5 round5: h_ordering 1, 2, 3, 4, 0; data_index 13; roll_shift 6; // Parallel Round 1 par_round1: h_ordering 0, 1, 2, 3, 4; data_index 5; roll_shift 8 par_round1: h_ordering 4, 0, 1, 2, 3; data_index 14; roll_shift 9 par_round1: h_ordering 3, 4, 0, 1, 2; data_index 7; roll_shift 9 par_round1: h_ordering 2, 3, 4, 0, 1; data_index 0; roll_shift 11 par_round1: h_ordering 1, 2, 3, 4, 0; data_index 9; roll_shift 13 par_round1: h_ordering 0, 1, 2, 3, 4; data_index 2; roll_shift 15 par_round1: h_ordering 4, 0, 1, 2, 3; data_index 11; roll_shift 15 par_round1: h_ordering 3, 4, 0, 1, 2; data_index 4; roll_shift 5 par_round1: h_ordering 2, 3, 4, 0, 1; data_index 13; roll_shift 7 par_round1: h_ordering 1, 2, 3, 4, 0; data_index 6; roll_shift 7 par_round1: h_ordering 0, 1, 2, 3, 4; data_index 15; roll_shift 8 par_round1: h_ordering 4, 0, 1, 2, 3; data_index 8; roll_shift 11 par_round1: h_ordering 3, 4, 0, 1, 2; data_index 1; roll_shift 14 par_round1: h_ordering 2, 3, 4, 0, 1; data_index 10; roll_shift 14 par_round1: h_ordering 1, 2, 3, 4, 0; data_index 3; roll_shift 12 par_round1: h_ordering 0, 1, 2, 3, 4; data_index 12; roll_shift 6; // Parallel Round 2 par_round2: h_ordering 4, 0, 1, 2, 3; data_index 6; roll_shift 9 par_round2: h_ordering 3, 4, 0, 1, 2; data_index 11; roll_shift 13 par_round2: h_ordering 2, 3, 4, 0, 1; data_index 3; roll_shift 15 par_round2: h_ordering 1, 2, 3, 4, 0; data_index 7; roll_shift 7 par_round2: h_ordering 0, 1, 2, 3, 4; data_index 0; roll_shift 12 par_round2: h_ordering 4, 0, 1, 2, 3; data_index 13; roll_shift 8 par_round2: h_ordering 3, 4, 0, 1, 2; data_index 5; roll_shift 9 par_round2: h_ordering 2, 3, 4, 0, 1; data_index 10; roll_shift 11 par_round2: h_ordering 1, 2, 3, 4, 0; data_index 14; roll_shift 7 par_round2: h_ordering 0, 1, 2, 3, 4; data_index 15; roll_shift 7 par_round2: h_ordering 4, 0, 1, 2, 3; data_index 8; roll_shift 12 par_round2: h_ordering 3, 4, 0, 1, 2; data_index 12; roll_shift 7 par_round2: h_ordering 2, 3, 4, 0, 1; data_index 4; roll_shift 6 par_round2: h_ordering 1, 2, 3, 4, 0; data_index 9; roll_shift 15 par_round2: h_ordering 0, 1, 2, 3, 4; data_index 1; roll_shift 13 par_round2: h_ordering 4, 0, 1, 2, 3; data_index 2; roll_shift 11; // Parallel Round 3 par_round3: h_ordering 3, 4, 0, 1, 2; data_index 15; roll_shift 9 par_round3: h_ordering 2, 3, 4, 0, 1; data_index 5; roll_shift 7 par_round3: h_ordering 1, 2, 3, 4, 0; data_index 1; roll_shift 15 par_round3: h_ordering 0, 1, 2, 3, 4; data_index 3; roll_shift 11 par_round3: h_ordering 4, 0, 1, 2, 3; data_index 7; roll_shift 8 par_round3: h_ordering 3, 4, 0, 1, 2; data_index 14; roll_shift 6 par_round3: h_ordering 2, 3, 4, 0, 1; data_index 6; roll_shift 6 par_round3: h_ordering 1, 2, 3, 4, 0; data_index 9; roll_shift 14 par_round3: h_ordering 0, 1, 2, 3, 4; data_index 11; roll_shift 12 par_round3: h_ordering 4, 0, 1, 2, 3; data_index 8; roll_shift 13 par_round3: h_ordering 3, 4, 0, 1, 2; data_index 12; roll_shift 5 par_round3: h_ordering 2, 3, 4, 0, 1; data_index 2; roll_shift 14 par_round3: h_ordering 1, 2, 3, 4, 0; data_index 10; roll_shift 13 par_round3: h_ordering 0, 1, 2, 3, 4; data_index 0; roll_shift 13 par_round3: h_ordering 4, 0, 1, 2, 3; data_index 4; roll_shift 7 par_round3: h_ordering 3, 4, 0, 1, 2; data_index 13; roll_shift 5; // Parallel Round 4 par_round4: h_ordering 2, 3, 4, 0, 1; data_index 8; roll_shift 15 par_round4: h_ordering 1, 2, 3, 4, 0; data_index 6; roll_shift 5 par_round4: h_ordering 0, 1, 2, 3, 4; data_index 4; roll_shift 8 par_round4: h_ordering 4, 0, 1, 2, 3; data_index 1; roll_shift 11 par_round4: h_ordering 3, 4, 0, 1, 2; data_index 3; roll_shift 14 par_round4: h_ordering 2, 3, 4, 0, 1; data_index 11; roll_shift 14 par_round4: h_ordering 1, 2, 3, 4, 0; data_index 15; roll_shift 6 par_round4: h_ordering 0, 1, 2, 3, 4; data_index 0; roll_shift 14 par_round4: h_ordering 4, 0, 1, 2, 3; data_index 5; roll_shift 6 par_round4: h_ordering 3, 4, 0, 1, 2; data_index 12; roll_shift 9 par_round4: h_ordering 2, 3, 4, 0, 1; data_index 2; roll_shift 12 par_round4: h_ordering 1, 2, 3, 4, 0; data_index 13; roll_shift 9 par_round4: h_ordering 0, 1, 2, 3, 4; data_index 9; roll_shift 12 par_round4: h_ordering 4, 0, 1, 2, 3; data_index 7; roll_shift 5 par_round4: h_ordering 3, 4, 0, 1, 2; data_index 10; roll_shift 15 par_round4: h_ordering 2, 3, 4, 0, 1; data_index 14; roll_shift 8; // Parallel Round 5 par_round5: h_ordering 1, 2, 3, 4, 0; data_index 12; roll_shift 8 par_round5: h_ordering 0, 1, 2, 3, 4; data_index 15; roll_shift 5 par_round5: h_ordering 4, 0, 1, 2, 3; data_index 10; roll_shift 12 par_round5: h_ordering 3, 4, 0, 1, 2; data_index 4; roll_shift 9 par_round5: h_ordering 2, 3, 4, 0, 1; data_index 1; roll_shift 12 par_round5: h_ordering 1, 2, 3, 4, 0; data_index 5; roll_shift 5 par_round5: h_ordering 0, 1, 2, 3, 4; data_index 8; roll_shift 14 par_round5: h_ordering 4, 0, 1, 2, 3; data_index 7; roll_shift 6 par_round5: h_ordering 3, 4, 0, 1, 2; data_index 6; roll_shift 8 par_round5: h_ordering 2, 3, 4, 0, 1; data_index 2; roll_shift 13 par_round5: h_ordering 1, 2, 3, 4, 0; data_index 13; roll_shift 6 par_round5: h_ordering 0, 1, 2, 3, 4; data_index 14; roll_shift 5 par_round5: h_ordering 4, 0, 1, 2, 3; data_index 0; roll_shift 15 par_round5: h_ordering 3, 4, 0, 1, 2; data_index 3; roll_shift 13 par_round5: h_ordering 2, 3, 4, 0, 1; data_index 9; roll_shift 11 par_round5: h_ordering 1, 2, 3, 4, 0; data_index 11; roll_shift 11; ); } ripemd-0.1.3/src/lib.rs000064400000000000000000000135521046102023000130160ustar 00000000000000//! An implementation of the [RIPEMD] cryptographic hash. //! //! This crate implements only the modified 1996 versions, not the original //! one from 1992. //! //! Note that RIPEMD-256 provides only the same security as RIPEMD-128, //! and RIPEMD-320 provides only the same security as RIPEMD-160. //! //! # Usage //! //! ```rust //! use hex_literal::hex; //! use ripemd::{Ripemd160, Ripemd320, Digest}; //! //! // create a RIPEMD-160 hasher instance //! let mut hasher = Ripemd160::new(); //! //! // process input message //! hasher.update(b"Hello world!"); //! //! // acquire hash digest in the form of GenericArray, //! // which in this case is equivalent to [u8; 20] //! let result = hasher.finalize(); //! assert_eq!(result[..], hex!("7f772647d88750add82d8e1a7a3e5c0902a346a3")); //! //! // same for RIPEMD-320 //! let mut hasher = Ripemd320::new(); //! hasher.update(b"Hello world!"); //! let result = hasher.finalize(); //! assert_eq!(&result[..], &hex!(" //! f1c1c231d301abcf2d7daae0269ff3e7bc68e623 //! ad723aa068d316b056d26b7d1bb6f0cc0f28336d //! ")[..]); //! ``` //! //! Also see [RustCrypto/hashes] readme. //! //! [RIPEMD]: https://en.wikipedia.org/wiki/RIPEMD //! [RustCrypto/hashes]: https://github.com/RustCrypto/hashes #![no_std] #![doc( html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg", html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg" )] #![forbid(unsafe_code)] #![warn(missing_docs, rust_2018_idioms)] pub use digest::{self, Digest}; use core::fmt; #[cfg(feature = "oid")] use digest::const_oid::{AssociatedOid, ObjectIdentifier}; use digest::{ block_buffer::Eager, core_api::{ AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, CoreWrapper, FixedOutputCore, OutputSizeUser, Reset, UpdateCore, }, typenum::{Unsigned, U16, U20, U32, U40, U64}, HashMarker, Output, }; mod c128; mod c160; mod c256; mod c320; macro_rules! impl_ripemd { ( $name:ident, $wrapped_name:ident, $mod:ident, $alg_width:expr, $doc_name:expr, $output_size:ty $(,)? ) => { #[doc = "Core block-level"] #[doc = $doc_name] #[doc = " hasher state."] #[derive(Clone)] pub struct $name { h: [u32; $mod::DIGEST_BUF_LEN], block_len: u64, } impl HashMarker for $name {} impl BlockSizeUser for $name { type BlockSize = U64; } impl BufferKindUser for $name { type BufferKind = Eager; } impl OutputSizeUser for $name { type OutputSize = $output_size; } impl UpdateCore for $name { #[inline] fn update_blocks(&mut self, blocks: &[Block]) { // Assumes that `block_len` does not overflow self.block_len += blocks.len() as u64; for block in blocks { $mod::compress(&mut self.h, block.as_ref()); } } } impl FixedOutputCore for $name { #[inline] fn finalize_fixed_core(&mut self, buffer: &mut Buffer, out: &mut Output) { let bs = Self::BlockSize::U64; let bit_len = 8 * (buffer.get_pos() as u64 + bs * self.block_len); let mut h = self.h; buffer.len64_padding_le(bit_len, |block| $mod::compress(&mut h, block.as_ref())); for (chunk, v) in out.chunks_exact_mut(4).zip(h.iter()) { chunk.copy_from_slice(&v.to_le_bytes()); } } } impl Default for $name { #[inline] fn default() -> Self { Self { h: $mod::H0, block_len: 0, } } } impl Reset for $name { #[inline] fn reset(&mut self) { *self = Default::default(); } } impl AlgorithmName for $name { #[inline] fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(concat!("Ripemd", $alg_width)) } } impl fmt::Debug for $name { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(concat!("Ripemd", $alg_width, "Core { ... }")) } } #[doc = $doc_name] #[doc = " hasher."] pub type $wrapped_name = CoreWrapper<$name>; }; } impl_ripemd!(Ripemd128Core, Ripemd128, c128, "128", "RIPEMD-128", U16); impl_ripemd!(Ripemd160Core, Ripemd160, c160, "160", "RIPEMD-160", U20); impl_ripemd!(Ripemd256Core, Ripemd256, c256, "256", "RIPEMD-256", U32); impl_ripemd!(Ripemd320Core, Ripemd320, c320, "320", "RIPEMD-320", U40); #[cfg(feature = "oid")] #[cfg_attr(docsrs, doc(cfg(feature = "oid")))] impl AssociatedOid for Ripemd128Core { /// The OID used for the RIPEMD-160. There are two OIDs defined. The Teletrust one (which is /// used by almost anybody, including BouncyCastle, OpenSSL, GnuTLS, etc. and the ISO one /// (1.0.10118.3.0.50), which seems to be used by nobody. const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.36.3.2.2"); } #[cfg(feature = "oid")] #[cfg_attr(docsrs, doc(cfg(feature = "oid")))] impl AssociatedOid for Ripemd160Core { /// The OID used for the RIPEMD-160. There are two OIDs defined. The Teletrust one (which is /// used by almost anybody, including BouncyCastle, OpenSSL, GnuTLS, etc. and the ISO one /// (1.0.10118.3.0.49), which seems to be used by Go and nobody else. const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.36.3.2.1"); } #[cfg(feature = "oid")] #[cfg_attr(docsrs, doc(cfg(feature = "oid")))] impl AssociatedOid for Ripemd256Core { const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.36.3.2.3"); } ripemd-0.1.3/tests/data/ripemd128.blb000064400000000000000000000007761046102023000153660ustar 00000000000000 bP>aFa z3Dž/W3abc Jf亄ckiLwmessage digest 2{=nR0b-}Ѹ4abcdefghijklmnopqrstuvwxyz *qI"qNpabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq -"I:|ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 YbL` 12345678901234567890123456789012345678901234567890123456789012345678901234567890 ?EG2۲Ģiy_VThe quick brown fox jumps over the lazy dog ?<?'58 VThe quick brown fox jumps over the lazy cog 8ŏ6s?^2Yripemd-0.1.3/tests/data/ripemd160.blb000064400000000000000000000003521046102023000153500ustar 00000000000000abc(]zJưZ pabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq(S8J l'b+VThe quick brown fox jumps over the lazy dog(72{Ԗqg;VThe quick brown fox jumps over the lazy cog( ri 3^ wJripemd-0.1.3/tests/data/ripemd256.blb000064400000000000000000000010041046102023000153510ustar 00000000000000@LN_wRM0z-t]chR-a@3>EW  x<͈:4i)%abc@n"-ۡ }hBuEemessage digest@quzQM\L9,kDeUJT 4abcdefghijklmnopqrstuvwxyz@d04uwḱxQ}Q3pabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq@8CUs穀*4n/6?|ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@W@ D$cп@~w 12345678901234567890123456789012345678901234567890123456789012345678901234567890@z@HhjbuSgx߉ripemd-0.1.3/tests/data/ripemd320.blb000064400000000000000000000007661046102023000153570ustar 00000000000000fooP@Z~;s |M2D#g,ݿP"]VaSlu{As%W}pZȀ:2aPx8&X uymfzWV,cT/G֗ ]abcPLO0 s0Z[q>t/BLh-message digestP:(P.]B/hO繅3?*ҟ%ȍkNr}j|4abcdefghijklmnopqrstuvwxyzPʽ G k,(4?AQf@#@Dc pabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqP4 "Mi `YL&[tpir|ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789PTI@mgP2 {>Wp ;8# <ripemd-0.1.3/tests/mod.rs000064400000000000000000000051511046102023000133760ustar 00000000000000use digest::dev::{feed_rand_16mib, fixed_reset_test}; use digest::new_test; use hex_literal::hex; use ripemd::{Digest, Ripemd128, Ripemd160, Ripemd256, Ripemd320}; // Test vectors from FIPS 180-1 and from the [RIPEMD webpage][1]. // // [1] https://homes.esat.kuleuven.be/~bosselae/ripemd160.html new_test!(ripemd128_main, "ripemd128", Ripemd128, fixed_reset_test); new_test!(ripemd160_main, "ripemd160", Ripemd160, fixed_reset_test); new_test!(ripemd256_main, "ripemd256", Ripemd256, fixed_reset_test); new_test!(ripemd320_main, "ripemd320", Ripemd320, fixed_reset_test); #[test] fn ripemd128_1mil_a() { let mut h = Ripemd128::new(); let buf = [b'a'; 1000]; for _ in 0..1000 { h.update(&buf[..]); } assert_eq!( h.finalize(), hex!("4a7f5723f954eba1216c9d8f6320431f").into() ); } #[test] fn ripemd128_rand() { let mut h = Ripemd128::new(); feed_rand_16mib(&mut h); assert_eq!( h.finalize()[..], hex!("01eb52529bcec15bd0cb4040ec998632")[..] ); } #[test] fn ripemd160_1mil_a() { let mut h = Ripemd160::new(); let buf = [b'a'; 1000]; for _ in 0..1000 { h.update(&buf[..]); } assert_eq!( h.finalize(), hex!("52783243c1697bdbe16d37f97f68f08325dc1528").into() ); } #[test] fn ripemd160_rand() { let mut h = Ripemd160::new(); feed_rand_16mib(&mut h); assert_eq!( h.finalize()[..], hex!("bcd8c672932125776af3c60eeeb58bbaf206f386")[..] ); } #[test] fn ripemd256_1mil_a() { let mut h = Ripemd256::new(); let buf = [b'a'; 1000]; for _ in 0..1000 { h.update(&buf[..]); } assert_eq!( h.finalize(), hex!("ac953744e10e31514c150d4d8d7b677342e33399788296e43ae4850ce4f97978").into() ); } #[test] fn ripemd256_rand() { let mut h = Ripemd256::new(); feed_rand_16mib(&mut h); assert_eq!( h.finalize()[..], hex!("6492ffe075896441b737900bdf58fc960e77477e42a2a61bc02c66fd689b69d0")[..] ); } #[test] #[rustfmt::skip] fn ripemd320_1mil_a() { let mut h = Ripemd320::new(); let buf = [b'a'; 1000]; for _ in 0..1000 { h.update(&buf[..]); } assert_eq!( h.finalize(), hex!(" bdee37f4371e20646b8b0d862dda16292ae36f40 965e8c8509e63d1dbddecc503e2b63eb9245bb66 ").into() ); } #[test] #[rustfmt::skip] fn ripemd320_rand() { let mut h = Ripemd320::new(); feed_rand_16mib(&mut h); assert_eq!( h.finalize()[..], hex!(" 3a905312162c5c173639f6cc1cdf51d14e8bda02 865767592e26d9343fbec348ce55ce39b4b4b56f ")[..] ); }