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