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 {
137137 mem.set(u8, d.buf[d.buf_len..], 0);
138138 d.t += d.buf_len;
139139 d.round(d.buf[0..], true);
140
141 const rr = d.h[0 .. digest_length / 4];
142
143 for (rr) |s, j| {
144 mem.writeIntSliceLittle(u32, out[4 * j ..], s);
145 }
140 for (d.h) |*x| x.* = mem.nativeToLittle(u32, x.*);
141 mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));
146142 }
147143
148144 fn round(d: *Self, b: *const [64]u8, last: bool) void {
......@@ -480,12 +476,8 @@ pub fn Blake2b(comptime out_bits: usize) type {
480476 mem.set(u8, d.buf[d.buf_len..], 0);
481477 d.t += d.buf_len;
482478 d.round(d.buf[0..], true);
483
484 const rr = d.h[0 .. digest_length / 8];
485
486 for (rr) |s, j| {
487 mem.writeIntSliceLittle(u64, out[8 * j ..], s);
488 }
479 for (d.h) |*x| x.* = mem.nativeToLittle(u64, x.*);
480 mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));
489481 }
490482
491483 fn round(d: *Self, b: *const [128]u8, last: bool) void {