Skip to content

Commit

Permalink
Bump cipher crate to v0.3.0-pre.3
Browse files Browse the repository at this point in the history
Implements the API changes introduced in:

RustCrypto/traits#435
  • Loading branch information
tarcieri committed Dec 30, 2020
1 parent c97c973 commit 8712536
Show file tree
Hide file tree
Showing 45 changed files with 191 additions and 145 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions aes/Cargo.toml
Expand Up @@ -16,12 +16,12 @@ categories = ["cryptography", "no-std"]

[dependencies]
cfg-if = "1"
cipher = "=0.3.0-pre"
ctr = { version = "=0.7.0-pre", optional = true }
cipher = "=0.3.0-pre.3"
ctr = { version = "=0.7.0-pre.2", optional = true }
opaque-debug = "0.3"

[dev-dependencies]
cipher = { version = "=0.3.0-pre", features = ["dev"] }
cipher = { version = "=0.3.0-pre.3", features = ["dev"] }

[target.'cfg(any(target_arch = "x86_64", target_arch = "x86"))'.dependencies]
cpuid-bool = "0.2"
Expand Down
7 changes: 3 additions & 4 deletions aes/src/autodetect.rs
Expand Up @@ -109,8 +109,7 @@ pub(crate) mod ctr {
block::BlockCipher,
generic_array::GenericArray,
stream::{
FromBlockCipher, LoopError, OverflowError, SeekNum, SyncStreamCipher,
SyncStreamCipherSeek,
FromBlockCipher, LoopError, OverflowError, SeekNum, StreamCipher, StreamCipherSeek,
},
};

Expand Down Expand Up @@ -165,7 +164,7 @@ pub(crate) mod ctr {
}
}

impl SyncStreamCipher for $name {
impl StreamCipher for $name {
#[inline]
fn try_apply_keystream(&mut self, data: &mut [u8]) -> Result<(), LoopError> {
match &mut self.inner {
Expand All @@ -175,7 +174,7 @@ pub(crate) mod ctr {
}
}

impl SyncStreamCipherSeek for $name {
impl StreamCipherSeek for $name {
#[inline]
fn try_current_pos<T: SeekNum>(&self) -> Result<T, OverflowError> {
match &self.inner {
Expand Down
8 changes: 5 additions & 3 deletions aes/src/ni/ctr.rs
@@ -1,13 +1,15 @@
//! AES in counter mode (a.k.a. AES-CTR)

// TODO(tarcieri): support generic CTR API

#![allow(clippy::unreadable_literal)]

use super::arch::*;
use core::mem;

use super::{Aes128, Aes192, Aes256};
use cipher::stream::{
FromBlockCipher, LoopError, OverflowError, SeekNum, SyncStreamCipher, SyncStreamCipherSeek,
FromBlockCipher, LoopError, OverflowError, SeekNum, StreamCipher, StreamCipherSeek,
};
use cipher::{consts::U16, generic_array::GenericArray, BlockCipher};

Expand Down Expand Up @@ -146,7 +148,7 @@ macro_rules! impl_ctr {
}
}

impl SyncStreamCipher for $name {
impl StreamCipher for $name {
#[inline]
fn try_apply_keystream(&mut self, mut data: &mut [u8])
-> Result<(), LoopError>
Expand Down Expand Up @@ -200,7 +202,7 @@ macro_rules! impl_ctr {
}
}

impl SyncStreamCipherSeek for $name {
impl StreamCipherSeek for $name {
fn try_current_pos<T: SeekNum>(&self) -> Result<T, OverflowError> {
T::from_block_byte(self.get_u64_ctr(), self.pos, BLOCK_SIZE as u8)
}
Expand Down
8 changes: 5 additions & 3 deletions aes/src/soft/ctr.rs
@@ -1,15 +1,17 @@
//! AES in counter mode (a.k.a. AES-CTR)

// TODO(tarcieri): support generic CTR API

use super::{Aes128, Aes192, Aes256};

/// AES-128 in CTR mode
#[cfg_attr(docsrs, doc(cfg(feature = "ctr")))]
pub type Aes128Ctr = ::ctr::Ctr128<Aes128>;
pub type Aes128Ctr = ::ctr::Ctr64BE<Aes128>;

/// AES-192 in CTR mode
#[cfg_attr(docsrs, doc(cfg(feature = "ctr")))]
pub type Aes192Ctr = ::ctr::Ctr128<Aes192>;
pub type Aes192Ctr = ::ctr::Ctr64BE<Aes192>;

/// AES-256 in CTR mode
#[cfg_attr(docsrs, doc(cfg(feature = "ctr")))]
pub type Aes256Ctr = ::ctr::Ctr128<Aes256>;
pub type Aes256Ctr = ::ctr::Ctr64BE<Aes256>;
4 changes: 2 additions & 2 deletions aes/tests/ctr.rs
Expand Up @@ -3,7 +3,7 @@
use aes::{Aes128Ctr, Aes256Ctr};

// Random tests generated by OpenSSL
cipher::stream_cipher_sync_test!(aes128_ctr_core, Aes128Ctr, "aes128-ctr");
cipher::stream_cipher_sync_test!(aes256_ctr_core, Aes256Ctr, "aes256-ctr");
cipher::stream_cipher_test!(aes128_ctr_core, Aes128Ctr, "aes128-ctr");
cipher::stream_cipher_test!(aes256_ctr_core, Aes256Ctr, "aes256-ctr");
cipher::stream_cipher_seek_test!(aes128_ctr_seek, Aes128Ctr);
cipher::stream_cipher_seek_test!(aes256_ctr_seek, Aes256Ctr);
2 changes: 1 addition & 1 deletion block-modes/Cargo.toml
Expand Up @@ -12,7 +12,7 @@ keywords = ["crypto", "block-cipher", "ciphers"]

[dependencies]
block-padding = "0.2"
cipher = "=0.3.0-pre"
cipher = "=0.3.0-pre.3"

[dev-dependencies]
aes = { version = "=0.7.0-pre", path = "../aes" }
Expand Down
15 changes: 9 additions & 6 deletions block-modes/src/cfb.rs
@@ -1,10 +1,13 @@
use crate::traits::BlockMode;
use crate::utils::{xor, Block, ParBlocks};
use crate::{
traits::BlockMode,
utils::{xor, Block, ParBlocks},
};
use block_padding::Padding;
use cipher::block::{BlockCipher, BlockEncrypt, NewBlockCipher};
use cipher::generic_array::{typenum::Unsigned, GenericArray};
use core::marker::PhantomData;
use core::ptr;
use cipher::{
generic_array::{typenum::Unsigned, GenericArray},
BlockCipher, BlockEncrypt, NewBlockCipher,
};
use core::{marker::PhantomData, ptr};

/// [Cipher feedback][1] (CFB) block mode instance with a full block feedback.
///
Expand Down
6 changes: 2 additions & 4 deletions block-modes/src/cfb8.rs
@@ -1,8 +1,6 @@
use crate::traits::BlockMode;
use crate::utils::Block;
use crate::{traits::BlockMode, utils::Block};
use block_padding::Padding;
use cipher::block::{BlockCipher, BlockEncrypt, NewBlockCipher};
use cipher::generic_array::GenericArray;
use cipher::{generic_array::GenericArray, BlockCipher, BlockEncrypt, NewBlockCipher};
use core::marker::PhantomData;

/// [Cipher feedback][1] (CFB) block mode instance with a full block feedback.
Expand Down
20 changes: 13 additions & 7 deletions block-modes/src/ecb.rs
@@ -1,10 +1,16 @@
use crate::errors::InvalidKeyIvLength;
use crate::traits::BlockMode;
use crate::utils::{get_par_blocks, Block};
use crate::{
errors::InvalidKeyIvLength,
traits::BlockMode,
utils::{get_par_blocks, Block},
};
use block_padding::Padding;
use cipher::block::{BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher};
use cipher::generic_array::typenum::{Unsigned, U0};
use cipher::generic_array::GenericArray;
use cipher::{
generic_array::{
typenum::{Unsigned, U0},
GenericArray,
},
BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher,
};
use core::marker::PhantomData;

/// [Electronic Codebook][1] (ECB) block cipher mode instance.
Expand Down Expand Up @@ -34,7 +40,7 @@ where
}

fn new_var(key: &[u8], _iv: &[u8]) -> Result<Self, InvalidKeyIvLength> {
let cipher = C::new_varkey(key).map_err(|_| InvalidKeyIvLength)?;
let cipher = C::new_var(key).map_err(|_| InvalidKeyIvLength)?;
Ok(Self {
cipher,
_p: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion block-modes/src/ige.rs
Expand Up @@ -4,11 +4,11 @@ use crate::{
};
use block_padding::Padding;
use cipher::{
block::{BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher},
generic_array::{
typenum::{Prod, Unsigned, U2},
ArrayLength, GenericArray,
},
BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher,
};
use core::{marker::PhantomData, ops::Mul};

Expand Down
9 changes: 5 additions & 4 deletions block-modes/src/ofb.rs
@@ -1,8 +1,9 @@
use crate::traits::BlockMode;
use crate::utils::{xor, Block};
use crate::{
traits::BlockMode,
utils::{xor, Block},
};
use block_padding::Padding;
use cipher::block::{BlockCipher, BlockEncrypt, NewBlockCipher};
use cipher::generic_array::GenericArray;
use cipher::{generic_array::GenericArray, BlockCipher, BlockEncrypt, NewBlockCipher};
use core::marker::PhantomData;

/// [Output feedback][1] (OFB) block mode instance with a full block feedback.
Expand Down
11 changes: 7 additions & 4 deletions block-modes/src/pcbc.rs
@@ -1,8 +1,11 @@
use crate::traits::BlockMode;
use crate::utils::{xor, Block};
use crate::{
traits::BlockMode,
utils::{xor, Block},
};
use block_padding::Padding;
use cipher::block::{BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher};
use cipher::generic_array::GenericArray;
use cipher::{
generic_array::GenericArray, BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher,
};
use core::marker::PhantomData;

/// [Propagating Cipher Block Chaining][1] (PCBC) mode instance.
Expand Down
15 changes: 9 additions & 6 deletions block-modes/src/traits.rs
@@ -1,12 +1,15 @@
#[cfg(feature = "alloc")]
pub use alloc::vec::Vec;

use crate::errors::{BlockModeError, InvalidKeyIvLength};
use crate::utils::{to_blocks, Block, Key};
use crate::{
errors::{BlockModeError, InvalidKeyIvLength},
utils::{to_blocks, Block, Key},
};
use block_padding::Padding;
use cipher::block::{BlockCipher, NewBlockCipher};
use cipher::generic_array::typenum::Unsigned;
use cipher::generic_array::{ArrayLength, GenericArray};
use cipher::{
generic_array::{typenum::Unsigned, ArrayLength, GenericArray},
BlockCipher, NewBlockCipher,
};

/// Trait for a block cipher mode of operation that is used to apply a block cipher
/// operation to input data to transform it into a variable-length output message.
Expand Down Expand Up @@ -34,7 +37,7 @@ where
return Err(InvalidKeyIvLength);
}
let iv = GenericArray::from_slice(iv);
let cipher = C::new_varkey(key).map_err(|_| InvalidKeyIvLength)?;
let cipher = C::new_var(key).map_err(|_| InvalidKeyIvLength)?;
Ok(Self::new(cipher, iv))
}

Expand Down
7 changes: 4 additions & 3 deletions block-modes/src/utils.rs
@@ -1,6 +1,7 @@
use cipher::block::{BlockCipher, NewBlockCipher};
use cipher::generic_array::typenum::Unsigned;
use cipher::generic_array::{ArrayLength, GenericArray};
use cipher::{
generic_array::{typenum::Unsigned, ArrayLength, GenericArray},
BlockCipher, NewBlockCipher,
};
use core::slice;

#[inline(always)]
Expand Down
4 changes: 2 additions & 2 deletions blowfish/Cargo.toml
Expand Up @@ -12,12 +12,12 @@ keywords = ["crypto", "blowfish", "block-cipher"]
categories = ["cryptography", "no-std"]

[dependencies]
cipher = "=0.3.0-pre"
cipher = "=0.3.0-pre.3"
byteorder = { version = "1", default-features = false }
opaque-debug = "0.3"

[dev-dependencies]
cipher = { version = "=0.3.0-pre", features = ["dev"] }
cipher = { version = "=0.3.0-pre.3", features = ["dev"] }

[features]
bcrypt = []
15 changes: 9 additions & 6 deletions blowfish/src/lib.rs
Expand Up @@ -11,9 +11,12 @@
pub use cipher;

use byteorder::{ByteOrder, BE, LE};
use cipher::block::{BlockCipher, BlockDecrypt, BlockEncrypt, InvalidKeyLength, NewBlockCipher};
use cipher::consts::{U1, U56, U8};
use cipher::generic_array::GenericArray;
use cipher::{
consts::{U1, U56, U8},
errors::InvalidLength,
generic_array::GenericArray,
BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher,
};
use core::marker::PhantomData;

mod consts;
Expand Down Expand Up @@ -110,12 +113,12 @@ impl<T: ByteOrder> NewBlockCipher for Blowfish<T> {
type KeySize = U56;

fn new(key: &GenericArray<u8, U56>) -> Self {
Self::new_varkey(&key).unwrap()
Self::new_var(&key).unwrap()
}

fn new_varkey(key: &[u8]) -> Result<Self, InvalidKeyLength> {
fn new_var(key: &[u8]) -> Result<Self, InvalidLength> {
if key.len() < 4 || key.len() > 56 {
return Err(InvalidKeyLength);
return Err(InvalidLength);
}
let mut blowfish = Blowfish::init_state();
blowfish.expand_key(key);
Expand Down
4 changes: 2 additions & 2 deletions cast5/Cargo.toml
Expand Up @@ -12,12 +12,12 @@ keywords = ["crypto", "cast5", "block-cipher"]
categories = ["cryptography", "no-std"]

[dependencies]
cipher = "=0.3.0-pre"
cipher = "=0.3.0-pre.3"
opaque-debug = "0.3"
byteorder = { version = "1", default-features = false }

[dev-dependencies]
cipher = { version = "=0.3.0-pre", features = ["dev"] }
cipher = { version = "=0.3.0-pre.3", features = ["dev"] }
hex-literal = "0.2"

[features]
Expand Down
9 changes: 5 additions & 4 deletions cast5/src/cast5.rs
@@ -1,10 +1,11 @@
use cipher::{
consts::{U1, U16, U8},
errors::InvalidLength,
generic_array::GenericArray,
BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher,
};

use byteorder::{BigEndian, ByteOrder};
use cipher::block::{BlockCipher, BlockDecrypt, BlockEncrypt, InvalidKeyLength, NewBlockCipher};

use crate::{
consts::{S1, S2, S3, S4},
Expand Down Expand Up @@ -86,13 +87,13 @@ impl NewBlockCipher for Cast5 {
type KeySize = U16;

fn new(key: &GenericArray<u8, U16>) -> Self {
Self::new_varkey(&key).unwrap()
Self::new_var(&key).unwrap()
}

fn new_varkey(key: &[u8]) -> Result<Self, InvalidKeyLength> {
fn new_var(key: &[u8]) -> Result<Self, InvalidLength> {
// Available key sizes are 40...128 bits.
if key.len() < 5 || key.len() > 16 {
return Err(InvalidKeyLength);
return Err(InvalidLength);
}
let mut cast5 = Cast5::init_state(key.len());

Expand Down

0 comments on commit 8712536

Please sign in to comment.