| ... | ... | @@ -87,6 +87,11 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 87 | 87 | self.msg_len +%= @truncate(u8, b.len); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | pub fn peek(self: Self) [digest_length]u8 { |
| 91 | var copy = self; |
| 92 | return copy.finalResult(); |
| 93 | } |
| 94 | |
| 90 | 95 | pub fn final(self: *Self, b: []const u8) T { |
| 91 | 96 | std.debug.assert(b.len < 8); |
| 92 | 97 | |
| ... | ... | @@ -124,6 +129,12 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 124 | 129 | return (@as(u128, b2) << 64) | b1; |
| 125 | 130 | } |
| 126 | 131 | |
| 132 | pub fn finalResult(self: *Self) [digest_length]u8 { |
| 133 | var result: [digest_length]u8 = undefined; |
| 134 | self.final(&result); |
| 135 | return result; |
| 136 | } |
| 137 | |
| 127 | 138 | fn round(self: *Self, b: [8]u8) void { |
| 128 | 139 | const m = mem.readIntLittle(u64, b[0..8]); |
| 129 | 140 | self.v3 ^= m; |
| ... | ... | @@ -205,12 +216,23 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) |
| 205 | 216 | self.buf_len += @intCast(u8, b[off + aligned_len ..].len); |
| 206 | 217 | } |
| 207 | 218 | |
| 219 | pub fn peek(self: Self) [mac_length]u8 { |
| 220 | var copy = self; |
| 221 | return copy.finalResult(); |
| 222 | } |
| 223 | |
| 208 | 224 | /// Return an authentication tag for the current state |
| 209 | 225 | /// Assumes `out` is less than or equal to `mac_length`. |
| 210 | 226 | pub fn final(self: *Self, out: *[mac_length]u8) void { |
| 211 | 227 | mem.writeIntLittle(T, out, self.state.final(self.buf[0..self.buf_len])); |
| 212 | 228 | } |
| 213 | 229 | |
| 230 | pub fn finalResult(self: *Self) [mac_length]u8 { |
| 231 | var result: [mac_length]u8 = undefined; |
| 232 | self.final(&result); |
| 233 | return result; |
| 234 | } |
| 235 | |
| 214 | 236 | /// Return an authentication tag for a message and a key |
| 215 | 237 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { |
| 216 | 238 | var ctx = Self.init(key); |