diff --git a/examples/bench.rs b/examples/bench.rs index 0c2e272..691b8b5 100644 --- a/examples/bench.rs +++ b/examples/bench.rs @@ -1,3 +1,5 @@ +use aes_gcm::{Aes256Gcm, KeyInit}; +use aes_gcm::aead::{Aead, Nonce}; use benchmark_simple::{Bench, Options}; use aes_gcm_stream::{Aes128GcmStreamEncryptor, Aes192GcmStreamEncryptor, Aes256GcmStreamEncryptor}; @@ -29,6 +31,17 @@ fn test_aes256_encrypt(m: &mut [u8]) { encryptor.finalize(); } +fn test_aes256_encrypt_aesgcm(m: &mut [u8]) { + let key = [0u8; 32]; + let nonce = [0u8; 12]; + + let cipher = Aes256Gcm::new_from_slice(&key).expect("new from key slice"); + let mut n = Nonce::::default(); + let mn: &mut [u8] = n.as_mut(); + for i in 0..mn.len() { mn[i] = nonce[i]; } + cipher.encrypt(&n, &m[0..]).expect("decrypt"); +} + fn main() { let bench = Bench::new(); let mut m = vec![0xd0u8; 16384]; @@ -43,11 +56,14 @@ fn main() { }; let res = bench.run(options, || test_aes128_encrypt(&mut m)); - println!("AES128 encrypt : {}", res.throughput(m.len() as _)); + println!("AES128 encrypt : {}", res.throughput(m.len() as _)); let res = bench.run(options, || test_aes192_encrypt(&mut m)); - println!("AES192 encrypt : {}", res.throughput(m.len() as _)); + println!("AES192 encrypt : {}", res.throughput(m.len() as _)); let res = bench.run(options, || test_aes256_encrypt(&mut m)); - println!("AES256 encrypt : {}", res.throughput(m.len() as _)); + println!("AES256 encrypt : {}", res.throughput(m.len() as _)); + + let res = bench.run(options, || test_aes256_encrypt_aesgcm(&mut m)); + println!("AES256 encrypt aes-gcm : {}", res.throughput(m.len() as _)); } \ No newline at end of file