From db4eb74435c3d8dd2336ad895cee3e6471519991 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Thu, 29 Feb 2024 00:15:41 -0800 Subject: [PATCH] Bump `cipher` to `0.5.0-pre.4` --- .github/workflows/aes-gcm-siv.yml | 6 +- .github/workflows/aes-gcm.yml | 6 +- .github/workflows/aes-siv.yml | 4 +- .github/workflows/ascon-aead.yml | 6 +- .github/workflows/ccm.yml | 6 +- .github/workflows/chacha20poly1305.yml | 6 +- .github/workflows/deoxys.yml | 4 +- .github/workflows/eax.yml | 4 +- .github/workflows/workspace.yml | 2 +- Cargo.lock | 181 +++++++++++++++---------- Cargo.toml | 26 ++++ aes-gcm-siv/Cargo.toml | 16 +-- aes-gcm-siv/src/lib.rs | 30 ++-- aes-gcm-siv/tests/aes128gcmsiv.rs | 2 +- aes-gcm-siv/tests/aes256gcmsiv.rs | 2 +- aes-gcm-siv/tests/common/mod.rs | 12 +- aes-gcm-siv/tests/ctr_wrap.rs | 2 +- aes-gcm/Cargo.toml | 16 +-- aes-gcm/src/lib.rs | 39 +++--- aes-gcm/tests/aes128gcm.rs | 2 +- aes-gcm/tests/aes256gcm.rs | 2 +- aes-gcm/tests/common/mod.rs | 18 +-- aes-gcm/tests/other_ivlen.rs | 6 +- aes-siv/Cargo.toml | 18 +-- aes-siv/src/lib.rs | 54 ++++---- aes-siv/src/siv.rs | 24 ++-- aes-siv/tests/aead.rs | 26 ++-- aes-siv/tests/siv.rs | 18 +-- ascon-aead/Cargo.toml | 6 +- ascon-aead/src/asconcore.rs | 24 ++-- ascon-aead/src/lib.rs | 4 +- ccm/Cargo.toml | 12 +- ccm/src/lib.rs | 65 ++++----- ccm/src/private.rs | 2 +- ccm/tests/mod.rs | 14 +- chacha20poly1305/Cargo.toml | 11 +- chacha20poly1305/src/cipher.rs | 6 +- chacha20poly1305/src/lib.rs | 46 +++---- chacha20poly1305/tests/lib.rs | 18 +-- deoxys/Cargo.toml | 8 +- deoxys/src/deoxys_bc.rs | 24 ++-- deoxys/src/lib.rs | 40 +++--- deoxys/src/modes.rs | 32 ++--- deoxys/tests/deoxys_i_128.rs | 34 ++--- deoxys/tests/deoxys_i_256.rs | 34 ++--- deoxys/tests/deoxys_ii_128.rs | 34 ++--- deoxys/tests/deoxys_ii_256.rs | 34 ++--- eax/Cargo.toml | 14 +- eax/src/lib.rs | 68 ++++++---- eax/src/online.rs | 65 +++++---- eax/src/traits.rs | 10 +- eax/tests/common/mod.rs | 12 +- 52 files changed, 623 insertions(+), 532 deletions(-) diff --git a/.github/workflows/aes-gcm-siv.yml b/.github/workflows/aes-gcm-siv.yml index 8fb6ef1a..c5c2e581 100644 --- a/.github/workflows/aes-gcm-siv.yml +++ b/.github/workflows/aes-gcm-siv.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - armv7a-none-eabi @@ -44,7 +44,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.72.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -52,7 +52,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.72.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable steps: diff --git a/.github/workflows/aes-gcm.yml b/.github/workflows/aes-gcm.yml index 9b7aa97c..c371627f 100644 --- a/.github/workflows/aes-gcm.yml +++ b/.github/workflows/aes-gcm.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - armv7a-none-eabi @@ -44,7 +44,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.72.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -52,7 +52,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.72.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable steps: diff --git a/.github/workflows/aes-siv.yml b/.github/workflows/aes-siv.yml index c8b7e61c..d2da386e 100644 --- a/.github/workflows/aes-siv.yml +++ b/.github/workflows/aes-siv.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.72.0 # MSRV - stable target: - armv7a-none-eabi @@ -42,7 +42,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.72.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/ascon-aead.yml b/.github/workflows/ascon-aead.yml index 61084f69..79d67f52 100644 --- a/.github/workflows/ascon-aead.yml +++ b/.github/workflows/ascon-aead.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - armv7a-none-eabi @@ -44,7 +44,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -52,7 +52,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable steps: diff --git a/.github/workflows/ccm.yml b/.github/workflows/ccm.yml index 122f9b94..bbe36ffe 100644 --- a/.github/workflows/ccm.yml +++ b/.github/workflows/ccm.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -43,7 +43,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.72.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -51,7 +51,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.72.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable steps: diff --git a/.github/workflows/chacha20poly1305.yml b/.github/workflows/chacha20poly1305.yml index f5929b67..1e7d049f 100644 --- a/.github/workflows/chacha20poly1305.yml +++ b/.github/workflows/chacha20poly1305.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - armv7a-none-eabi @@ -45,7 +45,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -53,7 +53,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.56.0 # MSRV + rust: 1.65.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable steps: diff --git a/.github/workflows/deoxys.yml b/.github/workflows/deoxys.yml index 62cf1ce8..40b8c2ec 100644 --- a/.github/workflows/deoxys.yml +++ b/.github/workflows/deoxys.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.72.0 # MSRV - stable target: - armv7a-none-eabi @@ -42,7 +42,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.72.0 # MSRV - stable steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/eax.yml b/.github/workflows/eax.yml index cdc97a15..4a3b506c 100644 --- a/.github/workflows/eax.yml +++ b/.github/workflows/eax.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: rust: - - 1.56.0 # MSRV + - 1.65.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -41,7 +41,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 00db0961..d321c825 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -28,6 +28,6 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: 1.70.0 + toolchain: 1.72.0 components: clippy - run: cargo clippy --all --all-features -- -D warnings diff --git a/Cargo.lock b/Cargo.lock index 53df2da8..241d62a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,29 +11,39 @@ checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" dependencies = [ "arrayvec", "blobby", - "crypto-common", + "crypto-common 0.1.6", "generic-array", - "heapless", + "heapless 0.7.16", +] + +[[package]] +name = "aead" +version = "0.6.0-pre" +source = "git+https://github.com/RustCrypto/traits.git#ea334c2f9927fcd94f7307fdd2b19b019f116af2" +dependencies = [ + "arrayvec", + "blobby", + "crypto-common 0.2.0-pre.5", + "heapless 0.8.0", ] [[package]] name = "aes" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +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 0.4.4", + "cipher 0.5.0-pre.4", "cpufeatures", ] [[package]] name = "aes-gcm" -version = "0.10.3" +version = "0.11.0-pre" dependencies = [ - "aead", + "aead 0.6.0-pre", "aes", - "cipher 0.4.4", + "cipher 0.5.0-pre.4", "ctr", "ghash", "hex-literal 0.3.4", @@ -43,11 +53,11 @@ dependencies = [ [[package]] name = "aes-gcm-siv" -version = "0.11.1" +version = "0.12.0-pre" dependencies = [ - "aead", + "aead 0.6.0-pre", "aes", - "cipher 0.4.4", + "cipher 0.5.0-pre.4", "ctr", "polyval", "subtle", @@ -58,10 +68,10 @@ dependencies = [ name = "aes-siv" version = "0.7.0" dependencies = [ - "aead", + "aead 0.6.0-pre", "aes", "blobby", - "cipher 0.4.4", + "cipher 0.5.0-pre.4", "cmac", "ctr", "dbl", @@ -90,7 +100,7 @@ dependencies = [ name = "ascon-aead" version = "0.4.2" dependencies = [ - "aead", + "aead 0.6.0-pre", "ascon", "hex-literal 0.3.4", "subtle", @@ -120,11 +130,11 @@ checksum = "847495c209977a90e8aad588b959d0ca9f5dc228096d29a6bd3defd53f35eaec" [[package]] name = "block-buffer" -version = "0.10.4" +version = "0.11.0-pre.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +checksum = "3ded684142010808eb980d9974ef794da2bcf97d13396143b1515e9f0fb4a10e" dependencies = [ - "generic-array", + "crypto-common 0.2.0-pre.5", ] [[package]] @@ -137,9 +147,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" name = "ccm" version = "0.5.0" dependencies = [ - "aead", + "aead 0.6.0-pre", "aes", - "cipher 0.4.4", + "cipher 0.5.0-pre.4", "ctr", "hex-literal 0.3.4", "subtle", @@ -153,12 +163,11 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chacha20" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" +version = "0.10.0-pre" +source = "git+https://github.com/RustCrypto/stream-ciphers.git#fea3dd013ee9c35fba56903ad44b411957de8cb2" dependencies = [ "cfg-if", - "cipher 0.4.4", + "cipher 0.5.0-pre.4", "cpufeatures", ] @@ -166,9 +175,9 @@ dependencies = [ name = "chacha20poly1305" version = "0.10.1" dependencies = [ - "aead", + "aead 0.6.0-pre", "chacha20", - "cipher 0.4.4", + "cipher 0.5.0-pre.4", "poly1305", "zeroize", ] @@ -184,22 +193,21 @@ dependencies = [ [[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 = [ - "crypto-common", + "crypto-common 0.2.0-pre.5", "inout", "zeroize", ] [[package]] name = "cmac" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8543454e3c3f5126effff9cd44d562af4e31fb8ce1cc0d3dcd8f084515dbc1aa" +version = "0.8.0-pre" +source = "git+https://github.com/baloo/MACs.git?branch=baloo/pre-releases-march-2024#0f6b6a45fe58a167b159a1a124190cab7e127652" dependencies = [ - "cipher 0.4.4", + "cipher 0.5.0-pre.4", "dbl", "digest", ] @@ -231,28 +239,38 @@ dependencies = [ ] [[package]] -name = "ctr" -version = "0.9.2" +name = "crypto-common" +version = "0.2.0-pre.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +checksum = "b7aa2ec04f5120b830272a481e8d9d8ba4dda140d2cda59b0f1110d5eb93c38e" dependencies = [ - "cipher 0.4.4", + "getrandom", + "hybrid-array", + "rand_core", +] + +[[package]] +name = "ctr" +version = "0.10.0-pre" +source = "git+https://github.com/baloo/block-modes.git?branch=baloo/bump-prereleases#743e93e9766c8e920a4fb6b4ad3c28b54dc83941" +dependencies = [ + "cipher 0.5.0-pre.4", ] [[package]] name = "dbl" -version = "0.3.2" +version = "0.4.0-pre.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd2735a791158376708f9347fe8faba9667589d82427ef3aed6794a8981de3d9" +checksum = "977125a36bcb9fcf23cec295ffd25a7499046d5ae95603cd536d4ec1e39bd673" dependencies = [ - "generic-array", + "hybrid-array", ] [[package]] name = "deoxys" version = "0.1.0" dependencies = [ - "aead", + "aead 0.6.0-pre", "aes", "hex-literal 0.3.4", "subtle", @@ -261,12 +279,12 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.7" +version = "0.11.0-pre.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +checksum = "065d93ead7c220b85d5b4be4795d8398eac4ff68b5ee63895de0a3c1fb6edf25" dependencies = [ "block-buffer", - "crypto-common", + "crypto-common 0.2.0-pre.5", "subtle", ] @@ -274,9 +292,9 @@ dependencies = [ name = "eax" version = "0.5.0" dependencies = [ - "aead", + "aead 0.6.0-pre", "aes", - "cipher 0.4.4", + "cipher 0.5.0-pre.4", "cmac", "ctr", "subtle", @@ -305,9 +323,8 @@ dependencies = [ [[package]] name = "ghash" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" +version = "0.6.0-pre" +source = "git+https://github.com/baloo/universal-hashes.git?branch=baloo/pre-releases#894cf78d058736950cc46d0e4ac134a2791d7b91" dependencies = [ "opaque-debug", "polyval", @@ -322,6 +339,15 @@ dependencies = [ "byteorder", ] +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + [[package]] name = "heapless" version = "0.7.16" @@ -329,12 +355,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db04bc24a18b9ea980628ecf00e6c0264f3c1426dac36c00cb49b6fbad8b0743" dependencies = [ "atomic-polyfill", - "hash32", + "hash32 0.2.1", "rustc_version", "spin", "stable_deref_trait", ] +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32 0.3.1", + "stable_deref_trait", +] + [[package]] name = "hex-literal" version = "0.2.2" @@ -360,13 +396,22 @@ dependencies = [ "proc-macro-hack", ] +[[package]] +name = "hybrid-array" +version = "0.2.0-rc.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87c2311a0adecbffff284aabcf1249b1485193b16e685f9ef171b1ba82979cff" +dependencies = [ + "typenum", +] + [[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 = [ - "generic-array", + "hybrid-array", ] [[package]] @@ -408,7 +453,7 @@ dependencies = [ name = "mgm" version = "0.5.0-pre.1" dependencies = [ - "aead", + "aead 0.5.2", "cfg-if", "cipher 0.3.0", "cpufeatures", @@ -426,20 +471,18 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "pmac" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa22f777eff0306a722b57833475f6ade9a8307f069358e8e808b2655d6de407" +version = "0.8.0-pre" +source = "git+https://github.com/baloo/MACs.git?branch=baloo/pre-releases-march-2024#0f6b6a45fe58a167b159a1a124190cab7e127652" dependencies = [ - "cipher 0.4.4", + "cipher 0.5.0-pre.4", "dbl", "digest", ] [[package]] name = "poly1305" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" +version = "0.9.0-pre" +source = "git+https://github.com/baloo/universal-hashes.git?branch=baloo/pre-releases#894cf78d058736950cc46d0e4ac134a2791d7b91" dependencies = [ "cpufeatures", "opaque-debug", @@ -448,9 +491,8 @@ dependencies = [ [[package]] name = "polyval" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" +version = "0.7.0-pre" +source = "git+https://github.com/baloo/universal-hashes.git?branch=baloo/pre-releases#894cf78d058736950cc46d0e4ac134a2791d7b91" dependencies = [ "cfg-if", "cpufeatures", @@ -558,11 +600,10 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "universal-hash" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +version = "0.6.0-pre" +source = "git+https://github.com/RustCrypto/traits.git?branch=master#ea334c2f9927fcd94f7307fdd2b19b019f116af2" dependencies = [ - "crypto-common", + "crypto-common 0.2.0-pre.5", "subtle", ] @@ -580,9 +621,9 @@ 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" dependencies = [ "zeroize_derive", ] diff --git a/Cargo.toml b/Cargo.toml index ff932711..307526c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,29 @@ members = [ "mgm", ] resolver = "2" + +[patch.crates-io] + +# 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" } + +# https://github.com/RustCrypto/block-modes/pull/56 +ctr = { git = "https://github.com/baloo/block-modes.git", branch = "baloo/bump-prereleases" } + +universal-hash = { git = "https://github.com/RustCrypto/traits.git", branch = "master" } + +# https://github.com/RustCrypto/MACs/pull/158 +cmac = { git = "https://github.com/baloo/MACs.git", branch = "baloo/pre-releases-march-2024" } +pmac = { git = "https://github.com/baloo/MACs.git", branch = "baloo/pre-releases-march-2024" } + +# https://github.com/RustCrypto/stream-ciphers/pull/345 +chacha20 = { git = "https://github.com/RustCrypto/stream-ciphers.git" } + +# https://github.com/RustCrypto/traits/pull/1531 +aead = { git = "https://github.com/RustCrypto/traits.git" } + +# https://github.com/RustCrypto/universal-hashes/pull/196 +ghash = { git = "https://github.com/baloo/universal-hashes.git", branch = "baloo/pre-releases" } +polyval = { git = "https://github.com/baloo/universal-hashes.git", branch = "baloo/pre-releases" } +poly1305 = { git = "https://github.com/baloo/universal-hashes.git", branch = "baloo/pre-releases" } + diff --git a/aes-gcm-siv/Cargo.toml b/aes-gcm-siv/Cargo.toml index 46e9a3b0..42c70cf8 100644 --- a/aes-gcm-siv/Cargo.toml +++ b/aes-gcm-siv/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aes-gcm-siv" -version = "0.11.1" +version = "0.12.0-pre" description = """ Pure Rust implementation of the AES-GCM-SIV Misuse-Resistant Authenticated Encryption Cipher (RFC 8452) with optional architecture-specific @@ -14,19 +14,19 @@ documentation = "https://docs.rs/aes-gcm-siv" repository = "https://github.com/RustCrypto/AEADs" keywords = ["aead", "aes", "aes-gcm", "encryption", "siv"] categories = ["cryptography", "no-std"] -rust-version = "1.56" +rust-version = "1.65" [dependencies] -aead = { version = "0.5", default-features = false } -aes = { version = "0.8", optional = true } -cipher = "0.4" -ctr = "0.9" -polyval = { version = "0.6", default-features = false } +aead = { version = "=0.6.0-pre", default-features = false } +aes = { version = "=0.9.0-pre", optional = true } +cipher = "0.5.0-pre.4" +ctr = "=0.10.0-pre" +polyval = { version = "=0.7.0-pre", default-features = false } subtle = { version = "2", default-features = false } zeroize = { version = "1", default-features = false } [dev-dependencies] -aead = { version = "0.5", features = ["dev"], default-features = false } +aead = { version = "=0.6.0-pre", features = ["dev"], default-features = false } [features] default = ["aes", "alloc", "getrandom"] diff --git a/aes-gcm-siv/src/lib.rs b/aes-gcm-siv/src/lib.rs index f04c5848..d6dfab57 100644 --- a/aes-gcm-siv/src/lib.rs +++ b/aes-gcm-siv/src/lib.rs @@ -19,9 +19,9 @@ //! Aes256GcmSiv, Nonce // Or `Aes128GcmSiv` //! }; //! -//! let key = Aes256GcmSiv::generate_key(&mut OsRng); +//! let key = Aes256GcmSiv::generate_key()?; //! let cipher = Aes256GcmSiv::new(&key); -//! let nonce = Aes256GcmSiv::generate_nonce(&mut OsRng); // 96-bits; unique per message +//! let nonce = Aes256GcmSiv::generate_nonce()?; // 96-bits; unique per message //! let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref())?; //! let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref())?; //! assert_eq!(&plaintext, b"plaintext message"); @@ -58,7 +58,7 @@ //! Aes256GcmSiv, Nonce, // Or `Aes128GcmSiv` //! }; //! -//! let key = Aes256GcmSiv::generate_key(&mut OsRng); +//! let key = Aes256GcmSiv::generate_key()?; //! let cipher = Aes256GcmSiv::new(&key); //! let nonce = Nonce::from_slice(b"unique nonce"); // 96-bits; unique per message //! @@ -85,9 +85,9 @@ pub use aead::{self, AeadCore, AeadInPlace, Error, Key, KeyInit, KeySizeUser}; use cipher::{ + array::Array, consts::{U0, U12, U16}, - generic_array::GenericArray, - BlockCipher, BlockEncrypt, InnerIvInit, StreamCipherCore, + BlockCipher, BlockCipherEncrypt, InnerIvInit, StreamCipherCore, }; use polyval::{universal_hash::UniversalHash, Polyval}; use zeroize::Zeroize; @@ -106,10 +106,10 @@ pub const P_MAX: u64 = 1 << 36; pub const C_MAX: u64 = (1 << 36) + 16; /// AES-GCM-SIV nonces. -pub type Nonce = GenericArray; +pub type Nonce = Array; /// AES-GCM-SIV tags. -pub type Tag = GenericArray; +pub type Tag = Array; /// AES-GCM-SIV with a 128-bit key. #[cfg(feature = "aes")] @@ -138,7 +138,7 @@ where impl KeyInit for AesGcmSiv where - Aes: BlockCipher + BlockEncrypt + KeyInit, + Aes: BlockCipher + BlockCipherEncrypt + KeyInit, { fn new(key_bytes: &Key) -> Self { Self { @@ -149,7 +149,7 @@ where impl From for AesGcmSiv where - Aes: BlockCipher + BlockEncrypt, + Aes: BlockCipher + BlockCipherEncrypt, { fn from(key_generating_key: Aes) -> Self { Self { key_generating_key } @@ -158,7 +158,7 @@ where impl AeadCore for AesGcmSiv where - Aes: BlockCipher + BlockEncrypt + KeyInit, + Aes: BlockCipher + BlockCipherEncrypt + KeyInit, { type NonceSize = U12; type TagSize = U16; @@ -167,7 +167,7 @@ where impl AeadInPlace for AesGcmSiv where - Aes: BlockCipher + BlockEncrypt + KeyInit, + Aes: BlockCipher + BlockCipherEncrypt + KeyInit, { fn encrypt_in_place_detached( &self, @@ -197,7 +197,7 @@ where /// AES-GCM-SIV: Misuse-Resistant Authenticated Encryption Cipher (RFC8452). struct Cipher where - Aes: BlockCipher + BlockEncrypt, + Aes: BlockCipher + BlockCipherEncrypt, { /// Encryption cipher. enc_cipher: Aes, @@ -211,13 +211,13 @@ where impl Cipher where - Aes: BlockCipher + BlockEncrypt + KeyInit, + Aes: BlockCipher + BlockCipherEncrypt + KeyInit, { /// Initialize AES-GCM-SIV, deriving per-nonce message-authentication and /// message-encryption keys. pub(crate) fn new(key_generating_key: &Aes, nonce: &Nonce) -> Self { let mut mac_key = polyval::Key::default(); - let mut enc_key = GenericArray::default(); + let mut enc_key = Array::default(); let mut block = cipher::Block::::default(); let mut counter = 0u32; @@ -347,7 +347,7 @@ where #[inline] fn init_ctr(cipher: Aes, nonce: &cipher::Block) -> Ctr32LE where - Aes: BlockCipher + BlockEncrypt, + Aes: BlockCipher + BlockCipherEncrypt, { let mut counter_block = *nonce; counter_block[15] |= 0x80; diff --git a/aes-gcm-siv/tests/aes128gcmsiv.rs b/aes-gcm-siv/tests/aes128gcmsiv.rs index 18bdd9e4..5462cbd9 100644 --- a/aes-gcm-siv/tests/aes128gcmsiv.rs +++ b/aes-gcm-siv/tests/aes128gcmsiv.rs @@ -6,7 +6,7 @@ mod common; use self::common::TestVector; -use aes_gcm_siv::aead::{generic_array::GenericArray, Aead, KeyInit, Payload}; +use aes_gcm_siv::aead::{array::Array, Aead, KeyInit, Payload}; use aes_gcm_siv::Aes128GcmSiv; /// Test vectors from RFC8452 Appendix C.1: AEAD_AES_128_auth tag_SIV diff --git a/aes-gcm-siv/tests/aes256gcmsiv.rs b/aes-gcm-siv/tests/aes256gcmsiv.rs index 9e2eed28..fada4208 100644 --- a/aes-gcm-siv/tests/aes256gcmsiv.rs +++ b/aes-gcm-siv/tests/aes256gcmsiv.rs @@ -6,7 +6,7 @@ mod common; use self::common::TestVector; -use aes_gcm_siv::aead::{generic_array::GenericArray, Aead, KeyInit, Payload}; +use aes_gcm_siv::aead::{array::Array, Aead, KeyInit, Payload}; use aes_gcm_siv::Aes256GcmSiv; /// Test vectors from RFC8452 Appendix C.2. AEAD_AES_256_auth tag_SIV diff --git a/aes-gcm-siv/tests/common/mod.rs b/aes-gcm-siv/tests/common/mod.rs index 080cc7b6..31bf29ac 100644 --- a/aes-gcm-siv/tests/common/mod.rs +++ b/aes-gcm-siv/tests/common/mod.rs @@ -16,8 +16,8 @@ macro_rules! tests { #[test] fn encrypt() { for vector in $vectors { - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let payload = Payload { msg: vector.plaintext, aad: vector.aad, @@ -33,8 +33,8 @@ macro_rules! tests { #[test] fn decrypt() { for vector in $vectors { - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let payload = Payload { msg: vector.ciphertext, @@ -51,8 +51,8 @@ macro_rules! tests { #[test] fn decrypt_modified() { let vector = &$vectors[1]; - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let mut ciphertext = Vec::from(vector.ciphertext); diff --git a/aes-gcm-siv/tests/ctr_wrap.rs b/aes-gcm-siv/tests/ctr_wrap.rs index e86f8563..e03a93d3 100644 --- a/aes-gcm-siv/tests/ctr_wrap.rs +++ b/aes-gcm-siv/tests/ctr_wrap.rs @@ -9,7 +9,7 @@ mod common; use self::common::TestVector; -use aes_gcm_siv::aead::{generic_array::GenericArray, Aead, KeyInit, Payload}; +use aes_gcm_siv::aead::{array::Array, Aead, KeyInit, Payload}; use aes_gcm_siv::Aes256GcmSiv; /// Test vectors from RFC8452 Appendix C.3. Counter Wrap Tests diff --git a/aes-gcm/Cargo.toml b/aes-gcm/Cargo.toml index 422aa5fe..9a4008d8 100644 --- a/aes-gcm/Cargo.toml +++ b/aes-gcm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aes-gcm" -version = "0.10.3" +version = "0.11.0-pre" description = """ Pure Rust implementation of the AES-GCM (Galois/Counter Mode) Authenticated Encryption with Associated Data (AEAD) Cipher @@ -14,19 +14,19 @@ documentation = "https://docs.rs/aes-gcm" repository = "https://github.com/RustCrypto/AEADs" keywords = ["aead", "aes", "encryption", "gcm", "ghash"] categories = ["cryptography", "no-std"] -rust-version = "1.56" +rust-version = "1.65" [dependencies] -aead = { version = "0.5", default-features = false } -aes = { version = "0.8", optional = true } -cipher = "0.4" -ctr = "0.9" -ghash = { version = "0.5", default-features = false } +aead = { version = "=0.6.0-pre", default-features = false } +aes = { version = "=0.9.0-pre", optional = true } +cipher = "0.5.0-pre.4" +ctr = "=0.10.0-pre" +ghash = { version = "=0.6.0-pre", default-features = false } subtle = { version = "2", default-features = false } zeroize = { version = "1", optional = true, default-features = false } [dev-dependencies] -aead = { version = "0.5", features = ["dev"], default-features = false } +aead = { version = "=0.6.0-pre", features = ["dev"], default-features = false } hex-literal = "0.3" [features] diff --git a/aes-gcm/src/lib.rs b/aes-gcm/src/lib.rs index f7a26513..5fef0a4e 100644 --- a/aes-gcm/src/lib.rs +++ b/aes-gcm/src/lib.rs @@ -21,7 +21,7 @@ //! # fn gen_key() -> Result<(), core::array::TryFromSliceError> { //! // The encryption key can be generated randomly: //! # #[cfg(all(feature = "getrandom", feature = "std"))] { -//! let key = Aes256Gcm::generate_key(OsRng); +//! let key = Aes256Gcm::generate_key().expect("generate key"); //! # } //! //! // Transformed from a byte array: @@ -33,14 +33,14 @@ //! let key: [u8; 32] = key.try_into()?; //! # Ok(()) } //! -//! # fn main() -> Result<(), aes_gcm::Error> { +//! # fn main() -> Result<(), Box> { //! // Alternatively, the key can be transformed directly from a byte slice //! // (panics on length mismatch): //! # let key: &[u8] = &[42; 32]; //! let key = Key::::from_slice(key); //! //! let cipher = Aes256Gcm::new(&key); -//! let nonce = Aes256Gcm::generate_nonce(&mut OsRng); // 96-bits; unique per message +//! let nonce = Aes256Gcm::generate_nonce()?; // 96-bits; unique per message //! let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref())?; //! let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref())?; //! assert_eq!(&plaintext, b"plaintext message"); @@ -77,9 +77,9 @@ //! Aes256Gcm, Nonce, // Or `Aes128Gcm` //! }; //! -//! let key = Aes256Gcm::generate_key(&mut OsRng); +//! let key = Aes256Gcm::generate_key()?; //! let cipher = Aes256Gcm::new(&key); -//! let nonce = Aes256Gcm::generate_nonce(&mut OsRng); // 96-bits; unique per message +//! let nonce = Aes256Gcm::generate_nonce()?; // 96-bits; unique per message //! //! let mut buffer: Vec = Vec::new(); // Note: buffer needs 16-bytes overhead for auth tag //! buffer.extend_from_slice(b"plaintext message"); @@ -107,9 +107,9 @@ pub use aead::{self, AeadCore, AeadInPlace, Error, Key, KeyInit, KeySizeUser}; pub use aes; use cipher::{ + array::{Array, ArraySize}, consts::{U0, U16}, - generic_array::{ArrayLength, GenericArray}, - BlockCipher, BlockEncrypt, BlockSizeUser, InnerIvInit, StreamCipherCore, + BlockCipher, BlockCipherEncrypt, BlockSizeUser, InnerIvInit, StreamCipherCore, }; use core::marker::PhantomData; use ghash::{universal_hash::UniversalHash, GHash}; @@ -130,10 +130,10 @@ pub const P_MAX: u64 = 1 << 36; pub const C_MAX: u64 = (1 << 36) + 16; /// AES-GCM nonces. -pub type Nonce = GenericArray; +pub type Nonce = Array; /// AES-GCM tags. -pub type Tag = GenericArray; +pub type Tag = Array; /// Trait implemented for valid tag sizes, i.e. /// [`U12`][consts::U12], [`U13`][consts::U13], [`U14`][consts::U14], @@ -143,11 +143,10 @@ pub trait TagSize: private::SealedTagSize {} impl TagSize for T {} mod private { - use aead::generic_array::ArrayLength; - use cipher::{consts, Unsigned}; + use cipher::{array::ArraySize, consts, Unsigned}; // Sealed traits stop other crates from implementing any traits that use it. - pub trait SealedTagSize: ArrayLength + Unsigned {} + pub trait SealedTagSize: ArraySize + Unsigned {} impl SealedTagSize for consts::U12 {} impl SealedTagSize for consts::U13 {} @@ -167,7 +166,7 @@ pub type Aes128Gcm = AesGcm; pub type Aes256Gcm = AesGcm; /// AES block. -type Block = GenericArray; +type Block = Array; /// Counter mode with a 32-bit big endian counter. type Ctr32BE = ctr::CtrCore; @@ -217,7 +216,7 @@ where impl KeyInit for AesGcm where - Aes: BlockSizeUser + BlockEncrypt + KeyInit, + Aes: BlockSizeUser + BlockCipherEncrypt + KeyInit, TagSize: self::TagSize, { fn new(key: &Key) -> Self { @@ -227,7 +226,7 @@ where impl From for AesGcm where - Aes: BlockSizeUser + BlockEncrypt, + Aes: BlockSizeUser + BlockCipherEncrypt, TagSize: self::TagSize, { fn from(cipher: Aes) -> Self { @@ -250,7 +249,7 @@ where impl AeadCore for AesGcm where - NonceSize: ArrayLength, + NonceSize: ArraySize, TagSize: self::TagSize, { type NonceSize = NonceSize; @@ -260,8 +259,8 @@ where impl AeadInPlace for AesGcm where - Aes: BlockCipher + BlockSizeUser + BlockEncrypt, - NonceSize: ArrayLength, + Aes: BlockCipher + BlockSizeUser + BlockCipherEncrypt, + NonceSize: ArraySize, TagSize: self::TagSize, { fn encrypt_in_place_detached( @@ -313,8 +312,8 @@ where impl AesGcm where - Aes: BlockCipher + BlockSizeUser + BlockEncrypt, - NonceSize: ArrayLength, + Aes: BlockCipher + BlockSizeUser + BlockCipherEncrypt, + NonceSize: ArraySize, TagSize: self::TagSize, { /// Initialize counter mode. diff --git a/aes-gcm/tests/aes128gcm.rs b/aes-gcm/tests/aes128gcm.rs index 7b84fbcb..4ded9592 100644 --- a/aes-gcm/tests/aes128gcm.rs +++ b/aes-gcm/tests/aes128gcm.rs @@ -6,7 +6,7 @@ mod common; use self::common::TestVector; -use aes_gcm::aead::{generic_array::GenericArray, Aead, AeadInPlace, KeyInit, Payload}; +use aes_gcm::aead::{array::Array, Aead, AeadInPlace, KeyInit, Payload}; use aes_gcm::Aes128Gcm; use hex_literal::hex; diff --git a/aes-gcm/tests/aes256gcm.rs b/aes-gcm/tests/aes256gcm.rs index f1fdda5d..294d6a53 100644 --- a/aes-gcm/tests/aes256gcm.rs +++ b/aes-gcm/tests/aes256gcm.rs @@ -6,7 +6,7 @@ mod common; use self::common::TestVector; -use aes_gcm::aead::{generic_array::GenericArray, Aead, AeadInPlace, KeyInit, Payload}; +use aes_gcm::aead::{array::Array, Aead, AeadInPlace, KeyInit, Payload}; use aes_gcm::Aes256Gcm; use hex_literal::hex; diff --git a/aes-gcm/tests/common/mod.rs b/aes-gcm/tests/common/mod.rs index 6255bb3a..fffc3d91 100644 --- a/aes-gcm/tests/common/mod.rs +++ b/aes-gcm/tests/common/mod.rs @@ -17,8 +17,8 @@ macro_rules! tests { #[test] fn encrypt() { for vector in $vectors { - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let payload = Payload { msg: vector.plaintext, aad: vector.aad, @@ -35,8 +35,8 @@ macro_rules! tests { #[test] fn decrypt() { for vector in $vectors { - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let mut ciphertext = Vec::from(vector.ciphertext); ciphertext.extend_from_slice(vector.tag); @@ -55,8 +55,8 @@ macro_rules! tests { #[test] fn decrypt_modified() { let vector = &$vectors[0]; - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let mut ciphertext = Vec::from(vector.ciphertext); ciphertext.extend_from_slice(vector.tag); @@ -76,14 +76,14 @@ macro_rules! tests { #[test] fn decrypt_in_place_detached_modified() { let vector = &$vectors.iter().last().unwrap(); - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let mut buffer = Vec::from(vector.ciphertext); assert!(!buffer.is_empty()); // Tweak the first byte - let mut tag = GenericArray::clone_from_slice(vector.tag); + let mut tag = Array::clone_from_slice(vector.tag); tag[0] ^= 0xaa; let cipher = <$aead>::new(key); diff --git a/aes-gcm/tests/other_ivlen.rs b/aes-gcm/tests/other_ivlen.rs index 124647fb..cd28f436 100644 --- a/aes-gcm/tests/other_ivlen.rs +++ b/aes-gcm/tests/other_ivlen.rs @@ -6,7 +6,7 @@ #![cfg(all(feature = "aes", feature = "alloc"))] use aead::{ - generic_array::{typenum, GenericArray}, + array::{typenum, Array}, Aead, KeyInit, }; use aes::Aes128; @@ -34,7 +34,7 @@ mod ivlen8 { let plaintext = hex!("8cfa255530c6fbc19d51bd4aeb39c91b"); let ciphertext = Aes128GcmWith8BitNonce::new(&key.into()) - .encrypt(GenericArray::from_slice(&nonce), &plaintext[..]) + .encrypt(Array::from_slice(&nonce), &plaintext[..]) .unwrap(); let (ct, tag) = ciphertext.split_at(ciphertext.len() - 16); @@ -69,7 +69,7 @@ mod ivlen1024 { let plaintext = hex!("705da82292143d2c949dc4ba014f6396"); let ciphertext = Aes128GcmWith1024BitNonce::new(&key.into()) - .encrypt(GenericArray::from_slice(&nonce), &plaintext[..]) + .encrypt(Array::from_slice(&nonce), &plaintext[..]) .unwrap(); let (ct, tag) = ciphertext.split_at(ciphertext.len() - 16); diff --git a/aes-siv/Cargo.toml b/aes-siv/Cargo.toml index 6344b068..efbbb635 100644 --- a/aes-siv/Cargo.toml +++ b/aes-siv/Cargo.toml @@ -14,20 +14,20 @@ documentation = "https://docs.rs/aes-siv" repository = "https://github.com/RustCrypto/AEADs" keywords = ["aead", "aes", "encryption", "siv"] categories = ["cryptography", "no-std"] -rust-version = "1.56" +rust-version = "1.72" [dependencies] -aead = "0.5" -aes = "0.8" -cipher = "0.4" -cmac = "0.7" -ctr = "0.9" -dbl = "0.3" -digest = { version = "0.10", features = ["mac"] } +aead = "=0.6.0-pre" +aes = "=0.9.0-pre" +cipher = "=0.5.0-pre.4" +cmac = "0.8.0-pre" +ctr = "=0.10.0-pre" +dbl = "0.4.0-pre.4" +digest = { version = "0.11.0-pre.8", features = ["mac"] } zeroize = { version = "1", default-features = false } # optional dependencies -pmac = { version = "0.7", optional = true } +pmac = { version = "0.8.0-pre", optional = true } [dev-dependencies] blobby = "0.3" diff --git a/aes-siv/src/lib.rs b/aes-siv/src/lib.rs index ebe917d1..48360e4b 100644 --- a/aes-siv/src/lib.rs +++ b/aes-siv/src/lib.rs @@ -19,9 +19,9 @@ //! Aes256SivAead, Nonce // Or `Aes128SivAead` //! }; //! -//! let key = Aes256SivAead::generate_key(&mut OsRng); +//! let key = Aes256SivAead::generate_key()?; //! let cipher = Aes256SivAead::new(&key); -//! let nonce = Aes256SivAead::generate_nonce(&mut OsRng); // 128-bits; unique per message +//! let nonce = Aes256SivAead::generate_nonce()?; // 128-bits; unique per message //! let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref())?; //! let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref())?; //! assert_eq!(&plaintext, b"plaintext message"); @@ -58,9 +58,9 @@ //! Aes256SivAead, Nonce, // Or `Aes128SivAead` //! }; //! -//! let key = Aes256SivAead::generate_key(&mut OsRng); +//! let key = Aes256SivAead::generate_key()?; //! let cipher = Aes256SivAead::new(&key); -//! let nonce = Aes256SivAead::generate_nonce(&mut OsRng); // 128-bits; unique per message +//! let nonce = Aes256SivAead::generate_nonce()?; // 128-bits; unique per message //! //! let mut buffer: Vec = Vec::new(); // Note: buffer needs 16-bytes overhead for auth tag //! buffer.extend_from_slice(b"plaintext message"); @@ -91,12 +91,12 @@ pub use aead::{self, AeadCore, AeadInPlace, Error, Key, KeyInit, KeySizeUser}; use crate::siv::Siv; use aead::{ + array::Array, consts::{U0, U1, U16, U32, U64}, - generic_array::GenericArray, Buffer, }; use aes::{Aes128, Aes256}; -use cipher::{typenum::IsGreaterOrEqual, ArrayLength, BlockCipher, BlockEncryptMut}; +use cipher::{typenum::IsGreaterOrEqual, ArraySize, BlockCipher, BlockCipherEncrypt}; use cmac::Cmac; use core::{marker::PhantomData, ops::Add}; use digest::{FixedOutputReset, Mac}; @@ -105,10 +105,10 @@ use digest::{FixedOutputReset, Mac}; use pmac::Pmac; /// AES-SIV nonces -pub type Nonce = GenericArray; +pub type Nonce = Array; /// AES-SIV tags (i.e. the Synthetic Initialization Vector value) -pub type Tag = GenericArray; +pub type Tag = Array; /// The `SivAead` type wraps the more powerful `Siv` interface in a more /// commonly used Authenticated Encryption with Associated Data (AEAD) API, @@ -116,12 +116,12 @@ pub type Tag = GenericArray; pub struct SivAead where Self: KeySizeUser, - C: BlockCipher + BlockEncryptMut + KeyInit + KeySizeUser, + C: BlockCipher + BlockCipherEncrypt + KeyInit + KeySizeUser, M: Mac + FixedOutputReset + KeyInit, ::KeySize: Add, - NonceSize: ArrayLength + IsGreaterOrEqual, + NonceSize: ArraySize + IsGreaterOrEqual, { - key: GenericArray::KeySize>, + key: Array::KeySize>, mac: PhantomData, // TODO(tarcieri): include `M` in `KeySize` calculation } @@ -152,7 +152,7 @@ pub type Aes256PmacSivAead = PmacSivAead; impl KeySizeUser for SivAead where M: Mac + FixedOutputReset + KeyInit, - NonceSize: ArrayLength + IsGreaterOrEqual, + NonceSize: ArraySize + IsGreaterOrEqual, { type KeySize = U32; } @@ -160,7 +160,7 @@ where impl KeySizeUser for SivAead where M: Mac + FixedOutputReset + KeyInit, - NonceSize: ArrayLength + IsGreaterOrEqual, + NonceSize: ArraySize + IsGreaterOrEqual, { type KeySize = U64; } @@ -168,9 +168,9 @@ where impl KeyInit for SivAead where M: Mac + FixedOutputReset + KeyInit, - NonceSize: ArrayLength + IsGreaterOrEqual, + NonceSize: ArraySize + IsGreaterOrEqual, { - fn new(key: &GenericArray) -> Self { + fn new(key: &Array) -> Self { Self { key: *key, mac: PhantomData, @@ -181,9 +181,9 @@ where impl KeyInit for SivAead where M: Mac + FixedOutputReset + KeyInit, - NonceSize: ArrayLength + IsGreaterOrEqual, + NonceSize: ArraySize + IsGreaterOrEqual, { - fn new(key: &GenericArray) -> Self { + fn new(key: &Array) -> Self { Self { key: *key, mac: PhantomData, @@ -194,10 +194,10 @@ where impl AeadCore for SivAead where Self: KeySizeUser, - C: BlockCipher + BlockEncryptMut + KeyInit + KeySizeUser, + C: BlockCipher + BlockCipherEncrypt + KeyInit + KeySizeUser, M: Mac + FixedOutputReset + KeyInit, ::KeySize: Add, - NonceSize: ArrayLength + IsGreaterOrEqual, + NonceSize: ArraySize + IsGreaterOrEqual, { // "If the nonce is random, it SHOULD be at least 128 bits in length" // https://tools.ietf.org/html/rfc5297#section-3 @@ -212,14 +212,14 @@ impl AeadInPlace for SivAead where Self: KeySizeUser, Siv: KeyInit + KeySizeUser::KeySize>, - C: BlockCipher + BlockEncryptMut + KeyInit + KeySizeUser, + C: BlockCipher + BlockCipherEncrypt + KeyInit + KeySizeUser, M: Mac + FixedOutputReset + KeyInit, ::KeySize: Add, - NonceSize: ArrayLength + IsGreaterOrEqual, + NonceSize: ArraySize + IsGreaterOrEqual, { fn encrypt_in_place( &self, - nonce: &GenericArray, + nonce: &Array, associated_data: &[u8], buffer: &mut dyn Buffer, ) -> Result<(), Error> { @@ -233,17 +233,17 @@ where fn encrypt_in_place_detached( &self, - nonce: &GenericArray, + nonce: &Array, associated_data: &[u8], buffer: &mut [u8], - ) -> Result, Error> { + ) -> Result, Error> { Siv::::new(&self.key) .encrypt_in_place_detached([associated_data, nonce.as_slice()], buffer) } fn decrypt_in_place( &self, - nonce: &GenericArray, + nonce: &Array, associated_data: &[u8], buffer: &mut dyn Buffer, ) -> Result<(), Error> { @@ -252,10 +252,10 @@ where fn decrypt_in_place_detached( &self, - nonce: &GenericArray, + nonce: &Array, associated_data: &[u8], buffer: &mut [u8], - tag: &GenericArray, + tag: &Array, ) -> Result<(), Error> { Siv::::new(&self.key).decrypt_in_place_detached( [associated_data, nonce.as_slice()], diff --git a/aes-siv/src/siv.rs b/aes-siv/src/siv.rs index 4c61f8b7..df559f09 100644 --- a/aes-siv/src/siv.rs +++ b/aes-siv/src/siv.rs @@ -5,12 +5,12 @@ use crate::Tag; use aead::{ - generic_array::{typenum::U16, ArrayLength, GenericArray}, + array::{typenum::U16, Array, ArraySize}, Buffer, Error, }; use aes::{Aes128, Aes256}; use cipher::{ - BlockCipher, BlockEncryptMut, InnerIvInit, Key, KeyInit, KeySizeUser, StreamCipherCore, + BlockCipher, BlockCipherEncrypt, InnerIvInit, Key, KeyInit, KeySizeUser, StreamCipherCore, }; use cmac::Cmac; use core::ops::Add; @@ -40,7 +40,7 @@ pub type KeySize = <::KeySize as Add>::Output; /// authenticated encryption (MRAE). pub struct Siv where - C: BlockCipher + BlockEncryptMut + KeyInit + KeySizeUser, + C: BlockCipher + BlockCipherEncrypt + KeyInit + KeySizeUser, M: Mac, { encryption_key: Key, @@ -73,36 +73,36 @@ pub type Aes256PmacSiv = PmacSiv; impl KeySizeUser for Siv where - C: BlockCipher + BlockEncryptMut + KeyInit + KeySizeUser, + C: BlockCipher + BlockCipherEncrypt + KeyInit + KeySizeUser, M: Mac + FixedOutputReset + KeyInit, ::KeySize: Add, - KeySize: ArrayLength, + KeySize: ArraySize, { type KeySize = KeySize; } impl KeyInit for Siv where - C: BlockCipher + BlockEncryptMut + KeyInit + KeySizeUser, + C: BlockCipher + BlockCipherEncrypt + KeyInit + KeySizeUser, M: Mac + FixedOutputReset + KeyInit, ::KeySize: Add, - KeySize: ArrayLength, + KeySize: ArraySize, { /// Create a new AES-SIV instance - fn new(key: &GenericArray>) -> Self { + fn new(key: &Array>) -> Self { // Use the first half of the key as the MAC key and // the second one as the encryption key let (mac_key, enc_key) = key.split_at(M::key_size()); Self { - encryption_key: GenericArray::clone_from_slice(enc_key), - mac: ::new(GenericArray::from_slice(mac_key)), + encryption_key: Array::clone_from_slice(enc_key), + mac: ::new(Array::from_slice(mac_key)), } } } impl Siv where - C: BlockCipher + BlockEncryptMut + KeyInit + KeySizeUser, + C: BlockCipher + BlockCipherEncrypt + KeyInit + KeySizeUser, M: Mac + FixedOutputReset + KeyInit, { /// Encrypt the given plaintext, allocating and returning a `Vec` for @@ -258,7 +258,7 @@ where impl Drop for Siv where - C: BlockCipher + BlockEncryptMut + KeyInit + KeySizeUser, + C: BlockCipher + BlockCipherEncrypt + KeyInit + KeySizeUser, M: Mac, { fn drop(&mut self) { diff --git a/aes-siv/tests/aead.rs b/aes-siv/tests/aead.rs index 48f276cf..49b6018d 100644 --- a/aes-siv/tests/aead.rs +++ b/aes-siv/tests/aead.rs @@ -18,8 +18,8 @@ macro_rules! tests { #[test] fn encrypt() { for vector in $vectors { - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let payload = Payload { msg: vector.plaintext, aad: vector.aad, @@ -34,8 +34,8 @@ macro_rules! tests { #[test] fn encrypt_in_place_detached() { for vector in $vectors { - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let mut buffer = vector.plaintext.to_vec(); let cipher = <$aead>::new(key); @@ -51,8 +51,8 @@ macro_rules! tests { #[test] fn decrypt() { for vector in $vectors { - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let payload = Payload { msg: vector.ciphertext, @@ -69,9 +69,9 @@ macro_rules! tests { #[test] fn decrypt_in_place_detached() { for vector in $vectors { - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); - let tag = GenericArray::clone_from_slice(&vector.ciphertext[..16]); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); + let tag = Array::clone_from_slice(&vector.ciphertext[..16]); let mut buffer = vector.ciphertext[16..].to_vec(); <$aead>::new(key) @@ -85,8 +85,8 @@ macro_rules! tests { #[test] fn decrypt_modified() { let vector = &$vectors[0]; - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let mut ciphertext = Vec::from(vector.ciphertext); // Tweak the first byte @@ -107,7 +107,7 @@ macro_rules! tests { mod aes128cmacsivaead { use super::TestVector; - use aes_siv::aead::{generic_array::GenericArray, Aead, AeadInPlace, KeyInit, Payload}; + use aes_siv::aead::{array::Array, Aead, AeadInPlace, KeyInit, Payload}; use aes_siv::Aes128SivAead; /// AES-128-CMAC-SIV test vectors @@ -127,7 +127,7 @@ mod aes128cmacsivaead { #[cfg(feature = "pmac")] mod aes128pmacsivaead { use super::TestVector; - use aes_siv::aead::{generic_array::GenericArray, Aead, AeadInPlace, KeyInit, Payload}; + use aes_siv::aead::{array::Array, Aead, AeadInPlace, KeyInit, Payload}; use aes_siv::Aes128PmacSivAead; /// AES-128-PMAC-SIV test vectors diff --git a/aes-siv/tests/siv.rs b/aes-siv/tests/siv.rs index 0db1a2e9..e8be24f8 100644 --- a/aes-siv/tests/siv.rs +++ b/aes-siv/tests/siv.rs @@ -2,7 +2,7 @@ #![cfg(feature = "alloc")] -use aes_siv::aead::generic_array::GenericArray; +use aes_siv::aead::array::Array; /// Test vectors #[derive(Debug)] @@ -18,7 +18,7 @@ macro_rules! tests { #[test] fn encrypt() { for vector in $vectors { - let mut cipher = <$siv>::new(GenericArray::from_slice(vector.key)); + let mut cipher = <$siv>::new(Array::from_slice(vector.key)); let ciphertext = cipher.encrypt(vector.aad, vector.plaintext).unwrap(); assert_eq!(vector.ciphertext, ciphertext.as_slice()); } @@ -27,7 +27,7 @@ macro_rules! tests { #[test] fn decrypt() { for vector in $vectors { - let mut cipher = <$siv>::new(GenericArray::from_slice(vector.key)); + let mut cipher = <$siv>::new(Array::from_slice(vector.key)); let plaintext = cipher.decrypt(vector.aad, vector.ciphertext).unwrap(); assert_eq!(vector.plaintext, plaintext.as_slice()); } @@ -41,7 +41,7 @@ macro_rules! tests { // Tweak the first byte ciphertext[0] ^= 0xaa; - let mut cipher = <$siv>::new(GenericArray::from_slice(vector.key)); + let mut cipher = <$siv>::new(Array::from_slice(vector.key)); assert!(cipher.decrypt(vector.aad, &ciphertext).is_err()); // TODO(tarcieri): test ciphertext is unmodified in in-place API @@ -63,7 +63,7 @@ macro_rules! wycheproof_tests { ct: &[u8], pass: bool, ) -> Option<&'static str> { - let mut cipher = <$siv>::new(GenericArray::from_slice(key)); + let mut cipher = <$siv>::new(Array::from_slice(key)); let ciphertext = cipher.encrypt(&[aad], pt).unwrap(); if pass && ct != ciphertext.as_slice() { return Some("encryption mismatch"); @@ -111,7 +111,7 @@ macro_rules! wycheproof_tests { } mod aes128cmacsiv { - use super::{GenericArray, TestVector}; + use super::{Array, TestVector}; use aes_siv::{siv::Aes128Siv, KeyInit}; use hex_literal::hex; @@ -153,7 +153,7 @@ mod aes128cmacsiv { } mod aes256cmacsiv { - use super::{GenericArray, TestVector}; + use super::{Array, TestVector}; use aes_siv::{siv::Aes256Siv, KeyInit}; use hex_literal::hex; @@ -184,7 +184,7 @@ mod aes256cmacsiv { #[cfg(feature = "pmac")] mod aes128pmaccsiv { - use super::{GenericArray, TestVector}; + use super::{Array, TestVector}; use aes_siv::{siv::Aes128PmacSiv, KeyInit}; use hex_literal::hex; @@ -225,7 +225,7 @@ mod aes128pmaccsiv { #[cfg(feature = "pmac")] mod aes256pmaccsiv { - use super::{GenericArray, TestVector}; + use super::{Array, TestVector}; use aes_siv::{siv::Aes256PmacSiv, KeyInit}; use hex_literal::hex; diff --git a/ascon-aead/Cargo.toml b/ascon-aead/Cargo.toml index 1cd3016a..1bb7cc2b 100644 --- a/ascon-aead/Cargo.toml +++ b/ascon-aead/Cargo.toml @@ -12,10 +12,10 @@ readme = "README.md" repository = "https://github.com/RustCrypto/AEADs" keywords = ["AEAD", "ascon", "encryption"] categories = ["cryptography", "no-std"] -rust-version = "1.56" +rust-version = "1.65" [dependencies] -aead = { version = "0.5", default-features = false } +aead = { version = "=0.6.0-pre", default-features = false } subtle = { version = "2", default-features = false } zeroize_crate = { package = "zeroize", version = "1.6", optional = true, default-features = false, features = [ "derive", @@ -24,7 +24,7 @@ ascon = "0.4" [dev-dependencies] hex-literal = "0.3" -aead = { version = "0.5", features = ["alloc"] } +aead = { version = "=0.6.0-pre", features = ["alloc"] } [features] default = ["alloc", "getrandom"] diff --git a/ascon-aead/src/asconcore.rs b/ascon-aead/src/asconcore.rs index 1e37e256..7c2bc3be 100644 --- a/ascon-aead/src/asconcore.rs +++ b/ascon-aead/src/asconcore.rs @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT use aead::{ + array::{typenum::Unsigned, Array, ArraySize}, consts::{U16, U20}, - generic_array::{typenum::Unsigned, ArrayLength, GenericArray}, Error, }; use ascon::{pad, State}; @@ -45,8 +45,8 @@ fn u32_from_be_bytes(input: &[u8]) -> u32 { /// Helper trait for handling differences in key usage of Ascon-128* and Ascon-80* /// /// For internal use-only. -pub(crate) trait InternalKey>: - Sized + Clone + for<'a> From<&'a GenericArray> +pub(crate) trait InternalKey: + Sized + Clone + for<'a> From<&'a Array> { /// Return K0. fn get_k0(&self) -> u64; @@ -77,8 +77,8 @@ impl InternalKey for InternalKey16 { } } -impl From<&GenericArray> for InternalKey16 { - fn from(key: &GenericArray) -> Self { +impl From<&Array> for InternalKey16 { + fn from(key: &Array) -> Self { Self(u64_from_be_bytes(&key[..8]), u64_from_be_bytes(&key[8..])) } } @@ -104,8 +104,8 @@ impl InternalKey for InternalKey20 { } } -impl From<&GenericArray> for InternalKey20 { - fn from(key: &GenericArray) -> Self { +impl From<&Array> for InternalKey20 { + fn from(key: &Array) -> Self { Self( u64_from_be_bytes(&key[4..12]), u64_from_be_bytes(&key[12..]), @@ -119,7 +119,7 @@ pub(crate) trait Parameters { /// Size of the secret key /// /// For internal use-only. - type KeySize: ArrayLength; + type KeySize: ArraySize; /// Internal storage for secret keys /// /// For internal use-only. @@ -173,7 +173,7 @@ pub(crate) struct AsconCore<'a, P: Parameters> { } impl<'a, P: Parameters> AsconCore<'a, P> { - pub(crate) fn new(internal_key: &'a P::InternalKey, nonce: &GenericArray) -> Self { + pub(crate) fn new(internal_key: &'a P::InternalKey, nonce: &Array) -> Self { let mut state = State::new( if P::KeySize::USIZE == 20 { P::IV ^ internal_key.get_k0() @@ -341,17 +341,17 @@ impl<'a, P: Parameters> AsconCore<'a, P> { &mut self, message: &mut [u8], associated_data: &[u8], - ) -> GenericArray { + ) -> Array { self.process_associated_data(associated_data); self.process_encrypt_inplace(message); - GenericArray::from(self.process_final()) + Array::from(self.process_final()) } pub(crate) fn decrypt_inplace( &mut self, ciphertext: &mut [u8], associated_data: &[u8], - expected_tag: &GenericArray, + expected_tag: &Array, ) -> Result<(), Error> { self.process_associated_data(associated_data); self.process_decrypt_inplace(ciphertext); diff --git a/ascon-aead/src/lib.rs b/ascon-aead/src/lib.rs index 81774e94..3c9b23a0 100644 --- a/ascon-aead/src/lib.rs +++ b/ascon-aead/src/lib.rs @@ -39,10 +39,10 @@ //! use ascon_aead::Ascon128; // Or `Ascon128a` //! use ascon_aead::aead::{Aead, AeadCore, KeyInit, OsRng}; //! -//! let key = Ascon128::generate_key(&mut OsRng); +//! let key = Ascon128::generate_key().expect("generate key"); //! let cipher = Ascon128::new(&key); //! -//! let nonce = Ascon128::generate_nonce(&mut OsRng); // 128 bits; unique per message +//! let nonce = Ascon128::generate_nonce().expect("generate nonce"); // 128 bits; unique per message //! //! let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref()) //! .expect("encryption failure!"); // NOTE: handle this error to avoid panics! diff --git a/ccm/Cargo.toml b/ccm/Cargo.toml index 978db024..51d342ce 100644 --- a/ccm/Cargo.toml +++ b/ccm/Cargo.toml @@ -11,17 +11,17 @@ homepage = "https://github.com/RustCrypto/AEADs" repository = "https://github.com/RustCrypto/AEADs/tree/master/ccm" categories = ["cryptography", "no-std"] keywords = ["encryption", "aead"] -rust-version = "1.56" +rust-version = "1.65" [dependencies] -aead = { version = "0.5", default-features = false } -cipher = { version = "0.4.3", default-features = false } -ctr = { version = "0.9.1", default-features = false } +aead = { version = "=0.6.0-pre", default-features = false } +cipher = { version = "0.5.0-pre.4", default-features = false } +ctr = { version = "=0.10.0-pre", default-features = false } subtle = { version = "2", default-features = false } [dev-dependencies] -aead = { version = "0.5", features = ["dev"], default-features = false } -aes = { version = "0.8.4" } +aead = { version = "=0.6.0-pre", features = ["dev"], default-features = false } +aes = { version = "=0.9.0-pre" } hex-literal = "0.3.4" [features] diff --git a/ccm/src/lib.rs b/ccm/src/lib.rs index b6e75d74..c399995a 100644 --- a/ccm/src/lib.rs +++ b/ccm/src/lib.rs @@ -16,7 +16,7 @@ //! # fn main() -> Result<(), Box> { //! use aes::Aes256; //! use ccm::{ -//! aead::{Aead, AeadCore, KeyInit, OsRng, generic_array::GenericArray}, +//! aead::{Aead, AeadCore, KeyInit, OsRng, array::Array}, //! consts::{U10, U13}, //! Ccm, //! }; @@ -24,9 +24,9 @@ //! // AES-256-CCM type with tag and nonce size equal to 10 and 13 bytes respectively //! pub type Aes256Ccm = Ccm; //! -//! let key = Aes256Ccm::generate_key(&mut OsRng); +//! let key = Aes256Ccm::generate_key()?; //! let cipher = Aes256Ccm::new(&key); -//! let nonce = Aes256Ccm::generate_nonce(&mut OsRng); // 13-bytes; unique per message +//! let nonce = Aes256Ccm::generate_nonce()?; // 13-bytes; unique per message //! let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref())?; //! let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref())?; //! assert_eq!(&plaintext, b"plaintext message"); @@ -45,11 +45,12 @@ pub use aead::{self, consts, AeadCore, AeadInPlace, Error, Key, KeyInit, KeySizeUser}; use aead::{ + array::{typenum::Unsigned, Array, ArraySize}, consts::{U0, U16}, - generic_array::{typenum::Unsigned, ArrayLength, GenericArray}, }; use cipher::{ - Block, BlockCipher, BlockEncrypt, BlockSizeUser, InnerIvInit, StreamCipher, StreamCipherSeek, + Block, BlockCipher, BlockCipherEncrypt, BlockSizeUser, InnerIvInit, StreamCipher, + StreamCipherSeek, }; use core::marker::PhantomData; use ctr::{Ctr32BE, Ctr64BE, CtrCore}; @@ -58,10 +59,10 @@ use subtle::ConstantTimeEq; mod private; /// CCM nonces -pub type Nonce = GenericArray; +pub type Nonce = Array; /// CCM tags -pub type Tag = GenericArray; +pub type Tag = Array; /// Trait implemented for valid tag sizes, i.e. /// [`U4`][consts::U4], [`U6`][consts::U6], [`U8`][consts::U8], @@ -94,9 +95,9 @@ impl NonceSize for T {} #[derive(Clone)] pub struct Ccm where - C: BlockCipher + BlockSizeUser + BlockEncrypt, - M: ArrayLength + TagSize, - N: ArrayLength + NonceSize, + C: BlockCipher + BlockSizeUser + BlockCipherEncrypt, + M: ArraySize + TagSize, + N: ArraySize + NonceSize, { cipher: C, _pd: PhantomData<(M, N)>, @@ -104,9 +105,9 @@ where impl Ccm where - C: BlockCipher + BlockSizeUser + BlockEncrypt, - M: ArrayLength + TagSize, - N: ArrayLength + NonceSize, + C: BlockCipher + BlockSizeUser + BlockCipherEncrypt, + M: ArraySize + TagSize, + N: ArraySize + NonceSize, { fn extend_nonce(nonce: &Nonce) -> Block { let mut ext_nonce = Block::::default(); @@ -170,9 +171,9 @@ where impl From for Ccm where - C: BlockCipher + BlockSizeUser + BlockEncrypt, - M: ArrayLength + TagSize, - N: ArrayLength + NonceSize, + C: BlockCipher + BlockSizeUser + BlockCipherEncrypt, + M: ArraySize + TagSize, + N: ArraySize + NonceSize, { fn from(cipher: C) -> Self { Self { @@ -184,18 +185,18 @@ where impl KeySizeUser for Ccm where - C: BlockCipher + BlockSizeUser + BlockEncrypt + KeyInit, - M: ArrayLength + TagSize, - N: ArrayLength + NonceSize, + C: BlockCipher + BlockSizeUser + BlockCipherEncrypt + KeyInit, + M: ArraySize + TagSize, + N: ArraySize + NonceSize, { type KeySize = C::KeySize; } impl KeyInit for Ccm where - C: BlockCipher + BlockSizeUser + BlockEncrypt + KeyInit, - M: ArrayLength + TagSize, - N: ArrayLength + NonceSize, + C: BlockCipher + BlockSizeUser + BlockCipherEncrypt + KeyInit, + M: ArraySize + TagSize, + N: ArraySize + NonceSize, { fn new(key: &Key) -> Self { Self::from(C::new(key)) @@ -204,9 +205,9 @@ where impl AeadCore for Ccm where - C: BlockCipher + BlockSizeUser + BlockEncrypt, - M: ArrayLength + TagSize, - N: ArrayLength + NonceSize, + C: BlockCipher + BlockSizeUser + BlockCipherEncrypt, + M: ArraySize + TagSize, + N: ArraySize + NonceSize, { type NonceSize = N; type TagSize = M; @@ -215,9 +216,9 @@ where impl AeadInPlace for Ccm where - C: BlockCipher + BlockSizeUser + BlockEncrypt, - M: ArrayLength + TagSize, - N: ArrayLength + NonceSize, + C: BlockCipher + BlockSizeUser + BlockCipherEncrypt, + M: ArraySize + TagSize, + N: ArraySize + NonceSize, { fn encrypt_in_place_detached( &self, @@ -284,14 +285,14 @@ where } } -struct CbcMac<'a, C: BlockCipher + BlockEncrypt> { +struct CbcMac<'a, C: BlockCipher + BlockCipherEncrypt> { cipher: &'a C, state: Block, } impl<'a, C> CbcMac<'a, C> where - C: BlockCipher + BlockEncrypt, + C: BlockCipher + BlockCipherEncrypt, { fn from_cipher(cipher: &'a C) -> Self { Self { @@ -326,10 +327,10 @@ where } } -fn fill_aad_header(adata_len: usize) -> (usize, GenericArray) { +fn fill_aad_header(adata_len: usize) -> (usize, Array) { debug_assert_ne!(adata_len, 0); - let mut b = GenericArray::::default(); + let mut b = Array::::default(); let n = if adata_len < 0xFF00 { b[..2].copy_from_slice(&(adata_len as u16).to_be_bytes()); 2 diff --git a/ccm/src/private.rs b/ccm/src/private.rs index 7d4c58cc..658ee028 100644 --- a/ccm/src/private.rs +++ b/ccm/src/private.rs @@ -1,4 +1,4 @@ -use aead::{consts, generic_array::typenum::Unsigned}; +use aead::{array::typenum::Unsigned, consts}; // Sealed traits stop other crates from implementing any traits that use it. pub trait SealedTag: Unsigned { diff --git a/ccm/tests/mod.rs b/ccm/tests/mod.rs index 1ead71b2..f2f6ce15 100644 --- a/ccm/tests/mod.rs +++ b/ccm/tests/mod.rs @@ -1,6 +1,6 @@ #![cfg(feature = "alloc")] -use aead::{generic_array::GenericArray, Aead, AeadInPlace, KeyInit, Payload}; +use aead::{array::Array, Aead, AeadInPlace, KeyInit, Payload}; use aes::{Aes128, Aes192, Aes256}; use ccm::{ consts::{U10, U11, U12, U13, U14, U16, U4, U6, U7, U8, U9}, @@ -14,8 +14,8 @@ fn test_data_len_check() { let nonce = hex!("2F1DBD38CE3EDA7C23F04DD650"); type Cipher = Ccm; - let key = GenericArray::from_slice(&key); - let nonce = GenericArray::from_slice(&nonce); + let key = Array::from_slice(&key); + let nonce = Array::from_slice(&nonce); let c = Cipher::new(key); let mut buf1 = [1; core::u16::MAX as usize]; @@ -36,15 +36,15 @@ fn sp800_38c_examples() { $key:expr, $m:ty, $n:ty, nonce: $nonce:expr, adata: $adata:expr, pt: $pt:expr, ct: $ct:expr, ) => { - let key = GenericArray::from_slice(&$key); + let key = Array::from_slice(&$key); let c = Ccm::::new(key); - let nonce = GenericArray::from_slice(&$nonce); + let nonce = Array::from_slice(&$nonce); let res = c.encrypt(nonce, Payload { aad: &$adata, msg: &$pt }) .unwrap(); - assert_eq!(res, $ct.as_ref()); + assert_eq!(res, &$ct); let res = c.decrypt(nonce, Payload { aad: &$adata, msg: &$ct }) .unwrap(); - assert_eq!(res, $pt.as_ref()); + assert_eq!(res, &$pt); }; } diff --git a/chacha20poly1305/Cargo.toml b/chacha20poly1305/Cargo.toml index fc35bb83..37eba06e2 100644 --- a/chacha20poly1305/Cargo.toml +++ b/chacha20poly1305/Cargo.toml @@ -16,16 +16,17 @@ documentation = "https://docs.rs/chacha20poly1305" repository = "https://github.com/RustCrypto/AEADs/tree/master/chacha20poly1305" keywords = ["aead", "chacha20", "poly1305", "xchacha20", "xchacha20poly1305"] categories = ["cryptography", "no-std"] +rust-version = "1.65" [dependencies] -aead = { version = "0.5", default-features = false } -chacha20 = { version = "0.9", features = ["zeroize"] } -cipher = "0.4" -poly1305 = "0.8" +aead = { version = "=0.6.0-pre", default-features = false } +chacha20 = { version = "=0.10.0-pre", features = ["zeroize"] } +cipher = "0.5.0-pre.4" +poly1305 = "=0.9.0-pre" zeroize = { version = "1.6", default-features = false } [dev-dependencies] -aead = { version = "0.5", features = ["dev"], default-features = false } +aead = { version = "=0.6.0-pre", features = ["dev"], default-features = false } [features] default = ["alloc", "getrandom"] diff --git a/chacha20poly1305/src/cipher.rs b/chacha20poly1305/src/cipher.rs index 47e8b487..44637077 100644 --- a/chacha20poly1305/src/cipher.rs +++ b/chacha20poly1305/src/cipher.rs @@ -1,7 +1,7 @@ //! Core AEAD cipher implementation for (X)ChaCha20Poly1305. use ::cipher::{StreamCipher, StreamCipherSeek}; -use aead::generic_array::GenericArray; +use aead::array::Array; use aead::Error; use poly1305::{ universal_hash::{KeyInit, UniversalHash}, @@ -37,7 +37,7 @@ where let mut mac_key = poly1305::Key::default(); cipher.apply_keystream(&mut mac_key); - let mac = Poly1305::new(GenericArray::from_slice(&mac_key)); + let mac = Poly1305::new(Array::from_slice(&mac_key)); mac_key.zeroize(); // Set ChaCha20 counter to 1 @@ -99,7 +99,7 @@ where let associated_data_len: u64 = associated_data.len().try_into().map_err(|_| Error)?; let buffer_len: u64 = buffer.len().try_into().map_err(|_| Error)?; - let mut block = GenericArray::default(); + let mut block = Array::default(); block[..8].copy_from_slice(&associated_data_len.to_le_bytes()); block[8..].copy_from_slice(&buffer_len.to_le_bytes()); self.mac.update(&[block]); diff --git a/chacha20poly1305/src/lib.rs b/chacha20poly1305/src/lib.rs index de0b8eed..1be90044 100644 --- a/chacha20poly1305/src/lib.rs +++ b/chacha20poly1305/src/lib.rs @@ -31,9 +31,9 @@ //! ChaCha20Poly1305, Nonce //! }; //! -//! let key = ChaCha20Poly1305::generate_key(&mut OsRng); +//! let key = ChaCha20Poly1305::generate_key()?; //! let cipher = ChaCha20Poly1305::new(&key); -//! let nonce = ChaCha20Poly1305::generate_nonce(&mut OsRng); // 96-bits; unique per message +//! let nonce = ChaCha20Poly1305::generate_nonce()?; // 96-bits; unique per message //! let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref())?; //! let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref())?; //! assert_eq!(&plaintext, b"plaintext message"); @@ -70,9 +70,9 @@ //! ChaCha20Poly1305, Nonce, //! }; //! -//! let key = ChaCha20Poly1305::generate_key(&mut OsRng); +//! let key = ChaCha20Poly1305::generate_key()?; //! let cipher = ChaCha20Poly1305::new(&key); -//! let nonce = ChaCha20Poly1305::generate_nonce(&mut OsRng); // 96-bits; unique per message +//! let nonce = ChaCha20Poly1305::generate_nonce()?; // 96-bits; unique per message //! //! let mut buffer: Vec = Vec::new(); // Note: buffer needs 16-bytes overhead for auth tag //! buffer.extend_from_slice(b"plaintext message"); @@ -131,9 +131,9 @@ //! XChaCha20Poly1305, XNonce //! }; //! -//! let key = XChaCha20Poly1305::generate_key(&mut OsRng); +//! let key = XChaCha20Poly1305::generate_key()?; //! let cipher = XChaCha20Poly1305::new(&key); -//! let nonce = XChaCha20Poly1305::generate_nonce(&mut OsRng); // 192-bits; unique per message +//! let nonce = XChaCha20Poly1305::generate_nonce()?; // 192-bits; unique per message //! let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref())?; //! let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref())?; //! assert_eq!(&plaintext, b"plaintext message"); @@ -148,8 +148,8 @@ pub use aead::{self, consts, AeadCore, AeadInPlace, Error, KeyInit, KeySizeUser} use self::cipher::Cipher; use ::cipher::{KeyIvInit, StreamCipher, StreamCipherSeek}; use aead::{ + array::{Array, ArraySize}, consts::{U0, U12, U16, U24, U32}, - generic_array::{ArrayLength, GenericArray}, }; use core::marker::PhantomData; use zeroize::{Zeroize, ZeroizeOnDrop}; @@ -161,26 +161,26 @@ use chacha20::{ChaCha12, ChaCha8, XChaCha12, XChaCha8}; /// Key type (256-bits/32-bytes). /// -/// Implemented as an alias for [`GenericArray`]. +/// Implemented as an alias for [`Array`]. /// /// All [`ChaChaPoly1305`] variants (including `XChaCha20Poly1305`) use this /// key type. -pub type Key = GenericArray; +pub type Key = Array; /// Nonce type (96-bits/12-bytes). /// -/// Implemented as an alias for [`GenericArray`]. -pub type Nonce = GenericArray; +/// Implemented as an alias for [`Array`]. +pub type Nonce = Array; /// XNonce type (192-bits/24-bytes). /// -/// Implemented as an alias for [`GenericArray`]. -pub type XNonce = GenericArray; +/// Implemented as an alias for [`Array`]. +pub type XNonce = Array; /// Poly1305 tag. /// -/// Implemented as an alias for [`GenericArray`]. -pub type Tag = GenericArray; +/// Implemented as an alias for [`Array`]. +pub type Tag = Array; /// ChaCha20Poly1305 Authenticated Encryption with Additional Data (AEAD). pub type ChaCha20Poly1305 = ChaChaPoly1305; @@ -211,7 +211,7 @@ pub type XChaCha12Poly1305 = ChaChaPoly1305; /// Generic ChaCha+Poly1305 Authenticated Encryption with Additional Data (AEAD) construction. /// /// See the [toplevel documentation](index.html) for a usage example. -pub struct ChaChaPoly1305 = U12> { +pub struct ChaChaPoly1305 { /// Secret key. key: Key, @@ -224,14 +224,14 @@ pub struct ChaChaPoly1305 = U12> { impl KeySizeUser for ChaChaPoly1305 where - N: ArrayLength, + N: ArraySize, { type KeySize = U32; } impl KeyInit for ChaChaPoly1305 where - N: ArrayLength, + N: ArraySize, { #[inline] fn new(key: &Key) -> Self { @@ -245,7 +245,7 @@ where impl AeadCore for ChaChaPoly1305 where - N: ArrayLength, + N: ArraySize, { type NonceSize = N; type TagSize = U16; @@ -255,7 +255,7 @@ where impl AeadInPlace for ChaChaPoly1305 where C: KeyIvInit + StreamCipher + StreamCipherSeek, - N: ArrayLength, + N: ArraySize, { fn encrypt_in_place_detached( &self, @@ -283,7 +283,7 @@ where impl Clone for ChaChaPoly1305 where - N: ArrayLength, + N: ArraySize, { fn clone(&self) -> Self { Self { @@ -296,11 +296,11 @@ where impl Drop for ChaChaPoly1305 where - N: ArrayLength, + N: ArraySize, { fn drop(&mut self) { self.key.as_mut_slice().zeroize(); } } -impl> ZeroizeOnDrop for ChaChaPoly1305 {} +impl ZeroizeOnDrop for ChaChaPoly1305 {} diff --git a/chacha20poly1305/tests/lib.rs b/chacha20poly1305/tests/lib.rs index 8a38a469..2bd8d0a1 100644 --- a/chacha20poly1305/tests/lib.rs +++ b/chacha20poly1305/tests/lib.rs @@ -21,8 +21,8 @@ macro_rules! impl_tests { ($cipher:ty, $key:expr, $nonce:expr, $aad:expr, $plaintext:expr, $ciphertext:expr, $tag:expr) => { #[test] fn encrypt() { - let key = GenericArray::from_slice($key); - let nonce = GenericArray::from_slice($nonce); + let key = Array::from_slice($key); + let nonce = Array::from_slice($nonce); let payload = Payload { msg: $plaintext, aad: $aad, @@ -37,8 +37,8 @@ macro_rules! impl_tests { #[test] fn decrypt() { - let key = GenericArray::from_slice($key); - let nonce = GenericArray::from_slice($nonce); + let key = Array::from_slice($key); + let nonce = Array::from_slice($nonce); let mut ciphertext = Vec::from($ciphertext); ciphertext.extend_from_slice($tag); @@ -54,8 +54,8 @@ macro_rules! impl_tests { #[test] fn decrypt_modified() { - let key = GenericArray::from_slice($key); - let nonce = GenericArray::from_slice($nonce); + let key = Array::from_slice($key); + let nonce = Array::from_slice($nonce); let mut ciphertext = Vec::from($ciphertext); ciphertext.extend_from_slice($tag); @@ -96,7 +96,7 @@ const PLAINTEXT: &[u8] = b"Ladies and Gentlemen of the class of '99: \ /// mod chacha20 { use super::{AAD, KEY, PLAINTEXT}; - use chacha20poly1305::aead::generic_array::GenericArray; + use chacha20poly1305::aead::array::Array; use chacha20poly1305::aead::{Aead, KeyInit, Payload}; use chacha20poly1305::ChaCha20Poly1305; @@ -132,7 +132,7 @@ mod chacha20 { #[test] fn clone_impl() { - let _ = ChaCha20Poly1305::new(GenericArray::from_slice(KEY)).clone(); + let _ = ChaCha20Poly1305::new(Array::from_slice(KEY)).clone(); } } @@ -141,7 +141,7 @@ mod chacha20 { /// From mod xchacha20 { use super::{AAD, KEY, PLAINTEXT}; - use chacha20poly1305::aead::generic_array::GenericArray; + use chacha20poly1305::aead::array::Array; use chacha20poly1305::aead::{Aead, KeyInit, Payload}; use chacha20poly1305::XChaCha20Poly1305; diff --git a/deoxys/Cargo.toml b/deoxys/Cargo.toml index f3b9cd25..6db0d7aa 100644 --- a/deoxys/Cargo.toml +++ b/deoxys/Cargo.toml @@ -15,16 +15,16 @@ keywords = ["aead", "deoxys", "deoxys-i", "deoxys-ii"] categories = ["cryptography", "no-std"] readme = "README.md" edition = "2021" -rust-version = "1.56" +rust-version = "1.72" [dependencies] -aead = { version = "0.5", default-features = false } -aes = { version = "0.8", features = ["hazmat"], default-features = false } +aead = { version = "0.6.0-pre", default-features = false } +aes = { version = "0.9.0-pre", features = ["hazmat"], default-features = false } subtle = { version = "2", default-features = false } zeroize = { version = "1", default-features = false } [dev-dependencies] -aead = { version = "0.5", features = ["dev"], default-features = false } +aead = { version = "0.6.0-pre", features = ["dev"], default-features = false } hex-literal = "0.3" [features] diff --git a/deoxys/src/deoxys_bc.rs b/deoxys/src/deoxys_bc.rs index ff974edf..05945024 100644 --- a/deoxys/src/deoxys_bc.rs +++ b/deoxys/src/deoxys_bc.rs @@ -1,6 +1,6 @@ use aead::{ + array::{Array, ArraySize}, consts::{U15, U16, U17, U32, U48}, - generic_array::{ArrayLength, GenericArray}, }; use crate::DeoxysBcType; @@ -42,14 +42,14 @@ pub struct DeoxysBc256; pub struct DeoxysBc384; pub trait DeoxysBcInternal { - type SubkeysSize: ArrayLength<[u8; 16]>; - type TweakKeySize: ArrayLength; + type SubkeysSize: ArraySize; + type TweakKeySize: ArraySize; fn key_schedule( tweak: &[u8; 16], - subkeys: &GenericArray<[u8; 16], Self::SubkeysSize>, - ) -> GenericArray<[u8; 16], Self::SubkeysSize> { - let mut subtweakeys: GenericArray<[u8; 16], Self::SubkeysSize> = Default::default(); + subkeys: &Array<[u8; 16], Self::SubkeysSize>, + ) -> Array<[u8; 16], Self::SubkeysSize> { + let mut subtweakeys: Array<[u8; 16], Self::SubkeysSize> = Default::default(); let mut tweak = *tweak; // First key @@ -78,10 +78,8 @@ impl DeoxysBcInternal for DeoxysBc256 { impl DeoxysBcType for DeoxysBc256 { type KeySize = U16; - fn precompute_subkeys( - key: &GenericArray, - ) -> GenericArray<[u8; 16], Self::SubkeysSize> { - let mut subkeys: GenericArray<[u8; 16], Self::SubkeysSize> = Default::default(); + fn precompute_subkeys(key: &Array) -> Array<[u8; 16], Self::SubkeysSize> { + let mut subkeys: Array<[u8; 16], Self::SubkeysSize> = Default::default(); let mut tk2 = [0u8; 16]; @@ -118,10 +116,8 @@ impl DeoxysBcInternal for DeoxysBc384 { impl DeoxysBcType for DeoxysBc384 { type KeySize = U32; - fn precompute_subkeys( - key: &GenericArray, - ) -> GenericArray<[u8; 16], Self::SubkeysSize> { - let mut subkeys: GenericArray<[u8; 16], Self::SubkeysSize> = Default::default(); + fn precompute_subkeys(key: &Array) -> Array<[u8; 16], Self::SubkeysSize> { + let mut subkeys: Array<[u8; 16], Self::SubkeysSize> = Default::default(); let mut tk3 = [0u8; 16]; let mut tk2 = [0u8; 16]; diff --git a/deoxys/src/lib.rs b/deoxys/src/lib.rs index 7d44b2e1..ab053fc5 100644 --- a/deoxys/src/lib.rs +++ b/deoxys/src/lib.rs @@ -17,9 +17,9 @@ //! Nonce // Or `Aes128Gcm` //! }; //! -//! let key = DeoxysII256::generate_key(&mut OsRng); +//! let key = DeoxysII256::generate_key()?; //! let cipher = DeoxysII256::new(&key); -//! let nonce = DeoxysII256::generate_nonce(&mut OsRng); // 120-bits; unique per message +//! let nonce = DeoxysII256::generate_nonce()?; // 120-bits; unique per message //! let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref())?; //! let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref())?; //! assert_eq!(&plaintext, b"plaintext message"); @@ -33,10 +33,10 @@ //! use deoxys::{DeoxysII256, Nonce}; // Can be `DeoxysI128`, `DeoxysI256`, `DeoxysII128` of `DeoxysII256` //! use deoxys::aead::{Aead, AeadCore, KeyInit, Payload, OsRng}; //! -//! let key = DeoxysII256::generate_key(&mut OsRng); +//! let key = DeoxysII256::generate_key().expect("generate key"); //! let cipher = DeoxysII256::new(&key); //! -//! let nonce = DeoxysII256::generate_nonce(&mut OsRng); // 120-bits; unique per message +//! let nonce = DeoxysII256::generate_nonce().expect("generate nonce"); // 120-bits; unique per message //! //! let payload = Payload { //! msg: &b"this will be encrypted".as_ref(), @@ -78,10 +78,10 @@ //! use deoxys::{DeoxysII256, Nonce}; // Can be `DeoxysI128`, `DeoxysI256`, `DeoxysII128` of `DeoxysII256` //! use deoxys::aead::{AeadCore, AeadInPlace, KeyInit, OsRng, heapless::Vec}; //! -//! let key = DeoxysII256::generate_key(&mut OsRng); +//! let key = DeoxysII256::generate_key().expect("generate key"); //! let cipher = DeoxysII256::new(&key); //! -//! let nonce = DeoxysII256::generate_nonce(&mut OsRng); // 120-bits; unique per message +//! let nonce = DeoxysII256::generate_nonce().expect("generate nonce"); // 120-bits; unique per message //! //! let mut buffer: Vec = Vec::new(); // Buffer needs 16-bytes overhead for tag //! buffer.extend_from_slice(b"plaintext message"); @@ -111,8 +111,8 @@ mod modes; pub use aead::{self, consts, AeadCore, AeadInPlace, Error, Key, KeyInit, KeySizeUser}; use aead::{ + array::{Array, ArraySize}, consts::{U0, U16}, - generic_array::{ArrayLength, GenericArray}, }; use core::marker::PhantomData; @@ -133,10 +133,10 @@ pub type DeoxysII128 = Deoxys, deoxys_bc pub type DeoxysII256 = Deoxys, deoxys_bc::DeoxysBc384>; /// Deoxys nonces -pub type Nonce = GenericArray; +pub type Nonce = Array; /// Deoxys tags -pub type Tag = GenericArray; +pub type Tag = Array; /// Deoxys encryption modes. /// This type contains the public API for a Deoxys mode, like Deoxys-I and Deoxys-II. @@ -145,25 +145,25 @@ where B: DeoxysBcType, { /// The size of the required nonce - type NonceSize: ArrayLength; + type NonceSize: ArraySize; /// Encrypts the data in place with the specified parameters /// Returns the tag fn encrypt_in_place( - nonce: &GenericArray, + nonce: &Array, associated_data: &[u8], buffer: &mut [u8], - subkeys: &GenericArray<[u8; 16], B::SubkeysSize>, + subkeys: &Array<[u8; 16], B::SubkeysSize>, ) -> [u8; 16]; /// Decrypts the data in place with the specified parameters /// Returns an error if the tag verification fails fn decrypt_in_place( - nonce: &GenericArray, + nonce: &Array, associated_data: &[u8], buffer: &mut [u8], tag: &Tag, - subkeys: &GenericArray<[u8; 16], B::SubkeysSize>, + subkeys: &Array<[u8; 16], B::SubkeysSize>, ) -> Result<(), aead::Error>; } @@ -171,18 +171,16 @@ where /// This type contains the public API for Deoxys-BC implementations, which varies depending on the size of the key. pub trait DeoxysBcType: deoxys_bc::DeoxysBcInternal { /// The size of the required tweakey. - type KeySize: ArrayLength; + type KeySize: ArraySize; /// Precompute the subkeys - fn precompute_subkeys( - key: &GenericArray, - ) -> GenericArray<[u8; 16], Self::SubkeysSize>; + fn precompute_subkeys(key: &Array) -> Array<[u8; 16], Self::SubkeysSize>; /// Encrypts a block of data in place. fn encrypt_in_place( block: &mut [u8; 16], tweak: &[u8; 16], - subkeys: &GenericArray<[u8; 16], Self::SubkeysSize>, + subkeys: &Array<[u8; 16], Self::SubkeysSize>, ) { let keys = Self::key_schedule(tweak, subkeys); @@ -199,7 +197,7 @@ pub trait DeoxysBcType: deoxys_bc::DeoxysBcInternal { fn decrypt_in_place( block: &mut [u8; 16], tweak: &[u8; 16], - subkeys: &GenericArray<[u8; 16], Self::SubkeysSize>, + subkeys: &Array<[u8; 16], Self::SubkeysSize>, ) { let mut keys = Self::key_schedule(tweak, subkeys); @@ -228,7 +226,7 @@ where M: DeoxysMode, B: DeoxysBcType, { - subkeys: GenericArray<[u8; 16], B::SubkeysSize>, + subkeys: Array<[u8; 16], B::SubkeysSize>, mode: PhantomData, } diff --git a/deoxys/src/modes.rs b/deoxys/src/modes.rs index 7bcb6362..74a2f9d8 100644 --- a/deoxys/src/modes.rs +++ b/deoxys/src/modes.rs @@ -1,7 +1,7 @@ use super::{DeoxysBcType, DeoxysMode}; use aead::{ + array::Array, consts::{U15, U16, U8}, - generic_array::GenericArray, }; use core::marker::PhantomData; use subtle::ConstantTimeEq; @@ -31,7 +31,7 @@ where fn compute_ad_tag( associated_data: &[u8], tweak: &mut [u8; 16], - subkeys: &GenericArray<[u8; 16], B::SubkeysSize>, + subkeys: &Array<[u8; 16], B::SubkeysSize>, tag: &mut [u8; 16], ) { if !associated_data.is_empty() { @@ -81,10 +81,10 @@ where type NonceSize = U8; fn encrypt_in_place( - nonce: &GenericArray, + nonce: &Array, associated_data: &[u8], buffer: &mut [u8], - subkeys: &GenericArray<[u8; 16], B::SubkeysSize>, + subkeys: &Array<[u8; 16], B::SubkeysSize>, ) -> [u8; 16] { let mut tag = [0u8; 16]; let mut checksum = [0u8; 16]; @@ -179,11 +179,11 @@ where } fn decrypt_in_place( - nonce: &GenericArray, + nonce: &Array, associated_data: &[u8], buffer: &mut [u8], - tag: &GenericArray, - subkeys: &GenericArray<[u8; 16], B::SubkeysSize>, + tag: &Array, + subkeys: &Array<[u8; 16], B::SubkeysSize>, ) -> Result<(), aead::Error> { let mut computed_tag = [0u8; 16]; let mut checksum = [0u8; 16]; @@ -288,7 +288,7 @@ where fn authenticate_message( buffer: &[u8], tweak: &mut [u8; 16], - subkeys: &GenericArray<[u8; 16], B::SubkeysSize>, + subkeys: &Array<[u8; 16], B::SubkeysSize>, tag: &mut [u8; 16], ) { if !buffer.is_empty() { @@ -329,9 +329,9 @@ where fn encrypt_decrypt_message( buffer: &mut [u8], tweak: &mut [u8; 16], - subkeys: &GenericArray<[u8; 16], B::SubkeysSize>, - tag: &GenericArray, - nonce: &GenericArray, + subkeys: &Array<[u8; 16], B::SubkeysSize>, + tag: &Array, + nonce: &Array, ) { if !buffer.is_empty() { tweak.copy_from_slice(tag); @@ -370,10 +370,10 @@ where type NonceSize = U15; fn encrypt_in_place( - nonce: &GenericArray, + nonce: &Array, associated_data: &[u8], buffer: &mut [u8], - subkeys: &GenericArray<[u8; 16], B::SubkeysSize>, + subkeys: &Array<[u8; 16], B::SubkeysSize>, ) -> [u8; 16] { let mut tag = [0u8; 16]; let mut tweak = [0u8; 16]; @@ -400,11 +400,11 @@ where } fn decrypt_in_place( - nonce: &GenericArray, + nonce: &Array, associated_data: &[u8], buffer: &mut [u8], - tag: &GenericArray, - subkeys: &GenericArray<[u8; 16], B::SubkeysSize>, + tag: &Array, + subkeys: &Array<[u8; 16], B::SubkeysSize>, ) -> Result<(), aead::Error> { let mut computed_tag = [0u8; 16]; let mut tweak = [0u8; 16]; diff --git a/deoxys/tests/deoxys_i_128.rs b/deoxys/tests/deoxys_i_128.rs index b2fee03a..06471ec4 100644 --- a/deoxys/tests/deoxys_i_128.rs +++ b/deoxys/tests/deoxys_i_128.rs @@ -2,7 +2,7 @@ #![cfg(feature = "alloc")] -use deoxys::aead::generic_array::GenericArray; +use deoxys::aead::array::Array; use deoxys::aead::{Aead, KeyInit, Payload}; use deoxys::DeoxysI128; @@ -20,10 +20,10 @@ fn test_deoxys_i_128_1() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext: Vec = Vec::new(); @@ -57,10 +57,10 @@ fn test_deoxys_i_128_2() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext: Vec = Vec::new(); @@ -94,10 +94,10 @@ fn test_deoxys_i_128_3() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext: Vec = Vec::new(); @@ -131,10 +131,10 @@ fn test_deoxys_i_128_4() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext = hex!("4bf8c5ecec375b25acabd687aa605f1a8bb296face74f82527d4944dbb11b757"); @@ -168,10 +168,10 @@ fn test_deoxys_i_128_5() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext = hex!("cded5a43d3c76e942277c2a1517530ad66037897c985305ede345903ed7585a626"); @@ -205,10 +205,10 @@ fn test_deoxys_i_128_6() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext: [u8; 32] = hex!("4bf8c5ecec375b25acabd687aa605f1a8bb296face74f82527d4944dbb11b757"); @@ -243,10 +243,10 @@ fn test_deoxys_i_128_7() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext: [u8; 33] = hex!("09af865850abc0bce7d35f664a63e41b1475d0385e31a6551edf69ea9f2f8b8ed4"); @@ -281,10 +281,10 @@ fn test_deoxys_i_128_8() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext= hex!("f86ecad0d69d2c573cdeee96c90f37ac3c861bd5f4d82ac7396dda102adfa7a94f1daab1e537f03b2a6665eaa8ee057eee403db7ced61adbd77b5c286b7afc5ec23f3f9333773f02d533b0c49ecfc6bcd359bc8a3db6ab16b423efc93e2591e5485a5b21a8cf9312a10d76c840bd1a7e9f5a9954cb636b01ebc8e91a550a0123a50883627d5535f0f6a7960f005d5f340e054ea145dd756e37efd91bc774f93d385da7135372bc51d0401e6499784618da55c31e0b7ad1aa09a3e002f3021ce02926c79741992d9d0252761a7ca6667a56f78e81eaf08cf36d4117d9b2349262d411bef955d7408562ed040e1ea85e3aa3dcf942ea5205edec164dbd6304f90da59b9fb4f8fdeb2c2df473f90494cf09c6af69d191abd7baf97058a3694872d01f63afc225e3796251375a7520a5f755b24b8fd153f362ff09c7e85f02e789ed8cf8adabfcde4c764ebdd703dee39b4e90a91ab0377e0bebc61b2ec9b3c4e3ac7fd893e13c5d0e303e7e625281c988a48dcfd9ee4b698a1c2a82927168e754c99338ea24d24b9bba11cdb4472badc038ab01f250d359c4ade703329062c6260d8fcfda3a6b50b641f9e1e5f2107fd6ca77140dba9048919cab4ea21e4178fde08e7213bf0b730c0415331775039e99f11146b0ebb99a8f5f2d2c4e1767b6fed9c7140dfcf01c793e88889cf34b4ecb044fc740f3d4a2cad1f93455cc36b9a0c6"); diff --git a/deoxys/tests/deoxys_i_256.rs b/deoxys/tests/deoxys_i_256.rs index 207d25d3..387fb6ce 100644 --- a/deoxys/tests/deoxys_i_256.rs +++ b/deoxys/tests/deoxys_i_256.rs @@ -2,7 +2,7 @@ #![cfg(feature = "alloc")] -use deoxys::aead::generic_array::GenericArray; +use deoxys::aead::array::Array; use deoxys::aead::{Aead, KeyInit, Payload}; use deoxys::DeoxysI256; @@ -20,10 +20,10 @@ fn test_deoxys_i_256_1() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("0001020304050607"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext: Vec = Vec::new(); @@ -57,10 +57,10 @@ fn test_deoxys_i_256_2() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("0001020304050607"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext: Vec = Vec::new(); @@ -94,10 +94,10 @@ fn test_deoxys_i_256_3() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("0001020304050607"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext: Vec = Vec::new(); @@ -131,10 +131,10 @@ fn test_deoxys_i_256_4() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("0001020304050607"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext = hex!("2c36c041fa3b1436c5153214131d493be9d014689a6a1e93e4a50989f0342941"); @@ -168,10 +168,10 @@ fn test_deoxys_i_256_5() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("0001020304050607"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext = hex!("fd1ea6745fb5b435751d92be58f5973b84c7589501fcfaff6ce07e2a0e9a72c23e"); @@ -205,10 +205,10 @@ fn test_deoxys_i_256_6() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("0001020304050607"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext: [u8; 32] = hex!("2c36c041fa3b1436c5153214131d493be9d014689a6a1e93e4a50989f0342941"); @@ -243,10 +243,10 @@ fn test_deoxys_i_256_7() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("0001020304050607"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext: [u8; 33] = hex!("705f9db5d50ec6ff0ae28557a5640d32b19504833d5fc6de3baf638cef4cda50bc"); @@ -281,10 +281,10 @@ fn test_deoxys_i_256_8() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("0001020304050607"); - let nonce = GenericArray::from_slice(&nonce[..8]); + let nonce = Array::from_slice(&nonce[..8]); let ciphertext = hex!("e94c5c6df7c19474bbdd292baa2555fdbd5e90a35fb94627cdd7dd3b424ca47d6779f3e6997809204263bdbd4825b7d6510995b1c371e582942bd7f6ab909f993cd5b7db5f95e8b8b56e4cdf016f5cab37f662329b32801fda4403f731fa61f7aa16b9a23f2637b1f75fa0b36ced90ce6a1f73aafbb5adca756e0d59b8ae6661f2d3fc409c88d8baf3836fac55df78b9ba522221345f42bd794c26d5d1a83fed0114d1d1b04d3c3b77ff0083647710b316e17896b2081d9375fde1f2fe063e66423a0d413919ffa6b5754d10de8de64d32ede0d02ebe8f8791d8e9f59462b615f4122dd8c3b97671a8c156eb32ebebb3fb91832fd01f6afee9d4ab045fea83ec87743823ea3bd18f7826229c312ad8a4bc9e2f6d1ad520e6d850bd189b4538d10005abf5a7c50f4f8ded6a62b18cd2a7e6bd3159edc3e9b553cbddd419af540da10576e9ea7d49e2fd0dc1c5ee7693504b63b928e4e23b1753147a3d0ad00cc2e6390fba10e925dc536db4eb30cf152ddb0420f8e8eaa8460feb9a7f0be589ccb877732d8d606085536c405c2ba6c03cb68e12f7d14609587a6c478e2a32794290ba35ce6dba21784d8f6faf401920bfc2aa172c3b4d9bea2eae8542b18410d3a40414247a406379855cb78c28e82ab67b62433a4016b15c4abf4f01c372ba4f1562596531cb0337117ad769eaa666b497b7822eba924e358693bc48cf555f70"); diff --git a/deoxys/tests/deoxys_ii_128.rs b/deoxys/tests/deoxys_ii_128.rs index dad16fd5..6a1229f7 100644 --- a/deoxys/tests/deoxys_ii_128.rs +++ b/deoxys/tests/deoxys_ii_128.rs @@ -2,7 +2,7 @@ #![cfg(feature = "alloc")] -use deoxys::aead::generic_array::GenericArray; +use deoxys::aead::array::Array; use deoxys::aead::{Aead, KeyInit, Payload}; use deoxys::DeoxysII128; @@ -20,10 +20,10 @@ fn test_deoxys_ii_128_1() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext: Vec = Vec::new(); @@ -57,10 +57,10 @@ fn test_deoxys_ii_128_2() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext: Vec = Vec::new(); @@ -94,10 +94,10 @@ fn test_deoxys_ii_128_3() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext: Vec = Vec::new(); @@ -131,10 +131,10 @@ fn test_deoxys_ii_128_4() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext = hex!("fa22f8eb84ee6d2388bdb16150232e856cd5fa3508bc589dad16d284208048c9"); @@ -168,10 +168,10 @@ fn test_deoxys_ii_128_5() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext = hex!("82bf241958b324ed053555d23315d3cc20935527fc970ff34a9f521a95e302136d"); @@ -205,10 +205,10 @@ fn test_deoxys_ii_128_6() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext: [u8; 32] = hex!("9cdb554dfc03bff4feeb94df7736038361a76532b6b5a9c0bdb64a74dee983ff"); @@ -243,10 +243,10 @@ fn test_deoxys_ii_128_7() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext: [u8; 33] = hex!("801f1b81878faca562c8c6c0859b166c2669fbc54b1784be637827b4905729bdf9"); @@ -282,10 +282,10 @@ fn test_deoxys_ii_128_8() { }; let key = hex!("101112131415161718191a1b1c1d1e1f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext= hex!("b8eddddb8d0042bb42fdf675bae285e504b90e4d73e02f99f790b2ffe7815dba40fe4c7bc886ce44505f6ac53d3bba5d3c73efd98daf4b7a5af250a5d100ff5558c211cb03a28d9519502d7d0fc85a6d73e618feb6b503af12cb0330bb9c5743b19996174a84dbf5bac38d10d207067e4ab211a62ad0f85dd8245dfb077443017b7847996fe7ed547b9e02051f1cbe39128e21486b4f73399d0a50d9a1111bed11ebb0547454d0a922633c83f0bba784571f63f55dc33f92e09862471945312d99e40b4ed739556f102afd43055497739a4b22d107e867cc652a5d96974ff785976c82bc1ff89731c780e84a257bb885cd23e00a7bdc7a68e0a1668516fb972721a777429c76cfd4adb45afa554d44a8932d133af8c9254fd3fef2bd0bb65801f2ffbf752f14eaa783e53c2342f021863598e88b20232a0c44e963dd8943e9a54213ffbb174b90e38b55aa9b223e9596acb1517ff21b7458b7694488047797c521883c00762e7227f1e8a5e3f11a43962bdccde8dc4009aef7628a96efa8793d6080982f9b00a7b97d93fd5928702e78427f34eb434e2286de00216b405c36105dc2e8dae68c3342a23274b32a6d2d8ac85239a8fa2947126f505a517fb18847104b21b0326b7fd67efb54f5d0b12b311ef998ebaf14939b7cdb44b35435eedf1ba5b07eea99533f1857b8cc1538290a8dbd44ca696c6bc2f1105451032a650c"); diff --git a/deoxys/tests/deoxys_ii_256.rs b/deoxys/tests/deoxys_ii_256.rs index 5af92334..af70a8ea 100644 --- a/deoxys/tests/deoxys_ii_256.rs +++ b/deoxys/tests/deoxys_ii_256.rs @@ -2,7 +2,7 @@ #![cfg(feature = "alloc")] -use deoxys::aead::generic_array::GenericArray; +use deoxys::aead::array::Array; use deoxys::aead::{Aead, KeyInit, Payload}; use deoxys::DeoxysII256; @@ -20,10 +20,10 @@ fn test_deoxys_ii_256_1() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext: Vec = Vec::new(); @@ -57,10 +57,10 @@ fn test_deoxys_ii_256_2() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext: Vec = Vec::new(); @@ -94,10 +94,10 @@ fn test_deoxys_ii_256_3() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext: Vec = Vec::new(); @@ -131,10 +131,10 @@ fn test_deoxys_ii_256_4() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext = hex!("9da20db1c2781f6669257d87e2a4d9be1970f7581bef2c995e1149331e5e8cc1"); @@ -168,10 +168,10 @@ fn test_deoxys_ii_256_5() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext = hex!("e5ffd2abc5b459a73667756eda6443ede86c0883fc51dd75d22bb14992c684618c"); @@ -205,10 +205,10 @@ fn test_deoxys_ii_256_6() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext: [u8; 32] = hex!("109f8a168b36dfade02628a9e129d5257f03cc7912aefa79729b67b186a2b08f"); @@ -243,10 +243,10 @@ fn test_deoxys_ii_256_7() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext: [u8; 33] = hex!("7d772203fa38be296d8d20d805163130c69aba8cb16ed845c2296c61a8f34b394e"); @@ -282,10 +282,10 @@ fn test_deoxys_ii_256_8() { }; let key = hex!("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); - let key = GenericArray::from_slice(&key); + let key = Array::from_slice(&key); let nonce = hex!("202122232425262728292a2b2c2d2e2f"); - let nonce = GenericArray::from_slice(&nonce[..15]); + let nonce = Array::from_slice(&nonce[..15]); let ciphertext = hex!("88294fcef65a1bdfd7baaa472816c64ef5bef2622b88c1ec5a739396157ef4935f3aa76449e391c32da28ee2857f399ac3dd95aed30cfb26cc0063cd4cd8f7431108176fbf370123856662b000a8348e5925fbb97c9ec0c737758330a7983f06b51590c1d2f5e5faaf0eb58e34e19e5fc85cec03d3926dd46a79ba7026e83dec24e07484c9103dd0cdb0edb505500caca5e1d5dbc71348cf00648821488ebaab7f9d84bbbf91b3c521dbef30110e7bd94f8dad5ab8e0cc5411ca9682d210d5d80c0c4bdbba8181789a4273d6deb80899fdcd976ca6f3a9770b54305f586a04256cfbeb4c11254e88559f294db3b9a94b80ab9f9a02cb4c0748de0af7818685521691dba5738be546dba13a56016fb8635af9dff50f25d1b17ad21707db2640a76a741e65e559b2afaaec0f37e18436bf02008f84dbd7b2698687a22376b65dc7524fca8a28709eee3f3caee3b28ed1173d1e08ee849e2ca63d2c90d555755c8fbafd5d2f4b37f06a1dbd6852ee2ffcfe79d510152e98fc4f3094f740a4aede9ee378b606d34576776bf5f1269f5385a84b3928433bfca177550ccfcd22cd0331bbc595e38c2758b2662476fa66354c4e84c7b360405aa3f5b2a48621bdca1a90c69b21789c91b5b8c568e3c741d99e22f6d7e26f2abed045f1d578b782ab4a5cf2af636d842b3012e180e4b045d8d15b057b69c92398a517053daf9be7c2935e"); diff --git a/eax/Cargo.toml b/eax/Cargo.toml index b2aabfae..0a22e152 100644 --- a/eax/Cargo.toml +++ b/eax/Cargo.toml @@ -17,18 +17,18 @@ documentation = "https://docs.rs/eax" repository = "https://github.com/RustCrypto/AEADs" keywords = ["aead", "aes", "encryption"] categories = ["cryptography", "no-std"] -rust-version = "1.56" +rust-version = "1.65" [dependencies] -aead = { version = "0.5", default-features = false } -cipher = "0.4" -cmac = "0.7" -ctr = "0.9" +aead = { version = "=0.6.0-pre", default-features = false } +cipher = "0.5.0-pre.4" +cmac = "=0.8.0-pre" +ctr = "=0.10.0-pre" subtle = { version = "2", default-features = false } [dev-dependencies] -aead = { version = "0.5", features = ["dev"], default-features = false } -aes = "0.8" +aead = { version = "0.6.0-pre", features = ["dev"], default-features = false } +aes = "=0.9.0-pre" [features] default = ["alloc", "getrandom"] diff --git a/eax/src/lib.rs b/eax/src/lib.rs index e8323d74..acfe96ff 100644 --- a/eax/src/lib.rs +++ b/eax/src/lib.rs @@ -17,15 +17,15 @@ //! # fn main() -> Result<(), Box> { //! use aes::Aes256; //! use eax::{ -//! aead::{Aead, AeadCore, KeyInit, OsRng, generic_array::GenericArray}, +//! aead::{Aead, AeadCore, KeyInit, OsRng, array::Array}, //! Eax, Nonce //! }; //! //! pub type Aes256Eax = Eax; //! -//! let key = Aes256Eax::generate_key(&mut OsRng); +//! let key = Aes256Eax::generate_key()?; //! let cipher = Aes256Eax::new(&key); -//! let nonce = Aes256Eax::generate_nonce(&mut OsRng); // 128-bits; unique per message +//! let nonce = Aes256Eax::generate_nonce()?; // 128-bits; unique per message //! let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref())?; //! let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref())?; //! assert_eq!(&plaintext, b"plaintext message"); @@ -54,17 +54,17 @@ //! use aes::Aes256; //! use eax::Eax; //! use eax::aead::{ -//! generic_array::GenericArray, +//! array::Array, //! heapless::Vec, //! AeadCore, AeadInPlace, KeyInit, OsRng //! }; //! //! pub type Aes256Eax = Eax; //! -//! let key = Aes256Eax::generate_key(&mut OsRng); +//! let key = Aes256Eax::generate_key().expect("generate key"); //! let cipher = Aes256Eax::new(&key); //! -//! let nonce = Aes256Eax::generate_nonce(&mut OsRng); // 128-bits; unique per message +//! let nonce = Aes256Eax::generate_nonce().expect("generate nonce"); // 128-bits; unique per message //! //! let mut buffer: Vec = Vec::new(); //! buffer.extend_from_slice(b"plaintext message"); @@ -95,14 +95,14 @@ //! # { //! use aes::Aes256; //! use eax::Eax; -//! use eax::aead::{AeadInPlace, KeyInit, generic_array::GenericArray}; +//! use eax::aead::{AeadInPlace, KeyInit, array::Array}; //! use eax::aead::heapless::Vec; //! use eax::aead::consts::{U8, U128}; //! -//! let key = GenericArray::from_slice(b"an example very very secret key."); +//! let key = Array::from_slice(b"an example very very secret key."); //! let cipher = Eax::::new(key); //! -//! let nonce = GenericArray::from_slice(b"my unique nonces"); // 128-bits; unique per message +//! let nonce = Array::from_slice(b"my unique nonces"); // 128-bits; unique per message //! //! let mut buffer: Vec = Vec::new(); //! buffer.extend_from_slice(b"plaintext message"); @@ -126,9 +126,10 @@ pub use aead::{self, AeadCore, AeadInPlace, Error, Key, KeyInit, KeySizeUser}; pub use cipher; use cipher::{ + array::Array, consts::{U0, U16}, - generic_array::{functional::FunctionalSequence, GenericArray}, - BlockCipher, BlockEncrypt, InnerIvInit, StreamCipherCore, + crypto_common::OutputSizeUser, + BlockCipher, BlockCipherEncrypt, InnerIvInit, StreamCipherCore, Unsigned, }; use cmac::{digest::Output, Cmac, Mac}; use core::marker::PhantomData; @@ -148,10 +149,12 @@ pub const P_MAX: u64 = 1 << 36; pub const C_MAX: u64 = (1 << 36) + 16; /// EAX nonces -pub type Nonce = GenericArray; +pub type Nonce = Array; /// EAX tags -pub type Tag = GenericArray; +pub type Tag = Array; + +type OutputSize = ::OutputSize; pub mod online; @@ -169,7 +172,7 @@ type Ctr128BE = ctr::CtrCore; #[derive(Clone)] pub struct Eax where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { /// Encryption key @@ -179,7 +182,7 @@ where impl KeySizeUser for Eax where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { type KeySize = Cipher::KeySize; @@ -187,7 +190,7 @@ where impl KeyInit for Eax where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { fn new(key: &Key) -> Self { @@ -200,7 +203,7 @@ where impl AeadCore for Eax where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { type NonceSize = Cipher::BlockSize; @@ -210,7 +213,7 @@ where impl AeadInPlace for Eax where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { fn encrypt_in_place_detached( @@ -243,7 +246,15 @@ where // 5. tag ← n ^ h ^ c // (^ means xor) - let full_tag = n.zip(h, |a, b| a ^ b).zip(c, |a, b| a ^ b); + let full_tag: Array<_, OutputSize>> = n + .into_iter() + .zip(h) + .map(|(a, b)| a ^ b) + .zip(c) + .map(|(a, b)| a ^ b) + .take(OutputSize::>::to_usize()) + .collect(); + let tag = Tag::::clone_from_slice(&full_tag[..M::to_usize()]); Ok(tag) } @@ -270,7 +281,14 @@ where // 5. tag ← n ^ h ^ c // (^ means xor) - let expected_tag = n.zip(h, |a, b| a ^ b).zip(c, |a, b| a ^ b); + let expected_tag: Array<_, OutputSize>> = n + .into_iter() + .zip(h) + .map(|(a, b)| a ^ b) + .zip(c) + .map(|(a, b)| a ^ b) + .take(OutputSize::>::to_usize()) + .collect(); let expected_tag = &expected_tag[..tag.len()]; @@ -290,19 +308,15 @@ where impl Eax where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { /// CMAC/OMAC1 /// /// To avoid constructing new buffers on the heap, an iv encoded into 16 /// bytes is prepended inside this function. - fn cmac_with_iv( - key: &GenericArray, - iv: u8, - data: &[u8], - ) -> Output> { - let mut mac = as Mac>::new(key); + fn cmac_with_iv(key: &Array, iv: u8, data: &[u8]) -> Output> { + let mut mac = as KeyInit>::new(key); mac.update(&[0; 15]); mac.update(&[iv]); mac.update(data); diff --git a/eax/src/online.rs b/eax/src/online.rs index 12ab75a0..5f524702 100644 --- a/eax/src/online.rs +++ b/eax/src/online.rs @@ -13,11 +13,11 @@ //! //! ## Example //! ``` -//! use eax::{Error, online::{Eax, Decrypt, Encrypt}, cipher::generic_array::GenericArray}; +//! use eax::{Error, online::{Eax, Decrypt, Encrypt}, cipher::array::Array}; //! use aes::Aes256; //! -//! let key = GenericArray::from_slice(b"an example very very secret key."); -//! let nonce = GenericArray::from_slice(b"my unique nonces"); // 128-bits; unique per message +//! let key = Array::from_slice(b"an example very very secret key."); +//! let nonce = Array::from_slice(b"my unique nonces"); // 128-bits; unique per message //! let assoc = b"my associated data"; //! let plaintext = b"plaintext message"; //! let mut buffer: [u8; 17] = *plaintext; @@ -60,8 +60,7 @@ use crate::{Cmac, Error, Nonce, Tag, TagSize}; use aead::consts::U16; use cipher::{ - generic_array::functional::FunctionalSequence, BlockCipher, BlockEncrypt, Key, KeyInit, - KeyIvInit, StreamCipher, + array::Array, BlockCipher, BlockCipherEncrypt, Key, KeyInit, KeyIvInit, StreamCipher, Unsigned, }; use cmac::Mac; use core::marker::PhantomData; @@ -100,12 +99,12 @@ impl CipherOp for Decrypt {} /// /// ## Example /// ``` -/// use eax::{Error, online::{Eax, Decrypt, Encrypt}, cipher::generic_array::GenericArray}; +/// use eax::{Error, online::{Eax, Decrypt, Encrypt}, cipher::array::Array}; /// use aes::Aes256; /// -/// let key = GenericArray::from_slice(b"an example very very secret key."); +/// let key = Array::from_slice(b"an example very very secret key."); /// -/// let nonce = GenericArray::from_slice(b"my unique nonces"); // 128-bits; unique per message +/// let nonce = Array::from_slice(b"my unique nonces"); // 128-bits; unique per message /// /// let assoc = b"my associated data"; /// let plaintext = b"plaintext message"; @@ -150,7 +149,7 @@ impl CipherOp for Decrypt {} /// [`finish`]: #method.finish pub struct Eax where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, Op: CipherOp, M: TagSize, { @@ -161,7 +160,7 @@ where impl Eax where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, Op: CipherOp, M: TagSize, { @@ -196,7 +195,7 @@ where impl Eax where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { /// Applies encryption to the plaintext. @@ -217,7 +216,7 @@ where impl Eax where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { /// Applies decryption to the ciphertext **without** verifying the @@ -265,7 +264,7 @@ where #[doc(hidden)] struct EaxImpl where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { @@ -281,14 +280,14 @@ where impl EaxImpl where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { /// Creates a stateful EAX instance that is capable of processing both /// the associated data and the plaintext in an "on-line" fashion. fn with_key_and_nonce(key: &Key, nonce: &Nonce) -> Self { let prepend_cmac = |key, init_val, data| { - let mut cmac = as Mac>::new(key); + let mut cmac = as KeyInit>::new(key); cmac.update(&[0; 15]); cmac.update(&[init_val]); cmac.update(data); @@ -349,7 +348,16 @@ where let h = self.data.finalize().into_bytes(); let c = self.message.finalize().into_bytes(); - let full_tag = self.nonce.zip(h, |a, b| a ^ b).zip(c, |a, b| a ^ b); + let full_tag: Array<_, Cipher::BlockSize> = self + .nonce + .into_iter() + .zip(h) + .map(|(a, b)| a ^ b) + .zip(c) + .map(|(a, b)| a ^ b) + .take(Cipher::BlockSize::to_usize()) + .collect(); + Tag::::clone_from_slice(&full_tag[..M::to_usize()]) } @@ -359,7 +367,16 @@ where let h = self.data.clone().finalize().into_bytes(); let c = self.message.clone().finalize().into_bytes(); - let full_tag = self.nonce.zip(h, |a, b| a ^ b).zip(c, |a, b| a ^ b); + let full_tag: Array<_, Cipher::BlockSize> = self + .nonce + .into_iter() + .zip(h) + .map(|(a, b)| a ^ b) + .zip(c) + .map(|(a, b)| a ^ b) + .take(Cipher::BlockSize::to_usize()) + .collect(); + Tag::::clone_from_slice(&full_tag[..M::to_usize()]) } @@ -386,13 +403,11 @@ where #[cfg(test)] mod test_impl { use super::*; - use aead::{ - consts::U0, generic_array::GenericArray, AeadCore, AeadMutInPlace, KeyInit, KeySizeUser, - }; + use aead::{array::Array, consts::U0, AeadCore, AeadMutInPlace, KeyInit, KeySizeUser}; impl KeySizeUser for EaxImpl where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { type KeySize = Cipher::KeySize; @@ -400,7 +415,7 @@ mod test_impl { impl KeyInit for EaxImpl where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { fn new(key: &Key) -> Self { @@ -409,7 +424,7 @@ mod test_impl { // This is currently done so because that trait only implements // offline operations and thus need to re-initialize the `EaxImpl` // instance. - let nonce = GenericArray::default(); + let nonce = Array::default(); Self::with_key_and_nonce(key, &nonce) } @@ -417,7 +432,7 @@ mod test_impl { impl AeadCore for super::EaxImpl where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { type NonceSize = Cipher::BlockSize; @@ -427,7 +442,7 @@ mod test_impl { impl AeadMutInPlace for super::EaxImpl where - Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + Cipher: BlockCipher + BlockCipherEncrypt + Clone + KeyInit, M: TagSize, { fn encrypt_in_place_detached( diff --git a/eax/src/traits.rs b/eax/src/traits.rs index 5b9fc14a..b2664625 100644 --- a/eax/src/traits.rs +++ b/eax/src/traits.rs @@ -1,7 +1,7 @@ +use aead::array::typenum::type_operators::{IsGreaterOrEqual, IsLessOrEqual}; +use aead::array::typenum::Unsigned; +use aead::array::ArraySize; use aead::consts::{U16, U4}; -use aead::generic_array::typenum::type_operators::{IsGreaterOrEqual, IsLessOrEqual}; -use aead::generic_array::typenum::Unsigned; -use aead::generic_array::ArrayLength; mod private { // Sealed traits stop other crates from implementing any traits that use it. @@ -13,6 +13,6 @@ mod private { } } -pub trait TagSize: ArrayLength + Unsigned + private::SealedTag {} +pub trait TagSize: ArraySize + Unsigned + private::SealedTag {} -impl TagSize for T where T: ArrayLength + IsGreaterOrEqual + IsLessOrEqual {} +impl TagSize for T where T: ArraySize + IsGreaterOrEqual + IsLessOrEqual {} diff --git a/eax/tests/common/mod.rs b/eax/tests/common/mod.rs index 3012f67c..457cd8d5 100644 --- a/eax/tests/common/mod.rs +++ b/eax/tests/common/mod.rs @@ -16,8 +16,8 @@ macro_rules! tests { #[test] fn encrypt() { for vector in $vectors { - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let payload = Payload { msg: vector.plaintext, aad: vector.aad, @@ -32,8 +32,8 @@ macro_rules! tests { #[test] fn decrypt() { for vector in $vectors { - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let ciphertext = Vec::from(vector.ciphertext); let payload = Payload { @@ -51,8 +51,8 @@ macro_rules! tests { #[test] fn decrypt_modified() { let vector = &$vectors[0]; - let key = GenericArray::from_slice(vector.key); - let nonce = GenericArray::from_slice(vector.nonce); + let key = Array::from_slice(vector.key); + let nonce = Array::from_slice(vector.nonce); let mut ciphertext = Vec::from(vector.ciphertext);