keccak.rs
1 // Copyright (c) 2025-2026 ACDC Network 2 // This file is part of the alphavm library. 3 // 4 // Alpha Chain | Delta Chain Protocol 5 // International Monetary Graphite. 6 // 7 // Derived from Aleo (https://aleo.org) and ProvableHQ (https://provable.com). 8 // They built world-class ZK infrastructure. We installed the EASY button. 9 // Their cryptography: elegant. Our modifications: bureaucracy-compatible. 10 // Original brilliance: theirs. Robert's Rules: ours. Bugs: definitely ours. 11 // 12 // Original Aleo/ProvableHQ code subject to Apache 2.0 https://www.apache.org/licenses/LICENSE-2.0 13 // All modifications and new work: CC0 1.0 Universal Public Domain Dedication. 14 // No rights reserved. No permission required. No warranty. No refunds. 15 // 16 // https://creativecommons.org/publicdomain/zero/1.0/ 17 // SPDX-License-Identifier: CC0-1.0 18 19 #[macro_use] 20 extern crate criterion; 21 22 use alphavm_console_algorithms::{Keccak256, Keccak384, Keccak512}; 23 use alphavm_console_types::prelude::*; 24 use alphavm_utilities::{TestRng, Uniform}; 25 26 use criterion::Criterion; 27 28 fn keccak256(c: &mut Criterion) { 29 let rng = &mut TestRng::default(); 30 let hash = Keccak256::default(); 31 32 let input = (0..256).map(|_| bool::rand(rng)).collect::<Vec<_>>(); 33 c.bench_function(&format!("Keccak256 Hash - input size {}", input.len()), |b| b.iter(|| hash.hash(&input))); 34 } 35 36 fn keccak384(c: &mut Criterion) { 37 let rng = &mut TestRng::default(); 38 let hash = Keccak384::default(); 39 40 let input = (0..256).map(|_| bool::rand(rng)).collect::<Vec<_>>(); 41 c.bench_function(&format!("Keccak384 Hash - input size {}", input.len()), |b| b.iter(|| hash.hash(&input))); 42 } 43 44 fn keccak512(c: &mut Criterion) { 45 let rng = &mut TestRng::default(); 46 let hash = Keccak512::default(); 47 48 let input = (0..256).map(|_| bool::rand(rng)).collect::<Vec<_>>(); 49 c.bench_function(&format!("Keccak512 Hash - input size {}", input.len()), |b| b.iter(|| hash.hash(&input))); 50 } 51 52 criterion_group! { 53 name = keccak; 54 config = Criterion::default().sample_size(1000); 55 targets = keccak256, keccak384, keccak512 56 } 57 58 criterion_main!(keccak);