| ... | @@ -22,7 +22,7 @@ pub fn Hkdf(comptime Hmac: type) type { | ... | @@ -22,7 +22,7 @@ pub fn Hkdf(comptime Hmac: type) type { |
| 22 | | 22 | |
| 23 | /// Derive a subkey from a master key `prk` and a subkey description `ctx`. | 23 | /// Derive a subkey from a master key `prk` and a subkey description `ctx`. |
| 24 | pub fn expand(out: []u8, ctx: []const u8, prk: [Hmac.mac_length]u8) void { | 24 | 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 |
| 26 | var i: usize = 0; | 26 | var i: usize = 0; |
| 27 | var counter = [1]u8{1}; | 27 | var counter = [1]u8{1}; |
| 28 | while (i + Hmac.mac_length <= out.len) : (i += Hmac.mac_length) { | 28 | while (i + Hmac.mac_length <= out.len) : (i += Hmac.mac_length) { |
| ... | @@ -33,7 +33,8 @@ pub fn Hkdf(comptime Hmac: type) type { | ... | @@ -33,7 +33,8 @@ pub fn Hkdf(comptime Hmac: type) type { |
| 33 | st.update(ctx); | 33 | st.update(ctx); |
| 34 | st.update(&counter); | 34 | st.update(&counter); |
| 35 | st.final(out[i..][0..Hmac.mac_length]); | 35 | st.final(out[i..][0..Hmac.mac_length]); |
| 36 | counter[0] += 1; | 36 | counter[0] +%= 1; |
| | 37 | assert(counter[0] != 1); |
| 37 | } | 38 | } |
| 38 | const left = out.len % Hmac.mac_length; | 39 | const left = out.len % Hmac.mac_length; |
| 39 | if (left > 0) { | 40 | if (left > 0) { |