-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
Hashes.h
1443 lines (1326 loc) · 50.7 KB
/
Hashes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#include "Platform.h"
#include "Types.h"
#include <algorithm>
#include "MurmurHash1.h"
#include "MurmurHash2.h"
#include "MurmurHash3.h"
#include "PMurHash.h"
#include "xmsx.h"
#define XXH_INLINE_ALL
#include "xxhash.h"
#include "gxhash.h"
#include "metrohash/metrohash64.h"
#include "metrohash/metrohash128.h"
#include "cmetrohash.h"
#include "opt_cmetrohash.h"
#if defined(HAVE_SSE42) && (defined(__x86_64__) || defined(__aarch64__))
#include "metrohash/metrohash64crc.h"
#include "metrohash/metrohash128crc.h"
#endif
#ifdef HAVE_AHASH_C
#include "ahash.h"
#endif
#include "fasthash.h"
#include "jody_hash32.h"
#include "jody_hash64.h"
// objsize: 0-0x113 = 276
#include "tifuhash.h"
// objsize: 5f0-85f = 623
#include "floppsyhash.h"
#include "siphash.h"
#include "vmac.h"
#include "tabulation.h"
//----------
// These are _not_ hash functions (even though people tend to use crc32 as one...)
static inline bool BadHash_bad_seeds(std::vector<uint32_t> &seeds)
{
seeds = std::vector<uint32_t> { UINT32_C(0) };
return true;
}
void BadHash(const void *key, int len, uint32_t seed, void *out);
static inline bool sumhash_bad_seeds(std::vector<uint32_t> &seeds)
{
seeds = std::vector<uint32_t> { UINT32_C(0) };
return true;
}
void sumhash(const void *key, int len, uint32_t seed, void *out);
void sumhash32(const void *key, int len, uint32_t seed, void *out);
void DoNothingHash(const void *key, int len, uint32_t seed, void *out);
void NoopOAATReadHash(const void *key, int len, uint32_t seed, void *out);
void crc32(const void *key, int len, uint32_t seed, void *out);
static inline bool crc32c_bad_seeds(std::vector<uint32_t> &seeds)
{
seeds = std::vector<uint32_t> { UINT32_C(0x111c2232) };
return true;
}
//----------
// General purpose hashes
#if defined(HAVE_SSE2)
void hasshe2_test(const void *key, int len, uint32_t seed, void *out);
#endif
#if defined(HAVE_SSE42)
// This falls into a MSVC CL 14.16.27023 32bit compiler bug. 14.28.29910 works fine.
# ifndef HAVE_BROKEN_MSVC_CRC32C_HW
void crc32c_hw_test(const void *key, int len, uint32_t seed, void *out);
void crc64c_hw_test(const void *key, int len, uint32_t seed, void *out);
# endif
# if defined(__SSE4_2__) && (defined(__i686__) || defined(__x86_64__)) && !defined(_MSC_VER)
void crc32c_hw1_test(const void *key, int len, uint32_t seed, void *out);
# endif
static inline bool crc64c_bad_seeds(std::vector<uint64_t> &seeds)
{
seeds = std::vector<uint64_t> { UINT64_C(0) };
return true;
}
#if defined(__x86_64__)
void CityHashCrc128_test(const void *key, int len, uint32_t seed, void *out);
void CityHashCrc256_test(const void *key, int len, uint32_t seed, void *out);
#endif
#endif
#if defined(HAVE_CLMUL) && !defined(_MSC_VER)
/* Function from linux kernel 3.14. It computes the CRC over the given
* buffer with initial CRC value <crc32>. The buffer is <len> byte in length,
* and must be 16-byte aligned, and larger than 63. */
extern "C" uint32_t crc32_pclmul_le_16(unsigned char const *buffer, size_t len,
uint32_t crc32);
void crc32c_pclmul_test(const void *key, int len, uint32_t seed, void *out);
static inline bool crc32c_pclmul_bad_seeds(std::vector<uint32_t> &seeds)
{
seeds = std::vector<uint32_t> { UINT32_C(0) };
return true;
}
static inline bool need_minlen64_align16(pfHash hash) {
return hash == crc32c_pclmul_test;
}
void falkhash_test_cxx(const void *key, int len, uint32_t seed, void *out);
#else
static inline bool need_minlen64_align16(pfHash hash) {
return false;
}
#endif
size_t fibonacci(const char *key, int len, uint32_t seed);
inline void fibonacci_test(const void *key, int len, uint32_t seed, void *out) {
*(size_t *)out = fibonacci((const char *)key, len, seed);
}
size_t FNV2(const char *key, int len, size_t seed);
inline void FNV2_test(const void *key, int len, uint32_t seed, void *out) {
*(size_t *)out = FNV2((const char *)key, len, (size_t)seed);
}
uint32_t FNV32a(const void *key, int len, uint32_t seed);
static inline bool FNV32a_bad_seeds(std::vector<uint32_t> &seeds)
{
seeds = std::vector<uint32_t> { UINT32_C(0x811c9dc5) };
return true;
}
inline void FNV32a_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *)out = FNV32a((const char *)key, len, seed);
}
uint32_t FNV32a_YoshimitsuTRIAD(const char *key, int len, uint32_t seed);
static inline bool FNV32a_YT_bad_seeds(std::vector<uint32_t> &seeds)
{
seeds = std::vector<uint32_t> { UINT32_C(0x811c9dc5) };
return true;
}
inline void FNV32a_YT_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *)out = FNV32a_YoshimitsuTRIAD((const char *)key, len, seed);
}
#ifdef HAVE_INT64
uint32_t FNV1A_Totenschiff(const char *key, int len, uint32_t seed);
inline void FNV1A_Totenschiff_test(const void *key, int len, uint32_t seed,
void *out) {
*(uint32_t *)out = FNV1A_Totenschiff((const char *)key, len, seed);
}
uint32_t FNV1A_Pippip_Yurii(const char *key, int wrdlen, uint32_t seed);
inline void FNV1A_PY_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *)out = FNV1A_Pippip_Yurii((const char *)key, len, seed);
}
#endif
void FNV128(uint64_t buf[2], const char *key, int len, uint64_t seed);
inline void FNV128_test(const void *key, int len, uint32_t seed, void *out) {
FNV128((uint64_t*)out, (const char *)key, len, (uint64_t)seed);
}
uint64_t FNV64a(const char *key, int len, uint64_t seed);
inline void FNV64a_test(const void *key, int len, uint32_t seed, void *out) {
*(uint64_t *)out = FNV64a((const char *)key, len, (uint64_t)seed);
}
static inline bool fletcher_bad_seeds(std::vector<uint64_t> &seeds)
{
seeds = std::vector<uint64_t> { UINT64_C(0) };
return true;
}
uint64_t fletcher2(const char *key, int len, uint64_t seed);
inline void fletcher2_test(const void *key, int len, uint32_t seed, void *out) {
*(uint64_t *) out = fletcher2((const char *)key, len, (uint64_t)seed);
}
uint64_t fletcher4(const char *key, int len, uint64_t seed);
inline void fletcher4_test(const void *key, int len, uint32_t seed, void *out) {
*(uint64_t *) out = fletcher2((const char *)key, len, (uint64_t)seed);
}
uint32_t Bernstein(const char *key, int len, uint32_t seed);
static inline bool Bernstein_bad_seeds(std::vector<uint32_t> &seeds)
{
seeds = std::vector<uint32_t> { UINT32_C(0) };
return true;
}
inline void Bernstein_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *) out = Bernstein((const char *)key, len, seed);
}
uint32_t sdbm(const char *key, int len, uint32_t hash);
static inline bool sdbm_bad_seeds(std::vector<uint32_t> &seeds)
{
seeds = std::vector<uint32_t> { UINT32_C(0) };
return true;
}
inline void sdbm_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *) out = sdbm((const char *)key, len, seed);
}
uint32_t x17(const char *key, int len, uint32_t h);
inline void x17_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *) out = x17((const char *)key, len, seed);
}
uint32_t libiberty_hash(unsigned char *key, int len, uint32_t seed);
inline void libiberty_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *) out = libiberty_hash((unsigned char *)key, len, seed);
}
inline void gcc_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *) out = len + libiberty_hash((unsigned char *)key, len, seed);
}
uint32_t JenkinsOOAT(const char *key, int len, uint32_t hash);
inline void JenkinsOOAT_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *) out = JenkinsOOAT((const char *)key, len, seed);
}
uint32_t JenkinsOOAT_perl(const char *key, int len, uint32_t hash);
inline void JenkinsOOAT_perl_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *) out = JenkinsOOAT_perl((const char *)key, len, seed);
}
uint32_t GoodOAAT(const char *key, int len, uint32_t hash);
inline void GoodOAAT_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *) out = GoodOAAT((const char *)key, len, seed);
}
uint32_t MicroOAAT(const char *key, int len, uint32_t hash);
inline void MicroOAAT_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *) out = MicroOAAT((const char *)key, len, seed);
}
uint32_t SuperFastHash (const char * data, int len, uint32_t hash);
static inline bool SuperFastHash_bad_seeds(std::vector<uint32_t> &seeds)
{
seeds = std::vector<uint32_t> { UINT32_C(0) };
return true;
}
inline void SuperFastHash_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t*)out = SuperFastHash((const char*)key, len, seed);
}
uint32_t lookup3(const char *key, int len, uint32_t hash);
inline void lookup3_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *) out = lookup3((const char *)key, len, seed);
}
uint32_t MurmurOAAT(const char *key, int len, uint32_t hash);
inline void MurmurOAAT_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *) out = MurmurOAAT((const char *)key, len, seed);
}
uint32_t Crap8(const uint8_t * key, uint32_t len, uint32_t seed);
inline void Crap8_test(const void *key, int len, uint32_t seed, void *out) {
*(uint32_t *) out = Crap8((const uint8_t *)key, len, seed);
}
void CityHash32_test(const void *key, int len, uint32_t seed, void *out);
void CityHash64noSeed_test(const void *key, int len, uint32_t seed, void *out);
void CityHash64_test(const void *key, int len, uint32_t seed, void *out);
inline void CityHash64_low_test(const void *key, int len, uint32_t seed, void *out) {
uint64_t result;
CityHash64_test(key, len, seed, &result);
*(uint32_t *)out = (uint32_t)result;
}
void CityHash128_test(const void *key, int len, uint32_t seed, void *out);
// objsize: eb0-3b91: 11489 (mult. variants per len)
void FarmHash32_test ( const void * key, int len, uint32_t seed, void * out );
// objsize: 0-eae: 3758 (mult. variants per len)
void FarmHash64_test ( const void * key, int len, uint32_t seed, void * out );
void FarmHash64noSeed_test ( const void * key, int len, uint32_t seed, void * out );
// objsize: 44a0-4543: 163
void FarmHash128_test ( const void * key, int len, uint32_t seed, void * out );
// objsize: 0x2c70-0x2f6a farmhash32_su_with_seed
void farmhash32_c_test ( const void * key, int len, uint32_t seed, void * out );
// objsize: 4a20-4a82/5b0-5fd/660-1419: 3688 farmhash64_na_with_seeds
void farmhash64_c_test ( const void * key, int len, uint32_t seed, void * out );
// objsize: 4140-48a2: 1890
void farmhash128_c_test ( const void * key, int len, uint32_t seed, void * out );
// all 3 using the same Hash128
// objsize: 0-8ad: 2221
void SpookyHash32_test ( const void * key, int len, uint32_t seed, void * out );
void SpookyHash64_test ( const void * key, int len, uint32_t seed, void * out );
void SpookyHash128_test ( const void * key, int len, uint32_t seed, void * out );
// objsize: 465b90-4663c0: 2069
void SpookyV2_32_test ( const void * key, int len, uint32_t seed, void * out );
void SpookyV2_64_test ( const void * key, int len, uint32_t seed, void * out );
void SpookyV2_128_test ( const void * key, int len, uint32_t seed, void * out );
//----------
// Used internally as C++
uint32_t MurmurOAAT ( const char * key, int len, uint32_t seed );
// MurmurHash2
void MurmurHash2_test ( const void * key, int len, uint32_t seed, void * out );
void MurmurHash2A_test ( const void * key, int len, uint32_t seed, void * out );
void siphash_test ( const void * key, int len, uint32_t seed, void * out );
void siphash13_test ( const void * key, int len, uint32_t seed, void * out );
void halfsiphash_test ( const void * key, int len, uint32_t seed, void * out );
extern "C" void chaskey_c ( const void * key, int len, uint64_t seed, void * out );
extern "C" void chaskey_init();
inline void
chaskey_test(const void *input, int len, uint32_t seed, void *out)
{
uint64_t lseed = (uint64_t)seed;
chaskey_c (input, len, lseed, out);
}
//-----------------------------------------------------------------------------
// Test harnesses for Murmur1/2
inline void MurmurHash1_test ( const void * key, int len, uint32_t seed, void * out )
{
*(uint32_t*)out = MurmurHash1(key,len,seed);
}
inline void MurmurHash2_test ( const void * key, int len, uint32_t seed, void * out )
{
*(uint32_t*)out = MurmurHash2(key,len,seed);
}
inline void MurmurHash2A_test ( const void * key, int len, uint32_t seed, void * out )
{
*(uint32_t*)out = MurmurHash2A(key,len,seed);
}
#if __WORDSIZE >= 64
inline void MurmurHash64A_test ( const void * key, int len, uint32_t seed, void * out )
{
*(uint64_t*)out = MurmurHash64A(key,len,seed);
}
#endif
#ifdef HAVE_INT64
// 2^32 bad seeds for Murmur2C
static void MurmurHash64B_seed_init(uint32_t &seed) {
if ((seed & 0x10) == 0x10)
seed++;
}
inline void MurmurHash64B_test ( const void * key, int len, uint32_t seed, void * out )
{
*(uint64_t*)out = MurmurHash64B(key,len,seed);
}
#endif
inline void xmsx32_test ( const void * key, int len, uint32_t seed, void * out )
{
*(uint32_t*)out = xmsx32(key, (size_t)len, seed);
}
inline void jodyhash32_test( const void * key, int len, uint32_t seed, void * out ) {
*(uint32_t*)out = jody_block_hash32((const jodyhash32_t *)key, (jodyhash32_t) seed, (size_t) len);
}
#ifdef HAVE_INT64
inline void jodyhash64_test( const void * key, int len, uint32_t seed, void * out ) {
*(uint64_t*)out = jody_block_hash((jodyhash_t *)key, (jodyhash_t) seed, (size_t) len);
}
#endif
inline void xxHash32_test( const void * key, int len, uint32_t seed, void * out ) {
// objsize 10-104 + 3e0-5ce: 738
*(uint32_t*)out = (uint32_t) XXH32(key, (size_t) len, (unsigned) seed);
}
// objsize 4183e0 - 4186c0: 736
inline void gxhash32_test( const void * key, int len, uint32_t seed, void * out ) {
*(uint32_t*)out = gxhash32((uint8_t*)key, (size_t) len, seed);
}
static inline bool gxhash32_bad_seeds(std::vector<uint32_t> &seeds)
{
seeds = std::vector<uint32_t>{
0xe1c1ec7d, 0x0376a937, 0x64ef3cc9, 0x282c25a4,
0xab1d407e, 0xef794206, 0x90626a1e, 0x9c0731c3,
0x3c1daeaa, 0xbd359253 };
return true;
}
void gxhash32_seed_init(uint32_t &seed);
#ifdef HAVE_INT64
inline void xxHash64_test( const void * key, int len, uint32_t seed, void * out ) {
// objsize 630-7fc + c10-1213: 1999
*(uint64_t*)out = (uint64_t) XXH64(key, (size_t) len, (unsigned long long) seed);
}
// objsize 418110 - 4183e0: 720
inline void gxhash64_test( const void * key, int len, uint32_t seed, void * out ) {
*(uint64_t*)out = gxhash64((uint8_t*)key, (size_t) len, seed);
}
#endif
#define restrict // oddly enough, seems to choke on this keyword
#include "xxh3.h"
#ifdef HAVE_INT64
static inline bool xxh3_bad_seeds(std::vector<uint64_t> &seeds) {
return false;
}
inline void xxh3_test( const void * key, int len, uint32_t seed, void * out ) {
// objsize 12d0-15b8: 744
*(uint64_t*)out = (uint64_t) XXH3_64bits_withSeed(key, (size_t) len, seed);
}
#endif
inline void xxh3low_test( const void * key, int len, uint32_t seed, void * out ) {
// objsize 12d0-15b8: 744 + 1f50-1f5c: 756
*(uint32_t*)out = (uint32_t) XXH3_64bits_withSeed(key, (size_t) len, seed);
}
#ifdef HAVE_INT64
inline void xxh128_test( const void * key, int len, uint32_t seed, void * out ) {
// objsize 1f60-2354: 1012
*(XXH128_hash_t*)out = XXH128(key, (size_t) len, seed);
}
inline void xxh128low_test( const void * key, int len, uint32_t seed, void * out ) {
*(uint64_t*)out = (uint64_t) (XXH128(key, (size_t) len, seed).low64);
}
#ifdef HAVE_INT64
inline void metrohash64_test ( const void * key, int len, uint32_t seed, void * out ) {
MetroHash64::Hash((const uint8_t *)key, (uint64_t)len, (uint8_t *)out, seed);
}
inline void metrohash64_1_test ( const void * key, int len, uint32_t seed, void * out ) {
metrohash64_1((const uint8_t *)key, (uint64_t)len, seed, (uint8_t *)out);
}
inline void metrohash64_2_test ( const void * key, int len, uint32_t seed, void * out ) {
metrohash64_2((const uint8_t *)key, (uint64_t)len, seed, (uint8_t *)out);
}
inline void metrohash128_test ( const void * key, int len, uint32_t seed, void * out ) {
MetroHash128::Hash((const uint8_t *)key, (uint64_t)len, (uint8_t *)out, seed);
}
inline void metrohash128_1_test ( const void * key, int len, uint32_t seed, void * out ) {
metrohash128_1((const uint8_t *)key, (uint64_t)len, seed, (uint8_t *)out);
}
inline void metrohash128_2_test ( const void * key, int len, uint32_t seed, void * out ) {
metrohash128_2((const uint8_t *)key, (uint64_t)len, seed, (uint8_t *)out);
}
#endif
#if defined(HAVE_SSE42) && (defined(__x86_64__) || defined(__aarch64__)) && !defined(_MSC_VER)
inline void metrohash64crc_1_test ( const void * key, int len, uint32_t seed, void * out ) {
metrohash64crc_1((const uint8_t *)key, (uint64_t)len, seed, (uint8_t *)out);
}
inline void metrohash64crc_2_test ( const void * key, int len, uint32_t seed, void * out ) {
metrohash64crc_2((const uint8_t *)key, (uint64_t)len, seed, (uint8_t *)out);
}
inline void metrohash128crc_1_test ( const void * key, int len, uint32_t seed, void * out ) {
metrohash128crc_1((const uint8_t *)key, (uint64_t)len, seed, (uint8_t *)out);
}
inline void metrohash128crc_2_test ( const void * key, int len, uint32_t seed, void * out ) {
metrohash128crc_2((const uint8_t *)key, (uint64_t)len, seed, (uint8_t *)out);
}
#endif
inline void cmetrohash64_1_test ( const void * key, int len, uint32_t seed, void * out ) {
// objsize 0-28c: 652
cmetrohash64_1((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
}
inline void cmetrohash64_1_optshort_test ( const void * key, int len, uint32_t seed, void * out ) {
// objsize 0-db2: 3506
cmetrohash64_1_optshort((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
}
inline void cmetrohash64_2_test ( const void * key, int len, uint32_t seed, void * out ) {
// objsize 290-51f: 655
cmetrohash64_2((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
}
#endif
inline void fasthash32_test ( const void * key, int len, uint32_t seed, void * out ) {
*(uint32_t*)out = fasthash32(key, (size_t) len, seed);
}
#ifdef HAVE_INT64
inline void fasthash64_test ( const void * key, int len, uint32_t seed, void * out ) {
*(uint64_t*)out = fasthash64(key, (size_t) len, (uint64_t)seed);
}
#ifdef HAVE_AHASH_C
// objsize: 4c48a0-4c4a3c: 412
inline void ahash64_test ( const void * key, int len, uint32_t seed, void * out ) {
*(uint64_t*)out = ahash64(key, (size_t) len, (uint64_t)seed);
}
#endif
#endif
// objsize 0-778: 1912
void mum_hash_test(const void * key, int len, uint32_t seed, void * out);
static inline bool mum_hash_bad_seeds(std::vector<uint64_t> &seeds)
{
seeds = std::vector<uint64_t> { UINT64_C(0) };
return true;
}
inline void mum_low_test ( const void * key, int len, uint32_t seed, void * out ) {
uint64_t result;
mum_hash_test(key, len, seed, &result);
*(uint32_t*)out = (uint32_t)result;
}
//-----------------------------------------------------------------------------
#define T1HA0_RUNTIME_SELECT 0
#ifdef HAVE_AESNI
# define T1HA0_AESNI_AVAILABLE 1
#else
# define T1HA0_AESNI_AVAILABLE 0
#endif
#include "t1ha.h"
inline void t1ha2_atonce_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize 0-21d: 541
*(uint64_t*)out = t1ha2_atonce(key, len, seed);
}
inline void t1ha2_stream_test(const void * key, int len, uint32_t seed, void * out)
{
t1ha_context_t ctx;
// objsize 570-bf1: 1665
t1ha2_init(&ctx, seed, 0);
t1ha2_update(&ctx, key, len);
*(uint64_t*)out = t1ha2_final(&ctx, NULL);
}
inline void t1ha2_atonce128_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize b50-db5: 613
*(uint64_t*)out = t1ha2_atonce128((uint64_t*)out + 1, key, len, seed);
}
inline void t1ha2_stream128_test(const void * key, int len, uint32_t seed, void * out)
{
t1ha_context_t ctx;
// objsize e20-14a1: 1665
t1ha2_init(&ctx, seed, 0);
t1ha2_update(&ctx, key, len);
*(uint64_t*)out = t1ha2_final(&ctx, (uint64_t*)out + 1);
}
inline void t1ha1_64le_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize 0-205: 517
*(uint64_t*)out = t1ha1_le(key, len, seed);
}
inline void t1ha1_64be_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize 280-4ab: 555
*(uint64_t*)out = t1ha1_be(key, len, seed);
}
inline void t1ha0_32le_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize 0-1fd: 509
*(uint64_t*)out = t1ha0_32le(key, len, seed);
}
inline void t1ha0_32be_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize 250-465: 533
*(uint64_t*)out = t1ha0_32be(key, len, seed);
}
#if T1HA0_AESNI_AVAILABLE
#ifndef _MSC_VER
inline void t1ha0_ia32aes_noavx_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize 0-39d: 925
*(uint64_t*)out = t1ha0_ia32aes_noavx(key, len, seed);
}
#endif
#if defined(__AVX__)
inline void t1ha0_ia32aes_avx1_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize 0-34b: 843
*(uint64_t*)out = t1ha0_ia32aes_avx(key, len, seed);
}
#endif /* __AVX__ */
#if defined(__AVX2__)
inline void t1ha0_ia32aes_avx2_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize 0-318: 792
*(uint64_t*)out = t1ha0_ia32aes_avx2(key, len, seed);
}
#endif /* __AVX2__ */
#endif /* T1HA0_AESNI_AVAILABLE */
#if defined(HAVE_SSE42) && defined(__x86_64__)
#include "clhash.h"
void clhash_init();
void clhash_seed_init(size_t &seed);
void clhash_test (const void * key, int len, uint32_t seed, void * out);
#endif
#ifndef _MSC_VER
// objsize 454880-4554f3: 2911
void halftime_hash_style64_test(const void *key, int len, uint32_t seed, void *out);
// 455e90 - 45682e: 2462
void halftime_hash_style128_test(const void *key, int len, uint32_t seed, void *out);
// 458840 - 45927e: 2622
void halftime_hash_style256_test(const void *key, int len, uint32_t seed, void *out);
// 457a60 - 45883e: 3550 (without AVX512 on Ryzen3)
void halftime_hash_style512_test(const void *key, int len, uint32_t seed, void *out);
void halftime_hash_init();
void halftime_hash_seed_init(size_t &seed);
#endif
#ifdef __SIZEOF_INT128__
void multiply_shift_init();
void multiply_shift_seed_init(uint32_t &seed);
bool multiply_shift_bad_seeds(std::vector<uint64_t> &seeds);
void multiply_shift (const void * key, int len, uint32_t seed, void * out);
void pair_multiply_shift (const void *key, int len, uint32_t seed, void *out);
void poly_mersenne_init();
void poly_mersenne_seed_init(uint32_t &seed);
// insecure: hashes cancel itself out, as with CRC
// void poly_0_mersenne (const void* key, int len, uint32_t seed, void* out);
void poly_1_mersenne (const void* key, int len, uint32_t seed, void* out);
void poly_2_mersenne (const void* key, int len, uint32_t seed, void* out);
void poly_3_mersenne (const void* key, int len, uint32_t seed, void* out);
void poly_4_mersenne (const void* key, int len, uint32_t seed, void* out);
#endif
#ifdef __SIZEOF_INT128__
inline void tabulation_init() {
size_t seed = 2;
tabulation_seed_init(seed);
}
// insecure: hashes cancel itself out, as with poly_X and CRC
// objsize: 40b780 - 40b9aa: 554
inline void tabulation_test (const void * key, int len, uint32_t seed, void * out) {
*(uint64_t*)out = tabulation_hash(key, len, seed);
}
#endif
inline void tabulation_32_init() {
size_t seed = 0;
tabulation_32_seed_init(seed);
}
// objsize: 40b9b0 - 40bd00: 848
inline void tabulation_32_test (const void * key, int len, uint32_t seed, void * out) {
*(uint32_t*)out = tabulation_32_hash(key, len, seed);
}
void HighwayHash_init();
// objsize 20-a12: 2546
void HighwayHash64_test (const void * key, int len, uint32_t seed, void * out);
#if defined HAVE_BIT32
// native 32bit. objsize: 8055230 - 80553da: 426
#include "wyhash32.h"
inline void wyhash32_test (const void * key, int len, uint32_t seed, void * out) {
*(uint32_t*)out = wyhash32(key, (uint64_t)len, (unsigned)seed);
}
#elif defined HAVE_INT64
#include "wyhash.h"
// objsize 40dbe0-40ddba: 474
inline void wyhash_test (const void * key, int len, uint32_t seed, void * out) {
*(uint64_t*)out = wyhash(key, (uint64_t)len, (uint64_t)seed, _wyp);
}
// objsize: 40da00-40dbda: 474
inline void wyhash32low (const void * key, int len, uint32_t seed, void * out) {
*(uint32_t*)out = 0xFFFFFFFF & wyhash(key, (uint64_t)len, (uint64_t)seed, _wyp);
}
#include "w1hash.h"
inline void w1hash_test (const void * key, int len, uint32_t seed, void * out) {
*(uint64_t*)out = w1hash_with_seed(key, len, seed);
}
#endif
#ifdef HAVE_INT64
#include "rapidhash.h"
// objsize: 181e0-1841e: 574
inline void rapidhash_test (const void * key, int len, uint32_t seed, void * out) {
*(uint64_t*)out = rapidhash_withSeed_compact(key, (uint64_t)len, (uint64_t)seed);
}
// objsize: 18420-1872e: 782
inline void rapidhash_unrolled_test (const void * key, int len, uint32_t seed, void * out) {
*(uint64_t*)out = rapidhash_withSeed_unrolled(key, (uint64_t)len, (uint64_t)seed);
}
#endif
#ifdef HAVE_INT64
#include "o1hash.h"
// unseeded. objsize: 101
// This is vulnerable to keys len>4 and key[len/2 -2]..[len/2 +2] being 0 (binary keys).
inline void o1hash_test (const void * key, int len, uint32_t seed, void * out) {
*(uint64_t*)out = o1hash(key, (uint64_t)len);
}
//https://github.com/vnmakarov/mir/blob/master/mir-hash.h
#include "mir-hash.h"
static inline bool mirhash_bad_seeds(std::vector<uint64_t> &seeds)
{
seeds = std::vector<uint64_t> { 0x0, 0x5e74c778, 0xa521f17b, 0xe0ab70e3 };
// plus all 64bit variants << 32 !!
return true;
}
inline void mirhash_test (const void * key, int len, uint32_t seed, void * out) {
// objsize 2950-2da8: 1112
*(uint64_t*)out = mir_hash(key, (uint64_t)len, (uint64_t)seed);
}
static inline bool mirhash32_bad_seeds(std::vector<uint32_t> &seeds)
{
seeds = std::vector<uint32_t> { 0x0, 0x5e74c778, 0xa521f17b, 0xe0ab70e3 };
return true;
}
inline void mirhash32low (const void * key, int len, uint32_t seed, void * out) {
*(uint32_t*)out = 0xFFFFFFFF & mir_hash(key, (uint64_t)len, (uint64_t)seed);
}
inline void mirhashstrict_test (const void * key, int len, uint32_t seed, void * out) {
// objsize 2950-2da8: 1112
*(uint64_t*)out = mir_hash_strict(key, (uint64_t)len, (uint64_t)seed);
}
static inline bool mirhashstrict32low_bad_seeds(std::vector<uint32_t> &seeds)
{
seeds = std::vector<uint32_t> { 0x7fcc747f };
return true;
}
inline void mirhashstrict32low (const void * key, int len, uint32_t seed, void * out) {
*(uint32_t*)out = 0xFFFFFFFF & mir_hash_strict(key, (uint64_t)len, (uint64_t)seed);
}
static void mirhash_seed_init(uint32_t &seed)
{
// reject bad seeds
std::vector<uint64_t> bad_seeds;
mirhash_bad_seeds(bad_seeds);
for (uint64_t s : bad_seeds) {
if (s == seed) {
seed++; break;
}
// also all hi ranges
if ((s << 32) & seed) {
seed++; break;
}
}
}
static void mirhash32_seed_init(uint32_t &seed)
{
// reject bad seeds
std::vector<uint32_t> bad_seeds;
mirhash32_bad_seeds(bad_seeds);
while (std::find(bad_seeds.begin(), bad_seeds.end(), (uint32_t)seed) != bad_seeds.end())
seed++;
}
//TODO MSVC
#ifndef _MSC_VER
void tsip_init();
void tsip_test (const void * key, int len, uint32_t seed, void * out);
// objsize 0-207: 519
extern "C" uint64_t tsip(const unsigned char *seed, const unsigned char *m, uint64_t len);
extern "C" uint64_t seahash(const char *key, int len, uint64_t seed);
// objsize 29b0-2d17: 871
inline void seahash_test (const void *key, int len, uint32_t seed, void *out) {
*(uint64_t*)out = seahash((const char *)key, len, (uint64_t)seed);
}
inline void seahash32low (const void *key, int len, uint32_t seed, void *out) {
uint64_t result = seahash((const char *)key, len, (uint64_t)seed);
*(uint32_t*)out = (uint32_t)(UINT64_C(0xffffffff) & result);
}
#endif /* !MSVC */
#endif /* HAVE_INT64 */
//----------
// Cryptographic hashes
#include "md5.h"
inline void md5_128(const void *key, int len, uint32_t seed, void *out) {
md5_context md5_ctx;
md5_starts( &md5_ctx );
md5_ctx.state[0] ^= seed;
md5_update( &md5_ctx, (unsigned char *)key, len );
md5_finish( &md5_ctx, (unsigned char *)out );
//memset( &md5_ctx.buffer, 0, 64+64+64 ); // for buffer, ipad, opad
}
inline void md5_32(const void *key, int len, uint32_t seed, void *out) {
unsigned char hash[16];
md5_context md5_ctx;
md5_starts( &md5_ctx );
md5_ctx.state[0] ^= seed;
md5_update( &md5_ctx, (unsigned char *)key, len );
md5_finish( &md5_ctx, hash );
//memset( &md5_ctx.buffer, 0, 64+64+64 ); // for buffer, ipad, opad
// The "B" state was modified last in the hash round, so return the
// second word of output.
memcpy(out, hash + 4, 4);
}
inline void md5_64(const void *key, int len, uint32_t seed, void *out) {
unsigned char hash[16];
md5_context md5_ctx;
md5_starts( &md5_ctx );
md5_ctx.state[0] ^= seed;
md5_update( &md5_ctx, (unsigned char *)key, len );
md5_finish( &md5_ctx, hash );
//memset( &md5_ctx.buffer, 0, 64+64+64 ); // for buffer, ipad, opad
// The "B" and "C" states were modified last in the hash rounds, so
// return the second and third word of output.
memcpy(out, hash + 4, 8);
}
#include "sha1.h"
inline void sha1_160(const void *key, int len, uint32_t seed, void *out) {
SHA1_CTX context;
SHA1_Init(&context);
context.state[0] ^= seed;
SHA1_Update(&context, (uint8_t*)key, len);
SHA1_Final(&context, SHA1_DIGEST_SIZE, (uint8_t*)out);
}
inline void sha1_32(const void *key, int len, uint32_t seed, void *out) {
SHA1_CTX context;
SHA1_Init(&context);
context.state[0] ^= seed;
SHA1_Update(&context, (uint8_t *)key, len);
SHA1_Final(&context, 4, (uint8_t *)out);
}
inline void sha1_64(const void *key, int len, uint32_t seed, void *out) {
SHA1_CTX context;
SHA1_Init(&context);
context.state[0] ^= seed;
SHA1_Update(&context, (uint8_t *)key, len);
SHA1_Final(&context, 8, (uint8_t *)out);
}
#include "tomcrypt.h"
int blake2b_init(hash_state * md, unsigned long outlen,
const unsigned char *key, unsigned long keylen);
inline void blake2b160_test(const void *key, int len, uint32_t seed, void *out)
{
// objsize
hash_state ltc_state;
blake2b_init(<c_state, 20, NULL, 0);
ltc_state.blake2b.h[0] ^= seed; // mix seed into lowest int
blake2b_process(<c_state, (unsigned char *)key, len);
blake2b_done(<c_state, (unsigned char *)out);
}
inline void blake2b224_test(const void *key, int len, uint32_t seed, void *out)
{
// objsize
hash_state ltc_state;
blake2b_init(<c_state, 28, NULL, 0);
ltc_state.blake2b.h[0] ^= seed;
blake2b_process(<c_state, (unsigned char *)key, len);
blake2b_done(<c_state, (unsigned char *)out);
}
inline void blake2b256_test(const void *key, int len, uint32_t seed, void *out)
{
// objsize
hash_state ltc_state;
blake2b_init(<c_state, 32, NULL, 0);
ltc_state.blake2b.h[0] ^= seed;
blake2b_process(<c_state, (unsigned char *)key, len);
blake2b_done(<c_state, (unsigned char *)out);
}
inline void blake2b256_64(const void *key, int len, uint32_t seed, void *out)
{
// objsize
hash_state ltc_state;
unsigned char buf[32];
blake2b_init(<c_state, 32, NULL, 0);
ltc_state.blake2b.h[0] ^= seed;
blake2b_process(<c_state, (unsigned char *)key, len);
blake2b_done(<c_state, buf);
memcpy(out, buf, 8);
}
int blake2s_init(hash_state * md, unsigned long outlen,
const unsigned char *key, unsigned long keylen);
inline void blake2s128_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize
hash_state ltc_state;
blake2s_init(<c_state, 16, NULL, 0);
ltc_state.blake2s.h[0] ^= seed;
blake2s_process(<c_state, (unsigned char *)key, len);
blake2s_done(<c_state, (unsigned char *)out);
}
inline void blake2s160_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize
hash_state ltc_state;
blake2s_init(<c_state, 20, NULL, 0);
ltc_state.blake2s.h[0] ^= seed;
blake2s_process(<c_state, (unsigned char *)key, len);
blake2s_done(<c_state, (unsigned char *)out);
}
inline void blake2s224_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize
hash_state ltc_state;
blake2s_init(<c_state, 28, NULL, 0);
ltc_state.blake2s.h[0] ^= seed;
blake2s_process(<c_state, (unsigned char *)key, len);
blake2s_done(<c_state, (unsigned char *)out);
}
inline void blake2s256_test(const void * key, int len, uint32_t seed, void * out)
{
// objsize
hash_state ltc_state;
blake2s_init(<c_state, 32, NULL, 0);
ltc_state.blake2s.h[0] ^= seed;
blake2s_process(<c_state, (unsigned char *)key, len);
blake2s_done(<c_state, (unsigned char *)out);
}
inline void blake2s256_64(const void * key, int len, uint32_t seed, void * out)
{
// objsize
hash_state ltc_state;
unsigned char buf[32];
blake2s_init(<c_state, 32, NULL, 0);
ltc_state.blake2s.h[0] ^= seed;
blake2s_process(<c_state, (unsigned char *)key, len);
blake2s_done(<c_state, buf);
memcpy(out, buf, 8);
}
inline void sha2_224(const void *key, int len, uint32_t seed, void *out)
{
// objsize
hash_state ltc_state;
sha224_init(<c_state);
ltc_state.sha256.state[0] ^= seed;
ltc_state.sha256.state[0] += len; // hardened against padding
sha224_process(<c_state, (unsigned char *)key, len);
sha224_done(<c_state, (unsigned char *)out);
}
inline void sha2_224_64(const void *key, int len, uint32_t seed, void *out)
{
// objsize
unsigned char buf[28];
hash_state ltc_state;
sha224_init(<c_state);
ltc_state.sha256.state[0] ^= seed;
ltc_state.sha256.state[0] += len; // hardened against padding
sha224_process(<c_state, (unsigned char *)key, len);
sha224_done(<c_state, buf);
memcpy(out, buf, 8);
}
inline void sha2_256(const void *key, int len, uint32_t seed, void *out)
{
// objsize
hash_state ltc_state;
sha256_init(<c_state);
ltc_state.sha256.state[0] ^= seed;
ltc_state.sha256.state[0] += len; // hardened against padding
sha256_process(<c_state, (unsigned char *)key, len);
sha256_done(<c_state, (unsigned char *)out);
}
inline void sha2_256_64(const void *key, int len, uint32_t seed, void *out)
{
// objsize
unsigned char buf[32];
hash_state ltc_state;
sha256_init(<c_state);
ltc_state.sha256.state[0] ^= seed;
ltc_state.sha256.state[0] += len; // hardened against padding
sha256_process(<c_state, (unsigned char *)key, len);
sha256_done(<c_state, buf);
memcpy(out, buf, 8);
}
inline void rmd128(const void *key, int len, uint32_t seed, void *out)
{
// objsize
hash_state ltc_state;
rmd128_init(<c_state);
ltc_state.rmd128.state[0] ^= seed;
rmd128_process(<c_state, (unsigned char *)key, len);
rmd128_done(<c_state, (unsigned char *)out);
}
inline void rmd160(const void *key, int len, uint32_t seed, void *out)
{
// objsize
hash_state ltc_state;
rmd160_init(<c_state);
ltc_state.rmd160.state[0] = 0x67452301UL ^ seed;
rmd160_process(<c_state, (unsigned char *)key, len);
rmd160_done(<c_state, (unsigned char *)out);
}
inline void rmd256(const void *key, int len, uint32_t seed, void *out)
{
// objsize
hash_state ltc_state;
rmd256_init(<c_state);
ltc_state.rmd256.state[0] ^= seed;
rmd256_process(<c_state, (unsigned char *)key, len);
rmd256_done(<c_state, (unsigned char *)out);
}
#if !defined(__BYTE_ORDER__) || !defined(__ORDER_BIG_ENDIAN__) || !defined(__ORDER_LITTLE_ENDIAN__)
# error __BYTE_ORDER__ and __ORDER_BIG_ENDIAN__ should be defined.
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# undef HAVE_EDONR // BE build fails due to missing rhash_swap_copy_str_to_u32()
#else
# define HAVE_EDONR
#endif
#ifdef HAVE_EDONR
#include "edonr.h"
inline void edonr224(const void *key, int len, uint32_t seed, void *out)
{
// objsize
struct edonr_ctx ctx;
rhash_edonr224_init(&ctx);
ctx.u.data256.hash[0] ^= seed;