@@ -106,7 +106,7 @@ fn test_keys_change_output<T: Hasher>(constructor: impl Fn(u128, u128) -> T) {
106
106
}
107
107
108
108
fn test_input_affect_every_byte < T : Hasher > ( constructor : impl Fn ( u128 , u128 ) -> T ) {
109
- let base = hash_with ( & 0 , constructor ( 0 , 0 ) ) ;
109
+ let base = hash_with ( & 0_u128 , constructor ( 0 , 0 ) ) ;
110
110
for shift in 0 ..16 {
111
111
let mut alternatives = vec ! [ ] ;
112
112
for v in 0 ..256 {
@@ -257,7 +257,6 @@ fn test_single_bit_flip<T: Hasher>(hasher: impl Fn() -> T) {
257
257
let compare_value = hash ( & 0u128 , & hasher) ;
258
258
for pos in 0 ..size {
259
259
let test_value = hash ( & ( 1u128 << pos) , & hasher) ;
260
- dbg ! ( compare_value, test_value) ;
261
260
assert_sufficiently_different ( compare_value, test_value, 2 ) ;
262
261
}
263
262
}
@@ -330,10 +329,14 @@ fn test_padding_doesnot_collide<T: Hasher>(hasher: impl Fn() -> T) {
330
329
fn test_length_extension < T : Hasher > ( hasher : impl Fn ( u128 , u128 ) -> T ) {
331
330
for key in 0 ..256 {
332
331
let h1 = hasher ( key, key) ;
333
- let v1 = hash_with ( & [ 0_u8 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , h1) ;
334
- let h2 = hasher ( key, key) ;
335
- let v2 = hash_with ( & [ 1_u8 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , h2) ;
336
- assert_ne ! ( v1, v2) ;
332
+ let v1 = vec ! [ 0_u8 ; 1 ] ;
333
+ let o1 = hash_with ( & v1, h1) ;
334
+ for len in 2 ..256 {
335
+ let h2 = hasher ( key, key) ;
336
+ let v2 = vec ! [ 0 ; len] ;
337
+ let o2 = hash_with ( & v2, h2) ;
338
+ assert_ne ! ( o1, o2) ;
339
+ }
337
340
}
338
341
}
339
342
@@ -371,6 +374,8 @@ mod fallback_tests {
371
374
372
375
#[ test]
373
376
fn fallback_single_bit_flip ( ) {
377
+ #[ cfg( feature = "specialize" ) ]
378
+ test_single_bit_flip ( || AHasherFixed ( AHasher :: new_with_keys ( 0 , 0 ) ) ) ;
374
379
test_single_bit_flip ( || AHasher :: new_with_keys ( 0 , 0 ) )
375
380
}
376
381
@@ -381,16 +386,22 @@ mod fallback_tests {
381
386
382
387
#[ test]
383
388
fn fallback_all_bytes_matter ( ) {
389
+ #[ cfg( feature = "specialize" ) ]
390
+ test_all_bytes_matter ( || AHasherStr ( AHasher :: new_with_keys ( 0 , 0 ) ) ) ;
384
391
test_all_bytes_matter ( || AHasher :: new_with_keys ( 0 , 0 ) ) ;
385
392
}
386
393
387
394
#[ test]
388
395
fn fallback_test_no_pair_collisions ( ) {
396
+ #[ cfg( feature = "specialize" ) ]
397
+ test_no_pair_collisions ( || AHasherFixed ( AHasher :: new_with_keys ( 0 , 0 ) ) ) ;
389
398
test_no_pair_collisions ( || AHasher :: new_with_keys ( 0 , 0 ) ) ;
390
399
}
391
400
392
401
#[ test]
393
402
fn fallback_test_no_full_collisions ( ) {
403
+ #[ cfg( feature = "specialize" ) ]
404
+ test_no_full_collisions ( || AHasherStr ( AHasher :: new_with_keys ( 0 , 0 ) ) ) ;
394
405
test_no_full_collisions ( || AHasher :: new_with_keys ( 0 , 0 ) ) ;
395
406
}
396
407
@@ -401,6 +412,8 @@ mod fallback_tests {
401
412
402
413
#[ test]
403
414
fn fallback_input_affect_every_byte ( ) {
415
+ #[ cfg( feature = "specialize" ) ]
416
+ test_input_affect_every_byte ( |a, b| AHasherFixed ( AHasher :: new_with_keys ( a, b) ) ) ;
404
417
test_input_affect_every_byte ( AHasher :: new_with_keys) ;
405
418
}
406
419
@@ -415,6 +428,8 @@ mod fallback_tests {
415
428
416
429
#[ test]
417
430
fn fallback_finish_is_consistant ( ) {
431
+ #[ cfg( feature = "specialize" ) ]
432
+ test_finish_is_consistent ( |a, b| AHasherStr ( AHasher :: test_with_keys ( a, b) ) ) ;
418
433
test_finish_is_consistent ( AHasher :: test_with_keys)
419
434
}
420
435
@@ -424,17 +439,31 @@ mod fallback_tests {
424
439
test_padding_doesnot_collide ( || AHasher :: new_with_keys ( 0 , 2 ) ) ;
425
440
test_padding_doesnot_collide ( || AHasher :: new_with_keys ( 2 , 0 ) ) ;
426
441
test_padding_doesnot_collide ( || AHasher :: new_with_keys ( 2 , 2 ) ) ;
442
+ #[ cfg( feature = "specialize" ) ]
443
+ {
444
+ test_padding_doesnot_collide ( || AHasherStr ( AHasher :: new_with_keys ( 0 , 0 ) ) ) ;
445
+ test_padding_doesnot_collide ( || AHasherStr ( AHasher :: new_with_keys ( 0 , 2 ) ) ) ;
446
+ test_padding_doesnot_collide ( || AHasherStr ( AHasher :: new_with_keys ( 2 , 0 ) ) ) ;
447
+ test_padding_doesnot_collide ( || AHasherStr ( AHasher :: new_with_keys ( 2 , 2 ) ) ) ;
448
+ }
427
449
}
428
450
429
451
#[ test]
430
452
fn fallback_length_extension ( ) {
453
+ #[ cfg( feature = "specialize" ) ]
454
+ test_length_extension ( |a, b| AHasherStr ( AHasher :: new_with_keys ( a, b) ) ) ;
431
455
test_length_extension ( |a, b| AHasher :: new_with_keys ( a, b) ) ;
432
456
}
433
457
434
458
#[ test]
435
459
fn test_no_sparse_collisions ( ) {
436
460
test_sparse ( || AHasher :: new_with_keys ( 0 , 0 ) ) ;
437
461
test_sparse ( || AHasher :: new_with_keys ( 1 , 2 ) ) ;
462
+ #[ cfg( feature = "specialize" ) ]
463
+ {
464
+ test_sparse ( || AHasherStr ( AHasher :: new_with_keys ( 0 , 0 ) ) ) ;
465
+ test_sparse ( || AHasherStr ( AHasher :: new_with_keys ( 1 , 2 ) ) ) ;
466
+ }
438
467
}
439
468
}
440
469
@@ -449,7 +478,7 @@ mod aes_tests {
449
478
use crate :: aes_hash:: * ;
450
479
use crate :: hash_quality_test:: * ;
451
480
use std:: hash:: { Hash , Hasher } ;
452
-
481
+
453
482
//This encrypts to 0.
454
483
const BAD_KEY2 : u128 = 0x6363_6363_6363_6363_6363_6363_6363_6363 ;
455
484
//This decrypts to 0.
@@ -466,40 +495,77 @@ mod aes_tests {
466
495
467
496
#[ test]
468
497
fn aes_single_bit_flip ( ) {
498
+ test_single_bit_flip ( || AHasher :: test_with_keys ( 0 , 0 ) ) ;
469
499
test_single_bit_flip ( || AHasher :: test_with_keys ( BAD_KEY , BAD_KEY ) ) ;
470
500
test_single_bit_flip ( || AHasher :: test_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ;
501
+ #[ cfg( feature = "specialize" ) ]
502
+ {
503
+ test_single_bit_flip ( || AHasherFixed ( AHasher :: test_with_keys ( 0 , 0 ) ) ) ;
504
+ test_single_bit_flip ( || AHasherFixed ( AHasher :: test_with_keys ( BAD_KEY , BAD_KEY ) ) ) ;
505
+ test_single_bit_flip ( || AHasherFixed ( AHasher :: test_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ) ;
506
+ }
471
507
}
472
508
473
509
#[ test]
474
510
fn aes_single_key_bit_flip ( ) {
475
- test_single_key_bit_flip ( AHasher :: test_with_keys)
511
+ test_single_key_bit_flip ( AHasher :: test_with_keys) ;
512
+ #[ cfg( feature = "specialize" ) ]
513
+ {
514
+ test_single_key_bit_flip ( |a, b| AHasherStr ( AHasher :: test_with_keys ( a, b) ) ) ;
515
+ }
476
516
}
477
517
478
518
#[ test]
479
519
fn aes_all_bytes_matter ( ) {
520
+ test_all_bytes_matter ( || AHasher :: test_with_keys ( 0 , 0 ) ) ;
480
521
test_all_bytes_matter ( || AHasher :: test_with_keys ( BAD_KEY , BAD_KEY ) ) ;
481
522
test_all_bytes_matter ( || AHasher :: test_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ;
523
+ #[ cfg( feature = "specialize" ) ]
524
+ {
525
+ test_all_bytes_matter ( || AHasherStr ( AHasher :: test_with_keys ( 0 , 0 ) ) ) ;
526
+ test_all_bytes_matter ( || AHasherStr ( AHasher :: test_with_keys ( BAD_KEY , BAD_KEY ) ) ) ;
527
+ test_all_bytes_matter ( || AHasherStr ( AHasher :: test_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ) ;
528
+ }
482
529
}
483
530
484
531
#[ test]
485
532
fn aes_test_no_pair_collisions ( ) {
533
+ test_no_pair_collisions ( || AHasher :: test_with_keys ( 0 , 0 ) ) ;
486
534
test_no_pair_collisions ( || AHasher :: test_with_keys ( BAD_KEY , BAD_KEY ) ) ;
487
535
test_no_pair_collisions ( || AHasher :: test_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ;
536
+ #[ cfg( feature = "specialize" ) ]
537
+ {
538
+ test_no_pair_collisions ( || AHasherFixed ( AHasher :: test_with_keys ( 0 , 0 ) ) ) ;
539
+ test_no_pair_collisions ( || AHasherFixed ( AHasher :: test_with_keys ( BAD_KEY , BAD_KEY ) ) ) ;
540
+ test_no_pair_collisions ( || AHasherFixed ( AHasher :: test_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ) ;
541
+ }
488
542
}
489
543
490
544
#[ test]
491
545
fn ase_test_no_full_collisions ( ) {
492
546
test_no_full_collisions ( || AHasher :: test_with_keys ( 12345 , 67890 ) ) ;
547
+ #[ cfg( feature = "specialize" ) ]
548
+ {
549
+ test_no_full_collisions ( || AHasherStr ( AHasher :: test_with_keys ( 12345 , 67890 ) ) ) ;
550
+ }
493
551
}
494
552
495
553
#[ test]
496
554
fn aes_keys_change_output ( ) {
497
555
test_keys_change_output ( AHasher :: test_with_keys) ;
556
+ #[ cfg( feature = "specialize" ) ]
557
+ {
558
+ test_keys_change_output ( |a, b| AHasherStr ( AHasher :: test_with_keys ( a, b) ) ) ;
559
+ }
498
560
}
499
561
500
562
#[ test]
501
563
fn aes_input_affect_every_byte ( ) {
502
564
test_input_affect_every_byte ( AHasher :: test_with_keys) ;
565
+ #[ cfg( feature = "specialize" ) ]
566
+ {
567
+ test_input_affect_every_byte ( |a, b| AHasherFixed ( AHasher :: test_with_keys ( a, b) ) ) ;
568
+ }
503
569
}
504
570
505
571
#[ test]
@@ -512,23 +578,43 @@ mod aes_tests {
512
578
513
579
#[ test]
514
580
fn aes_finish_is_consistant ( ) {
515
- test_finish_is_consistent ( AHasher :: test_with_keys)
581
+ test_finish_is_consistent ( AHasher :: test_with_keys) ;
582
+ #[ cfg( feature = "specialize" ) ]
583
+ {
584
+ test_finish_is_consistent ( |a, b| AHasherStr ( AHasher :: test_with_keys ( a, b) ) ) ;
585
+ }
516
586
}
517
587
518
588
#[ test]
519
589
fn aes_padding_doesnot_collide ( ) {
590
+ test_padding_doesnot_collide ( || AHasher :: test_with_keys ( 0 , 0 ) ) ;
520
591
test_padding_doesnot_collide ( || AHasher :: test_with_keys ( BAD_KEY , BAD_KEY ) ) ;
521
592
test_padding_doesnot_collide ( || AHasher :: test_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ;
593
+ #[ cfg( feature = "specialize" ) ]
594
+ {
595
+ test_padding_doesnot_collide ( || AHasherStr ( AHasher :: test_with_keys ( 0 , 0 ) ) ) ;
596
+ test_padding_doesnot_collide ( || AHasherStr ( AHasher :: test_with_keys ( BAD_KEY , BAD_KEY ) ) ) ;
597
+ test_padding_doesnot_collide ( || AHasherStr ( AHasher :: test_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ) ;
598
+ }
522
599
}
523
600
524
601
#[ test]
525
602
fn aes_length_extension ( ) {
526
603
test_length_extension ( |a, b| AHasher :: test_with_keys ( a, b) ) ;
604
+ #[ cfg( feature = "specialize" ) ]
605
+ {
606
+ test_length_extension ( |a, b| AHasherStr ( AHasher :: test_with_keys ( a, b) ) ) ;
607
+ }
527
608
}
528
609
529
610
#[ test]
530
611
fn aes_no_sparse_collisions ( ) {
531
612
test_sparse ( || AHasher :: test_with_keys ( 0 , 0 ) ) ;
532
613
test_sparse ( || AHasher :: test_with_keys ( 1 , 2 ) ) ;
614
+ #[ cfg( feature = "specialize" ) ]
615
+ {
616
+ test_sparse ( || AHasherStr ( AHasher :: test_with_keys ( 0 , 0 ) ) ) ;
617
+ test_sparse ( || AHasherStr ( AHasher :: test_with_keys ( 1 , 2 ) ) ) ;
618
+ }
533
619
}
534
620
}
0 commit comments