hashes: reformat
Essentially this just adds indentation after the previous commit.
This commit is contained in:
parent
aadd7df266
commit
0aeff359f5
|
@ -15,17 +15,16 @@ crate::internal_macros::general_hash_type! {
|
||||||
"Output of the Bitcoin HASH160 hash function. (RIPEMD160(SHA256))"
|
"Output of the Bitcoin HASH160 hash function. (RIPEMD160(SHA256))"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Hash {
|
impl Hash {
|
||||||
/// Finalize a hash engine to produce a hash.
|
/// Finalize a hash engine to produce a hash.
|
||||||
pub fn from_engine(e: HashEngine) -> Self {
|
pub fn from_engine(e: HashEngine) -> Self {
|
||||||
let sha2 = sha256::Hash::from_engine(e.0);
|
let sha2 = sha256::Hash::from_engine(e.0);
|
||||||
let rmd = ripemd160::Hash::hash(sha2.as_byte_array());
|
let rmd = ripemd160::Hash::hash(sha2.as_byte_array());
|
||||||
|
|
||||||
let mut ret = [0; 20];
|
let mut ret = [0; 20];
|
||||||
ret.copy_from_slice(rmd.as_byte_array());
|
ret.copy_from_slice(rmd.as_byte_array());
|
||||||
Hash(ret)
|
Hash(ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Engine to compute HASH160 hash function.
|
/// Engine to compute HASH160 hash function.
|
||||||
|
|
|
@ -20,11 +20,10 @@ crate::internal_macros::general_hash_type! {
|
||||||
"Output of the RIPEMD160 hash function."
|
"Output of the RIPEMD160 hash function."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Hash {
|
impl Hash {
|
||||||
/// Finalize a hash engine to produce a hash.
|
/// Finalize a hash engine to produce a hash.
|
||||||
#[cfg(not(hashes_fuzz))]
|
#[cfg(not(hashes_fuzz))]
|
||||||
pub fn from_engine(mut e: HashEngine) -> Self {
|
pub fn from_engine(mut e: HashEngine) -> Self {
|
||||||
// pad buffer with a single 1-bit then all 0s, until there are exactly 8 bytes remaining
|
// pad buffer with a single 1-bit then all 0s, until there are exactly 8 bytes remaining
|
||||||
let n_bytes_hashed = e.bytes_hashed;
|
let n_bytes_hashed = e.bytes_hashed;
|
||||||
|
|
||||||
|
@ -41,15 +40,15 @@ pub fn from_engine(mut e: HashEngine) -> Self {
|
||||||
debug_assert_eq!(incomplete_block_len(&e), 0);
|
debug_assert_eq!(incomplete_block_len(&e), 0);
|
||||||
|
|
||||||
Hash(e.midstate())
|
Hash(e.midstate())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finalize a hash engine to produce a hash.
|
/// Finalize a hash engine to produce a hash.
|
||||||
#[cfg(hashes_fuzz)]
|
#[cfg(hashes_fuzz)]
|
||||||
pub fn from_engine(e: HashEngine) -> Self {
|
pub fn from_engine(e: HashEngine) -> Self {
|
||||||
let mut res = e.midstate();
|
let mut res = e.midstate();
|
||||||
res[0] ^= (e.bytes_hashed & 0xff) as u8;
|
res[0] ^= (e.bytes_hashed & 0xff) as u8;
|
||||||
Hash(res)
|
Hash(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const BLOCK_SIZE: usize = 64;
|
const BLOCK_SIZE: usize = 64;
|
||||||
|
|
|
@ -21,8 +21,8 @@ crate::internal_macros::general_hash_type! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash {
|
impl Hash {
|
||||||
/// Finalize a hash engine to produce a hash.
|
/// Finalize a hash engine to produce a hash.
|
||||||
pub fn from_engine(mut e: HashEngine) -> Self {
|
pub fn from_engine(mut e: HashEngine) -> Self {
|
||||||
// pad buffer with a single 1-bit then all 0s, until there are exactly 8 bytes remaining
|
// pad buffer with a single 1-bit then all 0s, until there are exactly 8 bytes remaining
|
||||||
let n_bytes_hashed = e.bytes_hashed;
|
let n_bytes_hashed = e.bytes_hashed;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ pub fn from_engine(mut e: HashEngine) -> Self {
|
||||||
debug_assert_eq!(incomplete_block_len(&e), 0);
|
debug_assert_eq!(incomplete_block_len(&e), 0);
|
||||||
|
|
||||||
Hash(e.midstate())
|
Hash(e.midstate())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const BLOCK_SIZE: usize = 64;
|
const BLOCK_SIZE: usize = 64;
|
||||||
|
|
|
@ -110,9 +110,9 @@ impl crate::HashEngine for HashEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash {
|
impl Hash {
|
||||||
/// Finalize a hash engine to obtain a hash.
|
/// Finalize a hash engine to obtain a hash.
|
||||||
#[cfg(not(hashes_fuzz))]
|
#[cfg(not(hashes_fuzz))]
|
||||||
pub fn from_engine(mut e: HashEngine) -> Self {
|
pub fn from_engine(mut e: HashEngine) -> Self {
|
||||||
// pad buffer with a single 1-bit then all 0s, until there are exactly 8 bytes remaining
|
// pad buffer with a single 1-bit then all 0s, until there are exactly 8 bytes remaining
|
||||||
let n_bytes_hashed = e.bytes_hashed;
|
let n_bytes_hashed = e.bytes_hashed;
|
||||||
|
|
||||||
|
@ -129,11 +129,11 @@ pub fn from_engine(mut e: HashEngine) -> Self {
|
||||||
debug_assert_eq!(incomplete_block_len(&e), 0);
|
debug_assert_eq!(incomplete_block_len(&e), 0);
|
||||||
|
|
||||||
Hash(e.midstate_unchecked().bytes)
|
Hash(e.midstate_unchecked().bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finalize a hash engine to obtain a hash.
|
/// Finalize a hash engine to obtain a hash.
|
||||||
#[cfg(hashes_fuzz)]
|
#[cfg(hashes_fuzz)]
|
||||||
pub fn from_engine(e: HashEngine) -> Self {
|
pub fn from_engine(e: HashEngine) -> Self {
|
||||||
let mut hash = e.midstate_unchecked().bytes;
|
let mut hash = e.midstate_unchecked().bytes;
|
||||||
if hash == [0; 32] {
|
if hash == [0; 32] {
|
||||||
// Assume sha256 is secure and never generate 0-hashes (which represent invalid
|
// Assume sha256 is secure and never generate 0-hashes (which represent invalid
|
||||||
|
@ -141,7 +141,7 @@ pub fn from_engine(e: HashEngine) -> Self {
|
||||||
hash[0] = 1;
|
hash[0] = 1;
|
||||||
}
|
}
|
||||||
Hash(hash)
|
Hash(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate the sha256 algorithm to turn a sha256 hash into a sha256d hash
|
/// Iterate the sha256 algorithm to turn a sha256 hash into a sha256d hash
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|
|
@ -11,15 +11,15 @@ crate::internal_macros::general_hash_type! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash {
|
impl Hash {
|
||||||
/// Finalize a hash engine to produce a hash.
|
/// Finalize a hash engine to produce a hash.
|
||||||
pub fn from_engine(e: HashEngine) -> Self {
|
pub fn from_engine(e: HashEngine) -> Self {
|
||||||
let sha2 = sha256::Hash::from_engine(e.0);
|
let sha2 = sha256::Hash::from_engine(e.0);
|
||||||
let sha2d = sha256::Hash::hash(sha2.as_byte_array());
|
let sha2d = sha256::Hash::hash(sha2.as_byte_array());
|
||||||
|
|
||||||
let mut ret = [0; 32];
|
let mut ret = [0; 32];
|
||||||
ret.copy_from_slice(sha2d.as_byte_array());
|
ret.copy_from_slice(sha2d.as_byte_array());
|
||||||
Hash(ret)
|
Hash(ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Engine to compute SHA256d hash function.
|
/// Engine to compute SHA256d hash function.
|
||||||
|
|
|
@ -11,12 +11,12 @@ crate::internal_macros::general_hash_type! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash {
|
impl Hash {
|
||||||
/// Finalize a hash engine to produce a hash.
|
/// Finalize a hash engine to produce a hash.
|
||||||
pub fn from_engine(e: HashEngine) -> Self {
|
pub fn from_engine(e: HashEngine) -> Self {
|
||||||
let mut ret = [0; 48];
|
let mut ret = [0; 48];
|
||||||
ret.copy_from_slice(&sha512::Hash::from_engine(e.0).as_byte_array()[..48]);
|
ret.copy_from_slice(&sha512::Hash::from_engine(e.0).as_byte_array()[..48]);
|
||||||
Hash(ret)
|
Hash(ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Engine to compute SHA384 hash function.
|
/// Engine to compute SHA384 hash function.
|
||||||
|
|
|
@ -21,9 +21,9 @@ crate::internal_macros::general_hash_type! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash {
|
impl Hash {
|
||||||
/// Finalize a hash engine to produce a hash.
|
/// Finalize a hash engine to produce a hash.
|
||||||
#[cfg(not(hashes_fuzz))]
|
#[cfg(not(hashes_fuzz))]
|
||||||
pub fn from_engine(mut e: HashEngine) -> Self {
|
pub fn from_engine(mut e: HashEngine) -> Self {
|
||||||
// pad buffer with a single 1-bit then all 0s, until there are exactly 16 bytes remaining
|
// pad buffer with a single 1-bit then all 0s, until there are exactly 16 bytes remaining
|
||||||
let n_bytes_hashed = e.bytes_hashed;
|
let n_bytes_hashed = e.bytes_hashed;
|
||||||
|
|
||||||
|
@ -41,15 +41,15 @@ pub fn from_engine(mut e: HashEngine) -> Self {
|
||||||
debug_assert_eq!(incomplete_block_len(&e), 0);
|
debug_assert_eq!(incomplete_block_len(&e), 0);
|
||||||
|
|
||||||
Hash(e.midstate())
|
Hash(e.midstate())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finalize a hash engine to produce a hash.
|
/// Finalize a hash engine to produce a hash.
|
||||||
#[cfg(hashes_fuzz)]
|
#[cfg(hashes_fuzz)]
|
||||||
pub fn from_engine(e: HashEngine) -> Self {
|
pub fn from_engine(e: HashEngine) -> Self {
|
||||||
let mut hash = e.midstate();
|
let mut hash = e.midstate();
|
||||||
hash[0] ^= 0xff; // Make this distinct from SHA-256
|
hash[0] ^= 0xff; // Make this distinct from SHA-256
|
||||||
Hash(hash)
|
Hash(hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) const BLOCK_SIZE: usize = 128;
|
pub(crate) const BLOCK_SIZE: usize = 128;
|
||||||
|
|
|
@ -16,12 +16,12 @@ crate::internal_macros::general_hash_type! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash {
|
impl Hash {
|
||||||
/// Finalize a hash engine to produce a hash.
|
/// Finalize a hash engine to produce a hash.
|
||||||
pub fn from_engine(e: HashEngine) -> Self {
|
pub fn from_engine(e: HashEngine) -> Self {
|
||||||
let mut ret = [0; 32];
|
let mut ret = [0; 32];
|
||||||
ret.copy_from_slice(&sha512::Hash::from_engine(e.0).as_byte_array()[..32]);
|
ret.copy_from_slice(&sha512::Hash::from_engine(e.0).as_byte_array()[..32]);
|
||||||
Hash(ret)
|
Hash(ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Engine to compute SHA512/256 hash function.
|
/// Engine to compute SHA512/256 hash function.
|
||||||
|
|
Loading…
Reference in New Issue