@@ -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,26 +56,26 @@ 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 ) {
64- unsafe { * ek = vaesimcq_u8 ( * ek) }
65+ * ek = vaesimcq_u8 ( * ek) ;
6566 }
6667
6768 expanded_keys. reverse ( ) ;
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}
0 commit comments