Skip to content

Commit b424dc4

Browse files
authored
Remove nightly ARM flag. (Requires version bump) (#217)
Signed-off-by: Tom Kaitchuck <Tom.Kaitchuck@gmail.com>
1 parent 8c3f257 commit b424dc4

8 files changed

+31
-33
lines changed

Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ no-rng = []
4444
# in case this is being used on an architecture lacking core::sync::atomic::AtomicUsize and friends
4545
atomic-polyfill = [ "dep:atomic-polyfill", "once_cell/atomic-polyfill"]
4646

47-
# Nightly-only support for AES intrinsics on 32-bit ARM
48-
nightly-arm-aes = []
49-
5047
[[bench]]
5148
name = "ahash"
5249
path = "tests/bench.rs"

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ The aHash package has the following flags:
5757
This is done using the [getrandom](https://github.com/rust-random/getrandom) crate.
5858
* `compile-time-rng`: For OS targets without access to a random number generator, `compile-time-rng` provides an alternative.
5959
If `getrandom` is unavailable and `compile-time-rng` is enabled, aHash will generate random numbers at compile time and embed them in the binary.
60-
* `nightly-arm-aes`: To use AES instructions on 32-bit ARM, which requires nightly. This is not needed on AArch64.
6160
This allows for DOS resistance even if there is no random number generator available at runtime (assuming the compiled binary is not public).
6261
This makes the binary non-deterministic. (If non-determinism is a problem see [constrandom's documentation](https://github.com/tkaitchuck/constrandom#deterministic-builds))
6362

src/aes_hash.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ impl AHasher {
101101
let result: [u64; 2] = aesdec(combined, combined).convert();
102102
result[0]
103103
}
104+
105+
#[inline]
106+
#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
107+
fn final_mix(&self) -> u128 {
108+
let sum = aesenc(self.sum, self.key);
109+
aesdec(aesdec(sum, self.enc), sum)
110+
}
111+
112+
#[inline]
113+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
114+
fn final_mix(&self) -> u128 {
115+
let combined = aesenc(self.sum, self.enc);
116+
aesdec(aesdec(combined, self.key), combined)
117+
}
104118
}
105119

106120
/// Provides [Hasher] methods to hash all of the primitive types.
@@ -207,10 +221,10 @@ impl Hasher for AHasher {
207221
}
208222
}
209223
}
224+
210225
#[inline]
211226
fn finish(&self) -> u64 {
212-
let combined = aesenc(self.sum, self.enc);
213-
let result: [u64; 2] = aesdec(aesdec(combined, self.key), combined).convert();
227+
let result: [u64; 2] = self.final_mix().convert();
214228
result[0]
215229
}
216230
}
@@ -329,15 +343,13 @@ impl Hasher for AHasherStr {
329343
fn write(&mut self, bytes: &[u8]) {
330344
if bytes.len() > 8 {
331345
self.0.write(bytes);
332-
self.0.enc = aesenc(self.0.sum, self.0.enc);
333-
self.0.enc = aesdec(aesdec(self.0.enc, self.0.key), self.0.enc);
346+
self.0.enc = self.0.final_mix();
334347
} else {
335348
add_in_length(&mut self.0.enc, bytes.len() as u64);
336349

337350
let value = read_small(bytes).convert();
338351
self.0.sum = shuffle_and_add(self.0.sum, value);
339-
self.0.enc = aesenc(self.0.sum, self.0.enc);
340-
self.0.enc = aesdec(aesdec(self.0.enc, self.0.key), self.0.enc);
352+
self.0.enc = self.0.final_mix();
341353
}
342354
}
343355

src/hash_quality_test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ mod fallback_tests {
442442
#[cfg(any(
443443
all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
444444
all(target_arch = "aarch64", target_feature = "aes", not(miri)),
445-
all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)),
445+
all(target_arch = "arm", target_feature = "aes", not(miri)),
446446
))]
447447
#[cfg(test)]
448448
mod aes_tests {

src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ Note the import of [HashMapExt]. This is needed for the constructor.
9898
#![allow(clippy::pedantic, clippy::cast_lossless, clippy::unreadable_literal, unused_imports)]
9999
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
100100
#![cfg_attr(feature = "specialize", feature(min_specialization))]
101-
#![cfg_attr(feature = "nightly-arm-aes", feature(stdarch_arm_neon_intrinsics))]
102101

103102
#[macro_use]
104103
mod convert;
@@ -108,8 +107,8 @@ mod fallback_hash;
108107
cfg_if::cfg_if! {
109108
if #[cfg(any(
110109
all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
111-
all(feature = "nightly-arm-aes", target_arch = "aarch64", target_feature = "aes", not(miri)),
112-
all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)),
110+
all(target_arch = "aarch64", target_feature = "aes", not(miri)),
111+
all(target_arch = "arm", target_feature = "aes", not(miri)),
113112
))] {
114113
mod aes_hash;
115114
pub use crate::aes_hash::AHasher;

src/operations.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ pub(crate) fn aesenc(value: u128, xor: u128) -> u128 {
112112
}
113113

114114
#[cfg(any(
115-
all(feature = "nightly-arm-aes", target_arch = "aarch64", target_feature = "aes", not(miri)),
116-
all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)),
115+
all(target_arch = "aarch64", target_feature = "aes", not(miri)),
116+
all(target_arch = "arm", target_feature = "aes", not(miri)),
117117
))]
118118
#[allow(unused)]
119119
#[inline(always)]
@@ -122,9 +122,7 @@ pub(crate) fn aesenc(value: u128, xor: u128) -> u128 {
122122
use core::arch::aarch64::*;
123123
#[cfg(target_arch = "arm")]
124124
use core::arch::arm::*;
125-
let res = unsafe { vaesmcq_u8(vaeseq_u8(transmute!(value), transmute!(0u128))) };
126-
let value: u128 = transmute!(res);
127-
xor ^ value
125+
unsafe { transmute!(vaeseq_u8(transmute!(value), transmute!(xor))) }
128126
}
129127

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

144142
#[cfg(any(
145-
all(feature = "nightly-arm-aes", target_arch = "aarch64", target_feature = "aes", not(miri)),
146-
all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)),
143+
all(target_arch = "aarch64", target_feature = "aes", not(miri)),
144+
all(target_arch = "arm", target_feature = "aes", not(miri)),
147145
))]
148146
#[allow(unused)]
149147
#[inline(always)]
@@ -152,9 +150,7 @@ pub(crate) fn aesdec(value: u128, xor: u128) -> u128 {
152150
use core::arch::aarch64::*;
153151
#[cfg(target_arch = "arm")]
154152
use core::arch::arm::*;
155-
let res = unsafe { vaesimcq_u8(vaesdq_u8(transmute!(value), transmute!(0u128))) };
156-
let value: u128 = transmute!(res);
157-
xor ^ value
153+
unsafe { transmute!(vaesdq_u8(transmute!(value), transmute!(xor))) }
158154
}
159155

160156
#[allow(unused)]

src/random_state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use core::hash::Hash;
22
cfg_if::cfg_if! {
33
if #[cfg(any(
44
all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
5-
all(feature = "nightly-arm-aes", target_arch = "aarch64", target_feature = "aes", not(miri)),
6-
all(feature = "nightly-arm-aes", target_arch = "arm", target_feature = "aes", not(miri)),
5+
all(target_arch = "aarch64", target_feature = "aes", not(miri)),
6+
all(target_arch = "arm", target_feature = "aes", not(miri)),
77
))] {
88
use crate::aes_hash::*;
99
} else {

tests/bench.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ const AHASH_IMPL: &str = if cfg!(any(
1212
target_feature = "aes",
1313
not(miri),
1414
),
15-
all(feature = "nightly-arm-aes", target_arch = "aarch64", target_feature = "aes", not(miri)),
16-
all(
17-
feature = "nightly-arm-aes",
18-
target_arch = "arm",
19-
target_feature = "aes",
20-
not(miri)
21-
),
15+
all(target_arch = "aarch64", target_feature = "aes", not(miri)),
16+
all(target_arch = "arm", target_feature = "aes", not(miri)),
2217
)) {
2318
"aeshash"
2419
} else {

0 commit comments

Comments
 (0)