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::{Data, DATA_CTX, IKMLS, KEY_CTX, MEASUREMENT_TIME, PLAIN_INPUTS};
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
fn encrypt_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.encrypt(&key_ctx, &data_ctx, input) {
|
2024-03-23 19:23:14 +01:00
|
|
|
assert!(false, "{e}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn encryption_benchmark(c: &mut Criterion) {
|
2024-06-22 12:47:10 +02:00
|
|
|
for (input_name, input) in PLAIN_INPUTS.iter() {
|
|
|
|
let mut group = c.benchmark_group(format!("Encryption {input_name}"));
|
|
|
|
group.measurement_time(Duration::from_secs(MEASUREMENT_TIME));
|
|
|
|
for (alg_name, ikml) in IKMLS.iter() {
|
2024-03-23 19:23:14 +01:00
|
|
|
let data = Data { ikml, input };
|
|
|
|
group.bench_with_input(BenchmarkId::new(*alg_name, input_name), &data, |b, i| {
|
|
|
|
b.iter(|| encrypt_coffio(i.ikml, i.input))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, encryption_benchmark);
|
|
|
|
criterion_main!(benches);
|