authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-04-20 12:14:38+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-20 18:27:22+02:00
log3a07f50dabbda0532b9e87d76662d81a4740fe40
tree51172b0f9080548d00b85d1f1b320a67a6cb2ee5
parent858d7eda6550ebb80e96c92b82c2e17ca5107b29

std.crypto.ml_kem tests: simplify incV

We don't need to reimplement 16-byte subtraction, just use a u128. As a bonus, that handles the theoretical case of an all-0xff value properly.

1 files changed, 2 insertions(+), 9 deletions(-)

lib/std/crypto/ml_kem.zig+2-9
...@@ -1725,15 +1725,8 @@ const NistDRBG = struct {...@@ -1725,15 +1725,8 @@ const NistDRBG = struct {
1725 v: [16]u8,1725 v: [16]u8,
17261726
1727 fn incV(g: *NistDRBG) void {1727 fn incV(g: *NistDRBG) void {
1728 var j: usize = 15;1728 const val = std.mem.readInt(u128, &g.v, .big);
1729 while (j >= 0) : (j -= 1) {1729 std.mem.writeInt(u128, &g.v, val +% 1, .big);
1730 if (g.v[j] == 255) {
1731 g.v[j] = 0;
1732 } else {
1733 g.v[j] += 1;
1734 break;
1735 }
1736 }
1737 }1730 }
17381731
1739 // AES256_CTR_DRBG_Update(pd, &g.key, &g.v).1732 // AES256_CTR_DRBG_Update(pd, &g.key, &g.v).