@@ -41,9 +41,9 @@ pub(super) fn expand_key<const L: usize, const N: usize>(key: &[u8; L]) -> [uint
41
41
let mut word = ek_words[ i - 1 ] ;
42
42
43
43
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 ] ;
45
45
} else if nk > 6 && i % nk == 4 {
46
- word = sub_word ( word)
46
+ word = unsafe { sub_word ( word) } ;
47
47
}
48
48
49
49
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
56
56
///
57
57
/// This is the reverse of the encryption keys, with the Inverse Mix Columns
58
58
/// 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 ] ) {
61
62
assert ! ( N == 11 || N == 13 || N == 15 ) ;
62
63
63
64
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;
68
69
}
69
70
70
71
/// 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) ) ;
75
76
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 ) ) ;
78
79
79
- vgetq_lane_u32 ( vreinterpretq_u32_u8 ( sub_input) , 0 )
80
- }
80
+ vgetq_lane_u32 ( vreinterpretq_u32_u8 ( sub_input) , 0 )
81
81
}
0 commit comments