Add benchmark tests for AEADs
@@ -8,6 +8,7 @@ use orion::hazardous::mac::hmac;
use orion::hazardous::mac::poly1305;
use orion::hazardous::stream::*;
use orion::hazardous::xof::cshake;
+use orion::hazardous::aead::{chacha20poly1305, xchacha20poly1305};
use test::Bencher;
#[bench]
@@ -128,3 +129,61 @@ fn bench_xchacha20_decrypt(b: &mut Bencher) {
).unwrap();
});
}
+
+#[bench]
+fn bench_chacha20poly1305_encrypt_decrypt(b: &mut Bencher) {
+
+ let mut plaintext = [0u8; 256];
+ let mut ciphertext_with_tag = [0u8; 256 + 16];
+
+ b.iter(|| {
+
+ let key = chacha20poly1305::SecretKey::from_slice(&[0u8; 32]).unwrap();
+ let nonce = chacha20poly1305::Nonce::from_slice(&[0u8; 12]).unwrap();
+
+ chacha20poly1305::seal(
+ &key,
+ &nonce,
+ &plaintext,
+ None,
+ &mut ciphertext_with_tag,
+ ).unwrap();
+
+ chacha20poly1305::open(
+ &key,
+ &nonce,
+ &ciphertext_with_tag,
+ None,
+ &mut plaintext,
+ ).unwrap();
+ });
+}
+
+#[bench]
+fn bench_xchacha20poly1305_encrypt_decrypt(b: &mut Bencher) {
+
+ let mut plaintext = [0u8; 256];
+ let mut ciphertext_with_tag = [0u8; 256 + 16];
+
+ b.iter(|| {
+
+ let key = xchacha20poly1305::SecretKey::from_slice(&[0u8; 32]).unwrap();
+ let nonce = xchacha20poly1305::Nonce::from_slice(&[0u8; 24]).unwrap();
+
+ xchacha20poly1305::seal(
+ &key,
+ &nonce,
+ &plaintext,
+ None,
+ &mut ciphertext_with_tag,
+ ).unwrap();
+
+ xchacha20poly1305::open(
+ &key,
+ &nonce,
+ &ciphertext_with_tag,
+ None,
+ &mut plaintext,
+ ).unwrap();
+ });
+}
