Skip to content

Commit

Permalink
Strengthen fastpath (#169)
Browse files Browse the repository at this point in the history
This change adds a test which probes for issues with sparse inputs on the fast path.

This fixes #163 in multiple ways. Each of the improvements have been tested individually and in various combinations with weakened versions of other parts of the algorithm to insure they work as intended and provide a benefit.

Signed-off-by: Tom Kaitchuck <Tom.Kaitchuck@gmail.com>
  • Loading branch information
tkaitchuck committed Oct 23, 2023
1 parent 47b6dd6 commit d16ebf6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/aes_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ impl Hasher for AHasher {
let tail = data.read_last_u128x4();
let mut current: [u128; 4] = [self.key; 4];
current[0] = aesenc(current[0], tail[0]);
current[1] = aesenc(current[1], tail[1]);
current[1] = aesdec(current[1], tail[1]);
current[2] = aesenc(current[2], tail[2]);
current[3] = aesenc(current[3], tail[3]);
let mut sum: [u128; 2] = [self.key, self.key];
current[3] = aesdec(current[3], tail[3]);
let mut sum: [u128; 2] = [self.key, !self.key];
sum[0] = add_by_64s(sum[0].convert(), tail[0].convert()).convert();
sum[1] = add_by_64s(sum[1].convert(), tail[1].convert()).convert();
sum[0] = shuffle_and_add(sum[0], tail[2]);
Expand All @@ -188,8 +188,9 @@ impl Hasher for AHasher {
sum[1] = shuffle_and_add(sum[1], blocks[3]);
data = rest;
}
self.hash_in_2(aesenc(current[0], current[1]), aesenc(current[2], current[3]));
self.hash_in(add_by_64s(sum[0].convert(), sum[1].convert()).convert());
self.hash_in_2(current[0], current[1]);
self.hash_in_2(current[2], current[3]);
self.hash_in_2(sum[0], sum[1]);
} else {
//len 33-64
let (head, _) = data.read_u128x2();
Expand All @@ -213,7 +214,7 @@ impl Hasher for AHasher {
fn finish(&self) -> u64 {
let combined = aesdec(self.sum, self.enc);
let result: [u64; 2] = aesenc(aesenc(combined, self.key), combined).convert();
result[0]
result[1]
}
}

Expand Down

0 comments on commit d16ebf6

Please sign in to comment.