@@ -93,7 +93,7 @@ fn test_no_full_collisions<T: Hasher>(gen_hash: impl Fn() -> T) {
93
93
assert_eq ! ( 2396744 , map. len( ) ) ;
94
94
}
95
95
96
- fn test_keys_change_output < T : HasherExt > ( constructor : impl Fn ( u64 , u64 ) -> T ) {
96
+ fn test_keys_change_output < T : HasherExt > ( constructor : impl Fn ( u128 , u128 ) -> T ) {
97
97
let mut a = constructor ( 1 , 1 ) ;
98
98
let mut b = constructor ( 1 , 2 ) ;
99
99
let mut c = constructor ( 2 , 1 ) ;
@@ -110,7 +110,7 @@ fn test_keys_change_output<T: HasherExt>(constructor: impl Fn(u64, u64) -> T) {
110
110
assert_sufficiently_different ( c. finish ( ) , d. finish ( ) , 1 ) ;
111
111
}
112
112
113
- fn test_input_affect_every_byte < T : HasherExt > ( constructor : impl Fn ( u64 , u64 ) -> T ) {
113
+ fn test_input_affect_every_byte < T : HasherExt > ( constructor : impl Fn ( u128 , u128 ) -> T ) {
114
114
let base = 0 . get_hash ( constructor ( 0 , 0 ) ) ;
115
115
for shift in 0 ..16 {
116
116
let mut alternitives = vec ! [ ] ;
@@ -124,13 +124,13 @@ fn test_input_affect_every_byte<T: HasherExt>(constructor: impl Fn(u64, u64) ->
124
124
}
125
125
126
126
///Ensures that for every bit in the output there is some value for each byte in the key that flips it.
127
- fn test_keys_affect_every_byte < H : Hash , T : HasherExt > ( item : H , constructor : impl Fn ( u64 , u64 ) -> T ) {
127
+ fn test_keys_affect_every_byte < H : Hash , T : HasherExt > ( item : H , constructor : impl Fn ( u128 , u128 ) -> T ) {
128
128
let base = item. get_hash ( constructor ( 0 , 0 ) ) ;
129
- for shift in 0 ..8 {
129
+ for shift in 0 ..16 {
130
130
let mut alternitives1 = vec ! [ ] ;
131
131
let mut alternitives2 = vec ! [ ] ;
132
132
for v in 0 ..256 {
133
- let input = ( v as u64 ) << ( shift * 8 ) ;
133
+ let input = ( v as u128 ) << ( shift * 8 ) ;
134
134
let hasher1 = constructor ( input, 0 ) ;
135
135
let hasher2 = constructor ( 0 , input) ;
136
136
let h1 = item. get_hash ( hasher1) ;
@@ -151,16 +151,16 @@ fn assert_each_byte_differs(base: u64, alternitives: Vec<u64>) {
151
151
assert_eq ! ( core:: u64 :: MAX , changed_bits, "Bits changed: {:x}" , changed_bits) ;
152
152
}
153
153
154
- fn test_finish_is_consistent < T : Hasher > ( constructor : impl Fn ( u64 , u64 ) -> T ) {
154
+ fn test_finish_is_consistent < T : Hasher > ( constructor : impl Fn ( u128 , u128 ) -> T ) {
155
155
let mut hasher = constructor ( 1 , 2 ) ;
156
156
"Foo" . hash ( & mut hasher) ;
157
157
let a = hasher. finish ( ) ;
158
158
let b = hasher. finish ( ) ;
159
159
assert_eq ! ( a, b) ;
160
160
}
161
161
162
- fn test_single_key_bit_flip < T : Hasher > ( constructor : impl Fn ( u64 , u64 ) -> T ) {
163
- for bit in 0 ..64 {
162
+ fn test_single_key_bit_flip < T : Hasher > ( constructor : impl Fn ( u128 , u128 ) -> T ) {
163
+ for bit in 0 ..128 {
164
164
let mut a = constructor ( 0 , 0 ) ;
165
165
let mut b = constructor ( 0 , 1 << bit) ;
166
166
let mut c = constructor ( 1 << bit, 0 ) ;
@@ -320,57 +320,58 @@ mod fallback_tests {
320
320
321
321
#[ test]
322
322
fn fallback_single_bit_flip ( ) {
323
- test_single_bit_flip ( || AHasher :: test_with_keys ( 0 , 0 ) )
323
+ test_single_bit_flip ( || AHasher :: new_with_keys ( 0 , 0 ) )
324
324
}
325
325
326
326
#[ test]
327
327
fn fallback_single_key_bit_flip ( ) {
328
- test_single_key_bit_flip ( AHasher :: test_with_keys )
328
+ test_single_key_bit_flip ( AHasher :: new_with_keys )
329
329
}
330
330
331
331
#[ test]
332
332
fn fallback_all_bytes_matter ( ) {
333
- test_all_bytes_matter ( || AHasher :: test_with_keys ( 0 , 0 ) ) ;
333
+ test_all_bytes_matter ( || AHasher :: new_with_keys ( 0 , 0 ) ) ;
334
334
}
335
335
336
336
#[ test]
337
337
fn fallback_test_no_pair_collisions ( ) {
338
- test_no_pair_collisions ( || AHasher :: test_with_keys ( 0 , 0 ) ) ;
338
+ test_no_pair_collisions ( || AHasher :: new_with_keys ( 0 , 0 ) ) ;
339
339
}
340
340
341
341
#[ test]
342
342
fn fallback_test_no_full_collisions ( ) {
343
- test_no_full_collisions ( || AHasher :: test_with_keys ( 12345 , 67890 ) ) ;
343
+ test_no_full_collisions ( || AHasher :: new_with_keys ( 12345 , 67890 ) ) ;
344
344
}
345
345
346
346
#[ test]
347
347
fn fallback_keys_change_output ( ) {
348
- test_keys_change_output ( AHasher :: test_with_keys ) ;
348
+ test_keys_change_output ( AHasher :: new_with_keys ) ;
349
349
}
350
350
351
351
#[ test]
352
352
fn fallback_input_affect_every_byte ( ) {
353
- test_input_affect_every_byte ( AHasher :: test_with_keys ) ;
353
+ test_input_affect_every_byte ( AHasher :: new_with_keys ) ;
354
354
}
355
355
356
356
#[ test]
357
357
fn fallback_keys_affect_every_byte ( ) {
358
- test_keys_affect_every_byte ( 0 , AHasher :: test_with_keys) ;
359
- test_keys_affect_every_byte ( "" , AHasher :: test_with_keys) ;
360
- test_keys_affect_every_byte ( ( 0 , 0 ) , AHasher :: test_with_keys) ;
358
+ //For fallback second key is not used in every hash.
359
+ test_keys_affect_every_byte ( 0 , |a, b| AHasher :: new_with_keys ( a ^ b, a) ) ;
360
+ test_keys_affect_every_byte ( "" , |a, b| AHasher :: new_with_keys ( a ^ b, a) ) ;
361
+ test_keys_affect_every_byte ( ( 0 , 0 ) , |a, b| AHasher :: new_with_keys ( a ^ b, a) ) ;
361
362
}
362
363
363
364
#[ test]
364
365
fn fallback_finish_is_consistant ( ) {
365
- test_finish_is_consistent ( AHasher :: test_with_keys )
366
+ test_finish_is_consistent ( AHasher :: new_with_keys )
366
367
}
367
368
368
369
#[ test]
369
370
fn fallback_padding_doesnot_collide ( ) {
370
- test_padding_doesnot_collide ( || AHasher :: test_with_keys ( 0 , 0 ) ) ;
371
- test_padding_doesnot_collide ( || AHasher :: test_with_keys ( 0 , 1 ) ) ;
372
- test_padding_doesnot_collide ( || AHasher :: test_with_keys ( 1 , 0 ) ) ;
373
- test_padding_doesnot_collide ( || AHasher :: test_with_keys ( 1 , 1 ) ) ;
371
+ test_padding_doesnot_collide ( || AHasher :: new_with_keys ( 0 , 0 ) ) ;
372
+ test_padding_doesnot_collide ( || AHasher :: new_with_keys ( 0 , 1 ) ) ;
373
+ test_padding_doesnot_collide ( || AHasher :: new_with_keys ( 1 , 0 ) ) ;
374
+ test_padding_doesnot_collide ( || AHasher :: new_with_keys ( 1 , 1 ) ) ;
374
375
}
375
376
}
376
377
@@ -382,8 +383,8 @@ mod aes_tests {
382
383
use crate :: hash_quality_test:: * ;
383
384
use std:: hash:: { Hash , Hasher } ;
384
385
385
- const BAD_KEY : u64 = 0x5252_5252_5252_5252 ; //This encrypts to 0.
386
- const BAD_KEY2 : u64 = 0x6363_6363_6363_6363 ; //This decrypts to 0.
386
+ const BAD_KEY : u128 = 0x5252_5252_5252_5252_5252_5252_5252_5252 ; //This encrypts to 0.
387
+ const BAD_KEY2 : u128 = 0x6363_6363_6363_6363_6363_6363_6363_6363 ; //This decrypts to 0.
387
388
388
389
#[ test]
389
390
fn test_single_bit_in_byte ( ) {
@@ -396,56 +397,56 @@ mod aes_tests {
396
397
397
398
#[ test]
398
399
fn aes_single_bit_flip ( ) {
399
- test_single_bit_flip ( || AHasher :: test_with_keys ( BAD_KEY , BAD_KEY ) ) ;
400
- test_single_bit_flip ( || AHasher :: test_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ;
400
+ test_single_bit_flip ( || AHasher :: new_with_keys ( BAD_KEY , BAD_KEY ) ) ;
401
+ test_single_bit_flip ( || AHasher :: new_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ;
401
402
}
402
403
403
404
#[ test]
404
405
fn aes_single_key_bit_flip ( ) {
405
- test_single_key_bit_flip ( |k1 , k2| AHasher :: test_with_keys ( k1 , k2 ) )
406
+ test_single_key_bit_flip ( AHasher :: new_with_keys )
406
407
}
407
408
408
409
#[ test]
409
410
fn aes_all_bytes_matter ( ) {
410
- test_all_bytes_matter ( || AHasher :: test_with_keys ( BAD_KEY , BAD_KEY ) ) ;
411
- test_all_bytes_matter ( || AHasher :: test_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ;
411
+ test_all_bytes_matter ( || AHasher :: new_with_keys ( BAD_KEY , BAD_KEY ) ) ;
412
+ test_all_bytes_matter ( || AHasher :: new_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ;
412
413
}
413
414
414
415
#[ test]
415
416
fn aes_test_no_pair_collisions ( ) {
416
- test_no_pair_collisions ( || AHasher :: test_with_keys ( BAD_KEY , BAD_KEY ) ) ;
417
- test_no_pair_collisions ( || AHasher :: test_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ;
417
+ test_no_pair_collisions ( || AHasher :: new_with_keys ( BAD_KEY , BAD_KEY ) ) ;
418
+ test_no_pair_collisions ( || AHasher :: new_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ;
418
419
}
419
420
420
421
#[ test]
421
422
fn ase_test_no_full_collisions ( ) {
422
- test_no_full_collisions ( || AHasher :: test_with_keys ( 12345 , 67890 ) ) ;
423
+ test_no_full_collisions ( || AHasher :: new_with_keys ( 12345 , 67890 ) ) ;
423
424
}
424
425
425
426
#[ test]
426
427
fn aes_keys_change_output ( ) {
427
- test_keys_change_output ( AHasher :: test_with_keys ) ;
428
+ test_keys_change_output ( AHasher :: new_with_keys ) ;
428
429
}
429
430
430
431
#[ test]
431
432
fn aes_input_affect_every_byte ( ) {
432
- test_input_affect_every_byte ( AHasher :: test_with_keys ) ;
433
+ test_input_affect_every_byte ( AHasher :: new_with_keys ) ;
433
434
}
434
435
435
436
#[ test]
436
437
fn aes_keys_affect_every_byte ( ) {
437
- test_keys_affect_every_byte ( 0 , AHasher :: test_with_keys ) ;
438
- test_keys_affect_every_byte ( "" , AHasher :: test_with_keys ) ;
439
- test_keys_affect_every_byte ( ( 0 , 0 ) , AHasher :: test_with_keys ) ;
438
+ test_keys_affect_every_byte ( 0 , AHasher :: new_with_keys ) ;
439
+ test_keys_affect_every_byte ( "" , AHasher :: new_with_keys ) ;
440
+ test_keys_affect_every_byte ( ( 0 , 0 ) , AHasher :: new_with_keys ) ;
440
441
}
441
442
#[ test]
442
443
fn aes_finish_is_consistant ( ) {
443
- test_finish_is_consistent ( AHasher :: test_with_keys )
444
+ test_finish_is_consistent ( AHasher :: new_with_keys )
444
445
}
445
446
446
447
#[ test]
447
448
fn aes_padding_doesnot_collide ( ) {
448
- test_padding_doesnot_collide ( || AHasher :: test_with_keys ( BAD_KEY , BAD_KEY ) ) ;
449
- test_padding_doesnot_collide ( || AHasher :: test_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ;
449
+ test_padding_doesnot_collide ( || AHasher :: new_with_keys ( BAD_KEY , BAD_KEY ) ) ;
450
+ test_padding_doesnot_collide ( || AHasher :: new_with_keys ( BAD_KEY2 , BAD_KEY2 ) ) ;
450
451
}
451
452
}
0 commit comments