Skip to main content

bench_keccak/
lib.rs

1//! Keccak-256 hashing benchmark.
2
3#![cfg_attr(target_os = "none", no_std)]
4
5use subsoil as _;
6
7use sha3::{Digest, Keccak256};
8
9const MSG_LEN: usize = 1024;
10
11/// Keccak-256 of 1KB message. Returns first 4 bytes of hash as u32.
12pub fn keccak_bench() -> u32 {
13    let mut msg = [0u8; MSG_LEN];
14    let mut i: usize = 0;
15    while i < MSG_LEN {
16        msg[i] = (i & 0xFF) as u8;
17        i += 1;
18    }
19
20    let mut hasher = Keccak256::new();
21    hasher.update(msg);
22    let result = hasher.finalize();
23    u32::from_le_bytes([result[0], result[1], result[2], result[3]])
24}