Module chksum_hash_sha2_384::state
source · Expand description
Module contains items related to the State
structure which allows to the direct MD5 state manipulation.
§Example
use chksum_hash_sha2_384 as sha2_384;
// Create new state
let mut state = sha2_384::state::default();
// By default it returns initialization values
assert_eq!(
state.digest(),
[
0xCBBB9D5DC1059ED8,
0x629A292A367CD507,
0x9159015A3070DD17,
0x152FECD8F70E5939,
0x67332667FFC00B31,
0x8EB44A8768581511,
]
);
// Manually create block of data with proper padding
let data = [
u64::from_be_bytes([0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
u64::from_be_bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
// ...
u64::from_be_bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
];
// Update state and own new value
state = state.update(data);
// Proper digest of empty input
assert_eq!(
state.digest(),
[
0x38B060A751AC9638,
0x4CD9327EB1B1E36A,
0x21FDB71114BE0743,
0x4C0CC7BF63F6E1DA,
0x274EDEBFE76F65FB,
0xD51AD2F14898B95B,
]
);
// Reset state to initial values
state = state.reset();
assert_eq!(
state.digest(),
[
0xCBBB9D5DC1059ED8,
0x629A292A367CD507,
0x9159015A3070DD17,
0x152FECD8F70E5939,
0x67332667FFC00B31,
0x8EB44A8768581511,
]
);
§Warning
The State
structure does not modify internal state, each function returns a new state that must be used.
Structs§
- A low-level hash state.
Functions§
- Creates a default state.
- Create a new state.