aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFrank Denis <github@pureftpd.org>2021-01-02 20:08:27 +0100
committerAndrew Kelley <andrew@ziglang.org>2021-01-02 22:32:57 -0800
commit5aac2fc28111e59a2a05a4fae42b6e19d4e0b7ca (patch)
tree39f754326e98c10e9c87108fbcf2eae1ac996fc4 /lib
parent683814190bde2340dbecf8e48ae1629900f51306 (diff)
downloadzig-5aac2fc28111e59a2a05a4fae42b6e19d4e0b7ca.tar.gz
zig-5aac2fc28111e59a2a05a4fae42b6e19d4e0b7ca.zip
std/crypto: properly support arbitrary output sizes
Fixes #7657
Diffstat (limited to 'lib')
-rw-r--r--lib/std/crypto/blake2.zig16
1 files changed, 4 insertions, 12 deletions
diff --git a/lib/std/crypto/blake2.zig b/lib/std/crypto/blake2.zig
index bcb925c12d..91fd23208a 100644
--- a/lib/std/crypto/blake2.zig
+++ b/lib/std/crypto/blake2.zig
@@ -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 {
@@ -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 {