ex_crypto_shake256.rs

Hash with SHAKE256. Host cryptography with explicit security boundaries.

ExSDK source-ownedRustCrypto

Source

Example

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