1
1
#![ allow( non_snake_case) ]
2
2
3
3
use rand:: rngs:: OsRng ;
4
- use rand:: thread_rng;
4
+ use rand:: { thread_rng, Rng } ;
5
5
6
6
use criterion:: measurement:: Measurement ;
7
7
use criterion:: BatchSize ;
@@ -47,6 +47,25 @@ mod edwards_benches {
47
47
} ) ;
48
48
}
49
49
50
+ fn scalar_from_canonical_bytes ( c : & mut Criterion ) {
51
+ let bytes = [ 0xFF ; 32 ] ;
52
+ c. bench_function ( "Max scalar from_canonical_bytes" , move |b| {
53
+ b. iter ( || Scalar :: from_canonical_bytes ( bytes) )
54
+ } ) ;
55
+ let bytes = [ 0u8 ; 32 ] ;
56
+ c. bench_function ( "Zero scalar from_canonical_bytes" , move |b| {
57
+ b. iter ( || Scalar :: from_canonical_bytes ( bytes) )
58
+ } ) ;
59
+ c. bench_function ( "Rand scalar from_canonical_bytes" , |bench| {
60
+ let mut rng = thread_rng ( ) ;
61
+ bench. iter_batched (
62
+ || rng. gen ( ) ,
63
+ |bytes| Scalar :: from_canonical_bytes ( bytes) ,
64
+ BatchSize :: SmallInput ,
65
+ ) ;
66
+ } ) ;
67
+ }
68
+
50
69
fn vartime_double_base_scalar_mul ( c : & mut Criterion ) {
51
70
c. bench_function ( "Variable-time aA+bB, A variable, B fixed" , |bench| {
52
71
let mut rng = thread_rng ( ) ;
@@ -68,6 +87,7 @@ mod edwards_benches {
68
87
consttime_fixed_base_scalar_mul,
69
88
consttime_variable_base_scalar_mul,
70
89
vartime_double_base_scalar_mul,
90
+ scalar_from_canonical_bytes,
71
91
}
72
92
}
73
93
0 commit comments