Skip to content

Commit

Permalink
AES-CTR benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
oconnor663-zoom committed Nov 13, 2020
1 parent 0ecb8e4 commit 7bf791e
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,90 @@ fn bench_onebyte_openssl_sha512(b: &mut Bencher) {
b.iter(|| openssl::hash::hash(openssl::hash::MessageDigest::sha512(), b"x"));
}

#[cfg(feature = "openssl")]
#[bench]
fn bench_long_openssl_aes128ctr(b: &mut Bencher) {
let mut ciphertext = [0; LONG];
let mut input = RandomInput::new(b, LONG);
b.iter(|| {
use openssl::symm::{Cipher, Crypter, Mode};

let key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
let iv = b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07";

// Create a cipher context for encryption.
let mut encrypter =
Crypter::new(Cipher::aes_128_ctr(), Mode::Encrypt, key, Some(iv)).unwrap();

// Encrypt 2 chunks of plaintexts successively.
encrypter.update(input.get(), &mut ciphertext).unwrap();
test::black_box(&ciphertext);
});
}

#[cfg(feature = "openssl")]
#[bench]
fn bench_onebyte_openssl_aes128ctr(b: &mut Bencher) {
b.iter(|| {
use openssl::symm::{Cipher, Crypter, Mode};

let key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
let iv = b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07";

// Create a cipher context for encryption.
let mut encrypter =
Crypter::new(Cipher::aes_128_ctr(), Mode::Encrypt, key, Some(iv)).unwrap();

let mut ciphertext = [0];

// Encrypt 2 chunks of plaintexts successively.
encrypter.update(b"a", &mut ciphertext).unwrap();
test::black_box(&ciphertext);
});
}

#[cfg(feature = "openssl")]
#[bench]
fn bench_long_openssl_aes256ctr(b: &mut Bencher) {
let mut ciphertext = [0; LONG];
let mut input = RandomInput::new(b, LONG);
b.iter(|| {
use openssl::symm::{Cipher, Crypter, Mode};

let key = &[0; 32];
let iv = b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07";

// Create a cipher context for encryption.
let mut encrypter =
Crypter::new(Cipher::aes_256_ctr(), Mode::Encrypt, key, Some(iv)).unwrap();

// Encrypt 2 chunks of plaintexts successively.
encrypter.update(input.get(), &mut ciphertext).unwrap();
test::black_box(&ciphertext);
});
}

#[cfg(feature = "openssl")]
#[bench]
fn bench_onebyte_openssl_aes256ctr(b: &mut Bencher) {
b.iter(|| {
use openssl::symm::{Cipher, Crypter, Mode};

let key = &[0; 32];
let iv = b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07";

// Create a cipher context for encryption.
let mut encrypter =
Crypter::new(Cipher::aes_256_ctr(), Mode::Encrypt, key, Some(iv)).unwrap();

let mut ciphertext = [0];

// Encrypt 2 chunks of plaintexts successively.
encrypter.update(b"a", &mut ciphertext).unwrap();
test::black_box(&ciphertext);
});
}

#[cfg(feature = "ring")]
#[bench]
fn bench_long_ring_sha1(b: &mut Bencher) {
Expand Down

0 comments on commit 7bf791e

Please sign in to comment.