-
-
Notifications
You must be signed in to change notification settings - Fork 178
Verification Test
This should hopefully be a thorough and uambiguous test of whether a hash is correctly implemented on a given platform. Note that some newer hash are self-seeded (e.g. by using the randomized address of the key), denoted by expected = 0.
The Verification value is calculated by hashing 255 times over messages of [0], [0,1], [0,1,2] ... [0,1,2,...,255] with a reverse seed
255, 254, ... 0.
Then the 256 results are treated as array buffer and hashed with another seed, and the Verification value is the hash as uint32_t
.
This is one of the few tests which runs with varying seeds.
The test is best run by SMHasher --verbose --test=VerifiyAll
on all available architectures and variants.
I.e. at least 64bit and 32bit, gcc/clang and MSVC, with or without SSE, AVX, ...
When a Verification value is given as 0, then the Verification value computation is skipped, as the hash function itself does the random seeding, and the computed Verification value is not constant. I.e. highwayhash.
Some functions have different Verification values per compiler, then the hash is not considered portable (yet). This happens typically with MSVC or on big-endian, but sometimes even on 32-bit. Some hash functions have different optimized implementations per CPU feature, such as SSE2, SSE4, AVX, ... Then the hash functions need to have the same Verification values per variant (i.e. compiler switch).
The result value should never be 0. This is typically the sign of Insecure seeds
Some hash function are unseeded, i.e. when they ignore the given seed. The result is always the same with a given message but different seeds. This is the typical functionality for crypto hashes or other trivial poor hashes, but in order to avoid trivial hash table DDOS attacks new hash functions always mixin some random seed into its initial state. Our tested crypto hashes were patched to mixin some small seed into its initial IV ("Initialization vector"), which is normally constant. A good hash will distribute this short seed into all states, so the seed will be equally distributed over all resulting hash bits.