base: add hasher_u64

This commit is contained in:
Nigel Tao committed 2023-10-06 10:33:53 +11:00
1 parent 74a6ea2fcd
commit 88efa8360f
4 files changed
+281 -5

No files matched your search

+2 -1
View File
@@ -9,7 +9,8 @@ The LICENSE has changed from a single license (Apache 2) to a dual license
- Added `compact_retaining` and `history_retain_length`.
- Added `example/toy-aux-image`.
- Added `get_quirk(key: u32) u64`.
- Added `hasher_u32` `update!` and `checksum_u32` methods
- Added `hasher_u32` `update!` and `checksum_u32` methods.
- Added `hasher_u64`.
- Added `if.likely` and `if.unlikely`.
- Added `slice_var as nptr array[etc] etc` conversion.
- Added `std/jpeg`.
+14 -4
View File
@@ -4,10 +4,10 @@ Hashers take a stream of bytes (of arbitrary length) and produce a fixed length
value - the hash. For example, the CRC-32/IEEE hashing algorithm produces a 32
bit value (a `base.u32`). The MD5 hashing algorithm produces a 128 bit value.
Wuffs' hasher implementations have only one method. For 32 bit hashes, the
method signature is `update_u32!(x: slice base.u8) base.u32`. It incrementally
updates the hasher object's state with the addition data `x`, and returns the
hash value so far, for all of the data up to and including `x`.
Wuffs' hasher implementations have one core method. For 32 bit hashes, the
method signature is `update_u32!(x: roslice base.u8) base.u32`. It
incrementally updates the hasher object's state with the addition data `x`, and
returns the hash value so far, for all of the data up to and including `x`.
This method is stateful. Calling `update_u32` twice with the same slice of
bytes can produce two different hash values. Conversely, calling `update_u32`
@@ -15,6 +15,13 @@ twice with two different slices should be equivalent to calling it once on
their concatenation. [Re-initialize](/doc/note/initialization.md) the object to
reset the state.
The `update_u32!` method is equivalent to calling `update!` and then
`checksum_u32` (which is a pure method). For the rare algorithms where
computing the checksum from internal state is relatively expensive, and when
streaming many relatively-small updates, it might be more efficient to call
`update!` N times and `checksum_u32` only once, instead of calling
`update_u32!` N times.
Wuffs' hasher implementations are not cryptographic. They make no attempt to
resist timing attacks.
@@ -29,6 +36,9 @@ In Wuffs syntax, the `base.hasher_u32` methods are:
- `update!(x: slice u8)`
- `update_u32!(x: slice u8) u32`
The `base.hasher_u64` methods are similar, except for the obvious difference of
calculating a 64-bit (not 32-bit) checksum.
## Implementations