diff --git a/rust/cryptest/Cargo.toml b/rust/cryptest/Cargo.toml index f7613d3..5dce981 100644 --- a/rust/cryptest/Cargo.toml +++ b/rust/cryptest/Cargo.toml @@ -10,3 +10,4 @@ k210-shared = { path = "../k210-shared" } riscv = "0.5" riscv-rt = "0.6" hex-literal = "0.2" +sha2 = { version = "0.8", default-features = false } diff --git a/rust/cryptest/src/main.rs b/rust/cryptest/src/main.rs index c12ee75..fb4e382 100644 --- a/rust/cryptest/src/main.rs +++ b/rust/cryptest/src/main.rs @@ -16,6 +16,7 @@ use k210_shared::soc::sha256::SHA256Ctx; use k210_shared::timing::clock; use riscv::asm; use riscv_rt::entry; +use sha2::{Sha256, Digest}; struct AESTestVec { cipher_mode: cipher_mode, @@ -567,6 +568,22 @@ fn main() -> ! { } write!(stdout, " ({} kB/s)", (size as u64) * 1_000 / (time_end - time_start)).unwrap(); writeln!(stdout).unwrap(); + + // Software + write!(stdout, "SHA256 sw ({} bytes): ", size).unwrap(); + let time_start = clock(); + let mut hasher = Sha256::new(); + for _ in 0..65_535 { + hasher.input(&s[..]); + } + let time_end = clock(); + if hasher.result()[..] == expected { + write!(stdout, "MATCH").unwrap(); + } else { + write!(stdout, "MISMATCH").unwrap(); + } + write!(stdout, " ({} kB/s)", (size as u64) * 1_000 / (time_end - time_start)).unwrap(); + writeln!(stdout).unwrap(); } loop {