### Usage example for Sha1CD hasher Source: https://docs.rs/sha1collisiondetection/latest/sha1collisiondetection/index.html?search=std%3A%3Avec Shows how to create a Sha1CD hasher, update it with a message, and finalize to get the hash digest. The result is compared to a known hex value. Requires the hex_literal crate for the hex! macro. ```rust use hex_literal::hex; use sha1collisiondetection::Sha1CD; // create a Sha1CD object let mut hasher = Sha1CD::default(); // 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_cd().unwrap(); assert_eq!(result[..], hex!("2aae6c35c94fcfb415dbe95f408b9ce91ee846ed")); ``` -------------------------------- ### Install sha1collisiondetection CLI and check help Source: https://docs.rs/sha1collisiondetection/latest/sha1collisiondetection/index.html?search=u32+-%3E+bool Install the command-line utility using cargo, then run sha1cdsum --help to display usage information. ```bash $ cargo install sha1collisiondetection [...] $ sha1cdsum --help sha1cdsum 0.2.3 Print or check SHA1 (160-bit) checksums with collision detection. USAGE: sha1cdsum [FLAGS] [files]... [...] ``` -------------------------------- ### Sha1CD usage example Source: https://docs.rs/sha1collisiondetection/latest/sha1collisiondetection/index.html?search=std%3A%3Avec Example demonstrating how to create a Sha1CD hasher, update it with data, and finalize to obtain the digest. ```APIDOC ## Sha1CD usage example ### Description Example demonstrating how to create a Sha1CD hasher, update it with data, and finalize to obtain the digest. ### Code Example ```rust use hex_literal::hex; use sha1collisiondetection::Sha1CD; // create a Sha1CD object let mut hasher = Sha1CD::default(); // 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_cd().unwrap(); assert_eq!(result[..], hex!("2aae6c35c94fcfb415dbe95f408b9ce91ee846ed")); ``` ``` -------------------------------- ### Install and use sha1cdsum command line utility Source: https://docs.rs/sha1collisiondetection/latest/sha1collisiondetection/index.html?search=std%3A%3Avec Install the sha1collisiondetection command line utility with cargo, then run sha1cdsum --help to see usage and sha1cdsum test/*1.* to check files with collision detection. The output shows colliding files marked with *coll*. ```shell $ cargo install sha1collisiondetection [...] $ sha1cdsum --help sha1cdsum 0.2.3 Print or check SHA1 (160-bit) checksums with collision detection. USAGE: sha1cdsum [FLAGS] [files]... [...] $ sha1cdsum test/*1.* 4f3d9be4a472c4dae83c6314aa6c36a064c1fd14 *coll* test/sha-mbles-1.bin 16e96b70000dd1e7c85b8368ee197754400e58ec *coll* test/shattered-1.pdf ``` -------------------------------- ### sha1collisiondetection crate lib.rs source Source: https://docs.rs/sha1collisiondetection/latest/src/sha1collisiondetection/lib.rs.html The entire lib.rs source file for the sha1collisiondetection crate. It includes the crate-level documentation, the no_std setup, module declarations, and the public re-export of generic_array. ```rust //! An implementation of the [SHA-1][1] cryptographic hash algorithm. //! //! This is a port of Marc Stevens' sha1collisiondetection algorithm to //! Rust. The code is translated from C to Rust using c2rust. //! //! To improve the translation, the code is transformed first, replacing //! macros with inline functions. Running the test suite using `make //! check` tests the correctness of the transformation. //! //! This crate, like the C implementation, is distributed under the MIT //! Software License. //! //! # Installation of the command line utility //! //! The command line utility is a drop-in replacement for coreutils' //! `sha1sum` utility. It can be installed, for example, using cargo: //! //! ```sh //! $ cargo install sha1collisiondetection //! [...] //! $ sha1cdsum --help //! sha1cdsum 0.2.3 //! Print or check SHA1 (160-bit) checksums with collision detection. //! //! USAGE: //! sha1cdsum [FLAGS] [files]... //! [...] //! $ sha1cdsum test/*1.* //! 4f3d9be4a472c4dae83c6314aa6c36a064c1fd14 *coll* test/sha-mbles-1.bin //! 16e96b70000dd1e7c85b8368ee197754400e58ec *coll* test/shattered-1.pdf //! ``` //! //! //! # About //! //! This library was designed as near drop-in replacements for common //! SHA-1 libraries. They will compute the SHA-1 hash of any given //! file and additionally will detect cryptanalytic collision attacks //! against SHA-1 present in each file. It is very fast and takes less //! than twice the amount of time as regular SHA-1. //! //! More specifically they will detect any cryptanalytic collision attack //! against SHA-1 using any of the top 32 SHA-1 disturbance vectors with //! probability 1: //! //! ```text //! I(43,0), I(44,0), I(45,0), I(46,0), I(47,0), I(48,0), I(49,0), I(50,0), I(51,0), I(52,0), //! I(46,2), I(47,2), I(48,2), I(49,2), I(50,2), I(51,2), //! II(45,0), II(46,0), II(47,0), II(48,0), II(49,0), II(50,0), II(51,0), II(52,0), II(53,0), II(54,0), II(55,0), II(56,0), //! II(46,2), II(49,2), II(50,2), II(51,2) //! ``` //! //! The possibility of false positives can be neglected as the probability //! is smaller than 2^-90. //! //! The library supports both an indicator flag that applications can //! check and act on, as well as a special _safe-hash_ mode that returns //! the real SHA-1 hash when no collision was detected and a different //! _safe_ hash when a collision was detected. Colliding files will have //! the same SHA-1 hash, but will have different unpredictable //! safe-hashes. This essentially enables protection of applications //! against SHA-1 collisions with no further changes in the application, //! e.g., digital signature forgeries based on SHA-1 collisions //! automatically become invalid. //! //! For the theoretical explanation of collision detection see the //! award-winning paper on _Counter-Cryptanalysis_: //! //! Counter-cryptanalysis, Marc Stevens, CRYPTO 2013, Lecture Notes in //! Computer Science, vol. 8042, Springer, 2013, pp. 129-146, //! https://marc-stevens.nl/research/papers/C13-S.pdf //! //! # Developers //! //! The C implementation of the collision detection algorithm is //! implemented by: //! //! - Marc Stevens, CWI Amsterdam (https://marc-stevens.nl) //! - Dan Shumow, Microsoft Research (https://www.microsoft.com/en-us/research/people/danshu/) //! //! The C implementation is maintained //! [here](https://github.com/cr-marcstevens/sha1collisiondetection). //! //! Please report issues with the rust port //! [here](https://gitlab.com/sequoia-pgp/sha1collisiondetection). //! //! # Usage //! //! ```rust //! use hex_literal::hex; //! use sha1collisiondetection::Sha1CD; //! //! // create a Sha1CD object //! let mut hasher = Sha1CD::default(); //! //! // 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_cd().unwrap(); //! assert_eq!(result[..], hex!("2aae6c35c94fcfb415dbe95f408b9ce91ee846ed")); //! ``` //! //! If this crate's "digest-trait" feature is used, `Sha1CD` also //! implements the `Digest` trait from the `digest` crate. Also see //! [RustCrypto/hashes][2] readme. //! //! [1]: https://en.wikipedia.org/wiki/SHA-1 //! [2]: https://github.com/RustCrypto/hashes #![no_std] #![warn(missing_docs, rust_2018_idioms)] use core::fmt; #[cfg(feature = "std")] extern crate std; mod sha1; use crate::sha1 as sys; mod ubc_check; /// Public re-export for consumers of this crate. pub use generic_array; ``` -------------------------------- ### SHA1_CTX reset method Source: https://docs.rs/sha1collisiondetection/latest/src/sha1collisiondetection/sha1.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Re-initializes the context like SHA1DCInit by resetting total, ihv, and other fields to their initial values. This is used to start a new hashing operation. ```rust impl SHA1_CTX { /// Re-initializes the context like SHA1DCInit. pub(crate) fn reset(&mut self) { self.total = 0; self.ihv = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0, ]; self.buffer = Buffer { bytes: [0; 64] }; self.found_collision = false; self.safe_hash = true; self.ubc_check = true; self.detect_coll = true; self.reduced_round_coll = false; self.callback = None; self.ihv1 = [0; 5]; self.ihv2 = [0; 5]; self.m1 = [0; 80]; self.m2 = [0; 80]; self.states = [[0; 5]; 80]; } } ``` -------------------------------- ### Sha1CD::configure Source: https://docs.rs/sha1collisiondetection/latest/sha1collisiondetection/struct.Sha1CD.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Configures the algorithm. Returns a Builder for setting options. ```APIDOC ## Sha1CD::configure ### Description Configures the algorithm. Returns a Builder for setting options. ### Method configure ### Signature pub fn configure() -> Builder ### Parameters None ### Returns - **Builder** - A builder for configuring the SHA-1 algorithm. ``` -------------------------------- ### sha1_compression_states: run first 20 SHA-1 compression steps Source: https://docs.rs/sha1collisiondetection/latest/src/sha1collisiondetection/sha1.rs.html?search=std%3A%3Avec Defines sha1_compression_states, which initializes working variables a-e from the intermediate hash values and runs the first 20 SHA-1 compression steps. Steps 0-15 load message words from m, while steps 16-19 expand the message schedule in W; each call passes a mutable temp scratch value. ```rust fn sha1_compression_states(ihv: &mut [uint32_t; 5], m: &[uint32_t; 16], W: &mut [uint32_t; 80], states: &mut [[uint32_t; 5]; 80]) { let mut a: uint32_t = ihv[0]; let mut b: uint32_t = ihv[1]; let mut c: uint32_t = ihv[2]; let mut d: uint32_t = ihv[3]; let mut e: uint32_t = ihv[4]; let mut temp: uint32_t = 0; sha1compress_full_round1_step_load(a, &mut b, c, d, &mut e, m, W, 0, &mut temp); sha1compress_full_round1_step_load(e, &mut a, b, c, &mut d, m, W, 1, &mut temp); sha1compress_full_round1_step_load(d, &mut e, a, b, &mut c, m, W, 2, &mut temp); sha1compress_full_round1_step_load(c, &mut d, e, a, &mut b, m, W, 3, &mut temp); sha1compress_full_round1_step_load(b, &mut c, d, e, &mut a, m, W, 4, &mut temp); sha1compress_full_round1_step_load(a, &mut b, c, d, &mut e, m, W, 5, &mut temp); sha1compress_full_round1_step_load(e, &mut a, b, c, &mut d, m, W, 6, &mut temp); sha1compress_full_round1_step_load(d, &mut e, a, b, &mut c, m, W, 7, &mut temp); sha1compress_full_round1_step_load(c, &mut d, e, a, &mut b, m, W, 8, &mut temp); sha1compress_full_round1_step_load(b, &mut c, d, e, &mut a, m, W, 9, &mut temp); sha1compress_full_round1_step_load(a, &mut b, c, d, &mut e, m, W, 10, &mut temp); sha1compress_full_round1_step_load(e, &mut a, b, c, &mut d, m, W, 11, &mut temp); sha1compress_full_round1_step_load(d, &mut e, a, b, &mut c, m, W, 12, &mut temp); sha1compress_full_round1_step_load(c, &mut d, e, a, &mut b, m, W, 13, &mut temp); sha1compress_full_round1_step_load(b, &mut c, d, e, &mut a, m, W, 14, &mut temp); sha1compress_full_round1_step_load(a, &mut b, c, d, &mut e, m, W, 15, &mut temp); sha1compress_full_round1_step_expand(e, &mut a, b, c, &mut d, W, 16, &mut temp); sha1compress_full_round1_step_expand(d, &mut e, a, b, &mut c, W, 17, &mut temp); sha1compress_full_round1_step_expand(c, &mut d, e, a, &mut b, W, 18, &mut temp); sha1compress_full_round1_step_expand(b, &mut c, d, e, &mut a, W, 19, ``` -------------------------------- ### Builder::build Source: https://docs.rs/sha1collisiondetection/latest/sha1collisiondetection/struct.Builder.html Finalizes the configuration and returns a Sha1CD instance. ```APIDOC ## Builder::build ### Description Finalizes the configuration and returns a Sha1CD instance. ### Method pub fn build(self) -> Sha1CD ### Returns - **Sha1CD** - The configured SHA-1 collision-detecting hasher. ``` -------------------------------- ### Sha1CD::by_ref Source: https://docs.rs/sha1collisiondetection/latest/sha1collisiondetection/struct.Sha1CD.html?search=std%3A%3Avec Creates a “by reference” adapter for this instance of Write. ```APIDOC ## Sha1CD::by_ref ### Description Creates a “by reference” adapter for this instance of `Write`. ### Method by_ref ### Signature fn by_ref(&mut self) -> &mut Self where Self: Sized ### Parameters None. ### Returns - **&mut Self** - A mutable reference to the adapter. ### Availability Available on **crate feature `std`** only. ``` -------------------------------- ### Default implementation for SHA1_CTX Source: https://docs.rs/sha1collisiondetection/latest/src/sha1collisiondetection/sha1.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes a SHA1_CTX with the standard SHA-1 initial hash values, a zeroed 64-byte buffer, and default flags: safe_hash, ubc_check, and detect_coll are true; reduced_round_coll is false; callback is None. This mirrors SHA1DCInit but also initializes the buffers. ```rust impl Default for SHA1_CTX { /// Initializes the context like SHA1DCInit, but also initializes /// the buffers. fn default() -> Self { SHA1_CTX { total: 0, ihv: [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0, ], buffer: Buffer { bytes: [0; 64] }, found_collision: false, safe_hash: true, ubc_check: true, detect_coll: true, reduced_round_coll: false, callback: None, ihv1: [0; 5], ihv2: [0; 5], m1: [0; 80], m2: [0; 80], states: [[0; 5]; 80], } } } ``` -------------------------------- ### SHA-1 full compression round step helpers (sha1compress_full_round*_step) Source: https://docs.rs/sha1collisiondetection/latest/src/sha1collisiondetection/sha1.rs.html?search=std%3A%3Avec These inline helper functions implement the SHA-1 compression function rounds for the full (non-optimized) path. Each step updates the working variables a, b, c, d, e using the message schedule W and the round-specific constant (0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, or 0xca62c1d6). The round1_load variant loads the message word directly with maybe_bswap32, while the other variants expand the schedule via sha1_mix. All functions use wrapping_add and rotate_left and are marked #[inline]. ```rust fn sha1compress_full_round1_step_load(a: uint32_t, b: &mut uint32_t, c: uint32_t, d: uint32_t, e: &mut uint32_t, m: &[uint32_t; 16], W: &mut [uint32_t; 80], t: usize, temp: &mut uint32_t) { *temp = maybe_bswap32(m[t]); W[t] = *temp; *e = e.wrapping_add((*temp).wrapping_add(rotate_left(a, 5)).wrapping_add(sha1_f1(*b, c, d)).wrapping_add(0x5a827999)); *b = rotate_left(*b, 30); } ``` ```rust fn sha1compress_full_round1_step_expand(a: uint32_t, b: &mut uint32_t, c: uint32_t, d: uint32_t, e: &mut uint32_t, W: &mut [uint32_t; 80], t: usize, temp: &mut uint32_t) { *temp = sha1_mix(W, t); W[t] = *temp; *e = e.wrapping_add((*temp).wrapping_add(rotate_left(a, 5)).wrapping_add(sha1_f1(*b, c, d)).wrapping_add(0x5a827999)); *b = rotate_left(*b, 30); } ``` ```rust fn sha1compress_full_round2_step(a: uint32_t, b: &mut uint32_t, c: uint32_t, d: uint32_t, e: &mut uint32_t, W: &mut [uint32_t; 80], t: usize, temp: &mut uint32_t) { *temp = sha1_mix(W, t); W[t] = *temp; *e = e.wrapping_add((*temp).wrapping_add(rotate_left(a, 5)).wrapping_add(sha1_f2(*b, c, d)).wrapping_add(0x6ed9eba1)); *b = rotate_left(*b, 30); } ``` ```rust fn sha1compress_full_round3_step(a: uint32_t, b: &mut uint32_t, c: uint32_t, d: uint32_t, e: &mut uint32_t, W: &mut [uint32_t; 80], t: usize, temp: &mut uint32_t) { *temp = sha1_mix(W, t); W[t] = *temp; *e = e.wrapping_add((*temp).wrapping_add(rotate_left(a, 5)).wrapping_add(sha1_f3(*b, c, d)).wrapping_add(0x8f1bbcdc)); *b = rotate_left(*b, 30); } ``` ```rust fn sha1compress_full_round4_step(a: uint32_t, b: &mut uint32_t, c: uint32_t, d: uint32_t, e: &mut uint32_t, W: &mut [uint32_t; 80], t: usize, temp: &mut uint32_t) { *temp = sha1_mix(W, t); W[t] = *temp; *e = e.wrapping_add((*temp).wrapping_add(rotate_left(a, 5)).wrapping_add(sha1_f4(*b, c, d)).wrapping_add(0xca62c1d6).wrapping_add(m[t])); *b = rotate_left(*b, 30); } ``` -------------------------------- ### Sha1CD::default() Source: https://docs.rs/sha1collisiondetection/latest/index.html Creates a new Sha1CD hasher instance with default settings. This is the primary entry point for computing SHA-1 hashes with collision detection. ```APIDOC ## Sha1CD::default() ### Description Creates a new Sha1CD hasher instance with default settings. This is the primary entry point for computing SHA-1 hashes with collision detection. ### Method Constructor ### Parameters None ### Returns A new Sha1CD instance. ### Example ```rust use sha1collisiondetection::Sha1CD; let mut hasher = Sha1CD::default(); ``` ``` -------------------------------- ### Builder::use_ubc Source: https://docs.rs/sha1collisiondetection/latest/sha1collisiondetection/struct.Builder.html Configures use of Unavoidable Bitconditions, which provides a significant speed up. Enabled by default. ```APIDOC ## Builder::use_ubc ### Description Configures use of Unavoidable Bitconditions, which provides a significant speed up. Enabled by default. ### Method pub fn use_ubc(self, v: bool) -> Self ### Parameters - **v** (bool) - Required - Whether to use Unavoidable Bitconditions. ### Returns - **Self** - The builder with the updated configuration. ``` -------------------------------- ### SHA-1 compression rounds 20-50 with sha1compress_full_round2_step and sha1compress_full_round3_step Source: https://docs.rs/sha1collisiondetection/latest/src/sha1collisiondetection/sha1.rs.html?search=std%3A%3Avec Continuation of a SHA-1 compression function implementation, showing calls to sha1compress_full_round2_step for rounds 20-39 and sha1compress_full_round3_step for rounds 40-50. Each call passes the working variables a-e, the message schedule W, the round index, and a mutable temp variable. ```rust 565 &mut temp); 566 sha1compress_full_round2_step(a, &mut b, c, d, &mut e, 567 W, 568 20, &mut temp); 569 sha1compress_full_round2_step(e, &mut a, b, c, &mut d, 570 W, 571 21, &mut temp); 572 sha1compress_full_round2_step(d, &mut e, a, b, &mut c, 573 W, 574 22, &mut temp); 575 sha1compress_full_round2_step(c, &mut d, e, a, &mut b, 576 W, 577 23, &mut temp); 578 sha1compress_full_round2_step(b, &mut c, d, e, &mut a, 579 W, 580 24, &mut temp); 581 sha1compress_full_round2_step(a, &mut b, c, d, &mut e, 582 W, 583 25, &mut temp); 584 sha1compress_full_round2_step(e, &mut a, b, c, &mut d, 585 W, 586 26, &mut temp); 587 sha1compress_full_round2_step(d, &mut e, a, b, &mut c, 588 W, 589 27, &mut temp); 590 sha1compress_full_round2_step(c, &mut d, e, a, &mut b, 591 W, 592 28, &mut temp); 593 sha1compress_full_round2_step(b, &mut c, d, e, &mut a, 594 W, 595 29, &mut temp); 596 sha1compress_full_round2_step(a, &mut b, c, d, &mut e, 597 W, 598 30, &mut temp); 599 sha1compress_full_round2_step(e, &mut a, b, c, &mut d, 600 W, 601 31, &mut temp); 602 sha1compress_full_round2_step(d, &mut e, a, b, &mut c, 603 W, 604 32, &mut temp); 605 sha1compress_full_round2_step(c, &mut d, e, a, &mut b, 606 W, 607 33, &mut temp); 608 sha1compress_full_round2_step(b, &mut c, d, e, &mut a, 609 W, 610 34, &mut temp); 611 sha1compress_full_round2_step(a, &mut b, c, d, &mut e, 612 W, 613 35, &mut temp); 614 sha1compress_full_round2_step(e, &mut a, b, c, &mut d, 615 W, 616 36, &mut temp); 617 sha1compress_full_round2_step(d, &mut e, a, b, &mut c, 618 W, 619 37, &mut temp); 620 sha1compress_full_round2_step(c, &mut d, e, a, &mut b, 621 W, 622 38, &mut temp); 623 sha1compress_full_round2_step(b, &mut c, d, e, &mut a, 624 W, 625 39, &mut temp); 626 sha1compress_full_round3_step(a, &mut b, c, d, &mut e, 627 W, 628 40, &mut temp); 629 sha1compress_full_round3_step(e, &mut a, b, c, &mut d, 630 W, 631 41, &mut temp); 632 sha1compress_full_round3_step(d, &mut e, a, b, &mut c, 633 W, 634 42, &mut temp); 635 sha1compress_full_round3_step(c, &mut d, e, a, &mut b, 636 W, 637 43, &mut temp); 638 sha1compress_full_round3_step(b, &mut c, d, e, &mut a, 639 W, 640 44, &mut temp); 641 sha1compress_full_round3_step(a, &mut b, c, d, &mut e, 642 W, 643 45, &mut temp); 644 sha1compress_full_round3_step(e, &mut a, b, c, &mut d, 645 W, 646 46, &mut temp); 647 sha1compress_full_round3_step(d, &mut e, a, b, &mut c, 648 W, 649 47, &mut temp); 650 sha1compress_full_round3_step(c, &mut d, e, a, &mut b, 651 W, 652 48, &mut temp); 653 sha1compress_full_round3_step(b, &mut c, d, e, &mut a, 654 W, 655 49, &mut temp); 656 sha1compress_full_round3_step(a, &mut b, c, d, &mut e, 657 W, 658 50, &mut temp); 659 sha1compress_full_round3_step(e, &mut a, b, c, &mut d, 660 W, ``` -------------------------------- ### SHA-1 compression: round 3 and round 4 steps with state saving and final hash update Source: https://docs.rs/sha1collisiondetection/latest/src/sha1collisiondetection/sha1.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Completes the SHA-1 compression function by running round 3 steps (rounds 51-59) and round 4 steps (rounds 60-79), saving the state at rounds 58 and 65, and then adding the working variables to the intermediate hash values using wrapping_add. The code uses the sha1compress_full_round3_step and sha1compress_full_round4_step functions with a mutable temp variable. ```rust 661 51, &mut temp); 662 sha1compress_full_round3_step(d, &mut e, a, b, &mut c, 663 W, 664 52, &mut temp); 665 sha1compress_full_round3_step(c, &mut d, e, a, &mut b, 666 W, 667 53, &mut temp); 668 sha1compress_full_round3_step(b, &mut c, d, e, &mut a, 669 W, 670 54, &mut temp); 671 sha1compress_full_round3_step(a, &mut b, c, d, &mut e, 672 W, 673 55, &mut temp); 674 sha1compress_full_round3_step(e, &mut a, b, c, &mut d, 675 W, 676 56, &mut temp); 677 sha1compress_full_round3_step(d, &mut e, a, b, &mut c, 678 W, 679 57, &mut temp); 680 681 states[58][0] = a; 682 states[58][1] = b; 683 states[58][2] = c; 684 states[58][3] = d; 685 states[58][4] = e; 686 687 sha1compress_full_round3_step(c, &mut d, e, a, &mut b, 688 W, 689 58, &mut temp); 690 sha1compress_full_round3_step(b, &mut c, d, e, &mut a, 691 W, 692 59, &mut temp); 693 sha1compress_full_round4_step(a, &mut b, c, d, &mut e, 694 W, 695 60, &mut temp); 696 sha1compress_full_round4_step(e, &mut a, b, c, &mut d, 697 W, 698 61, &mut temp); 699 sha1compress_full_round4_step(d, &mut e, a, b, &mut c, 700 W, 701 62, &mut temp); 702 sha1compress_full_round4_step(c, &mut d, e, a, &mut b, 703 W, 704 63, &mut temp); 705 sha1compress_full_round4_step(b, &mut c, d, e, &mut a, 706 W, 707 64, &mut temp); 708 709 states[65][0] = a; 710 states[65][1] = b; 711 states[65][2] = c; 712 states[65][3] = d; 713 states[65][4] = e; 714 715 sha1compress_full_round4_step(a, &mut b, c, d, &mut e, 716 W, 717 65, &mut temp); 718 sha1compress_full_round4_step(e, &mut a, b, c, &mut d, 719 W, 720 66, &mut temp); 721 sha1compress_full_round4_step(d, &mut e, a, b, &mut c, 722 W, 723 67, &mut temp); 724 sha1compress_full_round4_step(c, &mut d, e, a, &mut b, 725 W, 726 68, &mut temp); 727 sha1compress_full_round4_step(b, &mut c, d, e, &mut a, 728 W, 729 69, &mut temp); 730 sha1compress_full_round4_step(a, &mut b, c, d, &mut e, 731 W, 732 70, &mut temp); 733 sha1compress_full_round4_step(e, &mut a, b, c, &mut d, 734 W, 735 71, &mut temp); 736 sha1compress_full_round4_step(d, &mut e, a, b, &mut c, 737 W, 738 72, &mut temp); 739 sha1compress_full_round4_step(c, &mut d, e, a, &mut b, 740 W, 741 73, &mut temp); 742 sha1compress_full_round4_step(b, &mut c, d, e, &mut a, 743 W, 744 74, &mut temp); 745 sha1compress_full_round4_step(a, &mut b, c, d, &mut e, 746 W, 747 75, &mut temp); 748 sha1compress_full_round4_step(e, &mut a, b, c, &mut d, 749 W, 750 76, &mut temp); 751 sha1compress_full_round4_step(d, &mut e, a, b, &mut c, 752 W, 753 77, &mut temp); 754 sha1compress_full_round4_step(c, &mut d, e, a, &mut b, 755 W, 756 78, &mut temp); 757 sha1compress_full_round4_step(b, &mut c, d, e, &mut a, 758 W, 759 79, &mut temp); 760 761 let fresh5 = &mut ihv[0]; 762 *fresh5 = fresh5.wrapping_add(a); 763 let fresh6 = &mut ihv[1]; 764 *fresh6 = fresh6.wrapping_add(b); 765 let fresh7 = &mut ihv[2]; 766 *fresh7 = fresh7.wrapping_add(c); 767 let fresh8 = &mut ihv[3]; 768 *fresh8 = fresh8.wrapping_add(d); ``` -------------------------------- ### SHA-1 compression round step functions (hashclash_sha1compress_round*_step) Source: https://docs.rs/sha1collisiondetection/latest/src/sha1collisiondetection/sha1.rs.html?search=std%3A%3Avec These inline functions implement the SHA-1 compression round steps used by the sha1collisiondetection crate. Each forward step updates e with a wrapping add of the rotated a, the round-specific f function, a constant, and the message word, then rotates b left by 30; each backward step rotates b right by 30 first and subtracts the same expression from e. The constants 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, and 0xca62c1d6 correspond to rounds 1 through 4 respectively. ```rust fn hashclash_sha1compress_round3_step(a: uint32_t, b: &mut uint32_t, c: uint32_t, d: uint32_t, e: &mut uint32_t, m: &[uint32_t; 80], t: usize) { *e = e.wrapping_add(rotate_left(a, 5).wrapping_add(sha1_f3(*b, c, d)).wrapping_add(0x8f1bbcdc).wrapping_add(m[t])); *b = rotate_left(*b, 30); } ``` ```rust fn hashclash_sha1compress_round4_step(a: uint32_t, b: &mut uint32_t, c: uint32_t, d: uint32_t, e: &mut uint32_t, m: &[uint32_t; 80], t: usize) { *e = e.wrapping_add(rotate_left(a, 5).wrapping_add(sha1_f4(*b, c, d)).wrapping_add(0xca62c1d6).wrapping_add(m[t])); *b = rotate_left(*b, 30); } ``` ```rust fn hashclash_sha1compress_round1_step_bw(a: uint32_t, b: &mut uint32_t, c: uint32_t, d: uint32_t, e: &mut uint32_t, m: &[uint32_t; 80], t: usize) { *b = rotate_right(*b, 30); *e = e.wrapping_sub(rotate_left(a, 5).wrapping_add(sha1_f1(*b, c, d)).wrapping_add(0x5a827999).wrapping_add(m[t])); } ``` ```rust fn hashclash_sha1compress_round2_step_bw(a: uint32_t, b: &mut uint32_t, c: uint32_t, d: uint32_t, e: &mut uint32_t, m: &[uint32_t; 80], t: usize) { *b = rotate_right(*b, 30); *e = e.wrapping_sub(rotate_left(a, 5).wrapping_add(sha1_f2(*b, c, d)).wrapping_add(0x6ed9eba1).wrapping_add(m[t])); } ``` ```rust fn hashclash_sha1compress_round3_step_bw(a: uint32_t, b: &mut uint32_t, c: uint32_t, d: uint32_t, e: &mut uint32_t, m: &[uint32_t; 80], t: usize) { *b = rotate_right(*b, 30); *e = e.wrapping_sub(rotate_left(a, 5).wrapping_add(sha1_f3(*b, c, d)).wrapping_add(0x8f1bbcdc).wrapping_add(m[t])); } ``` ```rust fn hashclash_sha1compress_round4_step_bw(a: uint32_t, b: &mut uint32_t, c: uint32_t, d: uint32_t, e: &mut uint32_t, m: &[uint32_t; 80], t: usize) { *b = rotate_right(*b, 30); *e = e.wrapping_sub(rotate_left(a, 5).wrapping_add(sha1_f4(*b, c, d)).wrapping_add(0xca62c1d6).wrapping_add(m[t])); } ``` -------------------------------- ### SHA-1 Recompression Fast 65 with Backward Step Macros Source: https://docs.rs/sha1collisiondetection/latest/src/sha1collisiondetection/sha1.rs.html?search=u32+-%3E+bool Defines sha1recompress_fast_65, which recompresses the last 65 steps of SHA-1 in reverse order using backward step macros (hashclash_sha1compress_round4_step_bw and hashclash_sha1compress_round3_step_bw). It initializes working variables from the state array and processes message schedule words from index 64 down to 45. ```rust fn sha1recompress_fast_65(ihvin: &mut [uint32_t; 5], ihvout: &mut [uint32_t; 5], me2: &[uint32_t; 80], state: &[uint32_t; 5]) { let mut a: uint32_t = state[0]; let mut b: uint32_t = state[1]; let mut c: uint32_t = state[2]; let mut d: uint32_t = state[3]; let mut e: uint32_t = state[4]; hashclash_sha1compress_round4_step_bw(b, &mut c, d, e, &mut a, me2, 64); hashclash_sha1compress_round4_step_bw(c, &mut d, e, a, &mut b, me2, 63); hashclash_sha1compress_round4_step_bw(d, &mut e, a, b, &mut c, me2, 62); hashclash_sha1compress_round4_step_bw(e, &mut a, b, c, &mut d, me2, 61); hashclash_sha1compress_round4_step_bw(a, &mut b, c, d, &mut e, me2, 60); hashclash_sha1compress_round3_step_bw(b, &mut c, d, e, &mut a, me2, 59); hashclash_sha1compress_round3_step_bw(c, &mut d, e, a, &mut b, me2, 58); hashclash_sha1compress_round3_step_bw(d, &mut e, a, b, &mut c, me2, 57); hashclash_sha1compress_round3_step_bw(e, &mut a, b, c, &mut d, me2, 56); hashclash_sha1compress_round3_step_bw(a, &mut b, c, d, &mut e, me2, 55); hashclash_sha1compress_round3_step_bw(b, &mut c, d, e, &mut a, me2, 54); hashclash_sha1compress_round3_step_bw(c, &mut d, e, a, &mut b, me2, 53); hashclash_sha1compress_round3_step_bw(d, &mut e, a, b, &mut c, me2, 52); hashclash_sha1compress_round3_step_bw(e, &mut a, b, c, &mut d, me2, 51); hashclash_sha1compress_round3_step_bw(a, &mut b, c, d, &mut e, me2, 50); hashclash_sha1compress_round3_step_bw(b, &mut c, d, e, &mut a, me2, 49); hashclash_sha1compress_round3_step_bw(c, &mut d, e, a, &mut b, me2, 48); hashclash_sha1compress_round3_step_bw(d, &mut e, a, b, &mut c, me2, 47); hashclash_sha1compress_round3_step_bw(e, &mut a, b, c, &mut d, me2, 46); hashclash_sha1compress_round3_step_bw(a, &mut b, c, d, &mut e, me2, 45); } ``` -------------------------------- ### Sha1CD::fmt Source: https://docs.rs/sha1collisiondetection/latest/sha1collisiondetection/struct.Sha1CD.html?search=std%3A%3Avec Formats the value using the given formatter. ```APIDOC ## Sha1CD::fmt ### Description Formats the value using the given formatter. ### Method fmt ### Signature fn fmt(&self, f: &mut Formatter<'_>) -> Result ### Parameters - **f** (&mut Formatter<'_>) - The formatter to use. ### Returns - **Result** - The formatting result. ``` -------------------------------- ### impl Write for Sha1CD Source: https://docs.rs/sha1collisiondetection/latest/sha1collisiondetection/struct.Sha1CD.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides write functionality for Sha1CD. Available on crate feature `std` only. ```APIDOC ## impl Write for Sha1CD ### Description Provides write functionality for Sha1CD. Available on crate feature `std` only. ### Methods - **write(&mut self, buf: &[u8]) -> Result** - Writes a buffer into this writer, returning how many bytes were written. - **flush(&mut self) -> Result<()>** - Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. - **write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result** - Like `write`, except that it writes from a slice of buffers. - **is_write_vectored(&self) -> bool** - Determines if this `Write`r has an efficient `write_vectored` implementation. - **write_all(&mut self, buf: &[u8]) -> Result<(), Error>** - Attempts to write an entire buffer into this writer. - **write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>** - Attempts to write multiple buffers into this writer. - **write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>** - Writes a formatted string into this writer, returning any error encountered. - **by_ref(&mut self) -> &mut Self** where Self: Sized - Creates a “by reference” adapter for this instance of `Write`. ```