authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2022-12-23 22:38:27+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-12-23 21:38:27+00:00
logc9e3524d0b12e11488519bb377e7dcf60047963a
tree5b6bfd9dca072cf3da4b9790499341d68f047d71
parent581d292381157464ae6f2c88c8a628314f005742
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

HKDF allow expansion up to, and including <hash size> * 255 bytes (#14051)

Fixes #14050

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

lib/std/crypto/hkdf.zig+3-2
......@@ -22,7 +22,7 @@ pub fn Hkdf(comptime Hmac: type) type {
2222
2323 /// Derive a subkey from a master key `prk` and a subkey description `ctx`.
2424 pub fn expand(out: []u8, ctx: []const u8, prk: [Hmac.mac_length]u8) void {
25 assert(out.len < Hmac.mac_length * 255); // output size is too large for the Hkdf construction
25 assert(out.len <= Hmac.mac_length * 255); // output size is too large for the Hkdf construction
2626 var i: usize = 0;
2727 var counter = [1]u8{1};
2828 while (i + Hmac.mac_length <= out.len) : (i += Hmac.mac_length) {
......@@ -33,7 +33,8 @@ pub fn Hkdf(comptime Hmac: type) type {
3333 st.update(ctx);
3434 st.update(&counter);
3535 st.final(out[i..][0..Hmac.mac_length]);
36 counter[0] += 1;
36 counter[0] +%= 1;
37 assert(counter[0] != 1);
3738 }
3839 const left = out.len % Hmac.mac_length;
3940 if (left > 0) {