Skip to content

Commit

Permalink
feat(stdlib): optimize constraint counts in sha256/sha512 (#3253)
Browse files Browse the repository at this point in the history
Co-authored-by: jfecher <[email protected]>
  • Loading branch information
TomAFrench and jfecher authored Oct 23, 2023
1 parent 247b7ce commit d3be552
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
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

0 comments on commit d3be552

Please sign in to comment.