Skip to content

Commit cc70182

Browse files
committed
Annotate outer AES functions with target_feature
This seems to fix the build failures we were experiencing here: rust-lang/rust#112709
1 parent 7818f35 commit cc70182

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

aes/src/armv8.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ macro_rules! define_aes_impl {
223223
impl From<&$name_enc> for $name_dec {
224224
fn from(enc: &$name_enc) -> $name_dec {
225225
let mut round_keys = enc.round_keys;
226-
inv_expanded_keys(&mut round_keys);
226+
unsafe { inv_expanded_keys(&mut round_keys) };
227227
Self { round_keys }
228228
}
229229
}

aes/src/armv8/expand.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ pub(super) fn expand_key<const L: usize, const N: usize>(key: &[u8; L]) -> [uint
4141
let mut word = ek_words[i - 1];
4242

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

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

6364
for ek in expanded_keys.iter_mut().take(N - 1).skip(1) {
@@ -68,14 +69,13 @@ pub(super) fn inv_expanded_keys<const N: usize>(expanded_keys: &mut [uint8x16_t;
6869
}
6970

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

76-
// AES single round encryption (with a "round" key of all zeros)
77-
let sub_input = vaeseq_u8(input, vdupq_n_u8(0));
77+
// AES single round encryption (with a "round" key of all zeros)
78+
let sub_input = vaeseq_u8(input, vdupq_n_u8(0));
7879

79-
vgetq_lane_u32(vreinterpretq_u32_u8(sub_input), 0)
80-
}
80+
vgetq_lane_u32(vreinterpretq_u32_u8(sub_input), 0)
8181
}

aes/src/armv8/test_expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn aes128_key_expansion() {
113113
#[test]
114114
fn aes128_key_expansion_inv() {
115115
let mut ek = load_expanded_keys(AES128_EXP_KEYS);
116-
inv_expanded_keys(&mut ek);
116+
unsafe { inv_expanded_keys(&mut ek) };
117117
assert_eq!(store_expanded_keys(ek), AES128_EXP_INVKEYS);
118118
}
119119

0 commit comments

Comments
 (0)