Skip to content
Snippets Groups Projects
Commit 966af430 authored by Mike Hommey's avatar Mike Hommey
Browse files

Bug 1881370 - Upgrade ahash to 0.7.8. a=RyanVM

parent 85d239fc
No related branches found
No related tags found
No related merge requests found
...@@ -18,9 +18,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" ...@@ -18,9 +18,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.7.6" version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9"
dependencies = [ dependencies = [
"getrandom", "getrandom",
"once_cell", "once_cell",
......
...@@ -355,6 +355,11 @@ criteria = "safe-to-deploy" ...@@ -355,6 +355,11 @@ criteria = "safe-to-deploy"
version = "0.1.0" version = "0.1.0"
notes = "Written and maintained by Gfx team at Mozilla." notes = "Written and maintained by Gfx team at Mozilla."
[[audits.ahash]]
who = "Mike Hommey <mh+mozilla@glandium.org>"
criteria = "safe-to-deploy"
delta = "0.7.6 -> 0.7.8"
[[audits.aho-corasick]] [[audits.aho-corasick]]
who = "Mike Hommey <mh+mozilla@glandium.org>" who = "Mike Hommey <mh+mozilla@glandium.org>"
criteria = "safe-to-deploy" criteria = "safe-to-deploy"
......
{"files":{"Cargo.toml":"31399b9babab52fabfe71f52ffe38fef0d3d894fdd5829f84a4e69b031f463c9","FAQ.md":"9eb41898523ee209a0a937f9bcb78afe45ad55ca0556f8a4d4063558098f6d1e","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"ff8f68cb076caf8cefe7a6430d4ac086ce6af2ca8ce2c4e5a2004d4552ef52a2","README.md":"72185284f100e149998fe5301f70489e617cc4415b51cc77e967c63c6e970a67","build.rs":"123b322034273b5aa1b4934d84c277fef279afd533ecfb44831a3715e9887fcd","rustfmt.toml":"e090969e99df9360705680cc0097cfaddae10c22dc2e01470592cf3b9787fd36","src/aes_hash.rs":"04483498a0d86e3ab099e22f734ea6fcac384b92f349bd310456856bf6a9a5e2","src/convert.rs":"f0e78840046493d0679a9ec077c8164cf57cf30d5e852b11bfadfdd996d29bd1","src/fallback_hash.rs":"ec00691bd555c69f7446afe893b6631cb84207cb7b512260dec8ef488e1905f3","src/hash_map.rs":"ed0c79c41c2218ad9591a585670a2b9b983807c9725880b780138a44c126cbfd","src/hash_quality_test.rs":"6c1fea90a38dc7b2ac5b2fa6e44a565e0c3385c72df6e87231401f920912d053","src/hash_set.rs":"dc3d33e290aad62457ab1f5e64d3e33eb79e28c9468bfc8686339f0bbd8b19aa","src/lib.rs":"9fec7d1d412e414231c9b929081b1daa7c3b788a9f91eedd79a55efdf5d0d291","src/operations.rs":"10772e65b8b7106f195428c5eb8dbf6cbd49dd5a2165ac750e54af5995210f88","src/random_state.rs":"b7981967ec5ecbff04d166b5e05c59c386062b4de3b36816f3c98ef284372f63","src/specialize.rs":"38d3b56ef4f264d564f48dbcb8ac137928babf90635090c9771c1a62140d1f30","tests/bench.rs":"0851dffebaffd7a437f6f9946ed5e03a957e9a6eb0da7911451af58778c411ec","tests/map_tests.rs":"e0f155f964dd965740b072ee1da110a8c6ef34491c95219f7c89064112c7840f","tests/nopanic.rs":"3363675c4c1a197b86604a0aebbe958fb5ec7c01a414fbfd70e9eb8a29707400"},"package":"fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"} {"files":{"Cargo.toml":"a519809f46c9aad28d6c48748f330fe31e05029d234b6d1743522ec403441744","FAQ.md":"9eb41898523ee209a0a937f9bcb78afe45ad55ca0556f8a4d4063558098f6d1e","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"ff8f68cb076caf8cefe7a6430d4ac086ce6af2ca8ce2c4e5a2004d4552ef52a2","README.md":"72185284f100e149998fe5301f70489e617cc4415b51cc77e967c63c6e970a67","build.rs":"f80cb1cdb731a63d16513f1f0b0871d9c077d2c6bf2312af40a202f9c0fefe49","rustfmt.toml":"e090969e99df9360705680cc0097cfaddae10c22dc2e01470592cf3b9787fd36","src/aes_hash.rs":"0b11ce066931396222d2bed7eff678fdd7c8351819485efb721f62a30551866b","src/convert.rs":"f0e78840046493d0679a9ec077c8164cf57cf30d5e852b11bfadfdd996d29bd1","src/fallback_hash.rs":"ec00691bd555c69f7446afe893b6631cb84207cb7b512260dec8ef488e1905f3","src/hash_map.rs":"ed0c79c41c2218ad9591a585670a2b9b983807c9725880b780138a44c126cbfd","src/hash_quality_test.rs":"61695e5cac46ea25021a9d04199fb00c513e0c0c9c0f67aca0c647b9d2f7dd5a","src/hash_set.rs":"dc3d33e290aad62457ab1f5e64d3e33eb79e28c9468bfc8686339f0bbd8b19aa","src/lib.rs":"9fec7d1d412e414231c9b929081b1daa7c3b788a9f91eedd79a55efdf5d0d291","src/operations.rs":"10772e65b8b7106f195428c5eb8dbf6cbd49dd5a2165ac750e54af5995210f88","src/random_state.rs":"ce9689147659efa975887debe1481daddca09386ea8e1d5b4ee90ebeda6c8745","src/specialize.rs":"38d3b56ef4f264d564f48dbcb8ac137928babf90635090c9771c1a62140d1f30","tests/bench.rs":"0851dffebaffd7a437f6f9946ed5e03a957e9a6eb0da7911451af58778c411ec","tests/map_tests.rs":"e0f155f964dd965740b072ee1da110a8c6ef34491c95219f7c89064112c7840f","tests/nopanic.rs":"3363675c4c1a197b86604a0aebbe958fb5ec7c01a414fbfd70e9eb8a29707400"},"package":"891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9"}
\ No newline at end of file \ No newline at end of file
...@@ -3,43 +3,63 @@ ...@@ -3,43 +3,63 @@
# When uploading crates to the registry Cargo will automatically # When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility # "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies # with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies # to registry (e.g., crates.io) dependencies.
# #
# If you believe there's an error in this file please file an # If you are reading this file be aware that the original Cargo.toml
# issue against the rust-lang/cargo repository. If you're # will likely look very different (and much more reasonable).
# editing this file be aware that the upstream Cargo.toml # See Cargo.toml.orig for the original contents.
# will likely look very different (and much more reasonable)
[package] [package]
edition = "2018" edition = "2018"
name = "ahash" name = "ahash"
version = "0.7.6" version = "0.7.8"
authors = ["Tom Kaitchuck <Tom.Kaitchuck@gmail.com>"] authors = ["Tom Kaitchuck <Tom.Kaitchuck@gmail.com>"]
build = "./build.rs" build = "./build.rs"
exclude = ["/smhasher", "/benchmark_tools"] exclude = [
"/smhasher",
"/benchmark_tools",
]
description = "A non-cryptographic hash function using AES-NI for high performance" description = "A non-cryptographic hash function using AES-NI for high performance"
documentation = "https://docs.rs/ahash" documentation = "https://docs.rs/ahash"
readme = "README.md" readme = "README.md"
keywords = ["hash", "hasher", "hashmap", "aes", "no-std"] keywords = [
categories = ["algorithms", "data-structures", "no-std"] "hash",
"hasher",
"hashmap",
"aes",
"no-std",
]
categories = [
"algorithms",
"data-structures",
"no-std",
]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
repository = "https://github.com/tkaitchuck/ahash" repository = "https://github.com/tkaitchuck/ahash"
[package.metadata.docs.rs] [package.metadata.docs.rs]
features = ["std"] features = ["std"]
rustc-args = ["-C", "target-feature=+aes"] rustc-args = [
rustdoc-args = ["-C", "target-feature=+aes"] "-C",
"target-feature=+aes",
]
rustdoc-args = [
"-C",
"target-feature=+aes",
]
[profile.bench] [profile.bench]
opt-level = 3 opt-level = 3
lto = "fat" lto = "fat"
codegen-units = 1 codegen-units = 1
debug = false debug = 0
debug-assertions = false debug-assertions = false
[profile.release] [profile.release]
opt-level = 3 opt-level = 3
lto = "fat" lto = "fat"
codegen-units = 1 codegen-units = 1
debug = false debug = 0
debug-assertions = false debug-assertions = false
[profile.test] [profile.test]
...@@ -63,6 +83,7 @@ harness = false ...@@ -63,6 +83,7 @@ harness = false
name = "map" name = "map"
path = "tests/map_tests.rs" path = "tests/map_tests.rs"
harness = false harness = false
[dev-dependencies.criterion] [dev-dependencies.criterion]
version = "0.3.2" version = "0.3.2"
...@@ -86,13 +107,19 @@ version = "4.0" ...@@ -86,13 +107,19 @@ version = "4.0"
[dev-dependencies.serde_json] [dev-dependencies.serde_json]
version = "1.0.59" version = "1.0.59"
[build-dependencies.version_check] [build-dependencies.version_check]
version = "0.9" version = "0.9"
[features] [features]
atomic-polyfill = [
"dep:atomic-polyfill",
"once_cell/atomic-polyfill",
]
compile-time-rng = ["const-random"] compile-time-rng = ["const-random"]
default = ["std"] default = ["std"]
std = [] std = []
[target."cfg(any(target_os = \"linux\", target_os = \"android\", target_os = \"windows\", target_os = \"macos\", target_os = \"ios\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"dragonfly\", target_os = \"solaris\", target_os = \"illumos\", target_os = \"fuchsia\", target_os = \"redox\", target_os = \"cloudabi\", target_os = \"haiku\", target_os = \"vxworks\", target_os = \"emscripten\", target_os = \"wasi\"))".dependencies.const-random] [target."cfg(any(target_os = \"linux\", target_os = \"android\", target_os = \"windows\", target_os = \"macos\", target_os = \"ios\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"dragonfly\", target_os = \"solaris\", target_os = \"illumos\", target_os = \"fuchsia\", target_os = \"redox\", target_os = \"cloudabi\", target_os = \"haiku\", target_os = \"vxworks\", target_os = \"emscripten\", target_os = \"wasi\"))".dependencies.const-random]
version = "0.1.12" version = "0.1.12"
optional = true optional = true
...@@ -103,10 +130,16 @@ version = "0.2.3" ...@@ -103,10 +130,16 @@ version = "0.2.3"
[target."cfg(any(target_os = \"linux\", target_os = \"android\", target_os = \"windows\", target_os = \"macos\", target_os = \"ios\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"dragonfly\", target_os = \"solaris\", target_os = \"illumos\", target_os = \"fuchsia\", target_os = \"redox\", target_os = \"cloudabi\", target_os = \"haiku\", target_os = \"vxworks\", target_os = \"emscripten\", target_os = \"wasi\"))".dependencies.serde] [target."cfg(any(target_os = \"linux\", target_os = \"android\", target_os = \"windows\", target_os = \"macos\", target_os = \"ios\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"dragonfly\", target_os = \"solaris\", target_os = \"illumos\", target_os = \"fuchsia\", target_os = \"redox\", target_os = \"cloudabi\", target_os = \"haiku\", target_os = \"vxworks\", target_os = \"emscripten\", target_os = \"wasi\"))".dependencies.serde]
version = "1.0.117" version = "1.0.117"
optional = true optional = true
[target."cfg(not(all(target_arch = \"arm\", target_os = \"none\")))".dependencies.once_cell] [target."cfg(not(all(target_arch = \"arm\", target_os = \"none\")))".dependencies.once_cell]
version = "1.8" version = "1.13.1"
features = ["alloc"] features = ["alloc"]
default-features = false default-features = false
[target."cfg(not(any(target_os = \"linux\", target_os = \"android\", target_os = \"windows\", target_os = \"macos\", target_os = \"ios\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"dragonfly\", target_os = \"solaris\", target_os = \"illumos\", target_os = \"fuchsia\", target_os = \"redox\", target_os = \"cloudabi\", target_os = \"haiku\", target_os = \"vxworks\", target_os = \"emscripten\", target_os = \"wasi\")))".dependencies.atomic-polyfill]
version = "1.0.1"
optional = true
[target."cfg(not(any(target_os = \"linux\", target_os = \"android\", target_os = \"windows\", target_os = \"macos\", target_os = \"ios\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"dragonfly\", target_os = \"solaris\", target_os = \"illumos\", target_os = \"fuchsia\", target_os = \"redox\", target_os = \"cloudabi\", target_os = \"haiku\", target_os = \"vxworks\", target_os = \"emscripten\", target_os = \"wasi\")))".dependencies.const-random] [target."cfg(not(any(target_os = \"linux\", target_os = \"android\", target_os = \"windows\", target_os = \"macos\", target_os = \"ios\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"dragonfly\", target_os = \"solaris\", target_os = \"illumos\", target_os = \"fuchsia\", target_os = \"redox\", target_os = \"cloudabi\", target_os = \"haiku\", target_os = \"vxworks\", target_os = \"emscripten\", target_os = \"wasi\")))".dependencies.const-random]
version = "0.1.12" version = "0.1.12"
optional = true optional = true
......
...@@ -7,7 +7,9 @@ fn main() { ...@@ -7,7 +7,9 @@ fn main() {
if let Some(channel) = version_check::Channel::read() { if let Some(channel) = version_check::Channel::read() {
if channel.supports_features() { if channel.supports_features() {
println!("cargo:rustc-cfg=feature=\"specialize\""); println!("cargo:rustc-cfg=feature=\"specialize\"");
println!("cargo:rustc-cfg=feature=\"stdsimd\""); if version_check::Version::read().map_or(false, |v| v.at_most("1.77.9")) {
println!("cargo:rustc-cfg=feature=\"stdsimd\"");
}
} }
} }
let os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS was not set"); let os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS was not set");
......
...@@ -170,10 +170,10 @@ impl Hasher for AHasher { ...@@ -170,10 +170,10 @@ impl Hasher for AHasher {
let tail = data.read_last_u128x4(); let tail = data.read_last_u128x4();
let mut current: [u128; 4] = [self.key; 4]; let mut current: [u128; 4] = [self.key; 4];
current[0] = aesenc(current[0], tail[0]); 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[2] = aesenc(current[2], tail[2]);
current[3] = aesenc(current[3], tail[3]); current[3] = aesdec(current[3], tail[3]);
let mut sum: [u128; 2] = [self.key, self.key]; let mut sum: [u128; 2] = [self.key, !self.key];
sum[0] = add_by_64s(sum[0].convert(), tail[0].convert()).convert(); 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[1] = add_by_64s(sum[1].convert(), tail[1].convert()).convert();
sum[0] = shuffle_and_add(sum[0], tail[2]); sum[0] = shuffle_and_add(sum[0], tail[2]);
...@@ -190,8 +190,9 @@ impl Hasher for AHasher { ...@@ -190,8 +190,9 @@ impl Hasher for AHasher {
sum[1] = shuffle_and_add(sum[1], blocks[3]); sum[1] = shuffle_and_add(sum[1], blocks[3]);
data = rest; data = rest;
} }
self.hash_in_2(aesenc(current[0], current[1]), aesenc(current[2], current[3])); self.hash_in_2(current[0], current[1]);
self.hash_in(add_by_64s(sum[0].convert(), sum[1].convert()).convert()); self.hash_in_2(current[2], current[3]);
self.hash_in_2(sum[0], sum[1]);
} else { } else {
//len 33-64 //len 33-64
let (head, _) = data.read_u128x2(); let (head, _) = data.read_u128x2();
...@@ -215,7 +216,7 @@ impl Hasher for AHasher { ...@@ -215,7 +216,7 @@ impl Hasher for AHasher {
fn finish(&self) -> u64 { fn finish(&self) -> u64 {
let combined = aesdec(self.sum, self.enc); let combined = aesdec(self.sum, self.enc);
let result: [u64; 2] = aesenc(aesenc(combined, self.key), combined).convert(); let result: [u64; 2] = aesenc(aesenc(combined, self.key), combined).convert();
result[0] result[1]
} }
} }
......
use core::hash::{Hash, Hasher}; use core::hash::{Hash, Hasher};
use std::collections::HashMap; use std::collections::{HashMap};
fn assert_sufficiently_different(a: u64, b: u64, tolerance: i32) { fn assert_sufficiently_different(a: u64, b: u64, tolerance: i32) {
let (same_byte_count, same_nibble_count) = count_same_bytes_and_nibbles(a, b); let (same_byte_count, same_nibble_count) = count_same_bytes_and_nibbles(a, b);
...@@ -326,6 +326,28 @@ fn test_length_extension<T: Hasher>(hasher: impl Fn(u128, u128) -> T) { ...@@ -326,6 +326,28 @@ fn test_length_extension<T: Hasher>(hasher: impl Fn(u128, u128) -> T) {
} }
} }
fn test_sparse<T: Hasher>(hasher: impl Fn() -> T) {
let mut buf = [0u8; 256];
let mut hashes = HashMap::new();
for idx_1 in 0..256 {
for idx_2 in idx_1+1..256 {
for value_1 in [1, 2, 4, 8, 16, 32, 64, 128] {
for value_2 in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 16, 17, 18, 20, 24, 31, 32, 33, 48, 64, 96, 127, 128, 129, 192, 254, 255] {
buf[idx_1] = value_1;
buf[idx_2] = value_2;
let hash_value = hash_with(&buf, &mut hasher());
let keys = hashes.entry(hash_value).or_insert(Vec::new());
keys.push((idx_1, value_1, idx_2, value_2));
buf[idx_1] = 0;
buf[idx_2] = 0;
}
}
}
}
hashes.retain(|_key, value| value.len() != 1);
assert_eq!(0, hashes.len(), "Collision with: {:?}", hashes);
}
#[cfg(test)] #[cfg(test)]
mod fallback_tests { mod fallback_tests {
use crate::fallback_hash::*; use crate::fallback_hash::*;
...@@ -392,6 +414,12 @@ mod fallback_tests { ...@@ -392,6 +414,12 @@ mod fallback_tests {
fn fallback_length_extension() { fn fallback_length_extension() {
test_length_extension(|a, b| AHasher::new_with_keys(a, b)); test_length_extension(|a, b| AHasher::new_with_keys(a, b));
} }
#[test]
fn test_no_sparse_collisions() {
test_sparse(|| AHasher::new_with_keys(0, 0));
test_sparse(|| AHasher::new_with_keys(1, 2));
}
} }
///Basic sanity tests of the cypto properties of aHash. ///Basic sanity tests of the cypto properties of aHash.
...@@ -480,4 +508,10 @@ mod aes_tests { ...@@ -480,4 +508,10 @@ mod aes_tests {
fn aes_length_extension() { fn aes_length_extension() {
test_length_extension(|a, b| AHasher::test_with_keys(a, b)); test_length_extension(|a, b| AHasher::test_with_keys(a, b));
} }
#[test]
fn aes_no_sparse_collisions() {
test_sparse(|| AHasher::test_with_keys(0, 0));
test_sparse(|| AHasher::test_with_keys(1, 2));
}
} }
...@@ -29,8 +29,13 @@ extern crate alloc; ...@@ -29,8 +29,13 @@ extern crate alloc;
#[cfg(feature = "std")] #[cfg(feature = "std")]
extern crate std as alloc; extern crate std as alloc;
#[cfg(feature = "atomic-polyfill")]
use atomic_polyfill as atomic;
#[cfg(not(feature = "atomic-polyfill"))]
use core::sync::atomic;
use alloc::boxed::Box; use alloc::boxed::Box;
use core::sync::atomic::{AtomicUsize, Ordering}; use atomic::{AtomicUsize, Ordering};
#[cfg(not(all(target_arch = "arm", target_os = "none")))] #[cfg(not(all(target_arch = "arm", target_os = "none")))]
use once_cell::race::OnceBox; use once_cell::race::OnceBox;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment