From 3a07f50dabbda0532b9e87d76662d81a4740fe40 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 20 Apr 2026 12:14:38 +0200 Subject: [PATCH] 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. --- lib/std/crypto/ml_kem.zig | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/std/crypto/ml_kem.zig b/lib/std/crypto/ml_kem.zig index 468be166d0..ea75d6ec8f 100644 --- 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).