forked from rurban/smhasher
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Hashes.h
980 lines (906 loc) · 34.6 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
#pragma once
#include "Platform.h"
#include "Types.h"
#include "MurmurHash1.h"
#include "MurmurHash2.h"
#include "MurmurHash3.h"
#include "PMurHash.h"
#define XXH_INLINE_ALL
#include "xxhash.h"
#include "metrohash/metrohash64.h"
#include "metrohash/metrohash128.h"
#include "cmetrohash.h"
#include "opt_cmetrohash.h"
#if defined(__SSE4_2__) && defined(__x86_64__)
#include "metrohash/metrohash64crc.h"
#include "metrohash/metrohash128crc.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 "vmac.h"
//----------
// These are _not_ hash functions (even though people tend to use crc32 as one...)
void BadHash(const void *key, int len, uint32_t seed, void *out);
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);
//----------
// General purpose hashes
#ifdef __SSE2__
void hasshe2_test(const void *key, int len, uint32_t seed, void *out);
#endif
#if defined(__SSE4_2__) && defined(__x86_64__)
void crc32c_hw_test(const void *key, int len, uint32_t seed, void *out);
void crc32c_hw1_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(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. */
extern "C" uint32_t crc32_pclmul_le_16(unsigned char const *buffer, size_t len,
uint32_t crc32);
inline void crc32c_pclmul_test(const void *key, int len, uint32_t seed, void *out)
{
if (!len) {
*(uint32_t *) out = 0;
return;
}
// objsize: 0x1e1 = 481
#ifdef NDEBUG
if (((uintptr_t)key & 15) != 0) {
#if 0 // slower
if (len < 1024) {
unsigned char input[1024];
memcpy((void*)input, key, len);
*(uint32_t *) out = crc32_pclmul_le_16(input, (size_t)len, seed);
}
else
#endif
{
unsigned char const *input = (unsigned char const *)malloc(len);
memcpy((void*)input, key, len);
*(uint32_t *) out = crc32_pclmul_le_16(input, (size_t)len, seed);
free ((void*)input);
}
}
#else
assert(((uintptr_t)key & 15) == 0); // input must be 16byte aligned
*(uint32_t *) out = crc32_pclmul_le_16((unsigned char const *)key, (size_t)len, seed);
#endif
}
void CityHashCrc64_test(const void *key, int len, uint32_t seed, void *out);
void CityHashCrc128_test(const void *key, int len, uint32_t seed, void *out);
void falkhash_test_cxx(const void *key, int len, uint32_t seed, void *out);
#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);
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);
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
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);
}
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);
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);
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 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, int32_t hash);
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 );
//----------
// 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
inline void MurmurHash64B_test ( const void * key, int len, uint32_t seed, void * out )
{
*(uint64_t*)out = MurmurHash64B(key,len,seed);
}
#endif
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((const 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);
}
#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);
}
#endif
#define restrict // oddly enough, seems to choke on this keyword
#include "xxh3.h"
#ifdef HAVE_INT64
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 ) {
(void)seed;
// 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(__SSE4_2__) && defined(__x86_64__)
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);
}
#endif
// objsize 0-778: 1912
void mum_hash_test(const void * key, int len, uint32_t seed, void * out);
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(__SSE4_2__) && defined(__x86_64__)
#include "clhash.h"
void clhash_init();
void clhash_test (const void * key, int len, uint32_t seed, void * out);
#endif
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 HighwayHash_init();
// objsize 20-a12: 2546
void HighwayHash64_test (const void * key, int len, uint32_t seed, void * out);
#ifdef HAVE_INT64
//https://github.com/wangyi-fudan/wyhash
#include "wyhash.h"
// objsize 40c8f0-40cc9a: 938
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 407630-4079ca: 922
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);
}
// fixed to be seeded a bit, and to avoid mult. blinding. Still too bad for Diff test
inline void FastestHash_test (const void * key, int len, uint32_t seed, void * out) {
*(uint64_t*)out = FastestHash(key, (size_t)len, (uint64_t)seed);
}
//https://github.com/vnmakarov/mir/blob/master/mir-hash.h
#include "mir-hash.h"
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);
}
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);
}
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);
}
//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 ctx;
md5_starts( &ctx );
ctx.state[0] ^= seed;
md5_update( &ctx, (unsigned char *)key, len );
md5_finish( &ctx, (unsigned char *)out );
//memset( &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 ctx;
md5_starts( &ctx );
ctx.state[0] ^= seed;
md5_update( &ctx, (unsigned char *)key, len );
md5_finish( &ctx, hash );
//memset( &ctx.buffer, 0, 64+64+64 ); // for buffer, ipad, opad
memcpy(out, hash, 4);
}
#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, (uint8_t*)out);
}
void SHA1_Update(SHA1_CTX *context, const uint8_t *data, const size_t len);
inline void sha1_32a(const void *key, int len, uint32_t seed, void *out) {
SHA1_CTX context;
uint8_t *digest = (uint8_t *)out;
SHA1_Init(&context);
context.state[0] ^= seed;
SHA1_Update(&context, (uint8_t *)key, len);
//SHA1_Final(&context, digest); //inlined below
//memcpy(out, digest, 4);
unsigned i;
uint8_t finalcount[8];
uint8_t c;
for (i = 0; i < 8; i++) {
finalcount[i] =
/* Endian independent */
(uint8_t)(context.count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8));
}
c = 0200;
SHA1_Update(&context, &c, 1);
while ((context.count[0] & 504) != 448) {
c = 0000;
SHA1_Update(&context, &c, 1);
}
SHA1_Update(&context, finalcount, 8); /* Should cause a SHA1_Transform() */
for (i = 0; i < 4; i++) { // only the needed bytes
digest[i] = (uint8_t)(context.state[i >> 2] >> ((3 - (i & 3)) * 8));
}
}
#include "tomcrypt.h"
#ifndef _MAIN_CPP
extern
#endif
hash_state ltc_state;
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
blake2b_init(<c_state, 20, NULL, 0);
ltc_state.blake2b.h[0] = CONST64(0x6a09e667f3bcc908) ^ 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
blake2b_init(<c_state, 28, NULL, 0);
ltc_state.blake2b.h[0] = CONST64(0x6a09e667f3bcc908) ^ 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
blake2b_init(<c_state, 32, NULL, 0);
ltc_state.blake2b.h[0] = CONST64(0x6a09e667f3bcc908) ^ 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
unsigned char buf[32];
blake2b_init(<c_state, 32, NULL, 0);
ltc_state.blake2b.h[0] = CONST64(0x6a09e667f3bcc908) ^ 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
blake2s_init(<c_state, 16, NULL, 0);
ltc_state.blake2s.h[0] = 0x6A09E667UL ^ 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
blake2s_init(<c_state, 20, NULL, 0);
ltc_state.blake2s.h[0] = 0x6A09E667UL ^ 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
blake2s_init(<c_state, 28, NULL, 0);
ltc_state.blake2s.h[0] = 0x6A09E667UL ^ 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
blake2s_init(<c_state, 32, NULL, 0);
ltc_state.blake2s.h[0] = 0x6A09E667UL ^ 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
unsigned char buf[32];
blake2s_init(<c_state, 32, NULL, 0);
ltc_state.blake2s.h[0] = 0x6A09E667UL ^ 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
unsigned char buf[28];
sha224_init(<c_state);
ltc_state.sha256.state[0] = 0xc1059ed8UL ^ seed;
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];
sha224_init(<c_state);
ltc_state.sha256.state[0] = 0xc1059ed8UL ^ seed;
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
sha256_init(<c_state);
ltc_state.sha256.state[0] = 0x6A09E667UL ^ seed;
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];
sha256_init(<c_state);
ltc_state.sha256.state[0] = 0x6A09E667UL ^ seed;
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
rmd128_init(<c_state);
ltc_state.rmd128.state[0] = 0x67452301UL ^ 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
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
rmd256_init(<c_state);
ltc_state.rmd256.state[0] = 0x67452301UL ^ seed;
rmd256_process(<c_state, (unsigned char *)key, len);
rmd256_done(<c_state, (unsigned char *)out);
}
// Keccak:
inline void sha3_256_64(const void *key, int len, uint32_t seed, void *out)
{
// objsize
unsigned char buf[32];
sha3_256_init(<c_state);
ltc_state.sha3.s[0] = CONST64(1) ^ seed;
sha3_process(<c_state, (unsigned char *)key, len);
sha3_done(<c_state, buf);
memcpy(out, buf, 8);
}
inline void sha3_256(const void *key, int len, uint32_t seed, void *out)
{
// objsize
unsigned char buf[32];
sha3_256_init(<c_state);
ltc_state.sha3.s[0] = CONST64(1) ^ seed;
sha3_process(<c_state, (unsigned char *)key, len);
sha3_done(<c_state, (unsigned char *)out);
}
inline void wysha(const void *key, int len, unsigned seed, void *out) {
uint64_t s[4] = {wyhash(key, len, seed + 0, _wyp), wyhash(key, len, seed + 1, _wyp),
wyhash(key, len, seed + 2, _wyp), wyhash(key, len, seed + 3, _wyp)};
memcpy(out, s, 32);
}
#if defined(HAVE_AESNI) && defined(__SIZEOF_INT128__)
#include "meow_hash_x64_aesni.h"
// objsize: 0x84b0-8b94 = 1764
inline void MeowHash128_test(const void *key, int len, unsigned seed, void *out) {
*(int unsigned *)MeowDefaultSeed = seed;
meow_u128 h = MeowHash(MeowDefaultSeed, (meow_umm)len, (void*)key);
((uint64_t *)out)[0] = MeowU64From(h, 0);
((uint64_t *)out)[1] = MeowU64From(h, 1);
}
inline void MeowHash32_test(const void *key, int len, unsigned seed, void *out) {
*(int unsigned *)MeowDefaultSeed = seed;
meow_u128 h = MeowHash(MeowDefaultSeed, (meow_umm)len, (void*)key);
*(uint32_t *)out = MeowU32From(h, 0);
}
#endif
#if defined(HAVE_SHANI) && defined(__x86_64__)
extern "C" void sha1_process_x86(uint32_t *state, const uint8_t *data, uint32_t length);
extern "C" void sha256_process_x86(uint32_t *state, const uint8_t *data, uint32_t length);
// Note: improved native SHA functions with seed.
// These functions need to be padded to 64byte blocks, so its trivial to create max
// 64 collisions for each key.
inline void sha1ni(const void *key, int len, uint32_t seed, void *out)
{
// objsize: 0x2c1 + this (0x408bac - 0x408a90) = 989
uint32_t state[5] = {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0};
state[0] = 0x67452301U ^ seed;
if (len < 64) {
uint8_t padded[64];
memcpy (padded, key, len);
memset (&padded[len], 0, 64-len);
sha1_process_x86(state, (const uint8_t*)padded, 64);
} else if (len % 64) {
uint32_t lenpadded = len + (64 - len % 64);
uint8_t *padded = (uint8_t*)malloc (lenpadded);
memcpy (padded, key, len);
memset (&padded[len], 0, lenpadded-len);
sha1_process_x86(state, (const uint8_t*)padded, lenpadded);
free (padded);
} else {
sha1_process_x86(state, (const uint8_t*)key, (uint32_t)len);
}
memcpy(out, state, 20);
}
// Note: improved native SHA functions with seed and len encoded into the seed, to prevent Zeroes.
// These functions need to be padded to 64byte blocks, so it would be trivial to create max
// 64 collisions for each key.
inline void sha1ni_32(const void *key, int len, uint32_t seed, void *out)
{
uint32_t state[5] = {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0};
state[0] = 0x67452301U ^ seed;
if (len < 64) {
uint8_t padded[64];
memcpy (padded, key, len);
memset (&padded[len], 0, 64-len);
state[0] += len;
sha1_process_x86(state, (const uint8_t*)padded, 64);
} else if (len % 64) {
uint32_t lenpadded = len + (64 - len % 64);
uint8_t *padded = (uint8_t*)malloc (lenpadded);
memcpy (padded, key, len);
memset (&padded[len], 0, lenpadded-len);
state[0] += len;
sha1_process_x86(state, (const uint8_t*)padded, lenpadded);
free (padded);
} else {
sha1_process_x86(state, (const uint8_t*)key, (uint32_t)len);
}
*(uint32_t *)out = *(uint32_t *)state;
}
inline void sha2ni_256(const void *key, int len, uint32_t seed, void *out)
{
// objsize: 0x2f1 + this (0x4095c0-0x408820) = 4241
uint32_t state[8] = {
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
};
state[0] = 0x6a09e667U ^ seed;
if (len < 64) {
uint8_t padded[64];
memcpy (padded, key, len);
memset (&padded[len], 0, 64-len);
//state[0] += len; to prevent Zeroes
sha256_process_x86(state, (const uint8_t*)padded, 64);
} else if (len % 64) {
uint32_t lenpadded = len + (64 - len % 64);
uint8_t *padded = (uint8_t*)malloc (lenpadded);
memcpy (padded, key, len);
memset (&padded[len], 0, lenpadded-len);
//state[0] += len;
sha256_process_x86(state, (const uint8_t*)padded, lenpadded);
free (padded);
} else {
sha256_process_x86(state, (const uint8_t*)key, (uint32_t)len);
}
memcpy(out, state, 32);
}
inline void sha2ni_256_64(const void *key, int len, uint32_t seed, void *out)
{
uint32_t state[8] = {
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
};
state[0] = 0x6a09e667U ^ seed;
if (len < 64) {
uint8_t padded[64];
memcpy (padded, key, len);
memset (&padded[len], 0, 64-len);
state[0] += len;
sha256_process_x86(state, (const uint8_t*)padded, 64);
} else if (len % 64) {
uint32_t lenpadded = len + (64 - len % 64);
uint8_t *padded = (uint8_t*)malloc (lenpadded);
memcpy (padded, key, len);
memset (&padded[len], 0, lenpadded-len);
state[0] += len;
sha256_process_x86(state, (const uint8_t*)padded, lenpadded);
free (padded);
} else {
sha256_process_x86(state, (const uint8_t*)key, (uint32_t)len);
}
*(uint64_t *)out = *(uint64_t *)state;
}
#endif
#ifdef _MAIN_CPP
#include "farsh.h"
#else
#ifdef __AVX2__
#define FARSH_AVX2
#elif defined HAVE_SSE42
#define FARSH_SSE2
#endif
#include "farsh.c"
#endif
// objsize: 0-3b0: 944
inline void farsh32_test ( const void * key, int len, unsigned seed, void * out )
{
farsh_n(key,len,0,1,seed,out);
}
inline void farsh64_test ( const void * key, int len, unsigned seed, void * out )
{
farsh_n(key,len,0,2,seed,out);
}
inline void farsh128_test ( const void * key, int len, unsigned seed, void * out )
{
farsh_n(key,len,0,4,seed,out);
}
inline void farsh256_test ( const void * key, int len, unsigned seed, void * out )
{
farsh_n(key,len,0,8,seed,out);
}
extern "C" {
#include "blake3/blake3_impl.h"
// The C API, serially
inline void blake3c_test ( const void * key, int len, unsigned seed, void * out )
{
blake3_hasher hasher;
blake3_hasher_init (&hasher);
// mix-in seed. key0 is not enough to pass MomentChi2. but even mixing all does not help
//for (int i = 0; i < 8; i++)
// hasher.key[i] ^= (uint32_t)seed;
hasher.key[0] ^= (uint32_t)seed;
blake3_hasher_update (&hasher, (uint8_t*)key, (size_t)len);
blake3_hasher_finalize (&hasher, (uint8_t*)out, BLAKE3_OUT_LEN);
}
}
#ifdef HAVE_BLAKE3
// The Rust API, parallized
typedef struct rust_array {
char *ptr;
size_t len;
} rs_arr;
extern "C" rs_arr *blake3_hash (const rs_arr *input);
inline void blake3_test ( const void * key, int len, unsigned seed, void * out )
{
rs_arr input;
rs_arr *result;
input.ptr = (char*)key;
input.len = (size_t)len;
result = blake3_hash (&input);
memcpy (out, result->ptr, 32);
}
inline void blake3_64 ( const void * key, int len, unsigned seed, void * out )
{
rs_arr input;
rs_arr *result;
input.ptr = (char*)key;
input.len = (size_t)len;
result = blake3_hash (&input);
*(uint64_t *)out = *(uint64_t *)result->ptr;
}
#endif
//64 objsize: a50-f69: 1305
//32 objsize: 1680-1abc: 1084
#ifndef DEBUG
#include "PMP_Multilinear_test.h"
#endif
#include "beamsplitter.h"
#include "discohash.h"
#ifdef HAVE_AESNI
/* https://gist.github.com/majek/96dd615ed6c8aa64f60aac14e3f6ab5a */
uint64_t aesnihash(uint8_t *in, unsigned long src_sz);
inline void aesnihash_test ( const void * key, int len, unsigned seed, void * out )
{
uint64_t result = aesnihash ((uint8_t *)key, (unsigned long)len);
*(uint64_t *)out = result;
}
#endif