]>
git.proxmox.com Git - proxmox-backup.git/blob - src/bin/cipherbench.rs
7238c09b0c2eded82d40949bb6d3bc7db8476cac
5 fn rate_test(name
: &str, bench
: &dyn Fn() -> usize) {
7 let start
= std
::time
::SystemTime
::now();
8 let duration
= std
::time
::Duration
::new(1, 0);
14 let elapsed
= start
.elapsed().unwrap();
15 if elapsed
> duration { break; }
18 let elapsed
= start
.elapsed().unwrap();
19 let elapsed
= (elapsed
.as_secs() as f64) +
20 (elapsed
.subsec_millis() as f64)/1000.0;
22 println
!("{} {} MB/s", name
, (bytes
as f64)/(elapsed
*1024.0*1024.0));
26 fn main() -> Result
<(), Error
> {
28 let input
= proxmox
::sys
::linux
::random_data(1024*1024)?
;
30 rate_test("crc32", &|| {
31 let mut crchasher
= crc32fast
::Hasher
::new();
32 crchasher
.update(&input
);
33 let _checksum
= crchasher
.finalize();
37 rate_test("zstd", &|| {
38 zstd
::block
::compress(&input
, 1).unwrap();
42 rate_test("sha256", &|| {
43 openssl
::sha
::sha256(&input
);
47 let key
= proxmox
::sys
::linux
::random_data(32)?
;
49 let iv
= proxmox
::sys
::linux
::random_data(16)?
;
51 let cipher
= openssl
::symm
::Cipher
::aes_256_gcm();
53 rate_test("aes-256-gcm", &|| {
54 let mut tag
= [0u8;16];
55 openssl
::symm
::encrypt_aead(
65 let cipher
= openssl
::symm
::Cipher
::chacha20_poly1305();
67 rate_test("chacha20-poly1305", &|| {
68 let mut tag
= [0u8;16];
69 openssl
::symm
::encrypt_aead(