Skip to content

Commit

Permalink
Remove nightly ARM flag. (Requires version bump)
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Kaitchuck <Tom.Kaitchuck@gmail.com>
  • Loading branch information
tkaitchuck committed Mar 2, 2024
1 parent e7481cd commit 4cd6ee9
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 37 deletions.
7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ahash"
version = "0.8.8"
version = "0.9.0"
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"
Expand All @@ -12,7 +12,7 @@ edition = "2018"
readme = "README.md"
build = "./build.rs"
exclude = ["/smhasher", "/benchmark_tools"]
rust-version = "1.60.0"
rust-version = "1.72.0"

[lib]
name = "ahash"
Expand Down Expand Up @@ -44,9 +44,6 @@ 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"
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ 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))

Expand Down
24 changes: 18 additions & 6 deletions src/aes_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,24 @@ impl Hasher for AHasher {
}
}
}

#[inline]
fn finish(&self) -> u64 {
#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
fn final_mix(&self) -> u128 {
let sum = aesenc(self.sum, self.key);
aesdec(aesdec(sum, self.enc), sum)
}

#[inline]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn final_mix(&self) -> u128 {
let combined = aesenc(self.sum, self.enc);
let result: [u64; 2] = aesdec(aesdec(combined, self.key), combined).convert();
aesdec(aesdec(combined, self.key), combined)
}

#[inline]
fn finish(&self) -> u64 {
let result: [u64; 2] = self.final_mix().convert();
result[0]
}
}
Expand Down Expand Up @@ -330,15 +344,13 @@ impl Hasher for AHasherStr {
fn write(&mut self, bytes: &[u8]) {
if bytes.len() > 8 {
self.0.write(bytes);
self.0.enc = aesenc(self.0.sum, self.0.enc);
self.0.enc = aesdec(aesdec(self.0.enc, self.0.key), self.0.enc);
self.0.enc = self.0.final_mix();
} 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 = aesenc(self.0.sum, self.0.enc);
self.0.enc = aesdec(aesdec(self.0.enc, self.0.key), self.0.enc);
self.0.enc = self.0.final_mix();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/hash_quality_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ mod fallback_tests {
#[cfg(any(
all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
all(target_arch = "aarch64", target_feature = "aes", not(miri)),
all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)),
all(target_arch = "arm", target_feature = "aes", not(miri)),
))]
#[cfg(test)]
mod aes_tests {
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ 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 = "nightly-arm-aes", feature(stdarch_arm_neon_intrinsics))]

#[macro_use]
mod convert;
Expand All @@ -108,8 +107,8 @@ 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(feature = "nightly-arm-aes", target_arch = "aarch64", target_feature = "aes", not(miri)),
all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)),
all(target_arch = "aarch64", target_feature = "aes", not(miri)),
all(target_arch = "arm", target_feature = "aes", not(miri)),
))] {
mod aes_hash;
pub use crate::aes_hash::AHasher;
Expand Down
16 changes: 6 additions & 10 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ pub(crate) fn aesenc(value: u128, xor: u128) -> u128 {
}

#[cfg(any(
all(feature = "nightly-arm-aes", target_arch = "aarch64", target_feature = "aes", not(miri)),
all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)),
all(target_arch = "aarch64", target_feature = "aes", not(miri)),
all(target_arch = "arm", target_feature = "aes", not(miri)),
))]
#[allow(unused)]
#[inline(always)]
Expand All @@ -122,9 +122,7 @@ pub(crate) fn aesenc(value: u128, xor: u128) -> u128 {
use core::arch::aarch64::*;
#[cfg(target_arch = "arm")]
use core::arch::arm::*;
let res = unsafe { vaesmcq_u8(vaeseq_u8(transmute!(value), transmute!(0u128))) };
let value: u128 = transmute!(res);
xor ^ value
unsafe { transmute!(vaeseq_u8(transmute!(value), transmute!(xor))) };
}

#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)))]
Expand All @@ -142,8 +140,8 @@ pub(crate) fn aesdec(value: u128, xor: u128) -> u128 {
}

#[cfg(any(
all(feature = "nightly-arm-aes", target_arch = "aarch64", target_feature = "aes", not(miri)),
all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)),
all(target_arch = "aarch64", target_feature = "aes", not(miri)),
all(target_arch = "arm", target_feature = "aes", not(miri)),
))]
#[allow(unused)]
#[inline(always)]
Expand All @@ -152,9 +150,7 @@ pub(crate) fn aesdec(value: u128, xor: u128) -> u128 {
use core::arch::aarch64::*;
#[cfg(target_arch = "arm")]
use core::arch::arm::*;
let res = unsafe { vaesimcq_u8(vaesdq_u8(transmute!(value), transmute!(0u128))) };
let value: u128 = transmute!(res);
xor ^ value
unsafe { transmute!(vaesdq_u8(transmute!(value), transmute!(xor))) }
}

#[allow(unused)]
Expand Down
4 changes: 2 additions & 2 deletions src/random_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +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(feature = "nightly-arm-aes", target_arch = "aarch64", target_feature = "aes", not(miri)),
all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)),
all(target_arch = "aarch64", target_feature = "aes", not(miri)),
all(target_arch = "arm", target_feature = "aes", not(miri)),
))] {
use crate::aes_hash::*;
} else {
Expand Down
10 changes: 2 additions & 8 deletions tests/bench.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg_attr(feature = "specialize", feature(build_hasher_simple_hash_one))]

use ahash::{AHasher, RandomState};
use criterion::*;
Expand All @@ -14,13 +13,8 @@ const AHASH_IMPL: &str = if cfg!(any(
target_feature = "aes",
not(miri),
),
all(feature = "nightly-arm-aes", target_arch = "aarch64", target_feature = "aes", not(miri)),
all(
feature = "nightly-arm-aes",
target_arch = "arm",
target_feature = "aes",
not(miri)
),
all(target_arch = "aarch64", target_feature = "aes", not(miri)),
all(target_arch = "arm", target_feature = "aes", not(miri)),
)) {
"aeshash"
} else {
Expand Down
1 change: 0 additions & 1 deletion tests/map_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg_attr(feature = "specialize", feature(build_hasher_simple_hash_one))]

use std::hash::{BuildHasher, Hash, Hasher};

Expand Down

0 comments on commit 4cd6ee9

Please sign in to comment.