Skip to content

Commit 066e50d

Browse files
committed
Add benchmarks
1 parent 9000fc9 commit 066e50d

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-
Decaf448, DecafPoint, DecafScalar, EdwardsPoint, EdwardsScalar, MontgomeryScalar,
4-
MontgomeryXpoint, ProjectiveMontgomeryXpoint,
3+
Curve448, Decaf448, DecafPoint, DecafScalar, EdwardsPoint, EdwardsScalar, MontgomeryScalar,
4+
MontgomeryXpoint, ProjectiveMontgomeryPoint, ProjectiveMontgomeryXpoint,
55
};
66
use elliptic_curve::group::GroupEncoding;
77
use elliptic_curve::{Field, Group};
@@ -130,6 +130,53 @@ pub fn decaf448(c: &mut Criterion) {
130130
group.finish();
131131
}
132132

133+
pub fn curve448(c: &mut Criterion) {
134+
let mut group = c.benchmark_group("Curve448");
135+
136+
group.bench_function("scalar multiplication", |b| {
137+
b.iter_batched(
138+
|| {
139+
let point = ProjectiveMontgomeryPoint::try_from_rng(&mut OsRng).unwrap();
140+
let scalar = MontgomeryScalar::try_from_rng(&mut OsRng).unwrap();
141+
(point, scalar)
142+
},
143+
|(point, scalar)| point * scalar,
144+
BatchSize::SmallInput,
145+
)
146+
});
147+
148+
group.bench_function("point addition", |b| {
149+
b.iter_batched(
150+
|| {
151+
let p1 = ProjectiveMontgomeryPoint::try_from_rng(&mut OsRng).unwrap();
152+
let p2 = ProjectiveMontgomeryPoint::try_from_rng(&mut OsRng).unwrap();
153+
(p1, p2)
154+
},
155+
|(p1, p2)| p1 + p2,
156+
BatchSize::SmallInput,
157+
)
158+
});
159+
160+
group.bench_function("encode_to_curve", |b| {
161+
b.iter_batched(
162+
|| {
163+
let mut msg = [0; 64];
164+
OsRng.try_fill_bytes(&mut msg).unwrap();
165+
msg
166+
},
167+
|msg| {
168+
Curve448::encode_from_bytes::<ExpandMsgXof<Shake256>>(
169+
&[&msg],
170+
&[b"curve448_XOF:SHAKE256_ELL2_NU_"],
171+
)
172+
},
173+
BatchSize::SmallInput,
174+
)
175+
});
176+
177+
group.finish();
178+
}
179+
133180
pub fn x448(c: &mut Criterion) {
134181
let mut group = c.benchmark_group("X448");
135182

0 commit comments

Comments
 (0)