| author | |
| committer | |
| log | f92a5d79440402233bd0215e2bb2aeeb4f333931 |
| tree | 1ac88ba0238f0d6944d45dcbc4aea1e0168d5169 |
| parent | 3bed749b1c1285aa340f793fadb6b5b7275529cf |
Some MACs have a 64-bit output4 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 | ... | @@ -56,19 +56,19 @@ pub fn benchmarkHash(comptime Hash: anytype, comptime bytes: comptime_int) !u64 |
| 56 | 56 | ||
| 57 | const macs = [_]Crypto{ | 57 | const macs = [_]Crypto{ |
| 58 | Crypto{ .ty = crypto.onetimeauth.Poly1305, .name = "poly1305" }, | 58 | Crypto{ .ty = crypto.onetimeauth.Poly1305, .name = "poly1305" }, |
| 59 | Crypto{ .ty = crypto.auth.HmacMd5, .name = "hmac-md5" }, | 59 | Crypto{ .ty = crypto.auth.hmac.HmacMd5, .name = "hmac-md5" }, |
| 60 | Crypto{ .ty = crypto.auth.HmacSha1, .name = "hmac-sha1" }, | 60 | Crypto{ .ty = crypto.auth.hmac.HmacSha1, .name = "hmac-sha1" }, |
| 61 | Crypto{ .ty = crypto.auth.sha2.HmacSha256, .name = "hmac-sha256" }, | 61 | Crypto{ .ty = crypto.auth.hmac.sha2.HmacSha256, .name = "hmac-sha256" }, |
| 62 | Crypto{ .ty = crypto.auth.sha2.HmacSha512, .name = "hmac-sha512" }, | 62 | Crypto{ .ty = crypto.auth.hmac.sha2.HmacSha512, .name = "hmac-sha512" }, |
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| 65 | pub fn benchmarkMac(comptime Mac: anytype, comptime bytes: comptime_int) !u64 { | 65 | pub 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); |
| 67 | 67 | ||
| 68 | var in: [1 * MiB]u8 = undefined; | 68 | var in: [1 * MiB]u8 = undefined; |
| 69 | prng.random.bytes(in[0..]); | 69 | prng.random.bytes(in[0..]); |
| 70 | 70 | ||
| 71 | var key: [32]u8 = undefined; | 71 | var key: [64]u8 = undefined; |
| 72 | prng.random.bytes(key[0..]); | 72 | prng.random.bytes(key[0..]); |
| 73 | 73 | ||
| 74 | var offset: usize = 0; | 74 | var offset: usize = 0; |
lib/std/crypto/blake2.zig+2-1| ... | @@ -74,7 +74,7 @@ pub fn Blake2s(comptime out_len: usize) type { | ... | @@ -74,7 +74,7 @@ pub fn Blake2s(comptime out_len: usize) type { |
| 74 | key: []const u8, | 74 | key: []const u8, |
| 75 | 75 | ||
| 76 | pub fn init() Self { | 76 | pub fn init() Self { |
| 77 | return init_keyed(""); | 77 | return comptime init_keyed(""); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | pub fn init_keyed(key: []const u8) Self { | 80 | pub fn init_keyed(key: []const u8) Self { |
| ... | @@ -364,6 +364,7 @@ test "comptime blake2s256" { | ... | @@ -364,6 +364,7 @@ test "comptime blake2s256" { |
| 364 | ///////////////////// | 364 | ///////////////////// |
| 365 | // Blake2b | 365 | // Blake2b |
| 366 | 366 | ||
| 367 | pub const Blake2b256 = Blake2b(256); | ||
| 367 | pub const Blake2b384 = Blake2b(384); | 368 | pub const Blake2b384 = Blake2b(384); |
| 368 | pub const Blake2b512 = Blake2b(512); | 369 | pub const Blake2b512 = Blake2b(512); |
| 369 | 370 |
lib/std/crypto/blake3.zig+1-1| ... | @@ -298,7 +298,7 @@ pub const Blake3 = struct { | ... | @@ -298,7 +298,7 @@ pub const Blake3 = struct { |
| 298 | 298 | ||
| 299 | /// Construct a new `Blake3` for the regular hash function. | 299 | /// Construct a new `Blake3` for the regular hash function. |
| 300 | pub fn init() Blake3 { | 300 | pub fn init() Blake3 { |
| 301 | return Blake3.init_internal(IV, 0); | 301 | return comptime Blake3.init_internal(IV, 0); |
| 302 | } | 302 | } |
| 303 | 303 | ||
| 304 | /// Construct a new `Blake3` for the keyed hash function. | 304 | /// 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 { | ... | @@ -26,11 +26,11 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type { |
| 26 | rate: usize, | 26 | rate: usize, |
| 27 | 27 | ||
| 28 | pub fn init() Self { | 28 | pub fn init() Self { |
| 29 | var d: Self = undefined; | 29 | return comptime Self{ |
| 30 | mem.set(u8, d.s[0..], 0); | 30 | .s = [_]u8{0} ** 200, |
| 31 | d.offset = 0; | 31 | .offset = 0, |
| 32 | d.rate = 200 - (bits / 4); | 32 | .rate = 200 - (bits / 4), |
| 33 | return d; | 33 | }; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | pub fn reset(self: *Self) void { | 36 | pub fn reset(self: *Self) void { |