core/crypto/_sha3: Fix edge case in cSHAKE bytepad

If the domain separator happens to be exactly the rate, we would
previously incorrectly add another rate-bytes of 0s.
This commit is contained in:
Yawning Angel
2024-09-30 21:50:18 +09:00
parent a7d7c92a53
commit cf7d705c1f
2 changed files with 25 additions and 6 deletions
+8 -6
View File
@@ -81,16 +81,18 @@ bytepad :: proc(ctx: ^Context, x_strings: [][]byte, w: int) {
// 2. while len(z) mod 8 ≠ 0:
// z = z || 0
// 3. while (len(z)/8) mod w 0:
// 3. while (len(z)/8) mod w != 0:
// z = z || 00000000
z_len := u128(z_hi) << 64 | u128(z_lo)
z_rem := int(z_len % u128(w))
pad := _PAD[:w - z_rem]
if z_rem != 0 {
pad := _PAD[:w - z_rem]
// We just add the padding to the state, instead of returning z.
//
// 4. return z.
update(ctx, pad)
// We just add the padding to the state, instead of returning z.
//
// 4. return z.
update(ctx, pad)
}
}
encode_string :: #force_inline proc(ctx: ^Context, s: []byte) -> (u64, u64) {