Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ed448-goldilocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ signing = ["dep:ed448", "dep:signature"]
serde = ["dep:serdect", "ed448?/serde_bytes"]

[dev-dependencies]
criterion = { version = "0.7", default-features = false, features = ["cargo_bench_support"] }
hex-literal = "1"
hex = "0.4"
rand_core = { version = "0.9", features = ["os_rng"] }
rand_chacha = "0.9"
serde_bare = "0.5"
serde_json = "1.0"

[[bench]]
harness = false
name = "bench"
181 changes: 181 additions & 0 deletions ed448-goldilocks/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
use ed448_goldilocks::{
CompressedDecaf, CompressedEdwardsY, Decaf448, DecafPoint, DecafScalar, EdwardsPoint,
EdwardsScalar, MontgomeryPoint,
};
use elliptic_curve::{Field, Group};
use hash2curve::{ExpandMsgXof, GroupDigest};
use rand_core::{OsRng, TryRngCore};
use sha3::Shake256;

pub fn ed448(c: &mut Criterion) {
let mut group = c.benchmark_group("Ed448");

group.bench_function("scalar multiplication", |b| {
b.iter_batched(
|| {
let point = EdwardsPoint::try_from_rng(&mut OsRng).unwrap();
let scalar = EdwardsScalar::try_from_rng(&mut OsRng).unwrap();
(point, scalar)
},
|(point, scalar)| point * scalar,
BatchSize::SmallInput,
)
});

group.bench_function("point addition", |b| {
b.iter_batched(
|| {
let p1 = EdwardsPoint::try_from_rng(&mut OsRng).unwrap();
let p2 = EdwardsPoint::try_from_rng(&mut OsRng).unwrap();
(p1, p2)
},
|(p1, p2)| p1 + p2,
BatchSize::SmallInput,
)
});

group.bench_function("hash_to_curve", |b| {
b.iter_batched(
|| {
let mut msg = [0; 64];
OsRng.try_fill_bytes(&mut msg).unwrap();
msg
},
|msg| EdwardsPoint::hash_with_defaults(&msg),
BatchSize::SmallInput,
)
});

group.bench_function("encode_to_curve", |b| {
b.iter_batched(
|| {
let mut msg = [0; 64];
OsRng.try_fill_bytes(&mut msg).unwrap();
msg
},
|msg| EdwardsPoint::encode_with_defaults(&msg),
BatchSize::SmallInput,
)
});

group.bench_function("compress", |b| {
b.iter_batched(
|| EdwardsPoint::try_from_rng(&mut OsRng).unwrap(),
|point| point.compress().0,
BatchSize::SmallInput,
)
});

group.bench_function("decompress", |b| {
b.iter_batched(
|| EdwardsPoint::try_from_rng(&mut OsRng).unwrap().compress().0,
|bytes| CompressedEdwardsY(bytes).decompress().unwrap(),
BatchSize::SmallInput,
)
});

group.finish();
}

pub fn decaf448(c: &mut Criterion) {
let mut group = c.benchmark_group("Decaf448");

group.bench_function("scalar multiplication", |b| {
b.iter_batched(
|| {
let point = DecafPoint::try_from_rng(&mut OsRng).unwrap();
let scalar = DecafScalar::try_from_rng(&mut OsRng).unwrap();
(point, scalar)
},
|(point, scalar)| point * scalar,
BatchSize::SmallInput,
)
});

group.bench_function("point addition", |b| {
b.iter_batched(
|| {
let p1 = DecafPoint::try_from_rng(&mut OsRng).unwrap();
let p2 = DecafPoint::try_from_rng(&mut OsRng).unwrap();
(p1, p2)
},
|(p1, p2)| p1 + p2,
BatchSize::SmallInput,
)
});

group.bench_function("hash_to_curve", |b| {
b.iter_batched(
|| {
let mut msg = [0; 64];
OsRng.try_fill_bytes(&mut msg).unwrap();
msg
},
|msg| {
Decaf448::hash_from_bytes::<ExpandMsgXof<Shake256>>(
&[&msg],
&[b"decaf448_XOF:SHAKE256_D448MAP_RO_"],
)
},
BatchSize::SmallInput,
)
});

group.bench_function("encode_to_curve", |b| {
b.iter_batched(
|| {
let mut msg = [0; 64];
OsRng.try_fill_bytes(&mut msg).unwrap();
msg
},
|msg| {
Decaf448::encode_from_bytes::<ExpandMsgXof<Shake256>>(
&[&msg],
&[b"decaf448_XOF:SHAKE256_D448MAP_NU_"],
)
},
BatchSize::SmallInput,
)
});

group.bench_function("compress", |b| {
b.iter_batched(
|| DecafPoint::try_from_rng(&mut OsRng).unwrap(),
|point| point.compress().0,
BatchSize::SmallInput,
)
});

group.bench_function("decompress", |b| {
b.iter_batched(
|| DecafPoint::try_from_rng(&mut OsRng).unwrap().compress().0,
|bytes| CompressedDecaf(bytes).decompress().unwrap(),
BatchSize::SmallInput,
)
});

group.finish();
}

pub fn curve448(c: &mut Criterion) {
let mut group = c.benchmark_group("Curve448");

group.bench_function("scalar multiplication", |b| {
b.iter_batched(
|| {
let mut point = MontgomeryPoint::default();
OsRng.try_fill_bytes(&mut point.0).unwrap();
let scalar = EdwardsScalar::try_from_rng(&mut OsRng).unwrap();
(point, scalar)
},
|(point, scalar)| &point * &scalar,
BatchSize::SmallInput,
)
});

group.finish();
}

criterion_group!(benches, ed448, decaf448, curve448);
criterion_main!(benches);