pub const BLOCK_SIZE: usize = 64;
pub const STATE_WORDS: usize = 4;
#[inline]
pub fn transform(state: &mut [u32; STATE_WORDS], block: &[u8; BLOCK_SIZE]) {
#[cfg(target_arch = "x86_64")]
super::single_x86::transform(state, block);
#[cfg(target_arch = "aarch64")]
super::single_aarch::transform(state, block);
#[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))]
{
let _ = (state, block);
unreachable!("single_stream::transform is only built for x86_64/aarch64 opt");
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::frame::hash_with;
use alloc::vec::Vec;
#[test]
fn rfc_vectors_via_single_opt() {
let vectors: &[(&[u8], &str)] = &[
(b"", "d41d8cd98f00b204e9800998ecf8427e"),
(b"abc", "900150983cd24fb0d6963f7d28e17f72"),
(
b"abcdefghijklmnopqrstuvwxyz",
"c3fcd3d76192e4007dfb496cca67e13b",
),
];
for (input, want) in vectors {
assert_eq!(&crate::md5::hex_encode(&hash_with(input, transform)), want);
}
}
#[test]
fn matches_in_tree_oracle() {
for len in [0usize, 1, 55, 56, 64, 65, 128, 1024] {
let data: Vec<u8> = (0..len).map(|i| (i as u8).wrapping_mul(31)).collect();
assert_eq!(
hash_with(&data, transform),
crate::backend::hash_in_tree(&data),
"len={len}"
);
}
}
}