55pub ( super ) use core:: cmp:: { Ordering , max} ;
66
77use super :: BoxedUint ;
8- use crate :: { ConstChoice , CtEq , Limb , Uint , word} ;
9- use subtle:: { Choice , ConditionallySelectable , ConstantTimeGreater , ConstantTimeLess } ;
8+ use crate :: { ConstChoice , CtEq , CtGt , CtLt , CtSelect , Limb , Uint , word} ;
109
1110impl BoxedUint {
1211 /// Returns the Ordering between `self` and `rhs` in variable time.
@@ -53,26 +52,40 @@ impl CtEq for BoxedUint {
5352 }
5453}
5554
55+ impl CtGt for BoxedUint {
56+ #[ inline]
57+ fn ct_gt ( & self , other : & Self ) -> ConstChoice {
58+ let ( _, borrow) = other. borrowing_sub ( self , Limb :: ZERO ) ;
59+ word:: choice_from_mask ( borrow. 0 )
60+ }
61+ }
62+
63+ impl CtLt for BoxedUint {
64+ #[ inline]
65+ fn ct_lt ( & self , other : & Self ) -> ConstChoice {
66+ let ( _, borrow) = self . borrowing_sub ( other, Limb :: ZERO ) ;
67+ word:: choice_from_mask ( borrow. 0 )
68+ }
69+ }
70+
5671impl subtle:: ConstantTimeEq for BoxedUint {
5772 #[ inline]
58- fn ct_eq ( & self , other : & Self ) -> Choice {
73+ fn ct_eq ( & self , other : & Self ) -> subtle :: Choice {
5974 CtEq :: ct_eq ( self , other) . into ( )
6075 }
6176}
6277
63- impl ConstantTimeGreater for BoxedUint {
78+ impl subtle :: ConstantTimeGreater for BoxedUint {
6479 #[ inline]
65- fn ct_gt ( & self , other : & Self ) -> Choice {
66- let ( _, borrow) = other. borrowing_sub ( self , Limb :: ZERO ) ;
67- word:: choice_from_mask ( borrow. 0 ) . into ( )
80+ fn ct_gt ( & self , other : & Self ) -> subtle:: Choice {
81+ CtGt :: ct_gt ( self , other) . into ( )
6882 }
6983}
7084
71- impl ConstantTimeLess for BoxedUint {
85+ impl subtle :: ConstantTimeLess for BoxedUint {
7286 #[ inline]
73- fn ct_lt ( & self , other : & Self ) -> Choice {
74- let ( _, borrow) = self . borrowing_sub ( other, Limb :: ZERO ) ;
75- word:: choice_from_mask ( borrow. 0 ) . into ( )
87+ fn ct_lt ( & self , other : & Self ) -> subtle:: Choice {
88+ CtLt :: ct_lt ( self , other) . into ( )
7689 }
7790}
7891
@@ -92,8 +105,8 @@ impl<const LIMBS: usize> PartialEq<Uint<LIMBS>> for BoxedUint {
92105impl Ord for BoxedUint {
93106 fn cmp ( & self , other : & Self ) -> Ordering {
94107 let mut ret = Ordering :: Equal ;
95- ret. conditional_assign ( & Ordering :: Greater , self . ct_gt ( other) ) ;
96- ret. conditional_assign ( & Ordering :: Less , self . ct_lt ( other) ) ;
108+ ret. ct_assign ( & Ordering :: Greater , self . ct_gt ( other) ) ;
109+ ret. ct_assign ( & Ordering :: Less , self . ct_lt ( other) ) ;
97110
98111 #[ cfg( debug_assertions) ]
99112 if ret == Ordering :: Equal {
0 commit comments