Skip to content

Commit

Permalink
feat: patch
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Jun 10, 2024
1 parent 28a7b0d commit 1f22438
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sha2/src/sha256.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use digest::{generic_array::GenericArray, typenum::U64};

cfg_if::cfg_if! {
if #[cfg(feature = "force-soft")] {
if #[cfg(all(target_os = "zkvm", target_vendor = "succinct", target_arch = "riscv32"))] {
mod succinct;
use succinct::compress;
} else if #[cfg(feature = "force-soft")] {
mod soft;
use soft::compress;
} else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
Expand Down
23 changes: 23 additions & 0 deletions sha2/src/sha256/succinct.rs
Original file line number Diff line number Diff line change
@@ -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());
}
}
}

0 comments on commit 1f22438

Please sign in to comment.