File tree Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ pub trait Integer:
138
138
+ for < ' a > Sub < & ' a Self , Output = Self >
139
139
+ SubMod < Output = Self >
140
140
+ Sync
141
+ + SquareRoot
141
142
+ WrappingAdd
142
143
+ WrappingSub
143
144
+ WrappingMul
@@ -463,6 +464,15 @@ pub trait SquareAssign {
463
464
fn square_assign ( & mut self ) ;
464
465
}
465
466
467
+ /// Support for calucaling square roots.
468
+ pub trait SquareRoot {
469
+ /// Computes `floor(sqrt(self))`.
470
+ fn sqrt ( & self ) -> Self ;
471
+
472
+ /// Computes `floor(sqrt(self))`, variable time in `self`.
473
+ fn sqrt_vartime ( & self ) -> Self ;
474
+ }
475
+
466
476
/// Support for optimized division by a single limb.
467
477
pub trait DivRemLimb : Sized {
468
478
/// Computes `self / rhs` using a pre-made reciprocal,
Original file line number Diff line number Diff line change 2
2
3
3
use subtle:: { ConstantTimeEq , ConstantTimeGreater , CtOption } ;
4
4
5
- use crate :: { BoxedUint , ConstantTimeSelect , NonZero } ;
5
+ use crate :: { BoxedUint , ConstantTimeSelect , NonZero , SquareRoot } ;
6
6
7
7
impl BoxedUint {
8
8
/// Computes √(`self`) in constant time.
@@ -121,6 +121,16 @@ impl BoxedUint {
121
121
}
122
122
}
123
123
124
+ impl SquareRoot for BoxedUint {
125
+ fn sqrt ( & self ) -> Self {
126
+ self . sqrt ( )
127
+ }
128
+
129
+ fn sqrt_vartime ( & self ) -> Self {
130
+ self . sqrt_vartime ( )
131
+ }
132
+ }
133
+
124
134
#[ cfg( test) ]
125
135
mod tests {
126
136
use crate :: { BoxedUint , Limb } ;
Original file line number Diff line number Diff line change 1
1
//! [`Uint`] square root operations.
2
2
3
- use crate :: Uint ;
3
+ use crate :: { SquareRoot , Uint } ;
4
4
use subtle:: { ConstantTimeEq , CtOption } ;
5
5
6
6
impl < const LIMBS : usize > Uint < LIMBS > {
@@ -113,6 +113,16 @@ impl<const LIMBS: usize> Uint<LIMBS> {
113
113
}
114
114
}
115
115
116
+ impl < const LIMBS : usize > SquareRoot for Uint < LIMBS > {
117
+ fn sqrt ( & self ) -> Self {
118
+ self . sqrt ( )
119
+ }
120
+
121
+ fn sqrt_vartime ( & self ) -> Self {
122
+ self . sqrt_vartime ( )
123
+ }
124
+ }
125
+
116
126
#[ cfg( test) ]
117
127
mod tests {
118
128
use crate :: { Limb , U192 , U256 } ;
You can’t perform that action at this time.
0 commit comments