authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2021-01-02 20:08:27+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-02 22:32:57-08:00
log5aac2fc28111e59a2a05a4fae42b6e19d4e0b7ca
tree39f754326e98c10e9c87108fbcf2eae1ac996fc4
parent683814190bde2340dbecf8e48ae1629900f51306

std/crypto: properly support arbitrary output sizes

Fixes #7657

1 files changed, 4 insertions(+), 12 deletions(-)

lib/std/crypto/blake2.zig+4-12
...@@ -137,12 +137,8 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -137,12 +137,8 @@ pub fn Blake2s(comptime out_bits: usize) type {
137 mem.set(u8, d.buf[d.buf_len..], 0);137 mem.set(u8, d.buf[d.buf_len..], 0);
138 d.t += d.buf_len;138 d.t += d.buf_len;
139 d.round(d.buf[0..], true);139 d.round(d.buf[0..], true);
140140 for (d.h) |*x| x.* = mem.nativeToLittle(u32, x.*);
141 const rr = d.h[0 .. digest_length / 4];141 mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));
142
143 for (rr) |s, j| {
144 mem.writeIntSliceLittle(u32, out[4 * j ..], s);
145 }
146 }142 }
147143
148 fn round(d: *Self, b: *const [64]u8, last: bool) void {144 fn round(d: *Self, b: *const [64]u8, last: bool) void {
...@@ -480,12 +476,8 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -480,12 +476,8 @@ pub fn Blake2b(comptime out_bits: usize) type {
480 mem.set(u8, d.buf[d.buf_len..], 0);476 mem.set(u8, d.buf[d.buf_len..], 0);
481 d.t += d.buf_len;477 d.t += d.buf_len;
482 d.round(d.buf[0..], true);478 d.round(d.buf[0..], true);
483479 for (d.h) |*x| x.* = mem.nativeToLittle(u64, x.*);
484 const rr = d.h[0 .. digest_length / 8];480 mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));
485
486 for (rr) |s, j| {
487 mem.writeIntSliceLittle(u64, out[8 * j ..], s);
488 }
489 }481 }
490482
491 fn round(d: *Self, b: *const [128]u8, last: bool) void {483 fn round(d: *Self, b: *const [128]u8, last: bool) void {