Realm

ex_crypto_shake256.rs

Hash with SHAKE256. Host cryptography with explicit security boundaries.

ExSDK source-ownedRustCrypto

Source

Example

1use oa::{Matrix, crypto};
2
3fn main() -> oa::Result<()> {
4 // Three 5-byte messages packed into a [3, 5] u8 matrix.
5 let rows: &[&[u8]] = &[b"alpha", b"bravo", b"crypt"];
6 let flat: Vec<u8> = rows.iter().flat_map(|r| r.iter().copied()).collect();
7 let messages = Matrix::new_from_slice::<u8>([3, 5], &flat)?;
8
9 let digests = crypto::hash::shake256(&messages, 32)?;
10
11 // Verify GPU digests match the independent CPU reference.
12 let gpu = digests.read::<u8>()?;
13 let cpu: Vec<u8> = rows
14 .iter()
15 .flat_map(|row| {
16 let mut digest = [0u8; 32];
17 crypto::shake256(row, &mut digest);
18 digest
19 })
20 .collect();
21 assert_eq!(gpu, cpu);
22
23 println!("3 GPU SHAKE-256 digests match the CPU oracle");
24 Ok(())
25}
26