From 87125369b7a78a0b02219fe991a16cb65154df88 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Tue, 29 Dec 2020 21:09:30 -0800 Subject: [PATCH] Bump `cipher` crate to v0.3.0-pre.3 Implements the API changes introduced in: RustCrypto/traits#435 --- Cargo.lock | 8 ++++---- aes/Cargo.toml | 6 +++--- aes/src/autodetect.rs | 7 +++---- aes/src/ni/ctr.rs | 8 +++++--- aes/src/soft/ctr.rs | 8 +++++--- aes/tests/ctr.rs | 4 ++-- block-modes/Cargo.toml | 2 +- block-modes/src/cfb.rs | 15 +++++++++------ block-modes/src/cfb8.rs | 6 ++---- block-modes/src/ecb.rs | 20 +++++++++++++------- block-modes/src/ige.rs | 2 +- block-modes/src/ofb.rs | 9 +++++---- block-modes/src/pcbc.rs | 11 +++++++---- block-modes/src/traits.rs | 15 +++++++++------ block-modes/src/utils.rs | 7 ++++--- blowfish/Cargo.toml | 4 ++-- blowfish/src/lib.rs | 15 +++++++++------ cast5/Cargo.toml | 4 ++-- cast5/src/cast5.rs | 9 +++++---- cast5/tests/lib.rs | 9 ++++----- des/Cargo.toml | 4 ++-- gost-modes/Cargo.toml | 4 ++-- gost-modes/src/cbc.rs | 2 +- gost-modes/src/cfb.rs | 15 +++++++++------ gost-modes/src/ctr128.rs | 11 +++++------ gost-modes/src/ctr64.rs | 11 +++++------ gost-modes/src/lib.rs | 4 ++-- gost-modes/src/ofb.rs | 6 +++--- gost-modes/tests/lib.rs | 29 ++++++++++++++++++++++++++--- idea/Cargo.toml | 4 ++-- kuznyechik/Cargo.toml | 4 ++-- kuznyechik/tests/lib.rs | 5 ++--- magma/Cargo.toml | 4 ++-- rc2/Cargo.toml | 4 ++-- rc2/src/lib.rs | 9 +++++---- rc2/tests/lib.rs | 4 ++-- serpent/Cargo.toml | 4 ++-- serpent/src/lib.rs | 9 +++++---- sm4/Cargo.toml | 4 ++-- sm4/tests/lib.rs | 2 +- threefish/Cargo.toml | 4 ++-- twofish/Cargo.toml | 4 ++-- twofish/src/lib.rs | 9 +++++---- twofish/src/tests.rs | 6 +++--- twofish/tests/lib.rs | 5 ++--- 45 files changed, 191 insertions(+), 145 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 80983beb..96cde5cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,9 +66,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cipher" -version = "0.3.0-pre" +version = "0.3.0-pre.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42848bd4f28c6e74641082fc3ca870cb5381ce08d8715045cc96ff4ca20c0bbe" +checksum = "e067eaf9ba1497adc11bb7fb96c9aa4355ac978da0c384d27fc97866ea9e4c6b" dependencies = [ "blobby", "generic-array", @@ -82,9 +82,9 @@ checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" [[package]] name = "ctr" -version = "0.7.0-pre" +version = "0.7.0-pre.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c24c08075706da56b6eebe30dc3af9a842802dadd1f169651a8defd69852a4e6" +checksum = "f5dd7f3794a8f1f25789696c1586cb133bdd5a997317dfa464ecab45714eb98f" dependencies = [ "cipher", ] diff --git a/aes/Cargo.toml b/aes/Cargo.toml index fa876265..5e43faf0 100644 --- a/aes/Cargo.toml +++ b/aes/Cargo.toml @@ -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" diff --git a/aes/src/autodetect.rs b/aes/src/autodetect.rs index 86d40ca2..df4972b7 100644 --- a/aes/src/autodetect.rs +++ b/aes/src/autodetect.rs @@ -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, }, }; @@ -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 { @@ -175,7 +174,7 @@ pub(crate) mod ctr { } } - impl SyncStreamCipherSeek for $name { + impl StreamCipherSeek for $name { #[inline] fn try_current_pos(&self) -> Result { match &self.inner { diff --git a/aes/src/ni/ctr.rs b/aes/src/ni/ctr.rs index e72eecae..ce509ddb 100644 --- a/aes/src/ni/ctr.rs +++ b/aes/src/ni/ctr.rs @@ -1,5 +1,7 @@ //! AES in counter mode (a.k.a. AES-CTR) +// TODO(tarcieri): support generic CTR API + #![allow(clippy::unreadable_literal)] use super::arch::*; @@ -7,7 +9,7 @@ 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}; @@ -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> @@ -200,7 +202,7 @@ macro_rules! impl_ctr { } } - impl SyncStreamCipherSeek for $name { + impl StreamCipherSeek for $name { fn try_current_pos(&self) -> Result { T::from_block_byte(self.get_u64_ctr(), self.pos, BLOCK_SIZE as u8) } diff --git a/aes/src/soft/ctr.rs b/aes/src/soft/ctr.rs index e29c5b0d..a288ab11 100644 --- a/aes/src/soft/ctr.rs +++ b/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; +pub type Aes128Ctr = ::ctr::Ctr64BE; /// AES-192 in CTR mode #[cfg_attr(docsrs, doc(cfg(feature = "ctr")))] -pub type Aes192Ctr = ::ctr::Ctr128; +pub type Aes192Ctr = ::ctr::Ctr64BE; /// AES-256 in CTR mode #[cfg_attr(docsrs, doc(cfg(feature = "ctr")))] -pub type Aes256Ctr = ::ctr::Ctr128; +pub type Aes256Ctr = ::ctr::Ctr64BE; diff --git a/aes/tests/ctr.rs b/aes/tests/ctr.rs index 70a3f9f6..3fd3c9ef 100644 --- a/aes/tests/ctr.rs +++ b/aes/tests/ctr.rs @@ -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); diff --git a/block-modes/Cargo.toml b/block-modes/Cargo.toml index b9604db4..d4afd463 100644 --- a/block-modes/Cargo.toml +++ b/block-modes/Cargo.toml @@ -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" } diff --git a/block-modes/src/cfb.rs b/block-modes/src/cfb.rs index 7d79506f..10a85a19 100644 --- a/block-modes/src/cfb.rs +++ b/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. /// diff --git a/block-modes/src/cfb8.rs b/block-modes/src/cfb8.rs index 559a66f0..26bd9c2d 100644 --- a/block-modes/src/cfb8.rs +++ b/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. diff --git a/block-modes/src/ecb.rs b/block-modes/src/ecb.rs index 5e9d111a..b0566464 100644 --- a/block-modes/src/ecb.rs +++ b/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. @@ -34,7 +40,7 @@ where } fn new_var(key: &[u8], _iv: &[u8]) -> Result { - let cipher = C::new_varkey(key).map_err(|_| InvalidKeyIvLength)?; + let cipher = C::new_var(key).map_err(|_| InvalidKeyIvLength)?; Ok(Self { cipher, _p: Default::default(), diff --git a/block-modes/src/ige.rs b/block-modes/src/ige.rs index 5eba6b9e..1e56e828 100644 --- a/block-modes/src/ige.rs +++ b/block-modes/src/ige.rs @@ -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}; diff --git a/block-modes/src/ofb.rs b/block-modes/src/ofb.rs index 029c369c..1ea4755e 100644 --- a/block-modes/src/ofb.rs +++ b/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. diff --git a/block-modes/src/pcbc.rs b/block-modes/src/pcbc.rs index 8d4360ce..374e2f2d 100644 --- a/block-modes/src/pcbc.rs +++ b/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. diff --git a/block-modes/src/traits.rs b/block-modes/src/traits.rs index 228f00e1..ffb5fe32 100644 --- a/block-modes/src/traits.rs +++ b/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. @@ -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)) } diff --git a/block-modes/src/utils.rs b/block-modes/src/utils.rs index 812316a0..a16d2908 100644 --- a/block-modes/src/utils.rs +++ b/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)] diff --git a/blowfish/Cargo.toml b/blowfish/Cargo.toml index cd214fcd..b88e6447 100644 --- a/blowfish/Cargo.toml +++ b/blowfish/Cargo.toml @@ -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 = [] diff --git a/blowfish/src/lib.rs b/blowfish/src/lib.rs index f5ccfeab..75b06680 100644 --- a/blowfish/src/lib.rs +++ b/blowfish/src/lib.rs @@ -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; @@ -110,12 +113,12 @@ impl NewBlockCipher for Blowfish { type KeySize = U56; fn new(key: &GenericArray) -> Self { - Self::new_varkey(&key).unwrap() + Self::new_var(&key).unwrap() } - fn new_varkey(key: &[u8]) -> Result { + fn new_var(key: &[u8]) -> Result { if key.len() < 4 || key.len() > 56 { - return Err(InvalidKeyLength); + return Err(InvalidLength); } let mut blowfish = Blowfish::init_state(); blowfish.expand_key(key); diff --git a/cast5/Cargo.toml b/cast5/Cargo.toml index 3ac006a2..42a065d1 100644 --- a/cast5/Cargo.toml +++ b/cast5/Cargo.toml @@ -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] diff --git a/cast5/src/cast5.rs b/cast5/src/cast5.rs index 4bac043d..c3e5043d 100644 --- a/cast5/src/cast5.rs +++ b/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}, @@ -86,13 +87,13 @@ impl NewBlockCipher for Cast5 { type KeySize = U16; fn new(key: &GenericArray) -> Self { - Self::new_varkey(&key).unwrap() + Self::new_var(&key).unwrap() } - fn new_varkey(key: &[u8]) -> Result { + fn new_var(key: &[u8]) -> Result { // 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()); diff --git a/cast5/tests/lib.rs b/cast5/tests/lib.rs index 27fa7fed..9dcd658f 100644 --- a/cast5/tests/lib.rs +++ b/cast5/tests/lib.rs @@ -1,6 +1,5 @@ use cast5::Cast5; -use cipher::block::{BlockDecrypt, BlockEncrypt, NewBlockCipher}; -use cipher::generic_array::GenericArray; +use cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, NewBlockCipher}; use hex_literal::hex; /// Test vectors from RFC 2144 Appendix B.1 @@ -17,19 +16,19 @@ fn rfc2144_b1() { let mut buf = pt.clone(); - let c = Cast5::new_varkey(&key128).unwrap(); + let c = Cast5::new_var(&key128).unwrap(); c.encrypt_block(&mut buf); assert_eq!(buf, ct128); c.decrypt_block(&mut buf); assert_eq!(buf, pt); - let c = Cast5::new_varkey(&key80).unwrap(); + let c = Cast5::new_var(&key80).unwrap(); c.encrypt_block(&mut buf); assert_eq!(buf, ct80); c.decrypt_block(&mut buf); assert_eq!(buf, pt); - let c = Cast5::new_varkey(&key40).unwrap(); + let c = Cast5::new_var(&key40).unwrap(); c.encrypt_block(&mut buf); assert_eq!(buf, ct40); c.decrypt_block(&mut buf); diff --git a/des/Cargo.toml b/des/Cargo.toml index 4c9a824d..2986d4a3 100644 --- a/des/Cargo.toml +++ b/des/Cargo.toml @@ -12,9 +12,9 @@ keywords = ["crypto", "des", "tdes", "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"] } diff --git a/gost-modes/Cargo.toml b/gost-modes/Cargo.toml index 730b7165..10a751d2 100644 --- a/gost-modes/Cargo.toml +++ b/gost-modes/Cargo.toml @@ -12,13 +12,13 @@ keywords = ["crypto", "block-cipher", "ciphers"] [dependencies] block-modes = { version = "=0.8.0-pre", path = "../block-modes", default-features = false } -cipher = { version = "=0.3.0-pre", default-features = false } +cipher = { version = "=0.3.0-pre.3", default-features = false } generic-array = "0.14" [dev-dependencies] kuznyechik = { version = "=0.7.0-pre", path = "../kuznyechik" } magma = { version = "=0.7.0-pre", path = "../magma" } -cipher = { version = "=0.3.0-pre", features = ["dev"] } +cipher = { version = "=0.3.0-pre.3", features = ["dev"] } hex-literal = "0.2" [features] diff --git a/gost-modes/src/cbc.rs b/gost-modes/src/cbc.rs index 04605d55..c11678b1 100644 --- a/gost-modes/src/cbc.rs +++ b/gost-modes/src/cbc.rs @@ -1,6 +1,6 @@ use crate::{utils::xor, GostPadding}; use block_modes::{block_padding::Padding, BlockMode}; -use cipher::block::{Block, BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher}; +use cipher::{Block, BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher}; use core::{marker::PhantomData, ops::Mul}; use generic_array::typenum::{ type_operators::{IsGreater, IsLessOrEqual}, diff --git a/gost-modes/src/cfb.rs b/gost-modes/src/cfb.rs index 7e30da20..bfadf9d7 100644 --- a/gost-modes/src/cfb.rs +++ b/gost-modes/src/cfb.rs @@ -1,12 +1,15 @@ use crate::utils::{xor_set1, xor_set2}; use cipher::{ - block::{Block, BlockCipher, BlockEncrypt, NewBlockCipher}, - stream::{FromBlockCipher, StreamCipher}, + AsyncStreamCipher, Block, BlockCipher, BlockEncrypt, FromBlockCipher, NewBlockCipher, }; use core::ops::Sub; -use generic_array::typenum::type_operators::{IsGreater, IsGreaterOrEqual, IsLessOrEqual}; -use generic_array::typenum::{Diff, Unsigned, U0, U255}; -use generic_array::{ArrayLength, GenericArray}; +use generic_array::{ + typenum::{ + type_operators::{IsGreater, IsGreaterOrEqual, IsLessOrEqual}, + Diff, Unsigned, U0, U255, + }, + ArrayLength, GenericArray, +}; type BlockSize = ::BlockSize; @@ -90,7 +93,7 @@ where } } -impl StreamCipher for GostCfb +impl AsyncStreamCipher for GostCfb where C: BlockCipher + BlockEncrypt + NewBlockCipher, C::BlockSize: IsLessOrEqual, diff --git a/gost-modes/src/ctr128.rs b/gost-modes/src/ctr128.rs index f346a8d3..cb48de53 100644 --- a/gost-modes/src/ctr128.rs +++ b/gost-modes/src/ctr128.rs @@ -1,9 +1,8 @@ use crate::utils::xor; use cipher::{ - block::{Block, BlockCipher, BlockEncrypt, NewBlockCipher}, - stream::{ - FromBlockCipher, LoopError, OverflowError, SeekNum, SyncStreamCipher, SyncStreamCipherSeek, - }, + errors::{LoopError, OverflowError}, + Block, BlockCipher, BlockEncrypt, FromBlockCipher, NewBlockCipher, SeekNum, StreamCipher, + StreamCipherSeek, }; use generic_array::typenum::{ type_operators::{IsGreater, IsLessOrEqual}, @@ -68,7 +67,7 @@ where } } -impl SyncStreamCipher for GostCtr128 +impl StreamCipher for GostCtr128 where C: BlockCipher + BlockEncrypt + NewBlockCipher, C::ParBlocks: ArrayLength>, @@ -110,7 +109,7 @@ where } } -impl SyncStreamCipherSeek for GostCtr128 +impl StreamCipherSeek for GostCtr128 where C: BlockCipher + BlockEncrypt + NewBlockCipher, C::ParBlocks: ArrayLength>, diff --git a/gost-modes/src/ctr64.rs b/gost-modes/src/ctr64.rs index e1034e67..302d4fbf 100644 --- a/gost-modes/src/ctr64.rs +++ b/gost-modes/src/ctr64.rs @@ -1,9 +1,8 @@ use crate::utils::xor; use cipher::{ - block::{Block, BlockCipher, BlockEncrypt, NewBlockCipher}, - stream::{ - FromBlockCipher, LoopError, OverflowError, SeekNum, SyncStreamCipher, SyncStreamCipherSeek, - }, + errors::{LoopError, OverflowError}, + Block, BlockCipher, BlockEncrypt, FromBlockCipher, NewBlockCipher, SeekNum, StreamCipher, + StreamCipherSeek, }; use generic_array::typenum::{ type_operators::{IsGreater, IsLessOrEqual}, @@ -68,7 +67,7 @@ where } } -impl SyncStreamCipher for GostCtr64 +impl StreamCipher for GostCtr64 where C: BlockCipher + BlockEncrypt + NewBlockCipher, C::ParBlocks: ArrayLength>, @@ -110,7 +109,7 @@ where } } -impl SyncStreamCipherSeek for GostCtr64 +impl StreamCipherSeek for GostCtr64 where C: BlockCipher + BlockEncrypt + NewBlockCipher, C::ParBlocks: ArrayLength>, diff --git a/gost-modes/src/lib.rs b/gost-modes/src/lib.rs index e3012866..ab36683d 100644 --- a/gost-modes/src/lib.rs +++ b/gost-modes/src/lib.rs @@ -32,7 +32,7 @@ //! assert_eq!(buf, &pt[..]); //! //! // OFB mode example -//! use gost_modes::{GostOfb, SyncStreamCipher, NewStreamCipher}; +//! use gost_modes::{GostOfb, StreamCipher, NewCipher}; //! //! let mut cipher = GostOfb::::new_var(&key, &iv).unwrap(); //! let mut buf = pt.to_vec(); @@ -58,7 +58,7 @@ pub use cipher::{self, consts}; pub use generic_array; pub use block_modes::{BlockMode, Ecb}; -pub use cipher::stream::{NewStreamCipher, StreamCipher, SyncStreamCipher, SyncStreamCipherSeek}; +pub use cipher::{AsyncStreamCipher, NewCipher, StreamCipher, StreamCipherSeek}; mod cbc; mod cfb; diff --git a/gost-modes/src/ofb.rs b/gost-modes/src/ofb.rs index 739d2565..c3dfcc16 100644 --- a/gost-modes/src/ofb.rs +++ b/gost-modes/src/ofb.rs @@ -1,7 +1,7 @@ use crate::utils::xor; use cipher::{ - block::{Block, BlockCipher, BlockEncrypt, NewBlockCipher}, - stream::{FromBlockCipher, LoopError, SyncStreamCipher}, + errors::LoopError, Block, BlockCipher, BlockEncrypt, FromBlockCipher, NewBlockCipher, + StreamCipher, }; use core::{marker::PhantomData, ops::Mul}; use generic_array::typenum::{ @@ -65,7 +65,7 @@ where } } -impl SyncStreamCipher for GostOfb +impl StreamCipher for GostOfb where C: BlockCipher + BlockEncrypt + NewBlockCipher, C::BlockSize: IsLessOrEqual, diff --git a/gost-modes/tests/lib.rs b/gost-modes/tests/lib.rs index ec6cf07d..c73fe2e7 100644 --- a/gost-modes/tests/lib.rs +++ b/gost-modes/tests/lib.rs @@ -5,7 +5,7 @@ use gost_modes::{ block_padding::ZeroPadding, consts::{U14, U16, U2, U3, U32, U5}, generic_array::GenericArray, - BlockMode, Ecb, GostCbc, GostCfb, GostCtr128, GostCtr64, GostOfb, NewStreamCipher, + AsyncStreamCipher, BlockMode, Ecb, GostCbc, GostCfb, GostCtr128, GostCtr64, GostOfb, NewCipher, StreamCipher, }; use hex_literal::hex; @@ -13,6 +13,29 @@ use kuznyechik::Kuznyechik; use magma::{cipher::NewBlockCipher, Magma}; fn test_stream_cipher(cipher: impl StreamCipher + Clone, pt: &[u8], ct: &[u8]) { + let mut buf = pt.to_vec(); + cipher.clone().apply_keystream(&mut buf); + assert_eq!(buf, &ct[..]); + cipher.clone().apply_keystream(&mut buf); + assert_eq!(buf, &pt[..]); + + for i in 1..32 { + let mut c = cipher.clone(); + let mut buf = pt.to_vec(); + for chunk in buf.chunks_mut(i) { + c.apply_keystream(chunk); + } + assert_eq!(buf, &ct[..]); + + let mut c = cipher.clone(); + for chunk in buf.chunks_mut(i) { + c.apply_keystream(chunk); + } + assert_eq!(buf, &pt[..]); + } +} + +fn test_async_stream_cipher(cipher: impl AsyncStreamCipher + Clone, pt: &[u8], ct: &[u8]) { let mut buf = pt.to_vec(); cipher.clone().encrypt(&mut buf); assert_eq!(buf, &ct[..]); @@ -90,7 +113,7 @@ fn kuznyechik_modes() { test_stream_cipher(c, &pt, &ofb_ct); let c = GostCfb::::new(&key, &iv); - test_stream_cipher(c, &pt, &cfb_ct); + test_async_stream_cipher(c, &pt, &cfb_ct); let c = GostCtr128::::new(&key, &ctr_iv); test_stream_cipher(c, &pt, &ctr_ct); @@ -157,7 +180,7 @@ fn magma_modes() { test_stream_cipher(c, &pt, &ofb_ct); let c = GostCfb::::new(&key, &iv); - test_stream_cipher(c, &pt, &cfb_ct); + test_async_stream_cipher(c, &pt, &cfb_ct); let c = GostCtr64::::new(&key, &ctr_iv); test_stream_cipher(c, &pt, &ctr_ct); diff --git a/idea/Cargo.toml b/idea/Cargo.toml index 2163ea98..7ea5c39f 100644 --- a/idea/Cargo.toml +++ b/idea/Cargo.toml @@ -12,8 +12,8 @@ keywords = ["crypto", "idea", "block-cipher"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "=0.3.0-pre" +cipher = "=0.3.0-pre.3" opaque-debug = "0.3" [dev-dependencies] -cipher = { version = "=0.3.0-pre", features = ["dev"] } +cipher = { version = "=0.3.0-pre.3", features = ["dev"] } diff --git a/kuznyechik/Cargo.toml b/kuznyechik/Cargo.toml index 013461f4..f307de8e 100644 --- a/kuznyechik/Cargo.toml +++ b/kuznyechik/Cargo.toml @@ -12,11 +12,11 @@ keywords = ["crypto", "kuznyechik", "gost", "block-cipher"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "=0.3.0-pre" +cipher = "=0.3.0-pre.3" opaque-debug = "0.3" [dev-dependencies] -cipher = { version = "=0.3.0-pre", features = ["dev"] } +cipher = { version = "=0.3.0-pre.3", features = ["dev"] } hex-literal = "0.2" [features] diff --git a/kuznyechik/tests/lib.rs b/kuznyechik/tests/lib.rs index 44c0963c..f41e682c 100644 --- a/kuznyechik/tests/lib.rs +++ b/kuznyechik/tests/lib.rs @@ -1,7 +1,6 @@ #![cfg_attr(rustfmt, rustfmt_skip)] -use cipher::generic_array::GenericArray; -use cipher::block::{BlockEncrypt, BlockDecrypt, NewBlockCipher}; +use cipher::{generic_array::GenericArray, BlockEncrypt, BlockDecrypt, NewBlockCipher}; use hex_literal::hex; /// Example vectors from GOST 34.12-2018 @@ -14,7 +13,7 @@ fn kuznyechik() { let plaintext = hex!("1122334455667700FFEEDDCCBBAA9988"); let ciphertext = hex!("7F679D90BEBC24305a468d42b9d4EDCD"); - let state = kuznyechik::Kuznyechik::new_varkey(&key).unwrap(); + let state = kuznyechik::Kuznyechik::new_var(&key).unwrap(); let mut block = GenericArray::clone_from_slice(&plaintext); state.encrypt_block(&mut block); diff --git a/magma/Cargo.toml b/magma/Cargo.toml index 0e51dd51..02819970 100644 --- a/magma/Cargo.toml +++ b/magma/Cargo.toml @@ -12,9 +12,9 @@ keywords = ["crypto", "magma", "gost", "block-cipher"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "=0.3.0-pre" +cipher = "=0.3.0-pre.3" opaque-debug = "0.3" [dev-dependencies] -cipher = { version = "=0.3.0-pre", features = ["dev"] } +cipher = { version = "=0.3.0-pre.3", features = ["dev"] } hex-literal = "0.2" diff --git a/rc2/Cargo.toml b/rc2/Cargo.toml index 912929b4..4192aeea 100644 --- a/rc2/Cargo.toml +++ b/rc2/Cargo.toml @@ -12,8 +12,8 @@ keywords = ["crypto", "rc2", "block-cipher"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "=0.3.0-pre" +cipher = "=0.3.0-pre.3" opaque-debug = "0.3" [dev-dependencies] -cipher = { version = "=0.3.0-pre", features = ["dev"] } +cipher = { version = "=0.3.0-pre.3", features = ["dev"] } diff --git a/rc2/src/lib.rs b/rc2/src/lib.rs index 8c40f9ad..9968d2b2 100644 --- a/rc2/src/lib.rs +++ b/rc2/src/lib.rs @@ -13,9 +13,10 @@ pub use cipher; use cipher::{ - block::{BlockCipher, BlockDecrypt, BlockEncrypt, InvalidKeyLength, NewBlockCipher}, consts::{U1, U32, U8}, + errors::InvalidLength, generic_array::GenericArray, + BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher, }; mod consts; @@ -197,12 +198,12 @@ impl NewBlockCipher for Rc2 { type KeySize = U32; fn new(key: &GenericArray) -> Self { - Self::new_varkey(key).unwrap() + Self::new_var(key).unwrap() } - fn new_varkey(key: &[u8]) -> Result { + fn new_var(key: &[u8]) -> Result { if key.is_empty() || key.len() > 128 { - Err(InvalidKeyLength) + Err(InvalidLength) } else { Ok(Self::new_with_eff_key_len(key, key.len() * 8)) } diff --git a/rc2/tests/lib.rs b/rc2/tests/lib.rs index d950ea70..d5bde0d6 100644 --- a/rc2/tests/lib.rs +++ b/rc2/tests/lib.rs @@ -1,5 +1,5 @@ -use cipher::block::{BlockDecrypt, BlockEncrypt, NewBlockCipher}; use cipher::generic_array::GenericArray; +use cipher::{BlockDecrypt, BlockEncrypt, NewBlockCipher}; struct Test { key: &'static [u8], @@ -24,7 +24,7 @@ macro_rules! new_tests { fn rc2() { let tests = new_tests!("1", "2", "3", "7"); for test in &tests { - let cipher = rc2::Rc2::new_varkey(&test.key).unwrap(); + let cipher = rc2::Rc2::new_var(&test.key).unwrap(); let mut buf = GenericArray::clone_from_slice(test.input); cipher.encrypt_block(&mut buf); diff --git a/serpent/Cargo.toml b/serpent/Cargo.toml index 37f727ef..310bdb0a 100644 --- a/serpent/Cargo.toml +++ b/serpent/Cargo.toml @@ -13,8 +13,8 @@ categories = ["cryptography", "no-std"] [dependencies] byteorder = { version = "1", default-features = false } -cipher = "=0.3.0-pre" +cipher = "=0.3.0-pre.3" opaque-debug = "0.3" [dev-dependencies] -cipher = { version = "=0.3.0-pre", features = ["dev"] } +cipher = { version = "=0.3.0-pre.3", features = ["dev"] } diff --git a/serpent/src/lib.rs b/serpent/src/lib.rs index 16116cfa..8674bda1 100644 --- a/serpent/src/lib.rs +++ b/serpent/src/lib.rs @@ -17,9 +17,10 @@ pub use cipher; use byteorder::{ByteOrder, LE}; use cipher::{ - block::{BlockCipher, BlockDecrypt, BlockEncrypt, InvalidKeyLength, NewBlockCipher}, consts::{U1, U16}, + errors::InvalidLength, generic_array::GenericArray, + BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher, }; mod consts; @@ -236,12 +237,12 @@ impl NewBlockCipher for Serpent { type KeySize = U16; fn new(key: &GenericArray) -> Self { - Self::new_varkey(key).unwrap() + Self::new_var(key).unwrap() } - fn new_varkey(key: &[u8]) -> Result { + fn new_var(key: &[u8]) -> Result { if key.len() < 16 || key.len() > 32 { - return Err(InvalidKeyLength); + return Err(InvalidLength); } let mut k = [0u8; 32]; expand_key(key, key.len() * 8, &mut k); diff --git a/sm4/Cargo.toml b/sm4/Cargo.toml index 83c7e51d..40651787 100644 --- a/sm4/Cargo.toml +++ b/sm4/Cargo.toml @@ -12,10 +12,10 @@ keywords = ["crypto", "sm4", "block-cipher"] categories = ["cryptography"] [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"] } hex-literal = "0.2" diff --git a/sm4/tests/lib.rs b/sm4/tests/lib.rs index 1ea03a66..56212949 100644 --- a/sm4/tests/lib.rs +++ b/sm4/tests/lib.rs @@ -1,6 +1,6 @@ //! Test vectors are from GM/T 0002-2012 -use cipher::block::{BlockDecrypt, BlockEncrypt, NewBlockCipher}; +use cipher::{BlockDecrypt, BlockEncrypt, NewBlockCipher}; use hex_literal::hex; use sm4::Sm4; diff --git a/threefish/Cargo.toml b/threefish/Cargo.toml index f7ed4415..ad03a483 100644 --- a/threefish/Cargo.toml +++ b/threefish/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/RustCrypto/block-ciphers" keywords = ["crypto", "threefish", "gost", "block-cipher"] [dependencies] -cipher = "=0.3.0-pre" +cipher = "=0.3.0-pre.3" [dev-dependencies] -cipher = { version = "=0.3.0-pre", features = ["dev"] } +cipher = { version = "=0.3.0-pre.3", features = ["dev"] } diff --git a/twofish/Cargo.toml b/twofish/Cargo.toml index beb2f07f..c747bac1 100644 --- a/twofish/Cargo.toml +++ b/twofish/Cargo.toml @@ -13,9 +13,9 @@ categories = ["cryptography", "no-std"] [dependencies] byteorder = { version = "1", default-features = false } -cipher = "=0.3.0-pre" +cipher = "=0.3.0-pre.3" opaque-debug = "0.3" [dev-dependencies] -cipher = { version = "=0.3.0-pre", features = ["dev"] } +cipher = { version = "=0.3.0-pre.3", features = ["dev"] } hex-literal = "0.2" diff --git a/twofish/src/lib.rs b/twofish/src/lib.rs index c9aaa8bd..7a484582 100644 --- a/twofish/src/lib.rs +++ b/twofish/src/lib.rs @@ -13,9 +13,10 @@ pub use cipher; use byteorder::{ByteOrder, LE}; use cipher::{ - block::{BlockCipher, BlockDecrypt, BlockEncrypt, InvalidKeyLength, NewBlockCipher}, consts::{U1, U16, U32}, + errors::InvalidLength, generic_array::GenericArray, + BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher, }; mod consts; @@ -164,13 +165,13 @@ impl NewBlockCipher for Twofish { type KeySize = U32; fn new(key: &GenericArray) -> Self { - Self::new_varkey(key).unwrap() + Self::new_var(key).unwrap() } - fn new_varkey(key: &[u8]) -> Result { + fn new_var(key: &[u8]) -> Result { let n = key.len(); if n != 16 && n != 24 && n != 32 { - return Err(InvalidKeyLength); + return Err(InvalidLength); } let mut twofish = Self { s: [0u8; 16], diff --git a/twofish/src/tests.rs b/twofish/src/tests.rs index 85ddfd3c..af118696 100644 --- a/twofish/src/tests.rs +++ b/twofish/src/tests.rs @@ -3,7 +3,7 @@ use super::*; #[test] fn intermediate128() { let key = [0u8; 16]; - let twofish = Twofish::new_varkey(&key).unwrap(); + let twofish = Twofish::new_var(&key).unwrap(); let subkeys: [u32; 40] = [ 0x52C54DDE, 0x11F0626D, 0x7CAC9D4A, 0x4D1B4AAA, 0xB7B83A10, 0x1E7D0BEB, 0xEE9C341F, 0xCFE14BE4, 0xF98FFEF9, 0x9C5B3C17, 0x15A48310, 0x342A4D81, 0x424D89FE, 0xC14724A7, @@ -21,7 +21,7 @@ fn intermediate192() { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, ]; - let twofish = Twofish::new_varkey(&key).unwrap(); + let twofish = Twofish::new_var(&key).unwrap(); let sboxkey: [u8; 12] = [ 0xf2, 0xf6, 0x9f, 0xb8, 0x4b, 0xbc, 0x55, 0xb2, 0x61, 0x10, 0x66, 0x45, ]; @@ -44,7 +44,7 @@ fn intermediate256() { 0x10, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, ]; - let twofish = Twofish::new_varkey(&key).unwrap(); + let twofish = Twofish::new_var(&key).unwrap(); let sboxkey: [u8; 16] = [ 0xf2, 0xf6, 0x9f, 0xb8, 0x4b, 0xbc, 0x55, 0xb2, 0x61, 0x10, 0x66, 0x45, 0xf7, 0x47, 0x44, 0x8e, diff --git a/twofish/tests/lib.rs b/twofish/tests/lib.rs index 89f5a0f8..d80421ed 100644 --- a/twofish/tests/lib.rs +++ b/twofish/tests/lib.rs @@ -1,5 +1,4 @@ -use cipher::block::{BlockDecrypt, BlockEncrypt, NewBlockCipher}; -use cipher::generic_array::GenericArray; +use cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, NewBlockCipher}; use hex_literal::hex; use twofish::Twofish; @@ -16,7 +15,7 @@ macro_rules! new_test { let mut cipher; for i in 1..50 { - let twofish = Twofish::new_varkey(&key).unwrap(); + let twofish = Twofish::new_var(&key).unwrap(); let mut buf = plain.clone(); twofish.encrypt_block(&mut buf);