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

feat(stdlib): optimize constraint counts in sha256/sha512 #3253

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion noir_stdlib/src/sha256.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// Auxiliary mappings; names as in FIPS PUB 180-4
fn rotr32(a: u32, b: u32) -> u32 // 32-bit right rotation
{
(a >> b) | (a << (32 as u32 - b))
// None of the bits overlap between `(a >> b)` and `(a << (32 - b))`
// Addition is then equivalent to OR, with fewer constraints.
(a >> b) + (a << (32 - b))
}

fn ch(x: u32, y: u32, z: u32) -> u32
Expand Down
4 changes: 3 additions & 1 deletion noir_stdlib/src/sha512.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// Auxiliary mappings; names as in FIPS PUB 180-4
fn rotr64(a: u64, b: u64) -> u64 // 64-bit right rotation
{
(a >> b) | (a << (64 - b))
// None of the bits overlap between `(a >> b)` and `(a << (64 - b))`
// Addition is then equivalent to OR, with fewer constraints.
(a >> b) + (a << (64 - b))
}

fn sha_ch(x: u64, y: u64, z: u64) -> u64
Expand Down