| author | |
| committer | |
| log | f1ad94437baaae40109f388a7d44d698c10a56d3 |
| tree | 8267128a08b5cfb13dd2bb1dc06b4bf02c0a8160 |
| parent | 58873ed3f90325cee5c442169d609d02c71fd05a |
2 files changed, 6 insertions(+), 16 deletions(-)
lib/std/crypto/ghash.zig+3-8| ... | ... | @@ -34,8 +34,7 @@ pub const Ghash = struct { |
| 34 | 34 | leftover: usize = 0, |
| 35 | 35 | buf: [block_size]u8 align(16) = undefined, |
| 36 | 36 | |
| 37 | pub fn init(key: []const u8) Ghash { | |
| 38 | assert(key.len >= minimum_key_length); | |
| 37 | pub fn init(key: *const [minimum_key_length]u8) Ghash { | |
| 39 | 38 | const h1 = mem.readIntBig(u64, key[0..8]); |
| 40 | 39 | const h0 = mem.readIntBig(u64, key[8..16]); |
| 41 | 40 | const h1r = @bitReverse(u64, h1); |
| ... | ... | @@ -150,8 +149,7 @@ pub const Ghash = struct { |
| 150 | 149 | } |
| 151 | 150 | } |
| 152 | 151 | |
| 153 | pub fn final(st: *Ghash, out: []u8) void { | |
| 154 | assert(out.len >= mac_length); | |
| 152 | pub fn final(st: *Ghash, out: *[mac_length]u8) void { | |
| 155 | 153 | if (st.leftover > 0) { |
| 156 | 154 | var i = st.leftover; |
| 157 | 155 | while (i < block_size) : (i += 1) { |
| ... | ... | @@ -165,10 +163,7 @@ pub const Ghash = struct { |
| 165 | 163 | mem.secureZero(u8, @ptrCast([*]u8, st)[0..@sizeOf(Ghash)]); |
| 166 | 164 | } |
| 167 | 165 | |
| 168 | pub fn create(out: []u8, msg: []const u8, key: []const u8) void { | |
| 169 | std.debug.assert(out.len >= mac_length); | |
| 170 | std.debug.assert(key.len >= minimum_key_length); | |
| 171 | ||
| 166 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [minimum_key_length]u8) void { | |
| 172 | 167 | var st = Ghash.init(key); |
| 173 | 168 | st.update(msg); |
| 174 | 169 | st.final(out); |
lib/std/crypto/poly1305.zig+3-8| ... | ... | @@ -22,8 +22,7 @@ pub const Poly1305 = struct { |
| 22 | 22 | // partial block buffer |
| 23 | 23 | buf: [block_size]u8 align(16) = undefined, |
| 24 | 24 | |
| 25 | pub fn init(key: []const u8) Poly1305 { | |
| 26 | std.debug.assert(key.len >= minimum_key_length); | |
| 25 | pub fn init(key: *const [minimum_key_length]u8) Poly1305 { | |
| 27 | 26 | const t0 = mem.readIntLittle(u64, key[0..8]); |
| 28 | 27 | const t1 = mem.readIntLittle(u64, key[8..16]); |
| 29 | 28 | return Poly1305{ |
| ... | ... | @@ -115,8 +114,7 @@ pub const Poly1305 = struct { |
| 115 | 114 | } |
| 116 | 115 | } |
| 117 | 116 | |
| 118 | pub fn final(st: *Poly1305, out: []u8) void { | |
| 119 | std.debug.assert(out.len >= mac_length); | |
| 117 | pub fn final(st: *Poly1305, out: *[mac_length]u8) void { | |
| 120 | 118 | if (st.leftover > 0) { |
| 121 | 119 | var i = st.leftover; |
| 122 | 120 | st.buf[i] = 1; |
| ... | ... | @@ -187,10 +185,7 @@ pub const Poly1305 = struct { |
| 187 | 185 | std.mem.secureZero(u8, @ptrCast([*]u8, st)[0..@sizeOf(Poly1305)]); |
| 188 | 186 | } |
| 189 | 187 | |
| 190 | pub fn create(out: []u8, msg: []const u8, key: []const u8) void { | |
| 191 | std.debug.assert(out.len >= mac_length); | |
| 192 | std.debug.assert(key.len >= minimum_key_length); | |
| 193 | ||
| 188 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [minimum_key_length]u8) void { | |
| 194 | 189 | var st = Poly1305.init(key); |
| 195 | 190 | st.update(msg); |
| 196 | 191 | st.final(out); |