diff --git a/sha2/src/sha256.rs b/sha2/src/sha256.rs index 5e5909657..49d105f57 100644 --- a/sha2/src/sha256.rs +++ b/sha2/src/sha256.rs @@ -157,6 +157,9 @@ cfg_if::cfg_if! { mod soft; mod aarch64; use aarch64::compress; + } else if #[cfg(all(target_os = "zkvm", target_vendor = "succinct", target_arch = "riscv32"))] { + mod succinct; + use succinct::compress; } else { mod soft; use soft::compress; diff --git a/sha2/src/sha256/succinct.rs b/sha2/src/sha256/succinct.rs new file mode 100644 index 000000000..ca58cab14 --- /dev/null +++ b/sha2/src/sha256/succinct.rs @@ -0,0 +1,23 @@ +extern "C" { + fn syscall_sha256_extend(w: *mut u32); + fn syscall_sha256_compress(w: *mut u32, state: *mut u32); +} + +#[inline] +pub fn compress(state: &mut [u32; 8], blocks: &[[u8; 64]]) { + unsafe { + for i in 0..blocks.len() { + let mut w = [0u32; 64]; + for j in 0..16 { + w[j] = u32::from_be_bytes([ + blocks[i][j * 4], + blocks[i][j * 4 + 1], + blocks[i][j * 4 + 2], + blocks[i][j * 4 + 3], + ]); + } + syscall_sha256_extend(w.as_mut_ptr()); + syscall_sha256_compress(w.as_mut_ptr(), state.as_mut_ptr()); + } + } +}