@@ -4,7 +4,7 @@ use criterion::{
4
4
} ;
5
5
use crypto_bigint:: {
6
6
modular:: { BoxedMontyForm , BoxedMontyParams } ,
7
- BoxedUint , NonZero , RandomMod ,
7
+ BoxedUint , NonZero , Odd , RandomMod ,
8
8
} ;
9
9
use num_bigint:: BigUint ;
10
10
use rand_core:: OsRng ;
@@ -17,10 +17,7 @@ fn to_biguint(uint: &BoxedUint) -> BigUint {
17
17
}
18
18
19
19
fn bench_montgomery_ops < M : Measurement > ( group : & mut BenchmarkGroup < ' _ , M > ) {
20
- let params = BoxedMontyParams :: new (
21
- BoxedUint :: random ( & mut OsRng , UINT_BITS ) | BoxedUint :: one_with_precision ( UINT_BITS ) ,
22
- )
23
- . unwrap ( ) ;
20
+ let params = BoxedMontyParams :: new ( Odd :: < BoxedUint > :: random ( & mut OsRng , UINT_BITS ) ) ;
24
21
25
22
group. bench_function ( "invert, U256" , |b| {
26
23
b. iter_batched (
@@ -60,8 +57,8 @@ fn bench_montgomery_ops<M: Measurement>(group: &mut BenchmarkGroup<'_, M>) {
60
57
)
61
58
} ) ;
62
59
63
- let m = BoxedUint :: random ( & mut OsRng , UINT_BITS ) | BoxedUint :: one_with_precision ( UINT_BITS ) ;
64
- let params = BoxedMontyParams :: new ( m) . unwrap ( ) ;
60
+ let m = Odd :: < BoxedUint > :: random ( & mut OsRng , UINT_BITS ) ;
61
+ let params = BoxedMontyParams :: new ( m) ;
65
62
group. bench_function ( "modpow, BoxedUint^BoxedUint" , |b| {
66
63
b. iter_batched (
67
64
|| {
@@ -96,24 +93,21 @@ fn bench_montgomery_ops<M: Measurement>(group: &mut BenchmarkGroup<'_, M>) {
96
93
fn bench_montgomery_conversion < M : Measurement > ( group : & mut BenchmarkGroup < ' _ , M > ) {
97
94
group. bench_function ( "BoxedMontyParams::new" , |b| {
98
95
b. iter_batched (
99
- || BoxedUint :: random ( & mut OsRng , UINT_BITS ) | BoxedUint :: one_with_precision ( UINT_BITS ) ,
96
+ || Odd :: < BoxedUint > :: random ( & mut OsRng , UINT_BITS ) ,
100
97
|modulus| black_box ( BoxedMontyParams :: new ( modulus) ) ,
101
98
BatchSize :: SmallInput ,
102
99
)
103
100
} ) ;
104
101
105
102
group. bench_function ( "BoxedMontyParams::new_vartime" , |b| {
106
103
b. iter_batched (
107
- || BoxedUint :: random ( & mut OsRng , UINT_BITS ) | BoxedUint :: one_with_precision ( UINT_BITS ) ,
104
+ || Odd :: < BoxedUint > :: random ( & mut OsRng , UINT_BITS ) ,
108
105
|modulus| black_box ( BoxedMontyParams :: new_vartime ( modulus) ) ,
109
106
BatchSize :: SmallInput ,
110
107
)
111
108
} ) ;
112
109
113
- let params = BoxedMontyParams :: new (
114
- BoxedUint :: random ( & mut OsRng , UINT_BITS ) | BoxedUint :: one_with_precision ( UINT_BITS ) ,
115
- )
116
- . unwrap ( ) ;
110
+ let params = BoxedMontyParams :: new ( Odd :: < BoxedUint > :: random ( & mut OsRng , UINT_BITS ) ) ;
117
111
group. bench_function ( "BoxedMontyForm::new" , |b| {
118
112
b. iter_batched (
119
113
|| BoxedUint :: random ( & mut OsRng , UINT_BITS ) ,
@@ -122,10 +116,7 @@ fn bench_montgomery_conversion<M: Measurement>(group: &mut BenchmarkGroup<'_, M>
122
116
)
123
117
} ) ;
124
118
125
- let params = BoxedMontyParams :: new (
126
- BoxedUint :: random ( & mut OsRng , UINT_BITS ) | BoxedUint :: one_with_precision ( UINT_BITS ) ,
127
- )
128
- . unwrap ( ) ;
119
+ let params = BoxedMontyParams :: new ( Odd :: < BoxedUint > :: random ( & mut OsRng , UINT_BITS ) ) ;
129
120
group. bench_function ( "BoxedMontyForm::retrieve" , |b| {
130
121
b. iter_batched (
131
122
|| BoxedMontyForm :: new ( BoxedUint :: random ( & mut OsRng , UINT_BITS ) , params. clone ( ) ) ,
0 commit comments