@@ -19,12 +19,12 @@ use hybrid_array::{Array, ArraySize, typenum::U1};
1919#[ cfg( feature = "alloc" ) ]
2020use alloc:: boxed:: Box ;
2121
22+ #[ cfg( feature = "ctutils" ) ]
23+ use ctutils:: { Choice , CtSelect } ;
24+
2225#[ cfg( feature = "serde" ) ]
2326use serdect:: serde:: { Deserialize , Serialize , de, ser} ;
2427
25- #[ cfg( feature = "subtle" ) ]
26- use subtle:: { Choice , ConditionallySelectable } ;
27-
2828#[ cfg( feature = "zeroize" ) ]
2929use zeroize:: Zeroize ;
3030
@@ -254,23 +254,6 @@ where
254254 }
255255}
256256
257- #[ cfg( feature = "subtle" ) ]
258- impl < Size > ConditionallySelectable for EncodedPoint < Size >
259- where
260- Size : ModulusSize ,
261- <Size :: UncompressedPointSize as ArraySize >:: ArrayType < u8 > : Copy ,
262- {
263- fn conditional_select ( a : & Self , b : & Self , choice : Choice ) -> Self {
264- let mut bytes = Array :: default ( ) ;
265-
266- for ( i, byte) in bytes. iter_mut ( ) . enumerate ( ) {
267- * byte = u8:: conditional_select ( & a. bytes [ i] , & b. bytes [ i] , choice) ;
268- }
269-
270- Self { bytes }
271- }
272- }
273-
274257impl < Size > Copy for EncodedPoint < Size >
275258where
276259 Size : ModulusSize ,
@@ -392,6 +375,23 @@ where
392375 }
393376}
394377
378+ // TODO(tarcieri): add `ctutils` support to `hybrid-array`
379+ #[ cfg( feature = "ctutils" ) ]
380+ impl < Size > CtSelect for EncodedPoint < Size >
381+ where
382+ Size : ModulusSize ,
383+ {
384+ fn ct_select ( & self , other : & Self , choice : Choice ) -> Self {
385+ let mut bytes = Array :: default ( ) ;
386+
387+ for ( i, byte) in bytes. iter_mut ( ) . enumerate ( ) {
388+ * byte = self . bytes [ i] . ct_select ( & other. bytes [ i] , choice) ;
389+ }
390+
391+ Self { bytes }
392+ }
393+ }
394+
395395#[ cfg( feature = "serde" ) ]
396396impl < Size > Serialize for EncodedPoint < Size >
397397where
@@ -565,8 +565,8 @@ mod tests {
565565 #[ cfg( feature = "alloc" ) ]
566566 use alloc:: string:: ToString ;
567567
568- #[ cfg( feature = "subtle " ) ]
569- use subtle :: ConditionallySelectable ;
568+ #[ cfg( feature = "ctutils " ) ]
569+ use ctutils :: CtSelect ;
570570
571571 type EncodedPoint = super :: EncodedPoint < U32 > ;
572572
@@ -731,16 +731,16 @@ mod tests {
731731 assert_eq ! ( compressed_point. as_bytes( ) , & COMPRESSED_BYTES [ ..] ) ;
732732 }
733733
734- #[ cfg( feature = "subtle " ) ]
734+ #[ cfg( feature = "ctutils " ) ]
735735 #[ test]
736- fn conditional_select ( ) {
736+ fn ct_select ( ) {
737737 let a = EncodedPoint :: from_bytes ( & COMPRESSED_BYTES [ ..] ) . unwrap ( ) ;
738738 let b = EncodedPoint :: from_bytes ( & UNCOMPRESSED_BYTES [ ..] ) . unwrap ( ) ;
739739
740- let a_selected = EncodedPoint :: conditional_select ( & a, & b, 0 . into ( ) ) ;
740+ let a_selected = EncodedPoint :: ct_select ( & a, & b, 0 . into ( ) ) ;
741741 assert_eq ! ( a, a_selected) ;
742742
743- let b_selected = EncodedPoint :: conditional_select ( & a, & b, 1 . into ( ) ) ;
743+ let b_selected = EncodedPoint :: ct_select ( & a, & b, 1 . into ( ) ) ;
744744 assert_eq ! ( b, b_selected) ;
745745 }
746746
0 commit comments