Skip to content

Commit a6b622b

Browse files
committed
chacha20: Add c2-chacha benchmark for comparison
See rust-random/rand#934
1 parent e3e6a3c commit a6b622b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

chacha20/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ zeroize = { version = "1", optional = true }
2626

2727
[dev-dependencies]
2828
stream-cipher = { version = "0.3", features = ["dev"] }
29+
c2-chacha = "0.2"
2930
criterion = "0.3"
3031
criterion-cycles-per-byte = "0.1"
3132

chacha20/benches/stream_cipher.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ fn bench(c: &mut Criterion<CyclesPerByte>) {
3131
}
3232

3333
group.finish();
34+
35+
let mut group = c.benchmark_group("c2-chacha");
36+
37+
for size in &[KB, 2 * KB, 4 * KB, 8 * KB, 16 * KB] {
38+
let mut buf = vec![0u8; *size];
39+
40+
group.throughput(Throughput::Bytes(*size as u64));
41+
42+
group.bench_function(BenchmarkId::new("apply_keystream", size), |b| {
43+
let key = b"very secret key-the most secret.";
44+
let iv = b"my nonce";
45+
let mut cipher = c2_chacha::ChaCha20::new_var(key, iv).unwrap();
46+
47+
b.iter(|| cipher.apply_keystream(&mut buf));
48+
});
49+
}
50+
51+
group.finish();
3452
}
3553

3654
criterion_group!(

0 commit comments

Comments
 (0)