Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 92 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ members = [
"idea",
"kuznyechik",
"magma",
"modes/cbc",
"modes/cfb8",
"modes/cfb-mode",
"modes/ctr",
"modes/ige",
"modes/ofb",
"modes/pcbc",
"rc2",
"serpent",
"sm4",
Expand Down
4 changes: 2 additions & 2 deletions aes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ categories = ["cryptography", "no-std"]

[dependencies]
cfg-if = "1"
cipher = "=0.3.0-pre.4"
cipher = { git = "https://github.com/RustCrypto/traits", branch = "experimental_design" }
ctr = { version = "=0.7.0-pre.3", optional = true }
opaque-debug = "0.3"

[dev-dependencies]
cipher = { version = "=0.3.0-pre.4", features = ["dev"] }
cipher = { git = "https://github.com/RustCrypto/traits", branch = "experimental_design", features = ["dev"] }

[target.'cfg(any(target_arch = "x86_64", target_arch = "x86"))'.dependencies]
cpuid-bool = "0.2"
Expand Down
37 changes: 23 additions & 14 deletions aes/src/autodetect.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Autodetection support for hardware accelerated AES backends with fallback
//! to the fixsliced "soft" implementation.

use crate::{Block, ParBlocks};
use cipher::{
consts::{U16, U24, U32, U8},
consts::{U16, U24, U32},
generic_array::GenericArray,
BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher,
BlockCipher, BlockProcessing, BlockDecrypt, BlockEncrypt, KeyInit, InOutVal, InOutBuf, InResOutBuf,
};
use crate::Block;
use core::mem::ManuallyDrop;

cpuid_bool::new!(aes_cpuid, "aes");
Expand All @@ -33,7 +33,7 @@ macro_rules! define_aes_impl {
}
}

impl NewBlockCipher for $name {
impl KeyInit for $name {
type KeySize = $key_size;

#[inline]
Expand Down Expand Up @@ -62,14 +62,13 @@ macro_rules! define_aes_impl {
}
}

impl BlockCipher for $name {
impl BlockProcessing for $name {
type BlockSize = U16;
type ParBlocks = U8;
}

impl BlockEncrypt for $name {
#[inline]
fn encrypt_block(&self, block: &mut Block) {
fn encrypt_block(&self, block: impl InOutVal<Block>) {
if self.token.get() {
unsafe { self.inner.ni.encrypt_block(block) }
} else {
Expand All @@ -78,18 +77,22 @@ macro_rules! define_aes_impl {
}

#[inline]
fn encrypt_par_blocks(&self, blocks: &mut ParBlocks) {
fn encrypt_blocks(
&self,
blocks: InOutBuf<'_, '_, Block>,
proc: impl FnMut(InResOutBuf<'_, '_, '_, Block>),
) {
if self.token.get() {
unsafe { self.inner.ni.encrypt_par_blocks(blocks) }
unsafe { self.inner.ni.encrypt_blocks(blocks, proc) }
} else {
unsafe { self.inner.soft.encrypt_par_blocks(blocks) }
unsafe { self.inner.soft.encrypt_blocks(blocks, proc) }
}
}
}

impl BlockDecrypt for $name {
#[inline]
fn decrypt_block(&self, block: &mut Block) {
fn decrypt_block(&self, block: impl InOutVal<Block>) {
if self.token.get() {
unsafe { self.inner.ni.decrypt_block(block) }
} else {
Expand All @@ -98,15 +101,21 @@ macro_rules! define_aes_impl {
}

#[inline]
fn decrypt_par_blocks(&self, blocks: &mut ParBlocks) {
fn decrypt_blocks(
&self,
blocks: InOutBuf<'_, '_, Block>,
proc: impl FnMut(InResOutBuf<'_, '_, '_, Block>),
) {
if self.token.get() {
unsafe { self.inner.ni.decrypt_par_blocks(blocks) }
unsafe { self.inner.ni.decrypt_blocks(blocks, proc) }
} else {
unsafe { self.inner.soft.decrypt_par_blocks(blocks) }
unsafe { self.inner.soft.decrypt_blocks(blocks, proc) }
}
}
}

impl BlockCipher for $name {}

opaque_debug::implement!($name);
}
}
Expand Down
Loading