crate::ix!();
#[inline]
pub unsafe fn sha256_initialize(s: *mut u32) {
const IV: [u32; 8] = [
0x6a09e667,
0xbb67ae85,
0x3c6ef372,
0xa54ff53a,
0x510e527f,
0x9b05688c,
0x1f83d9ab,
0x5be0cd19,
];
for (i, &word) in IV.iter().enumerate() {
*s.add(i) = word;
}
}
#[cfg(test)]
mod sha256_initialisation_tests {
use super::*;
const IV: [u32; 8] = [
0x6a09e667,
0xbb67ae85,
0x3c6ef372,
0xa54ff53a,
0x510e527f,
0x9b05688c,
0x1f83d9ab,
0x5be0cd19,
];
#[traced_test]
fn default_constructor_sets_iv_and_zeros() {
let ctx = Sha256::default();
assert_eq!(*ctx.s(), IV, "state words do not match FIPS 180‑4 IV");
assert!(ctx.buf().iter().all(|&b| b == 0), "buffer not zero‑initialised");
assert_eq!(*ctx.bytes(), 0, "byte counter not initialised to zero");
}
#[traced_test]
fn pointer_initialiser_writes_correct_values() {
let mut state = [0u32; 8];
unsafe { sha256_initialize(state.as_mut_ptr()) };
assert_eq!(state, IV, "sha256_initialize did not write canonical IV");
}
}