Skip to content

Commit

Permalink
update to 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mikelodder7 committed Nov 8, 2024
1 parent e6758b3 commit f920096
Show file tree
Hide file tree
Showing 10 changed files with 570 additions and 461 deletions.
29 changes: 14 additions & 15 deletions frodo-kem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "Apache-2.0 OR MIT"
name = "frodo-kem"
readme = "README.md"
repository = "https://github.com/RustCrypto/KEMs/frodo-kem"
version = "0.3.0"
version = "0.4.0"

[features]
default = [
Expand Down Expand Up @@ -62,14 +62,20 @@ serde = { version = "1.0", features = ["derive"], optional = true }
serdect = "0.3.0-rc.0"
subtle = "2.6"
thiserror = "2.0"
zeroize = "1"

[target.'cfg(target_arch = "aarch64")'.dependencies]
sha3 = { version = "0.10", features = ["asm"] }
zeroize = { version = "1", features = ["aarch64"] }

[target.'cfg(any(target_arch = "x86_64", target_arch = "x86"))'.dependencies]
zeroize = { version = "1", features = ["simd"] }

[target.'cfg(not(target_arch = "aarch64"))'.dependencies]
sha3 = { version = "0.10" }

[target.'cfg(not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64")))'.dependencies]
zeroize = "1"

[dev-dependencies]
aes = "0.8"
bincode = "1.3"
Expand All @@ -95,21 +101,14 @@ features = [
]
rustdoc-args = ["--cfg", "docsrs"]

[lints.rust]
missing_docs = "warn"
missing_debug_implementations = "warn"
missing_copy_implementations = "warn"
trivial_casts = "warn"
trivial_numeric_casts = "warn"
unused = "warn"

[lints.clippy]
mod_module_files = "warn"
unwrap_used = "deny"

[[bench]]
name = "safe-oqs"
harness = false
path = "bench/safe_oqs.rs"
path = "benches/safe_oqs.rs"
required-features = ["efrodo"]

[[bench]]
name = "frodo"
harness = false
path = "benches/frodo.rs"
required-features = ["frodo"]
175 changes: 175 additions & 0 deletions frodo-kem/benches/frodo.rs
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);
Loading

0 comments on commit f920096

Please sign in to comment.