11pub ( crate ) mod ni;
2- #[ cfg( target_arch = "x86_64" ) ]
2+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
33pub ( crate ) mod vaes256;
4- #[ cfg( target_arch = "x86_64" ) ]
4+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
55pub ( crate ) mod vaes512;
66
77#[ cfg( target_arch = "x86" ) ]
@@ -11,26 +11,24 @@ use core::arch::x86_64 as arch;
1111
1212use self :: arch:: * ;
1313use crate :: Block ;
14+ #[ cfg( all( target_arch = "x86_64" , aes_avx512) ) ]
15+ use cipher:: consts:: U64 ;
1416use cipher:: {
1517 AlgorithmName , BlockCipherDecBackend , BlockCipherDecClosure , BlockCipherDecrypt ,
1618 BlockCipherEncBackend , BlockCipherEncClosure , BlockCipherEncrypt , BlockSizeUser , InOut , Key ,
1719 KeyInit , KeySizeUser , ParBlocksSizeUser ,
1820 consts:: { U9 , U16 , U24 , U32 } ,
1921 crypto_common:: WeakKeyError ,
2022} ;
21- #[ cfg( target_arch = "x86_64" ) ]
22- use cipher:: {
23- Array , InOutBuf ,
24- consts:: { U30 , U64 } ,
25- typenum:: Unsigned ,
26- } ;
27- #[ cfg( target_arch = "x86_64" ) ]
23+ #[ cfg( all( target_arch = "x86_64" , any( aes_avx256, aes_avx512) ) ) ]
24+ use cipher:: { Array , InOutBuf , consts:: U30 , typenum:: Unsigned } ;
25+ #[ cfg( all( target_arch = "x86_64" , any( aes_avx256, aes_avx512) ) ) ]
2826use core:: cell:: OnceCell ;
2927use core:: fmt;
3028
31- #[ cfg( target_arch = "x86_64" ) ]
29+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
3230pub ( crate ) type Block30 = Array < Block , U30 > ;
33- #[ cfg( target_arch = "x86_64" ) ]
31+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
3432pub ( crate ) type Block64 = Array < Block , U64 > ;
3533
3634pub ( crate ) mod features {
@@ -41,81 +39,81 @@ pub(crate) mod features {
4139 pub ( crate ) mod aes {
4240 pub use super :: features_aes:: * ;
4341 }
44- #[ cfg( target_arch = "x86_64" ) ]
42+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
4543 pub ( crate ) mod avx {
4644 pub use super :: features_avx:: * ;
4745 }
48- #[ cfg( target_arch = "x86_64" ) ]
46+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
4947 pub ( crate ) mod avx512f {
5048 pub use super :: features_avx512f:: * ;
5149 }
52- #[ cfg( target_arch = "x86_64" ) ]
50+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
5351 pub ( crate ) mod vaes {
5452 pub use super :: features_vaes:: * ;
5553 }
5654}
5755
5856type Simd128RoundKeys < const ROUNDS : usize > = [ __m128i ; ROUNDS ] ;
59- #[ cfg( target_arch = "x86_64" ) ]
57+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
6058type Simd256RoundKeys < const ROUNDS : usize > = [ __m256i ; ROUNDS ] ;
61- #[ cfg( target_arch = "x86_64" ) ]
59+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
6260type Simd512RoundKeys < const ROUNDS : usize > = [ __m512i ; ROUNDS ] ;
6361
6462#[ derive( Clone ) ]
6563enum Backend {
6664 Ni ,
67- #[ cfg( target_arch = "x86_64" ) ]
65+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
6866 Vaes256 ,
69- #[ cfg( target_arch = "x86_64" ) ]
67+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
7068 Vaes512 ,
7169}
7270
7371#[ derive( Clone , Copy ) ]
7472struct Features {
75- #[ cfg( target_arch = "x86_64" ) ]
73+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
7674 avx : self :: features:: avx:: InitToken ,
77- #[ cfg( target_arch = "x86_64" ) ]
75+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
7876 avx512f : self :: features:: avx512f:: InitToken ,
79- #[ cfg( target_arch = "x86_64" ) ]
77+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
8078 vaes : self :: features:: vaes:: InitToken ,
8179}
8280
8381impl Features {
8482 fn new ( ) -> Self {
8583 Self {
86- #[ cfg( target_arch = "x86_64" ) ]
84+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
8785 avx : self :: features:: avx:: init ( ) ,
88- #[ cfg( target_arch = "x86_64" ) ]
86+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
8987 avx512f : self :: features:: avx512f:: init ( ) ,
90- #[ cfg( target_arch = "x86_64" ) ]
88+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
9189 vaes : self :: features:: vaes:: init ( ) ,
9290 }
9391 }
9492
95- #[ cfg( target_arch = "x86_64" ) ]
93+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
9694 fn has_vaes256 ( & self ) -> bool {
9795 #[ cfg( target_arch = "x86_64" ) ]
98- if self . vaes . get ( ) && self . avx . get ( ) && ! cfg ! ( aes_avx256_disable ) {
96+ if cfg ! ( aes_avx256 ) && self . vaes . get ( ) && self . avx . get ( ) {
9997 return true ;
10098 }
10199 false
102100 }
103101
104- #[ cfg( target_arch = "x86_64" ) ]
102+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
105103 fn has_vaes512 ( & self ) -> bool {
106104 #[ cfg( target_arch = "x86_64" ) ]
107- if self . vaes . get ( ) && self . avx512f . get ( ) && ! cfg ! ( aes_avx512_disable ) {
105+ if cfg ! ( aes_avx512 ) && self . vaes . get ( ) && self . avx512f . get ( ) {
108106 return true ;
109107 }
110108 false
111109 }
112110
113111 fn dispatch ( & self ) -> Backend {
114- #[ cfg( target_arch = "x86_64" ) ]
112+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
115113 if self . has_vaes512 ( ) {
116114 return self :: Backend :: Vaes512 ;
117115 }
118- #[ cfg( target_arch = "x86_64" ) ]
116+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
119117 if self . has_vaes256 ( ) {
120118 return self :: Backend :: Vaes256 ;
121119 }
@@ -141,33 +139,35 @@ macro_rules! define_aes_impl {
141139 pub ( crate ) struct Ni <' a> {
142140 pub ( crate ) keys: & ' a Simd128RoundKeys <$rounds>,
143141 }
144- #[ cfg( target_arch = "x86_64" ) ]
142+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
145143 impl <' a> Ni <' a> {
146144 pub const fn par_blocks( & self ) -> usize {
147145 <Self as ParBlocksSizeUser >:: ParBlocksSize :: USIZE
148146 }
149147 }
150- #[ cfg( target_arch = "x86_64" ) ]
148+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
151149 impl <' a> From <& Vaes256 <' a>> for Ni <' a> {
152150 fn from( backend: & Vaes256 <' a>) -> Self {
153151 Self { keys: backend. keys }
154152 }
155153 }
156154
155+ #[ cfg( all( target_arch = "x86_64" , any( aes_avx256, aes_avx512) ) ) ]
157156 #[ derive( Clone ) ]
158- #[ cfg( target_arch = "x86_64" ) ]
159157 pub ( crate ) struct Vaes256 <' a> {
158+ #[ allow( unused) ] // TODO: remove once cfg flags are removed
160159 pub ( crate ) features: Features ,
161160 pub ( crate ) keys: & ' a Simd128RoundKeys <$rounds>,
162161 pub ( crate ) simd_256_keys: OnceCell <Simd256RoundKeys <$rounds>>,
163162 }
164- #[ cfg( target_arch = "x86_64" ) ]
163+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
165164 impl <' a> Vaes256 <' a> {
165+ #[ allow( unused) ] // TODO: remove once cfg flags are removed
166166 pub const fn par_blocks( & self ) -> usize {
167167 <Self as ParBlocksSizeUser >:: ParBlocksSize :: USIZE
168168 }
169169 }
170- #[ cfg( target_arch = "x86_64" ) ]
170+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
171171 impl <' a> From <& Vaes512 <' a>> for Vaes256 <' a> {
172172 fn from( backend: & Vaes512 <' a>) -> Self {
173173 Self {
@@ -178,7 +178,7 @@ macro_rules! define_aes_impl {
178178 }
179179 }
180180
181- #[ cfg( target_arch = "x86_64" ) ]
181+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
182182 pub ( crate ) struct Vaes512 <' a> {
183183 pub ( crate ) features: Features ,
184184 pub ( crate ) keys: & ' a Simd128RoundKeys <$rounds>,
@@ -314,13 +314,13 @@ macro_rules! define_aes_impl {
314314 let keys = & self . keys;
315315 match features. dispatch( ) {
316316 self :: Backend :: Ni => f. call( & mut $name_backend:: Ni { keys } ) ,
317- #[ cfg( target_arch = "x86_64" ) ]
317+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
318318 self :: Backend :: Vaes256 => f. call( & mut $name_backend:: Vaes256 {
319319 features,
320320 keys,
321321 simd_256_keys: OnceCell :: new( ) ,
322322 } ) ,
323- #[ cfg( target_arch = "x86_64" ) ]
323+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
324324 self :: Backend :: Vaes512 => f. call( & mut $name_backend:: Vaes512 {
325325 features,
326326 keys,
@@ -406,13 +406,13 @@ macro_rules! define_aes_impl {
406406 let keys = & self . keys;
407407 match features. dispatch( ) {
408408 self :: Backend :: Ni => f. call( & mut $name_backend:: Ni { keys } ) ,
409- #[ cfg( target_arch = "x86_64" ) ]
409+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
410410 self :: Backend :: Vaes256 => f. call( & mut $name_backend:: Vaes256 {
411411 features,
412412 keys,
413413 simd_256_keys: OnceCell :: new( ) ,
414414 } ) ,
415- #[ cfg( target_arch = "x86_64" ) ]
415+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
416416 self :: Backend :: Vaes512 => f. call( & mut $name_backend:: Vaes512 {
417417 features,
418418 keys,
@@ -437,23 +437,23 @@ macro_rules! define_aes_impl {
437437 impl <' a> BlockSizeUser for $name_backend:: Ni <' a> {
438438 type BlockSize = U16 ;
439439 }
440- #[ cfg( target_arch = "x86_64" ) ]
440+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
441441 impl <' a> BlockSizeUser for $name_backend:: Vaes256 <' a> {
442442 type BlockSize = U16 ;
443443 }
444- #[ cfg( target_arch = "x86_64" ) ]
444+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
445445 impl <' a> BlockSizeUser for $name_backend:: Vaes512 <' a> {
446446 type BlockSize = U16 ;
447447 }
448448
449449 impl <' a> ParBlocksSizeUser for $name_backend:: Ni <' a> {
450450 type ParBlocksSize = U9 ;
451451 }
452- #[ cfg( target_arch = "x86_64" ) ]
452+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
453453 impl <' a> ParBlocksSizeUser for $name_backend:: Vaes256 <' a> {
454454 type ParBlocksSize = U30 ;
455455 }
456- #[ cfg( target_arch = "x86_64" ) ]
456+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
457457 impl <' a> ParBlocksSizeUser for $name_backend:: Vaes512 <' a> {
458458 type ParBlocksSize = U64 ;
459459 }
@@ -472,7 +472,7 @@ macro_rules! define_aes_impl {
472472 }
473473 }
474474 }
475- #[ cfg( target_arch = "x86_64" ) ]
475+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
476476 impl <' a> BlockCipherEncBackend for $name_backend:: Vaes256 <' a> {
477477 #[ inline]
478478 fn encrypt_block( & self , block: InOut <' _, ' _, Block >) {
@@ -514,7 +514,7 @@ macro_rules! define_aes_impl {
514514 }
515515 }
516516 }
517- #[ cfg( target_arch = "x86_64" ) ]
517+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
518518 impl <' a> BlockCipherEncBackend for $name_backend:: Vaes512 <' a> {
519519 #[ inline]
520520 fn encrypt_block( & self , block: InOut <' _, ' _, Block >) {
@@ -582,7 +582,7 @@ macro_rules! define_aes_impl {
582582 }
583583 }
584584 }
585- #[ cfg( target_arch = "x86_64" ) ]
585+ #[ cfg( all ( target_arch = "x86_64" , any ( aes_avx256 , aes_avx512 ) ) ) ]
586586 impl <' a> BlockCipherDecBackend for $name_backend:: Vaes256 <' a> {
587587 #[ inline]
588588 fn decrypt_block( & self , block: InOut <' _, ' _, Block >) {
@@ -624,7 +624,7 @@ macro_rules! define_aes_impl {
624624 }
625625 }
626626 }
627- #[ cfg( target_arch = "x86_64" ) ]
627+ #[ cfg( all ( target_arch = "x86_64" , aes_avx512 ) ) ]
628628 impl <' a> BlockCipherDecBackend for $name_backend:: Vaes512 <' a> {
629629 #[ inline]
630630 fn decrypt_block( & self , block: InOut <' _, ' _, Block >) {
0 commit comments