Skip to content

Commit

Permalink
aes-soft: use fixslicing for AES encryption
Browse files Browse the repository at this point in the history
Fixslicing is presently defined for encryption only.

However, accelerating just encryption is still useful for AES-CTR.

Performance is improved by ~3X as measured on an Intel Core i9
(despite the fixslicing implementation being 32-bit only)
  • Loading branch information
tarcieri committed Oct 26, 2020
1 parent cd1837a commit 3d3c595
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 662 deletions.
14 changes: 1 addition & 13 deletions aes/aes-soft/benches/aes128.rs
Expand Up @@ -2,7 +2,7 @@
extern crate test;

use aes_soft::cipher::{BlockCipher, NewBlockCipher};
use aes_soft::{Aes128, Aes128Fixsliced};
use aes_soft::Aes128;

#[bench]
pub fn aes128_encrypt(bh: &mut test::Bencher) {
Expand Down Expand Up @@ -40,18 +40,6 @@ pub fn aes128_encrypt8(bh: &mut test::Bencher) {
bh.bytes = (input[0].len() * input.len()) as u64;
}

#[bench]
pub fn aes128_encrypt2_fixsliced(bh: &mut test::Bencher) {
let cipher = Aes128Fixsliced::new(&Default::default());
let mut input = Default::default();

bh.iter(|| {
cipher.encrypt_blocks(&mut input);
test::black_box(&input);
});
bh.bytes = (input[0].len() * input.len()) as u64;
}

#[bench]
pub fn aes128_decrypt8(bh: &mut test::Bencher) {
let cipher = Aes128::new(&Default::default());
Expand Down
14 changes: 1 addition & 13 deletions aes/aes-soft/benches/aes192.rs
Expand Up @@ -2,7 +2,7 @@
extern crate test;

use aes_soft::cipher::{BlockCipher, NewBlockCipher};
use aes_soft::{Aes192, Aes192Fixsliced};
use aes_soft::Aes192;

#[bench]
pub fn aes192_encrypt(bh: &mut test::Bencher) {
Expand Down Expand Up @@ -40,18 +40,6 @@ pub fn aes192_encrypt8(bh: &mut test::Bencher) {
bh.bytes = (input[0].len() * input.len()) as u64;
}

#[bench]
pub fn aes192_encrypt2_fixsliced(bh: &mut test::Bencher) {
let cipher = Aes192Fixsliced::new(&Default::default());
let mut input = Default::default();

bh.iter(|| {
cipher.encrypt_blocks(&mut input);
test::black_box(&input);
});
bh.bytes = (input[0].len() * input.len()) as u64;
}

#[bench]
pub fn aes192_decrypt8(bh: &mut test::Bencher) {
let cipher = Aes192::new(&Default::default());
Expand Down
14 changes: 1 addition & 13 deletions aes/aes-soft/benches/aes256.rs
Expand Up @@ -2,7 +2,7 @@
extern crate test;

use aes_soft::cipher::{BlockCipher, NewBlockCipher};
use aes_soft::{Aes256, Aes256Fixsliced};
use aes_soft::Aes256;

#[bench]
pub fn aes256_encrypt(bh: &mut test::Bencher) {
Expand Down Expand Up @@ -40,18 +40,6 @@ pub fn aes256_encrypt8(bh: &mut test::Bencher) {
bh.bytes = (input[0].len() * input.len()) as u64;
}

#[bench]
pub fn aes256_encrypt2_fixsliced(bh: &mut test::Bencher) {
let cipher = Aes256Fixsliced::new(&Default::default());
let mut input = Default::default();

bh.iter(|| {
cipher.encrypt_blocks(&mut input);
test::black_box(&input);
});
bh.bytes = (input[0].len() * input.len()) as u64;
}

#[bench]
pub fn aes256_decrypt8(bh: &mut test::Bencher) {
let cipher = Aes256::new(&Default::default());
Expand Down
20 changes: 0 additions & 20 deletions aes/aes-soft/src/bitslice.rs
Expand Up @@ -21,26 +21,6 @@ pub trait AesOps {
fn add_round_key(self, rk: &Self) -> Self;
}

pub fn encrypt_core<S: AesOps + Copy>(state: &S, sk: &[S]) -> S {
// Round 0 - add round key
let mut tmp = state.add_round_key(&sk[0]);

// Remaining rounds (except last round)
for i in 1..sk.len() - 1 {
tmp = tmp.sub_bytes();
tmp = tmp.shift_rows();
tmp = tmp.mix_columns();
tmp = tmp.add_round_key(&sk[i]);
}

// Last round
tmp = tmp.sub_bytes();
tmp = tmp.shift_rows();
tmp = tmp.add_round_key(&sk[sk.len() - 1]);

tmp
}

pub fn decrypt_core<S: AesOps + Copy>(state: &S, sk: &[S]) -> S {
// Round 0 - add round key
let mut tmp = state.add_round_key(&sk[sk.len() - 1]);
Expand Down

0 comments on commit 3d3c595

Please sign in to comment.