From 64ba29c13684c37d18091a081792bc27e4225901 Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Wed, 20 Mar 2024 22:44:01 -0700 Subject: [PATCH 01/10] Add SmallState Signed-off-by: Tom Kaitchuck --- src/aes_hash.rs | 2 +- src/fallback_hash.rs | 3 +- src/lib.rs | 1 + src/random_state.rs | 134 ++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 136 insertions(+), 4 deletions(-) diff --git a/src/aes_hash.rs b/src/aes_hash.rs index 5ba295d..1470302 100644 --- a/src/aes_hash.rs +++ b/src/aes_hash.rs @@ -60,7 +60,7 @@ impl AHasher { } } - #[allow(unused)] // False positive + #[cfg(test)] pub(crate) fn test_with_keys(key1: u128, key2: u128) -> Self { Self { enc: key1, diff --git a/src/fallback_hash.rs b/src/fallback_hash.rs index 6d76319..a85402b 100644 --- a/src/fallback_hash.rs +++ b/src/fallback_hash.rs @@ -41,7 +41,8 @@ impl AHasher { } } - #[allow(unused)] // False positive + #[inline] + #[cfg(test)] pub(crate) fn test_with_keys(key1: u128, key2: u128) -> Self { let key1: [u64; 2] = key1.convert(); let key2: [u64; 2] = key2.convert(); diff --git a/src/lib.rs b/src/lib.rs index c0173cb..66af806 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -143,6 +143,7 @@ pub mod random_state; mod specialize; pub use crate::random_state::RandomState; +pub use crate::random_state::SmallState; use core::hash::BuildHasher; use core::hash::Hash; diff --git a/src/random_state.rs b/src/random_state.rs index d0981c5..beb45eb 100644 --- a/src/random_state.rs +++ b/src/random_state.rs @@ -154,14 +154,14 @@ impl RandomSource for DefaultRandomSource { fn gen_hasher_seed(&self) -> usize { let stack = self as *const _ as usize; let previous = self.counter.load(Ordering::Relaxed); - let new = previous.wrapping_add(stack); + let new = previous.wrapping_add(stack | 1); self.counter.store(new, Ordering::Relaxed); new } } else { fn gen_hasher_seed(&self) -> usize { let stack = self as *const _ as usize; - self.counter.fetch_add(stack, Ordering::Relaxed) + self.counter.fetch_add(stack | 1, Ordering::Relaxed) } } } @@ -254,12 +254,27 @@ pub struct RandomState { _h: PhantomData, } +/// Provides a Hasher factory similar to [RandomState] that uses less memory at the cost +/// of a slower `build_hasher` function. In general [RandomState] should be +/// preferred unless there is a need for reduced memory use. +#[derive(Clone)] +pub struct SmallState { + key: usize, + _h: PhantomData, +} + impl fmt::Debug for RandomState { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("RandomState { .. }") } } +impl fmt::Debug for SmallState { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("SmallState { .. }") + } +} + impl RandomState { /// Create a new `RandomState` `BuildHasher` using random keys. /// @@ -375,6 +390,20 @@ impl RandomState { } } +impl SmallState { + /// Create a new `SmallState` `BuildHasher` using random keys. + /// + /// Each instance will have a unique set of keys derived from [RandomSource]. + /// + #[inline] + pub fn new() -> SmallState { + SmallState { + key: get_src().gen_hasher_seed(), + _h: Default::default(), + } + } +} + /// Creates an instance of RandomState using keys obtained from the random number generator. /// Each instance created in this way will have a unique set of keys. (But the resulting instance /// can be used to create many hashers each or which will have the same keys.) @@ -392,6 +421,19 @@ impl Default for RandomState { } } +/// Creates an instance of SmallState using keys obtained from the random number generator. +/// Each instance created in this way will have a unique set of keys. (But the resulting instance +/// can be used to create many hashers each or which will have the same keys.) +/// +/// This is the same as [SmallState::new()] +#[cfg(any(feature = "compile-time-rng", feature = "runtime-rng", feature = "no-rng"))] +impl Default for SmallState { + #[inline] + fn default() -> Self { + Self::new() + } +} + impl BuildHasher for RandomState { type Hasher = AHasher; @@ -478,6 +520,94 @@ impl BuildHasher for RandomState { } } +impl BuildHasher for SmallState { + type Hasher = AHasher; + + /// Constructs a new [AHasher] with keys based on this [SmallState] object. + /// This means that two different [SmallState]s will will generate + /// [AHasher]s that will return different hashcodes, but [Hasher]s created from the same [BuildHasher] + /// will generate the same hashes for the same input data. + /// + #[cfg_attr( + feature = "std", + doc = r##" # Examples +``` + use ahash::{AHasher, SmallState}; + use std::hash::{Hasher, BuildHasher}; + + let build_hasher = SmallState::::new(); + let mut hasher_1 = build_hasher.build_hasher(); + let mut hasher_2 = build_hasher.build_hasher(); + + hasher_1.write_u32(1234); + hasher_2.write_u32(1234); + + assert_eq!(hasher_1.finish(), hasher_2.finish()); + + let other_build_hasher = SmallState::::new(); + let mut different_hasher = other_build_hasher.build_hasher(); + different_hasher.write_u32(1234); + assert_ne!(different_hasher.finish(), hasher_1.finish()); +``` + "## + )] + /// [Hasher]: std::hash::Hasher + /// [BuildHasher]: std::hash::BuildHasher + /// [HashMap]: std::collections::HashMap + #[inline] + fn build_hasher(&self) -> AHasher { + let fixed = get_fixed_seeds(); + AHasher::from_random_state(&RandomState::::from_keys(&fixed[0], &fixed[1], self.key)) + } + + /// 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 +``` + use std::hash::BuildHasher; + use ahash::SmallState; + + let hash_builder = SmallState::::new(); + let hash = hash_builder.hash_one("Some Data"); +``` + "## + )] + /// This is similar to: + #[cfg_attr( + feature = "std", + doc = r##" # Examples +``` + use std::hash::{BuildHasher, Hash, Hasher}; + use ahash::SmallState; + + let hash_builder = SmallState::::new(); + let mut hasher = hash_builder.build_hasher(); + "Some Data".hash(&mut hasher); + let hash = hasher.finish(); +``` + "## + )] + /// (Note that these two ways to get a hash may not produce the same value for the same data) + /// + /// This is intended as a convenience for code which *consumes* hashes, such + /// as the implementation of a hash table or in unit tests that check + /// whether a custom [`Hash`] implementation behaves as expected. + /// + /// This must not be used in any code which *creates* hashes, such as in an + /// implementation of [`Hash`]. The way to create a combined hash of + /// multiple values is to call [`Hash::hash`] multiple times using the same + /// [`Hasher`], not to call this method repeatedly and combine the results. + #[cfg(feature = "specialize")] + #[inline] + fn hash_one(&self, x: V) -> u64 { + use crate::specialize::CallHasher; + let fixed = get_fixed_seeds(); + T::get_hash(&x, &RandomState::::from_keys(&fixed[0], &fixed[1], self.key)) + } +} + #[cfg(test)] mod test { use super::*; From 3e14ceb6210adaa617496912080dafb2ff8081bc Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Mon, 25 Mar 2024 14:59:12 -0700 Subject: [PATCH 02/10] Speed up generating keys Signed-off-by: Tom Kaitchuck --- src/random_state.rs | 49 ++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/random_state.rs b/src/random_state.rs index beb45eb..f56fc93 100644 --- a/src/random_state.rs +++ b/src/random_state.rs @@ -30,6 +30,8 @@ use core::fmt; use core::hash::BuildHasher; use core::hash::Hasher; use core::marker::PhantomData; +use crate::convert::Convert; +use crate::operations::{folded_multiply}; pub(crate) const PI: [u64; 4] = [ 0x243f_6a88_85a3_08d3, @@ -255,8 +257,8 @@ pub struct RandomState { } /// Provides a Hasher factory similar to [RandomState] that uses less memory at the cost -/// of a slower `build_hasher` function. In general [RandomState] should be -/// preferred unless there is a need for reduced memory use. +/// of a slower `build_hasher` function. (Which is generally called once per item hashed) +/// In general [RandomState] should be preferred unless there is a need for reduced memory use. #[derive(Clone)] pub struct SmallState { key: usize, @@ -305,23 +307,19 @@ impl RandomState { fn from_keys(a: &[u64; 4], b: &[u64; 4], c: usize) -> RandomState { let &[k0, k1, k2, k3] = a; - let mut hasher = AHasher::from_random_state(&RandomState { k0, k1, k2, k3, _h: PhantomData:: }); - hasher.write_usize(c); - let mix = |l: u64, r: u64| { - let mut h = hasher.clone(); - h.write_u64(l); - h.write_u64(r); - h.finish() - }; + let combined = folded_multiply(k0 ^ c as u64, k1); + let c1 = combined.wrapping_add(k2); + let c2 = combined.wrapping_add(k3); RandomState { - k0: mix(b[0], b[2]), - k1: mix(b[1], b[3]), - k2: mix(b[2], b[1]), - k3: mix(b[3], b[0]), + k0: folded_multiply(c1 ^ b[0], b[2]), + k1: folded_multiply(c1 ^ b[1], b[3]), + k2: folded_multiply(c2 ^ b[2], b[1]), + k3: folded_multiply(c2 ^ b[3], b[0]), _h: PhantomData::default(), } } + /// Internal. Used by Default. #[inline] pub(crate) fn with_fixed_keys() -> RandomState { @@ -402,6 +400,21 @@ impl SmallState { _h: Default::default(), } } + + /// Build a `SmallState` from a single key. The provided key does not need to be of high quality, + /// but all `SmallState`s created from the same key will produce identical hashers. + /// (In contrast to `new` above) + /// + /// This allows for explicitly setting the seed to be used. + /// + /// Note: This method does not require the provided seed to be strong. + #[inline] + pub fn with_seed(key: usize) -> SmallState { + SmallState { + key, + _h: Default::default(), + } + } } /// Creates an instance of RandomState using keys obtained from the random number generator. @@ -534,16 +547,16 @@ impl BuildHasher for SmallState { ``` use ahash::{AHasher, SmallState}; use std::hash::{Hasher, BuildHasher}; - + let build_hasher = SmallState::::new(); let mut hasher_1 = build_hasher.build_hasher(); let mut hasher_2 = build_hasher.build_hasher(); - + hasher_1.write_u32(1234); hasher_2.write_u32(1234); - + assert_eq!(hasher_1.finish(), hasher_2.finish()); - + let other_build_hasher = SmallState::::new(); let mut different_hasher = other_build_hasher.build_hasher(); different_hasher.write_u32(1234); From 1e94eac5895826af24bf17c6558ab740b778a4e9 Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Mon, 25 Mar 2024 15:24:53 -0700 Subject: [PATCH 03/10] Precompute first part of mix Signed-off-by: Tom Kaitchuck --- src/random_state.rs | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/random_state.rs b/src/random_state.rs index f56fc93..4606a94 100644 --- a/src/random_state.rs +++ b/src/random_state.rs @@ -261,7 +261,7 @@ pub struct RandomState { /// In general [RandomState] should be preferred unless there is a need for reduced memory use. #[derive(Clone)] pub struct SmallState { - key: usize, + key: u64, _h: PhantomData, } @@ -286,7 +286,8 @@ impl RandomState { pub fn new() -> RandomState { let src = get_src(); let fixed = get_fixed_seeds(); - Self::from_keys(&fixed[0], &fixed[1], src.gen_hasher_seed()) + let mixed = Self::pre_mix_key(&fixed[0], src.gen_hasher_seed()); + Self::from_keys(&fixed[0], &fixed[1], mixed) } /// Create a new `RandomState` `BuildHasher` based on the provided seeds, but in such a way @@ -302,14 +303,21 @@ impl RandomState { pub fn generate_with(k0: u64, k1: u64, k2: u64, k3: u64) -> RandomState { let src = get_src(); let fixed = get_fixed_seeds(); - RandomState::from_keys(&fixed[0], &[k0, k1, k2, k3], src.gen_hasher_seed()) + let mixed = Self::pre_mix_key(&fixed[0], src.gen_hasher_seed()); + RandomState::from_keys(&fixed[0], &[k0, k1, k2, k3], mixed) } - fn from_keys(a: &[u64; 4], b: &[u64; 4], c: usize) -> RandomState { - let &[k0, k1, k2, k3] = a; - let combined = folded_multiply(k0 ^ c as u64, k1); - let c1 = combined.wrapping_add(k2); - let c2 = combined.wrapping_add(k3); + #[inline] + fn pre_mix_key(a: &[u64; 4], c: usize) -> u64 { + let &[k0, k1, _k2, _k3] = a; + folded_multiply(k0 ^ c as u64, k1) + } + + #[inline] + fn from_keys(a: &[u64; 4], b: &[u64; 4], pre_mixed_key: u64) -> RandomState { + let &[_k0, _k1, k2, k3] = a; + let c1 = pre_mixed_key.wrapping_add(k2); + let c2 = pre_mixed_key.wrapping_add(k3); RandomState { k0: folded_multiply(c1 ^ b[0], b[2]), k1: folded_multiply(c1 ^ b[1], b[3]), @@ -318,8 +326,7 @@ impl RandomState { _h: PhantomData::default(), } } - - + /// Internal. Used by Default. #[inline] pub(crate) fn with_fixed_keys() -> RandomState { @@ -337,7 +344,8 @@ impl RandomState { #[inline] pub fn with_seed(key: usize) -> RandomState { let fixed = get_fixed_seeds(); - RandomState::from_keys(&fixed[0], &fixed[1], key) + let mixed = RandomState::::pre_mix_key(&fixed[0], key); + RandomState::from_keys(&fixed[0], &fixed[1], mixed) } /// Allows for explicitly setting the seeds to used. @@ -395,8 +403,10 @@ impl SmallState { /// #[inline] pub fn new() -> SmallState { + let fixed = get_fixed_seeds(); + let mixed = RandomState::::pre_mix_key(&fixed[0], get_src().gen_hasher_seed()); SmallState { - key: get_src().gen_hasher_seed(), + key: mixed, _h: Default::default(), } } @@ -410,8 +420,10 @@ impl SmallState { /// Note: This method does not require the provided seed to be strong. #[inline] pub fn with_seed(key: usize) -> SmallState { + let fixed = get_fixed_seeds(); + let mixed = RandomState::::pre_mix_key(&fixed[0], key); SmallState { - key, + key: mixed, _h: Default::default(), } } From e2ae7b75674a29cc77fd764afab0a5efc4522f5c Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Mon, 25 Mar 2024 17:13:09 -0700 Subject: [PATCH 04/10] Further speed up key generation Signed-off-by: Tom Kaitchuck --- src/random_state.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/random_state.rs b/src/random_state.rs index 4606a94..ebd12fa 100644 --- a/src/random_state.rs +++ b/src/random_state.rs @@ -316,13 +316,13 @@ impl RandomState { #[inline] fn from_keys(a: &[u64; 4], b: &[u64; 4], pre_mixed_key: u64) -> RandomState { let &[_k0, _k1, k2, k3] = a; - let c1 = pre_mixed_key.wrapping_add(k2); - let c2 = pre_mixed_key.wrapping_add(k3); + let c1 = folded_multiply(pre_mixed_key, k2); + let c2 = folded_multiply(pre_mixed_key, k3); RandomState { - k0: folded_multiply(c1 ^ b[0], b[2]), - k1: folded_multiply(c1 ^ b[1], b[3]), - k2: folded_multiply(c2 ^ b[2], b[1]), - k3: folded_multiply(c2 ^ b[3], b[0]), + k0: (c1 ^ b[0]).wrapping_add(b[2]), + k1: (c1 ^ b[1]).wrapping_add(b[3]), + k2: (c2 ^ b[2]).wrapping_add(b[1]), + k3: (c2 ^ b[3]).wrapping_add(b[0]), _h: PhantomData::default(), } } From d494c94fdcf1e6b71d3ad34526a0eadfec1e5621 Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Wed, 27 Mar 2024 00:11:17 -0700 Subject: [PATCH 05/10] Add shuffle instructions Signed-off-by: Tom Kaitchuck --- src/lib.rs | 4 ++-- src/operations.rs | 53 ++++++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 66af806..c0a9ece 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -251,8 +251,8 @@ impl Default for AHasher { // #[inline(never)] // #[doc(hidden)] // pub fn hash_test(input: &[u8]) -> u64 { -// let a = RandomState::with_seeds(11, 22, 33, 44); -// <[u8]>::get_hash(input, &a) +// let a = RandomState::<&[u8]>::with_seeds(11, 22, 33, 44); +// a.hash_one(input) // } #[cfg(feature = "std")] diff --git a/src/operations.rs b/src/operations.rs index 986a500..e20af9a 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -7,7 +7,7 @@ pub(crate) const MULTIPLE: u64 = 6364136223846793005; /// This is a constant with a lot of special properties found by automated search. /// See the unit tests below. (Below are alternative values) -#[cfg(all(target_feature = "ssse3", not(miri)))] +#[allow(dead_code)] const SHUFFLE_MASK: u128 = 0x020a0700_0c01030e_050f0d08_06090b04_u128; //const SHUFFLE_MASK: u128 = 0x000d0702_0a040301_05080f0c_0e0b0609_u128; //const SHUFFLE_MASK: u128 = 0x040A0700_030E0106_0D050F08_020B0C09_u128; @@ -51,17 +51,19 @@ pub(crate) fn read_small(data: &[u8]) -> [u64; 2] { #[inline(always)] pub(crate) fn shuffle(a: u128) -> u128 { - #[cfg(all(target_feature = "ssse3", not(miri)))] - { - #[cfg(target_arch = "x86")] - use core::arch::x86::*; - #[cfg(target_arch = "x86_64")] - use core::arch::x86_64::*; - unsafe { transmute!(_mm_shuffle_epi8(transmute!(a), transmute!(SHUFFLE_MASK))) } - } - #[cfg(not(all(target_feature = "ssse3", not(miri))))] - { - a.swap_bytes() + cfg_if::cfg_if! { + if #[cfg(all(target_feature = "ssse3", not(miri)))] { + #[cfg(target_arch = "x86")] + use core::arch::x86::*; + #[cfg(target_arch = "x86_64")] + use core::arch::x86_64::*; + unsafe { transmute!(_mm_shuffle_epi8(transmute!(a), transmute!(SHUFFLE_MASK))) } + } else if #[cfg(all(target_arch = "aarch64", target_feature = "neon", not(miri)))] { + use core::arch::aarch64::vqtbl1q_s8; + unsafe { transmute!(vqtbl1q_s8(transmute!(a), transmute!(SHUFFLE_MASK))) } + } else { + a.swap_bytes() + } } } @@ -79,22 +81,25 @@ pub(crate) fn shuffle_and_add(base: u128, to_add: u128) -> u128 { add_by_64s(shuffled, to_add.convert()).convert() } -#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "sse2", not(miri)))] #[inline(always)] pub(crate) fn add_by_64s(a: [u64; 2], b: [u64; 2]) -> [u64; 2] { - unsafe { - #[cfg(target_arch = "x86")] - use core::arch::x86::*; - #[cfg(target_arch = "x86_64")] - use core::arch::x86_64::*; - transmute!(_mm_add_epi64(transmute!(a), transmute!(b))) + cfg_if::cfg_if! { + if #[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "sse2", not(miri)))] { + unsafe { + #[cfg(target_arch = "x86")] + use core::arch::x86::*; + #[cfg(target_arch = "x86_64")] + use core::arch::x86_64::*; + transmute!(_mm_add_epi64(transmute!(a), transmute!(b))) + } + } else if #[cfg(all(target_arch = "aarch64", target_feature = "neon", not(miri)))] { + use core::arch::aarch64::vaddq_u64; + unsafe { transmute!(vaddq_u64(transmute!(a), transmute!(b))) } + } else { + [a[0].wrapping_add(b[0]), a[1].wrapping_add(b[1])] + } } -} -#[cfg(not(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "sse2", not(miri))))] -#[inline(always)] -pub(crate) fn add_by_64s(a: [u64; 2], b: [u64; 2]) -> [u64; 2] { - [a[0].wrapping_add(b[0]), a[1].wrapping_add(b[1])] } #[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)))] From 864988381a4ee1da76027ee8c76c27b480a51a3a Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Wed, 27 Mar 2024 08:09:29 -0700 Subject: [PATCH 06/10] Add debug term Signed-off-by: Tom Kaitchuck --- .github/workflows/rust.yml | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7e28cda..9abca92 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -72,14 +72,21 @@ jobs: toolchain: stable targets: aarch64-apple-darwin - run: cargo check --target aarch64-apple-darwin - - run: cargo test - - run: cargo test --no-default-features --features compile-time-rng - - name: Install 1.72.0 - uses: dtolnay/rust-toolchain@master - with: - toolchain: 1.72.0 - targets: aarch64-apple-darwin - - run: cargo +1.72.0 check --target aarch64-apple-darwin +# - run: cargo test +# - run: cargo test --no-default-features --features compile-time-rng +# - name: Install 1.72.0 +# uses: dtolnay/rust-toolchain@master +# with: +# toolchain: 1.72.0 +# targets: aarch64-apple-darwin +# - run: cargo +1.72.0 check --target aarch64-apple-darwin + aarch64-debug: + name: Debug Apple + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup upterm session + uses: lhotari/action-upterm@v1 i686-unknown-linux-gnu: name: Linux i686 runs-on: ubuntu-latest From be5e0ebb245983ae63954dbbd792177eb8165611 Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Wed, 27 Mar 2024 08:17:33 -0700 Subject: [PATCH 07/10] Debug on mac Signed-off-by: Tom Kaitchuck --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9abca92..daf68d4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -82,7 +82,7 @@ jobs: # - run: cargo +1.72.0 check --target aarch64-apple-darwin aarch64-debug: name: Debug Apple - runs-on: ubuntu-latest + runs-on: macos-latest steps: - uses: actions/checkout@v2 - name: Setup upterm session From 288b21bfef6f258f4f1444522971febae02b8e0a Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Wed, 27 Mar 2024 11:17:36 -0700 Subject: [PATCH 08/10] Change to macos 14 Signed-off-by: Tom Kaitchuck --- .github/workflows/rust.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index daf68d4..49427ea 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -64,7 +64,7 @@ jobs: - run: cargo +1.72.0 check --target armv7-unknown-linux-gnueabihf aarch64-apple-darwin: name: Aarch64 Apple Darwin - runs-on: macos-latest + runs-on: macos-14 steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master @@ -72,17 +72,17 @@ jobs: toolchain: stable targets: aarch64-apple-darwin - run: cargo check --target aarch64-apple-darwin -# - run: cargo test -# - run: cargo test --no-default-features --features compile-time-rng -# - name: Install 1.72.0 -# uses: dtolnay/rust-toolchain@master -# with: -# toolchain: 1.72.0 -# targets: aarch64-apple-darwin -# - run: cargo +1.72.0 check --target aarch64-apple-darwin + - run: cargo test + - run: cargo test --no-default-features --features compile-time-rng + - name: Install 1.72.0 + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.72.0 + targets: aarch64-apple-darwin + - run: cargo +1.72.0 check --target aarch64-apple-darwin aarch64-debug: name: Debug Apple - runs-on: macos-latest + runs-on: macos-14 steps: - uses: actions/checkout@v2 - name: Setup upterm session From d815ed3506683a484c51960bd49d72b81827bc8e Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Wed, 27 Mar 2024 15:47:35 -0700 Subject: [PATCH 09/10] Add mixcolumns step accedently removed earlier. Signed-off-by: Tom Kaitchuck --- src/aes_hash.rs | 8 -------- src/operations.rs | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/aes_hash.rs b/src/aes_hash.rs index 1470302..be0d996 100644 --- a/src/aes_hash.rs +++ b/src/aes_hash.rs @@ -101,16 +101,8 @@ impl AHasher { let result: [u64; 2] = aesdec(combined, combined).convert(); result[0] } - - #[inline] - #[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); aesdec(aesdec(combined, self.key), combined) diff --git a/src/operations.rs b/src/operations.rs index e20af9a..eed3a2a 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -127,7 +127,7 @@ pub(crate) fn aesenc(value: u128, xor: u128) -> u128 { use core::arch::aarch64::*; #[cfg(target_arch = "arm")] use core::arch::arm::*; - unsafe { transmute!(vaeseq_u8(transmute!(value), transmute!(xor))) } + unsafe { transmute!(vaesmcq_u8(vaeseq_u8(transmute!(value), transmute!(xor)))) } } #[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)))] @@ -155,7 +155,7 @@ pub(crate) fn aesdec(value: u128, xor: u128) -> u128 { use core::arch::aarch64::*; #[cfg(target_arch = "arm")] use core::arch::arm::*; - unsafe { transmute!(vaesdq_u8(transmute!(value), transmute!(xor))) } + unsafe { transmute!(vaesimcq_u8(vaesdq_u8(transmute!(value), transmute!(xor)))) } } #[allow(unused)] From a15c358a3b525fe4638cc78cbd5e89dc4a0ace65 Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Wed, 27 Mar 2024 15:58:22 -0700 Subject: [PATCH 10/10] Remove debug shell Signed-off-by: Tom Kaitchuck --- .github/workflows/rust.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 49427ea..ae04cc7 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -80,13 +80,13 @@ jobs: toolchain: 1.72.0 targets: aarch64-apple-darwin - run: cargo +1.72.0 check --target aarch64-apple-darwin - aarch64-debug: - name: Debug Apple - runs-on: macos-14 - steps: - - uses: actions/checkout@v2 - - name: Setup upterm session - uses: lhotari/action-upterm@v1 +# aarch64-debug: +# name: Debug Apple +# runs-on: macos-14 +# steps: +# - uses: actions/checkout@v2 +# - name: Setup upterm session +# uses: lhotari/action-upterm@v1 i686-unknown-linux-gnu: name: Linux i686 runs-on: ubuntu-latest