2024-03-23 19:23:14 +01:00
|
|
|
mod data;
|
|
|
|
|
2024-04-20 18:24:30 +02:00
|
|
|
use coffio::{Coffio, DataContext, InputKeyMaterialList, KeyContext};
|
2024-03-23 19:23:14 +01:00
|
|
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
|
|
|
use data::{
|
2024-03-24 14:38:03 +01:00
|
|
|
Data, AES128GCM_SHA256_INPUTS, DATA_CTX, IKML_AES128GCM_SHA256, IKML_XCHACHA20POLY1305_BLAKE3,
|
|
|
|
KEY_CTX, MEASUREMENT_TIME, XCHACHA20POLY1305_BLAKE3_INPUTS,
|
2024-03-23 19:23:14 +01:00
|
|
|
};
|
|
|
|
use std::time::Duration;
|
|
|
|
|
2024-03-24 14:38:03 +01:00
|
|
|
macro_rules! alg_group {
|
|
|
|
($group: ident, $name: expr, $inputs: ident, $ikml: ident) => {
|
|
|
|
for (input_name, input) in $inputs.iter() {
|
|
|
|
let data = Data { ikml: $ikml, input };
|
|
|
|
$group.bench_with_input(BenchmarkId::new($name, input_name), &data, |b, i| {
|
|
|
|
b.iter(|| decrypt_coffio(i.ikml, i.input))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-03-23 19:23:14 +01:00
|
|
|
fn decrypt_coffio(ikml: &str, input: &str) {
|
|
|
|
let ikm = InputKeyMaterialList::import(ikml).unwrap();
|
|
|
|
let key_ctx = KeyContext::from(KEY_CTX);
|
|
|
|
let data_ctx = DataContext::from(DATA_CTX);
|
2024-04-20 18:24:30 +02:00
|
|
|
let cb = Coffio::new(&ikm);
|
2024-03-24 09:25:27 +01:00
|
|
|
if let Err(e) = cb.decrypt(&key_ctx, &data_ctx, input) {
|
2024-03-23 19:23:14 +01:00
|
|
|
assert!(false, "{e}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn decryption_benchmark(c: &mut Criterion) {
|
|
|
|
let mut group = c.benchmark_group("Decryption");
|
|
|
|
group.measurement_time(Duration::from_secs(MEASUREMENT_TIME));
|
2024-03-24 14:38:03 +01:00
|
|
|
alg_group!(
|
|
|
|
group,
|
|
|
|
"Aes128GcmWithSha256",
|
|
|
|
AES128GCM_SHA256_INPUTS,
|
|
|
|
IKML_AES128GCM_SHA256
|
|
|
|
);
|
|
|
|
alg_group!(
|
|
|
|
group,
|
|
|
|
"XChaCha20Poly1305WithBlake3",
|
|
|
|
XCHACHA20POLY1305_BLAKE3_INPUTS,
|
|
|
|
IKML_XCHACHA20POLY1305_BLAKE3
|
|
|
|
);
|
2024-03-23 19:23:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, decryption_benchmark);
|
|
|
|
criterion_main!(benches);
|