Skip to content

Commit 46b6aee

Browse files
committed
feat: optimize constraint counts in sha256/sha512
1 parent c5a6229 commit 46b6aee

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

noir_stdlib/src/sha256.nr

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
// Auxiliary mappings; names as in FIPS PUB 180-4
66
fn rotr32(a: u32, b: u32) -> u32 // 32-bit right rotation
77
{
8-
(a >> b) | (a << (32 as u32 - b))
8+
// None of the bits overlap between `(a >> b)` and `(a << (32 - b))`
9+
// Addition is then equivalent to OR, with fewer constraints.
10+
(a >> b) + (a << (32 as u32 - b))
911
}
1012

1113
fn ch(x: u32, y: u32, z: u32) -> u32

noir_stdlib/src/sha512.nr

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
// Auxiliary mappings; names as in FIPS PUB 180-4
66
fn rotr64(a: u64, b: u64) -> u64 // 64-bit right rotation
77
{
8-
(a >> b) | (a << (64 - b))
8+
// None of the bits overlap between `(a >> b)` and `(a << (64 - b))`
9+
// Addition is then equivalent to OR, with fewer constraints.
10+
(a >> b) + (a << (64 - b))
911
}
1012

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

0 commit comments

Comments
 (0)