Alternative timings with an old but stable Intel i5-2300 2.8GHz desktop PC on 32bit:
Hash function | MiB/sec | cycl./hash | cycl./map | size | Quality problems |
---|---|---|---|---|---|
donothing32 | 15645155.23 | 6.00 | - | 13 | test NOP |
donothing64 | 15652229.33 | 6.00 | - | 13 | test NOP |
donothing128 | 15649304.54 | 6.00 | - | 13 | test NOP |
NOP_OAAT_read64 | 30389.83 | 23.92 | - | 47 | test NOP |
BadHash | 524.81 | 101.11 | - | 47 | test FAIL |
sumhash | 7133.69 | 32.84 | - | 363 | test FAIL |
sumhash32 | 22544.60 | 31.24 | - | 863 | UB, test FAIL |
crc32 | 350.97 | 147.23 | 203.08 (2) | 422 | insecure, 8590x collisions, distrib |
md5_32a | 539.75 | 466.12 | 609.97 (3) | 4419 | 8590x collisions, distrib |
sha1_32a | 340.59 | 1021.56 | 1238.74 (5) | 5126 | collisions, 36.6% distrib |
md5-128 | 540.15 | 473.16 | 624.80 (2) | 4419 | |
sha1-160 | 340.55 | 1118.97 | 1320.79 (11) | 5126 | Comb/Cyclic low32 |
sha2-224 | 134.54 | 1469.55 | 1640.76 (9) | Cyclic low32 | |
sha2-224_64 | 134.42 | 1458.89 | 1631.88 (10) | Cyclic low32 | |
sha2-256 | 134.42 | 1451.79 | 1633.41 (12) | ||
sha2-256_64 | 134.42 | 1456.17 | 1629.96 (11) | ||
blake3_c | 838.57 | 392.97 | 538.83 (2) | Moment Chi2, no 32bit portability | |
rmd128 | 320.15 | 666.10 | 816.83 (10) | ||
rmd160 | 162.92 | 1213.25 | 1374.75 (9) | ||
rmd256 | 319.31 | 670.23 | 831.46 (10) | ||
edonr224 | 597.30 | 446.83 | 674.26 (6) | ||
edonr256 | 596.64 | 439.85 | 668.40 (5) | ||
blake2s-128 | 208.20 | 1094.84 | 1240.17 (6) | ||
blake2s-160 | 208.11 | 1098.10 | 1244.70 (7) | ||
blake2s-224 | 208.19 | 1098.67 | 1243.77 (9) | ||
blake2s-256 | 208.19 | 1103.83 | 1250.91 (14) | ||
blake2s-256_64 | 208.19 | 1154.08 | 1251.59 (8) | ||
blake2b-160 | 66.53 | 5883.15 | 6066.24 (12) | ||
blake2b-224 | 66.32 | 5871.55 | 6079.06 (12) | ||
blake2b-256 | 66.26 | 5913.02 | 6105.54 (15) | Sparse high 32-bit | |
blake2b-256_64 | 66.06 | 6124.16 | 6666.31 (10) | ||
asconhashv12 | 29.66 | 4285.27 | 3775.21 (4) | ||
asconhashv12_64 | 30.30 | 1931.66 | 1415.42 (7) | ||
sha3-256 | 37.33 | 11027.50 | - | PerlinNoise | |
sha3-256_64 | 37.82 | 10224.27 | - | PerlinNoise | |
hasshe2 | 2390.43 | 73.45 | 198.18 (2) | 445 | Permutation,TwoBytes,Zeroes,Seed |
tabulation32 | 3096.66 | 56.92 | 187.55 (1) | 848 | collisions |
crc32_hw | 6330.42 | 35.55 | 170.16 (1) | 653 | insecure, 100% bias, collisions, distrib, machine-specific (x86 SSE4.2) |
crc32_hw1 | 23208.73 | 46.74 | 179.70 (2) | 671 | insecure, 100% bias, collisions, distrib, machine-specific (x86 SSE4.2) |
crc64_hw | 8440.13 | 34.94 | 141.15 (2) | 652 | insecure, 100% bias, collisions, distrib, machine-specific (x64 SSE4.2) |
crc32_pclmul | 1972140.38 | 7.00 | - | 481 | insecure, 100% bias, collisions, distrib, machine-specific (x86 PCLMUL) |
o1hash | 12040901.70 | 26.30 | 151.19 (1) | 101 | insecure, zeros, fails all tests |
fibonacci | 18940.39 | 35.86 | 166.67 (1) | 1692 | UB, zeros, fails all tests |
FNV1a | 791.82 | 73.85 | 157.35 (0) | 204 | zeros, fails all tests |
FNV1A_Totenschiff | 3450.72 | 44.68 | 166.67 (1) | 270 | UB, zeros, fails all tests |
FNV1A_Pippip_Yurii | 1752.72 | 62.72 | 176.96 (1) | 147 | UB, sanity, fails all tests |
FNV1a_YT | 9659.59 | 36.00 | 160.44 (1) | 321 | UB, fails all tests |
FNV2 | 3166.50 | 39.06 | 160.66 (1) | 278 | fails all tests |
FNV64 | 231.91 | 233.39 | 255.51 (2) | 79 | fails all tests |
FNV128 | 231.91 | 233.39 | 255.51 (2) | 171 | fails all tests |
fletcher2 | 12581.35 | 34.54 | 335.39 (2) | 248 | UB, fails all tests |
fletcher4 | 12570.88 | 34.54 | 335.33 (1) | 371 | UB, fails all tests |
bernstein | 791.82 | 73.01 | 160.99 (2) | 41 | fails all tests |
sdbm | 791.81 | 72.22 | 156.08 (2) | 41 | fails all tests |
x17 | 527.90 | 103.01 | 170.03 (1) | 79 | 99.98% bias, fails all tests |
JenkinsOOAT | 452.48 | 150.83 | 211.16 (1) | 153 | 53.5% bias, fails all tests |
JenkinsOOAT_perl | 452.48 | 124.39 | 183.68 (2) | 65 | 1.5-11.5% bias, 7.2x collisions, LongNeighbors |
MicroOAAT | 977.86 | 65.15 | 162.37 (1) | 68 | 100% bias, distrib |
beamsplitter | 91.76 | 2508.20 | 2681.14 (8) | UB, too many bad seeds, | |
VHASH_32 | 1197.22 | 181.18 | 344.86 (2) | 1231 | sanity, Seed, MomentChi2 |
VHASH_64 | 1226.54 | 183.85 | 347.10 (1) | 1231 | sanity, Seed, Sparse |
farsh32 | 14053.09 | 74.29 | 245.33 (3) | 944 | insecure: AppendedZeroes, collisions+bias, MomentChi2, LongNeighbors |
farsh64 | 7216.29 | 130.30 | 302.44 (3) | 944 | insecure: AppendedZeroes, collisions+bias, MomentChi2, LongNeighbors |
jodyhash32 | 1510.06 | 52.57 | 405.08 (46) | 102 | bias, collisions, distr, 1 bad seed, LongNeighbors |
jodyhash64 | 868.93 | 79.78 | 602.44 (62) | 118 | bias, collisions, distr, LongNeighbors |
lookup3 | 1745.26 | 52.82 | 172.47 (1) | 341 | UB, 28% bias, collisions, 30% distr |
superfast | 1956.13 | 58.81 | 170.23 (1) | 210 | UB, 91% bias, 5273.01x collisions, 37% distr, BIC |
MurmurOAAT | 452.49 | 118.36 | 176.54 (2) | 47 | collisions, 99.998% distr., BIC, LongNeighbors |
Crap8 | 3027.65 | 45.39 | 167.02 (1) | 342 | UB, 2.42% bias, collisions, 2% distrib |
Murmur1 | 1629.97 | 61.67 | 190.26 (2) | UB, fails all tests, 1 bad seed | |
Murmur2 | 3089.23 | 47.03 | 169.92 (1) | 358 | UB, 1.7% bias, 81x coll, 1.7% distrib, BIC |
Murmur2A | 3089.93 | 52.56 | 176.40 (2) | 407 | UB, 12.7% bias, LongNeighbors |
Murmur2B | 4882.95 | 39.72 | 149.43 (2) | 433 | UB, 1.8% bias, collisions, 3.4% distrib, BIC |
Murmur2C | 4097.96 | 58.28 | 181.47 (1) | 444 | UB, 91% bias, collisions, distr, BIC, LongNeighbors |
Murmur3A | 2347.85 | 56.49 | 177.51 (1) | 351 | UB, Moment Chi2 69 |
PMurHash32 | 2350.74 | 63.66 | 175.31 (4) | 1862 | Moment Chi2 69 |
Murmur3C | 3120.65 | 74.61 | 203.62 (1) | 859 | UB, LongNeighbors, DiffDist |
PMPML_32 | 5454.39 | 58.24 | 208.67 (2) | 1084 | Avalanche >512, unseeded: Seed, MomentChi2 |
PMPML_64 | 8161.19 | 53.20 | 179.16 (2) | 1305 | unseeded: Seed, MomentChi2 |
xxHash32 | 6042.00 | 57.98 | 184.27 (1) | 738 | LongNeighbors, collisions with 4bit diff, MomentChi2 220 |
metrohash64_1 | 2284.71 | 119.38 | 241.89 (1) | 624 | UB, LongNeighbors, BIC, MomentChi2 |
metrohash64_2 | 2282.47 | 120.60 | 242.58 (1) | 627 | UB, LongNeighbors |
metrohash64crc_1 | 14000.50 | 49.08 | 150.54 (2) | 632 | UB, cyclic collisions 8 byte, BIC, MomentChi2, machine-specific (x64 SSE4.2) |
metrohash64crc_2 | 14034.84 | 48.94 | 162.54 (2) | 632 | UB, cyclic collisions 8 byte, BIC, machine-specific (x64 SSE4.2) |
metrohash128_1 | 3219.11 | 184.96 | 300.89 (1) | 773 | UB, LongNeighbors |
metrohash128_2 | 3215.37 | 184.81 | 301.74 (1) | 773 | UB, LongNeighbors |
cmetrohash64_1o | 9658.31 | 42.84 | 163.45 (1) | 3506 | LongNeighbors, MomentChi2 |
cmetrohash64_1 | 9683.33 | 45.20 | 161.01 (2) | 652 | LongNeighbors, BIC, MomentChi2 |
cmetrohash64_2 | 9669.95 | 44.75 | 149.67 (2) | 655 | LongNeighbors |
City64noSeed | 2427.79 | 85.49 | 213.76 (1) | 1038 | Avalanche, Sparse, TwoBytes, MomentChi2, Seed |
City64 | 2682.22 | 109.73 | 228.73 (2) | 1120 | Sparse, TwoBytes |
t1ha1_64be | 2031.87 | 147.45 | 260.74 (1) | 555 | Avalanche |
t1ha0_32le | 3315.84 | 93.56 | 222.64 (2) | 509 | Sparse, LongNeighbors |
t1ha0_32be | 3257.85 | 97.33 | 225.89 (1) | 533 | Sparse, LongNeighbors |
t1ha2_stream | 1933.61 | 262.12 | 397.87 (2) | 1665 | Sparse, Permutation, LongNeighbors |
t1ha2_stream128 | 1943.22 | 327.48 | 462.99 (2) | 1665 | Sparse, Permutation, LongNeighbors |
aesnihash | 5062.79 | 92.67 | 276.05 (20) | 1209 | fails many tests, machine-specific (x64 AES-NI) |
falkhash | 20202.42 | 173.63 | 321.52 (2) | 264 | Sparse, LongNeighbors, machine-specific (x64 AES-NI) |
MeowHash | 17371.91 | 85.48 | 247.96 (2) | 1764 | Sparse, machine-specific (x64 AES-NI) |
MeowHash64low | 17378.06 | 85.48 | 237.60 (2) | 1764 | Sparse, machine-specific (x64 AES-NI) |
MeowHash32low | 17374.64 | 85.48 | 258.53 (2) | 1764 | Sparse, machine-specific (x64 AES-NI) |
t1ha1_64le | 2761.59 | 129.41 | 235.06 (2) | 517 | Avalanche |
tifuhash_64 | 29.71 | 2089.94 | 1502.27 (9) | 276 | |
floppsyhash | 29.52 | 2483.40 | - | 623 | |
chaskey | 693.14 | 180.71 | 294.49 (2) | 1609 | PerlinNoise |
SipHash | 883.98 | 170.87 | 295.46 (1) | 1071 | |
HalfSipHash | 759.07 | 119.09 | 226.08 (2) | 700 | zeroes |
GoodOAAT | 1052.25 | 77.44 | 170.43 (1) | 237 | |
pearsonbhash64 | 845.46 | 185.49 | 277.92 (1) | 683 | |
pearsonbhash128 | 640.96 | 238.74 | 330.63 (3) | 1134 | |
pearsonbhash256 | 393.20 | 395.52 | 459.62 (1) | 844 | |
prvhash64_64m | 728.15 | 150.77 | 330.90 (9) | 349 | |
prvhash64_64 | 764.97 | 147.29 | 279.76 (5) | 384 | |
prvhash64_128 | 818.46 | 223.81 | 394.38 (39) | 718 | |
prvhash64s_64 | 1985.28 | 886.07 | 1129.82 (52) | 2640 | |
prvhash64s_128 | 2016.14 | 1191.38 | 1545.19 (39) | 2799 | |
SipHash13 | 1911.17 | 114.10 | 252.66 (2) | 778 | 0.9% bias |
TSip | 909.19 | 168.44 | 282.31 (2) | 519 | !msvc |
discohash1 | 4158.02 | 200.07 | - | 1294 | |
discohash1-128 | 3815.35 | 236.58 | 701.67 (2) | 1294 | |
discohash2 | 4058.64 | 204.75 | 410.22 (3) | 1294 | |
discohash2-128 | 4147.52 | 232.69 | 689.98 (1) | 1294 | |
discoNONG | 3664.12 | 418.35 | 840.01 (2) | bad seeds | |
aesni | 28617.28 | 29.91 | 238.03 (8) | 519 | machine-specific (x64 AES-NI) |
aesni-low | 28173.53 | 38.58 | 215.47 (10) | 519 | machine-specific (x64 AES-NI) |
seahash | 1183.47 | 125.56 | 260.30 (2) | 871 | PerlinNoise, !msvc |
seahash32low | 1069.19 | 136.85 | 283.57 (3) | 871 | PerlinNoise, !msvc |
clhash | 4472.31 | 82.72 | 229.73 (3) | 1809 | PerlinNoise, machine-specific (x64 SSE4.2) |
HighwayHash64 | 6242.58 | 99.55 | 248.41 (3) | 2546 | |
Murmur3F | 5226.40 | 52.18 | 175.85 (1) | 699 | UB |
fasthash32 | 1651.98 | 86.04 | 210.69 (1) | 566 | UB |
fasthash64 | 1492.08 | 96.18 | 232.96 (2) | 509 | UB, Moment Chi2 5159 ! |
MUM | 999.30 | 155.29 | 292.08 (2) | 1912 | UB, too many bad seeds, machine-specific (32/64 differs) |
MUMlow | 999.47 | 154.57 | 288.32 (1) | 1912 | UB, 5 bad seeds |
xmsx32 | 1361.31 | 69.57 | 211.86 (10) | 288 | 2 bad seeds |
mirhash | 872.73 | 138.70 | 254.13 (1) | 1112 | 2^36 bad seeds, UB, LongNeighbors, machine-specific (32/64 differs) |
mirhash32low | 872.56 | 139.09 | 253.29 (1) | 1112 | 4 bad seeds, UB, Cyclic, LongNeighbors, machine-specific (32/64 differs) |
mirhashstrict | 966.09 | 125.34 | 231.31 (1) | 1112 | |
mirhashstrict32low | 965.76 | 125.56 | 231.38 (1) | 1112 | 1 bad seed, MomentChi2 9 |
mx3 | 1919.73 | 125.07 | 240.75 (2) | 734 | UB |
pengyhash | 1994.95 | 210.07 | 339.92 (2) | 421 | |
City32 | 3711.40 | 63.70 | 179.51 (1) | 1319 | |
City64low | 2700.96 | 105.92 | 224.00 (1) | 1120 | |
City128 | 9640.19 | 88.45 | 225.38 (3) | 1841 | |
CityCrc128 | 12343.43 | 74.50 | 209.75 (2) | 295 | |
FarmHash32 | 11215.25 | 59.39 | 180.95 (1) | 11489 | machine-specific (x64 SSE4/AVX) |
FarmHash64 | 2137.40 | 106.26 | 231.56 (2) | 3758 | |
FarmHash128 | 2054.08 | 218.86 | 309.26 (2) | 163 | |
farmhash32_c | 16299.81 | 47.79 | 219.19 (4) | 762 | machine-specific (x64 SSE4/AVX) |
farmhash64_c | 8713.16 | 47.96 | 201.00 (2) | 3688 | |
farmhash128_c | 9244.13 | 79.08 | 209.44 (2) | 1890 | |
metrohash64 | 2535.24 | 108.47 | 217.25 (0) | 624 | LongNeighbors |
metrohash128 | 3558.22 | 164.31 | 274.99 (2) | 624 | UB |
metrohash128crc_1 | 13948.67 | 65.20 | 168.08 (2) | 723 | UB, machine-specific (x64 SSE4.2) |
metrohash128crc_2 | 13920.19 | 65.12 | 176.70 (1) | 723 | UB, machine-specific (x64 SSE4.2) |
xxHash64 | 1839.29 | 125.68 | 231.96 (2) | 1999 | |
Spooky32 | 3949.12 | 194.40 | 308.02 (1) | 2221 | UB |
Spooky64 | 3939.15 | 193.62 | 308.27 (1) | 2221 | UB |
Spooky128 | 3946.22 | 195.90 | 309.32 (1) | 2221 | UB |
t1ha2_atonce | 1434.56 | 151.63 | 253.57 (1) | 541 | |
t1ha2_atonce128 | 1453.54 | 243.11 | 350.77 (3) | 613 | LongNeighbors |
t1ha0_aes_noavx | 23307.44 | 151.19 | 254.94 (3) | 925 | LongNeighbors, machine-specific (x86 AES-NI) |
t1ha0_aes_avx1 | 22531.70 | 163.44 | 265.34 (2) | 843 | LongNeighbors, machine-specific (x64 AVX) |
t1ha0_aes_avx2 | 22345.33 | 44.38 | 556.47 (89) | 792 | LongNeighbors, machine-specific (x64 AVX2) |
xxh3 | 12764.08 | 76.27 | 185.12 (1) | 744 | Moment Chi2 14974, BIC |
xxh3low | 12776.69 | 75.44 | 186.04 (2) | 756 | Moment Chi2 1.8e+9 ! |
xxh128 | 12249.39 | 120.14 | 234.25 (1) | 1012 | Moment Chi2 14974 |
xxh128low | 11055.69 | 113.79 | 224.32 (1) | 1012 | Moment Chi2 14974, BIC |
MeowHash | 17371.91 | 85.48 | 247.96 (2) | 1764 | Sparse low32, machine-specific (x64 AES-NI) |
MeowHash32low | 17374.64 | 85.48 | 258.53 (2) | 1764 | Sparse, machine-specific (x64 AES-NI) |
wyhash | 1736.80 | 111.32 | 235.21 (1) | 474 | |
wyhash32 | 1864.46 | 63.82 | 206.87 (5) | 426 | 4 bad and broken seeds, 32-bit |
wyhash32low | 12194.76 | 26.83 | 182.34 (1) | 474 | 5 bad seeds |
umash32 | 4633.19 | 53.42 | 216.33 (3) | 1530 | |
umash32_hi | 4662.92 | 54.22 | 214.20 (2) | 1530 | |
umash64 | 4662.09 | 53.42 | 188.09 (1) | 1530 | |
umash128 | 2427.46 | 70.60 | 197.29 (2) | 1530 | |
halftime_hash64 | 2276.72 | 178.45 | 326.70 (1) | 1530 | |
halftime_hash128 | 9810.42 | 171.92 | 303.30 (2) | 1530 | |
halftime_hash256 | 10600.70 | 253.33 | 400.02 (1) | 1530 | |
halftime_hash512 | 6767.31 | 228.65 | 376.04 (2) | 1530 | |
nmhash32 | 5858.06 | 72.39 | 194.01 (1) | 2445 | |
nmhash32x | 17013.67 | 54.18 | 387.55 (12) | 1494 | |
komihash | 2208.60 | 134.35 | 268.71 (6) | 2799 | |
polymur | 1017.15 | 178.25 | 313.64 (9) | 1128 |
I added some SSE assisted hashes and fast intel/arm CRC32-C and AES HW variants, but not the fastest crcutil yet. See our crcutil results. See also the old https://code.google.com/p/smhasher/w/list.
So the fastest hash functions on x86_64 without quality problems are:
Hash functions for symbol tables or hash tables typically use 32 bit hashes, for databases, file systems and file checksums typically 64 or 128bit, for crypto now starting with 256 bit.
Typical median key size in perl5 is 20, the most common 4. Similar for all other dynamic languages. See github.com/rurban/perl-hash-stats
When used in a hash table the instruction cache will usually beat the CPU and throughput measured here. In my tests the smallest FNV1A
beats the fastest crc32_hw1
with Perl 5 hash tables. Even if those worse hash functions will lead to more collisions, the overall speed advantage and inline-ability beats the slightly worse quality. See e.g. A Seven-Dimensional Analysis of Hashing Methods and its Implications on Query Processing for a concise overview of the best hash table strategies, confirming that the simplest Mult hashing (bernstein, FNV*, x17, sdbm) always beat "better" hash functions (Tabulation, Murmur, Farm, ...) when used in a hash table.
The fast hash functions tested here are recommendable as fast for file digests and maybe bigger databases, but not for 32bit hash tables. The "Quality problems" lead to less uniform distribution, i.e. more collisions and worse performance, but are rarely related to real security attacks, just the 2nd sanity zeroes test against \0
invariance is security relevant.
MiB/sec: The average of the Bulk key speed test for alignments 0-7 with 262144-byte keys. The higher the better.
cycl./hash: The average of the Small key speed test for 1-31 byte keys. The smaller the better.
cycl./map: The result of the Hashmap test for /usr/dict/words with std::unordered_map get queries, with the standard deviation in brackets. This tests the inlinability of the hash function (see size). The smaller the better.
size: The object size in byte on AMD64. This affects the inlinability in e.g. hash tables. The smaller the better.
Quality problems: See the failures in the linked doc. The less the better.
The hash table attacks described in SipHash against City, Murmur or Perl JenkinsOAAT or at Hash Function Lounge are not included here.
Such an attack avoidance cannot be the problem of the hash function, but only the hash table collision resolution scheme. You can attack every single hash function, even the best and most secure if you detect the seed, e.g. from language (mis-)features, side-channel attacks, collision timings and independly the sort-order, so you need to protect your collision handling scheme from the worst-case O(n), i.e. separate chaining with linked lists. Linked lists chaining allows high load factors, but is very cache-unfriendly. The only recommendable linked list scheme is inlining the key or hash into the array. Nowadays everybody uses fast open addressing, even if the load factor needs to be ~50%, unless you use Cuckoo Hashing.
I.e. the usage of SipHash for their hash table in Python 3.4, ruby, rust, systemd, OpenDNS, Haskell and OpenBSD is pure security theatre. SipHash is not secure enough for security purposes and not fast enough for general usage. Brute-force generation of ~32k collisions need 2-4m for all these hashes. siphash being the slowest needs max 4m, other typically max 2m30s, with <10s for practical 16k collision attacks with all hash functions. Using Murmur is usually slower than a simple Mult, even in the worst case. Provable secure is only uniform hashing, i.e. 2-5 independent Mult or Tabulation, or using a guaranteed logarithmic collision scheme (a tree) or a linear collision scheme, such as Robin Hood or Cockoo hashing with collision counting.
One more note regarding security: Nowadays even SHA1 can be solved in a solver, like Z3 (or faster ones) for practical hash table collision attacks (i.e. 14-20 bits). All hash functions with less than 160 bits tested here cannot be considered "secure" at all.
The '' vulnerability attack with binary keys is tested in the 2nd Sanity Zero test.
The official NIST hash function testsuite does not do such extensive statistical tests, to search for weak ranges in the bits. Also crypto does not change the initial state, which we do here for our random 32bit seed. Crypto mostly cares about unreversable key -> hash functions without changing the initial fixed state and timings/sidechannel attacks.
The NIST "Cryptographic Algorithm Validation Program" (CAVP) involves the testing of the implementations of FIPS-approved and NIST-recommended cryptographic algorithms. During the NIST SHA-3 competition, the testing methodology was borrowed from the "CAVP", as the KATs and MCTs of the SHA-3 Competition Test Suite were based on the CAVP tests for SHA-2. In addition to this, the “Extremely Long Message Test,” not present in the CAVP for SHA-2, required the submitters to generate the hash value corresponding to a message with a length of 1 GiB. “NIST - Cryptographic Algorithm Validation Program (CAVP),” June 2017. Available: http://csrc.nist.gov/groups/STM/cavp (No testing source code provided, just high-level descriptions)
Two other independent third party testsuites found an extensive number of bugs and weaknesses in the SHA3 candidates. "Finding Bugs in Cryptographic Hash Function Implementations", Nicky Mouha, Mohammad S Raunak, D. Richard Kuhn, and Raghu Kacker, 2017. https://eprint.iacr.org/2017/891.pdf
Maybe independent researchers should come together to do a better public SHA-4 round, based on better and more testing methods, open source code for the tests, and using standard industry practices, such as valgrind, address-sanitizer and ubsan to detect obvious bugs.
Typical undefined behaviour (UB) problems:
Misaligned
Many word-wise hashes (in opposite to safe byte-wise processing)
don't check the input buffer for proper word alignment, which will
fail with ubsan or Sparc. word being int32_t
or int64_t
or even
more. On some old RISC hardware this will be a BUS error, you can
even let Intel HW generate such a bus error by setting some CPU
flag. But generally using misaligned accesses is fine.
These are: mx3, Spooky, mirhash (but not strict), MUM, fasthash, Murmur3*, Murmur2*, metrohash* (all but cmetro*), Crap8, beamsplitter, lookup3, fletcher4, fletcher2, all sanmayce FNV1a_ variants (FNV1a_YT, FNV1A_Pippip_Yurii, FNV1A_Totenschiff, ...), fibonacci
The usual mitigation is to check the buffer alignment either in the
caller, provide a pre-processing loop for the misaligned prefix, or
copy the whole buffer into a fresh aligned area.
Put that extra code inside #ifdef HAVE_ALIGNED_ACCESS_REQUIRED
.
oob - Out of bounds
Some hash function assume a padded input buffer which can be accessed past its length up to the word size. This allows for faster loop processing, as no 2nd loop or switch table for the rest is needed, but it requires a cooperative calling enviroment and is as such considered cheating.
Signed integer overflow
A simple type error, this hash needs to use unsigned integer types internally, to avoid undefined and inconsistent behaviour. i.e. SuperFastHash: signed integer overflow: -2147483641 + -113 cannot be represented in type 'int'
shift exponent overflow
With: FNV1A_Pippip_Yurii, FNV1A_Totenschiff, pair_multiply_shift, sumhash32 shift exponent 64 is too large for 64-bit type 'long unsigned int'