@@ -133,6 +133,9 @@ use typenum::{Diff, Sum};
133133#[ cfg( feature = "bytemuck" ) ]
134134use bytemuck:: { Pod , Zeroable } ;
135135
136+ #[ cfg( feature = "subtle" ) ]
137+ use subtle:: { Choice , ConditionallySelectable , ConstantTimeEq } ;
138+
136139#[ cfg( feature = "zeroize" ) ]
137140use zeroize:: { Zeroize , ZeroizeOnDrop } ;
138141
@@ -854,6 +857,41 @@ where
854857{
855858}
856859
860+ #[ cfg( feature = "subtle" ) ]
861+ impl < T , U > ConditionallySelectable for Array < T , U >
862+ where
863+ Self : Copy ,
864+ T : ConditionallySelectable ,
865+ U : ArraySize ,
866+ {
867+ #[ inline]
868+ fn conditional_select ( a : & Self , b : & Self , choice : Choice ) -> Self {
869+ let mut output = * a;
870+ output. conditional_assign ( b, choice) ;
871+ output
872+ }
873+
874+ fn conditional_assign ( & mut self , other : & Self , choice : Choice ) {
875+ for ( a_i, b_i) in self . iter_mut ( ) . zip ( other) {
876+ a_i. conditional_assign ( b_i, choice)
877+ }
878+ }
879+ }
880+
881+ #[ cfg( feature = "subtle" ) ]
882+ impl < T , U > ConstantTimeEq for Array < T , U >
883+ where
884+ T : ConstantTimeEq ,
885+ U : ArraySize ,
886+ {
887+ #[ inline]
888+ fn ct_eq ( & self , other : & Self ) -> Choice {
889+ self . iter ( )
890+ . zip ( other. iter ( ) )
891+ . fold ( Choice :: from ( 1 ) , |acc, ( a, b) | acc & a. ct_eq ( b) )
892+ }
893+ }
894+
857895#[ cfg( feature = "zeroize" ) ]
858896impl < T , U > Zeroize for Array < T , U >
859897where
0 commit comments