Skip to content

Commit

Permalink
0101
Browse files Browse the repository at this point in the history
  • Loading branch information
Wel15 committed Jan 1, 2025
1 parent 3da3c59 commit bf21774
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ pub(crate) fn sbox_inplace(val: &mut U256) {

unsafe {
let ptr = a.as_mut_ptr();
// 使用SP1的memcpy
// SP1 memcpy
memory_local_event_to_row_babybear(
&MemoryLocalEvent::new(val, ptr),
&mut SingleMemoryLocal::new()
);

// 使用SP1的uint256乘法
// SP1 uint256
for _ in 0..4 {
uint256_mul(ptr, val);
}

// 拷贝回结果
//
memory_local_event_to_row_babybear(
&MemoryLocalEvent::new(ptr, val),
&mut SingleMemoryLocal::new()
Expand All @@ -31,7 +31,7 @@ pub(crate) fn fill_state(state: &mut MaybeUninit<State>, val: &U256) {
let ptr = state.as_mut_ptr() as *mut U256;
for i in 0..T {
unsafe {
// 使用SP1的memcpy

memory_local_event_to_row_babybear(
&MemoryLocalEvent::new(val, ptr.add(i)),
&mut SingleMemoryLocal::new()
Expand All @@ -43,7 +43,7 @@ pub(crate) fn fill_state(state: &mut MaybeUninit<State>, val: &U256) {
#[inline(always)]
pub(crate) fn set_state(state: &mut State, new_state: &State) {
unsafe {
// 使用SP1的memcpy

for i in 0..3 {
memory_local_event_to_row_babybear(
&MemoryLocalEvent::new(&new_state[i], &mut state[i]),
Expand All @@ -64,15 +64,15 @@ pub(crate) fn init_state_with_cap_and_msg<'a>(
unsafe {
let ptr = state.as_mut_ptr() as *mut U256;

// 拷贝cap

memory_local_event_to_row_babybear(
&MemoryLocalEvent::new(cap, ptr),
&mut SingleMemoryLocal::new()
);

match msg.len() {
0 => {
// 拷贝两个零

memory_local_event_to_row_babybear(
&MemoryLocalEvent::new(
&ZERO_TWO,
Expand All @@ -82,7 +82,7 @@ pub(crate) fn init_state_with_cap_and_msg<'a>(
);
}
1 => {
// 拷贝一个消息和一个零

memory_local_event_to_row_babybear(
&MemoryLocalEvent::new(msg.as_ptr(), ptr.add(1)),
&mut SingleMemoryLocal::new()
Expand All @@ -93,7 +93,7 @@ pub(crate) fn init_state_with_cap_and_msg<'a>(
);
}
_ => {
// 拷贝两个消息

memory_local_event_to_row_babybear(
&MemoryLocalEvent::new(
msg.as_ptr(),
Expand All @@ -110,7 +110,7 @@ pub(crate) fn init_state_with_cap_and_msg<'a>(
#[inline(always)]
pub(crate) fn mul_add_assign(dst: &mut U256, a: &U256, b: &U256) {
unsafe {
// 使用SP1的uint256乘法和加法

let tmp = uint256_mul(a, b);
*dst = uint256_add(*dst, tmp);
}
Expand Down

0 comments on commit bf21774

Please sign in to comment.