Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizations #136

Merged
merged 16 commits into from
Aug 29, 2024
12 changes: 8 additions & 4 deletions src/common/blake2s.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,23 @@ fn get_sigma(r: u32) -> Array<u32> {
}

fn rotr16(n: u32) -> u32 {
n / 65536 + (n % 65536) * 65536
let (high, low) = DivRem::div_rem(n, 65536);
high + (low % 65536) * 65536

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The % shouldn't be needed

}

fn rotr12(n: u32) -> u32 {
n / 4096 + (n % 4096) * 1048576
let (high, low) = DivRem::div_rem(n, 4096);
high + low * 1048576
}

fn rotr8(n: u32) -> u32 {
n / 256 + (n % 256) * 16777216
let (high, low) = DivRem::div_rem(n, 256);
high + low * 16777216
}

fn rotr7(n: u32) -> u32 {
n / 128 + (n % 128) * 33554432
let (high, low) = DivRem::div_rem(n, 128);
high + low * 33554432
}

#[derive(Drop, Clone)]
Expand Down
13 changes: 9 additions & 4 deletions src/common/blake2s_u8.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,26 @@ fn get_sigma(r: u32) -> Array<u32> {
}

fn rotr16(n: u32) -> u32 {
n / 65536 + (n % 65536) * 65536
let (high, low) = DivRem::div_rem(n, 65536);
high + (low % 65536) * 65536

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The % shouldn't be needed

}

fn rotr12(n: u32) -> u32 {
n / 4096 + (n % 4096) * 1048576
let (high, low) = DivRem::div_rem(n, 4096);
high + low * 1048576
}

fn rotr8(n: u32) -> u32 {
n / 256 + (n % 256) * 16777216
let (high, low) = DivRem::div_rem(n, 256);
high + low * 16777216
}

fn rotr7(n: u32) -> u32 {
n / 128 + (n % 128) * 33554432
let (high, low) = DivRem::div_rem(n, 128);
high + low * 33554432
}


#[derive(Drop, Clone)]
struct blake2s_state {
h: Array<u32>, // length: 8
Expand Down