-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KEM: Key-Encapsulation Mechanisms API Support (#260)
Co-authored-by: Ben Civjan <[email protected]> Co-authored-by: Justin W Smith <[email protected]>
- Loading branch information
1 parent
f6fd8a4
commit 516ffef
Showing
10 changed files
with
881 additions
and
35 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
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,74 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR ISC | ||
|
||
use aws_lc_rs::{ | ||
kem::DecapsulationKey, | ||
unstable::kem::{get_algorithm, AlgorithmId}, | ||
}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
const UNSTABLE_ALGORITHMS: &[Option<&aws_lc_rs::kem::Algorithm<AlgorithmId>>] = &[ | ||
get_algorithm(AlgorithmId::Kyber512_R3), | ||
get_algorithm(AlgorithmId::Kyber768_R3), | ||
get_algorithm(AlgorithmId::Kyber1024_R3), | ||
]; | ||
|
||
fn bench_kem_keygen(c: &mut Criterion) { | ||
for ele in UNSTABLE_ALGORITHMS { | ||
let ele = ele.unwrap(); | ||
let bench_group_name = format!("KEM/{:?}/keygen", ele.id()); | ||
let mut group = c.benchmark_group(bench_group_name); | ||
group.bench_function("AWS-LC", |b| { | ||
b.iter(|| { | ||
aws_lc_rs::kem::DecapsulationKey::generate(ele).unwrap(); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
fn bench_kem_encapsulate(c: &mut Criterion) { | ||
for ele in UNSTABLE_ALGORITHMS { | ||
let ele = ele.unwrap(); | ||
let bench_group_name = format!("KEM/{:?}/encapsulate", ele.id()); | ||
let mut group = c.benchmark_group(bench_group_name); | ||
group.bench_function("AWS-LC", |b| { | ||
b.iter_batched( | ||
|| { | ||
let private = DecapsulationKey::generate(ele).unwrap(); | ||
private.encapsulation_key().unwrap() | ||
}, | ||
|key| key.encapsulate(), | ||
criterion::BatchSize::LargeInput, | ||
); | ||
}); | ||
} | ||
} | ||
|
||
fn bench_kem_decapsulate(c: &mut Criterion) { | ||
for ele in UNSTABLE_ALGORITHMS { | ||
let ele = ele.unwrap(); | ||
let bench_group_name = format!("KEM/{:?}/decapsulate", ele.id()); | ||
let mut group = c.benchmark_group(bench_group_name); | ||
group.bench_function("AWS-LC", |b| { | ||
b.iter_batched( | ||
|| { | ||
let private = DecapsulationKey::generate(ele).unwrap(); | ||
let public = private.encapsulation_key().unwrap(); | ||
let (ciphertext, _) = public.encapsulate().unwrap(); | ||
(private, ciphertext) | ||
}, | ||
|(key, ciphertext)| key.decapsulate(ciphertext).unwrap(), | ||
criterion::BatchSize::LargeInput, | ||
); | ||
}); | ||
} | ||
} | ||
|
||
fn bench_kem(c: &mut Criterion) { | ||
bench_kem_keygen(c); | ||
bench_kem_encapsulate(c); | ||
bench_kem_decapsulate(c); | ||
} | ||
|
||
criterion_group!(benches, bench_kem); | ||
criterion_main!(benches); |
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
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
Oops, something went wrong.