Browse Source

aes hash: reduce full output mod range size

Lennart Braun 2 years ago
parent
commit
f672e4bc67
1 changed files with 7 additions and 4 deletions
  1. 7 4
      cuckoo/src/hash.rs

+ 7 - 4
cuckoo/src/hash.rs

@@ -101,10 +101,13 @@ impl HashFunction for AesHashFunction {
         for (x, y) in block.iter_mut().zip(sigma_x.iter()) {
             *x ^= y;
         }
-        let high: &[u8; 8] = block.as_slice()[..8]
-            .try_into()
-            .expect("does not fail since block is 16 bytes long");
-        u64::from_le_bytes(*high) % self.description.range_size
+        let h = u128::from_le_bytes(
+            block
+                .as_slice()
+                .try_into()
+                .expect("does not fail since block is 16 bytes long"),
+        );
+        (h % self.description.range_size as u128) as u64
     }
 }