@@ -22,8 +22,8 @@ fn make_rng() -> ChaCha8Rng {
22
22
ChaCha8Rng :: from_seed ( * b"01234567890123456789012345678901" )
23
23
}
24
24
25
- fn make_sieve < const L : usize > ( rng : & mut impl CryptoRngCore ) -> Sieve < L > {
26
- let start = random_odd_uint :: < L > ( rng, Uint :: < L > :: BITS ) ;
25
+ fn make_sieve < const L : usize > ( rng : & mut impl CryptoRngCore ) -> Sieve < Uint < L > > {
26
+ let start = random_odd_uint :: < Uint < L > > ( rng, Uint :: < L > :: BITS ) ;
27
27
Sieve :: new ( & start, Uint :: < L > :: BITS , false )
28
28
}
29
29
@@ -36,13 +36,13 @@ fn bench_sieve(c: &mut Criterion) {
36
36
let mut group = c. benchmark_group ( "Sieve" ) ;
37
37
38
38
group. bench_function ( "(U128) random start" , |b| {
39
- b. iter ( || random_odd_uint :: < { nlimbs ! ( 128 ) } > ( & mut OsRng , 128 ) )
39
+ b. iter ( || random_odd_uint :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut OsRng , 128 ) )
40
40
} ) ;
41
41
42
42
group. bench_function ( "(U128) creation" , |b| {
43
43
b. iter_batched (
44
- || random_odd_uint :: < { nlimbs ! ( 128 ) } > ( & mut OsRng , 128 ) ,
45
- |start| Sieve :: new ( & start, 128 , false ) ,
44
+ || random_odd_uint :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut OsRng , 128 ) ,
45
+ |start| Sieve :: new ( start. as_ref ( ) , 128 , false ) ,
46
46
BatchSize :: SmallInput ,
47
47
)
48
48
} ) ;
@@ -57,13 +57,13 @@ fn bench_sieve(c: &mut Criterion) {
57
57
} ) ;
58
58
59
59
group. bench_function ( "(U1024) random start" , |b| {
60
- b. iter ( || random_odd_uint :: < { nlimbs ! ( 1024 ) } > ( & mut OsRng , 1024 ) )
60
+ b. iter ( || random_odd_uint :: < Uint < { nlimbs ! ( 1024 ) } > > ( & mut OsRng , 1024 ) )
61
61
} ) ;
62
62
63
63
group. bench_function ( "(U1024) creation" , |b| {
64
64
b. iter_batched (
65
- || random_odd_uint :: < { nlimbs ! ( 1024 ) } > ( & mut OsRng , 1024 ) ,
66
- |start| Sieve :: new ( & start, 1024 , false ) ,
65
+ || random_odd_uint :: < Uint < { nlimbs ! ( 1024 ) } > > ( & mut OsRng , 1024 ) ,
66
+ |start| Sieve :: new ( start. as_ref ( ) , 1024 , false ) ,
67
67
BatchSize :: SmallInput ,
68
68
)
69
69
} ) ;
@@ -84,7 +84,7 @@ fn bench_miller_rabin(c: &mut Criterion) {
84
84
85
85
group. bench_function ( "(U128) creation" , |b| {
86
86
b. iter_batched (
87
- || random_odd_uint :: < { nlimbs ! ( 128 ) } > ( & mut OsRng , 128 ) ,
87
+ || random_odd_uint :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut OsRng , 128 ) ,
88
88
MillerRabin :: new,
89
89
BatchSize :: SmallInput ,
90
90
)
@@ -100,7 +100,7 @@ fn bench_miller_rabin(c: &mut Criterion) {
100
100
101
101
group. bench_function ( "(U1024) creation" , |b| {
102
102
b. iter_batched (
103
- || random_odd_uint :: < { nlimbs ! ( 1024 ) } > ( & mut OsRng , 1024 ) ,
103
+ || random_odd_uint :: < Uint < { nlimbs ! ( 1024 ) } > > ( & mut OsRng , 1024 ) ,
104
104
MillerRabin :: new,
105
105
BatchSize :: SmallInput ,
106
106
)
@@ -193,39 +193,39 @@ fn bench_presets(c: &mut Criterion) {
193
193
194
194
group. bench_function ( "(U128) Prime test" , |b| {
195
195
b. iter_batched (
196
- || random_odd_uint :: < { nlimbs ! ( 128 ) } > ( & mut OsRng , 128 ) ,
197
- |num| is_prime_with_rng ( & mut OsRng , & num) ,
196
+ || random_odd_uint :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut OsRng , 128 ) ,
197
+ |num| is_prime_with_rng ( & mut OsRng , num. as_ref ( ) ) ,
198
198
BatchSize :: SmallInput ,
199
199
)
200
200
} ) ;
201
201
202
202
group. bench_function ( "(U128) Safe prime test" , |b| {
203
203
b. iter_batched (
204
- || random_odd_uint :: < { nlimbs ! ( 128 ) } > ( & mut OsRng , 128 ) ,
205
- |num| is_safe_prime_with_rng ( & mut OsRng , & num) ,
204
+ || random_odd_uint :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut OsRng , 128 ) ,
205
+ |num| is_safe_prime_with_rng ( & mut OsRng , num. as_ref ( ) ) ,
206
206
BatchSize :: SmallInput ,
207
207
)
208
208
} ) ;
209
209
210
210
let mut rng = make_rng ( ) ;
211
211
group. bench_function ( "(U128) Random prime" , |b| {
212
- b. iter ( || generate_prime_with_rng :: < { nlimbs ! ( 128 ) } > ( & mut rng, None ) )
212
+ b. iter ( || generate_prime_with_rng :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut rng, 128 ) )
213
213
} ) ;
214
214
215
215
let mut rng = make_rng ( ) ;
216
216
group. bench_function ( "(U1024) Random prime" , |b| {
217
- b. iter ( || generate_prime_with_rng :: < { nlimbs ! ( 1024 ) } > ( & mut rng, None ) )
217
+ b. iter ( || generate_prime_with_rng :: < Uint < { nlimbs ! ( 1024 ) } > > ( & mut rng, 1024 ) )
218
218
} ) ;
219
219
220
220
let mut rng = make_rng ( ) ;
221
221
group. bench_function ( "(U128) Random safe prime" , |b| {
222
- b. iter ( || generate_safe_prime_with_rng :: < { nlimbs ! ( 128 ) } > ( & mut rng, None ) )
222
+ b. iter ( || generate_safe_prime_with_rng :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut rng, 128 ) )
223
223
} ) ;
224
224
225
225
group. sample_size ( 20 ) ;
226
226
let mut rng = make_rng ( ) ;
227
227
group. bench_function ( "(U1024) Random safe prime" , |b| {
228
- b. iter ( || generate_safe_prime_with_rng :: < { nlimbs ! ( 1024 ) } > ( & mut rng, None ) )
228
+ b. iter ( || generate_safe_prime_with_rng :: < Uint < { nlimbs ! ( 1024 ) } > > ( & mut rng, 1024 ) )
229
229
} ) ;
230
230
231
231
group. finish ( ) ;
@@ -235,19 +235,19 @@ fn bench_presets(c: &mut Criterion) {
235
235
236
236
let mut rng = make_rng ( ) ;
237
237
group. bench_function ( "(U128) Random safe prime" , |b| {
238
- b. iter ( || generate_safe_prime_with_rng :: < { nlimbs ! ( 128 ) } > ( & mut rng, None ) )
238
+ b. iter ( || generate_safe_prime_with_rng :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut rng, 128 ) )
239
239
} ) ;
240
240
241
241
// The performance should scale with the prime size, not with the Uint size.
242
242
// So we should strive for this test's result to be as close as possible
243
243
// to that of the previous one and as far away as possible from the next one.
244
244
group. bench_function ( "(U256) Random 128 bit safe prime" , |b| {
245
- b. iter ( || generate_safe_prime_with_rng :: < { nlimbs ! ( 256 ) } > ( & mut rng, Some ( 128 ) ) )
245
+ b. iter ( || generate_safe_prime_with_rng :: < Uint < { nlimbs ! ( 256 ) } > > ( & mut rng, 128 ) )
246
246
} ) ;
247
247
248
248
// The upper bound for the previous test.
249
249
group. bench_function ( "(U256) Random 256 bit safe prime" , |b| {
250
- b. iter ( || generate_safe_prime_with_rng :: < { nlimbs ! ( 256 ) } > ( & mut rng, None ) )
250
+ b. iter ( || generate_safe_prime_with_rng :: < Uint < { nlimbs ! ( 256 ) } > > ( & mut rng, 256 ) )
251
251
} ) ;
252
252
253
253
group. finish ( ) ;
@@ -258,7 +258,7 @@ fn bench_gmp(c: &mut Criterion) {
258
258
let mut group = c. benchmark_group ( "GMP" ) ;
259
259
260
260
fn random < const L : usize > ( rng : & mut impl CryptoRngCore ) -> Integer {
261
- let num = random_odd_uint :: < L > ( rng, Uint :: < L > :: BITS ) ;
261
+ let num = random_odd_uint :: < Uint < L > > ( rng, Uint :: < L > :: BITS ) . get ( ) ;
262
262
Integer :: from_digits ( num. as_words ( ) , Order :: Lsf )
263
263
}
264
264
0 commit comments