-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6758b3
commit f920096
Showing
10 changed files
with
570 additions
and
461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
use criterion::{ | ||
criterion_group, criterion_main, measurement::Measurement, BenchmarkGroup, Criterion, | ||
}; | ||
use frodo_kem::*; | ||
use rand_core::SeedableRng; | ||
|
||
fn bench_keygen<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) { | ||
let mut rng = rand_chacha::ChaCha8Rng::from_entropy(); | ||
group.bench_function("KeyGen 640Aes", |b| { | ||
b.iter(|| { | ||
let (_pk, _sk) = Algorithm::FrodoKem640Aes.generate_keypair(&mut rng); | ||
}); | ||
}); | ||
|
||
group.bench_function("KeyGen 976Aes", |b| { | ||
b.iter(|| { | ||
let (_pk, _sk) = Algorithm::FrodoKem976Aes.generate_keypair(&mut rng); | ||
}); | ||
}); | ||
|
||
group.bench_function("KeyGen 1344Aes", |b| { | ||
b.iter(|| { | ||
let (_pk, _sk) = Algorithm::FrodoKem1344Aes.generate_keypair(&mut rng); | ||
}); | ||
}); | ||
|
||
group.bench_function("KeyGen 640Shake", |b| { | ||
b.iter(|| { | ||
let (_pk, _sk) = Algorithm::FrodoKem640Shake.generate_keypair(&mut rng); | ||
}); | ||
}); | ||
|
||
group.bench_function("KeyGen 976Shake", |b| { | ||
b.iter(|| { | ||
let (_pk, _sk) = Algorithm::FrodoKem976Shake.generate_keypair(&mut rng); | ||
}); | ||
}); | ||
|
||
group.bench_function("KeyGen 1344Shake", |b| { | ||
b.iter(|| { | ||
let (_pk, _sk) = Algorithm::FrodoKem1344Shake.generate_keypair(&mut rng); | ||
}); | ||
}); | ||
} | ||
|
||
fn bench_encapsulate<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) { | ||
let mut rng = rand_chacha::ChaCha8Rng::from_entropy(); | ||
let (pk, _sk) = Algorithm::FrodoKem640Aes.generate_keypair(&mut rng); | ||
group.bench_function("Encapsulate 640Aes", |b| { | ||
b.iter(|| { | ||
let (_ct, _ss) = Algorithm::FrodoKem640Aes | ||
.encapsulate_with_rng(&pk, &mut rng) | ||
.unwrap(); | ||
}); | ||
}); | ||
|
||
let (pk, _sk) = Algorithm::FrodoKem976Aes.generate_keypair(&mut rng); | ||
group.bench_function("Encapsulate 976Aes", |b| { | ||
b.iter(|| { | ||
let (_ct, _ss) = Algorithm::FrodoKem976Aes | ||
.encapsulate_with_rng(&pk, &mut rng) | ||
.unwrap(); | ||
}); | ||
}); | ||
|
||
let (pk, _sk) = Algorithm::FrodoKem1344Aes.generate_keypair(&mut rng); | ||
group.bench_function("Encapsulate 1344Aes", |b| { | ||
b.iter(|| { | ||
let (_ct, _ss) = Algorithm::FrodoKem1344Aes | ||
.encapsulate_with_rng(&pk, &mut rng) | ||
.unwrap(); | ||
}); | ||
}); | ||
|
||
let (pk, _sk) = Algorithm::FrodoKem640Shake.generate_keypair(&mut rng); | ||
group.bench_function("Encapsulate 640Shake", |b| { | ||
b.iter(|| { | ||
let (_ct, _ss) = Algorithm::FrodoKem640Shake | ||
.encapsulate_with_rng(&pk, &mut rng) | ||
.unwrap(); | ||
}); | ||
}); | ||
|
||
let (pk, _sk) = Algorithm::FrodoKem976Shake.generate_keypair(&mut rng); | ||
group.bench_function("Encapsulate 976Shake", |b| { | ||
b.iter(|| { | ||
let (_ct, _ss) = Algorithm::FrodoKem976Shake | ||
.encapsulate_with_rng(&pk, &mut rng) | ||
.unwrap(); | ||
}); | ||
}); | ||
|
||
let (pk, _sk) = Algorithm::FrodoKem1344Shake.generate_keypair(&mut rng); | ||
group.bench_function("Encapsulate 1344Shake", |b| { | ||
b.iter(|| { | ||
let (_ct, _ss) = Algorithm::FrodoKem1344Shake | ||
.encapsulate_with_rng(&pk, &mut rng) | ||
.unwrap(); | ||
}); | ||
}); | ||
} | ||
|
||
fn bench_decapsulate<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) { | ||
let mut rng = rand_chacha::ChaCha8Rng::from_entropy(); | ||
let (pk, sk) = Algorithm::FrodoKem640Aes.generate_keypair(&mut rng); | ||
let (ct, _ss) = Algorithm::FrodoKem640Aes | ||
.encapsulate_with_rng(&pk, &mut rng) | ||
.unwrap(); | ||
group.bench_function("Decapsulate 640Aes", |b| { | ||
b.iter(|| { | ||
let (_ss, _mu) = Algorithm::FrodoKem640Aes.decapsulate(&sk, &ct).unwrap(); | ||
}); | ||
}); | ||
|
||
let (pk, sk) = Algorithm::FrodoKem976Aes.generate_keypair(&mut rng); | ||
let (ct, _ss) = Algorithm::FrodoKem976Aes | ||
.encapsulate_with_rng(&pk, &mut rng) | ||
.unwrap(); | ||
group.bench_function("Decapsulate 976Aes", |b| { | ||
b.iter(|| { | ||
let (_ss, _mu) = Algorithm::FrodoKem976Aes.decapsulate(&sk, &ct).unwrap(); | ||
}); | ||
}); | ||
|
||
let (pk, sk) = Algorithm::FrodoKem1344Aes.generate_keypair(&mut rng); | ||
let (ct, _ss) = Algorithm::FrodoKem1344Aes | ||
.encapsulate_with_rng(&pk, &mut rng) | ||
.unwrap(); | ||
group.bench_function("Decapsulate 1344Aes", |b| { | ||
b.iter(|| { | ||
let (_ss, _mu) = Algorithm::FrodoKem1344Aes.decapsulate(&sk, &ct).unwrap(); | ||
}); | ||
}); | ||
|
||
let (pk, sk) = Algorithm::FrodoKem640Shake.generate_keypair(&mut rng); | ||
let (ct, _ss) = Algorithm::FrodoKem640Shake | ||
.encapsulate_with_rng(&pk, &mut rng) | ||
.unwrap(); | ||
group.bench_function("Decapsulate 640Shake", |b| { | ||
b.iter(|| { | ||
let (_ss, _mu) = Algorithm::FrodoKem640Shake.decapsulate(&sk, &ct).unwrap(); | ||
}); | ||
}); | ||
|
||
let (pk, sk) = Algorithm::FrodoKem976Shake.generate_keypair(&mut rng); | ||
let (ct, _ss) = Algorithm::FrodoKem976Shake | ||
.encapsulate_with_rng(&pk, &mut rng) | ||
.unwrap(); | ||
group.bench_function("Decapsulate 976Shake", |b| { | ||
b.iter(|| { | ||
let (_ss, _mu) = Algorithm::FrodoKem976Shake.decapsulate(&sk, &ct).unwrap(); | ||
}); | ||
}); | ||
|
||
let (pk, sk) = Algorithm::FrodoKem1344Shake.generate_keypair(&mut rng); | ||
let (ct, _ss) = Algorithm::FrodoKem1344Shake | ||
.encapsulate_with_rng(&pk, &mut rng) | ||
.unwrap(); | ||
group.bench_function("Decapsulate 1344Shake", |b| { | ||
b.iter(|| { | ||
let (_ss, _mu) = Algorithm::FrodoKem1344Shake.decapsulate(&sk, &ct).unwrap(); | ||
}); | ||
}); | ||
} | ||
|
||
fn bench_against_liboqs(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("FrodoKEM"); | ||
bench_keygen(&mut group); | ||
bench_encapsulate(&mut group); | ||
bench_decapsulate(&mut group); | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench_against_liboqs); | ||
criterion_main!(benches); |
Oops, something went wrong.