33use crate :: {
44 Curve , Error , FieldBytes , FieldBytesEncoding , Result ,
55 array:: Array ,
6- bigint:: { Limb , Odd , prelude :: * } ,
7- scalar :: FromUintUnchecked ,
8- scalar:: IsHigh ,
6+ bigint:: { AddMod , ConstOne , ConstZero , Integer , Limb , NegMod , Odd , RandomMod , SubMod , Zero } ,
7+ ctutils :: { self , CtEq , CtGt , CtLt , CtSelect } ,
8+ scalar:: { FromUintUnchecked , IsHigh } ,
99} ;
1010use base16ct:: HexDisplay ;
1111use core:: {
7272
7373 /// Create a new scalar from [`Curve::Uint`].
7474 pub fn new ( uint : C :: Uint ) -> CtOption < Self > {
75- CtOption :: new ( Self { inner : uint } , uint. ct_lt ( & Self :: MODULUS ) . into ( ) )
75+ CtOption :: new (
76+ Self { inner : uint } ,
77+ CtLt :: ct_lt ( & uint, & Self :: MODULUS ) . into ( ) ,
78+ )
7679 }
7780
7881 /// Decode [`ScalarValue`] from a serialized field element
@@ -192,6 +195,44 @@ where
192195 }
193196}
194197
198+ impl < C > CtSelect for ScalarValue < C >
199+ where
200+ C : Curve ,
201+ {
202+ fn ct_select ( & self , other : & Self , choice : ctutils:: Choice ) -> Self {
203+ Self {
204+ inner : C :: Uint :: ct_select ( & self . inner , & other. inner , choice) ,
205+ }
206+ }
207+ }
208+
209+ impl < C > CtEq for ScalarValue < C >
210+ where
211+ C : Curve ,
212+ {
213+ fn ct_eq ( & self , other : & Self ) -> ctutils:: Choice {
214+ self . inner . ct_eq ( & other. inner )
215+ }
216+ }
217+
218+ impl < C > CtGt for ScalarValue < C >
219+ where
220+ C : Curve ,
221+ {
222+ fn ct_gt ( & self , other : & Self ) -> ctutils:: Choice {
223+ self . inner . ct_gt ( & other. inner )
224+ }
225+ }
226+
227+ impl < C > CtLt for ScalarValue < C >
228+ where
229+ C : Curve ,
230+ {
231+ fn ct_lt ( & self , other : & Self ) -> ctutils:: Choice {
232+ self . inner . ct_lt ( & other. inner )
233+ }
234+ }
235+
195236impl < C : Curve > DefaultIsZeroes for ScalarValue < C > { }
196237
197238impl < C : Curve > Eq for ScalarValue < C > { }
@@ -201,7 +242,7 @@ where
201242 C : Curve ,
202243{
203244 fn eq ( & self , other : & Self ) -> bool {
204- self . ct_eq ( other) . into ( )
245+ CtEq :: ct_eq ( self , other) . to_bool ( )
205246 }
206247}
207248
0 commit comments