Merge rust-bitcoin/rust-bitcoin#2166: Move `sha512_256` code
0bb537d45b
Move sha512_256 code (Tobin C. Harding) Pull request description: 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. ACKs for top commit: Kixunil: ACK0bb537d45b
apoelstra: ACK0bb537d45b
Tree-SHA512: 1b2471782b6aa39c6feb4ac3e7a899d13a12f621e1260365737f56511d7c4dd54bbe47695829a11cc4756ca4a5bf720f5d909632ff2598a6139e7bbc99f64e25
This commit is contained in:
commit
1cf5bd2e93
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue