From 3a53d4172a4aa6cf05cfbe455ea851d8072f05d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Fri, 27 Oct 2023 14:59:03 +0300 Subject: [PATCH 1/5] Update Cargo.lock --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3534ed18..27022521 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,9 +48,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" dependencies = [ "libc", ] From 47813cebe2ed4405d3c058146f913e9648e4a382 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Jan 2024 06:13:10 -0700 Subject: [PATCH 2/5] build(deps): bump cpufeatures from 0.2.11 to 0.2.12 (#337) Bumps [cpufeatures](https://github.com/RustCrypto/utils) from 0.2.11 to 0.2.12. - [Commits](https://github.com/RustCrypto/utils/compare/cpufeatures-v0.2.11...cpufeatures-v0.2.12) --- updated-dependencies: - dependency-name: cpufeatures dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27022521..896d1d50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,9 +48,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] From a8463f2031213f4f53cfbfbe55c0550ce0f223ab Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Sun, 7 Jan 2024 13:25:29 -0300 Subject: [PATCH 3/5] salsa20: SSE2 backend (#328) Provides a ~14% performance improvement --- Cargo.lock | 1 + salsa20/Cargo.toml | 1 + salsa20/src/backends.rs | 20 +++++ salsa20/src/backends/soft.rs | 70 ++++++++++++++++ salsa20/src/backends/sse2.rs | 156 +++++++++++++++++++++++++++++++++++ salsa20/src/lib.rs | 121 ++++++++++++--------------- salsa20/src/xsalsa.rs | 17 +++- 7 files changed, 316 insertions(+), 70 deletions(-) create mode 100644 salsa20/src/backends.rs create mode 100644 salsa20/src/backends/soft.rs create mode 100644 salsa20/src/backends/sse2.rs diff --git a/Cargo.lock b/Cargo.lock index 896d1d50..412659af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,6 +125,7 @@ dependencies = [ name = "salsa20" version = "0.10.2" dependencies = [ + "cfg-if", "cipher", "hex-literal", ] diff --git a/salsa20/Cargo.toml b/salsa20/Cargo.toml index 8feda050..f5068c0b 100644 --- a/salsa20/Cargo.toml +++ b/salsa20/Cargo.toml @@ -13,6 +13,7 @@ keywords = ["crypto", "stream-cipher", "trait", "xsalsa20"] categories = ["cryptography", "no-std"] [dependencies] +cfg-if = "1" cipher = "0.4.4" [dev-dependencies] diff --git a/salsa20/src/backends.rs b/salsa20/src/backends.rs new file mode 100644 index 00000000..49f13ee5 --- /dev/null +++ b/salsa20/src/backends.rs @@ -0,0 +1,20 @@ +use cfg_if::cfg_if; + +cfg_if! { + if #[cfg(salsa20_force_soft)] { + pub(crate) mod soft; + } else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { + cfg_if! { + if #[cfg(salsa20_force_sse2)] { + pub(crate) mod sse2; + } else if #[cfg(salsa20_force_soft)] { + pub(crate) mod soft; + } else { + pub(crate) mod sse2; + pub(crate) mod soft; + } + } + } else { + pub(crate) mod soft; + } +} diff --git a/salsa20/src/backends/soft.rs b/salsa20/src/backends/soft.rs new file mode 100644 index 00000000..c7c2a91c --- /dev/null +++ b/salsa20/src/backends/soft.rs @@ -0,0 +1,70 @@ +//! Portable implementation which does not rely on architecture-specific +//! intrinsics. + +use crate::{Block, SalsaCore, Unsigned, STATE_WORDS}; +use cipher::{ + consts::{U1, U64}, + BlockSizeUser, ParBlocksSizeUser, StreamBackend, StreamCipherSeekCore, +}; + +pub(crate) struct Backend<'a, R: Unsigned>(pub(crate) &'a mut SalsaCore); + +impl<'a, R: Unsigned> BlockSizeUser for Backend<'a, R> { + type BlockSize = U64; +} + +impl<'a, R: Unsigned> ParBlocksSizeUser for Backend<'a, R> { + type ParBlocksSize = U1; +} + +impl<'a, R: Unsigned> StreamBackend for Backend<'a, R> { + #[inline(always)] + fn gen_ks_block(&mut self, block: &mut Block) { + let res = run_rounds::(&self.0.state); + + self.0.set_block_pos(self.0.get_block_pos() + 1); + + for (chunk, val) in block.chunks_exact_mut(4).zip(res.iter()) { + chunk.copy_from_slice(&val.to_le_bytes()); + } + } +} + +#[inline] +#[allow(clippy::many_single_char_names)] +pub(crate) fn quarter_round( + a: usize, + b: usize, + c: usize, + d: usize, + state: &mut [u32; STATE_WORDS], +) { + state[b] ^= state[a].wrapping_add(state[d]).rotate_left(7); + state[c] ^= state[b].wrapping_add(state[a]).rotate_left(9); + state[d] ^= state[c].wrapping_add(state[b]).rotate_left(13); + state[a] ^= state[d].wrapping_add(state[c]).rotate_left(18); +} + +#[inline(always)] +fn run_rounds(state: &[u32; STATE_WORDS]) -> [u32; STATE_WORDS] { + let mut res = *state; + + for _ in 0..R::USIZE { + // column rounds + quarter_round(0, 4, 8, 12, &mut res); + quarter_round(5, 9, 13, 1, &mut res); + quarter_round(10, 14, 2, 6, &mut res); + quarter_round(15, 3, 7, 11, &mut res); + + // diagonal rounds + quarter_round(0, 1, 2, 3, &mut res); + quarter_round(5, 6, 7, 4, &mut res); + quarter_round(10, 11, 8, 9, &mut res); + quarter_round(15, 12, 13, 14, &mut res); + } + + for (s1, s0) in res.iter_mut().zip(state.iter()) { + *s1 = s1.wrapping_add(*s0); + } + res +} diff --git a/salsa20/src/backends/sse2.rs b/salsa20/src/backends/sse2.rs new file mode 100644 index 00000000..3e0199a8 --- /dev/null +++ b/salsa20/src/backends/sse2.rs @@ -0,0 +1,156 @@ +use crate::{Block, StreamClosure, Unsigned, STATE_WORDS}; +use cipher::{ + consts::{U1, U64}, + BlockSizeUser, ParBlocksSizeUser, StreamBackend, +}; +use core::marker::PhantomData; + +#[cfg(target_arch = "x86")] +use core::arch::x86::*; +#[cfg(target_arch = "x86_64")] +use core::arch::x86_64::*; + +#[inline] +#[target_feature(enable = "sse2")] +pub(crate) unsafe fn inner(state: &mut [u32; STATE_WORDS], f: F) +where + R: Unsigned, + F: StreamClosure, +{ + let state_ptr = state.as_ptr() as *const __m128i; + let mut backend = Backend:: { + v: [ + _mm_loadu_si128(state_ptr.add(0)), + _mm_loadu_si128(state_ptr.add(1)), + _mm_loadu_si128(state_ptr.add(2)), + _mm_loadu_si128(state_ptr.add(3)), + ], + _pd: PhantomData, + }; + + f.call(&mut backend); + + state[8] = _mm_cvtsi128_si32(backend.v[2]) as u32; +} + +struct Backend { + v: [__m128i; 4], + _pd: PhantomData, +} + +impl BlockSizeUser for Backend { + type BlockSize = U64; +} + +impl ParBlocksSizeUser for Backend { + type ParBlocksSize = U1; +} + +impl StreamBackend for Backend { + #[inline(always)] + fn gen_ks_block(&mut self, block: &mut Block) { + unsafe { + let res = rounds::(&self.v); + + self.v[2] = _mm_add_epi32(self.v[2], _mm_set_epi32(0, 0, 0, 1)); + let block_ptr = block.as_mut_ptr() as *mut __m128i; + + for (i, v) in res.iter().enumerate() { + _mm_storeu_si128(block_ptr.add(i), *v); + } + } + } +} + +#[inline] +#[target_feature(enable = "sse2")] +unsafe fn rounds(v: &[__m128i; 4]) -> [__m128i; 4] { + let mut res = *v; + + for _ in 0..R::USIZE { + double_round(&mut res); + } + + for i in 0..4 { + res[i] = _mm_add_epi32(res[i], v[i]); + } + + transpose(&mut res); + res[1] = _mm_shuffle_epi32(res[1], 0b_10_01_00_11); + res[2] = _mm_shuffle_epi32(res[2], 0b_01_00_11_10); + res[3] = _mm_shuffle_epi32(res[3], 0b_00_11_10_01); + transpose(&mut res); + + res +} + +/// The Salsa20 doubleround function for SSE2. +/// +/// https://users.rust-lang.org/t/can-the-compiler-infer-sse-instructions/59976 +#[inline] +#[target_feature(enable = "sse2")] +unsafe fn double_round([a, b, c, d]: &mut [__m128i; 4]) { + let mut t_sum: __m128i; + let mut t_rotl: __m128i; + + // Operate on "columns" + t_sum = _mm_add_epi32(*a, *d); + t_rotl = _mm_xor_si128(_mm_slli_epi32(t_sum, 7), _mm_srli_epi32(t_sum, 25)); + *b = _mm_xor_si128(*b, t_rotl); + + t_sum = _mm_add_epi32(*b, *a); + t_rotl = _mm_xor_si128(_mm_slli_epi32(t_sum, 9), _mm_srli_epi32(t_sum, 23)); + *c = _mm_xor_si128(*c, t_rotl); + + t_sum = _mm_add_epi32(*c, *b); + t_rotl = _mm_xor_si128(_mm_slli_epi32(t_sum, 13), _mm_srli_epi32(t_sum, 19)); + *d = _mm_xor_si128(*d, t_rotl); + + t_sum = _mm_add_epi32(*d, *c); + t_rotl = _mm_xor_si128(_mm_slli_epi32(t_sum, 18), _mm_srli_epi32(t_sum, 14)); + *a = _mm_xor_si128(*a, t_rotl); + + // Rearrange data. + *b = _mm_shuffle_epi32(*b, 0b_10_01_00_11); + *c = _mm_shuffle_epi32(*c, 0b_01_00_11_10); + *d = _mm_shuffle_epi32(*d, 0b_00_11_10_01); + + // Operate on "rows". + t_sum = _mm_add_epi32(*a, *b); + t_rotl = _mm_xor_si128(_mm_slli_epi32(t_sum, 7), _mm_srli_epi32(t_sum, 25)); + *d = _mm_xor_si128(*d, t_rotl); + + t_sum = _mm_add_epi32(*d, *a); + t_rotl = _mm_xor_si128(_mm_slli_epi32(t_sum, 9), _mm_srli_epi32(t_sum, 23)); + *c = _mm_xor_si128(*c, t_rotl); + + t_sum = _mm_add_epi32(*c, *d); + t_rotl = _mm_xor_si128(_mm_slli_epi32(t_sum, 13), _mm_srli_epi32(t_sum, 19)); + *b = _mm_xor_si128(*b, t_rotl); + + t_sum = _mm_add_epi32(*b, *c); + t_rotl = _mm_xor_si128(_mm_slli_epi32(t_sum, 18), _mm_srli_epi32(t_sum, 14)); + *a = _mm_xor_si128(*a, t_rotl); + + // Rearrange data. + *b = _mm_shuffle_epi32(*b, 0b_00_11_10_01); + *c = _mm_shuffle_epi32(*c, 0b_01_00_11_10); + *d = _mm_shuffle_epi32(*d, 0b_10_01_00_11); +} + +/// Transpose an integer 4 by 4 matrix in SSE2. +/// +/// https://randombit.net/bitbashing/posts/integer_matrix_transpose_in_sse2.html +#[inline] +#[target_feature(enable = "sse2")] +unsafe fn transpose([a, b, c, d]: &mut [__m128i; 4]) { + let t0 = _mm_unpacklo_epi32(*a, *b); + let t1 = _mm_unpacklo_epi32(*c, *d); + let t2 = _mm_unpackhi_epi32(*a, *b); + let t3 = _mm_unpackhi_epi32(*c, *d); + + *a = _mm_unpacklo_epi64(t0, t1); + *b = _mm_unpackhi_epi64(t0, t1); + *c = _mm_unpacklo_epi64(t2, t3); + *d = _mm_unpackhi_epi64(t2, t3); +} diff --git a/salsa20/src/lib.rs b/salsa20/src/lib.rs index df4771ef..81d83ee0 100644 --- a/salsa20/src/lib.rs +++ b/salsa20/src/lib.rs @@ -61,6 +61,21 @@ //! assert_eq!(buffer, ciphertext); //! ``` //! +//! # Configuration Flags +//! +//! You can modify crate using the following configuration flags: +//! +//! - `salsa20_force_soft`: force software backend. +//! - `salsa20_force_sse2`: force SSE2 backend on x86/x86_64 targets. +//! Requires enabled SSE2 target feature. Ignored on non-x86(-64) targets. +//! +//! Salsa20 will run the SSE2 backend in x86(-64) targets unless `salsa20_force_soft` is set. +//! +//! The flags can be enabled using `RUSTFLAGS` environmental variable +//! (e.g. `RUSTFLAGS="--cfg salsa20_force_sse2"`) or by modifying `.cargo/config`. +//! +//! You SHOULD NOT enable several `force` flags simultaneously. +//! //! [Salsa]: https://en.wikipedia.org/wiki/Salsa20 #![no_std] @@ -70,22 +85,23 @@ html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", html_root_url = "https://docs.rs/salsa20/0.10.2" )] -#![forbid(unsafe_code)] #![warn(missing_docs, rust_2018_idioms, trivial_casts, unused_qualifications)] +use cfg_if::cfg_if; pub use cipher; use cipher::{ - consts::{U1, U10, U24, U32, U4, U6, U64, U8}, + consts::{U10, U24, U32, U4, U6, U64, U8}, generic_array::{typenum::Unsigned, GenericArray}, - Block, BlockSizeUser, IvSizeUser, KeyIvInit, KeySizeUser, ParBlocksSizeUser, StreamBackend, - StreamCipherCore, StreamCipherCoreWrapper, StreamCipherSeekCore, StreamClosure, + Block, BlockSizeUser, IvSizeUser, KeyIvInit, KeySizeUser, StreamCipherCore, + StreamCipherCoreWrapper, StreamCipherSeekCore, StreamClosure, }; use core::marker::PhantomData; #[cfg(feature = "zeroize")] use cipher::zeroize::{Zeroize, ZeroizeOnDrop}; +mod backends; mod xsalsa; pub use xsalsa::{hsalsa, XSalsa12, XSalsa20, XSalsa8, XSalsaCore}; @@ -175,6 +191,19 @@ impl KeyIvInit for SalsaCore { state[15] = CONSTANTS[3]; + cfg_if! { + if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { + #[cfg(not(salsa20_force_soft))] { + state = [ + state[0], state[5], state[10], state[15], + state[4], state[9], state[14], state[3], + state[8], state[13], state[2], state[7], + state[12], state[1], state[6], state[11], + ]; + } + } + } + Self { state, rounds: PhantomData, @@ -189,7 +218,23 @@ impl StreamCipherCore for SalsaCore { rem.try_into().ok() } fn process_with_backend(&mut self, f: impl StreamClosure) { - f.call(&mut Backend(self)); + cfg_if! { + if #[cfg(salsa20_force_soft)] { + f.call(&mut backends::soft::Backend(self)); + } else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { + cfg_if! { + if #[cfg(not(salsa20_force_soft))] { + unsafe { + backends::sse2::inner::(&mut self.state, f); + } + } else { + f.call(&mut backends::soft::Backend(self)); + } + } + } else { + f.call(&mut backends::soft::Backend(self)); + } + } } } @@ -198,13 +243,12 @@ impl StreamCipherSeekCore for SalsaCore { #[inline(always)] fn get_block_pos(&self) -> u64 { - (self.state[8] as u64) + ((self.state[9] as u64) << 32) + self.state[8] as u64 } #[inline(always)] fn set_block_pos(&mut self, pos: u64) { - self.state[8] = (pos & 0xffff_ffff) as u32; - self.state[9] = ((pos >> 32) & 0xffff_ffff) as u32; + self.state[8] = pos as u32; } } @@ -219,64 +263,3 @@ impl Drop for SalsaCore { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] impl ZeroizeOnDrop for SalsaCore {} - -struct Backend<'a, R: Unsigned>(&'a mut SalsaCore); - -impl<'a, R: Unsigned> BlockSizeUser for Backend<'a, R> { - type BlockSize = U64; -} - -impl<'a, R: Unsigned> ParBlocksSizeUser for Backend<'a, R> { - type ParBlocksSize = U1; -} - -impl<'a, R: Unsigned> StreamBackend for Backend<'a, R> { - #[inline(always)] - fn gen_ks_block(&mut self, block: &mut Block) { - let res = run_rounds::(&self.0.state); - self.0.set_block_pos(self.0.get_block_pos() + 1); - - for (chunk, val) in block.chunks_exact_mut(4).zip(res.iter()) { - chunk.copy_from_slice(&val.to_le_bytes()); - } - } -} - -#[inline] -#[allow(clippy::many_single_char_names)] -pub(crate) fn quarter_round( - a: usize, - b: usize, - c: usize, - d: usize, - state: &mut [u32; STATE_WORDS], -) { - state[b] ^= state[a].wrapping_add(state[d]).rotate_left(7); - state[c] ^= state[b].wrapping_add(state[a]).rotate_left(9); - state[d] ^= state[c].wrapping_add(state[b]).rotate_left(13); - state[a] ^= state[d].wrapping_add(state[c]).rotate_left(18); -} - -#[inline(always)] -fn run_rounds(state: &[u32; STATE_WORDS]) -> [u32; STATE_WORDS] { - let mut res = *state; - - for _ in 0..R::USIZE { - // column rounds - quarter_round(0, 4, 8, 12, &mut res); - quarter_round(5, 9, 13, 1, &mut res); - quarter_round(10, 14, 2, 6, &mut res); - quarter_round(15, 3, 7, 11, &mut res); - - // diagonal rounds - quarter_round(0, 1, 2, 3, &mut res); - quarter_round(5, 6, 7, 4, &mut res); - quarter_round(10, 11, 8, 9, &mut res); - quarter_round(15, 12, 13, 14, &mut res); - } - - for (s1, s0) in res.iter_mut().zip(state.iter()) { - *s1 = s1.wrapping_add(*s0); - } - res -} diff --git a/salsa20/src/xsalsa.rs b/salsa20/src/xsalsa.rs index 42ce4f34..ba99b547 100644 --- a/salsa20/src/xsalsa.rs +++ b/salsa20/src/xsalsa.rs @@ -1,6 +1,6 @@ //! XSalsa20 is an extended nonce variant of Salsa20 -use super::{quarter_round, Key, Nonce, SalsaCore, Unsigned, XNonce, CONSTANTS}; +use super::{Key, Nonce, SalsaCore, Unsigned, XNonce, CONSTANTS, STATE_WORDS}; use cipher::{ consts::{U10, U16, U24, U32, U4, U6, U64}, generic_array::GenericArray, @@ -136,3 +136,18 @@ pub fn hsalsa(key: &Key, input: &GenericArray) -> GenericA output } + +/// The Salsa20 quarter round function +// for simplicity this function is copied from the software backend +pub(crate) fn quarter_round( + a: usize, + b: usize, + c: usize, + d: usize, + state: &mut [u32; STATE_WORDS], +) { + state[b] ^= state[a].wrapping_add(state[d]).rotate_left(7); + state[c] ^= state[b].wrapping_add(state[a]).rotate_left(9); + state[d] ^= state[c].wrapping_add(state[b]).rotate_left(13); + state[a] ^= state[d].wrapping_add(state[c]).rotate_left(18); +} From 4b63ec34415aa8370acd45b857b83e14a651875c Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sun, 7 Jan 2024 16:19:10 -0700 Subject: [PATCH 4/5] Bump `cipher` to v0.5.0-pre.1; MSRV 1.65 (#338) This also bumps all of the crate versions to prereleases to denote the breaking change, however they will not have associated releases. The main change in this prerelease of `cipher` is a migration from `generic-array` to `hybrid-array`. --- .github/workflows/chacha20.yml | 22 +++++----- .github/workflows/hc-256.yml | 4 +- .github/workflows/rabbit.yml | 4 +- .github/workflows/rc4.yml | 4 +- .github/workflows/salsa20.yml | 4 +- Cargo.lock | 78 +++++++++++++++++++++------------- Cargo.toml | 1 + README.md | 12 +++--- benches/Cargo.toml | 2 +- chacha20/Cargo.toml | 10 ++--- chacha20/README.md | 4 +- chacha20/src/legacy.rs | 4 +- chacha20/src/lib.rs | 11 ++--- chacha20/src/xchacha.rs | 15 +++---- hc-256/Cargo.toml | 10 ++--- hc-256/README.md | 4 +- hc-256/src/lib.rs | 5 +-- rabbit/Cargo.toml | 10 ++--- rabbit/README.md | 4 +- rabbit/src/lib.rs | 5 +-- rc4/Cargo.toml | 8 ++-- rc4/README.md | 4 +- rc4/src/lib.rs | 14 +++--- rc4/tests/lib.rs | 28 ++++++------ salsa20/Cargo.toml | 10 ++--- salsa20/README.md | 4 +- salsa20/src/lib.rs | 10 ++--- salsa20/src/xsalsa.rs | 8 ++-- 28 files changed, 158 insertions(+), 141 deletions(-) diff --git a/.github/workflows/chacha20.yml b/.github/workflows/chacha20.yml index a82523b1..e4a42d46 100644 --- a/.github/workflows/chacha20.yml +++ b/.github/workflows/chacha20.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -53,7 +53,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -61,7 +61,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable steps: @@ -86,7 +86,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -94,7 +94,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable steps: @@ -119,7 +119,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -127,7 +127,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable steps: @@ -152,7 +152,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -160,7 +160,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable steps: @@ -182,7 +182,7 @@ jobs: include: # ARM64 - target: aarch64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV - target: aarch64-unknown-linux-gnu rust: stable @@ -193,7 +193,7 @@ jobs: # PPC32 - target: powerpc-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV - target: powerpc-unknown-linux-gnu rust: stable diff --git a/.github/workflows/hc-256.yml b/.github/workflows/hc-256.yml index 90fd93ee..69435441 100644 --- a/.github/workflows/hc-256.yml +++ b/.github/workflows/hc-256.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -48,7 +48,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/rabbit.yml b/.github/workflows/rabbit.yml index 714adeca..ecdfef8f 100644 --- a/.github/workflows/rabbit.yml +++ b/.github/workflows/rabbit.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -47,7 +47,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/rc4.yml b/.github/workflows/rc4.yml index ddb29ef1..121fb67e 100644 --- a/.github/workflows/rc4.yml +++ b/.github/workflows/rc4.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -47,7 +47,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/salsa20.yml b/.github/workflows/salsa20.yml index 87ebbeff..8253e68c 100644 --- a/.github/workflows/salsa20.yml +++ b/.github/workflows/salsa20.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -47,7 +47,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/Cargo.lock b/Cargo.lock index 412659af..3cde1a2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,11 +11,11 @@ checksum = "847495c209977a90e8aad588b959d0ca9f5dc228096d29a6bd3defd53f35eaec" [[package]] name = "block-padding" -version = "0.3.3" +version = "0.4.0-pre.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93" +checksum = "d07a359e2b51a0e9b9d6a6d4582b7b62723e4a25f4e5ca6be70a6a00050202ab" dependencies = [ - "generic-array", + "hybrid-array", ] [[package]] @@ -26,7 +26,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chacha20" -version = "0.9.1" +version = "0.10.0-pre" dependencies = [ "cfg-if", "cipher", @@ -36,9 +36,9 @@ dependencies = [ [[package]] name = "cipher" -version = "0.4.4" +version = "0.5.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +checksum = "15e338a2ceb7493b9b89d12728c6feb2d4b61708cb63b577c556c92f43aef0cd" dependencies = [ "blobby", "crypto-common", @@ -57,27 +57,29 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.6" +version = "0.2.0-pre.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "cc17eb697364b18256ec92675ebe6b7b153d2f1041e568d74533c5d0fc1ca162" dependencies = [ - "generic-array", - "typenum", + "getrandom", + "hybrid-array", + "rand_core", ] [[package]] -name = "generic-array" -version = "0.14.7" +name = "getrandom" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" dependencies = [ - "typenum", - "version_check", + "cfg-if", + "libc", + "wasi", ] [[package]] name = "hc-256" -version = "0.5.0" +version = "0.6.0-pre" dependencies = [ "cipher", "hex-literal", @@ -85,18 +87,27 @@ dependencies = [ [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "hybrid-array" +version = "0.2.0-pre.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27fbaf242418fe980caf09ed348d5a6aeabe71fc1bd8bebad641f4591ae0a46d" +dependencies = [ + "typenum", +] [[package]] name = "inout" -version = "0.1.3" +version = "0.2.0-pre.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +checksum = "96ea9986e1fde8d177cd039f00f9f316d3bfce9ebc2787c1267d4414adf3acb3" dependencies = [ "block-padding", - "generic-array", + "hybrid-array", ] [[package]] @@ -107,15 +118,24 @@ checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "rabbit" -version = "0.4.1" +version = "0.5.0-pre" dependencies = [ "cipher", "hex-literal", ] +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "rc4" -version = "0.1.0" +version = "0.2.0-pre" dependencies = [ "cipher", "hex-literal", @@ -123,7 +143,7 @@ dependencies = [ [[package]] name = "salsa20" -version = "0.10.2" +version = "0.11.0-pre" dependencies = [ "cfg-if", "cipher", @@ -137,13 +157,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] -name = "version_check" -version = "0.9.4" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "zeroize" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/Cargo.toml b/Cargo.toml index 3ed45d2e..26910c8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "2" members = [ "chacha20", "hc-256", diff --git a/README.md b/README.md index 4fde8164..849f0355 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,11 @@ received any formal cryptographic and security reviews/audits. ## Crates | Name | Crate name | Crates.io | Docs | MSRV | Security | |----------|------------|-----------|------|------|----------| -| [ChaCha] | [`chacha20`] | [![crates.io](https://img.shields.io/crates/v/chacha20.svg)](https://crates.io/crates/chacha20) | [![Documentation](https://docs.rs/chacha20/badge.svg)](https://docs.rs/chacha20) | ![MSRV 1.56][msrv-1.56] | 💚 | -| [HC-256] | [`hc-256`] | [![crates.io](https://img.shields.io/crates/v/hc-256.svg)](https://crates.io/crates/hc-256) | [![Documentation](https://docs.rs/hc-256/badge.svg)](https://docs.rs/hc-256) | ![MSRV 1.56][msrv-1.56] | [💛](https://link.springer.com/chapter/10.1007/978-3-642-04846-3_4) | -| [Rabbit] | [`rabbit`] | [![crates.io](https://img.shields.io/crates/v/rabbit.svg)](https://crates.io/crates/rabbit) | [![Documentation](https://docs.rs/rabbit/badge.svg)](https://docs.rs/rabbit) | ![MSRV 1.56][msrv-1.56] | [💛](https://eprint.iacr.org/2013/780.pdf) | -| [RC4] | [`rc4`] | [![crates.io](https://img.shields.io/crates/v/rc4.svg)](https://crates.io/crates/rc4) | [![Documentation](https://docs.rs/rc4/badge.svg)](https://docs.rs/rc4) | ![MSRV 1.56][msrv-1.56] | [💔](https://www.usenix.org/system/files/conference/usenixsecurity13/sec13-paper_alfardan.pdf) | -| [Salsa20] | [`salsa20`] | [![crates.io](https://img.shields.io/crates/v/salsa20.svg)](https://crates.io/crates/salsa20) | [![Documentation](https://docs.rs/salsa20/badge.svg)](https://docs.rs/salsa20) | ![MSRV 1.56][msrv-1.56] | 💚 | +| [ChaCha] | [`chacha20`] | [![crates.io](https://img.shields.io/crates/v/chacha20.svg)](https://crates.io/crates/chacha20) | [![Documentation](https://docs.rs/chacha20/badge.svg)](https://docs.rs/chacha20) | ![MSRV 1.65][msrv-1.65] | 💚 | +| [HC-256] | [`hc-256`] | [![crates.io](https://img.shields.io/crates/v/hc-256.svg)](https://crates.io/crates/hc-256) | [![Documentation](https://docs.rs/hc-256/badge.svg)](https://docs.rs/hc-256) | ![MSRV 1.65][msrv-1.65] | [💛](https://link.springer.com/chapter/10.1007/978-3-642-04846-3_4) | +| [Rabbit] | [`rabbit`] | [![crates.io](https://img.shields.io/crates/v/rabbit.svg)](https://crates.io/crates/rabbit) | [![Documentation](https://docs.rs/rabbit/badge.svg)](https://docs.rs/rabbit) | ![MSRV 1.65][msrv-1.65] | [💛](https://eprint.iacr.org/2013/780.pdf) | +| [RC4] | [`rc4`] | [![crates.io](https://img.shields.io/crates/v/rc4.svg)](https://crates.io/crates/rc4) | [![Documentation](https://docs.rs/rc4/badge.svg)](https://docs.rs/rc4) | ![MSRV 1.65][msrv-1.65] | [💔](https://www.usenix.org/system/files/conference/usenixsecurity13/sec13-paper_alfardan.pdf) | +| [Salsa20] | [`salsa20`] | [![crates.io](https://img.shields.io/crates/v/salsa20.svg)](https://crates.io/crates/salsa20) | [![Documentation](https://docs.rs/salsa20/badge.svg)](https://docs.rs/salsa20) | ![MSRV 1.65][msrv-1.65] | 💚 | ### Security Level Legend @@ -107,7 +107,7 @@ Unless you explicitly state otherwise, any contribution intentionally submitted [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md -[msrv-1.56]: https://img.shields.io/badge/rustc-1.56.0+-blue.svg +[msrv-1.65]: https://img.shields.io/badge/rustc-1.65.0+-blue.svg [//]: # (footnotes) diff --git a/benches/Cargo.toml b/benches/Cargo.toml index aba16fbb..bcb000e2 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -4,7 +4,7 @@ version = "0.0.0" authors = ["RustCrypto Developers"] license = "Apache-2.0 OR MIT" description = "Criterion benchmarks of the stream-cipher crates" -edition = "2018" +edition = "2021" publish = false [workspace] diff --git a/chacha20/Cargo.toml b/chacha20/Cargo.toml index 9ba590d6..d33b7473 100644 --- a/chacha20/Cargo.toml +++ b/chacha20/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chacha20" -version = "0.9.1" +version = "0.10.0-pre" description = """ The ChaCha20 stream cipher (RFC 8439) implemented in pure Rust using traits from the RustCrypto `cipher` crate, with optional architecture-specific @@ -11,7 +11,7 @@ rand_core-compatible RNGs based on those ciphers. authors = ["RustCrypto Developers"] license = "Apache-2.0 OR MIT" edition = "2021" -rust-version = "1.56" +rust-version = "1.65" readme = "README.md" documentation = "https://docs.rs/chacha20" repository = "https://github.com/RustCrypto/stream-ciphers" @@ -20,14 +20,14 @@ categories = ["cryptography", "no-std"] [dependencies] cfg-if = "1" -cipher = "0.4.4" +cipher = "=0.5.0-pre.1" [target.'cfg(any(target_arch = "x86_64", target_arch = "x86"))'.dependencies] cpufeatures = "0.2" [dev-dependencies] -cipher = { version = "0.4.4", features = ["dev"] } -hex-literal = "0.3.3" +cipher = { version = "=0.5.0-pre.1", features = ["dev"] } +hex-literal = "0.4" [features] std = ["cipher/std"] diff --git a/chacha20/README.md b/chacha20/README.md index 2ff7d5bb..d2c3e933 100644 --- a/chacha20/README.md +++ b/chacha20/README.md @@ -64,7 +64,7 @@ stream cipher itself) are designed to execute in constant time. ## Minimum Supported Rust Version -Rust **1.56** or higher. +Rust **1.65** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -96,7 +96,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/chacha20/badge.svg [docs-link]: https://docs.rs/chacha20/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260049-stream-ciphers [build-image]: https://github.com/RustCrypto/stream-ciphers/workflows/chacha20/badge.svg?branch=master&event=push diff --git a/chacha20/src/legacy.rs b/chacha20/src/legacy.rs index 2541079c..e0b85f47 100644 --- a/chacha20/src/legacy.rs +++ b/chacha20/src/legacy.rs @@ -2,8 +2,8 @@ use super::{ChaChaCore, Key, Nonce}; use cipher::{ + array::Array, consts::{U10, U32, U64, U8}, - generic_array::GenericArray, BlockSizeUser, IvSizeUser, KeyIvInit, KeySizeUser, StreamCipherCore, StreamCipherCoreWrapper, StreamCipherSeekCore, StreamClosure, }; @@ -12,7 +12,7 @@ use cipher::{ use cipher::zeroize::ZeroizeOnDrop; /// Nonce type used by [`ChaCha20Legacy`]. -pub type LegacyNonce = GenericArray; +pub type LegacyNonce = Array; /// The ChaCha20 stream cipher (legacy "djb" construction with 64-bit nonce). /// diff --git a/chacha20/src/lib.rs b/chacha20/src/lib.rs index c5bc22aa..1716f60c 100644 --- a/chacha20/src/lib.rs +++ b/chacha20/src/lib.rs @@ -52,7 +52,7 @@ //! let plaintext = hex!("00010203 04050607 08090A0B 0C0D0E0F"); //! let ciphertext = hex!("e405626e 4f1236b3 670ee428 332ea20e"); //! -//! // Key and IV must be references to the `GenericArray` type. +//! // Key and IV must be references to the `Array` type. //! // Here we use the `Into` trait to convert arrays into it. //! let mut cipher = ChaCha20::new(&key.into(), &nonce.into()); //! @@ -113,8 +113,8 @@ pub use cipher; use cfg_if::cfg_if; use cipher::{ + array::{typenum::Unsigned, Array}, consts::{U10, U12, U32, U4, U6, U64}, - generic_array::{typenum::Unsigned, GenericArray}, BlockSizeUser, IvSizeUser, KeyIvInit, KeySizeUser, StreamCipherCore, StreamCipherCoreWrapper, StreamCipherSeekCore, StreamClosure, }; @@ -137,13 +137,13 @@ const CONSTANTS: [u32; 4] = [0x6170_7865, 0x3320_646e, 0x7962_2d32, 0x6b20_6574] const STATE_WORDS: usize = 16; /// Block type used by all ChaCha variants. -type Block = GenericArray; +type Block = Array; /// Key type used by all ChaCha variants. -pub type Key = GenericArray; +pub type Key = Array; /// Nonce type used by ChaCha variants. -pub type Nonce = GenericArray; +pub type Nonce = Array; /// ChaCha8 stream cipher (reduced-round variant of [`ChaCha20`] with 8 rounds) pub type ChaCha8 = StreamCipherCoreWrapper>; @@ -205,6 +205,7 @@ impl BlockSizeUser for ChaChaCore { impl KeyIvInit for ChaChaCore { #[inline] + #[allow(clippy::let_unit_value)] fn new(key: &Key, iv: &Nonce) -> Self { let mut state = [0u32; STATE_WORDS]; state[0..4].copy_from_slice(&CONSTANTS); diff --git a/chacha20/src/xchacha.rs b/chacha20/src/xchacha.rs index ad33bd04..46b9c653 100644 --- a/chacha20/src/xchacha.rs +++ b/chacha20/src/xchacha.rs @@ -2,8 +2,8 @@ use super::{ChaChaCore, Key, Nonce, CONSTANTS, STATE_WORDS}; use cipher::{ + array::{typenum::Unsigned, Array}, consts::{U10, U16, U24, U32, U4, U6, U64}, - generic_array::{typenum::Unsigned, GenericArray}, BlockSizeUser, IvSizeUser, KeyIvInit, KeySizeUser, StreamCipherCore, StreamCipherCoreWrapper, StreamCipherSeekCore, StreamClosure, }; @@ -12,7 +12,7 @@ use cipher::{ use cipher::zeroize::ZeroizeOnDrop; /// Nonce type used by XChaCha variants. -pub type XNonce = GenericArray; +pub type XNonce = Array; /// XChaCha is a ChaCha20 variant with an extended 192-bit (24-byte) nonce. /// @@ -52,7 +52,7 @@ impl BlockSizeUser for XChaChaCore { impl KeyIvInit for XChaChaCore { fn new(key: &Key, iv: &XNonce) -> Self { - let subkey = hchacha::(key, iv[..16].as_ref().into()); + let subkey = hchacha::(key, iv[..16].try_into().unwrap()); let mut padded_iv = Nonce::default(); padded_iv[4..].copy_from_slice(&iv[16..]); XChaChaCore(ChaChaCore::new(&subkey, &padded_iv)) @@ -103,7 +103,7 @@ impl ZeroizeOnDrop for XChaChaCore {} /// For more information on HSalsa on which HChaCha is based, see: /// /// -pub fn hchacha(key: &Key, input: &GenericArray) -> GenericArray { +pub fn hchacha(key: &Key, input: &Array) -> Array { let mut state = [0u32; STATE_WORDS]; state[..4].copy_from_slice(&CONSTANTS); @@ -131,7 +131,7 @@ pub fn hchacha(key: &Key, input: &GenericArray) -> Generic quarter_round(3, 4, 9, 14, &mut state); } - let mut output = GenericArray::default(); + let mut output = Array::default(); for (chunk, val) in output[..16].chunks_exact_mut(4).zip(&state[..4]) { chunk.copy_from_slice(&val.to_le_bytes()); @@ -185,10 +185,7 @@ mod hchacha20_tests { "a0f9e4d58a74a853c12ec41326d3ecdc" ); - let actual = hchacha::( - GenericArray::from_slice(&KEY), - GenericArray::from_slice(&INPUT), - ); + let actual = hchacha::(Array::ref_from_slice(&KEY), Array::ref_from_slice(&INPUT)); assert_eq!(actual.as_slice(), &OUTPUT); } } diff --git a/hc-256/Cargo.toml b/hc-256/Cargo.toml index 434d75d9..00dea615 100644 --- a/hc-256/Cargo.toml +++ b/hc-256/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "hc-256" -version = "0.5.0" # Also update html_root_url in lib.rs when bumping this +version = "0.6.0-pre" description = "HC-256 Stream Cipher" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.56" +rust-version = "1.65" readme = "README.md" documentation = "https://docs.rs/hc-256" repository = "https://github.com/RustCrypto/stream-ciphers" @@ -13,11 +13,11 @@ keywords = ["crypto", "stream-cipher", "trait"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "0.4.4" +cipher = "=0.5.0-pre.1" [dev-dependencies] -cipher = { version = "0.4.4", features = ["dev"] } -hex-literal = "0.3.3" +cipher = { version = "=0.5.0-pre.1", features = ["dev"] } +hex-literal = "0.4" [features] std = ["cipher/std"] diff --git a/hc-256/README.md b/hc-256/README.md index 14d3d91a..091d09df 100644 --- a/hc-256/README.md +++ b/hc-256/README.md @@ -26,7 +26,7 @@ USE AT YOUR OWN RISK! ## Minimum Supported Rust Version -Rust **1.56** or higher. +Rust **1.65** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -58,7 +58,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/hc-256/badge.svg [docs-link]: https://docs.rs/hc-256/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md [build-image]: https://github.com/RustCrypto/stream-ciphers/workflows/hc-256/badge.svg?branch=master&event=push diff --git a/hc-256/src/lib.rs b/hc-256/src/lib.rs index 0d8b45a3..d2511833 100644 --- a/hc-256/src/lib.rs +++ b/hc-256/src/lib.rs @@ -21,7 +21,7 @@ //! let plaintext = hex!("00010203 04050607 08090A0B 0C0D0E0F"); //! let ciphertext = hex!("ca982177 325cd40e bc208045 066c420f"); //! -//! // Key and IV must be references to the `GenericArray` type. +//! // Key and IV must be references to the `Array` type. //! // Here we use the `Into` trait to convert arrays into it. //! let mut cipher = Hc256::new(&key.into(), &nonce.into()); //! @@ -52,8 +52,7 @@ #![cfg_attr(docsrs, feature(doc_cfg))] #![doc( html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", - html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", - html_root_url = "https://docs.rs/hc-256/0.5.0" + html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg" )] #![forbid(unsafe_code)] #![warn(missing_docs, rust_2018_idioms)] diff --git a/rabbit/Cargo.toml b/rabbit/Cargo.toml index ad2d3c34..537659e8 100644 --- a/rabbit/Cargo.toml +++ b/rabbit/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "rabbit" -version = "0.4.1" # Also update html_root_url in lib.rs when bumping this +version = "0.5.0-pre" description = "An implementation of the Rabbit Stream Cipher Algorithm" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.56" +rust-version = "1.65" readme = "README.md" documentation = "https://docs.rs/rabbit" repository = "https://github.com/RustCrypto/stream-ciphers" @@ -13,11 +13,11 @@ keywords = ["crypto", "rabbit", "stream-cipher", "trait"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "0.4.4" +cipher = "=0.5.0-pre.1" [dev-dependencies] -cipher = { version = "0.4.4", features = ["dev"] } -hex-literal = "0.3.3" +cipher = { version = "=0.5.0-pre.1", features = ["dev"] } +hex-literal = "0.4" [features] std = ["cipher/std"] diff --git a/rabbit/README.md b/rabbit/README.md index 5342cd46..d85999c6 100644 --- a/rabbit/README.md +++ b/rabbit/README.md @@ -26,7 +26,7 @@ architectures. ## Minimum Supported Rust Version -Rust **1.56** or higher. +Rust **1.65** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -58,7 +58,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/rabbit/badge.svg [docs-link]: https://docs.rs/rabbit/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260049-stream-ciphers [build-image]: https://github.com/RustCrypto/stream-ciphers/workflows/rabbit/badge.svg?branch=master&event=push diff --git a/rabbit/src/lib.rs b/rabbit/src/lib.rs index 635c02a2..bab00d08 100644 --- a/rabbit/src/lib.rs +++ b/rabbit/src/lib.rs @@ -21,7 +21,7 @@ //! let plaintext = hex!("00010203 04050607 08090A0B 0C0D0E0F"); //! let ciphertext = hex!("10298496 ceda18ee 0e257cbb 1ab43bcc"); //! -//! // Key and IV must be references to the `GenericArray` type. +//! // Key and IV must be references to the `Array` type. //! // Here we use the `Into` trait to convert arrays into it. //! let mut cipher = Rabbit::new(&key.into(), &nonce.into()); //! @@ -52,8 +52,7 @@ #![cfg_attr(docsrs, feature(doc_cfg))] #![doc( html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", - html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", - html_root_url = "https://docs.rs/rabbit/0.4.1" + html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg" )] #![deny(unsafe_code)] #![warn(missing_docs, rust_2018_idioms)] diff --git a/rc4/Cargo.toml b/rc4/Cargo.toml index 3ecbae70..62497e62 100644 --- a/rc4/Cargo.toml +++ b/rc4/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "rc4" -version = "0.1.0" +version = "0.2.0-pre" description = "Pure Rust implementation of the RC4 stream cipher" authors = ["The Rust-Crypto Project Developers"] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.56" +rust-version = "1.65" readme = "README.md" documentation = "https://docs.rs/rc4" repository = "https://github.com/RustCrypto/stream-ciphers" @@ -13,10 +13,10 @@ keywords = ["arc4", "arcfour", "crypto", "stream-cipher", "trait"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "0.4.4" +cipher = "=0.5.0-pre.1" [dev-dependencies] -hex-literal = "0.3" +hex-literal = "0.4" [features] std = ["cipher/std"] diff --git a/rc4/README.md b/rc4/README.md index a26e660e..a4bc6c7d 100644 --- a/rc4/README.md +++ b/rc4/README.md @@ -28,7 +28,7 @@ relied on for security/confidentiality. ## Minimum Supported Rust Version -Rust **1.56** or higher. +Rust **1.65** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -60,7 +60,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/rc4/badge.svg [docs-link]: https://docs.rs/rc4/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260049-stream-ciphers [build-image]: https://github.com/RustCrypto/stream-ciphers/actions/workflows/rc4.yml/badge.svg diff --git a/rc4/src/lib.rs b/rc4/src/lib.rs index 9c28e1b7..6e4005b9 100644 --- a/rc4/src/lib.rs +++ b/rc4/src/lib.rs @@ -25,7 +25,7 @@ //! rc4.apply_keystream(&mut data); //! assert_eq!(data, [0x10, 0x21, 0xBF, 0x04, 0x20]); //! -//! let key = Key::::from_slice(b"Secret"); +//! let key = Key::::ref_from_slice(b"Secret"); //! let mut rc4 = Rc4::<_>::new(key); //! let mut data = b"Attack at dawn".to_vec(); //! rc4.apply_keystream(&mut data); @@ -38,7 +38,7 @@ pub use cipher::{self, consts, KeyInit, StreamCipher}; use cipher::{ - generic_array::{ArrayLength, GenericArray}, + array::{Array, ArraySize}, Block, BlockSizeUser, KeySizeUser, ParBlocksSizeUser, StreamBackend, StreamCipherCore, StreamCipherCoreWrapper, StreamClosure, }; @@ -50,8 +50,8 @@ use cipher::zeroize::{Zeroize, ZeroizeOnDrop}; /// RC4 key type (8–2048 bits/ 1-256 bytes) /// -/// Implemented as an alias for [`GenericArray`]. -pub type Key = GenericArray; +/// Implemented as an alias for [`Array`]. +pub type Key = Array; type BlockSize = consts::U1; @@ -67,14 +67,14 @@ pub struct Rc4Core { impl KeySizeUser for Rc4Core where - KeySize: ArrayLength, + KeySize: ArraySize, { type KeySize = KeySize; } impl KeyInit for Rc4Core where - KeySize: ArrayLength, + KeySize: ArraySize, { fn new(key: &Key) -> Self { Self { @@ -101,7 +101,7 @@ impl StreamCipherCore for Rc4Core { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl ZeroizeOnDrop for Rc4Core where KeySize: ArrayLength {} +impl ZeroizeOnDrop for Rc4Core where KeySize: ArraySize {} struct Backend<'a>(&'a mut Rc4State); diff --git a/rc4/tests/lib.rs b/rc4/tests/lib.rs index 92b44fee..894b9121 100644 --- a/rc4/tests/lib.rs +++ b/rc4/tests/lib.rs @@ -32,7 +32,7 @@ fn test_rfc6229_length_40_bits_key1() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -74,7 +74,7 @@ fn test_rfc6229_length_56_bits_key1() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -116,7 +116,7 @@ fn test_rfc6229_length_64_bits_key1() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -158,7 +158,7 @@ fn test_rfc6229_length_80_bits_key1() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -201,7 +201,7 @@ fn test_rfc6229_length_128_bits_key1() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -243,7 +243,7 @@ fn test_rfc6229_length_192_bits_key1() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -286,7 +286,7 @@ fn test_rfc6229_length_256_bits_key1() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -328,7 +328,7 @@ fn test_rfc6229_length_40_bits_key2() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -370,7 +370,7 @@ fn test_rfc6229_length_56_bits_key2() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -412,7 +412,7 @@ fn test_rfc6229_length_64_bits_key2() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -454,7 +454,7 @@ fn test_rfc6229_length_80_bits_key2() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -497,7 +497,7 @@ fn test_rfc6229_length_128_bits_key2() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -539,7 +539,7 @@ fn test_rfc6229_length_192_bits_key2() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -582,7 +582,7 @@ fn test_rfc6229_length_256_bits_key2() { " ); - let key = Key::::from_slice(&KEY); + let key = Key::::ref_from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; diff --git a/salsa20/Cargo.toml b/salsa20/Cargo.toml index f5068c0b..965e34b1 100644 --- a/salsa20/Cargo.toml +++ b/salsa20/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "salsa20" -version = "0.10.2" # Also update html_root_url in lib.rs when bumping this +version = "0.11.0-pre" # Also update html_root_url in lib.rs when bumping this description = "Salsa20 Stream Cipher" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.56" +rust-version = "1.65" readme = "README.md" documentation = "https://docs.rs/salsa20" repository = "https://github.com/RustCrypto/stream-ciphers" @@ -14,11 +14,11 @@ categories = ["cryptography", "no-std"] [dependencies] cfg-if = "1" -cipher = "0.4.4" +cipher = "=0.5.0-pre.1" [dev-dependencies] -cipher = { version = "0.4.4", features = ["dev"] } -hex-literal = "0.3.3" +cipher = { version = "=0.5.0-pre.1", features = ["dev"] } +hex-literal = "0.4" [features] std = ["cipher/std"] diff --git a/salsa20/README.md b/salsa20/README.md index 68e89494..828fbaba 100644 --- a/salsa20/README.md +++ b/salsa20/README.md @@ -37,7 +37,7 @@ USE AT YOUR OWN RISK! ## Minimum Supported Rust Version -Rust **1.56** or higher. +Rust **1.65** or higher. Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump. @@ -69,7 +69,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/salsa20/badge.svg [docs-link]: https://docs.rs/salsa20/ [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260049-stream-ciphers [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg diff --git a/salsa20/src/lib.rs b/salsa20/src/lib.rs index 81d83ee0..4e068220 100644 --- a/salsa20/src/lib.rs +++ b/salsa20/src/lib.rs @@ -34,7 +34,7 @@ //! let plaintext = hex!("00010203 04050607 08090A0B 0C0D0E0F"); //! let ciphertext = hex!("85843cc5 d58cce7b 5dd3dd04 fa005ded"); //! -//! // Key and IV must be references to the `GenericArray` type. +//! // Key and IV must be references to the `Array` type. //! // Here we use the `Into` trait to convert arrays into it. //! let mut cipher = Salsa20::new(&key.into(), &nonce.into()); //! @@ -91,8 +91,8 @@ use cfg_if::cfg_if; pub use cipher; use cipher::{ + array::{typenum::Unsigned, Array}, consts::{U10, U24, U32, U4, U6, U64, U8}, - generic_array::{typenum::Unsigned, GenericArray}, Block, BlockSizeUser, IvSizeUser, KeyIvInit, KeySizeUser, StreamCipherCore, StreamCipherCoreWrapper, StreamCipherSeekCore, StreamClosure, }; @@ -119,13 +119,13 @@ pub type Salsa12 = StreamCipherCoreWrapper>; pub type Salsa20 = StreamCipherCoreWrapper>; /// Key type used by all Salsa variants and [`XSalsa20`]. -pub type Key = GenericArray; +pub type Key = Array; /// Nonce type used by all Salsa variants. -pub type Nonce = GenericArray; +pub type Nonce = Array; /// Nonce type used by [`XSalsa20`]. -pub type XNonce = GenericArray; +pub type XNonce = Array; /// Number of 32-bit words in the Salsa20 state const STATE_WORDS: usize = 16; diff --git a/salsa20/src/xsalsa.rs b/salsa20/src/xsalsa.rs index ba99b547..fc8659a7 100644 --- a/salsa20/src/xsalsa.rs +++ b/salsa20/src/xsalsa.rs @@ -2,8 +2,8 @@ use super::{Key, Nonce, SalsaCore, Unsigned, XNonce, CONSTANTS, STATE_WORDS}; use cipher::{ + array::Array, consts::{U10, U16, U24, U32, U4, U6, U64}, - generic_array::GenericArray, BlockSizeUser, IvSizeUser, KeyIvInit, KeySizeUser, StreamCipherCore, StreamCipherCoreWrapper, StreamCipherSeekCore, StreamClosure, }; @@ -40,7 +40,7 @@ impl BlockSizeUser for XSalsaCore { impl KeyIvInit for XSalsaCore { #[inline] fn new(key: &Key, iv: &XNonce) -> Self { - let subkey = hsalsa::(key, iv[..16].as_ref().into()); + let subkey = hsalsa::(key, iv[..16].try_into().unwrap()); let mut padded_iv = Nonce::default(); padded_iv.copy_from_slice(&iv[16..]); XSalsaCore(SalsaCore::new(&subkey, &padded_iv)) @@ -88,7 +88,7 @@ impl ZeroizeOnDrop for XSalsaCore {} /// - Nonce (`u32` x 4) /// /// It produces 256-bits of output suitable for use as a Salsa20 key -pub fn hsalsa(key: &Key, input: &GenericArray) -> GenericArray { +pub fn hsalsa(key: &Key, input: &Array) -> Array { #[inline(always)] fn to_u32(chunk: &[u8]) -> u32 { u32::from_le_bytes(chunk.try_into().unwrap()) @@ -127,7 +127,7 @@ pub fn hsalsa(key: &Key, input: &GenericArray) -> GenericA quarter_round(15, 12, 13, 14, &mut state); } - let mut output = GenericArray::default(); + let mut output = Array::default(); let key_idx: [usize; 8] = [0, 5, 10, 15, 6, 7, 8, 9]; for (i, chunk) in output.chunks_exact_mut(4).enumerate() { From 521d8749c8249f7ac7a5fd216389579ba5398d36 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 10 Jan 2024 11:53:44 -0700 Subject: [PATCH 5/5] Bump `cipher` to v0.5.0-pre.2 (#339) --- Cargo.lock | 20 ++++++++++---------- chacha20/Cargo.toml | 4 ++-- chacha20/src/xchacha.rs | 2 +- hc-256/Cargo.toml | 4 ++-- rabbit/Cargo.toml | 4 ++-- rc4/Cargo.toml | 2 +- rc4/src/lib.rs | 2 +- rc4/tests/lib.rs | 28 ++++++++++++++-------------- salsa20/Cargo.toml | 4 ++-- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3cde1a2d..7c5bef2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,9 +11,9 @@ checksum = "847495c209977a90e8aad588b959d0ca9f5dc228096d29a6bd3defd53f35eaec" [[package]] name = "block-padding" -version = "0.4.0-pre.3" +version = "0.4.0-pre.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a359e2b51a0e9b9d6a6d4582b7b62723e4a25f4e5ca6be70a6a00050202ab" +checksum = "e8ab21a8964437caf2e83a92a1221ce65e356a2a9b8b52d58bece04005fe114e" dependencies = [ "hybrid-array", ] @@ -36,9 +36,9 @@ dependencies = [ [[package]] name = "cipher" -version = "0.5.0-pre.1" +version = "0.5.0-pre.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e338a2ceb7493b9b89d12728c6feb2d4b61708cb63b577c556c92f43aef0cd" +checksum = "40619e61d2e7c018604193e71763730a96b0e606e19aba895956635986c7fe98" dependencies = [ "blobby", "crypto-common", @@ -57,9 +57,9 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.2.0-pre.3" +version = "0.2.0-pre.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc17eb697364b18256ec92675ebe6b7b153d2f1041e568d74533c5d0fc1ca162" +checksum = "806e4e3731d44f1340b069551225b44c2056c105cad9e67f0c46266db8a3a6b9" dependencies = [ "getrandom", "hybrid-array", @@ -93,18 +93,18 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "hybrid-array" -version = "0.2.0-pre.8" +version = "0.2.0-rc.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27fbaf242418fe980caf09ed348d5a6aeabe71fc1bd8bebad641f4591ae0a46d" +checksum = "b8c5517ac29f08e88170b9647d85cc5f21c2596de177b4867232e20b214b8da1" dependencies = [ "typenum", ] [[package]] name = "inout" -version = "0.2.0-pre.3" +version = "0.2.0-pre.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96ea9986e1fde8d177cd039f00f9f316d3bfce9ebc2787c1267d4414adf3acb3" +checksum = "0a2cc35b920cc3b344af824e64e508ffc2c819fc2368ed4d253244446194d2fe" dependencies = [ "block-padding", "hybrid-array", diff --git a/chacha20/Cargo.toml b/chacha20/Cargo.toml index d33b7473..ffef6fb6 100644 --- a/chacha20/Cargo.toml +++ b/chacha20/Cargo.toml @@ -20,13 +20,13 @@ categories = ["cryptography", "no-std"] [dependencies] cfg-if = "1" -cipher = "=0.5.0-pre.1" +cipher = "=0.5.0-pre.2" [target.'cfg(any(target_arch = "x86_64", target_arch = "x86"))'.dependencies] cpufeatures = "0.2" [dev-dependencies] -cipher = { version = "=0.5.0-pre.1", features = ["dev"] } +cipher = { version = "=0.5.0-pre.2", features = ["dev"] } hex-literal = "0.4" [features] diff --git a/chacha20/src/xchacha.rs b/chacha20/src/xchacha.rs index 46b9c653..74e556c6 100644 --- a/chacha20/src/xchacha.rs +++ b/chacha20/src/xchacha.rs @@ -185,7 +185,7 @@ mod hchacha20_tests { "a0f9e4d58a74a853c12ec41326d3ecdc" ); - let actual = hchacha::(Array::ref_from_slice(&KEY), Array::ref_from_slice(&INPUT)); + let actual = hchacha::(Array::from_slice(&KEY), Array::from_slice(&INPUT)); assert_eq!(actual.as_slice(), &OUTPUT); } } diff --git a/hc-256/Cargo.toml b/hc-256/Cargo.toml index 00dea615..8060c564 100644 --- a/hc-256/Cargo.toml +++ b/hc-256/Cargo.toml @@ -13,10 +13,10 @@ keywords = ["crypto", "stream-cipher", "trait"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "=0.5.0-pre.1" +cipher = "=0.5.0-pre.2" [dev-dependencies] -cipher = { version = "=0.5.0-pre.1", features = ["dev"] } +cipher = { version = "=0.5.0-pre.2", features = ["dev"] } hex-literal = "0.4" [features] diff --git a/rabbit/Cargo.toml b/rabbit/Cargo.toml index 537659e8..669b2987 100644 --- a/rabbit/Cargo.toml +++ b/rabbit/Cargo.toml @@ -13,10 +13,10 @@ keywords = ["crypto", "rabbit", "stream-cipher", "trait"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "=0.5.0-pre.1" +cipher = "=0.5.0-pre.2" [dev-dependencies] -cipher = { version = "=0.5.0-pre.1", features = ["dev"] } +cipher = { version = "=0.5.0-pre.2", features = ["dev"] } hex-literal = "0.4" [features] diff --git a/rc4/Cargo.toml b/rc4/Cargo.toml index 62497e62..b35170ac 100644 --- a/rc4/Cargo.toml +++ b/rc4/Cargo.toml @@ -13,7 +13,7 @@ keywords = ["arc4", "arcfour", "crypto", "stream-cipher", "trait"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "=0.5.0-pre.1" +cipher = "=0.5.0-pre.2" [dev-dependencies] hex-literal = "0.4" diff --git a/rc4/src/lib.rs b/rc4/src/lib.rs index 6e4005b9..b3874e9f 100644 --- a/rc4/src/lib.rs +++ b/rc4/src/lib.rs @@ -25,7 +25,7 @@ //! rc4.apply_keystream(&mut data); //! assert_eq!(data, [0x10, 0x21, 0xBF, 0x04, 0x20]); //! -//! let key = Key::::ref_from_slice(b"Secret"); +//! let key = Key::::from_slice(b"Secret"); //! let mut rc4 = Rc4::<_>::new(key); //! let mut data = b"Attack at dawn".to_vec(); //! rc4.apply_keystream(&mut data); diff --git a/rc4/tests/lib.rs b/rc4/tests/lib.rs index 894b9121..92b44fee 100644 --- a/rc4/tests/lib.rs +++ b/rc4/tests/lib.rs @@ -32,7 +32,7 @@ fn test_rfc6229_length_40_bits_key1() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -74,7 +74,7 @@ fn test_rfc6229_length_56_bits_key1() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -116,7 +116,7 @@ fn test_rfc6229_length_64_bits_key1() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -158,7 +158,7 @@ fn test_rfc6229_length_80_bits_key1() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -201,7 +201,7 @@ fn test_rfc6229_length_128_bits_key1() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -243,7 +243,7 @@ fn test_rfc6229_length_192_bits_key1() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -286,7 +286,7 @@ fn test_rfc6229_length_256_bits_key1() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -328,7 +328,7 @@ fn test_rfc6229_length_40_bits_key2() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -370,7 +370,7 @@ fn test_rfc6229_length_56_bits_key2() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -412,7 +412,7 @@ fn test_rfc6229_length_64_bits_key2() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -454,7 +454,7 @@ fn test_rfc6229_length_80_bits_key2() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -497,7 +497,7 @@ fn test_rfc6229_length_128_bits_key2() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -539,7 +539,7 @@ fn test_rfc6229_length_192_bits_key2() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; @@ -582,7 +582,7 @@ fn test_rfc6229_length_256_bits_key2() { " ); - let key = Key::::ref_from_slice(&KEY); + let key = Key::::from_slice(&KEY); let mut cipher = Rc4::<_>::new(key); let mut data = [0u8; 0x1010]; diff --git a/salsa20/Cargo.toml b/salsa20/Cargo.toml index 965e34b1..8f5da3b2 100644 --- a/salsa20/Cargo.toml +++ b/salsa20/Cargo.toml @@ -14,10 +14,10 @@ categories = ["cryptography", "no-std"] [dependencies] cfg-if = "1" -cipher = "=0.5.0-pre.1" +cipher = "=0.5.0-pre.2" [dev-dependencies] -cipher = { version = "=0.5.0-pre.1", features = ["dev"] } +cipher = { version = "=0.5.0-pre.2", features = ["dev"] } hex-literal = "0.4" [features]