Skip to content

Commit 5aac2fc

Browse files
jedisct1andrewrk
authored andcommitted
std/crypto: properly support arbitrary output sizes
Fixes #7657
1 parent 6838141 commit 5aac2fc

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

lib/std/crypto/blake2.zig

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

0 commit comments

Comments
 (0)