diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-02 23:51:47 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-02 23:51:47 +0000 |
commit | d014edcbf0bb852729c1b3393f02dcc46fcc8c19 (patch) | |
tree | 58da9424cea6b82846215ec0ed62cbd11326bbce | |
parent | 0e8cc61fb41ba7e863032077ed803e8c3b36c051 (diff) | |
parent | 4a8bf8652737f580148ef816edc7639e30f84bee (diff) | |
download | ahash-simpleperf-release.tar.gz |
Snap for 11400057 from 4a8bf8652737f580148ef816edc7639e30f84bee to simpleperf-releasesimpleperf-release
Change-Id: I7d9fc4ce393e3915d4292da72d9dfdd847312db2
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .github/workflows/rust.yml | 27 | ||||
-rw-r--r-- | Android.bp | 3 | ||||
-rw-r--r-- | Cargo.toml | 15 | ||||
-rw-r--r-- | Cargo.toml.orig | 12 | ||||
-rw-r--r-- | METADATA | 23 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | build.rs | 3 | ||||
-rw-r--r-- | src/aes_hash.rs | 32 | ||||
-rw-r--r-- | src/hash_quality_test.rs | 20 | ||||
-rw-r--r-- | src/lib.rs | 16 | ||||
-rw-r--r-- | src/operations.rs | 16 | ||||
-rw-r--r-- | src/random_state.rs | 21 | ||||
-rw-r--r-- | tests/bench.rs | 9 |
14 files changed, 109 insertions, 91 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index a2a6019..93d0a7d 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "7bbbd833cb48c6f8e64bd94c196a700c09bb97e4" + "sha1": "ea78b05f0d603d40fa28855ba271f47494862e9d" }, "path_in_vcs": "" }
\ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f09853c..1d440a5 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -62,6 +62,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: check + args: -Z msrv-policy - name: test nightly uses: actions-rs/cargo@v1 with: @@ -167,3 +168,29 @@ jobs: with: command: check args: --target wasm32-unknown-unknown --no-default-features + msrv: + name: MSRV + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install 1.60.0 + uses: actions-rs/toolchain@v1 + with: + toolchain: 1.60.0 + - name: check + uses: actions-rs/cargo@v1 + with: + command: check + no_std: + name: no-std build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + - uses: actions-rs/cargo@v1 + with: + command: build + args: --manifest-path=no_std_test/Cargo.toml @@ -42,7 +42,7 @@ rust_library { host_supported: true, crate_name: "ahash", cargo_env_compat: true, - cargo_pkg_version: "0.8.5", + cargo_pkg_version: "0.8.7", srcs: ["src/lib.rs"], edition: "2018", arch: { @@ -59,7 +59,6 @@ rust_library { "runtime-rng", "specialize", "std", - "stdsimd", ], rustlibs: [ "libcfg_if", @@ -11,8 +11,9 @@ [package] edition = "2018" +rust-version = "1.60.0" name = "ahash" -version = "0.8.5" +version = "0.8.7" authors = ["Tom Kaitchuck <Tom.Kaitchuck@gmail.com>"] build = "./build.rs" exclude = [ @@ -92,7 +93,7 @@ optional = true version = "1.0" [dependencies.const-random] -version = "0.1.12" +version = "0.1.17" optional = true [dependencies.getrandom] @@ -104,7 +105,7 @@ version = "1.0.117" optional = true [dependencies.zerocopy] -version = "0.7.0" +version = "0.7.31" features = ["simd"] default-features = false @@ -149,14 +150,12 @@ default = [ "std", "runtime-rng", ] +nightly-arm-aes = [] no-rng = [] runtime-rng = ["getrandom"] std = [] [target."cfg(not(all(target_arch = \"arm\", target_os = \"none\")))".dependencies.once_cell] -version = "1.13.1" -features = [ - "unstable", - "alloc", -] +version = "1.18.0" +features = ["alloc"] default-features = false diff --git a/Cargo.toml.orig b/Cargo.toml.orig index b340522..7f2901f 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "ahash" -version = "0.8.5" +version = "0.8.7" authors = ["Tom Kaitchuck <Tom.Kaitchuck@gmail.com>"] license = "MIT OR Apache-2.0" description = "A non-cryptographic hash function using AES-NI for high performance" @@ -12,6 +12,7 @@ edition = "2018" readme = "README.md" build = "./build.rs" exclude = ["/smhasher", "/benchmark_tools"] +rust-version = "1.60.0" [lib] name = "ahash" @@ -43,6 +44,9 @@ no-rng = [] # in case this is being used on an architecture lacking core::sync::atomic::AtomicUsize and friends atomic-polyfill = [ "dep:atomic-polyfill", "once_cell/atomic-polyfill"] +# Nightly-only support for AES intrinsics on 32-bit ARM +nightly-arm-aes = [] + [[bench]] name = "ahash" path = "tests/bench.rs" @@ -75,15 +79,15 @@ codegen-units = 1 version_check = "0.9.4" [dependencies] -const-random = { version = "0.1.12", optional = true } +const-random = { version = "0.1.17", optional = true } serde = { version = "1.0.117", optional = true } cfg-if = "1.0" atomic-polyfill = { version="1.0.1", optional=true} getrandom = { version = "0.2.7", optional = true } -zerocopy = { version = "0.7.0", default-features = false, features = ["simd"] } +zerocopy = { version = "0.7.31", default-features = false, features = ["simd"] } [target.'cfg(not(all(target_arch = "arm", target_os = "none")))'.dependencies] -once_cell = { version = "1.13.1", default-features = false, features = ["unstable", "alloc"] } +once_cell = { version = "1.18.0", default-features = false, features = ["alloc"] } [dev-dependencies] no-panic = "0.1.10" @@ -1,23 +1,20 @@ # This project was upgraded with external_updater. -# Usage: tools/external_updater/updater.sh update rust/crates/ahash +# Usage: tools/external_updater/updater.sh update external/rust/crates/ahash # For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md name: "ahash" description: "A non-cryptographic hash function using AES-NI for high performance" third_party { - url { - type: HOMEPAGE - value: "https://crates.io/crates/ahash" - } - url { - type: ARCHIVE - value: "https://static.crates.io/crates/ahash/ahash-0.8.5.crate" - } - version: "0.8.5" license_type: NOTICE last_upgrade_date { - year: 2023 - month: 10 - day: 24 + year: 2024 + month: 1 + day: 31 + } + homepage: "https://crates.io/crates/ahash" + identifier { + type: "Archive" + value: "https://static.crates.io/crates/ahash/ahash-0.8.7.crate" + version: "0.8.7" } } @@ -57,6 +57,7 @@ The aHash package has the following flags: This is done using the [getrandom](https://github.com/rust-random/getrandom) crate. * `compile-time-rng`: For OS targets without access to a random number generator, `compile-time-rng` provides an alternative. If `getrandom` is unavailable and `compile-time-rng` is enabled, aHash will generate random numbers at compile time and embed them in the binary. +* `nightly-arm-aes`: To use AES instructions on 32-bit ARM, which requires nightly. This is not needed on AArch64. This allows for DOS resistance even if there is no random number generator available at runtime (assuming the compiled binary is not public). This makes the binary non-deterministic. (If non-determinism is a problem see [constrandom's documentation](https://github.com/tkaitchuck/constrandom#deterministic-builds)) @@ -7,9 +7,6 @@ fn main() { if let Some(true) = version_check::supports_feature("specialize") { println!("cargo:rustc-cfg=feature=\"specialize\""); } - if let Some(true) = version_check::supports_feature("stdsimd") { - println!("cargo:rustc-cfg=feature=\"stdsimd\""); - } let arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH was not set"); if arch.eq_ignore_ascii_case("x86_64") || arch.eq_ignore_ascii_case("aarch64") diff --git a/src/aes_hash.rs b/src/aes_hash.rs index d3b673f..0b9a1d4 100644 --- a/src/aes_hash.rs +++ b/src/aes_hash.rs @@ -81,23 +81,23 @@ impl AHasher { #[inline(always)] fn hash_in(&mut self, new_value: u128) { - self.enc = aesenc(self.enc, new_value); + self.enc = aesdec(self.enc, new_value); self.sum = shuffle_and_add(self.sum, new_value); } #[inline(always)] fn hash_in_2(&mut self, v1: u128, v2: u128) { - self.enc = aesenc(self.enc, v1); + self.enc = aesdec(self.enc, v1); self.sum = shuffle_and_add(self.sum, v1); - self.enc = aesenc(self.enc, v2); + self.enc = aesdec(self.enc, v2); self.sum = shuffle_and_add(self.sum, v2); } #[inline] #[cfg(feature = "specialize")] fn short_finish(&self) -> u64 { - let combined = aesdec(self.sum, self.enc); - let result: [u64; 2] = aesenc(combined, combined).convert(); + let combined = aesenc(self.sum, self.enc); + let result: [u64; 2] = aesdec(combined, combined).convert(); result[0] } } @@ -174,10 +174,10 @@ impl Hasher for AHasher { sum[1] = shuffle_and_add(sum[1], tail[3]); while data.len() > 64 { let (blocks, rest) = data.read_u128x4(); - current[0] = aesenc(current[0], blocks[0]); - current[1] = aesenc(current[1], blocks[1]); - current[2] = aesenc(current[2], blocks[2]); - current[3] = aesenc(current[3], blocks[3]); + current[0] = aesdec(current[0], blocks[0]); + current[1] = aesdec(current[1], blocks[1]); + current[2] = aesdec(current[2], blocks[2]); + current[3] = aesdec(current[3], blocks[3]); sum[0] = shuffle_and_add(sum[0], blocks[0]); sum[1] = shuffle_and_add(sum[1], blocks[1]); sum[0] = shuffle_and_add(sum[0], blocks[2]); @@ -208,9 +208,9 @@ impl Hasher for AHasher { } #[inline] fn finish(&self) -> u64 { - let combined = aesdec(self.sum, self.enc); - let result: [u64; 2] = aesenc(aesenc(combined, self.key), combined).convert(); - result[1] + let combined = aesenc(self.sum, self.enc); + let result: [u64; 2] = aesdec(aesdec(combined, self.key), combined).convert(); + result[0] } } @@ -329,15 +329,15 @@ impl Hasher for AHasherStr { fn write(&mut self, bytes: &[u8]) { if bytes.len() > 8 { self.0.write(bytes); - self.0.enc = aesdec(self.0.sum, self.0.enc); - self.0.enc = aesenc(aesenc(self.0.enc, self.0.key), self.0.enc); + self.0.enc = aesenc(self.0.sum, self.0.enc); + self.0.enc = aesdec(aesdec(self.0.enc, self.0.key), self.0.enc); } else { add_in_length(&mut self.0.enc, bytes.len() as u64); let value = read_small(bytes).convert(); self.0.sum = shuffle_and_add(self.0.sum, value); - self.0.enc = aesdec(self.0.sum, self.0.enc); - self.0.enc = aesenc(aesenc(self.0.enc, self.0.key), self.0.enc); + self.0.enc = aesenc(self.0.sum, self.0.enc); + self.0.enc = aesdec(aesdec(self.0.enc, self.0.key), self.0.enc); } } diff --git a/src/hash_quality_test.rs b/src/hash_quality_test.rs index 25356e4..4f6091a 100644 --- a/src/hash_quality_test.rs +++ b/src/hash_quality_test.rs @@ -1,5 +1,5 @@ use core::hash::{Hash, Hasher}; -use std::collections::{HashMap}; +use std::collections::HashMap; fn assert_sufficiently_different(a: u64, b: u64, tolerance: i32) { let (same_byte_count, same_nibble_count) = count_same_bytes_and_nibbles(a, b); @@ -64,8 +64,7 @@ fn gen_combinations(options: &[u32; 11], depth: u32, so_far: Vec<u32>, combinati fn test_no_full_collisions<T: Hasher>(gen_hash: impl Fn() -> T) { let options: [u32; 11] = [ - 0x00000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, 0xF0000000, - 1, 2, 4, 8, 15 + 0x00000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, 0xF0000000, 1, 2, 4, 8, 15, ]; let mut combinations = Vec::new(); gen_combinations(&options, 7, Vec::new(), &mut combinations); @@ -342,9 +341,12 @@ 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 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] { + 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()); @@ -437,12 +439,8 @@ mod fallback_tests { ///Basic sanity tests of the cypto properties of aHash. #[cfg(any( all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), - all( - any(target_arch = "arm", target_arch = "aarch64"), - any(target_feature = "aes", target_feature = "crypto"), - not(miri), - feature = "stdsimd" - ) + all(target_arch = "aarch64", target_feature = "aes", not(miri)), + all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)), ))] #[cfg(test)] mod aes_tests { @@ -13,7 +13,10 @@ //! But this also means that different computers or computers using different versions of ahash may observe different //! hash values for the same input. #![cfg_attr( - all(feature = "std", any(feature = "compile-time-rng", feature = "runtime-rng", feature = "no-rng")), + all( + feature = "std", + any(feature = "compile-time-rng", feature = "runtime-rng", feature = "no-rng") + ), doc = r##" # Basic Usage AHash provides an implementation of the [Hasher] trait. @@ -95,8 +98,7 @@ Note the import of [HashMapExt]. This is needed for the constructor. #![allow(clippy::pedantic, clippy::cast_lossless, clippy::unreadable_literal)] #![cfg_attr(all(not(test), not(feature = "std")), no_std)] #![cfg_attr(feature = "specialize", feature(min_specialization))] -#![cfg_attr(feature = "specialize", feature(build_hasher_simple_hash_one))] -#![cfg_attr(feature = "stdsimd", feature(stdsimd))] +#![cfg_attr(feature = "nightly-arm-aes", feature(stdarch_arm_neon_intrinsics))] #[macro_use] mod convert; @@ -106,11 +108,9 @@ mod fallback_hash; cfg_if::cfg_if! { if #[cfg(any( all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), - all(any(target_arch = "arm", target_arch = "aarch64"), - any(target_feature = "aes", target_feature = "crypto"), - not(miri), - feature = "stdsimd") - ))] { + all(target_arch = "aarch64", target_feature = "aes", not(miri)), + all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)), + ))] { mod aes_hash; pub use crate::aes_hash::AHasher; } else { diff --git a/src/operations.rs b/src/operations.rs index 23d4e22..a420587 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -110,11 +110,9 @@ pub(crate) fn aesenc(value: u128, xor: u128) -> u128 { } } -#[cfg(all( - any(target_arch = "arm", target_arch = "aarch64"), - any(target_feature = "aes", target_feature = "crypto"), - not(miri), - feature = "stdsimd" +#[cfg(any( + all(target_arch = "aarch64", target_feature = "aes", not(miri)), + all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)), ))] #[allow(unused)] #[inline(always)] @@ -142,11 +140,9 @@ pub(crate) fn aesdec(value: u128, xor: u128) -> u128 { } } -#[cfg(all( - any(target_arch = "arm", target_arch = "aarch64"), - any(target_feature = "aes", target_feature = "crypto"), - not(miri), - feature = "stdsimd" +#[cfg(any( + all(target_arch = "aarch64", target_feature = "aes", not(miri)), + all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)), ))] #[allow(unused)] #[inline(always)] diff --git a/src/random_state.rs b/src/random_state.rs index 6bdd05f..16fcc46 100644 --- a/src/random_state.rs +++ b/src/random_state.rs @@ -2,7 +2,8 @@ use core::hash::Hash; cfg_if::cfg_if! { if #[cfg(any( all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)), - all(any(target_arch = "arm", target_arch = "aarch64"), any(target_feature = "aes", target_feature = "crypto"), not(miri), feature = "stdsimd") + all(target_arch = "aarch64", target_feature = "aes", not(miri)), + all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)), ))] { use crate::aes_hash::*; } else { @@ -241,7 +242,6 @@ impl fmt::Debug for RandomState { } impl RandomState { - /// Create a new `RandomState` `BuildHasher` using random keys. /// /// Each instance will have a unique set of keys derived from [RandomSource]. @@ -328,8 +328,8 @@ impl RandomState { /// Calculates the hash of a single value. This provides a more convenient (and faster) way to obtain a hash: /// For example: #[cfg_attr( - feature = "std", - doc = r##" # Examples + feature = "std", + doc = r##" # Examples ``` use std::hash::BuildHasher; use ahash::RandomState; @@ -341,8 +341,8 @@ impl RandomState { )] /// This is similar to: #[cfg_attr( - feature = "std", - doc = r##" # Examples + feature = "std", + doc = r##" # Examples ``` use std::hash::{BuildHasher, Hash, Hasher}; use ahash::RandomState; @@ -430,12 +430,11 @@ impl BuildHasher for RandomState { AHasher::from_random_state(self) } - /// Calculates the hash of a single value. This provides a more convenient (and faster) way to obtain a hash: /// For example: #[cfg_attr( - feature = "std", - doc = r##" # Examples + feature = "std", + doc = r##" # Examples ``` use std::hash::BuildHasher; use ahash::RandomState; @@ -447,8 +446,8 @@ impl BuildHasher for RandomState { )] /// This is similar to: #[cfg_attr( - feature = "std", - doc = r##" # Examples + feature = "std", + doc = r##" # Examples ``` use std::hash::{BuildHasher, Hash, Hasher}; use ahash::RandomState; diff --git a/tests/bench.rs b/tests/bench.rs index 5bc0fc9..e038ba4 100644 --- a/tests/bench.rs +++ b/tests/bench.rs @@ -14,11 +14,12 @@ const AHASH_IMPL: &str = if cfg!(any( target_feature = "aes", not(miri), ), + all(target_arch = "aarch64", target_feature = "aes", not(miri)), all( - any(target_arch = "arm", target_arch = "aarch64"), - any(target_feature = "aes", target_feature = "crypto"), - not(miri), - feature = "stdsimd", + feature = "nightly-arm-aes", + target_arch = "arm", + target_feature = "aes", + not(miri) ), )) { "aeshash" |