Skip to content

Commit

Permalink
std/crypto: properly support arbitrary output sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 authored and andrewrk committed Jan 3, 2021
1 parent 6838141 commit 5aac2fc
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lib/std/crypto/blake2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,8 @@ pub fn Blake2s(comptime out_bits: usize) type {
mem.set(u8, d.buf[d.buf_len..], 0);
d.t += d.buf_len;
d.round(d.buf[0..], true);

const rr = d.h[0 .. digest_length / 4];

for (rr) |s, j| {
mem.writeIntSliceLittle(u32, out[4 * j ..], s);
}
for (d.h) |*x| x.* = mem.nativeToLittle(u32, x.*);
mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));
}

fn round(d: *Self, b: *const [64]u8, last: bool) void {
Expand Down Expand Up @@ -480,12 +476,8 @@ pub fn Blake2b(comptime out_bits: usize) type {
mem.set(u8, d.buf[d.buf_len..], 0);
d.t += d.buf_len;
d.round(d.buf[0..], true);

const rr = d.h[0 .. digest_length / 8];

for (rr) |s, j| {
mem.writeIntSliceLittle(u64, out[8 * j ..], s);
}
for (d.h) |*x| x.* = mem.nativeToLittle(u64, x.*);
mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));
}

fn round(d: *Self, b: *const [128]u8, last: bool) void {
Expand Down

0 comments on commit 5aac2fc

Please sign in to comment.