diff --git a/.github/workflows/aes-soft.yml b/.github/workflows/aes-soft.yml deleted file mode 100644 index 0f65372e..00000000 --- a/.github/workflows/aes-soft.yml +++ /dev/null @@ -1,100 +0,0 @@ -name: aes-soft - -on: - pull_request: - paths: - - "aes/**" - - "Cargo.*" - push: - branches: master - -defaults: - run: - working-directory: aes/aes-soft - -env: - CARGO_INCREMENTAL: 0 - RUSTFLAGS: "-Dwarnings" - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - 1.41.0 # MSRV - - stable - target: - - thumbv7em-none-eabi - - wasm32-unknown-unknown - steps: - - uses: actions/checkout@v1 - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - target: ${{ matrix.target }} - profile: minimal - override: true - - run: cargo build --release --target ${{ matrix.target }} - - test: - runs-on: ubuntu-latest - strategy: - matrix: - include: - # 32-bit Linux - - target: i686-unknown-linux-gnu - rust: 1.41.0 # MSRV - deps: sudo apt install gcc-multilib - - target: i686-unknown-linux-gnu - rust: stable - deps: sudo apt install gcc-multilib - - # 64-bit Linux - - target: x86_64-unknown-linux-gnu - rust: 1.41.0 # MSRV - - target: x86_64-unknown-linux-gnu - rust: stable - steps: - - uses: actions/checkout@v1 - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - target: ${{ matrix.target }} - profile: minimal - override: true - - run: ${{ matrix.deps }} - - run: cargo check --target ${{ matrix.target }} --all-features - - run: cargo test --release --target ${{ matrix.target }} - - run: cargo test --release --target ${{ matrix.target }} --features semi_fixslice - - # Cross-compiled tests - cross: - strategy: - matrix: - include: - # ARM64 - - target: aarch64-unknown-linux-gnu - rust: 1.41.0 # MSRV - - target: aarch64-unknown-linux-gnu - rust: stable - - # PPC32 - - target: powerpc-unknown-linux-gnu - rust: 1.41.0 # MSRV - - target: powerpc-unknown-linux-gnu - rust: stable - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - run: ${{ matrix.deps }} - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - target: ${{ matrix.target }} - profile: minimal - override: true - - run: cargo install cross - - run: cross test --release --target ${{ matrix.target }} - - run: cross test --release --target ${{ matrix.target }} --features semi_fixslice diff --git a/.github/workflows/aes.yml b/.github/workflows/aes.yml index efbbd385..5466bda0 100644 --- a/.github/workflows/aes.yml +++ b/.github/workflows/aes.yml @@ -31,25 +31,106 @@ jobs: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 with: + toolchain: ${{ matrix.rust }} + target: ${{ matrix.target }} profile: minimal + override: true + - run: cargo build --release --target ${{ matrix.target }} + + # Tests for the portable software backend + soft: + runs-on: ubuntu-latest + strategy: + matrix: + include: + # 32-bit Linux + - target: i686-unknown-linux-gnu + rust: 1.41.0 # MSRV + deps: sudo apt install gcc-multilib + - target: i686-unknown-linux-gnu + rust: stable + deps: sudo apt install gcc-multilib + + # 64-bit Linux + - target: x86_64-unknown-linux-gnu + rust: 1.41.0 # MSRV + - target: x86_64-unknown-linux-gnu + rust: stable + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: toolchain: ${{ matrix.rust }} target: ${{ matrix.target }} + profile: minimal override: true - - run: cargo build --no-default-features --release --target ${{ matrix.target }} - test: + - run: ${{ matrix.deps }} + - run: cargo check --target ${{ matrix.target }} --all-features + - run: cargo test --release --target ${{ matrix.target }} + - run: cargo test --release --target ${{ matrix.target }} --features semi_fixslice + + # Tests for the AES-NI backend + aesni: runs-on: ubuntu-latest + env: + CARGO_INCREMENTAL: 0 + RUSTDOCFLAGS: "-Ctarget-feature=+aes,+ssse3" + RUSTFLAGS: "-Dwarnings -Ctarget-feature=+aes,+ssse3" strategy: matrix: - rust: - - 1.41.0 # MSRV - - stable + include: + # 32-bit Linux + - target: i686-unknown-linux-gnu + rust: 1.41.0 # MSRV + deps: sudo apt install gcc-multilib + - target: i686-unknown-linux-gnu + rust: stable + deps: sudo apt install gcc-multilib + + # 64-bit Linux + - target: x86_64-unknown-linux-gnu + rust: 1.41.0 # MSRV + - target: x86_64-unknown-linux-gnu + rust: stable steps: - - uses: actions/checkout@v1 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - - run: cargo check --all-features - - run: cargo test --no-default-features - - run: cargo test - - run: cargo test --all-features + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + - run: ${{ matrix.deps }} + - run: cargo check --all-features + - run: cargo test --no-default-features + - run: cargo test + - run: cargo test --all-features + + # Cross-compiled tests + cross: + strategy: + matrix: + include: + # ARM64 + - target: aarch64-unknown-linux-gnu + rust: 1.41.0 # MSRV + - target: aarch64-unknown-linux-gnu + rust: stable + + # PPC32 + - target: powerpc-unknown-linux-gnu + rust: 1.41.0 # MSRV + - target: powerpc-unknown-linux-gnu + rust: stable + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - run: ${{ matrix.deps }} + - uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + target: ${{ matrix.target }} + profile: minimal + override: true + - run: cargo install cross + - run: cross test --release --target ${{ matrix.target }} + - run: cross test --release --target ${{ matrix.target }} --features semi_fixslice diff --git a/.github/workflows/aesni.yml b/.github/workflows/aesni.yml deleted file mode 100644 index 7b4080b9..00000000 --- a/.github/workflows/aesni.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: aesni - -on: - pull_request: - paths: - - "aes/**" - - "Cargo.*" - push: - branches: master - -defaults: - run: - working-directory: aes/aesni - -env: - CARGO_INCREMENTAL: 0 - RUSTDOCFLAGS: "-C target-feature=+aes,+ssse3" - RUSTFLAGS: "-Dwarnings -C target-feature=+aes,+ssse3" - -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - 1.41.0 # MSRV - - stable - steps: - - uses: actions/checkout@v1 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - - run: cargo check --all-features - - run: cargo test --no-default-features - - run: cargo test - - run: cargo test --all-features diff --git a/Cargo.lock b/Cargo.lock index 93421756..2aa80e20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,25 +3,9 @@ [[package]] name = "aes" version = "0.6.0" -dependencies = [ - "aes-soft", - "aesni", - "cipher", -] - -[[package]] -name = "aes-soft" -version = "0.6.4" -dependencies = [ - "cipher", - "opaque-debug", -] - -[[package]] -name = "aesni" -version = "0.10.0" dependencies = [ "cipher", + "ctr", "opaque-debug", ] @@ -82,6 +66,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "ctr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4a30d54f7443bf3d6191dcd486aca19e67cb3c49fa7a06a319966346707e7f" +dependencies = [ + "cipher", +] + [[package]] name = "des" version = "0.6.0" diff --git a/Cargo.toml b/Cargo.toml index 27a72414..3cc9549c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,6 @@ [workspace] members = [ "aes", - "aes/aes-soft", - "aes/aesni", "blowfish", "block-modes", "gost-modes", diff --git a/aes/Cargo.toml b/aes/Cargo.toml index e3028d84..39d2ed09 100644 --- a/aes/Cargo.toml +++ b/aes/Cargo.toml @@ -1,7 +1,10 @@ [package] name = "aes" version = "0.6.0" -description = "Facade for AES (Rijndael) block ciphers implementations" +description = """ +Pure Rust implementation of the Advanced Encryption Standard (a.k.a. Rijndael) +including support for AES in counter mode (a.k.a. AES-CTR) +""" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -13,12 +16,15 @@ categories = ["cryptography", "no-std"] [dependencies] cipher = "0.2" - -[target.'cfg(not(all(target_feature="aes", target_feature = "sse2", any(target_arch = "x86_64", target_arch = "x86"))))'.dependencies] -aes-soft = { version = "0.6", path = "aes-soft" } - -[target.'cfg(all(target_feature="aes", target_feature = "sse2", any(target_arch = "x86_64", target_arch = "x86")))'.dependencies] -aesni = { version = "0.10", default-features = false, path = "aesni" } +ctr = { version = "0.6", optional = true } +opaque-debug = "0.3" [dev-dependencies] cipher = { version = "0.2", features = ["dev"] } + +[features] +semi_fixslice = [] + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/aes/aes-soft/CHANGELOG.md b/aes/aes-soft/CHANGELOG.md deleted file mode 100644 index 4f0b80a3..00000000 --- a/aes/aes-soft/CHANGELOG.md +++ /dev/null @@ -1,83 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## 0.6.4 (2020-11-16) -### Changed -- Rework of xor_columns ([#197]) -- Implement semi-fixsliced support under `semi_fixslice` Cargo feature ([#195]) - -[#197]: https://github.com/RustCrypto/block-ciphers/pull/197 -[#195]: https://github.com/RustCrypto/block-ciphers/pull/195 - -## 0.6.3 (2020-11-01) -### Changed -- Comprehensive refactoring of fixslice code ([#192]) -- Forbid `unsafe` ([#190]) -- Re-order (`inv`)`_sbox` using custom scheduler ([#189]) - -[#192]: https://github.com/RustCrypto/block-ciphers/pull/192 -[#190]: https://github.com/RustCrypto/block-ciphers/pull/190 -[#189]: https://github.com/RustCrypto/block-ciphers/pull/189 - -## 0.6.2 (2020-10-28) -### Added -- 64-bit fixsliced AES implementation ([#180]) - -### Changed -- Fixsliced AES decryption ([#185]) -- Improved AES fixsliced MixColumns algorithms ([#184]) - -[#185]: https://github.com/RustCrypto/block-ciphers/pull/185 -[#184]: https://github.com/RustCrypto/block-ciphers/pull/184 -[#180]: https://github.com/RustCrypto/block-ciphers/pull/180 - -## 0.6.1 (2020-10-26) -### Changed -- Use fixslicing for AES encryption - 3X performance boost ([#174], [#176], [#177]) -- Additional bitslicing performance optimizations ([#171], [#175]) - -[#177]: https://github.com/RustCrypto/block-ciphers/pull/177 -[#176]: https://github.com/RustCrypto/block-ciphers/pull/176 -[#175]: https://github.com/RustCrypto/block-ciphers/pull/175 -[#174]: https://github.com/RustCrypto/block-ciphers/pull/174 -[#171]: https://github.com/RustCrypto/block-ciphers/pull/171 - -## 0.6.0 (2020-10-16) -### Changed -- Replace `block-cipher`/`stream-cipher` with `cipher` crate ([#167]) -- Performance improvements ([#166]) - -[#167]: https://github.com/RustCrypto/block-ciphers/pull/167 -[#166]: https://github.com/RustCrypto/block-ciphers/pull/166 - -## 0.5.0 (2020-08-07) -### Changed -- Bump `block-cipher` dependency to v0.8 ([#138]) -- Bump `opaque-debug` dependency to v0.3 ([#140]) - -[#138]: https://github.com/RustCrypto/block-ciphers/pull/138 -[#140]: https://github.com/RustCrypto/block-ciphers/pull/140 - -## 0.4.0 (2020-06-05) -### Changed -- Bump `block-cipher` dependency to v0.7 ([#86], [#122]) -- Update to Rust 2018 edition ([#86]) - -[#122]: https://github.com/RustCrypto/block-ciphers/pull/122 -[#86]: https://github.com/RustCrypto/block-ciphers/pull/86 - -## 0.3.3 (2018-12-23) - -## 0.3.2 (2018-10-04) - -## 0.3.1 (2018-10-03) - -## 0.3.0 (2018-10-03) - -## 0.2.0 (2018-07-27) - -## 0.1.0 (2018-03-04) diff --git a/aes/aes-soft/Cargo.toml b/aes/aes-soft/Cargo.toml deleted file mode 100644 index 5c351c26..00000000 --- a/aes/aes-soft/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "aes-soft" -version = "0.6.4" -description = "AES (Rijndael) block ciphers bit-sliced implementation" -authors = ["RustCrypto Developers"] -license = "MIT OR Apache-2.0" -edition = "2018" -documentation = "https://docs.rs/aes-soft" -repository = "https://github.com/RustCrypto/block-ciphers" -keywords = ["crypto", "aes", "rijndael", "block-cipher"] -categories = ["cryptography", "no-std"] - -[dependencies] -cipher = "0.2" -opaque-debug = "0.3" - -[dev-dependencies] -cipher = { version = "0.2", features = ["dev"] } - -[features] -semi_fixslice = [] diff --git a/aes/aes-soft/LICENSE-APACHE b/aes/aes-soft/LICENSE-APACHE deleted file mode 100644 index 78173fa2..00000000 --- a/aes/aes-soft/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/aes/aes-soft/LICENSE-MIT b/aes/aes-soft/LICENSE-MIT deleted file mode 100644 index 95d1222e..00000000 --- a/aes/aes-soft/LICENSE-MIT +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2006-2009 Graydon Hoare -Copyright (c) 2009-2013 Mozilla Foundation -Copyright (c) 2018 Artyom Pavlov - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/aes/aes-soft/benches/aes128.rs b/aes/aes-soft/benches/aes128.rs deleted file mode 100644 index fa562669..00000000 --- a/aes/aes-soft/benches/aes128.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![feature(test)] -extern crate test; - -use aes_soft::cipher::{BlockCipher, NewBlockCipher}; -use aes_soft::Aes128; - -#[bench] -pub fn aes128_new(bh: &mut test::Bencher) { - bh.iter(|| { - let cipher = Aes128::new(&Default::default()); - test::black_box(&cipher); - }); -} - -#[bench] -pub fn aes128_encrypt(bh: &mut test::Bencher) { - let cipher = Aes128::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.encrypt_block(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} - -#[bench] -pub fn aes128_decrypt(bh: &mut test::Bencher) { - let cipher = Aes128::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.decrypt_block(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} - -#[bench] -pub fn aes128_encrypt8(bh: &mut test::Bencher) { - let cipher = Aes128::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.encrypt_blocks(&mut input); - test::black_box(&input); - }); - bh.bytes = (input[0].len() * input.len()) as u64; -} - -#[bench] -pub fn aes128_decrypt8(bh: &mut test::Bencher) { - let cipher = Aes128::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.decrypt_blocks(&mut input); - test::black_box(&input); - }); - bh.bytes = (input[0].len() * input.len()) as u64; -} diff --git a/aes/aes-soft/benches/aes192.rs b/aes/aes-soft/benches/aes192.rs deleted file mode 100644 index c6b28112..00000000 --- a/aes/aes-soft/benches/aes192.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![feature(test)] -extern crate test; - -use aes_soft::cipher::{BlockCipher, NewBlockCipher}; -use aes_soft::Aes192; - -#[bench] -pub fn aes192_new(bh: &mut test::Bencher) { - bh.iter(|| { - let cipher = Aes192::new(&Default::default()); - test::black_box(&cipher); - }); -} - -#[bench] -pub fn aes192_encrypt(bh: &mut test::Bencher) { - let cipher = Aes192::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.encrypt_block(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} - -#[bench] -pub fn aes192_decrypt(bh: &mut test::Bencher) { - let cipher = Aes192::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.decrypt_block(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} - -#[bench] -pub fn aes192_encrypt8(bh: &mut test::Bencher) { - let cipher = Aes192::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.encrypt_blocks(&mut input); - test::black_box(&input); - }); - bh.bytes = (input[0].len() * input.len()) as u64; -} - -#[bench] -pub fn aes192_decrypt8(bh: &mut test::Bencher) { - let cipher = Aes192::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.decrypt_blocks(&mut input); - test::black_box(&input); - }); - bh.bytes = (input[0].len() * input.len()) as u64; -} diff --git a/aes/aes-soft/benches/aes256.rs b/aes/aes-soft/benches/aes256.rs deleted file mode 100644 index c10e44a3..00000000 --- a/aes/aes-soft/benches/aes256.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![feature(test)] -extern crate test; - -use aes_soft::cipher::{BlockCipher, NewBlockCipher}; -use aes_soft::Aes256; - -#[bench] -pub fn aes256_new(bh: &mut test::Bencher) { - bh.iter(|| { - let cipher = Aes256::new(&Default::default()); - test::black_box(&cipher); - }); -} - -#[bench] -pub fn aes256_encrypt(bh: &mut test::Bencher) { - let cipher = Aes256::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.encrypt_block(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} - -#[bench] -pub fn aes256_decrypt(bh: &mut test::Bencher) { - let cipher = Aes256::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.decrypt_block(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} - -#[bench] -pub fn aes256_encrypt8(bh: &mut test::Bencher) { - let cipher = Aes256::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.encrypt_blocks(&mut input); - test::black_box(&input); - }); - bh.bytes = (input[0].len() * input.len()) as u64; -} - -#[bench] -pub fn aes256_decrypt8(bh: &mut test::Bencher) { - let cipher = Aes256::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.decrypt_blocks(&mut input); - test::black_box(&input); - }); - bh.bytes = (input[0].len() * input.len()) as u64; -} diff --git a/aes/aes-soft/src/lib.rs b/aes/aes-soft/src/lib.rs deleted file mode 100644 index 2d30ab1d..00000000 --- a/aes/aes-soft/src/lib.rs +++ /dev/null @@ -1,60 +0,0 @@ -//! AES block cipher constant-time implementation. -//! -//! The `aes-soft` crate implements the AES algorithm completely in software -//! without using any table lookups or other timing dependant mechanisms. -//! -//! The encryption implementation is based on a technique called [fixslicing][1], -//! while the decryption implementation is heavily based on `aessafe` [module][2], -//! from the original `rust-crypto` crate. -//! -//! # Usage example -//! ``` -//! use aes_soft::cipher::generic_array::GenericArray; -//! use aes_soft::cipher::{BlockCipher, NewBlockCipher}; -//! use aes_soft::Aes128; -//! -//! let key = GenericArray::from_slice(&[0u8; 16]); -//! let mut block = GenericArray::clone_from_slice(&[0u8; 16]); -//! let mut block8 = GenericArray::clone_from_slice(&[block; 8]); -//! // Initialize cipher -//! let cipher = aes_soft::Aes128::new(&key); -//! -//! let block_copy = block.clone(); -//! // Encrypt block in-place -//! cipher.encrypt_block(&mut block); -//! // And decrypt it back -//! cipher.decrypt_block(&mut block); -//! assert_eq!(block, block_copy); -//! -//! // We can encrypt 8 blocks simultaneously using -//! // instruction-level parallelism -//! let block8_copy = block8.clone(); -//! cipher.encrypt_blocks(&mut block8); -//! cipher.decrypt_blocks(&mut block8); -//! assert_eq!(block8, block8_copy); -//! ``` -//! -//! [1]: https://eprint.iacr.org/2020/1123.pdf -//! [2]: https://github.com/DaGenix/rust-crypto/blob/master/src/aessafe.rs - -#![no_std] -#![doc( - html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg", - html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg" -)] -#![forbid(unsafe_code)] -#![warn(missing_docs, rust_2018_idioms)] - -#[cfg_attr(not(target_pointer_width = "64"), path = "fixslice32.rs")] -#[cfg_attr(target_pointer_width = "64", path = "fixslice64.rs")] -mod fixslice; -mod impls; - -pub use crate::impls::{Aes128, Aes192, Aes256}; -pub use cipher; - -/// 128-bit AES block -pub type Block = cipher::generic_array::GenericArray; - -/// 8 x 128-bit AES blocks to be processed in parallel -pub type ParBlocks = cipher::generic_array::GenericArray; diff --git a/aes/aes-soft/tests/data/aes128.blb b/aes/aes-soft/tests/data/aes128.blb deleted file mode 100644 index 0accb99e..00000000 Binary files a/aes/aes-soft/tests/data/aes128.blb and /dev/null differ diff --git a/aes/aes-soft/tests/data/aes192.blb b/aes/aes-soft/tests/data/aes192.blb deleted file mode 100644 index b5f70fa0..00000000 Binary files a/aes/aes-soft/tests/data/aes192.blb and /dev/null differ diff --git a/aes/aes-soft/tests/data/aes256.blb b/aes/aes-soft/tests/data/aes256.blb deleted file mode 100644 index 2fa2e3ae..00000000 Binary files a/aes/aes-soft/tests/data/aes256.blb and /dev/null differ diff --git a/aes/aes-soft/tests/lib.rs b/aes/aes-soft/tests/lib.rs deleted file mode 100644 index 874ef06a..00000000 --- a/aes/aes-soft/tests/lib.rs +++ /dev/null @@ -1,6 +0,0 @@ -//! Test vectors are from NESSIE: -//! https://www.cosic.esat.kuleuven.be/nessie/testvectors/ - -cipher::block_cipher_test!(aes128_test, "aes128", aes_soft::Aes128); -cipher::block_cipher_test!(aes192_test, "aes192", aes_soft::Aes192); -cipher::block_cipher_test!(aes256_test, "aes256", aes_soft::Aes256); diff --git a/aes/aesni/CHANGELOG.md b/aes/aesni/CHANGELOG.md deleted file mode 100644 index 4a055df6..00000000 --- a/aes/aesni/CHANGELOG.md +++ /dev/null @@ -1,87 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## 0.10.0 (2020-10-16) -### Added -- `target_feature` annotations to allow intrinsic inlining ([#165]) - -### Changed -- Replace `block-cipher`/`stream-cipher` with `cipher` crate ([#167]) - -[#167]: https://github.com/RustCrypto/block-ciphers/pull/167 -[#165]: https://github.com/RustCrypto/block-ciphers/pull/165 - -## 0.9.0 (2020-08-25) -### Changed -- Bump `stream-cipher` dependency to v0.7 ([#158]) - -### Fixed -- Incorrect values returned by the `SyncStreamCipherSeek::current_pos` method ([#71]) - -[#71]: https://github.com/RustCrypto/block-ciphers/issues/71 -[#158]: https://github.com/RustCrypto/block-ciphers/pull/158 - -## 0.8.0 (2020-08-07) -### Changed -- Bump `block-cipher` dependency to v0.8 and `stream-cipher` to v0.6 ([#138]) -- Bump `opaque-debug` dependency to v0.3 ([#140]) - -[#138]: https://github.com/RustCrypto/block-ciphers/pull/138 -[#140]: https://github.com/RustCrypto/block-ciphers/pull/140 - -## 0.7.0 (2020-06-05) -### Added -- Impl `FromBlockCipher` for AES-CTR types ([#121]) - -### Changed -- Bump `block-cipher` dependency to v0.7 ([#86], [#122]) -- Update to Rust 2018 edition ([#86]) -- Use `mem::zeroed` instead of `mem::uninitialized` on XMM registers ([#109], [#110]) - -[#122]: https://github.com/RustCrypto/block-ciphers/pull/122 -[#121]: https://github.com/RustCrypto/block-ciphers/pull/121 -[#110]: https://github.com/RustCrypto/block-ciphers/pull/110 -[#109]: https://github.com/RustCrypto/block-ciphers/pull/109 -[#86]: https://github.com/RustCrypto/block-ciphers/pull/86 - -## 0.6.0 (2018-11-01) - -## 0.5.1 (2018-10-04) - -## 0.5.0 (2018-10-03) - -## 0.4.1 (2018-08-07) - -## 0.4.0 (2018-07-27) - -## 0.3.5 (2018-06-22) - -## 0.3.4 (2018-06-13) - -## 0.3.3 (2018-06-13) - -## 0.3.2 (2018-06-13) - -## 0.3.1 (2018-03-06) - -## 0.3.0 (2018-03-06) - -## 0.2.2 (2018-03-06) - -## 0.2.1 (2017-12-01) - -## 0.2.0 (2017-11-26) - -## 0.1.4 (2017-08-06) - -## 0.1.3 (2017-08-06) - -## 0.1.2 (2017-08-02) - -## 0.1.1 (2017-07-31) - -## 0.1.0 (2017-07-21)~~~~ diff --git a/aes/aesni/Cargo.toml b/aes/aesni/Cargo.toml deleted file mode 100644 index 99a7f4ff..00000000 --- a/aes/aesni/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "aesni" -version = "0.10.0" -description = "AES (Rijndael) block ciphers implementation using AES-NI" -authors = ["RustCrypto Developers"] -license = "MIT OR Apache-2.0" -edition = "2018" -documentation = "https://docs.rs/aesni" -repository = "https://github.com/RustCrypto/block-ciphers" -keywords = ["crypto", "aes", "rijndael", "block-cipher"] -categories = ["cryptography", "no-std"] - -[dependencies] -cipher = "0.2" -opaque-debug = "0.3" - -[dev-dependencies] -cipher = { version = "0.2", features = ["dev"] } - -[features] -default = ["ctr"] -ctr = [] -nocheck = [] - -[package.metadata.docs.rs] -rustc-args = ["-C", "target-feature=+aes,+ssse3"] -rustdoc-args = ["-C", "target-feature=+aes,+ssse3"] diff --git a/aes/aesni/LICENSE-APACHE b/aes/aesni/LICENSE-APACHE deleted file mode 100644 index 78173fa2..00000000 --- a/aes/aesni/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/aes/aesni/LICENSE-MIT b/aes/aesni/LICENSE-MIT deleted file mode 100644 index 8dcb85b3..00000000 --- a/aes/aesni/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2017 Artyom Pavlov - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/aes/aesni/benches/aes128.rs b/aes/aesni/benches/aes128.rs deleted file mode 100644 index 3c921c6e..00000000 --- a/aes/aesni/benches/aes128.rs +++ /dev/null @@ -1,54 +0,0 @@ -#![feature(test)] - -extern crate test; - -use aesni::cipher::{BlockCipher, NewBlockCipher}; -use aesni::Aes128; - -#[bench] -pub fn aes128_encrypt(bh: &mut test::Bencher) { - let cipher = Aes128::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.encrypt_block(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} - -#[bench] -pub fn aes128_decrypt(bh: &mut test::Bencher) { - let cipher = Aes128::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.decrypt_block(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} - -#[bench] -pub fn aes128_encrypt8(bh: &mut test::Bencher) { - let cipher = Aes128::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.encrypt_blocks(&mut input); - test::black_box(&input); - }); - bh.bytes = (input[0].len() * input.len()) as u64; -} - -#[bench] -pub fn aes128_decrypt8(bh: &mut test::Bencher) { - let cipher = Aes128::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.decrypt_blocks(&mut input); - test::black_box(&input); - }); - bh.bytes = (input[0].len() * input.len()) as u64; -} diff --git a/aes/aesni/benches/aes128_ctr.rs b/aes/aesni/benches/aes128_ctr.rs deleted file mode 100644 index 3b7b1514..00000000 --- a/aes/aesni/benches/aes128_ctr.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![cfg(feature = "ctr")] -#![feature(test)] - -#[cfg(feature = "ctr")] -cipher::stream_cipher_sync_bench!(aesni::Aes128Ctr); diff --git a/aes/aesni/benches/aes192.rs b/aes/aesni/benches/aes192.rs deleted file mode 100644 index e6ce55d1..00000000 --- a/aes/aesni/benches/aes192.rs +++ /dev/null @@ -1,54 +0,0 @@ -#![feature(test)] - -extern crate test; - -use aesni::cipher::{BlockCipher, NewBlockCipher}; -use aesni::Aes192; - -#[bench] -pub fn aes192_encrypt(bh: &mut test::Bencher) { - let cipher = Aes192::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.encrypt_block(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} - -#[bench] -pub fn aes192_decrypt(bh: &mut test::Bencher) { - let cipher = Aes192::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.decrypt_block(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} - -#[bench] -pub fn aes192_encrypt8(bh: &mut test::Bencher) { - let cipher = Aes192::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.encrypt_blocks(&mut input); - test::black_box(&input); - }); - bh.bytes = (input[0].len() * input.len()) as u64; -} - -#[bench] -pub fn aes192_decrypt8(bh: &mut test::Bencher) { - let cipher = Aes192::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.decrypt_blocks(&mut input); - test::black_box(&input); - }); - bh.bytes = (input[0].len() * input.len()) as u64; -} diff --git a/aes/aesni/benches/aes192_ctr.rs b/aes/aesni/benches/aes192_ctr.rs deleted file mode 100644 index 683e98ec..00000000 --- a/aes/aesni/benches/aes192_ctr.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![cfg(feature = "ctr")] -#![feature(test)] - -#[cfg(feature = "ctr")] -cipher::stream_cipher_sync_bench!(aesni::Aes192Ctr); diff --git a/aes/aesni/benches/aes256.rs b/aes/aesni/benches/aes256.rs deleted file mode 100644 index 222c7392..00000000 --- a/aes/aesni/benches/aes256.rs +++ /dev/null @@ -1,54 +0,0 @@ -#![feature(test)] - -extern crate test; - -use aesni::cipher::{BlockCipher, NewBlockCipher}; -use aesni::Aes256; - -#[bench] -pub fn aes256_encrypt(bh: &mut test::Bencher) { - let cipher = Aes256::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.encrypt_block(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} - -#[bench] -pub fn aes256_decrypt(bh: &mut test::Bencher) { - let cipher = Aes256::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.decrypt_block(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} - -#[bench] -pub fn aes256_encrypt8(bh: &mut test::Bencher) { - let cipher = Aes256::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.encrypt_blocks(&mut input); - test::black_box(&input); - }); - bh.bytes = (input[0].len() * input.len()) as u64; -} - -#[bench] -pub fn aes256_decrypt8(bh: &mut test::Bencher) { - let cipher = Aes256::new(&Default::default()); - let mut input = Default::default(); - - bh.iter(|| { - cipher.decrypt_blocks(&mut input); - test::black_box(&input); - }); - bh.bytes = (input[0].len() * input.len()) as u64; -} diff --git a/aes/aesni/benches/aes256_ctr.rs b/aes/aesni/benches/aes256_ctr.rs deleted file mode 100644 index c16079c8..00000000 --- a/aes/aesni/benches/aes256_ctr.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![cfg(feature = "ctr")] -#![feature(test)] - -#[cfg(feature = "ctr")] -cipher::stream_cipher_sync_bench!(aesni::Aes256Ctr); diff --git a/aes/aesni/src/target_checks.rs b/aes/aesni/src/target_checks.rs deleted file mode 100644 index 9d3a568f..00000000 --- a/aes/aesni/src/target_checks.rs +++ /dev/null @@ -1,27 +0,0 @@ -//! Check all target requirements. Note that SSE2 should be enabled by default. -#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))] -compile_error!("crate can only be used on x86 and x86_64 architectures"); - -#[cfg(all( - feature = "ctr", - not(all( - target_feature = "aes", - target_feature = "sse2", - target_feature = "ssse3" - )), -))] -compile_error!( - "enable aes and ssse3 target features, e.g. with \ - RUSTFLAGS=\"-C target-feature=+aes,+ssse3\" environment variable. \ - For x86 target arch additionally enable sse2 target feature." -); - -#[cfg(all( - not(feature = "ctr"), - not(all(target_feature = "aes", target_feature = "sse2")), -))] -compile_error!( - "enable aes target feature, e.g. with \ - RUSTFLAGS=\"-C target-feature=+aes\" environment variable. \ - For x86 target arch additionally enable sse2 target feature." -); diff --git a/aes/aesni/tests/data/aes128.blb b/aes/aesni/tests/data/aes128.blb deleted file mode 100644 index 0accb99e..00000000 Binary files a/aes/aesni/tests/data/aes128.blb and /dev/null differ diff --git a/aes/aesni/tests/data/aes192.blb b/aes/aesni/tests/data/aes192.blb deleted file mode 100644 index b5f70fa0..00000000 Binary files a/aes/aesni/tests/data/aes192.blb and /dev/null differ diff --git a/aes/aesni/tests/data/aes256.blb b/aes/aesni/tests/data/aes256.blb deleted file mode 100644 index 2fa2e3ae..00000000 Binary files a/aes/aesni/tests/data/aes256.blb and /dev/null differ diff --git a/aes/aesni/tests/lib.rs b/aes/aesni/tests/lib.rs deleted file mode 100644 index f0610d68..00000000 --- a/aes/aesni/tests/lib.rs +++ /dev/null @@ -1,6 +0,0 @@ -//! Test vectors are from NESSIE: -//! https://www.cosic.esat.kuleuven.be/nessie/testvectors/ - -cipher::block_cipher_test!(aes128_test, "aes128", aesni::Aes128); -cipher::block_cipher_test!(aes192_test, "aes192", aesni::Aes192); -cipher::block_cipher_test!(aes256_test, "aes256", aesni::Aes256); diff --git a/aes/benches/aes128.rs b/aes/benches/aes128.rs index eccb0b1c..ee62bf00 100644 --- a/aes/benches/aes128.rs +++ b/aes/benches/aes128.rs @@ -1,8 +1,16 @@ #![feature(test)] - extern crate test; -use aes::{Aes128, BlockCipher, NewBlockCipher}; +use aes::cipher::{BlockCipher, NewBlockCipher}; +use aes::Aes128; + +#[bench] +pub fn aes128_new(bh: &mut test::Bencher) { + bh.iter(|| { + let cipher = Aes128::new(&Default::default()); + test::black_box(&cipher); + }); +} #[bench] pub fn aes128_encrypt(bh: &mut test::Bencher) { @@ -51,17 +59,3 @@ pub fn aes128_decrypt8(bh: &mut test::Bencher) { }); bh.bytes = (input[0].len() * input.len()) as u64; } -/* -#[bench] -pub fn ctr_aes128(bh: &mut test::Bencher) { - let mut cipher = aes::CtrAes128::new(&[0; 16], &[0; 16]); - let mut input = [0u8; 10000]; - - - bh.iter(|| { - cipher.xor(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} -*/ diff --git a/aes/benches/aes192.rs b/aes/benches/aes192.rs index 23ec688b..9f869d9b 100644 --- a/aes/benches/aes192.rs +++ b/aes/benches/aes192.rs @@ -1,8 +1,16 @@ #![feature(test)] - extern crate test; -use aes::{Aes192, BlockCipher, NewBlockCipher}; +use aes::cipher::{BlockCipher, NewBlockCipher}; +use aes::Aes192; + +#[bench] +pub fn aes192_new(bh: &mut test::Bencher) { + bh.iter(|| { + let cipher = Aes192::new(&Default::default()); + test::black_box(&cipher); + }); +} #[bench] pub fn aes192_encrypt(bh: &mut test::Bencher) { @@ -51,18 +59,3 @@ pub fn aes192_decrypt8(bh: &mut test::Bencher) { }); bh.bytes = (input[0].len() * input.len()) as u64; } - -/* -#[bench] -pub fn ctr_aes192(bh: &mut test::Bencher) { - let mut cipher = aes::CtrAes192::new(&[0; 24], &[0; 16]); - let mut input = [0u8; 10000]; - - - bh.iter(|| { - cipher.xor(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} -*/ diff --git a/aes/benches/aes256.rs b/aes/benches/aes256.rs index fddd33e9..2e0b1f8f 100644 --- a/aes/benches/aes256.rs +++ b/aes/benches/aes256.rs @@ -1,8 +1,16 @@ #![feature(test)] - extern crate test; -use aes::{Aes256, BlockCipher, NewBlockCipher}; +use aes::cipher::{BlockCipher, NewBlockCipher}; +use aes::Aes256; + +#[bench] +pub fn aes256_new(bh: &mut test::Bencher) { + bh.iter(|| { + let cipher = Aes256::new(&Default::default()); + test::black_box(&cipher); + }); +} #[bench] pub fn aes256_encrypt(bh: &mut test::Bencher) { @@ -51,17 +59,3 @@ pub fn aes256_decrypt8(bh: &mut test::Bencher) { }); bh.bytes = (input[0].len() * input.len()) as u64; } -/* -#[bench] -pub fn ctr_aes256(bh: &mut test::Bencher) { - let mut cipher = aes::CtrAes256::new(&[0; 32], &[0; 16]); - let mut input = [0u8; 10000]; - - - bh.iter(|| { - cipher.xor(&mut input); - test::black_box(&input); - }); - bh.bytes = input.len() as u64; -} -*/ diff --git a/aes/src/lib.rs b/aes/src/lib.rs index e0a55d18..a351c75d 100644 --- a/aes/src/lib.rs +++ b/aes/src/lib.rs @@ -1,12 +1,12 @@ -//! This crate is a wrapper around different implementations of AES block ciphers. +//! Pure Rust implementation of the Advanced Encryption Standard +//! (a.k.a. Rijndael) //! -//! Currently it uses: -//! - [`aes-soft`](https://docs.rs/aes-soft) hardware independent bit-sliced -//! implementation -//! - [`aesni`](https://docs.rs/aesni) implementation using -//! [AES-NI](https://en.wikipedia.org/wiki/AES_instruction_set) instruction set. -//! Used for x86-64 and x86 target architectures with enabled `aes` and `sse2` -//! target features (the latter is usually enabled by default). +//! It provides two different backends based on what target features +//! are specified: +//! - "soft" portable constant-time implementation based on [fixslicing]. +//! - [AES-NI] accelerated implementation for `i686`/`x86_64` target +//! architectures with `target-feature=+aes`, as well as an accelerated +//! AES-CTR implementation with `target-feature=+aes,+ssse3` //! //! Crate switches between implementations automatically at compile time. //! (i.e. it does not use run-time feature detection) @@ -39,28 +39,72 @@ //! ``` //! //! For implementations of block cipher modes of operation see -//! [`block-modes`](https://docs.rs/block-modes) crate. +//! [`block-modes`] crate. +//! +//! [fixslicing]: https://eprint.iacr.org/2020/1123.pdf +//! [AES-NI]: https://en.wikipedia.org/wiki/AES_instruction_set +//! [`block-modes`]: https://docs.rs/block-modes #![no_std] +#![cfg_attr(docsrs, feature(doc_cfg))] #![doc( html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg", html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg" )] -#![deny(unsafe_code)] #![warn(missing_docs, rust_2018_idioms)] -pub use cipher::{self, BlockCipher, NewBlockCipher}; +#[cfg(all( + target_feature = "aes", + target_feature = "sse2", + any(target_arch = "x86_64", target_arch = "x86"), +))] +mod ni; + +#[cfg(not(all( + target_feature = "aes", + target_feature = "sse2", + any(target_arch = "x86_64", target_arch = "x86"), +)))] +mod soft; #[cfg(not(all( target_feature = "aes", target_feature = "sse2", any(target_arch = "x86_64", target_arch = "x86"), )))] -pub use aes_soft::{Aes128, Aes192, Aes256}; +pub use soft::{Aes128, Aes192, Aes256}; #[cfg(all( target_feature = "aes", target_feature = "sse2", any(target_arch = "x86_64", target_arch = "x86"), ))] -pub use aesni::{Aes128, Aes192, Aes256}; +pub use ni::{Aes128, Aes192, Aes256}; + +#[cfg(all( + feature = "ctr", + not(all( + target_feature = "aes", + target_feature = "sse2", + target_feature = "ssse3", + any(target_arch = "x86_64", target_arch = "x86"), + )) +))] +pub use soft::{Aes128Ctr, Aes192Ctr, Aes256Ctr}; + +#[cfg(all( + feature = "ctr", + target_feature = "aes", + target_feature = "sse2", + target_feature = "ssse3", + any(target_arch = "x86_64", target_arch = "x86"), +))] +pub use ni::{Aes128Ctr, Aes192Ctr, Aes256Ctr}; + +pub use cipher::{self, BlockCipher, NewBlockCipher}; + +/// 128-bit AES block +pub type Block = cipher::generic_array::GenericArray; + +/// 8 x 128-bit AES blocks to be processed in parallel +pub type ParBlocks = cipher::generic_array::GenericArray; diff --git a/aes/aesni/src/lib.rs b/aes/src/ni.rs similarity index 56% rename from aes/aesni/src/lib.rs rename to aes/src/ni.rs index 73c49c47..b8d3c262 100644 --- a/aes/aesni/src/lib.rs +++ b/aes/src/ni.rs @@ -32,64 +32,17 @@ //! - [Intel advisory](https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00145.html) //! - [Wikipedia](https://en.wikipedia.org/wiki/Lazy_FP_state_restore) //! -//! # Usage example -//! ``` -//! use aesni::cipher::generic_array::GenericArray; -//! use aesni::cipher::{BlockCipher, NewBlockCipher}; -//! use aesni::Aes128; -//! -//! let key = GenericArray::from_slice(&[0u8; 16]); -//! let mut block = GenericArray::clone_from_slice(&[0u8; 16]); -//! let mut block8 = GenericArray::clone_from_slice(&[block; 8]); -//! // Initialize cipher -//! let cipher = aesni::Aes128::new(&key); -//! -//! let block_copy = block.clone(); -//! // Encrypt block in-place -//! cipher.encrypt_block(&mut block); -//! // And decrypt it back -//! cipher.decrypt_block(&mut block); -//! assert_eq!(block, block_copy); -//! -//! // We can encrypt 8 blocks simultaneously using -//! // instruction-level parallelism -//! let block8_copy = block8.clone(); -//! cipher.encrypt_blocks(&mut block8); -//! cipher.decrypt_blocks(&mut block8); -//! assert_eq!(block8, block8_copy); -//! ``` -//! -//! # Runtime detection -//! If you plan to use AES with runtime detection (e.g. via -//! `is_x86_feature_detected!("aes")`), then you'll need to enable `nocheck` -//! feature to disable compile-time target checks. Note that techincally -//! doing so will make API of this crate unsafe, so you MUST ensure that -//! this crate will be used in contexts with enabled necessary target features! -//! //! # Related documents -//! //! - [Intel AES-NI whitepaper](https://software.intel.com/sites/default/files/article/165683/aes-wp-2012-09-22-v01.pdf) //! - [Use of the AES Instruction Set](https://www.cosic.esat.kuleuven.be/ecrypt/AESday/slides/Use_of_the_AES_Instruction_Set.pdf) -#![no_std] -#![doc( - html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg", - html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg" -)] -#![warn(missing_docs, rust_2018_idioms)] - -pub use cipher; - -#[cfg(feature = "ctr")] -pub use cipher::stream; - -#[cfg(not(feature = "nocheck"))] -mod target_checks; #[macro_use] mod utils; + mod aes128; mod aes192; mod aes256; + #[cfg(feature = "ctr")] mod ctr; @@ -98,9 +51,7 @@ use core::arch::x86 as arch; #[cfg(target_arch = "x86_64")] use core::arch::x86_64 as arch; -pub use crate::aes128::Aes128; -pub use crate::aes192::Aes192; -pub use crate::aes256::Aes256; +pub use self::{aes128::Aes128, aes192::Aes192, aes256::Aes256}; #[cfg(feature = "ctr")] -pub use crate::ctr::{Aes128Ctr, Aes192Ctr, Aes256Ctr}; +pub use self::ctr::{Aes128Ctr, Aes192Ctr, Aes256Ctr}; diff --git a/aes/aesni/src/aes128.rs b/aes/src/ni/aes128.rs similarity index 98% rename from aes/aesni/src/aes128.rs rename to aes/src/ni/aes128.rs index 4339b564..85db802a 100644 --- a/aes/aesni/src/aes128.rs +++ b/aes/src/ni/aes128.rs @@ -1,11 +1,11 @@ -use crate::arch::*; +use super::arch::*; use cipher::{ consts::{U16, U8}, generic_array::GenericArray, BlockCipher, NewBlockCipher, }; -use crate::utils::{Block128, Block128x8}; +use super::utils::{Block128, Block128x8}; mod expand; #[cfg(test)] diff --git a/aes/aesni/src/aes128/expand.rs b/aes/src/ni/aes128/expand.rs similarity index 98% rename from aes/aesni/src/aes128/expand.rs rename to aes/src/ni/aes128/expand.rs index 12f70375..5334b032 100644 --- a/aes/aesni/src/aes128/expand.rs +++ b/aes/src/ni/aes128/expand.rs @@ -1,4 +1,4 @@ -use crate::arch::*; +use crate::ni::arch::*; use core::mem; diff --git a/aes/aesni/src/aes128/test_expand.rs b/aes/src/ni/aes128/test_expand.rs similarity index 99% rename from aes/aesni/src/aes128/test_expand.rs rename to aes/src/ni/aes128/test_expand.rs index bdbdf061..38744e65 100644 --- a/aes/aesni/src/aes128/test_expand.rs +++ b/aes/src/ni/aes128/test_expand.rs @@ -1,5 +1,5 @@ use super::expand::expand; -use crate::utils::check; +use crate::ni::utils::check; #[test] fn test() { diff --git a/aes/aesni/src/aes192.rs b/aes/src/ni/aes192.rs similarity index 98% rename from aes/aesni/src/aes192.rs rename to aes/src/ni/aes192.rs index 75826b6d..b7b27c32 100644 --- a/aes/aesni/src/aes192.rs +++ b/aes/src/ni/aes192.rs @@ -1,11 +1,11 @@ -use crate::arch::*; +use super::arch::*; use cipher::{ consts::{U16, U24, U8}, generic_array::GenericArray, BlockCipher, NewBlockCipher, }; -use crate::utils::{Block128, Block128x8}; +use super::utils::{Block128, Block128x8}; mod expand; #[cfg(test)] diff --git a/aes/aesni/src/aes192/expand.rs b/aes/src/ni/aes192/expand.rs similarity index 99% rename from aes/aesni/src/aes192/expand.rs rename to aes/src/ni/aes192/expand.rs index dbcf4859..553a7930 100644 --- a/aes/aesni/src/aes192/expand.rs +++ b/aes/src/ni/aes192/expand.rs @@ -1,4 +1,4 @@ -use crate::arch::*; +use crate::ni::arch::*; use core::{mem, ptr}; diff --git a/aes/aesni/src/aes192/test_expand.rs b/aes/src/ni/aes192/test_expand.rs similarity index 99% rename from aes/aesni/src/aes192/test_expand.rs rename to aes/src/ni/aes192/test_expand.rs index 1462724f..7811d4c8 100644 --- a/aes/aesni/src/aes192/test_expand.rs +++ b/aes/src/ni/aes192/test_expand.rs @@ -1,5 +1,5 @@ use super::expand::expand; -use crate::utils::check; +use crate::ni::utils::check; #[test] fn test() { diff --git a/aes/aesni/src/aes256.rs b/aes/src/ni/aes256.rs similarity index 98% rename from aes/aesni/src/aes256.rs rename to aes/src/ni/aes256.rs index 9448b20b..19dc769f 100644 --- a/aes/aesni/src/aes256.rs +++ b/aes/src/ni/aes256.rs @@ -1,11 +1,11 @@ -use crate::arch::*; +use super::arch::*; use cipher::{ consts::{U16, U32, U8}, generic_array::GenericArray, BlockCipher, NewBlockCipher, }; -use crate::utils::{Block128, Block128x8}; +use super::utils::{Block128, Block128x8}; mod expand; #[cfg(test)] diff --git a/aes/aesni/src/aes256/expand.rs b/aes/src/ni/aes256/expand.rs similarity index 99% rename from aes/aesni/src/aes256/expand.rs rename to aes/src/ni/aes256/expand.rs index c8bb0999..48dab854 100644 --- a/aes/aesni/src/aes256/expand.rs +++ b/aes/src/ni/aes256/expand.rs @@ -1,4 +1,4 @@ -use crate::arch::*; +use crate::ni::arch::*; use core::mem; diff --git a/aes/aesni/src/aes256/test_expand.rs b/aes/src/ni/aes256/test_expand.rs similarity index 99% rename from aes/aesni/src/aes256/test_expand.rs rename to aes/src/ni/aes256/test_expand.rs index 598b654f..52e728ff 100644 --- a/aes/aesni/src/aes256/test_expand.rs +++ b/aes/src/ni/aes256/test_expand.rs @@ -1,5 +1,5 @@ use super::expand::expand; -use crate::utils::check; +use crate::ni::utils::check; #[test] fn test() { diff --git a/aes/aesni/src/ctr.rs b/aes/src/ni/ctr.rs similarity index 98% rename from aes/aesni/src/ctr.rs rename to aes/src/ni/ctr.rs index 47726f08..e72eecae 100644 --- a/aes/aesni/src/ctr.rs +++ b/aes/src/ni/ctr.rs @@ -1,6 +1,8 @@ +//! AES in counter mode (a.k.a. AES-CTR) + #![allow(clippy::unreadable_literal)] -use crate::arch::*; +use super::arch::*; use core::mem; use super::{Aes128, Aes192, Aes256}; @@ -64,6 +66,7 @@ macro_rules! impl_ctr { ($name:ident, $cipher:ty, $doc:expr) => { #[doc=$doc] #[derive(Clone)] + #[cfg_attr(docsrs, doc(cfg(feature = "ctr")))] pub struct $name { nonce: __m128i, ctr: __m128i, diff --git a/aes/aesni/src/utils.rs b/aes/src/ni/utils.rs similarity index 99% rename from aes/aesni/src/utils.rs rename to aes/src/ni/utils.rs index 4ef30bbd..d7f49e2c 100644 --- a/aes/aesni/src/utils.rs +++ b/aes/src/ni/utils.rs @@ -1,5 +1,5 @@ #[cfg(test)] -use crate::arch::__m128i; +use super::arch::__m128i; #[cfg(test)] use core::mem; diff --git a/aes/src/soft.rs b/aes/src/soft.rs new file mode 100644 index 00000000..192c2ab5 --- /dev/null +++ b/aes/src/soft.rs @@ -0,0 +1,22 @@ +//! AES block cipher constant-time implementation. +//! +//! The implementation uses a technique called [fixslicing][1], an improved +//! form of bitslicing which represents ciphers in a way which enables +//! very efficient constant-time implementations in software. +//! +//! [1]: https://eprint.iacr.org/2020/1123.pdf + +#![deny(unsafe_code)] + +#[cfg_attr(not(target_pointer_width = "64"), path = "soft/fixslice32.rs")] +#[cfg_attr(target_pointer_width = "64", path = "soft/fixslice64.rs")] +mod fixslice; +mod impls; + +#[cfg(feature = "ctr")] +mod ctr; + +pub use self::impls::{Aes128, Aes192, Aes256}; + +#[cfg(feature = "ctr")] +pub use self::ctr::{Aes128Ctr, Aes192Ctr, Aes256Ctr}; diff --git a/aes/src/soft/ctr.rs b/aes/src/soft/ctr.rs new file mode 100644 index 00000000..e29c5b0d --- /dev/null +++ b/aes/src/soft/ctr.rs @@ -0,0 +1,15 @@ +//! AES in counter mode (a.k.a. AES-CTR) + +use super::{Aes128, Aes192, Aes256}; + +/// AES-128 in CTR mode +#[cfg_attr(docsrs, doc(cfg(feature = "ctr")))] +pub type Aes128Ctr = ::ctr::Ctr128; + +/// AES-192 in CTR mode +#[cfg_attr(docsrs, doc(cfg(feature = "ctr")))] +pub type Aes192Ctr = ::ctr::Ctr128; + +/// AES-256 in CTR mode +#[cfg_attr(docsrs, doc(cfg(feature = "ctr")))] +pub type Aes256Ctr = ::ctr::Ctr128; diff --git a/aes/aes-soft/src/fixslice32.rs b/aes/src/soft/fixslice32.rs similarity index 100% rename from aes/aes-soft/src/fixslice32.rs rename to aes/src/soft/fixslice32.rs diff --git a/aes/aes-soft/src/fixslice64.rs b/aes/src/soft/fixslice64.rs similarity index 100% rename from aes/aes-soft/src/fixslice64.rs rename to aes/src/soft/fixslice64.rs diff --git a/aes/aes-soft/src/impls.rs b/aes/src/soft/impls.rs similarity index 91% rename from aes/aes-soft/src/impls.rs rename to aes/src/soft/impls.rs index 901f4b10..33952b1d 100644 --- a/aes/aes-soft/src/impls.rs +++ b/aes/src/soft/impls.rs @@ -1,14 +1,13 @@ -pub use cipher::{BlockCipher, NewBlockCipher}; +//! Macros for implementing `Aes*` structs and the `BlockCipher` interface use cipher::{ consts::{U16, U24, U32, U8}, generic_array::GenericArray, + BlockCipher, NewBlockCipher, }; -use crate::{ - fixslice::{self, FixsliceKeys128, FixsliceKeys192, FixsliceKeys256, FIXSLICE_BLOCKS}, - Block, ParBlocks, -}; +use super::fixslice::{self, FixsliceKeys128, FixsliceKeys192, FixsliceKeys256, FIXSLICE_BLOCKS}; +use crate::{Block, ParBlocks}; macro_rules! define_aes_impl { ( diff --git a/aes/aesni/tests/ctr.rs b/aes/tests/ctr.rs similarity index 90% rename from aes/aesni/tests/ctr.rs rename to aes/tests/ctr.rs index 6a8d6b48..70a3f9f6 100644 --- a/aes/aesni/tests/ctr.rs +++ b/aes/tests/ctr.rs @@ -1,6 +1,6 @@ #![cfg(feature = "ctr")] -use aesni::{Aes128Ctr, Aes256Ctr}; +use aes::{Aes128Ctr, Aes256Ctr}; // Random tests generated by OpenSSL cipher::stream_cipher_sync_test!(aes128_ctr_core, Aes128Ctr, "aes128-ctr"); diff --git a/aes/aesni/tests/data/aes128-ctr.blb b/aes/tests/data/aes128-ctr.blb similarity index 100% rename from aes/aesni/tests/data/aes128-ctr.blb rename to aes/tests/data/aes128-ctr.blb diff --git a/aes/aesni/tests/data/aes256-ctr.blb b/aes/tests/data/aes256-ctr.blb similarity index 100% rename from aes/aesni/tests/data/aes256-ctr.blb rename to aes/tests/data/aes256-ctr.blb