ex_crypto_shake256.rs
Hash with SHAKE256. Host cryptography with explicit security boundaries.
ExSDK source-ownedRustCrypto
Source
Crypto · CPU cryptography
Example
1use oa::{Engine, Matrix, cryptography};23fn main() -> oa::Result<()> {4 let engine = Engine::new()?;56 // 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)?;1011 let digests = cryptography::hash::shake256(&messages, 32)?;1213 // Verify GPU digests match the independent CPU reference.14 let gpu = digests.read::<u8>()?;15 let cpu: Vec<u8> = rows16 .iter()17 .flat_map(|row| {18 let mut digest = [0u8; 32];19 cryptography::shake256(row, &mut digest);20 digest21 })22 .collect();23 assert_eq!(gpu, cpu);2425 println!("3 GPU SHAKE-256 digests match the CPU oracle");26 Ok(())27}28