| ... | @@ -57,6 +57,10 @@ pub const Wyhash = struct { | ... | @@ -57,6 +57,10 @@ pub const Wyhash = struct { |
| 57 | } | 57 | } |
| 58 | | 58 | |
| 59 | const remaining_bytes = input[i..]; | 59 | const remaining_bytes = input[i..]; |
| | 60 | if (remaining_bytes.len < 16 and i >= 48) { |
| | 61 | const rem = 16 - remaining_bytes.len; |
| | 62 | @memcpy(self.buf[self.buf.len - rem ..], input[i - rem .. i]); |
| | 63 | } |
| 60 | @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes); | 64 | @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes); |
| 61 | self.buf_len = remaining_bytes.len; | 65 | self.buf_len = remaining_bytes.len; |
| 62 | } | 66 | } |
| ... | @@ -271,3 +275,19 @@ test "iterative non-divisible update" { | ... | @@ -271,3 +275,19 @@ test "iterative non-divisible update" { |
| 271 | try std.testing.expectEqual(iterative_hash, non_iterative_hash); | 275 | try std.testing.expectEqual(iterative_hash, non_iterative_hash); |
| 272 | } | 276 | } |
| 273 | } | 277 | } |
| | 278 | |
| | 279 | test "iterative maintains last sixteen" { |
| | 280 | const input = "Z" ** 48 ++ "01234567890abcdefg"; |
| | 281 | const seed = 0; |
| | 282 | |
| | 283 | for (0..17) |i| { |
| | 284 | const payload = input[0 .. input.len - i]; |
| | 285 | const non_iterative_hash = Wyhash.hash(seed, payload); |
| | 286 | |
| | 287 | var wh = Wyhash.init(seed); |
| | 288 | wh.update(payload); |
| | 289 | const iterative_hash = wh.final(); |
| | 290 | |
| | 291 | try expectEqual(non_iterative_hash, iterative_hash); |
| | 292 | } |
| | 293 | } |