Skip to content

Commit 11c14bc

Browse files
committed
Add benchmarks
1 parent aa011c3 commit 11c14bc

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

ed448-goldilocks/benches/bench.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
22
use ed448_goldilocks::{
3-
CompressedDecaf, CompressedEdwardsY, Decaf448, DecafPoint, DecafScalar, EdwardsPoint,
4-
EdwardsScalar, MontgomeryScalar, MontgomeryXpoint,
3+
CompressedDecaf, CompressedEdwardsY, Curve448, Decaf448, DecafPoint, DecafScalar, EdwardsPoint,
4+
EdwardsScalar, MontgomeryScalar, MontgomeryXpoint, ProjectiveMontgomeryPoint,
55
};
66
use elliptic_curve::group::GroupEncoding;
77
use elliptic_curve::{Field, Group};
@@ -162,6 +162,53 @@ pub fn decaf448(c: &mut Criterion) {
162162
pub fn curve448(c: &mut Criterion) {
163163
let mut group = c.benchmark_group("Curve448");
164164

165+
group.bench_function("scalar multiplication", |b| {
166+
b.iter_batched(
167+
|| {
168+
let point = ProjectiveMontgomeryPoint::try_from_rng(&mut OsRng).unwrap();
169+
let scalar = MontgomeryScalar::try_from_rng(&mut OsRng).unwrap();
170+
(point, scalar)
171+
},
172+
|(point, scalar)| point * scalar,
173+
BatchSize::SmallInput,
174+
)
175+
});
176+
177+
group.bench_function("point addition", |b| {
178+
b.iter_batched(
179+
|| {
180+
let p1 = ProjectiveMontgomeryPoint::try_from_rng(&mut OsRng).unwrap();
181+
let p2 = ProjectiveMontgomeryPoint::try_from_rng(&mut OsRng).unwrap();
182+
(p1, p2)
183+
},
184+
|(p1, p2)| p1 + p2,
185+
BatchSize::SmallInput,
186+
)
187+
});
188+
189+
group.bench_function("encode_to_curve", |b| {
190+
b.iter_batched(
191+
|| {
192+
let mut msg = [0; 64];
193+
OsRng.try_fill_bytes(&mut msg).unwrap();
194+
msg
195+
},
196+
|msg| {
197+
Curve448::encode_from_bytes::<ExpandMsgXof<Shake256>>(
198+
&[&msg],
199+
&[b"curve448_XOF:SHAKE256_ELL2_NU_"],
200+
)
201+
},
202+
BatchSize::SmallInput,
203+
)
204+
});
205+
206+
group.finish();
207+
}
208+
209+
pub fn x448(c: &mut Criterion) {
210+
let mut group = c.benchmark_group("X448");
211+
165212
group.bench_function("scalar multiplication", |b| {
166213
b.iter_batched(
167214
|| {

0 commit comments

Comments
 (0)