@@ -7,7 +7,7 @@ use super::{
7
7
Retrieve ,
8
8
} ;
9
9
10
- use subtle:: CtOption ;
10
+ use subtle:: { Choice , ConditionallySelectable , ConstantTimeEq , CtOption } ;
11
11
12
12
/// Additions between residues with a modulus set at runtime
13
13
mod runtime_add;
@@ -103,6 +103,28 @@ impl<const LIMBS: usize> DynResidueParams<LIMBS> {
103
103
}
104
104
}
105
105
106
+ impl < const LIMBS : usize > ConditionallySelectable for DynResidueParams < LIMBS > {
107
+ fn conditional_select ( a : & Self , b : & Self , choice : Choice ) -> Self {
108
+ Self {
109
+ modulus : Uint :: conditional_select ( & a. modulus , & b. modulus , choice) ,
110
+ r : Uint :: conditional_select ( & a. r , & b. r , choice) ,
111
+ r2 : Uint :: conditional_select ( & a. r2 , & b. r2 , choice) ,
112
+ r3 : Uint :: conditional_select ( & a. r3 , & b. r3 , choice) ,
113
+ mod_neg_inv : Limb :: conditional_select ( & a. mod_neg_inv , & b. mod_neg_inv , choice) ,
114
+ }
115
+ }
116
+ }
117
+
118
+ impl < const LIMBS : usize > ConstantTimeEq for DynResidueParams < LIMBS > {
119
+ fn ct_eq ( & self , other : & Self ) -> Choice {
120
+ self . modulus . ct_eq ( & other. modulus )
121
+ & self . r . ct_eq ( & other. r )
122
+ & self . r2 . ct_eq ( & other. r2 )
123
+ & self . r3 . ct_eq ( & other. r3 )
124
+ & self . mod_neg_inv . ct_eq ( & other. mod_neg_inv )
125
+ }
126
+ }
127
+
106
128
/// A residue represented using `LIMBS` limbs. The odd modulus of this residue is set at runtime.
107
129
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
108
130
pub struct DynResidue < const LIMBS : usize > {
@@ -211,6 +233,30 @@ impl<const LIMBS: usize, P: ResidueParams<LIMBS>> From<&Residue<P, LIMBS>> for D
211
233
}
212
234
}
213
235
236
+ impl < const LIMBS : usize > ConditionallySelectable for DynResidue < LIMBS > {
237
+ fn conditional_select ( a : & Self , b : & Self , choice : Choice ) -> Self {
238
+ Self {
239
+ montgomery_form : Uint :: conditional_select (
240
+ & a. montgomery_form ,
241
+ & b. montgomery_form ,
242
+ choice,
243
+ ) ,
244
+ residue_params : DynResidueParams :: conditional_select (
245
+ & a. residue_params ,
246
+ & b. residue_params ,
247
+ choice,
248
+ ) ,
249
+ }
250
+ }
251
+ }
252
+
253
+ impl < const LIMBS : usize > ConstantTimeEq for DynResidue < LIMBS > {
254
+ fn ct_eq ( & self , other : & Self ) -> Choice {
255
+ self . montgomery_form . ct_eq ( & other. montgomery_form )
256
+ & self . residue_params . ct_eq ( & other. residue_params )
257
+ }
258
+ }
259
+
214
260
/// NOTE: this does _not_ zeroize the parameters, in order to maintain some form of type consistency
215
261
#[ cfg( feature = "zeroize" ) ]
216
262
impl < const LIMBS : usize > zeroize:: Zeroize for DynResidue < LIMBS > {
0 commit comments