commit 3a07f50dabbda0532b9e87d76662d81a4740fe40 (tree)
parent 858d7eda6550ebb80e96c92b82c2e17ca5107b29
Author: Frank Denis <github@pureftpd.org>
Date: Mon, 20 Apr 2026 12:14:38 +0200
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.
Diffstat:
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/lib/std/crypto/ml_kem.zig b/lib/std/crypto/ml_kem.zig
@@ -1725,15 +1725,8 @@ const NistDRBG = struct {
v: [16]u8,
fn incV(g: *NistDRBG) void {
- var j: usize = 15;
- while (j >= 0) : (j -= 1) {
- if (g.v[j] == 255) {
- g.v[j] = 0;
- } else {
- g.v[j] += 1;
- break;
- }
- }
+ const val = std.mem.readInt(u128, &g.v, .big);
+ std.mem.writeInt(u128, &g.v, val +% 1, .big);
}
// AES256_CTR_DRBG_Update(pd, &g.key, &g.v).