@@ -4,7 +4,7 @@ use criterion::{
44} ;
55use crypto_bigint:: {
66 modular:: { BoxedMontyForm , BoxedMontyParams } ,
7- BoxedUint , NonZero , RandomMod ,
7+ BoxedUint , NonZero , Odd , RandomMod ,
88} ;
99use num_bigint:: BigUint ;
1010use rand_core:: OsRng ;
@@ -17,10 +17,7 @@ fn to_biguint(uint: &BoxedUint) -> BigUint {
1717}
1818
1919fn 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 ) ) ;
2421
2522 group. bench_function ( "invert, U256" , |b| {
2623 b. iter_batched (
@@ -60,8 +57,8 @@ fn bench_montgomery_ops<M: Measurement>(group: &mut BenchmarkGroup<'_, M>) {
6057 )
6158 } ) ;
6259
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) ;
6562 group. bench_function ( "modpow, BoxedUint^BoxedUint" , |b| {
6663 b. iter_batched (
6764 || {
@@ -96,24 +93,21 @@ fn bench_montgomery_ops<M: Measurement>(group: &mut BenchmarkGroup<'_, M>) {
9693fn bench_montgomery_conversion < M : Measurement > ( group : & mut BenchmarkGroup < ' _ , M > ) {
9794 group. bench_function ( "BoxedMontyParams::new" , |b| {
9895 b. iter_batched (
99- || BoxedUint :: random ( & mut OsRng , UINT_BITS ) | BoxedUint :: one_with_precision ( UINT_BITS ) ,
96+ || Odd :: < BoxedUint > :: random ( & mut OsRng , UINT_BITS ) ,
10097 |modulus| black_box ( BoxedMontyParams :: new ( modulus) ) ,
10198 BatchSize :: SmallInput ,
10299 )
103100 } ) ;
104101
105102 group. bench_function ( "BoxedMontyParams::new_vartime" , |b| {
106103 b. iter_batched (
107- || BoxedUint :: random ( & mut OsRng , UINT_BITS ) | BoxedUint :: one_with_precision ( UINT_BITS ) ,
104+ || Odd :: < BoxedUint > :: random ( & mut OsRng , UINT_BITS ) ,
108105 |modulus| black_box ( BoxedMontyParams :: new_vartime ( modulus) ) ,
109106 BatchSize :: SmallInput ,
110107 )
111108 } ) ;
112109
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 ) ) ;
117111 group. bench_function ( "BoxedMontyForm::new" , |b| {
118112 b. iter_batched (
119113 || BoxedUint :: random ( & mut OsRng , UINT_BITS ) ,
@@ -122,10 +116,7 @@ fn bench_montgomery_conversion<M: Measurement>(group: &mut BenchmarkGroup<'_, M>
122116 )
123117 } ) ;
124118
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 ) ) ;
129120 group. bench_function ( "BoxedMontyForm::retrieve" , |b| {
130121 b. iter_batched (
131122 || BoxedMontyForm :: new ( BoxedUint :: random ( & mut OsRng , UINT_BITS ) , params. clone ( ) ) ,
0 commit comments