diff --git a/chacha20/Cargo.toml b/chacha20/Cargo.toml index c78bd6a6..f7af137a 100644 --- a/chacha20/Cargo.toml +++ b/chacha20/Cargo.toml @@ -26,6 +26,7 @@ zeroize = { version = "1", optional = true } [dev-dependencies] stream-cipher = { version = "0.3", features = ["dev"] } +c2-chacha = "0.2" criterion = "0.3" criterion-cycles-per-byte = "0.1" diff --git a/chacha20/benches/stream_cipher.rs b/chacha20/benches/stream_cipher.rs index 0f924e93..ed68c09c 100644 --- a/chacha20/benches/stream_cipher.rs +++ b/chacha20/benches/stream_cipher.rs @@ -31,6 +31,24 @@ fn bench(c: &mut Criterion) { } group.finish(); + + let mut group = c.benchmark_group("c2-chacha"); + + for size in &[KB, 2 * KB, 4 * KB, 8 * KB, 16 * KB] { + let mut buf = vec![0u8; *size]; + + group.throughput(Throughput::Bytes(*size as u64)); + + group.bench_function(BenchmarkId::new("apply_keystream", size), |b| { + let key = b"very secret key-the most secret."; + let iv = b"my nonce"; + let mut cipher = c2_chacha::ChaCha20::new_var(key, iv).unwrap(); + + b.iter(|| cipher.apply_keystream(&mut buf)); + }); + } + + group.finish(); } criterion_group!(