Repository navigation
Critical vulnerability: complete key recovery of AES-based hash through side-channels #163
Description
The AES version of aHash only performs a single round of AES between inputs. This is not sufficient, a single-bit difference only gets amplified once in the SubBytes step, leading to one of 256 possibilities, but nothing further. An attacker can guess this to recover the key byte-by-byte, leading to a complete key recovery in ~4000 tests. Note that the only thing an attacker has to see is whether two inputs collide, nothing else. The attack can thus be done entirely through side-channels.
That is, the following program (instantly) succeeds when compiled with -C target-feature=+aes. Again note that recover_ahash_seed is completely blind to the hash outputs, and only gets to test if h(s1) == h(s2). This can be done in e.g. hash tables through timing attacks.
use ahash::random_state::RandomState;
use rand::prelude::*;
const PI2: [u64; 4] = [
0x4528_21e6_38d0_1377,
0xbe54_66cf_34e9_0c6c,
0xc0ac_29b7_c97c_50dd,
0x3f84_d5b5_b547_0917,
];
fn main() {
// Instantiate a random aHash instance.
let mut rng = rand::thread_rng();
let seed: [u64; 4] = rng.gen();
let rs = RandomState::with_seeds(seed[0], seed[1], seed[2], seed[3]);
// Simulate aHash key init for the AES-based hash.
let k0 = seed[0] ^ PI2[0];
let k1 = seed[1] ^ PI2[1];
let k2 = seed[2] ^ PI2[2];
let k3 = seed[3] ^ PI2[3];
let ahash_reference_key = bytemuck::cast::<_, u128>([k0 ^ k2, k1 ^ k3]);
// Crack secret key using ONLY collision checks.
let mut total_collision_checks = 0;
let decoded = recover_ahash_seed(&mut |s1, s2| {
total_collision_checks += 1;
rs.hash_one(s1) == rs.hash_one(s2)
});
assert!(decoded == ahash_reference_key);
println!("aHash key recovery attack complete using {total_collision_checks} collision checks.");
}While it may be possible to thwart this particular instantiation of this attack using a different input schedule, I find the usage of only a single round of AES between input absorption to be deeply disturbing as it is simply insufficiently mixing. I strongly implore you to use at least two rounds between accepting input into the hash state, like Go's AES-based hash does.
For the purpose of responsible disclosure I have not included recover_ahash_seed here. It's not particularly sophisticated however - it's about 70 lines of code, 20 of which is AES intrinsic boilerplate. If you wish I can send the source code of it to a maintainer through private communication, please specify how/where you would wish to receive it. To give you time to fix this vulnerability, while it remains active I will not publicize the details of the attack or the source code before 1st of January 2024.
Activity
Strengthen fastpath (#169)
tkaitchuck commentedon Oct 23, 2023
Published fix in 0.8.4.
@orlp Please confirm it is working, and I will yank older versions
folex commentedon Oct 23, 2023
For anyone who comes here from search:
cargo install --locked $namewill allow to install even through yanked deps.UPD: 0.7.7 was released, now
cargo installworks again.Thank you!
It seems that this mass-yank broke a lot of CLIs that depended on these versions.
I'm not yet sure, but it seems that anything that's installed by
cargo installand depended onhashbrownwill now fail on installation.Not sure of severity here, I'd be glad if it only broke a few CLIs.
dfeyer commentedon Oct 23, 2023
starting a new project (with no lock file) with any crate with ahash as a deps is now broken .. it's a pretty big impact on the ecosystem, I understand the purpose of yanking ... but the situation feel a bit hard on many people/project. Any way thanks for behing security focused, I think cargo need to be a bit less strict with yanked package, that can help.
Strengthen fastpath (#169)
Strengthen fastpath (#169) (#175)
Strengthen fastpath (#169)
tkaitchuck commentedon Oct 23, 2023
Patches have been released in the from of versions
0.8.4,0.7.7, and0.4.8Vulnerable versions have been yanked with the details of the yanks here: https://github.com/tkaitchuck/aHash/wiki/Yanked-versions
orlp commentedon Oct 24, 2023
I can confirm that the changes foil my attack. I spent a few hours staring at the new function and couldn't find a similar attack, but I would like to note that I'm not a professional cryptographer, and that this should not be considered an audit.
Since the issue is now fixed I will post the omitted
recover_ahash_seedfrom my attack:ikopylov commentedon Oct 24, 2023
Is it possible to undo the
yank? My project uses this crate as a part of the Bloom filter, that is stored persistently on disk. I don't care about security, but it is strictly required to keep the same output of the hash function for the same input. So I restrict dependency to a specific version of this crate and when this version was yanked, everything broke. I can't update the crate to a new version because the hash output changed. So I ask to undo theyankorlp commentedon Oct 24, 2023
@ikopylov The readme does state "Specifically, aHash is not intended for network use or in applications which persist hashed values." =/
build(deps): bump `ahash` from v0.8.3 to v0.8.5
build(deps): bump `ahash` from v0.8.3 to v0.8.5 (#11538)
5 remaining items
Drop `ahash` dependency in favor of core's `SipHasher`
Drop `ahash` dependency in favor of core's `SipHasher`
Drop `ahash` dependency in favor of core's `SipHasher`
Drop `ahash` dependency in favor of core's `SipHasher`
Drop `ahash` dependency in favor of core's `SipHasher`
Drop `ahash` dependency in favor of core's `SipHasher`
Drop `ahash` dependency in favor of core's `SipHasher`
chore: fix `ahash`-caused build breakage (tokio-rs#2792)
chore: fix `ahash`-caused build breakage (tokio-rs#2792)
chore: fix `ahash`-caused build breakage (tokio-rs#2792)
chore: fix `ahash`-caused build breakage (tokio-rs#2792)
Drop `ahash` dependency in favor of core's `SipHasher`
Drop `ahash` dependency in favor of core's `SipHasher`
chore: fix `ahash`-caused build breakage (tokio-rs#2792)
Drop `ahash` dependency in favor of core's `SipHasher`