Skip to content

Commit

Permalink
Annotate outer AES functions with target_feature
Browse files Browse the repository at this point in the history
This seems to fix the build failures we were experiencing here:

rust-lang/rust#112709
  • Loading branch information
tarcieri committed Jun 16, 2023
1 parent 7818f35 commit c7fe62e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion aes/src/armv8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ macro_rules! define_aes_impl {
impl From<&$name_enc> for $name_dec {
fn from(enc: &$name_enc) -> $name_dec {
let mut round_keys = enc.round_keys;
inv_expanded_keys(&mut round_keys);
unsafe { inv_expanded_keys(&mut round_keys) };
Self { round_keys }
}
}
Expand Down
26 changes: 13 additions & 13 deletions aes/src/armv8/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ pub(super) fn expand_key<const L: usize, const N: usize>(key: &[u8; L]) -> [uint
let mut word = ek_words[i - 1];

if i % nk == 0 {
word = sub_word(word).rotate_right(8) ^ ROUND_CONSTS[i / nk - 1];
word = unsafe { sub_word(word) }.rotate_right(8) ^ ROUND_CONSTS[i / nk - 1];
} else if nk > 6 && i % nk == 4 {
word = sub_word(word)
word = unsafe { sub_word(word) };
}

ek_words[i] = ek_words[i - nk] ^ word;
Expand All @@ -56,26 +56,26 @@ pub(super) fn expand_key<const L: usize, const N: usize>(key: &[u8; L]) -> [uint
///
/// This is the reverse of the encryption keys, with the Inverse Mix Columns
/// operation applied to all but the first and last expanded key.
#[inline]
pub(super) fn inv_expanded_keys<const N: usize>(expanded_keys: &mut [uint8x16_t; N]) {
#[target_feature(enable = "aes")]
#[target_feature(enable = "neon")]
pub(super) unsafe fn inv_expanded_keys<const N: usize>(expanded_keys: &mut [uint8x16_t; N]) {
assert!(N == 11 || N == 13 || N == 15);

for ek in expanded_keys.iter_mut().take(N - 1).skip(1) {
unsafe { *ek = vaesimcq_u8(*ek) }
*ek = vaesimcq_u8(*ek);
}

expanded_keys.reverse();
}

/// Sub bytes for a single AES word: used for key expansion.
#[inline(always)]
fn sub_word(input: u32) -> u32 {
unsafe {
let input = vreinterpretq_u8_u32(vdupq_n_u32(input));
#[target_feature(enable = "aes")]
#[target_feature(enable = "neon")]
unsafe fn sub_word(input: u32) -> u32 {
let input = vreinterpretq_u8_u32(vdupq_n_u32(input));

// AES single round encryption (with a "round" key of all zeros)
let sub_input = vaeseq_u8(input, vdupq_n_u8(0));
// AES single round encryption (with a "round" key of all zeros)
let sub_input = vaeseq_u8(input, vdupq_n_u8(0));

vgetq_lane_u32(vreinterpretq_u32_u8(sub_input), 0)
}
vgetq_lane_u32(vreinterpretq_u32_u8(sub_input), 0)
}
2 changes: 1 addition & 1 deletion aes/src/armv8/test_expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn aes128_key_expansion() {
#[test]
fn aes128_key_expansion_inv() {
let mut ek = load_expanded_keys(AES128_EXP_KEYS);
inv_expanded_keys(&mut ek);
unsafe { inv_expanded_keys(&mut ek) };
assert_eq!(store_expanded_keys(ek), AES128_EXP_INVKEYS);
}

Expand Down

0 comments on commit c7fe62e

Please sign in to comment.