diff --git a/.github/workflows/belt-ctr.yaml b/.github/workflows/belt-ctr.yaml index e2148bc..d07ccff 100644 --- a/.github/workflows/belt-ctr.yaml +++ b/.github/workflows/belt-ctr.yaml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.57.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -39,6 +39,8 @@ jobs: - run: cargo build --no-default-features --release --target ${{ matrix.target }} minimal-versions: + # disabled until belt-block gets published + if: false uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master with: working-directory: ${{ github.workflow }} @@ -48,7 +50,7 @@ jobs: strategy: matrix: rust: - - 1.57.0 # MSRV + - 1.65.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/cbc.yaml b/.github/workflows/cbc.yaml index 3a33005..19f3875 100644 --- a/.github/workflows/cbc.yaml +++ b/.github/workflows/cbc.yaml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -37,6 +37,8 @@ jobs: - run: cargo build --no-default-features --release --target ${{ matrix.target }} minimal-versions: + # disabled until belt-block gets published + if: false uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master with: working-directory: ${{ github.workflow }} @@ -46,7 +48,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.72.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/cfb-mode.yaml b/.github/workflows/cfb-mode.yaml index 4f3d56d..440d4b1 100644 --- a/.github/workflows/cfb-mode.yaml +++ b/.github/workflows/cfb-mode.yaml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -37,6 +37,8 @@ jobs: - run: cargo build --no-default-features --release --target ${{ matrix.target }} minimal-versions: + # disabled until aes gets published + if: false uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master with: working-directory: ${{ github.workflow }} @@ -46,7 +48,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.72.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/cfb8.yaml b/.github/workflows/cfb8.yaml index c16d7c5..6e65785 100644 --- a/.github/workflows/cfb8.yaml +++ b/.github/workflows/cfb8.yaml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -37,6 +37,8 @@ jobs: - run: cargo build --no-default-features --release --target ${{ matrix.target }} minimal-versions: + # disabled until aes gets published + if: false uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master with: working-directory: ${{ github.workflow }} @@ -46,7 +48,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.72.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/ctr.yaml b/.github/workflows/ctr.yaml index 7290124..48104e9 100644 --- a/.github/workflows/ctr.yaml +++ b/.github/workflows/ctr.yaml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -37,6 +37,8 @@ jobs: - run: cargo build --no-default-features --release --target ${{ matrix.target }} minimal-versions: + # disabled until aes gets published + if: false uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master with: working-directory: ${{ github.workflow }} @@ -46,7 +48,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.72.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/ige.yaml b/.github/workflows/ige.yaml index 89ed57d..eefe70f 100644 --- a/.github/workflows/ige.yaml +++ b/.github/workflows/ige.yaml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -37,6 +37,8 @@ jobs: - run: cargo build --no-default-features --release --target ${{ matrix.target }} minimal-versions: + # disabled until aes gets published + if: false uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master with: working-directory: ${{ github.workflow }} @@ -46,7 +48,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.72.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/ofb.yaml b/.github/workflows/ofb.yaml index bce61c7..22d64db 100644 --- a/.github/workflows/ofb.yaml +++ b/.github/workflows/ofb.yaml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -37,6 +37,8 @@ jobs: - run: cargo build --no-default-features --release --target ${{ matrix.target }} minimal-versions: + # disabled until aes gets published + if: false uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master with: working-directory: ${{ github.workflow }} @@ -46,7 +48,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.72.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/pcbc.yaml b/.github/workflows/pcbc.yaml index 3be5d86..921eab8 100644 --- a/.github/workflows/pcbc.yaml +++ b/.github/workflows/pcbc.yaml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -37,6 +37,8 @@ jobs: - run: cargo build --no-default-features --release --target ${{ matrix.target }} minimal-versions: + # disabled until aes gets published + if: false uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master with: working-directory: ${{ github.workflow }} @@ -46,7 +48,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.72.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index 8738ae1..aaf0a20 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -17,7 +17,7 @@ jobs: - uses: RustCrypto/actions/cargo-cache@master - uses: dtolnay/rust-toolchain@master with: - toolchain: 1.71.0 + toolchain: 1.72.0 components: clippy - run: cargo clippy --all --all-features -- -D warnings diff --git a/Cargo.lock b/Cargo.lock index 06b1177..a3471cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,8 @@ version = 3 [[package]] name = "aes" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" +version = "0.9.0-pre" +source = "git+https://github.com/baloo/block-ciphers.git?branch=baloo/bump-cipher/0.5.0-pre.4#bb94e5e71f5320fcaab727ad0c503cca5190da4c" dependencies = [ "cfg-if", "cipher", @@ -15,16 +14,15 @@ dependencies = [ [[package]] name = "belt-block" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9aa1eef3994e2ccd304a78fe3fea4a73e5792007f85f09b79bb82143ca5f82b" +version = "0.2.0-pre" +source = "git+https://github.com/baloo/block-ciphers.git?branch=baloo/bump-cipher/0.5.0-pre.4#bb94e5e71f5320fcaab727ad0c503cca5190da4c" dependencies = [ "cipher", ] [[package]] name = "belt-ctr" -version = "0.1.0" +version = "0.2.0-pre" dependencies = [ "belt-block", "cipher", @@ -39,16 +37,16 @@ checksum = "847495c209977a90e8aad588b959d0ca9f5dc228096d29a6bd3defd53f35eaec" [[package]] name = "block-padding" -version = "0.3.3" +version = "0.4.0-pre.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93" +checksum = "e8ab21a8964437caf2e83a92a1221ce65e356a2a9b8b52d58bece04005fe114e" dependencies = [ - "generic-array", + "hybrid-array", ] [[package]] name = "cbc" -version = "0.1.2" +version = "0.2.0-pre" dependencies = [ "aes", "cipher", @@ -57,7 +55,7 @@ dependencies = [ [[package]] name = "cfb-mode" -version = "0.8.2" +version = "0.9.0-pre" dependencies = [ "aes", "belt-block", @@ -67,7 +65,7 @@ dependencies = [ [[package]] name = "cfb8" -version = "0.8.1" +version = "0.9.0-pre" dependencies = [ "aes", "cipher", @@ -82,9 +80,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cipher" -version = "0.4.4" +version = "0.5.0-pre.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +checksum = "84fba98785cecd0e308818a87c817576a40f99d8bab6405bf422bacd3efb6c1f" dependencies = [ "blobby", "crypto-common", @@ -103,17 +101,18 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.6" +version = "0.2.0-pre.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "b7aa2ec04f5120b830272a481e8d9d8ba4dda140d2cda59b0f1110d5eb93c38e" dependencies = [ - "generic-array", - "typenum", + "getrandom", + "hybrid-array", + "rand_core", ] [[package]] name = "ctr" -version = "0.9.2" +version = "0.10.0-pre" dependencies = [ "aes", "cipher", @@ -123,13 +122,14 @@ dependencies = [ ] [[package]] -name = "generic-array" -version = "0.14.7" +name = "getrandom" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ - "typenum", - "version_check", + "cfg-if", + "libc", + "wasi", ] [[package]] @@ -144,9 +144,18 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" +[[package]] +name = "hybrid-array" +version = "0.2.0-rc.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcda354500b318c287a6b91c1cfbc42edd53d52d259a80783ceb5e3986fca2b2" +dependencies = [ + "typenum", +] + [[package]] name = "ige" -version = "0.1.1" +version = "0.2.0-pre" dependencies = [ "aes", "cipher", @@ -155,41 +164,39 @@ dependencies = [ [[package]] name = "inout" -version = "0.1.3" +version = "0.2.0-pre.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +checksum = "0a2cc35b920cc3b344af824e64e508ffc2c819fc2368ed4d253244446194d2fe" dependencies = [ "block-padding", - "generic-array", + "hybrid-array", ] [[package]] name = "kuznyechik" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca7899a524198c60ded686fc826703de2a04470aff9d042e8cc1f845b912c12f" +version = "0.9.0-pre" +source = "git+https://github.com/baloo/block-ciphers.git?branch=baloo/bump-cipher/0.5.0-pre.4#bb94e5e71f5320fcaab727ad0c503cca5190da4c" dependencies = [ "cipher", ] [[package]] name = "libc" -version = "0.2.147" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "magma" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b09bd24ba5fcb427ee21a09e28f9a5e2c2fce78c69af974fb8d373662ceedb4" +version = "0.10.0-pre" +source = "git+https://github.com/baloo/block-ciphers.git?branch=baloo/bump-cipher/0.5.0-pre.4#bb94e5e71f5320fcaab727ad0c503cca5190da4c" dependencies = [ "cipher", ] [[package]] name = "ofb" -version = "0.6.1" +version = "0.7.0-pre" dependencies = [ "aes", "cipher", @@ -198,27 +205,36 @@ dependencies = [ [[package]] name = "pcbc" -version = "0.1.2" +version = "0.2.0-pre" dependencies = [ "aes", "cipher", "hex-literal 0.3.4", ] +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +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 1d90026..3aada94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,11 @@ members = [ "ofb", "pcbc", ] + +[patch.crates-io] +# please re-enable the minimal-versions when you remove those patches. +# https://github.com/RustCrypto/block-ciphers/pull/413 +aes = { git = "https://github.com/baloo/block-ciphers.git", branch = "baloo/bump-cipher/0.5.0-pre.4" } +belt-block = { git = "https://github.com/baloo/block-ciphers.git", branch = "baloo/bump-cipher/0.5.0-pre.4" } +kuznyechik = { git = "https://github.com/baloo/block-ciphers.git", branch = "baloo/bump-cipher/0.5.0-pre.4" } +magma = { git = "https://github.com/baloo/block-ciphers.git", branch = "baloo/bump-cipher/0.5.0-pre.4" } diff --git a/belt-ctr/Cargo.toml b/belt-ctr/Cargo.toml index 3d4a201..1d540f1 100644 --- a/belt-ctr/Cargo.toml +++ b/belt-ctr/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "belt-ctr" -version = "0.1.0" +version = "0.2.0-pre" description = "CTR block mode of operation specified by the BelT standard" 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/belt-ctr" repository = "https://github.com/RustCrypto/block-modes" @@ -13,13 +13,13 @@ keywords = ["crypto", "block-mode", "stream-cipher", "ciphers", "belt"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "0.4" -belt-block = "0.1" +cipher = "=0.5.0-pre.4" +belt-block = "=0.2.0-pre" [dev-dependencies] hex-literal = "0.4" -belt-block = "0.1" -cipher = { version = "0.4", features = ["dev"] } +belt-block = "=0.2.0-pre" +cipher = { version = "=0.5.0-pre.4", features = ["dev"] } [features] alloc = ["cipher/alloc"] diff --git a/belt-ctr/src/lib.rs b/belt-ctr/src/lib.rs index c3cccbb..869e6d6 100644 --- a/belt-ctr/src/lib.rs +++ b/belt-ctr/src/lib.rs @@ -12,9 +12,9 @@ pub use cipher; use belt_block::BeltBlock; use cipher::{ - consts::U16, crypto_common::InnerUser, generic_array::GenericArray, AlgorithmName, - BlockDecrypt, BlockEncrypt, BlockSizeUser, InnerIvInit, Iv, IvSizeUser, IvState, - StreamCipherCore, StreamCipherCoreWrapper, StreamCipherSeekCore, StreamClosure, + array::Array, consts::U16, crypto_common::InnerUser, AlgorithmName, BlockCipherDecrypt, + BlockCipherEncrypt, BlockSizeUser, InnerIvInit, Iv, IvSizeUser, IvState, StreamCipherCore, + StreamCipherCoreWrapper, StreamCipherSeekCore, StreamClosure, }; use core::fmt; @@ -26,7 +26,7 @@ pub type BeltCtr = StreamCipherCoreWrapper>; /// Block-level BelT CTR pub struct BeltCtrCore where - C: BlockEncrypt + BlockSizeUser, + C: BlockCipherEncrypt + BlockSizeUser, { cipher: C, s: u128, @@ -35,7 +35,7 @@ where impl StreamCipherCore for BeltCtrCore where - C: BlockEncrypt + BlockSizeUser, + C: BlockCipherEncrypt + BlockSizeUser, { fn remaining_blocks(&self) -> Option { let used = self.s.wrapping_sub(self.s_init); @@ -50,7 +50,7 @@ where impl StreamCipherSeekCore for BeltCtrCore where - C: BlockEncrypt + BlockSizeUser, + C: BlockCipherEncrypt + BlockSizeUser, { type Counter = u128; @@ -65,32 +65,32 @@ where impl BlockSizeUser for BeltCtrCore where - C: BlockEncrypt + BlockSizeUser, + C: BlockCipherEncrypt + BlockSizeUser, { type BlockSize = C::BlockSize; } impl IvSizeUser for BeltCtrCore where - C: BlockEncrypt + BlockSizeUser, + C: BlockCipherEncrypt + BlockSizeUser, { type IvSize = C::BlockSize; } impl InnerUser for BeltCtrCore where - C: BlockEncrypt + BlockSizeUser, + C: BlockCipherEncrypt + BlockSizeUser, { type Inner = C; } impl InnerIvInit for BeltCtrCore where - C: BlockEncrypt + BlockSizeUser, + C: BlockCipherEncrypt + BlockSizeUser, { #[inline] fn inner_iv_init(cipher: C, iv: &Iv) -> Self { - let mut t = GenericArray::default(); + let mut t = Array::default(); cipher.encrypt_block_b2b(iv, &mut t); let s = u128::from_le_bytes(t.into()); Self { @@ -103,7 +103,7 @@ where impl IvState for BeltCtrCore where - C: BlockEncrypt + BlockDecrypt + BlockSizeUser, + C: BlockCipherEncrypt + BlockCipherDecrypt + BlockSizeUser, { fn iv_state(&self) -> Iv { let mut t = self.s.to_le_bytes().into(); @@ -114,7 +114,7 @@ where impl AlgorithmName for BeltCtrCore where - C: BlockEncrypt + BlockDecrypt + BlockSizeUser + AlgorithmName, + C: BlockCipherEncrypt + BlockCipherDecrypt + BlockSizeUser + AlgorithmName, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("BeltCtr<")?; @@ -123,7 +123,7 @@ where } } -impl> fmt::Debug for BeltCtrCore { +impl> fmt::Debug for BeltCtrCore { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("BeltCtrCore { ... }") diff --git a/cbc/Cargo.toml b/cbc/Cargo.toml index 6fc68e2..77443ff 100644 --- a/cbc/Cargo.toml +++ b/cbc/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "cbc" -version = "0.1.2" +version = "0.2.0-pre" description = "Cipher Block Chaining (CBC) block cipher mode of operation" 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/cbc" repository = "https://github.com/RustCrypto/block-modes" @@ -13,11 +13,11 @@ keywords = ["crypto", "block-mode", "ciphers"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "0.4.2" +cipher = "=0.5.0-pre.4" [dev-dependencies] -aes = "0.8" -cipher = { version = "0.4.2", features = ["dev"] } +aes = "=0.9.0-pre" +cipher = { version = "=0.5.0-pre.4", features = ["dev"] } hex-literal = "0.3.3" [features] diff --git a/cbc/src/decrypt.rs b/cbc/src/decrypt.rs index 4d1635e..77fd40b 100644 --- a/cbc/src/decrypt.rs +++ b/cbc/src/decrypt.rs @@ -1,10 +1,10 @@ use crate::xor; use cipher::{ - crypto_common::{InnerUser, IvSizeUser}, - generic_array::{ArrayLength, GenericArray}, + array::Array, + crypto_common::{BlockSizes, InnerUser, IvSizeUser}, inout::InOut, - AlgorithmName, Block, BlockBackend, BlockCipher, BlockClosure, BlockDecryptMut, BlockSizeUser, - InnerIvInit, Iv, IvState, ParBlocks, ParBlocksSizeUser, + AlgorithmName, Block, BlockBackend, BlockCipher, BlockCipherDecrypt, BlockClosure, + BlockModeDecrypt, BlockSizeUser, InnerIvInit, Iv, IvState, ParBlocks, ParBlocksSizeUser, }; use core::fmt; @@ -15,7 +15,7 @@ use cipher::zeroize::{Zeroize, ZeroizeOnDrop}; #[derive(Clone)] pub struct Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { cipher: C, iv: Block, @@ -23,38 +23,38 @@ where impl BlockSizeUser for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { type BlockSize = C::BlockSize; } -impl BlockDecryptMut for Decryptor +impl BlockModeDecrypt for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { - fn decrypt_with_backend_mut(&mut self, f: impl BlockClosure) { + fn decrypt_with_backend(&mut self, f: impl BlockClosure) { let Self { cipher, iv } = self; - cipher.decrypt_with_backend_mut(Closure { iv, f }) + cipher.decrypt_with_backend(Closure { iv, f }) } } impl InnerUser for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { type Inner = C; } impl IvSizeUser for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { type IvSize = C::BlockSize; } impl InnerIvInit for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { #[inline] fn inner_iv_init(cipher: C, iv: &Iv) -> Self { @@ -67,7 +67,7 @@ where impl IvState for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { #[inline] fn iv_state(&self) -> Iv { @@ -77,7 +77,7 @@ where impl AlgorithmName for Decryptor where - C: BlockDecryptMut + BlockCipher + AlgorithmName, + C: BlockCipherDecrypt + BlockCipher + AlgorithmName, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cbc::Decryptor<")?; @@ -88,7 +88,7 @@ where impl fmt::Debug for Decryptor where - C: BlockDecryptMut + BlockCipher + AlgorithmName, + C: BlockCipherDecrypt + BlockCipher + AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cbc::Decryptor<")?; @@ -99,7 +99,7 @@ where #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl Drop for Decryptor { +impl Drop for Decryptor { fn drop(&mut self) { self.iv.zeroize(); } @@ -107,20 +107,20 @@ impl Drop for Decryptor { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl ZeroizeOnDrop for Decryptor {} +impl ZeroizeOnDrop for Decryptor {} struct Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { - iv: &'a mut GenericArray, + iv: &'a mut Array, f: BC, } impl<'a, BS, BC> BlockSizeUser for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { type BlockSize = BS; @@ -128,7 +128,7 @@ where impl<'a, BS, BC> BlockClosure for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { #[inline(always)] @@ -140,16 +140,16 @@ where struct Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { - iv: &'a mut GenericArray, + iv: &'a mut Array, backend: &'a mut BK, } impl<'a, BS, BK> BlockSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type BlockSize = BS; @@ -157,7 +157,7 @@ where impl<'a, BS, BK> ParBlocksSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type ParBlocksSize = BK::ParBlocksSize; @@ -165,7 +165,7 @@ where impl<'a, BS, BK> BlockBackend for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { #[inline(always)] diff --git a/cbc/src/encrypt.rs b/cbc/src/encrypt.rs index 50284fb..2c42629 100644 --- a/cbc/src/encrypt.rs +++ b/cbc/src/encrypt.rs @@ -1,11 +1,11 @@ use crate::xor; use cipher::{ + array::Array, consts::U1, - crypto_common::{InnerUser, IvSizeUser}, - generic_array::{ArrayLength, GenericArray}, + crypto_common::{BlockSizes, InnerUser, IvSizeUser}, inout::InOut, - AlgorithmName, Block, BlockBackend, BlockCipher, BlockClosure, BlockEncryptMut, BlockSizeUser, - InnerIvInit, Iv, IvState, ParBlocksSizeUser, + AlgorithmName, Block, BlockBackend, BlockCipher, BlockCipherEncrypt, BlockClosure, + BlockModeEncrypt, BlockSizeUser, InnerIvInit, Iv, IvState, ParBlocksSizeUser, }; use core::fmt; @@ -16,7 +16,7 @@ use cipher::zeroize::{Zeroize, ZeroizeOnDrop}; #[derive(Clone)] pub struct Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { cipher: C, iv: Block, @@ -24,38 +24,38 @@ where impl BlockSizeUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type BlockSize = C::BlockSize; } -impl BlockEncryptMut for Encryptor +impl BlockModeEncrypt for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { - fn encrypt_with_backend_mut(&mut self, f: impl BlockClosure) { + fn encrypt_with_backend(&mut self, f: impl BlockClosure) { let Self { cipher, iv } = self; - cipher.encrypt_with_backend_mut(Closure { iv, f }) + cipher.encrypt_with_backend(Closure { iv, f }) } } impl InnerUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type Inner = C; } impl IvSizeUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type IvSize = C::BlockSize; } impl InnerIvInit for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] fn inner_iv_init(cipher: C, iv: &Iv) -> Self { @@ -68,7 +68,7 @@ where impl IvState for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] fn iv_state(&self) -> Iv { @@ -78,7 +78,7 @@ where impl AlgorithmName for Encryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cbc::Encryptor<")?; @@ -89,7 +89,7 @@ where impl fmt::Debug for Encryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cbc::Encryptor<")?; @@ -100,7 +100,7 @@ where #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl Drop for Encryptor { +impl Drop for Encryptor { fn drop(&mut self) { self.iv.zeroize(); } @@ -108,20 +108,20 @@ impl Drop for Encryptor { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl ZeroizeOnDrop for Encryptor {} +impl ZeroizeOnDrop for Encryptor {} struct Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { - iv: &'a mut GenericArray, + iv: &'a mut Array, f: BC, } impl<'a, BS, BC> BlockSizeUser for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { type BlockSize = BS; @@ -129,7 +129,7 @@ where impl<'a, BS, BC> BlockClosure for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { #[inline(always)] @@ -141,16 +141,16 @@ where struct Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { - iv: &'a mut GenericArray, + iv: &'a mut Array, backend: &'a mut BK, } impl<'a, BS, BK> BlockSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type BlockSize = BS; @@ -158,7 +158,7 @@ where impl<'a, BS, BK> ParBlocksSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type ParBlocksSize = U1; @@ -166,7 +166,7 @@ where impl<'a, BS, BK> BlockBackend for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { #[inline(always)] diff --git a/cbc/src/lib.rs b/cbc/src/lib.rs index 8bbc8d8..4597ed2 100644 --- a/cbc/src/lib.rs +++ b/cbc/src/lib.rs @@ -15,7 +15,7 @@ //! # Example //! ``` //! # #[cfg(feature = "block-padding")] { -//! use aes::cipher::{block_padding::Pkcs7, BlockDecryptMut, BlockEncryptMut, KeyIvInit}; +//! use aes::cipher::{block_padding::Pkcs7, BlockModeEncrypt, BlockModeDecrypt, KeyIvInit}; //! use hex_literal::hex; //! //! type Aes128CbcEnc = cbc::Encryptor; @@ -36,25 +36,25 @@ //! let pt_len = plaintext.len(); //! buf[..pt_len].copy_from_slice(&plaintext); //! let ct = Aes128CbcEnc::new(&key.into(), &iv.into()) -//! .encrypt_padded_mut::(&mut buf, pt_len) +//! .encrypt_padded::(&mut buf, pt_len) //! .unwrap(); //! assert_eq!(ct, &ciphertext[..]); //! //! let pt = Aes128CbcDec::new(&key.into(), &iv.into()) -//! .decrypt_padded_mut::(&mut buf) +//! .decrypt_padded::(&mut buf) //! .unwrap(); //! assert_eq!(pt, &plaintext); //! //! // encrypt/decrypt from buffer to buffer //! let mut buf = [0u8; 48]; //! let ct = Aes128CbcEnc::new(&key.into(), &iv.into()) -//! .encrypt_padded_b2b_mut::(&plaintext, &mut buf) +//! .encrypt_padded_b2b::(&plaintext, &mut buf) //! .unwrap(); //! assert_eq!(ct, &ciphertext[..]); //! //! let mut buf = [0u8; 48]; //! let pt = Aes128CbcDec::new(&key.into(), &iv.into()) -//! .decrypt_padded_b2b_mut::(&ct, &mut buf) +//! .decrypt_padded_b2b::(&ct, &mut buf) //! .unwrap(); //! assert_eq!(pt, &plaintext); //! # } @@ -64,7 +64,7 @@ //! convenience methods: //! ``` //! # #[cfg(all(feature = "alloc", feature = "block-padding"))] { -//! # use aes::cipher::{block_padding::Pkcs7, BlockDecryptMut, BlockEncryptMut, KeyIvInit}; +//! # use aes::cipher::{block_padding::Pkcs7, BlockModeEncrypt, BlockModeDecrypt, KeyIvInit}; //! # use hex_literal::hex; //! # type Aes128CbcEnc = cbc::Encryptor; //! # type Aes128CbcDec = cbc::Decryptor; @@ -77,10 +77,10 @@ //! # "14cfb228a710de4171e396e7b6cf859e" //! # ); //! let res = Aes128CbcEnc::new(&key.into(), &iv.into()) -//! .encrypt_padded_vec_mut::(&plaintext); +//! .encrypt_padded_vec::(&plaintext); //! assert_eq!(res[..], ciphertext[..]); //! let res = Aes128CbcDec::new(&key.into(), &iv.into()) -//! .decrypt_padded_vec_mut::(&res) +//! .decrypt_padded_vec::(&res) //! .unwrap(); //! assert_eq!(res[..], plaintext[..]); //! # } @@ -104,10 +104,10 @@ pub use cipher; pub use decrypt::Decryptor; pub use encrypt::Encryptor; -use cipher::generic_array::{ArrayLength, GenericArray}; +use cipher::array::{Array, ArraySize}; #[inline(always)] -fn xor>(out: &mut GenericArray, buf: &GenericArray) { +fn xor(out: &mut Array, buf: &Array) { for (a, b) in out.iter_mut().zip(buf) { *a ^= *b; } diff --git a/cfb-mode/Cargo.toml b/cfb-mode/Cargo.toml index c94749e..182c855 100644 --- a/cfb-mode/Cargo.toml +++ b/cfb-mode/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "cfb-mode" -version = "0.8.2" +version = "0.9.0-pre" description = "Cipher Feedback (CFB) block cipher mode of operation" 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/cfb-mode" repository = "https://github.com/RustCrypto/block-modes" @@ -13,12 +13,12 @@ keywords = ["crypto", "block-mode", "stream-cipher", "ciphers"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "0.4.2" +cipher = "=0.5.0-pre.4" [dev-dependencies] -aes = "0.8" -belt-block = "0.1" -cipher = { version = "0.4.2", features = ["dev"] } +aes = "=0.9.0-pre" +belt-block = "=0.2.0-pre" +cipher = { version = "=0.5.0-pre.4", features = ["dev"] } hex-literal = "0.3" [features] diff --git a/cfb-mode/src/decrypt.rs b/cfb-mode/src/decrypt.rs index 7e7c1d6..2af7eeb 100644 --- a/cfb-mode/src/decrypt.rs +++ b/cfb-mode/src/decrypt.rs @@ -1,10 +1,10 @@ use cipher::{ - crypto_common::{InnerUser, IvSizeUser}, - generic_array::{ArrayLength, GenericArray}, + array::Array, + crypto_common::{BlockSizes, InnerUser, IvSizeUser}, inout::InOut, - AlgorithmName, AsyncStreamCipher, Block, BlockBackend, BlockCipher, BlockClosure, BlockDecrypt, - BlockDecryptMut, BlockEncryptMut, BlockSizeUser, InnerIvInit, Iv, IvState, ParBlocks, - ParBlocksSizeUser, Unsigned, + AlgorithmName, AsyncStreamCipher, Block, BlockBackend, BlockCipher, BlockCipherDecrypt, + BlockCipherEncrypt, BlockClosure, BlockModeDecrypt, BlockSizeUser, InnerIvInit, Iv, IvState, + ParBlocks, ParBlocksSizeUser, Unsigned, }; use core::fmt; @@ -15,7 +15,7 @@ use cipher::zeroize::{Zeroize, ZeroizeOnDrop}; #[derive(Clone)] pub struct Decryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { cipher: C, iv: Block, @@ -25,7 +25,7 @@ where #[derive(Clone)] pub struct BufDecryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { cipher: C, iv: Block, @@ -34,7 +34,7 @@ where impl BufDecryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { /// Decrypt a buffer in multiple parts. pub fn decrypt(&mut self, mut data: &mut [u8]) { @@ -50,12 +50,12 @@ where data = right; let mut iv = self.iv.clone(); xor_set2(left, &mut iv[self.pos..]); - self.cipher.encrypt_block_mut(&mut iv); + self.cipher.encrypt_block(&mut iv); let mut chunks = data.chunks_exact_mut(bs); for chunk in &mut chunks { xor_set2(chunk, iv.as_mut_slice()); - self.cipher.encrypt_block_mut(&mut iv); + self.cipher.encrypt_block(&mut iv); } let rem = chunks.into_remainder(); @@ -81,78 +81,78 @@ where impl BlockSizeUser for Decryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type BlockSize = C::BlockSize; } -impl BlockDecryptMut for Decryptor +impl BlockModeDecrypt for Decryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { - fn decrypt_with_backend_mut(&mut self, f: impl BlockClosure) { + fn decrypt_with_backend(&mut self, f: impl BlockClosure) { let Self { cipher, iv } = self; - cipher.encrypt_with_backend_mut(Closure { iv, f }) + cipher.encrypt_with_backend(Closure { iv, f }) } } -impl AsyncStreamCipher for Decryptor where C: BlockEncryptMut + BlockCipher {} +impl AsyncStreamCipher for Decryptor where C: BlockCipherEncrypt + BlockCipher {} impl InnerUser for Decryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type Inner = C; } impl InnerUser for BufDecryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type Inner = C; } impl IvSizeUser for Decryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type IvSize = C::BlockSize; } impl IvSizeUser for BufDecryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type IvSize = C::BlockSize; } impl InnerIvInit for Decryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] - fn inner_iv_init(mut cipher: C, iv: &Iv) -> Self { + fn inner_iv_init(cipher: C, iv: &Iv) -> Self { let mut iv = iv.clone(); - cipher.encrypt_block_mut(&mut iv); + cipher.encrypt_block(&mut iv); Self { cipher, iv } } } impl InnerIvInit for BufDecryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] - fn inner_iv_init(mut cipher: C, iv: &Iv) -> Self { + fn inner_iv_init(cipher: C, iv: &Iv) -> Self { let mut iv = iv.clone(); - cipher.encrypt_block_mut(&mut iv); + cipher.encrypt_block(&mut iv); Self { cipher, iv, pos: 0 } } } impl IvState for Decryptor where - C: BlockEncryptMut + BlockDecrypt + BlockCipher, + C: BlockCipherEncrypt + BlockCipherDecrypt + BlockCipher, { #[inline] fn iv_state(&self) -> Iv { @@ -164,7 +164,7 @@ where impl AlgorithmName for Decryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cfb::Decryptor<")?; @@ -175,7 +175,7 @@ where impl AlgorithmName for BufDecryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cfb::BufDecryptor<")?; @@ -186,7 +186,7 @@ where impl fmt::Debug for Decryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cfb::Decryptor<")?; @@ -197,7 +197,7 @@ where impl fmt::Debug for BufDecryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cfb::BufDecryptor<")?; @@ -208,7 +208,7 @@ where #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl Drop for Decryptor { +impl Drop for Decryptor { fn drop(&mut self) { self.iv.zeroize(); } @@ -216,7 +216,7 @@ impl Drop for Decryptor { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl Drop for BufDecryptor { +impl Drop for BufDecryptor { fn drop(&mut self) { self.iv.zeroize(); } @@ -224,24 +224,24 @@ impl Drop for BufDecryptor { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl ZeroizeOnDrop for Decryptor {} +impl ZeroizeOnDrop for Decryptor {} #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl ZeroizeOnDrop for BufDecryptor {} +impl ZeroizeOnDrop for BufDecryptor {} struct Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { - iv: &'a mut GenericArray, + iv: &'a mut Array, f: BC, } impl<'a, BS, BC> BlockSizeUser for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { type BlockSize = BS; @@ -249,7 +249,7 @@ where impl<'a, BS, BC> BlockClosure for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { #[inline(always)] @@ -261,16 +261,16 @@ where struct Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { - iv: &'a mut GenericArray, + iv: &'a mut Array, backend: &'a mut BK, } impl<'a, BS, BK> BlockSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type BlockSize = BS; @@ -278,7 +278,7 @@ where impl<'a, BS, BK> ParBlocksSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type ParBlocksSize = BK::ParBlocksSize; @@ -286,7 +286,7 @@ where impl<'a, BS, BK> BlockBackend for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { #[inline(always)] diff --git a/cfb-mode/src/encrypt.rs b/cfb-mode/src/encrypt.rs index cde30b8..b974fb0 100644 --- a/cfb-mode/src/encrypt.rs +++ b/cfb-mode/src/encrypt.rs @@ -1,10 +1,11 @@ use cipher::{ + array::Array, consts::U1, - crypto_common::{InnerUser, IvSizeUser}, - generic_array::{ArrayLength, GenericArray}, + crypto_common::{BlockSizes, InnerUser, IvSizeUser}, inout::InOut, - AlgorithmName, AsyncStreamCipher, Block, BlockBackend, BlockCipher, BlockClosure, BlockDecrypt, - BlockEncryptMut, BlockSizeUser, InnerIvInit, Iv, IvState, ParBlocksSizeUser, Unsigned, + AlgorithmName, AsyncStreamCipher, Block, BlockBackend, BlockCipher, BlockCipherDecrypt, + BlockCipherEncrypt, BlockClosure, BlockModeEncrypt, BlockSizeUser, InnerIvInit, Iv, IvState, + ParBlocksSizeUser, Unsigned, }; use core::fmt; @@ -15,7 +16,7 @@ use cipher::zeroize::{Zeroize, ZeroizeOnDrop}; #[derive(Clone)] pub struct Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { cipher: C, iv: Block, @@ -25,7 +26,7 @@ where #[derive(Clone)] pub struct BufEncryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { cipher: C, iv: Block, @@ -34,7 +35,7 @@ where impl BufEncryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { /// Encrypt a buffer in multiple parts. pub fn encrypt(&mut self, mut data: &mut [u8]) { @@ -51,12 +52,12 @@ where data = right; let mut iv = self.iv.clone(); xor_set1(left, &mut iv[self.pos..]); - self.cipher.encrypt_block_mut(&mut iv); + self.cipher.encrypt_block(&mut iv); let mut chunks = data.chunks_exact_mut(bs); for chunk in &mut chunks { xor_set1(chunk, iv.as_mut_slice()); - self.cipher.encrypt_block_mut(&mut iv); + self.cipher.encrypt_block(&mut iv); } let rem = chunks.into_remainder(); @@ -82,78 +83,78 @@ where impl BlockSizeUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type BlockSize = C::BlockSize; } -impl BlockEncryptMut for Encryptor +impl BlockModeEncrypt for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { - fn encrypt_with_backend_mut(&mut self, f: impl BlockClosure) { + fn encrypt_with_backend(&mut self, f: impl BlockClosure) { let Self { cipher, iv } = self; - cipher.encrypt_with_backend_mut(Closure { iv, f }) + cipher.encrypt_with_backend(Closure { iv, f }) } } -impl AsyncStreamCipher for Encryptor where C: BlockEncryptMut + BlockCipher {} +impl AsyncStreamCipher for Encryptor where C: BlockCipherEncrypt + BlockCipher {} impl InnerUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type Inner = C; } impl InnerUser for BufEncryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type Inner = C; } impl IvSizeUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type IvSize = C::BlockSize; } impl IvSizeUser for BufEncryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type IvSize = C::BlockSize; } impl InnerIvInit for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] - fn inner_iv_init(mut cipher: C, iv: &Iv) -> Self { + fn inner_iv_init(cipher: C, iv: &Iv) -> Self { let mut iv = iv.clone(); - cipher.encrypt_block_mut(&mut iv); + cipher.encrypt_block(&mut iv); Self { cipher, iv } } } impl InnerIvInit for BufEncryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] - fn inner_iv_init(mut cipher: C, iv: &Iv) -> Self { + fn inner_iv_init(cipher: C, iv: &Iv) -> Self { let mut iv = iv.clone(); - cipher.encrypt_block_mut(&mut iv); + cipher.encrypt_block(&mut iv); Self { cipher, iv, pos: 0 } } } impl IvState for Encryptor where - C: BlockEncryptMut + BlockDecrypt + BlockCipher, + C: BlockCipherEncrypt + BlockCipherDecrypt + BlockCipher, { #[inline] fn iv_state(&self) -> Iv { @@ -165,7 +166,7 @@ where impl AlgorithmName for BufEncryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cfb::BufEncryptor<")?; @@ -176,7 +177,7 @@ where impl AlgorithmName for Encryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cfb::Encryptor<")?; @@ -187,7 +188,7 @@ where impl fmt::Debug for Encryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cfb::Encryptor<")?; @@ -198,7 +199,7 @@ where impl fmt::Debug for BufEncryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cfb::BufEncryptor<")?; @@ -209,7 +210,7 @@ where #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl Drop for Encryptor { +impl Drop for Encryptor { fn drop(&mut self) { self.iv.zeroize(); } @@ -217,7 +218,7 @@ impl Drop for Encryptor { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl Drop for BufEncryptor { +impl Drop for BufEncryptor { fn drop(&mut self) { self.iv.zeroize(); } @@ -225,24 +226,24 @@ impl Drop for BufEncryptor { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl ZeroizeOnDrop for Encryptor {} +impl ZeroizeOnDrop for Encryptor {} #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl ZeroizeOnDrop for BufEncryptor {} +impl ZeroizeOnDrop for BufEncryptor {} struct Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { - iv: &'a mut GenericArray, + iv: &'a mut Array, f: BC, } impl<'a, BS, BC> BlockSizeUser for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { type BlockSize = BS; @@ -250,7 +251,7 @@ where impl<'a, BS, BC> BlockClosure for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { #[inline(always)] @@ -262,16 +263,16 @@ where struct Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { - iv: &'a mut GenericArray, + iv: &'a mut Array, backend: &'a mut BK, } impl<'a, BS, BK> BlockSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type BlockSize = BS; @@ -279,7 +280,7 @@ where impl<'a, BS, BK> ParBlocksSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type ParBlocksSize = U1; @@ -287,7 +288,7 @@ where impl<'a, BS, BK> BlockBackend for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { #[inline(always)] diff --git a/cfb8/Cargo.toml b/cfb8/Cargo.toml index 1178d9f..0415493 100644 --- a/cfb8/Cargo.toml +++ b/cfb8/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "cfb8" -version = "0.8.1" +version = "0.9.0-pre" description = "Cipher Feedback with eight bit feedback (CFB-8) block cipher mode of operation" 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/cfb8" repository = "https://github.com/RustCrypto/block-modes" @@ -13,11 +13,11 @@ keywords = ["crypto", "block-mode", "stream-cipher", "ciphers"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "0.4.2" +cipher = "=0.5.0-pre.4" [dev-dependencies] -aes = "0.8" -cipher = { version = "0.4.2", features = ["dev"] } +aes = "=0.9.0-pre" +cipher = { version = "=0.5.0-pre.4", features = ["dev"] } hex-literal = "0.3" [features] diff --git a/cfb8/src/decrypt.rs b/cfb8/src/decrypt.rs index 31362fc..a69f673 100644 --- a/cfb8/src/decrypt.rs +++ b/cfb8/src/decrypt.rs @@ -1,10 +1,11 @@ use cipher::{ + array::Array, consts::U1, - crypto_common::{InnerUser, IvSizeUser}, - generic_array::{ArrayLength, GenericArray}, + crypto_common::{BlockSizes, InnerUser, IvSizeUser}, inout::InOut, - AlgorithmName, AsyncStreamCipher, Block, BlockBackend, BlockCipher, BlockClosure, - BlockDecryptMut, BlockEncryptMut, BlockSizeUser, InnerIvInit, Iv, IvState, ParBlocksSizeUser, + AlgorithmName, AsyncStreamCipher, Block, BlockBackend, BlockCipher, BlockCipherDecrypt, + BlockCipherEncrypt, BlockClosure, BlockModeDecrypt, BlockSizeUser, InnerIvInit, Iv, IvState, + ParBlocksSizeUser, }; use core::fmt; @@ -15,7 +16,7 @@ use cipher::zeroize::{Zeroize, ZeroizeOnDrop}; #[derive(Clone)] pub struct Decryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { cipher: C, iv: Block, @@ -23,40 +24,40 @@ where impl BlockSizeUser for Decryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type BlockSize = U1; } -impl BlockDecryptMut for Decryptor +impl BlockModeDecrypt for Decryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { - fn decrypt_with_backend_mut(&mut self, f: impl BlockClosure) { + fn decrypt_with_backend(&mut self, f: impl BlockClosure) { let Self { cipher, iv } = self; - cipher.encrypt_with_backend_mut(Closure { iv, f }) + cipher.encrypt_with_backend(Closure { iv, f }) } } -impl AsyncStreamCipher for Decryptor {} +impl AsyncStreamCipher for Decryptor {} impl InnerUser for Decryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type Inner = C; } impl IvSizeUser for Decryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type IvSize = C::BlockSize; } impl InnerIvInit for Decryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] fn inner_iv_init(cipher: C, iv: &Iv) -> Self { @@ -67,7 +68,7 @@ where impl IvState for Decryptor where - C: BlockEncryptMut + BlockDecryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipherDecrypt + BlockCipher, { #[inline] fn iv_state(&self) -> Iv { @@ -77,7 +78,7 @@ where impl AlgorithmName for Decryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cfb8::Decryptor<")?; @@ -88,7 +89,7 @@ where impl fmt::Debug for Decryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cfb8::Decryptor<")?; @@ -99,7 +100,7 @@ where #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl Drop for Decryptor { +impl Drop for Decryptor { fn drop(&mut self) { self.iv.zeroize(); } @@ -107,20 +108,20 @@ impl Drop for Decryptor { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl ZeroizeOnDrop for Decryptor {} +impl ZeroizeOnDrop for Decryptor {} struct Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { - iv: &'a mut GenericArray, + iv: &'a mut Array, f: BC, } impl<'a, BS, BC> BlockSizeUser for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { type BlockSize = BS; @@ -128,7 +129,7 @@ where impl<'a, BS, BC> BlockClosure for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { #[inline(always)] @@ -140,16 +141,16 @@ where struct Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { - iv: &'a mut GenericArray, + iv: &'a mut Array, backend: &'a mut BK, } impl<'a, BS, BK> BlockSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type BlockSize = U1; @@ -157,7 +158,7 @@ where impl<'a, BS, BK> ParBlocksSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type ParBlocksSize = U1; @@ -165,7 +166,7 @@ where impl<'a, BS, BK> BlockBackend for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { #[inline(always)] @@ -173,7 +174,7 @@ where let mut t = self.iv.clone(); self.backend.proc_block((&mut t).into()); let r = block.get(0).clone_in(); - block.xor_in2out(GenericArray::from_slice(&t[..1])); + block.xor_in2out(Array::from_slice(&t[..1])); let n = self.iv.len(); for i in 0..n - 1 { self.iv[i] = self.iv[i + 1]; diff --git a/cfb8/src/encrypt.rs b/cfb8/src/encrypt.rs index 54c4c2a..ea15ead 100644 --- a/cfb8/src/encrypt.rs +++ b/cfb8/src/encrypt.rs @@ -1,10 +1,10 @@ use cipher::{ + array::Array, consts::U1, - crypto_common::{InnerUser, IvSizeUser}, - generic_array::{ArrayLength, GenericArray}, + crypto_common::{BlockSizes, InnerUser, IvSizeUser}, inout::InOut, - AlgorithmName, AsyncStreamCipher, Block, BlockBackend, BlockCipher, BlockClosure, - BlockEncryptMut, BlockSizeUser, InnerIvInit, Iv, IvState, ParBlocksSizeUser, + AlgorithmName, AsyncStreamCipher, Block, BlockBackend, BlockCipher, BlockCipherEncrypt, + BlockClosure, BlockModeEncrypt, BlockSizeUser, InnerIvInit, Iv, IvState, ParBlocksSizeUser, }; use core::fmt; @@ -15,7 +15,7 @@ use cipher::zeroize::{Zeroize, ZeroizeOnDrop}; #[derive(Clone)] pub struct Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { cipher: C, iv: Block, @@ -23,40 +23,40 @@ where impl BlockSizeUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type BlockSize = U1; } -impl BlockEncryptMut for Encryptor +impl BlockModeEncrypt for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { - fn encrypt_with_backend_mut(&mut self, f: impl BlockClosure) { + fn encrypt_with_backend(&mut self, f: impl BlockClosure) { let Self { cipher, iv } = self; - cipher.encrypt_with_backend_mut(Closure { iv, f }) + cipher.encrypt_with_backend(Closure { iv, f }) } } -impl AsyncStreamCipher for Encryptor {} +impl AsyncStreamCipher for Encryptor {} impl InnerUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type Inner = C; } impl IvSizeUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type IvSize = C::BlockSize; } impl InnerIvInit for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] fn inner_iv_init(cipher: C, iv: &Iv) -> Self { @@ -67,7 +67,7 @@ where impl IvState for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] fn iv_state(&self) -> Iv { @@ -77,7 +77,7 @@ where impl AlgorithmName for Encryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cfb8::Encryptor<")?; @@ -88,7 +88,7 @@ where impl fmt::Debug for Encryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("cfb8::Encryptor<")?; @@ -99,7 +99,7 @@ where #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl Drop for Encryptor { +impl Drop for Encryptor { fn drop(&mut self) { self.iv.zeroize(); } @@ -107,20 +107,20 @@ impl Drop for Encryptor { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl ZeroizeOnDrop for Encryptor {} +impl ZeroizeOnDrop for Encryptor {} struct Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { - iv: &'a mut GenericArray, + iv: &'a mut Array, f: BC, } impl<'a, BS, BC> BlockSizeUser for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { type BlockSize = BS; @@ -128,7 +128,7 @@ where impl<'a, BS, BC> BlockClosure for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { #[inline(always)] @@ -140,16 +140,16 @@ where struct Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { - iv: &'a mut GenericArray, + iv: &'a mut Array, backend: &'a mut BK, } impl<'a, BS, BK> BlockSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type BlockSize = U1; @@ -157,7 +157,7 @@ where impl<'a, BS, BK> ParBlocksSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type ParBlocksSize = U1; @@ -165,14 +165,14 @@ where impl<'a, BS, BK> BlockBackend for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { #[inline(always)] fn proc_block(&mut self, mut block: InOut<'_, '_, Block>) { let mut t = self.iv.clone(); self.backend.proc_block((&mut t).into()); - block.xor_in2out(GenericArray::from_slice(&t[..1])); + block.xor_in2out(Array::from_slice(&t[..1])); let r = block.get_out()[0]; let n = self.iv.len(); for i in 0..n - 1 { diff --git a/ctr/Cargo.toml b/ctr/Cargo.toml index 5d1fdf8..a2ba849 100644 --- a/ctr/Cargo.toml +++ b/ctr/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "ctr" -version = "0.9.2" +version = "0.10.0-pre" description = "CTR block modes of operation" 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/ctr" repository = "https://github.com/RustCrypto/block-modes" @@ -13,13 +13,13 @@ keywords = ["crypto", "block-mode", "stream-cipher", "ciphers"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "0.4.2" +cipher = "=0.5.0-pre.4" [dev-dependencies] -aes = "0.8" -magma = "0.9" -kuznyechik = "0.8" -cipher = { version = "0.4.2", features = ["dev"] } +aes = "=0.9.0-pre" +magma = "=0.10.0-pre" +kuznyechik = "=0.9.0-pre" +cipher = { version = "=0.5.0-pre.4", features = ["dev"] } hex-literal = "0.3.3" [features] diff --git a/ctr/src/backend.rs b/ctr/src/backend.rs index a94fd43..691a5dc 100644 --- a/ctr/src/backend.rs +++ b/ctr/src/backend.rs @@ -1,7 +1,7 @@ use crate::CtrFlavor; use cipher::{ - generic_array::ArrayLength, Block, BlockBackend, BlockClosure, BlockSizeUser, ParBlocks, - ParBlocksSizeUser, StreamBackend, StreamClosure, + array::ArraySize, crypto_common::BlockSizes, Block, BlockBackend, BlockClosure, BlockSizeUser, + ParBlocks, ParBlocksSizeUser, StreamBackend, StreamClosure, }; struct Backend<'a, F, B> @@ -53,7 +53,7 @@ where pub(crate) struct Closure<'a, F, BS, SC> where F: CtrFlavor, - BS: ArrayLength, + BS: ArraySize, SC: StreamClosure, { pub(crate) ctr_nonce: &'a mut F::CtrNonce, @@ -63,7 +63,7 @@ where impl<'a, F, BS, SC> BlockSizeUser for Closure<'a, F, BS, SC> where F: CtrFlavor, - BS: ArrayLength, + BS: BlockSizes, SC: StreamClosure, { type BlockSize = BS; @@ -72,7 +72,7 @@ where impl<'a, F, BS, SC> BlockClosure for Closure<'a, F, BS, SC> where F: CtrFlavor, - BS: ArrayLength, + BS: BlockSizes, SC: StreamClosure, { #[inline(always)] diff --git a/ctr/src/ctr_core.rs b/ctr/src/ctr_core.rs index c193596..ec65296 100644 --- a/ctr/src/ctr_core.rs +++ b/ctr/src/ctr_core.rs @@ -1,7 +1,7 @@ use crate::{backend::Closure, CtrFlavor}; use cipher::{ crypto_common::{InnerUser, IvSizeUser}, - AlgorithmName, BlockCipher, BlockEncryptMut, BlockSizeUser, InnerIvInit, Iv, IvState, + AlgorithmName, BlockCipher, BlockCipherEncrypt, BlockSizeUser, InnerIvInit, Iv, IvState, StreamCipherCore, StreamCipherSeekCore, StreamClosure, }; use core::fmt; @@ -12,7 +12,7 @@ use cipher::zeroize::ZeroizeOnDrop; /// Generic CTR block mode instance. pub struct CtrCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, F: CtrFlavor, { cipher: C, @@ -21,7 +21,7 @@ where impl BlockSizeUser for CtrCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, F: CtrFlavor, { type BlockSize = C::BlockSize; @@ -29,7 +29,7 @@ where impl StreamCipherCore for CtrCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, F: CtrFlavor, { #[inline] @@ -40,13 +40,13 @@ where #[inline] fn process_with_backend(&mut self, f: impl StreamClosure) { let Self { cipher, ctr_nonce } = self; - cipher.encrypt_with_backend_mut(Closure:: { ctr_nonce, f }); + cipher.encrypt_with_backend(Closure:: { ctr_nonce, f }); } } impl StreamCipherSeekCore for CtrCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, F: CtrFlavor, { type Counter = F::Backend; @@ -64,7 +64,7 @@ where impl InnerUser for CtrCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, F: CtrFlavor, { type Inner = C; @@ -72,7 +72,7 @@ where impl IvSizeUser for CtrCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, F: CtrFlavor, { type IvSize = C::BlockSize; @@ -80,7 +80,7 @@ where impl InnerIvInit for CtrCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, F: CtrFlavor, { #[inline] @@ -94,7 +94,7 @@ where impl IvState for CtrCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, F: CtrFlavor, { #[inline] @@ -105,7 +105,7 @@ where impl AlgorithmName for CtrCore where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, F: CtrFlavor, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -119,7 +119,7 @@ where impl Clone for CtrCore where - C: BlockEncryptMut + BlockCipher + Clone, + C: BlockCipherEncrypt + BlockCipher + Clone, F: CtrFlavor, { #[inline] @@ -133,7 +133,7 @@ where impl fmt::Debug for CtrCore where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, F: CtrFlavor, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -149,7 +149,7 @@ where #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] impl ZeroizeOnDrop for CtrCore where - C: BlockEncryptMut + BlockCipher + ZeroizeOnDrop, + C: BlockCipherEncrypt + BlockCipher + ZeroizeOnDrop, F: CtrFlavor, F::CtrNonce: ZeroizeOnDrop, { diff --git a/ctr/src/flavors.rs b/ctr/src/flavors.rs index 30361c8..71cc98b 100644 --- a/ctr/src/flavors.rs +++ b/ctr/src/flavors.rs @@ -1,7 +1,7 @@ //! CTR mode flavors use cipher::{ - generic_array::{ArrayLength, GenericArray}, + array::{Array, ArraySize}, Counter, }; @@ -14,7 +14,7 @@ pub use ctr32::{Ctr32BE, Ctr32LE}; pub use ctr64::{Ctr64BE, Ctr64LE}; /// Trait implemented by different CTR flavors. -pub trait CtrFlavor> { +pub trait CtrFlavor { /// Inner representation of nonce. type CtrNonce: Clone; /// Backend numeric type @@ -28,13 +28,13 @@ pub trait CtrFlavor> { fn remaining(cn: &Self::CtrNonce) -> Option; /// Generate block for given `nonce` and current counter value. - fn next_block(cn: &mut Self::CtrNonce) -> GenericArray; + fn next_block(cn: &mut Self::CtrNonce) -> Array; /// Generate block for given `nonce` and current counter value. - fn current_block(cn: &Self::CtrNonce) -> GenericArray; + fn current_block(cn: &Self::CtrNonce) -> Array; /// Initialize from bytes. - fn from_nonce(block: &GenericArray) -> Self::CtrNonce; + fn from_nonce(block: &Array) -> Self::CtrNonce; /// Convert from a backend value fn set_from_backend(cn: &mut Self::CtrNonce, v: Self::Backend); diff --git a/ctr/src/flavors/ctr128.rs b/ctr/src/flavors/ctr128.rs index ef9af96..4b1b878 100644 --- a/ctr/src/flavors/ctr128.rs +++ b/ctr/src/flavors/ctr128.rs @@ -1,7 +1,7 @@ //! 128-bit counter falvors. use super::CtrFlavor; use cipher::{ - generic_array::{ArrayLength, GenericArray}, + array::{Array, ArraySize}, typenum::{PartialDiv, PartialQuot, Unsigned, U16}, }; use core::fmt; @@ -14,12 +14,12 @@ type Chunks = PartialQuot; const CS: usize = ChunkSize::USIZE; #[derive(Clone)] -pub struct CtrNonce128> { +pub struct CtrNonce128 { ctr: u128, - nonce: GenericArray, + nonce: Array, } -impl> fmt::Debug for CtrNonce128 { +impl fmt::Debug for CtrNonce128 { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("CtrNonce128 { ... }") @@ -27,7 +27,7 @@ impl> fmt::Debug for CtrNonce128 { } #[cfg(feature = "zeroize")] -impl> Drop for CtrNonce128 { +impl Drop for CtrNonce128 { fn drop(&mut self) { self.ctr.zeroize(); self.nonce.zeroize(); @@ -35,7 +35,7 @@ impl> Drop for CtrNonce128 { } #[cfg(feature = "zeroize")] -impl> ZeroizeOnDrop for CtrNonce128 {} +impl ZeroizeOnDrop for CtrNonce128 {} /// 128-bit big endian counter flavor. #[derive(Debug)] @@ -43,8 +43,8 @@ pub enum Ctr128BE {} impl CtrFlavor for Ctr128BE where - B: ArrayLength + PartialDiv, - Chunks: ArrayLength, + B: ArraySize + PartialDiv, + Chunks: ArraySize, { type CtrNonce = CtrNonce128>; type Backend = u128; @@ -56,8 +56,8 @@ where } #[inline(always)] - fn current_block(cn: &Self::CtrNonce) -> GenericArray { - let mut block = GenericArray::::default(); + fn current_block(cn: &Self::CtrNonce) -> Array { + let mut block = Array::::default(); for i in 0..Chunks::::USIZE { let t = if i == Chunks::::USIZE - 1 { cn.ctr.wrapping_add(cn.nonce[i]).to_be_bytes() @@ -70,15 +70,15 @@ where } #[inline] - fn next_block(cn: &mut Self::CtrNonce) -> GenericArray { + fn next_block(cn: &mut Self::CtrNonce) -> Array { let block = Self::current_block(cn); cn.ctr = cn.ctr.wrapping_add(1); block } #[inline] - fn from_nonce(block: &GenericArray) -> Self::CtrNonce { - let mut nonce = GenericArray::>::default(); + fn from_nonce(block: &Array) -> Self::CtrNonce { + let mut nonce = Array::>::default(); for i in 0..Chunks::::USIZE { let chunk = block[CS * i..][..CS].try_into().unwrap(); nonce[i] = if i == Chunks::::USIZE - 1 { @@ -108,8 +108,8 @@ pub enum Ctr128LE {} impl CtrFlavor for Ctr128LE where - B: ArrayLength + PartialDiv, - Chunks: ArrayLength, + B: ArraySize + PartialDiv, + Chunks: ArraySize, { type CtrNonce = CtrNonce128>; type Backend = u128; @@ -121,8 +121,8 @@ where } #[inline(always)] - fn current_block(cn: &Self::CtrNonce) -> GenericArray { - let mut block = GenericArray::::default(); + fn current_block(cn: &Self::CtrNonce) -> Array { + let mut block = Array::::default(); for i in 0..Chunks::::USIZE { let t = if i == 0 { cn.ctr.wrapping_add(cn.nonce[i]).to_le_bytes() @@ -135,15 +135,15 @@ where } #[inline] - fn next_block(cn: &mut Self::CtrNonce) -> GenericArray { + fn next_block(cn: &mut Self::CtrNonce) -> Array { let block = Self::current_block(cn); cn.ctr = cn.ctr.wrapping_add(1); block } #[inline] - fn from_nonce(block: &GenericArray) -> Self::CtrNonce { - let mut nonce = GenericArray::>::default(); + fn from_nonce(block: &Array) -> Self::CtrNonce { + let mut nonce = Array::>::default(); for i in 0..Chunks::::USIZE { let chunk = block[CS * i..][..CS].try_into().unwrap(); nonce[i] = if i == 0 { diff --git a/ctr/src/flavors/ctr32.rs b/ctr/src/flavors/ctr32.rs index 7caa5f1..92f8a94 100644 --- a/ctr/src/flavors/ctr32.rs +++ b/ctr/src/flavors/ctr32.rs @@ -1,7 +1,7 @@ //! 32-bit counter falvors. use super::CtrFlavor; use cipher::{ - generic_array::{ArrayLength, GenericArray}, + array::{Array, ArraySize}, typenum::{PartialDiv, PartialQuot, Unsigned, U4}, }; use core::fmt; @@ -14,12 +14,12 @@ type Chunks = PartialQuot; const CS: usize = ChunkSize::USIZE; #[derive(Clone)] -pub struct CtrNonce32> { +pub struct CtrNonce32 { ctr: u32, - nonce: GenericArray, + nonce: Array, } -impl> fmt::Debug for CtrNonce32 { +impl fmt::Debug for CtrNonce32 { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("CtrNonce32 { ... }") @@ -27,7 +27,7 @@ impl> fmt::Debug for CtrNonce32 { } #[cfg(feature = "zeroize")] -impl> Drop for CtrNonce32 { +impl Drop for CtrNonce32 { fn drop(&mut self) { self.ctr.zeroize(); self.nonce.zeroize(); @@ -35,7 +35,7 @@ impl> Drop for CtrNonce32 { } #[cfg(feature = "zeroize")] -impl> ZeroizeOnDrop for CtrNonce32 {} +impl ZeroizeOnDrop for CtrNonce32 {} /// 32-bit big endian counter flavor. #[derive(Debug)] @@ -43,8 +43,8 @@ pub enum Ctr32BE {} impl CtrFlavor for Ctr32BE where - B: ArrayLength + PartialDiv, - Chunks: ArrayLength, + B: ArraySize + PartialDiv, + Chunks: ArraySize, { type CtrNonce = CtrNonce32>; type Backend = u32; @@ -56,8 +56,8 @@ where } #[inline(always)] - fn current_block(cn: &Self::CtrNonce) -> GenericArray { - let mut block = GenericArray::::default(); + fn current_block(cn: &Self::CtrNonce) -> Array { + let mut block = Array::::default(); for i in 0..Chunks::::USIZE { let t = if i == Chunks::::USIZE - 1 { cn.ctr.wrapping_add(cn.nonce[i]).to_be_bytes() @@ -70,15 +70,15 @@ where } #[inline] - fn next_block(cn: &mut Self::CtrNonce) -> GenericArray { + fn next_block(cn: &mut Self::CtrNonce) -> Array { let block = Self::current_block(cn); cn.ctr = cn.ctr.wrapping_add(1); block } #[inline] - fn from_nonce(block: &GenericArray) -> Self::CtrNonce { - let mut nonce = GenericArray::>::default(); + fn from_nonce(block: &Array) -> Self::CtrNonce { + let mut nonce = Array::>::default(); for i in 0..Chunks::::USIZE { let chunk = block[CS * i..][..CS].try_into().unwrap(); nonce[i] = if i == Chunks::::USIZE - 1 { @@ -108,8 +108,8 @@ pub enum Ctr32LE {} impl CtrFlavor for Ctr32LE where - B: ArrayLength + PartialDiv, - Chunks: ArrayLength, + B: ArraySize + PartialDiv, + Chunks: ArraySize, { type CtrNonce = CtrNonce32>; type Backend = u32; @@ -121,8 +121,8 @@ where } #[inline(always)] - fn current_block(cn: &Self::CtrNonce) -> GenericArray { - let mut block = GenericArray::::default(); + fn current_block(cn: &Self::CtrNonce) -> Array { + let mut block = Array::::default(); for i in 0..Chunks::::USIZE { let t = if i == 0 { cn.ctr.wrapping_add(cn.nonce[i]).to_le_bytes() @@ -135,15 +135,15 @@ where } #[inline] - fn next_block(cn: &mut Self::CtrNonce) -> GenericArray { + fn next_block(cn: &mut Self::CtrNonce) -> Array { let block = Self::current_block(cn); cn.ctr = cn.ctr.wrapping_add(1); block } #[inline] - fn from_nonce(block: &GenericArray) -> Self::CtrNonce { - let mut nonce = GenericArray::>::default(); + fn from_nonce(block: &Array) -> Self::CtrNonce { + let mut nonce = Array::>::default(); for i in 0..Chunks::::USIZE { let chunk = block[CS * i..][..CS].try_into().unwrap(); nonce[i] = if i == 0 { diff --git a/ctr/src/flavors/ctr64.rs b/ctr/src/flavors/ctr64.rs index 4683a44..08eb287 100644 --- a/ctr/src/flavors/ctr64.rs +++ b/ctr/src/flavors/ctr64.rs @@ -1,7 +1,7 @@ //! 64-bit counter falvors. use super::CtrFlavor; use cipher::{ - generic_array::{ArrayLength, GenericArray}, + array::{Array, ArraySize}, typenum::{PartialDiv, PartialQuot, Unsigned, U8}, }; use core::fmt; @@ -14,12 +14,12 @@ type Chunks = PartialQuot; const CS: usize = ChunkSize::USIZE; #[derive(Clone)] -pub struct CtrNonce64> { +pub struct CtrNonce64 { ctr: u64, - nonce: GenericArray, + nonce: Array, } -impl> fmt::Debug for CtrNonce64 { +impl fmt::Debug for CtrNonce64 { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("CtrNonce64 { ... }") @@ -27,7 +27,7 @@ impl> fmt::Debug for CtrNonce64 { } #[cfg(feature = "zeroize")] -impl> Drop for CtrNonce64 { +impl Drop for CtrNonce64 { fn drop(&mut self) { self.ctr.zeroize(); self.nonce.zeroize(); @@ -35,7 +35,7 @@ impl> Drop for CtrNonce64 { } #[cfg(feature = "zeroize")] -impl> ZeroizeOnDrop for CtrNonce64 {} +impl ZeroizeOnDrop for CtrNonce64 {} /// 64-bit big endian counter flavor. #[derive(Debug)] @@ -43,8 +43,8 @@ pub enum Ctr64BE {} impl CtrFlavor for Ctr64BE where - B: ArrayLength + PartialDiv, - Chunks: ArrayLength, + B: ArraySize + PartialDiv, + Chunks: ArraySize, { type CtrNonce = CtrNonce64>; type Backend = u64; @@ -56,8 +56,8 @@ where } #[inline(always)] - fn current_block(cn: &Self::CtrNonce) -> GenericArray { - let mut block = GenericArray::::default(); + fn current_block(cn: &Self::CtrNonce) -> Array { + let mut block = Array::::default(); for i in 0..Chunks::::USIZE { let t = if i == Chunks::::USIZE - 1 { cn.ctr.wrapping_add(cn.nonce[i]).to_be_bytes() @@ -70,15 +70,15 @@ where } #[inline] - fn next_block(cn: &mut Self::CtrNonce) -> GenericArray { + fn next_block(cn: &mut Self::CtrNonce) -> Array { let block = Self::current_block(cn); cn.ctr = cn.ctr.wrapping_add(1); block } #[inline] - fn from_nonce(block: &GenericArray) -> Self::CtrNonce { - let mut nonce = GenericArray::>::default(); + fn from_nonce(block: &Array) -> Self::CtrNonce { + let mut nonce = Array::>::default(); for i in 0..Chunks::::USIZE { let chunk = block[CS * i..][..CS].try_into().unwrap(); nonce[i] = if i == Chunks::::USIZE - 1 { @@ -108,8 +108,8 @@ pub enum Ctr64LE {} impl CtrFlavor for Ctr64LE where - B: ArrayLength + PartialDiv, - Chunks: ArrayLength, + B: ArraySize + PartialDiv, + Chunks: ArraySize, { type CtrNonce = CtrNonce64>; type Backend = u64; @@ -121,8 +121,8 @@ where } #[inline(always)] - fn current_block(cn: &Self::CtrNonce) -> GenericArray { - let mut block = GenericArray::::default(); + fn current_block(cn: &Self::CtrNonce) -> Array { + let mut block = Array::::default(); for i in 0..Chunks::::USIZE { let t = if i == 0 { cn.ctr.wrapping_add(cn.nonce[i]).to_le_bytes() @@ -135,15 +135,15 @@ where } #[inline] - fn next_block(cn: &mut Self::CtrNonce) -> GenericArray { + fn next_block(cn: &mut Self::CtrNonce) -> Array { let block = Self::current_block(cn); cn.ctr = cn.ctr.wrapping_add(1); block } #[inline] - fn from_nonce(block: &GenericArray) -> Self::CtrNonce { - let mut nonce = GenericArray::>::default(); + fn from_nonce(block: &Array) -> Self::CtrNonce { + let mut nonce = Array::>::default(); for i in 0..Chunks::::USIZE { let chunk = block[CS * i..][..CS].try_into().unwrap(); nonce[i] = if i == 0 { diff --git a/ctr/tests/ctr32/le.rs b/ctr/tests/ctr32/le.rs index 21bf358..6fc1276 100644 --- a/ctr/tests/ctr32/le.rs +++ b/ctr/tests/ctr32/le.rs @@ -1,8 +1,7 @@ //! Counter Mode with a 32-bit little endian counter use cipher::{ - consts::U16, generic_array::GenericArray, KeyIvInit, StreamCipher, StreamCipherSeek, - StreamCipherSeekCore, + array::Array, consts::U16, KeyIvInit, StreamCipher, StreamCipherSeek, StreamCipherSeekCore, }; use hex_literal::hex; @@ -13,7 +12,7 @@ const NONCE1: &[u8; 16] = &hex!("11111111111111111111111111111111"); const NONCE2: &[u8; 16] = &hex!("FEFFFFFF222222222222222222222222"); /// Compute nonce as used by AES-GCM-SIV -fn nonce(bytes: &[u8; 16]) -> GenericArray { +fn nonce(bytes: &[u8; 16]) -> Array { let mut n = *bytes; n[15] |= 0x80; n.into() diff --git a/ige/Cargo.toml b/ige/Cargo.toml index 396c4e4..9a2020b 100644 --- a/ige/Cargo.toml +++ b/ige/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "ige" -version = "0.1.1" +version = "0.2.0-pre" description = "Infinite Garble Extension (IGE) block cipher mode of operation" 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/ige" repository = "https://github.com/RustCrypto/block-modes" @@ -13,11 +13,11 @@ keywords = ["crypto", "block-mode", "ciphers"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "0.4.2" +cipher = "=0.5.0-pre.4" [dev-dependencies] -aes = "0.8" -cipher = { version = "0.4.2", features = ["dev"] } +aes = "=0.9.0-pre" +cipher = { version = "=0.5.0-pre.4", features = ["dev"] } hex-literal = "0.3.3" [features] diff --git a/ige/src/decrypt.rs b/ige/src/decrypt.rs index 4060cf4..17de4f1 100644 --- a/ige/src/decrypt.rs +++ b/ige/src/decrypt.rs @@ -1,11 +1,11 @@ use crate::{xor, IgeIvSize}; use cipher::{ - crypto_common::{InnerUser, IvSizeUser}, - generic_array::{sequence::Concat, ArrayLength, GenericArray}, + array::{Array, ArraySize}, + crypto_common::{BlockSizes, InnerUser, IvSizeUser}, inout::InOut, typenum::{Unsigned, U1}, - AlgorithmName, Block, BlockBackend, BlockCipher, BlockClosure, BlockDecryptMut, BlockSizeUser, - InnerIvInit, Iv, IvState, ParBlocksSizeUser, + AlgorithmName, Block, BlockBackend, BlockCipher, BlockCipherDecrypt, BlockClosure, + BlockModeDecrypt, BlockSizeUser, InnerIvInit, Iv, IvState, ParBlocksSizeUser, }; use core::{fmt, ops::Add}; @@ -16,76 +16,76 @@ use cipher::zeroize::{Zeroize, ZeroizeOnDrop}; #[derive(Clone)] pub struct Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { cipher: C, x: Block, y: Block, } -impl BlockDecryptMut for Decryptor +impl BlockModeDecrypt for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { - fn decrypt_with_backend_mut(&mut self, f: impl BlockClosure) { + fn decrypt_with_backend(&mut self, f: impl BlockClosure) { let Self { cipher, x, y } = self; - cipher.decrypt_with_backend_mut(Closure { x, y, f }) + cipher.decrypt_with_backend(Closure { x, y, f }) } } impl BlockSizeUser for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { type BlockSize = C::BlockSize; } impl InnerUser for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { type Inner = C; } impl IvSizeUser for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { type IvSize = IgeIvSize; } impl InnerIvInit for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { #[inline] fn inner_iv_init(cipher: C, iv: &Iv) -> Self { let (y, x) = iv.split_at(C::BlockSize::to_usize()); Self { cipher, - x: GenericArray::clone_from_slice(x), - y: GenericArray::clone_from_slice(y), + x: Array::clone_from_slice(x), + y: Array::clone_from_slice(y), } } } impl IvState for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { #[inline] fn iv_state(&self) -> Iv { @@ -95,9 +95,9 @@ where impl AlgorithmName for Decryptor where - C: BlockDecryptMut + BlockCipher + AlgorithmName, + C: BlockCipherDecrypt + BlockCipher + AlgorithmName, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("ige::Decryptor<")?; @@ -108,9 +108,9 @@ where impl fmt::Debug for Decryptor where - C: BlockDecryptMut + BlockCipher + AlgorithmName, + C: BlockCipherDecrypt + BlockCipher + AlgorithmName, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("ige::Decryptor<")?; @@ -123,9 +123,9 @@ where #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] impl Drop for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { fn drop(&mut self) { self.x.zeroize(); @@ -137,25 +137,25 @@ where #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] impl ZeroizeOnDrop for Decryptor where - C: BlockDecryptMut + BlockCipher + ZeroizeOnDrop, + C: BlockCipherDecrypt + BlockCipher + ZeroizeOnDrop, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { } struct Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { - x: &'a mut GenericArray, - y: &'a mut GenericArray, + x: &'a mut Array, + y: &'a mut Array, f: BC, } impl<'a, BS, BC> BlockSizeUser for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { type BlockSize = BS; @@ -163,7 +163,7 @@ where impl<'a, BS, BC> BlockClosure for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { #[inline(always)] @@ -175,17 +175,17 @@ where struct Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { - x: &'a mut GenericArray, - y: &'a mut GenericArray, + x: &'a mut Array, + y: &'a mut Array, backend: &'a mut BK, } impl<'a, BS, BK> BlockSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type BlockSize = BS; @@ -193,7 +193,7 @@ where impl<'a, BS, BK> ParBlocksSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type ParBlocksSize = U1; @@ -201,7 +201,7 @@ where impl<'a, BS, BK> BlockBackend for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { #[inline(always)] diff --git a/ige/src/encrypt.rs b/ige/src/encrypt.rs index c8fd965..6aab60d 100644 --- a/ige/src/encrypt.rs +++ b/ige/src/encrypt.rs @@ -1,11 +1,11 @@ use crate::{xor, IgeIvSize}; use cipher::{ - crypto_common::{InnerUser, IvSizeUser}, - generic_array::{sequence::Concat, ArrayLength, GenericArray}, + array::{Array, ArraySize}, + crypto_common::{BlockSizes, InnerUser, IvSizeUser}, inout::InOut, typenum::{Unsigned, U1}, - AlgorithmName, Block, BlockBackend, BlockCipher, BlockClosure, BlockEncryptMut, BlockSizeUser, - InnerIvInit, Iv, IvState, ParBlocksSizeUser, + AlgorithmName, Block, BlockBackend, BlockCipher, BlockCipherEncrypt, BlockClosure, + BlockModeEncrypt, BlockSizeUser, InnerIvInit, Iv, IvState, ParBlocksSizeUser, }; use core::{fmt, ops::Add}; @@ -16,76 +16,76 @@ use cipher::zeroize::{Zeroize, ZeroizeOnDrop}; #[derive(Clone)] pub struct Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { cipher: C, x: Block, y: Block, } -impl BlockEncryptMut for Encryptor +impl BlockModeEncrypt for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { - fn encrypt_with_backend_mut(&mut self, f: impl BlockClosure) { + fn encrypt_with_backend(&mut self, f: impl BlockClosure) { let Self { cipher, x, y } = self; - cipher.encrypt_with_backend_mut(Closure { x, y, f }) + cipher.encrypt_with_backend(Closure { x, y, f }) } } impl BlockSizeUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { type BlockSize = C::BlockSize; } impl InnerUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { type Inner = C; } impl IvSizeUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { type IvSize = IgeIvSize; } impl InnerIvInit for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { #[inline] fn inner_iv_init(cipher: C, iv: &Iv) -> Self { let (y, x) = iv.split_at(C::BlockSize::to_usize()); Self { cipher, - x: GenericArray::clone_from_slice(x), - y: GenericArray::clone_from_slice(y), + x: Array::clone_from_slice(x), + y: Array::clone_from_slice(y), } } } impl IvState for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { #[inline] fn iv_state(&self) -> Iv { @@ -95,9 +95,9 @@ where impl AlgorithmName for Encryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("ige::Encryptor<")?; @@ -108,9 +108,9 @@ where impl fmt::Debug for Encryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("ige::Encryptor<")?; @@ -123,9 +123,9 @@ where #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] impl Drop for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { fn drop(&mut self) { self.x.zeroize(); @@ -137,25 +137,25 @@ where #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] impl ZeroizeOnDrop for Encryptor where - C: BlockEncryptMut + BlockCipher + ZeroizeOnDrop, + C: BlockCipherEncrypt + BlockCipher + ZeroizeOnDrop, C::BlockSize: Add, - IgeIvSize: ArrayLength, + IgeIvSize: ArraySize, { } struct Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { - x: &'a mut GenericArray, - y: &'a mut GenericArray, + x: &'a mut Array, + y: &'a mut Array, f: BC, } impl<'a, BS, BC> BlockSizeUser for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { type BlockSize = BS; @@ -163,7 +163,7 @@ where impl<'a, BS, BC> BlockClosure for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { #[inline(always)] @@ -175,17 +175,17 @@ where struct Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { - x: &'a mut GenericArray, - y: &'a mut GenericArray, + x: &'a mut Array, + y: &'a mut Array, backend: &'a mut BK, } impl<'a, BS, BK> BlockSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type BlockSize = BS; @@ -193,7 +193,7 @@ where impl<'a, BS, BK> ParBlocksSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type ParBlocksSize = U1; @@ -201,7 +201,7 @@ where impl<'a, BS, BK> BlockBackend for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { #[inline(always)] diff --git a/ige/src/lib.rs b/ige/src/lib.rs index 9e3e3ea..1c37744 100644 --- a/ige/src/lib.rs +++ b/ige/src/lib.rs @@ -15,7 +15,7 @@ //! # Example //! ``` //! # #[cfg(feature = "block-padding")] { -//! use aes::cipher::{block_padding::Pkcs7, BlockDecryptMut, BlockEncryptMut, KeyIvInit}; +//! use aes::cipher::{block_padding::Pkcs7, BlockModeEncrypt, BlockModeDecrypt, KeyIvInit}; //! use hex_literal::hex; //! //! type Aes128IgeEnc = ige::Encryptor; @@ -36,25 +36,25 @@ //! let pt_len = plaintext.len(); //! buf[..pt_len].copy_from_slice(&plaintext); //! let ct = Aes128IgeEnc::new(&key.into(), &iv.into()) -//! .encrypt_padded_mut::(&mut buf, pt_len) +//! .encrypt_padded::(&mut buf, pt_len) //! .unwrap(); //! assert_eq!(ct, &ciphertext[..]); //! //! let pt = Aes128IgeDec::new(&key.into(), &iv.into()) -//! .decrypt_padded_mut::(&mut buf) +//! .decrypt_padded::(&mut buf) //! .unwrap(); //! assert_eq!(pt, &plaintext); //! //! // encrypt/decrypt from buffer to buffer //! let mut buf = [0u8; 48]; //! let ct = Aes128IgeEnc::new(&key.into(), &iv.into()) -//! .encrypt_padded_b2b_mut::(&plaintext, &mut buf) +//! .encrypt_padded_b2b::(&plaintext, &mut buf) //! .unwrap(); //! assert_eq!(ct, &ciphertext[..]); //! //! let mut buf = [0u8; 48]; //! let pt = Aes128IgeDec::new(&key.into(), &iv.into()) -//! .decrypt_padded_b2b_mut::(&ct, &mut buf) +//! .decrypt_padded_b2b::(&ct, &mut buf) //! .unwrap(); //! assert_eq!(pt, &plaintext); //! # } @@ -64,7 +64,7 @@ //! convenience methods: //! ``` //! # #[cfg(all(feature = "alloc", feature = "block-padding"))] { -//! # use aes::cipher::{block_padding::Pkcs7, BlockDecryptMut, BlockEncryptMut, KeyIvInit}; +//! # use aes::cipher::{block_padding::Pkcs7, BlockModeEncrypt, BlockModeDecrypt, KeyIvInit}; //! # use hex_literal::hex; //! # type Aes128IgeEnc = ige::Encryptor; //! # type Aes128IgeDec = ige::Decryptor; @@ -77,10 +77,10 @@ //! # "d9e586e4c5b8ac09f2190485a76873c2" //! # ); //! let res = Aes128IgeEnc::new(&key.into(), &iv.into()) -//! .encrypt_padded_vec_mut::(&plaintext); +//! .encrypt_padded_vec::(&plaintext); //! assert_eq!(res[..], ciphertext[..]); //! let res = Aes128IgeDec::new(&key.into(), &iv.into()) -//! .decrypt_padded_vec_mut::(&res) +//! .decrypt_padded_vec::(&res) //! .unwrap(); //! assert_eq!(res[..], plaintext[..]); //! # } @@ -104,7 +104,7 @@ pub use decrypt::Decryptor; pub use encrypt::Encryptor; use cipher::{ - generic_array::{ArrayLength, GenericArray}, + array::{Array, ArraySize}, typenum::Sum, BlockSizeUser, }; @@ -113,7 +113,7 @@ type BlockSize = ::BlockSize; type IgeIvSize = Sum, BlockSize>; #[inline(always)] -fn xor>(out: &mut GenericArray, buf: &GenericArray) { +fn xor(out: &mut Array, buf: &Array) { for (a, b) in out.iter_mut().zip(buf) { *a ^= *b; } diff --git a/ofb/Cargo.toml b/ofb/Cargo.toml index 43cc9d7..e222c2a 100644 --- a/ofb/Cargo.toml +++ b/ofb/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "ofb" -version = "0.6.1" +version = "0.7.0-pre" description = "Output Feedback][OFB] (OFB) block cipher mode of operation" 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/ofb" repository = "https://github.com/RustCrypto/block-modes" @@ -13,11 +13,11 @@ keywords = ["crypto", "block-mode", "stream-cipher", "ciphers"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "0.4.2" +cipher = "=0.5.0-pre.4" [dev-dependencies] -aes = "0.8" -cipher = { version = "0.4.2", features = ["dev"] } +aes = "=0.9.0-pre" +cipher = { version = "=0.5.0-pre.4", features = ["dev"] } hex-literal = "0.3" [features] diff --git a/ofb/src/backend.rs b/ofb/src/backend.rs index b5f9566..d2fa770 100644 --- a/ofb/src/backend.rs +++ b/ofb/src/backend.rs @@ -1,23 +1,20 @@ use cipher::{ - consts::U1, - generic_array::{ArrayLength, GenericArray}, - inout::InOut, - Block, BlockBackend, BlockClosure, BlockSizeUser, ParBlocksSizeUser, StreamBackend, - StreamClosure, + array::Array, consts::U1, crypto_common::BlockSizes, inout::InOut, Block, BlockBackend, + BlockClosure, BlockSizeUser, ParBlocksSizeUser, StreamBackend, StreamClosure, }; pub(crate) struct Closure1<'a, BS, SC> where - BS: ArrayLength, + BS: BlockSizes, SC: StreamClosure, { - pub(crate) iv: &'a mut GenericArray, + pub(crate) iv: &'a mut Array, pub(crate) f: SC, } impl<'a, BS, SC> BlockSizeUser for Closure1<'a, BS, SC> where - BS: ArrayLength, + BS: BlockSizes, SC: StreamClosure, { type BlockSize = BS; @@ -25,7 +22,7 @@ where impl<'a, BS, SC> BlockClosure for Closure1<'a, BS, SC> where - BS: ArrayLength, + BS: BlockSizes, SC: StreamClosure, { #[inline(always)] @@ -37,16 +34,16 @@ where pub(crate) struct Closure2<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { - pub(crate) iv: &'a mut GenericArray, + pub(crate) iv: &'a mut Array, pub(crate) f: BC, } impl<'a, BS, BC> BlockSizeUser for Closure2<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { type BlockSize = BS; @@ -54,7 +51,7 @@ where impl<'a, BS, BC> BlockClosure for Closure2<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { #[inline(always)] @@ -66,16 +63,16 @@ where struct Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { - iv: &'a mut GenericArray, + iv: &'a mut Array, backend: &'a mut BK, } impl<'a, BS, BK> BlockSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type BlockSize = BS; @@ -83,7 +80,7 @@ where impl<'a, BS, BK> ParBlocksSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type ParBlocksSize = U1; @@ -91,7 +88,7 @@ where impl<'a, BS, BK> BlockBackend for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { #[inline(always)] @@ -103,7 +100,7 @@ where impl<'a, BS, BK> StreamBackend for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { #[inline(always)] diff --git a/ofb/src/lib.rs b/ofb/src/lib.rs index 12d5303..0429466 100644 --- a/ofb/src/lib.rs +++ b/ofb/src/lib.rs @@ -71,9 +71,9 @@ mod backend; use cipher::{ crypto_common::{InnerUser, IvSizeUser}, - AlgorithmName, Block, BlockCipher, BlockClosure, BlockDecryptMut, BlockEncryptMut, - BlockSizeUser, InnerIvInit, Iv, IvState, StreamCipherCore, StreamCipherCoreWrapper, - StreamClosure, + AlgorithmName, Block, BlockCipher, BlockCipherEncrypt, BlockClosure, BlockModeDecrypt, + BlockModeEncrypt, BlockSizeUser, InnerIvInit, Iv, IvState, StreamCipherCore, + StreamCipherCoreWrapper, StreamClosure, }; use core::fmt; @@ -87,7 +87,7 @@ pub type Ofb = StreamCipherCoreWrapper>; #[derive(Clone)] pub struct OfbCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { cipher: C, iv: Block, @@ -95,28 +95,28 @@ where impl BlockSizeUser for OfbCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type BlockSize = C::BlockSize; } impl InnerUser for OfbCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type Inner = C; } impl IvSizeUser for OfbCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type IvSize = C::BlockSize; } impl InnerIvInit for OfbCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] fn inner_iv_init(cipher: C, iv: &Iv) -> Self { @@ -129,7 +129,7 @@ where impl IvState for OfbCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] fn iv_state(&self) -> Iv { @@ -139,7 +139,7 @@ where impl StreamCipherCore for OfbCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { fn remaining_blocks(&self) -> Option { None @@ -147,35 +147,35 @@ where fn process_with_backend(&mut self, f: impl StreamClosure) { let Self { cipher, iv } = self; - cipher.encrypt_with_backend_mut(backend::Closure1 { iv, f }); + cipher.encrypt_with_backend(backend::Closure1 { iv, f }); } } -impl BlockEncryptMut for OfbCore +impl BlockModeEncrypt for OfbCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] - fn encrypt_with_backend_mut(&mut self, f: impl BlockClosure) { + fn encrypt_with_backend(&mut self, f: impl BlockClosure) { let Self { cipher, iv } = self; - cipher.encrypt_with_backend_mut(backend::Closure2 { iv, f }) + cipher.encrypt_with_backend(backend::Closure2 { iv, f }) } } -impl BlockDecryptMut for OfbCore +impl BlockModeDecrypt for OfbCore where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] - fn decrypt_with_backend_mut(&mut self, f: impl BlockClosure) { + fn decrypt_with_backend(&mut self, f: impl BlockClosure) { let Self { cipher, iv } = self; - cipher.encrypt_with_backend_mut(backend::Closure2 { iv, f }) + cipher.encrypt_with_backend(backend::Closure2 { iv, f }) } } impl AlgorithmName for OfbCore where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("Ofb<")?; @@ -186,7 +186,7 @@ where impl fmt::Debug for OfbCore where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("OfbCore<")?; @@ -197,7 +197,7 @@ where #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl Drop for OfbCore { +impl Drop for OfbCore { fn drop(&mut self) { self.iv.zeroize(); } @@ -205,4 +205,4 @@ impl Drop for OfbCore { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl ZeroizeOnDrop for OfbCore {} +impl ZeroizeOnDrop for OfbCore {} diff --git a/pcbc/Cargo.toml b/pcbc/Cargo.toml index 6d52f4d..a2bd96a 100644 --- a/pcbc/Cargo.toml +++ b/pcbc/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "pcbc" -version = "0.1.2" +version = "0.2.0-pre" description = "Propagating Cipher Block Chaining (PCBC) block cipher mode of operation" 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/pcbc" repository = "https://github.com/RustCrypto/block-ciphers" @@ -13,11 +13,11 @@ keywords = ["crypto", "block-mode", "ciphers"] categories = ["cryptography", "no-std"] [dependencies] -cipher = "0.4.2" +cipher = "=0.5.0-pre.4" [dev-dependencies] -aes = "0.8" -cipher = { version = "0.4.2", features = ["dev"] } +aes = "=0.9.0-pre" +cipher = { version = "=0.5.0-pre.4", features = ["dev"] } hex-literal = "0.3.3" [features] diff --git a/pcbc/src/decrypt.rs b/pcbc/src/decrypt.rs index d8418b3..0c57dcf 100644 --- a/pcbc/src/decrypt.rs +++ b/pcbc/src/decrypt.rs @@ -1,11 +1,11 @@ use crate::xor; use cipher::{ + array::Array, consts::U1, - crypto_common::{InnerUser, IvSizeUser}, - generic_array::{ArrayLength, GenericArray}, + crypto_common::{BlockSizes, InnerUser, IvSizeUser}, inout::InOut, - AlgorithmName, Block, BlockBackend, BlockCipher, BlockClosure, BlockDecryptMut, BlockSizeUser, - InnerIvInit, Iv, IvState, ParBlocksSizeUser, + AlgorithmName, Block, BlockBackend, BlockCipher, BlockCipherDecrypt, BlockClosure, + BlockModeDecrypt, BlockSizeUser, InnerIvInit, Iv, IvState, ParBlocksSizeUser, }; use core::fmt; @@ -16,7 +16,7 @@ use cipher::zeroize::{Zeroize, ZeroizeOnDrop}; #[derive(Clone)] pub struct Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { cipher: C, iv: Block, @@ -24,38 +24,38 @@ where impl BlockSizeUser for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { type BlockSize = C::BlockSize; } -impl BlockDecryptMut for Decryptor +impl BlockModeDecrypt for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { - fn decrypt_with_backend_mut(&mut self, f: impl BlockClosure) { + fn decrypt_with_backend(&mut self, f: impl BlockClosure) { let Self { cipher, iv } = self; - cipher.decrypt_with_backend_mut(Closure { iv, f }) + cipher.decrypt_with_backend(Closure { iv, f }) } } impl InnerUser for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { type Inner = C; } impl IvSizeUser for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { type IvSize = C::BlockSize; } impl InnerIvInit for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { #[inline] fn inner_iv_init(cipher: C, iv: &Iv) -> Self { @@ -68,7 +68,7 @@ where impl IvState for Decryptor where - C: BlockDecryptMut + BlockCipher, + C: BlockCipherDecrypt + BlockCipher, { #[inline] fn iv_state(&self) -> Iv { @@ -78,7 +78,7 @@ where impl AlgorithmName for Decryptor where - C: BlockDecryptMut + BlockCipher + AlgorithmName, + C: BlockCipherDecrypt + BlockCipher + AlgorithmName, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("pcbc::Decryptor<")?; @@ -89,7 +89,7 @@ where impl fmt::Debug for Decryptor where - C: BlockDecryptMut + BlockCipher + AlgorithmName, + C: BlockCipherDecrypt + BlockCipher + AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("pcbc::Decryptor<")?; @@ -100,7 +100,7 @@ where #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl Drop for Decryptor { +impl Drop for Decryptor { fn drop(&mut self) { self.iv.zeroize(); } @@ -108,20 +108,20 @@ impl Drop for Decryptor { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl ZeroizeOnDrop for Decryptor {} +impl ZeroizeOnDrop for Decryptor {} struct Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { - iv: &'a mut GenericArray, + iv: &'a mut Array, f: BC, } impl<'a, BS, BC> BlockSizeUser for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { type BlockSize = BS; @@ -129,7 +129,7 @@ where impl<'a, BS, BC> BlockClosure for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { #[inline(always)] @@ -141,16 +141,16 @@ where struct Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { - iv: &'a mut GenericArray, + iv: &'a mut Array, backend: &'a mut BK, } impl<'a, BS, BK> BlockSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type BlockSize = BS; @@ -158,7 +158,7 @@ where impl<'a, BS, BK> ParBlocksSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type ParBlocksSize = U1; @@ -166,7 +166,7 @@ where impl<'a, BS, BK> BlockBackend for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { #[inline(always)] diff --git a/pcbc/src/encrypt.rs b/pcbc/src/encrypt.rs index 67bff04..2e4700e 100644 --- a/pcbc/src/encrypt.rs +++ b/pcbc/src/encrypt.rs @@ -1,11 +1,11 @@ use crate::xor; use cipher::{ + array::Array, consts::U1, - crypto_common::{InnerUser, IvSizeUser}, - generic_array::{ArrayLength, GenericArray}, + crypto_common::{BlockSizes, InnerUser, IvSizeUser}, inout::InOut, - AlgorithmName, Block, BlockBackend, BlockCipher, BlockClosure, BlockEncryptMut, BlockSizeUser, - InnerIvInit, Iv, IvState, ParBlocksSizeUser, + AlgorithmName, Block, BlockBackend, BlockCipher, BlockCipherEncrypt, BlockClosure, + BlockModeEncrypt, BlockSizeUser, InnerIvInit, Iv, IvState, ParBlocksSizeUser, }; use core::fmt; @@ -16,7 +16,7 @@ use cipher::zeroize::{Zeroize, ZeroizeOnDrop}; #[derive(Clone)] pub struct Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { cipher: C, iv: Block, @@ -24,38 +24,38 @@ where impl BlockSizeUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type BlockSize = C::BlockSize; } -impl BlockEncryptMut for Encryptor +impl BlockModeEncrypt for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { - fn encrypt_with_backend_mut(&mut self, f: impl BlockClosure) { + fn encrypt_with_backend(&mut self, f: impl BlockClosure) { let Self { cipher, iv } = self; - cipher.encrypt_with_backend_mut(Closure { iv, f }) + cipher.encrypt_with_backend(Closure { iv, f }) } } impl InnerUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type Inner = C; } impl IvSizeUser for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { type IvSize = C::BlockSize; } impl InnerIvInit for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] fn inner_iv_init(cipher: C, iv: &Iv) -> Self { @@ -68,7 +68,7 @@ where impl IvState for Encryptor where - C: BlockEncryptMut + BlockCipher, + C: BlockCipherEncrypt + BlockCipher, { #[inline] fn iv_state(&self) -> Iv { @@ -78,7 +78,7 @@ where impl AlgorithmName for Encryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("pcbc::Encryptor<")?; @@ -89,7 +89,7 @@ where impl fmt::Debug for Encryptor where - C: BlockEncryptMut + BlockCipher + AlgorithmName, + C: BlockCipherEncrypt + BlockCipher + AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("pcbc::Encryptor<")?; @@ -100,7 +100,7 @@ where #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl Drop for Encryptor { +impl Drop for Encryptor { fn drop(&mut self) { self.iv.zeroize(); } @@ -108,20 +108,20 @@ impl Drop for Encryptor { #[cfg(feature = "zeroize")] #[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl ZeroizeOnDrop for Encryptor {} +impl ZeroizeOnDrop for Encryptor {} struct Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { - iv: &'a mut GenericArray, + iv: &'a mut Array, f: BC, } impl<'a, BS, BC> BlockSizeUser for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { type BlockSize = BS; @@ -129,7 +129,7 @@ where impl<'a, BS, BC> BlockClosure for Closure<'a, BS, BC> where - BS: ArrayLength, + BS: BlockSizes, BC: BlockClosure, { #[inline(always)] @@ -141,16 +141,16 @@ where struct Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { - iv: &'a mut GenericArray, + iv: &'a mut Array, backend: &'a mut BK, } impl<'a, BS, BK> BlockSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type BlockSize = BS; @@ -158,7 +158,7 @@ where impl<'a, BS, BK> ParBlocksSizeUser for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { type ParBlocksSize = U1; @@ -166,7 +166,7 @@ where impl<'a, BS, BK> BlockBackend for Backend<'a, BS, BK> where - BS: ArrayLength, + BS: BlockSizes, BK: BlockBackend, { #[inline(always)] diff --git a/pcbc/src/lib.rs b/pcbc/src/lib.rs index b2415b4..245406c 100644 --- a/pcbc/src/lib.rs +++ b/pcbc/src/lib.rs @@ -15,7 +15,7 @@ //! # Example //! ``` //! # #[cfg(feature = "block-padding")] { -//! use aes::cipher::{block_padding::Pkcs7, BlockDecryptMut, BlockEncryptMut, KeyIvInit}; +//! use aes::cipher::{block_padding::Pkcs7, BlockModeEncrypt, BlockModeDecrypt, KeyIvInit}; //! use hex_literal::hex; //! //! type Aes128PcbcEnc = pcbc::Encryptor; @@ -36,25 +36,25 @@ //! let pt_len = plaintext.len(); //! buf[..pt_len].copy_from_slice(&plaintext); //! let ct = Aes128PcbcEnc::new(&key.into(), &iv.into()) -//! .encrypt_padded_mut::(&mut buf, pt_len) +//! .encrypt_padded::(&mut buf, pt_len) //! .unwrap(); //! assert_eq!(ct, &ciphertext[..]); //! //! let pt = Aes128PcbcDec::new(&key.into(), &iv.into()) -//! .decrypt_padded_mut::(&mut buf) +//! .decrypt_padded::(&mut buf) //! .unwrap(); //! assert_eq!(pt, &plaintext); //! //! // encrypt/decrypt from buffer to buffer //! let mut buf = vec![0u8; 48]; //! let ct = Aes128PcbcEnc::new(&key.into(), &iv.into()) -//! .encrypt_padded_b2b_mut::(&plaintext, &mut buf) +//! .encrypt_padded_b2b::(&plaintext, &mut buf) //! .unwrap(); //! assert_eq!(ct, &ciphertext[..]); //! //! let mut buf = vec![0u8; 48]; //! let pt = Aes128PcbcDec::new(&key.into(), &iv.into()) -//! .decrypt_padded_b2b_mut::(&ct, &mut buf) +//! .decrypt_padded_b2b::(&ct, &mut buf) //! .unwrap(); //! assert_eq!(pt, &plaintext); //! # } @@ -64,7 +64,7 @@ //! convenience methods: //! ``` //! # #[cfg(all(feature = "alloc", feature = "block-padding"))] { -//! # use aes::cipher::{block_padding::Pkcs7, BlockDecryptMut, BlockEncryptMut, KeyIvInit}; +//! # use aes::cipher::{block_padding::Pkcs7, BlockModeEncrypt, BlockModeDecrypt, KeyIvInit}; //! # use hex_literal::hex; //! # type Aes128PcbcEnc = pcbc::Encryptor; //! # type Aes128PcbcDec = pcbc::Decryptor; @@ -77,10 +77,10 @@ //! # "62cb0b6fa7816e254a2fc8d852fb4315" //! # ); //! let res = Aes128PcbcEnc::new(&key.into(), &iv.into()) -//! .encrypt_padded_vec_mut::(&plaintext); +//! .encrypt_padded_vec::(&plaintext); //! assert_eq!(res[..], ciphertext[..]); //! let res = Aes128PcbcDec::new(&key.into(), &iv.into()) -//! .decrypt_padded_vec_mut::(&res) +//! .decrypt_padded_vec::(&res) //! .unwrap(); //! assert_eq!(res[..], plaintext[..]); //! # } @@ -104,10 +104,10 @@ pub use cipher; pub use decrypt::Decryptor; pub use encrypt::Encryptor; -use cipher::generic_array::{ArrayLength, GenericArray}; +use cipher::array::{Array, ArraySize}; #[inline(always)] -fn xor>(out: &mut GenericArray, buf: &GenericArray) { +fn xor(out: &mut Array, buf: &Array) { for (a, b) in out.iter_mut().zip(buf) { *a ^= *b; }