Skip to content

Commit

Permalink
chacha20: Add c2-chacha benchmark for comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Jan 17, 2020
1 parent e3e6a3c commit a6b622b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions chacha20/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
18 changes: 18 additions & 0 deletions chacha20/benches/stream_cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ fn bench(c: &mut Criterion<CyclesPerByte>) {
}

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!(
Expand Down

0 comments on commit a6b622b

Please sign in to comment.