From 1491f8b4e9ce532e62cae53137aa27d449f3d483 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Mon, 4 Sep 2023 16:26:48 -0600 Subject: [PATCH] [WIP] Migrate to `hybrid-array`; MSRV 1.65 Builds on RustCrypto/traits#1319. Migrates the following crates away from using `generic-array` to using `hybrid-array` instead: - `block-buffer` - `block-padding` - `dbl` - `inout` --- Cargo.lock | 35 +++++------------- Cargo.toml | 4 +++ block-buffer/Cargo.toml | 1 - block-buffer/src/lib.rs | 23 ++++++------ block-buffer/src/sealed.rs | 12 +++---- block-buffer/tests/mod.rs | 73 +++++++++++++++++++------------------- block-padding/Cargo.toml | 4 +-- block-padding/src/lib.rs | 35 +++++++++--------- dbl/Cargo.toml | 6 ++-- dbl/src/lib.rs | 12 +++---- hybrid-array/src/lib.rs | 6 ++++ inout/Cargo.toml | 6 ++-- inout/src/inout.rs | 20 +++++------ inout/src/inout_buf.rs | 19 +++++----- inout/src/reserved.rs | 26 +++++++------- 15 files changed, 134 insertions(+), 148 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89e0d273..71df70e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,15 +14,14 @@ name = "block-buffer" version = "0.11.0-pre" dependencies = [ "crypto-common", - "generic-array", "hex-literal 0.3.4", ] [[package]] name = "block-padding" -version = "0.3.3" +version = "0.4.0-pre" dependencies = [ - "generic-array", + "hybrid-array", ] [[package]] @@ -43,18 +42,16 @@ dependencies = [ [[package]] name = "crypto-common" version = "0.2.0-pre" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6faaa83e7700e0832cbbf84854d4c356270526907d9b14fab927fc7a9b5befb8" +source = "git+https://github.com/RustCrypto/traits?branch=crypto-common/hybrid-array#0c9a9bb0031238b5b40ef957305623f9ed59a476" dependencies = [ - "generic-array", - "typenum", + "hybrid-array", ] [[package]] name = "dbl" -version = "0.3.2" +version = "0.4.0-pre" dependencies = [ - "generic-array", + "hybrid-array", ] [[package]] @@ -66,16 +63,6 @@ dependencies = [ "syn", ] -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "hex" version = "0.4.3" @@ -101,10 +88,10 @@ dependencies = [ [[package]] name = "inout" -version = "0.1.3" +version = "0.2.0-pre" dependencies = [ "block-padding", - "generic-array", + "hybrid-array", ] [[package]] @@ -201,12 +188,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "wycheproof2blb" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 58a96615..d0d3750c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,7 @@ members = [ [profile.dev] opt-level = 2 + +[patch.crates-io] +crypto-common = { git = "https://github.com/RustCrypto/traits", branch = "crypto-common/hybrid-array" } +hybrid-array = { path = "hybrid-array" } diff --git a/block-buffer/Cargo.toml b/block-buffer/Cargo.toml index 7b121f95..0ea76a54 100644 --- a/block-buffer/Cargo.toml +++ b/block-buffer/Cargo.toml @@ -13,7 +13,6 @@ readme = "README.md" [dependencies] crypto-common = "0.2.0-pre" -generic-array = "0.14" [dev-dependencies] hex-literal = "0.3.3" diff --git a/block-buffer/src/lib.rs b/block-buffer/src/lib.rs index 61438e71..d21f9946 100644 --- a/block-buffer/src/lib.rs +++ b/block-buffer/src/lib.rs @@ -6,15 +6,14 @@ )] #![warn(missing_docs, rust_2018_idioms)] -pub use generic_array; +pub use crypto_common::{array, Block}; -use core::{fmt, ops::Add, slice}; -pub use crypto_common::Block; -use crypto_common::{BlockSizeUser, BlockSizes}; -use generic_array::{ +use array::{ typenum::{Add1, B1}, - ArrayLength, GenericArray, + Array, ArraySize, }; +use core::{fmt, ops::Add, slice}; +use crypto_common::{BlockSizeUser, BlockSizes}; mod read; mod sealed; @@ -22,7 +21,7 @@ mod sealed; pub use read::ReadBuffer; /// Block with additional one byte -type BlockP1 = GenericArray>; +type BlockP1 = Array>; /// Trait for buffer kinds. pub trait BufferKind: sealed::Sealed {} @@ -304,7 +303,7 @@ impl BlockBuffer { pub fn serialize(&self) -> BlockP1 where BS: Add, - Add1: ArrayLength, + Add1: ArraySize, { let mut res = BlockP1::::default(); res[0] = self.pos; @@ -318,7 +317,7 @@ impl BlockBuffer { pub fn deserialize(buffer: &BlockP1) -> Result where BS: Add, - Add1: ArrayLength, + Add1: ArraySize, { let pos = buffer[0]; if !::invariant(pos as usize, BS::USIZE) { @@ -327,9 +326,7 @@ impl BlockBuffer { if buffer[1..][pos as usize..].iter().any(|&b| b != 0) { return Err(Error); } - Ok(Self { - buffer: GenericArray::clone_from_slice(&buffer[1..]), - pos, - }) + let buffer = Array::clone_from_slice(&buffer[1..]); + Ok(Self { buffer, pos }) } } diff --git a/block-buffer/src/sealed.rs b/block-buffer/src/sealed.rs index cc7b3ef6..7d36b9c2 100644 --- a/block-buffer/src/sealed.rs +++ b/block-buffer/src/sealed.rs @@ -1,5 +1,5 @@ +use crate::array::{Array, ArraySize}; use core::slice; -use generic_array::{ArrayLength, GenericArray}; /// Sealed trait for buffer kinds. pub trait Sealed { @@ -14,7 +14,7 @@ pub trait Sealed { fn invariant(pos: usize, block_size: usize) -> bool; /// Split input data into slice of blocks and tail. - fn split_blocks>(data: &[u8]) -> (&[GenericArray], &[u8]); + fn split_blocks(data: &[u8]) -> (&[Array], &[u8]); } impl Sealed for super::Eager { @@ -35,14 +35,14 @@ impl Sealed for super::Eager { } #[inline(always)] - fn split_blocks>(data: &[u8]) -> (&[GenericArray], &[u8]) { + fn split_blocks(data: &[u8]) -> (&[Array], &[u8]) { let nb = data.len() / N::USIZE; let blocks_len = nb * N::USIZE; let tail_len = data.len() - blocks_len; // SAFETY: we guarantee that created slices do not point // outside of `data` unsafe { - let blocks_ptr = data.as_ptr() as *const GenericArray; + let blocks_ptr = data.as_ptr() as *const Array; let tail_ptr = data.as_ptr().add(blocks_len); ( slice::from_raw_parts(blocks_ptr, nb), @@ -70,7 +70,7 @@ impl Sealed for super::Lazy { } #[inline(always)] - fn split_blocks>(data: &[u8]) -> (&[GenericArray], &[u8]) { + fn split_blocks(data: &[u8]) -> (&[Array], &[u8]) { if data.is_empty() { return (&[], &[]); } @@ -84,7 +84,7 @@ impl Sealed for super::Lazy { // SAFETY: we guarantee that created slices do not point // outside of `data` unsafe { - let blocks_ptr = data.as_ptr() as *const GenericArray; + let blocks_ptr = data.as_ptr() as *const Array; let tail_ptr = data.as_ptr().add(blocks_len); ( slice::from_raw_parts(blocks_ptr, nb), diff --git a/block-buffer/tests/mod.rs b/block-buffer/tests/mod.rs index da2a651b..6ee1712b 100644 --- a/block-buffer/tests/mod.rs +++ b/block-buffer/tests/mod.rs @@ -1,7 +1,7 @@ use block_buffer::{ - generic_array::{ + array::{ typenum::{U10, U16, U24, U4, U8}, - GenericArray, + Array, }, Block, EagerBuffer, LazyBuffer, ReadBuffer, }; @@ -203,17 +203,17 @@ fn test_eager_serialize() { assert_eq!(buf3.serialize(), ser3); // Invalid position - let buf = GenericArray::from_slice(&[0, 0, 0, 4]); - assert!(Buf::deserialize(buf).is_err()); - let buf = GenericArray::from_slice(&[0, 0, 0, 10]); - assert!(Buf::deserialize(buf).is_err()); + let buf = Array([0, 0, 0, 4]); + assert!(Buf::deserialize(&buf).is_err()); + let buf = Array([0, 0, 0, 10]); + assert!(Buf::deserialize(&buf).is_err()); // "Garbage" bytes are not zeroized - let buf = GenericArray::from_slice(&[1, 0, 0, 0]); - assert!(Buf::deserialize(buf).is_err()); - let buf = GenericArray::from_slice(&[0, 1, 0, 1]); - assert!(Buf::deserialize(buf).is_err()); - let buf = GenericArray::from_slice(&[0, 0, 1, 2]); - assert!(Buf::deserialize(buf).is_err()); + let buf = Array([1, 0, 0, 0]); + assert!(Buf::deserialize(&buf).is_err()); + let buf = Array([0, 1, 0, 1]); + assert!(Buf::deserialize(&buf).is_err()); + let buf = Array([0, 0, 1, 2]); + assert!(Buf::deserialize(&buf).is_err()); } #[test] @@ -223,6 +223,7 @@ fn test_lazy_serialize() { let mut buf1 = Buf::default(); let ser0 = buf1.serialize(); assert_eq!(&ser0[..], &[0, 0, 0, 0, 0]); + Buf::deserialize(&ser0).unwrap(); assert_eq!(Buf::deserialize(&ser0).unwrap().serialize(), ser0); buf1.digest_blocks(&[41, 42], |_| {}); @@ -262,19 +263,19 @@ fn test_lazy_serialize() { assert_eq!(buf3.serialize(), ser4); // Invalid position - let buf = GenericArray::from_slice(&[10, 0, 0, 0, 0]); - assert!(Buf::deserialize(buf).is_err()); - let buf = GenericArray::from_slice(&[5, 0, 0, 0, 0]); - assert!(Buf::deserialize(buf).is_err()); + let buf = Array([10, 0, 0, 0, 0]); + assert!(Buf::deserialize(&buf).is_err()); + let buf = Array([5, 0, 0, 0, 0]); + assert!(Buf::deserialize(&buf).is_err()); // "Garbage" bytes are not zeroized - let buf = GenericArray::from_slice(&[0, 1, 0, 0, 0]); - assert!(Buf::deserialize(buf).is_err()); - let buf = GenericArray::from_slice(&[1, 0, 1, 0, 0]); - assert!(Buf::deserialize(buf).is_err()); - let buf = GenericArray::from_slice(&[2, 0, 0, 1, 0]); - assert!(Buf::deserialize(buf).is_err()); - let buf = GenericArray::from_slice(&[3, 0, 0, 0, 1]); - assert!(Buf::deserialize(buf).is_err()); + let buf = Array([0, 1, 0, 0, 0]); + assert!(Buf::deserialize(&buf).is_err()); + let buf = Array([1, 0, 1, 0, 0]); + assert!(Buf::deserialize(&buf).is_err()); + let buf = Array([2, 0, 0, 1, 0]); + assert!(Buf::deserialize(&buf).is_err()); + let buf = Array([3, 0, 0, 0, 1]); + assert!(Buf::deserialize(&buf).is_err()); } #[test] @@ -332,17 +333,17 @@ fn test_read_serialize() { assert_eq!(&buf3.serialize()[..], &[1, 55, 56, 57]); // Invalid position - let buf = GenericArray::from_slice(&[0, 0, 0, 0]); - assert!(Buf::deserialize(buf).is_err()); - let buf = GenericArray::from_slice(&[5, 0, 0, 0]); - assert!(Buf::deserialize(buf).is_err()); - let buf = GenericArray::from_slice(&[10, 0, 0, 0]); - assert!(Buf::deserialize(buf).is_err()); + let buf = Array([0, 0, 0, 0]); + assert!(Buf::deserialize(&buf).is_err()); + let buf = Array([5, 0, 0, 0]); + assert!(Buf::deserialize(&buf).is_err()); + let buf = Array([10, 0, 0, 0]); + assert!(Buf::deserialize(&buf).is_err()); // "Garbage" bytes are not zeroized - let buf = GenericArray::from_slice(&[2, 1, 0, 0]); - assert!(Buf::deserialize(buf).is_err()); - let buf = GenericArray::from_slice(&[3, 0, 1, 0]); - assert!(Buf::deserialize(buf).is_err()); - let buf = GenericArray::from_slice(&[4, 0, 0, 1]); - assert!(Buf::deserialize(buf).is_err()); + let buf = Array([2, 1, 0, 0]); + assert!(Buf::deserialize(&buf).is_err()); + let buf = Array([3, 0, 1, 0]); + assert!(Buf::deserialize(&buf).is_err()); + let buf = Array([4, 0, 0, 1]); + assert!(Buf::deserialize(&buf).is_err()); } diff --git a/block-padding/Cargo.toml b/block-padding/Cargo.toml index 6a049717..198c84aa 100644 --- a/block-padding/Cargo.toml +++ b/block-padding/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "block-padding" -version = "0.3.3" +version = "0.4.0-pre" description = "Padding and unpadding of messages divided into blocks." authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" @@ -12,7 +12,7 @@ keywords = ["padding", "pkcs7", "ansix923", "iso7816"] categories = ["cryptography", "no-std"] [dependencies] -generic-array = "0.14" +hybrid-array = "=0.2.0-pre.3" [features] std = [] diff --git a/block-padding/src/lib.rs b/block-padding/src/lib.rs index 8190c8d1..28aa4775 100644 --- a/block-padding/src/lib.rs +++ b/block-padding/src/lib.rs @@ -14,9 +14,10 @@ #[cfg(feature = "std")] extern crate std; +pub use hybrid_array as array; + use core::fmt; -pub use generic_array; -use generic_array::{ArrayLength, GenericArray}; +use hybrid_array::{Array, ArraySize}; /// Padding types #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -49,10 +50,10 @@ pub trait RawPadding { } /// Block size. -pub type Block = GenericArray; +pub type Block = Array; /// Trait for padding messages divided into blocks -pub trait Padding> { +pub trait Padding { /// Padding type const TYPE: PadType; @@ -92,7 +93,7 @@ pub trait Padding> { } } -impl> Padding for T +impl Padding for T where T: RawPadding, { @@ -113,11 +114,11 @@ where /// /// ``` /// use block_padding::{ZeroPadding, Padding}; -/// use generic_array::{GenericArray, typenum::U8}; +/// use block_padding::array::{Array, typenum::U8}; /// /// let msg = b"test"; /// let pos = msg.len(); -/// let mut block: GenericArray:: = [0xff; 8].into(); +/// let mut block: Array:: = [0xff; 8].into(); /// block[..pos].copy_from_slice(msg); /// ZeroPadding::pad(&mut block, pos); /// assert_eq!(&block[..], b"test\x00\x00\x00\x00"); @@ -158,11 +159,11 @@ impl RawPadding for ZeroPadding { /// /// ``` /// use block_padding::{Pkcs7, Padding}; -/// use generic_array::{GenericArray, typenum::U8}; +/// use block_padding::array::{Array, typenum::U8}; /// /// let msg = b"test"; /// let pos = msg.len(); -/// let mut block: GenericArray:: = [0xff; 8].into(); +/// let mut block: Array:: = [0xff; 8].into(); /// block[..pos].copy_from_slice(msg); /// Pkcs7::pad(&mut block, pos); /// assert_eq!(&block[..], b"test\x04\x04\x04\x04"); @@ -220,11 +221,11 @@ impl RawPadding for Pkcs7 { /// /// ``` /// use block_padding::{Iso10126, Padding}; -/// use generic_array::{GenericArray, typenum::U8}; +/// use block_padding::array::{Array, typenum::U8}; /// /// let msg = b"test"; /// let pos = msg.len(); -/// let mut block: GenericArray:: = [0xff; 8].into(); +/// let mut block: Array:: = [0xff; 8].into(); /// block[..pos].copy_from_slice(msg); /// Iso10126::pad(&mut block, pos); /// assert_eq!(&block[..], b"test\x04\x04\x04\x04"); @@ -255,11 +256,11 @@ impl RawPadding for Iso10126 { /// /// ``` /// use block_padding::{AnsiX923, Padding}; -/// use generic_array::{GenericArray, typenum::U8}; +/// use block_padding::array::{Array, typenum::U8}; /// /// let msg = b"test"; /// let pos = msg.len(); -/// let mut block: GenericArray:: = [0xff; 8].into(); +/// let mut block: Array:: = [0xff; 8].into(); /// block[..pos].copy_from_slice(msg); /// AnsiX923::pad(&mut block, pos); /// assert_eq!(&block[..], b"test\x00\x00\x00\x04"); @@ -309,11 +310,11 @@ impl RawPadding for AnsiX923 { /// /// ``` /// use block_padding::{Iso7816, Padding}; -/// use generic_array::{GenericArray, typenum::U8}; +/// use block_padding::array::{Array, typenum::U8}; /// /// let msg = b"test"; /// let pos = msg.len(); -/// let mut block: GenericArray:: = [0xff; 8].into(); +/// let mut block: Array:: = [0xff; 8].into(); /// block[..pos].copy_from_slice(msg); /// Iso7816::pad(&mut block, pos); /// assert_eq!(&block[..], b"test\x80\x00\x00\x00"); @@ -352,11 +353,11 @@ impl RawPadding for Iso7816 { /// /// ``` /// use block_padding::{NoPadding, Padding}; -/// use generic_array::{GenericArray, typenum::U8}; +/// use block_padding::array::{Array, typenum::U8}; /// /// let msg = b"test"; /// let pos = msg.len(); -/// let mut block: GenericArray:: = [0xff; 8].into(); +/// let mut block: Array:: = [0xff; 8].into(); /// block[..pos].copy_from_slice(msg); /// NoPadding::pad(&mut block, pos); /// assert_eq!(&block[..], b"test\xff\xff\xff\xff"); diff --git a/dbl/Cargo.toml b/dbl/Cargo.toml index 5b29c45c..14ae996e 100644 --- a/dbl/Cargo.toml +++ b/dbl/Cargo.toml @@ -1,12 +1,14 @@ [package] name = "dbl" -version = "0.3.2" +version = "0.4.0-pre" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" description = "Double operation in Galois Field (GF)" documentation = "https://docs.rs/dbl" repository = "https://github.com/RustCrypto/utils" keywords = ["crypto", "dbl", "gf", "galois"] +edition = "2021" +rust-version = "1.65" [dependencies] -generic-array = "0.14" +hybrid-array = "=0.2.0-pre.3" diff --git a/dbl/src/lib.rs b/dbl/src/lib.rs index bddc565a..7cd04e8b 100644 --- a/dbl/src/lib.rs +++ b/dbl/src/lib.rs @@ -6,10 +6,8 @@ )] #![forbid(unsafe_code)] -extern crate generic_array; - -use generic_array::typenum::{U16, U32, U8}; -use generic_array::GenericArray; +use hybrid_array::typenum::{U16, U32, U8}; +use hybrid_array::Array; use core::convert::TryInto; @@ -39,7 +37,7 @@ pub trait Dbl { fn inv_dbl(self) -> Self; } -impl Dbl for GenericArray { +impl Dbl for Array { #[inline] fn dbl(self) -> Self { let mut val = u64::from_be_bytes(self.into()); @@ -63,7 +61,7 @@ impl Dbl for GenericArray { } } -impl Dbl for GenericArray { +impl Dbl for Array { #[inline] fn dbl(self) -> Self { let mut val = [ @@ -108,7 +106,7 @@ impl Dbl for GenericArray { } } -impl Dbl for GenericArray { +impl Dbl for Array { #[inline] fn dbl(self) -> Self { let mut val = [ diff --git a/hybrid-array/src/lib.rs b/hybrid-array/src/lib.rs index 2f76c6c6..1212b2c1 100644 --- a/hybrid-array/src/lib.rs +++ b/hybrid-array/src/lib.rs @@ -556,6 +556,12 @@ macro_rules! impl_array_size { type ArrayType = [T; $len]; } + impl From> for [T; $len] { + fn from(arr: Array) -> [T; $len] { + arr.0 + } + } + impl IntoArray for [T; $len] { type Size = typenum::$ty; diff --git a/inout/Cargo.toml b/inout/Cargo.toml index 8195a870..0487aeff 100644 --- a/inout/Cargo.toml +++ b/inout/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "inout" -version = "0.1.3" +version = "0.2.0-pre" description = "Custom reference types for code generic over in-place and buffer-to-buffer modes of operation." authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" @@ -11,8 +11,8 @@ repository = "https://github.com/RustCrypto/utils" keywords = ["custom-reference"] [dependencies] -generic-array = "0.14" -block-padding = { version = "0.3", path = "../block-padding", optional = true } +block-padding = { version = "0.4.0-pre", path = "../block-padding", optional = true } +hybrid-array = "=0.2.0-pre.3" [features] std = ["block-padding/std"] diff --git a/inout/src/inout.rs b/inout/src/inout.rs index 4cdad404..412d3e70 100644 --- a/inout/src/inout.rs +++ b/inout/src/inout.rs @@ -1,6 +1,6 @@ use crate::InOutBuf; use core::{marker::PhantomData, ptr}; -use generic_array::{ArrayLength, GenericArray}; +use hybrid_array::{Array, ArraySize}; /// Custom pointer type which contains one immutable (input) and one mutable /// (output) pointer, which are either equal or non-overlapping. @@ -98,7 +98,7 @@ impl<'inp, 'out, T> From<(&'inp T, &'out mut T)> for InOut<'inp, 'out, T> { } } -impl<'inp, 'out, T, N: ArrayLength> InOut<'inp, 'out, GenericArray> { +impl<'inp, 'out, T, N: ArraySize> InOut<'inp, 'out, Array> { /// Returns `InOut` for the given position. /// /// # Panics @@ -127,7 +127,7 @@ impl<'inp, 'out, T, N: ArrayLength> InOut<'inp, 'out, GenericArray> { } } -impl<'inp, 'out, N: ArrayLength> InOut<'inp, 'out, GenericArray> { +impl<'inp, 'out, N: ArraySize> InOut<'inp, 'out, Array> { /// XOR `data` with values behind the input slice and write /// result to the output slice. /// @@ -135,10 +135,10 @@ impl<'inp, 'out, N: ArrayLength> InOut<'inp, 'out, GenericArray> { /// If `data` length is not equal to the buffer length. #[inline(always)] #[allow(clippy::needless_range_loop)] - pub fn xor_in2out(&mut self, data: &GenericArray) { + pub fn xor_in2out(&mut self, data: &Array) { unsafe { let input = ptr::read(self.in_ptr); - let mut temp = GenericArray::::default(); + let mut temp = Array::::default(); for i in 0..N::USIZE { temp[i] = input[i] ^ data[i]; } @@ -147,10 +147,10 @@ impl<'inp, 'out, N: ArrayLength> InOut<'inp, 'out, GenericArray> { } } -impl<'inp, 'out, N, M> InOut<'inp, 'out, GenericArray, M>> +impl<'inp, 'out, N, M> InOut<'inp, 'out, Array, M>> where - N: ArrayLength, - M: ArrayLength>, + N: ArraySize, + M: ArraySize, { /// XOR `data` with values behind the input slice and write /// result to the output slice. @@ -159,10 +159,10 @@ where /// If `data` length is not equal to the buffer length. #[inline(always)] #[allow(clippy::needless_range_loop)] - pub fn xor_in2out(&mut self, data: &GenericArray, M>) { + pub fn xor_in2out(&mut self, data: &Array, M>) { unsafe { let input = ptr::read(self.in_ptr); - let mut temp = GenericArray::, M>::default(); + let mut temp = Array::, M>::default(); for i in 0..M::USIZE { for j in 0..N::USIZE { temp[i][j] = input[i][j] ^ data[i][j]; diff --git a/inout/src/inout_buf.rs b/inout/src/inout_buf.rs index 70f89af0..ec311d7b 100644 --- a/inout/src/inout_buf.rs +++ b/inout/src/inout_buf.rs @@ -3,7 +3,7 @@ use crate::{ InOut, }; use core::{marker::PhantomData, slice}; -use generic_array::{ArrayLength, GenericArray}; +use hybrid_array::{Array, ArraySize}; /// Custom slice type which references one immutable (input) slice and one /// mutable (output) slice of equal length. Input and output slices are @@ -209,19 +209,16 @@ impl<'inp, 'out, T> InOutBuf<'inp, 'out, T> { /// Partition buffer into 2 parts: buffer of arrays and tail. #[inline(always)] - pub fn into_chunks>( + pub fn into_chunks( self, - ) -> ( - InOutBuf<'inp, 'out, GenericArray>, - InOutBuf<'inp, 'out, T>, - ) { + ) -> (InOutBuf<'inp, 'out, Array>, InOutBuf<'inp, 'out, T>) { let chunks = self.len() / N::USIZE; let tail_pos = N::USIZE * chunks; let tail_len = self.len() - tail_pos; unsafe { let chunks = InOutBuf { - in_ptr: self.in_ptr as *const GenericArray, - out_ptr: self.out_ptr as *mut GenericArray, + in_ptr: self.in_ptr as *const Array, + out_ptr: self.out_ptr as *mut Array, len: chunks, _pd: PhantomData, }; @@ -256,14 +253,14 @@ impl<'inp, 'out> InOutBuf<'inp, 'out, u8> { } } -impl<'inp, 'out, T, N> TryInto>> for InOutBuf<'inp, 'out, T> +impl<'inp, 'out, T, N> TryInto>> for InOutBuf<'inp, 'out, T> where - N: ArrayLength, + N: ArraySize, { type Error = IntoArrayError; #[inline(always)] - fn try_into(self) -> Result>, Self::Error> { + fn try_into(self) -> Result>, Self::Error> { if self.len() == N::USIZE { Ok(InOut { in_ptr: self.in_ptr as *const _, diff --git a/inout/src/reserved.rs b/inout/src/reserved.rs index 553eac1c..8c8b7a62 100644 --- a/inout/src/reserved.rs +++ b/inout/src/reserved.rs @@ -8,7 +8,7 @@ use crate::{InOut, InOutBuf}; #[cfg(feature = "block-padding")] use block_padding::{PadType, Padding}; #[cfg(feature = "block-padding")] -use generic_array::{ArrayLength, GenericArray}; +use hybrid_array::{Array, ArraySize}; /// Custom slice type which references one immutable (input) slice and one /// mutable (output) slice. Input and output slices are either the same or @@ -134,19 +134,19 @@ impl<'inp, 'out> InOutBufReserved<'inp, 'out, u8> { pub fn into_padded_blocks(self) -> Result, PadError> where P: Padding, - BS: ArrayLength, + BS: ArraySize, { let bs = BS::USIZE; let blocks_len = self.in_len / bs; let tail_len = self.in_len - bs * blocks_len; let blocks = unsafe { InOutBuf::from_raw( - self.in_ptr as *const GenericArray, - self.out_ptr as *mut GenericArray, + self.in_ptr as *const Array, + self.out_ptr as *mut Array, blocks_len, ) }; - let mut tail_in = GenericArray::::default(); + let mut tail_in = Array::::default(); let tail_out = match P::TYPE { PadType::NoPadding | PadType::Ambiguous if tail_len == 0 => None, PadType::NoPadding => return Err(PadError), @@ -167,7 +167,7 @@ impl<'inp, 'out> InOutBufReserved<'inp, 'out, u8> { tail_in.as_mut_ptr(), tail_len, ); - &mut *(self.out_ptr.add(blen) as *mut GenericArray) + &mut *(self.out_ptr.add(blen) as *mut Array) }; P::pad(&mut tail_in, tail_len); Some(out_block) @@ -184,17 +184,17 @@ impl<'inp, 'out> InOutBufReserved<'inp, 'out, u8> { /// Variant of [`InOutBuf`] with optional padded tail block. #[cfg(feature = "block-padding")] #[cfg_attr(docsrs, doc(cfg(feature = "block-padding")))] -pub struct PaddedInOutBuf<'inp, 'out, BS: ArrayLength> { - blocks: InOutBuf<'inp, 'out, GenericArray>, - tail_in: GenericArray, - tail_out: Option<&'out mut GenericArray>, +pub struct PaddedInOutBuf<'inp, 'out, BS: ArraySize> { + blocks: InOutBuf<'inp, 'out, Array>, + tail_in: Array, + tail_out: Option<&'out mut Array>, } #[cfg(feature = "block-padding")] -impl<'inp, 'out, BS: ArrayLength> PaddedInOutBuf<'inp, 'out, BS> { +impl<'inp, 'out, BS: ArraySize> PaddedInOutBuf<'inp, 'out, BS> { /// Get full blocks. #[inline(always)] - pub fn get_blocks<'a>(&'a mut self) -> InOutBuf<'a, 'a, GenericArray> { + pub fn get_blocks<'a>(&'a mut self) -> InOutBuf<'a, 'a, Array> { self.blocks.reborrow() } @@ -203,7 +203,7 @@ impl<'inp, 'out, BS: ArrayLength> PaddedInOutBuf<'inp, 'out, BS> { /// For paddings with `P::TYPE = PadType::Reversible` it always returns `Some`. #[inline(always)] #[allow(clippy::needless_option_as_deref)] - pub fn get_tail_block<'a>(&'a mut self) -> Option>> { + pub fn get_tail_block<'a>(&'a mut self) -> Option>> { match self.tail_out.as_deref_mut() { Some(out_block) => Some((&self.tail_in, out_block).into()), None => None,