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 a7431da commit afdbfb0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sha2/src/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 afdbfb0

Please sign in to comment.