Move sha512_256 code

Make the `sha512_256` module use similar code layout to the other hash
modules by putting the call to `hash_type` at the top followed by the
`from_engine` function.

Code move only, no other changes.
This commit is contained in:
Tobin C. Harding 2023-11-03 10:35:56 +11:00
parent 071208ccdd
commit 0bb537d45b
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 13 additions and 13 deletions

View File

@ -13,6 +13,19 @@ use core::str;
use crate::{sha512, FromSliceError}; use crate::{sha512, FromSliceError};
crate::internal_macros::hash_type! {
256,
false,
"Output of the SHA512/256 hash function.\n\nSHA512/256 is a hash function that uses the sha512 alogrithm but it truncates the output to 256 bits. It has different initial constants than sha512 so it produces an entirely different hash compared to sha512. More information at <https://eprint.iacr.org/2010/548.pdf>. ",
"crate::util::json_hex_string::len_32"
}
fn from_engine(e: HashEngine) -> Hash {
let mut ret = [0; 32];
ret.copy_from_slice(&sha512::from_engine(e.0)[..32]);
Hash(ret)
}
/// Engine to compute SHA512/256 hash function. /// Engine to compute SHA512/256 hash function.
/// ///
/// SHA512/256 is a hash function that uses the sha512 alogrithm but it truncates /// SHA512/256 is a hash function that uses the sha512 alogrithm but it truncates
@ -41,19 +54,6 @@ impl crate::HashEngine for HashEngine {
fn input(&mut self, inp: &[u8]) { self.0.input(inp); } fn input(&mut self, inp: &[u8]) { self.0.input(inp); }
} }
crate::internal_macros::hash_type! {
256,
false,
"Output of the SHA512/256 hash function.\n\nSHA512/256 is a hash function that uses the sha512 alogrithm but it truncates the output to 256 bits. It has different initial constants than sha512 so it produces an entirely different hash compared to sha512. More information at <https://eprint.iacr.org/2010/548.pdf>. ",
"crate::util::json_hex_string::len_32"
}
fn from_engine(e: HashEngine) -> Hash {
let mut ret = [0; 32];
ret.copy_from_slice(&sha512::from_engine(e.0)[..32]);
Hash(ret)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[test] #[test]