authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-08-20 13:06:23+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-08-20 23:02:10+02:00
logf92a5d79440402233bd0215e2bb2aeeb4f333931
tree1ac88ba0238f0d6944d45dcbc4aea1e0168d5169
parent3bed749b1c1285aa340f793fadb6b5b7275529cf

Repair crypto/benchmark; add BLAKE2b256

Some MACs have a 64-bit output

4 files changed, 14 insertions(+), 13 deletions(-)

lib/std/crypto/benchmark.zig+6-6
......@@ -56,19 +56,19 @@ pub fn benchmarkHash(comptime Hash: anytype, comptime bytes: comptime_int) !u64
5656
5757const macs = [_]Crypto{
5858 Crypto{ .ty = crypto.onetimeauth.Poly1305, .name = "poly1305" },
59 Crypto{ .ty = crypto.auth.HmacMd5, .name = "hmac-md5" },
60 Crypto{ .ty = crypto.auth.HmacSha1, .name = "hmac-sha1" },
61 Crypto{ .ty = crypto.auth.sha2.HmacSha256, .name = "hmac-sha256" },
62 Crypto{ .ty = crypto.auth.sha2.HmacSha512, .name = "hmac-sha512" },
59 Crypto{ .ty = crypto.auth.hmac.HmacMd5, .name = "hmac-md5" },
60 Crypto{ .ty = crypto.auth.hmac.HmacSha1, .name = "hmac-sha1" },
61 Crypto{ .ty = crypto.auth.hmac.sha2.HmacSha256, .name = "hmac-sha256" },
62 Crypto{ .ty = crypto.auth.hmac.sha2.HmacSha512, .name = "hmac-sha512" },
6363};
6464
6565pub fn benchmarkMac(comptime Mac: anytype, comptime bytes: comptime_int) !u64 {
66 std.debug.assert(32 >= Mac.mac_length and 32 >= Mac.minimum_key_length);
66 std.debug.assert(64 >= Mac.mac_length and 32 >= Mac.minimum_key_length);
6767
6868 var in: [1 * MiB]u8 = undefined;
6969 prng.random.bytes(in[0..]);
7070
71 var key: [32]u8 = undefined;
71 var key: [64]u8 = undefined;
7272 prng.random.bytes(key[0..]);
7373
7474 var offset: usize = 0;
lib/std/crypto/blake2.zig+2-1
......@@ -74,7 +74,7 @@ pub fn Blake2s(comptime out_len: usize) type {
7474 key: []const u8,
7575
7676 pub fn init() Self {
77 return init_keyed("");
77 return comptime init_keyed("");
7878 }
7979
8080 pub fn init_keyed(key: []const u8) Self {
......@@ -364,6 +364,7 @@ test "comptime blake2s256" {
364364/////////////////////
365365// Blake2b
366366
367pub const Blake2b256 = Blake2b(256);
367368pub const Blake2b384 = Blake2b(384);
368369pub const Blake2b512 = Blake2b(512);
369370
lib/std/crypto/blake3.zig+1-1
......@@ -298,7 +298,7 @@ pub const Blake3 = struct {
298298
299299 /// Construct a new `Blake3` for the regular hash function.
300300 pub fn init() Blake3 {
301 return Blake3.init_internal(IV, 0);
301 return comptime Blake3.init_internal(IV, 0);
302302 }
303303
304304 /// Construct a new `Blake3` for the keyed hash function.
lib/std/crypto/sha3.zig+5-5
......@@ -26,11 +26,11 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
2626 rate: usize,
2727
2828 pub fn init() Self {
29 var d: Self = undefined;
30 mem.set(u8, d.s[0..], 0);
31 d.offset = 0;
32 d.rate = 200 - (bits / 4);
33 return d;
29 return comptime Self{
30 .s = [_]u8{0} ** 200,
31 .offset = 0,
32 .rate = 200 - (bits / 4),
33 };
3434 }
3535
3636 pub fn reset(self: *Self) void {