diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index 61329150..00000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,10 +0,0 @@ -# Enable hardware AES (ARMv8 Cryptography Extensions) in the `aes` crate on -# aarch64. Without this cfg, `aes` v0.8 falls back to its software -# (fixsliced) backend on ARM — roughly 60x slower per block on Apple -# Silicon. x86_64 AES-NI is auto-detected and needs no flag. -# -# This config covers builds *of this workspace* (tests, benches, examples). -# Downstream crates need the same cfg in their own build configuration to -# get hardware AES on ARM; see the README. -[target.'cfg(target_arch = "aarch64")'] -rustflags = ["--cfg", "aes_armv8"] diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 25dff0d2..164436df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ defaults: jobs: test: - # Both architectures: aarch64 runs hardware AES (`--cfg aes_armv8`), the + # Both architectures: aarch64 runs hardware AES (ARMv8 Crypto Extensions), the # NEON kernels and the NEON PRP builder, which x86_64 never reaches, against # the same pinned vectors. runs-on: ${{ matrix.os }} @@ -42,8 +42,8 @@ jobs: target/ key: ${{ runner.os }}-${{ runner.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: setup rust 1.78 - uses: dtolnay/rust-toolchain@1.78.0 + - name: setup rust 1.89 + uses: dtolnay/rust-toolchain@1.89.0 with: components: clippy, rustfmt @@ -78,8 +78,8 @@ jobs: target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: setup rust 1.78 - uses: dtolnay/rust-toolchain@1.78.0 + - name: setup rust 1.89 + uses: dtolnay/rust-toolchain@1.89.0 - name: "Benchmark" run: cargo bench diff --git a/.tool-versions b/.tool-versions index 2bae8195..0e309e9e 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -rust 1.78.0 +rust 1.89.0 diff --git a/Cargo.lock b/Cargo.lock index 2d10547f..d2f909bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,12 +4,11 @@ version = 4 [[package]] name = "aes" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +version = "0.9.3" +source = "git+https://github.com/RustCrypto/block-ciphers?rev=b99ebe6a2d394833a14a84b79aac60c0c0611577#b99ebe6a2d394833a14a84b79aac60c0c0611577" dependencies = [ - "cfg-if", "cipher", + "cpubits", "cpufeatures", "zeroize", ] @@ -47,12 +46,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "block-modes" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e2211b0817f061502a8dd9f11a37e879e79763e3c698d2418cf824d8cb2f21e" - [[package]] name = "bumpalo" version = "3.16.0" @@ -114,9 +107,9 @@ dependencies = [ [[package]] name = "cipher" -version = "0.4.4" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" dependencies = [ "crypto-common", "inout", @@ -147,11 +140,17 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" dependencies = [ "libc", ] @@ -225,12 +224,11 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto-common" -version = "0.1.6" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" dependencies = [ - "generic-array", - "typenum", + "hybrid-array", ] [[package]] @@ -249,16 +247,6 @@ dependencies = [ "regex", ] -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.15" @@ -298,13 +286,22 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" +[[package]] +name = "hybrid-array" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" +dependencies = [ + "typenum", +] + [[package]] name = "inout" -version = "0.1.3" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7" dependencies = [ - "generic-array", + "hybrid-array", ] [[package]] @@ -460,7 +457,6 @@ name = "ore-rs" version = "0.9.0-rc.1" dependencies = [ "aes", - "block-modes", "byteorder", "chrono", "criterion", @@ -735,9 +731,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.17.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "unicode-ident" @@ -745,12 +741,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "walkdir" version = "2.5.0" @@ -915,18 +905,18 @@ checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "zeroize" -version = "1.8.1" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.4.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 90c529a1..3ebbf19b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,8 @@ members = [ [patch.crates-io] # version 3.16.0 bumpalo = { git = 'https://github.com/fitzgen/bumpalo.git', rev = "4eeab88" } +# Unreleased: block-ciphers #598 fixes the aarch64 slowdown in aes 0.9.3. +# A patch only applies to this workspace (CI, benches), not to crates.io +# users, so ore-rs must not be released while this is here. Remove it once +# an aes release after 0.9.3 is out. +aes = { git = "https://github.com/RustCrypto/block-ciphers", rev = "b99ebe6a2d394833a14a84b79aac60c0c0611577" } diff --git a/packages/ct-dudect/Cargo.lock b/packages/ct-dudect/Cargo.lock index 45f634da..14f88e2f 100644 --- a/packages/ct-dudect/Cargo.lock +++ b/packages/ct-dudect/Cargo.lock @@ -4,13 +4,13 @@ version = 4 [[package]] name = "aes" -version = "0.8.4" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +checksum = "35f0f96ce78e38c3dc6d8948aa8163d06385be74000f3c7a95bf1eef35d3ea32" dependencies = [ - "cfg-if", "cipher", - "cpufeatures 0.2.17", + "cpubits", + "cpufeatures", "zeroize", ] @@ -52,12 +52,6 @@ version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" -[[package]] -name = "block-modes" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e2211b0817f061502a8dd9f11a37e879e79763e3c698d2418cf824d8cb2f21e" - [[package]] name = "block2" version = "0.6.2" @@ -92,15 +86,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" dependencies = [ "cfg-if", - "cpufeatures 0.3.1", + "cpufeatures", "rand_core 0.10.1", ] [[package]] name = "cipher" -version = "0.4.4" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" dependencies = [ "crypto-common", "inout", @@ -122,13 +116,10 @@ dependencies = [ ] [[package]] -name = "cpufeatures" -version = "0.2.17" +name = "cpubits" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" -dependencies = [ - "libc", -] +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" [[package]] name = "cpufeatures" @@ -141,12 +132,11 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.7" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" dependencies = [ - "generic-array", - "typenum", + "hybrid-array", ] [[package]] @@ -192,16 +182,6 @@ dependencies = [ "rand_chacha 0.10.0", ] -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.17" @@ -240,13 +220,22 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hybrid-array" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" +dependencies = [ + "typenum", +] + [[package]] name = "inout" -version = "0.1.4" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7" dependencies = [ - "generic-array", + "hybrid-array", ] [[package]] @@ -356,14 +345,13 @@ checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" [[package]] name = "orderable-bytes" -version = "0.1.1" +version = "0.2.0" [[package]] name = "ore-rs" -version = "0.8.3" +version = "0.9.0-rc.1" dependencies = [ "aes", - "block-modes", "byteorder", "hex", "num", @@ -541,12 +529,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" diff --git a/packages/ct-taint/Cargo.lock b/packages/ct-taint/Cargo.lock index 29677e4d..63482987 100644 --- a/packages/ct-taint/Cargo.lock +++ b/packages/ct-taint/Cargo.lock @@ -4,12 +4,12 @@ version = 4 [[package]] name = "aes" -version = "0.8.4" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +checksum = "35f0f96ce78e38c3dc6d8948aa8163d06385be74000f3c7a95bf1eef35d3ea32" dependencies = [ - "cfg-if", "cipher", + "cpubits", "cpufeatures", "zeroize", ] @@ -54,12 +54,6 @@ version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" -[[package]] -name = "block-modes" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e2211b0817f061502a8dd9f11a37e879e79763e3c698d2418cf824d8cb2f21e" - [[package]] name = "byteorder" version = "1.5.0" @@ -93,9 +87,9 @@ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" [[package]] name = "cipher" -version = "0.4.4" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" dependencies = [ "crypto-common", "inout", @@ -112,11 +106,17 @@ dependencies = [ "libloading", ] +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + [[package]] name = "cpufeatures" -version = "0.2.17" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" dependencies = [ "libc", ] @@ -135,12 +135,11 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.7" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" dependencies = [ - "generic-array", - "typenum", + "hybrid-array", ] [[package]] @@ -158,16 +157,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484" -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.17" @@ -197,13 +186,22 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" +[[package]] +name = "hybrid-array" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" +dependencies = [ + "typenum", +] + [[package]] name = "inout" -version = "0.1.4" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7" dependencies = [ - "generic-array", + "hybrid-array", ] [[package]] @@ -328,10 +326,9 @@ version = "0.2.0" [[package]] name = "ore-rs" -version = "0.8.4" +version = "0.9.0-rc.1" dependencies = [ "aes", - "block-modes", "byteorder", "hex", "num", @@ -523,12 +520,6 @@ version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" diff --git a/packages/orderable-bytes/src/lib.rs b/packages/orderable-bytes/src/lib.rs index d6bb3995..964d2fc2 100644 --- a/packages/orderable-bytes/src/lib.rs +++ b/packages/orderable-bytes/src/lib.rs @@ -216,7 +216,8 @@ impl private::Sealed for &T {} /// A reference encodes exactly as the value it points to. impl OrderableBytes for &T { - type Bytes<'a> = T::Bytes<'a> + type Bytes<'a> + = T::Bytes<'a> where Self: 'a; diff --git a/packages/ore-rs/Cargo.toml b/packages/ore-rs/Cargo.toml index b192f01d..92e665eb 100644 --- a/packages/ore-rs/Cargo.toml +++ b/packages/ore-rs/Cargo.toml @@ -6,6 +6,7 @@ authors = [ "James Sadler ", ] edition = "2018" +rust-version = "1.89" homepage = "https://cipherstash.com" repository = "https://github.com/cipherstash/ore.rs" documentation = "https://docs.rs/ore-rs" @@ -43,8 +44,7 @@ ct-bench = [] kani-full = [] [dependencies] -aes = { version = "0.8.2", features = ["zeroize"] } -block-modes = "0.9.1" +aes = { version = "0.9.3", features = ["zeroize"] } byteorder = "1.4.3" chrono = { version = "0.4.42", default-features = false, optional = true } orderable-bytes = { path = "../orderable-bytes", version = "^0.2", default-features = false } diff --git a/packages/ore-rs/README.md b/packages/ore-rs/README.md index 11626c06..d9fe6274 100644 --- a/packages/ore-rs/README.md +++ b/packages/ore-rs/README.md @@ -56,21 +56,11 @@ Example benchmark results below (from December 2021): ## ARMv8 and Apple Silicon support -ARMv8 and Apple Silicon Macs work out of the box but will default to AES in -software, which is dramatically slower than the hardware backend (~60x per -AES block on an M1 Max). To use the ARMv8 Cryptography Extensions, enable -the `aes` crate's cfg flag — stable Rust is fine (1.61+): - -```toml -# .cargo/config.toml in your project -[target.'cfg(target_arch = "aarch64")'] -rustflags = ["--cfg", "aes_armv8"] -``` - -This repository's own workspace sets this already (tests, benches and -examples get hardware AES); the flag is per-final-binary, so downstream -projects need it in their own build configuration. x86_64 AES-NI is -auto-detected and needs no flag. +Hardware AES is detected at runtime and used automatically: the ARMv8 +Cryptography Extensions on aarch64 (including Apple Silicon) and AES-NI on +x86_64. No build flags are needed in this crate or in downstream projects. +Earlier releases (`aes` 0.8) needed `--cfg aes_armv8` on aarch64; that flag +no longer has any effect and can be removed. ## Security diff --git a/packages/ore-rs/fuzz/Cargo.lock b/packages/ore-rs/fuzz/Cargo.lock index 0ce1a0b1..8313327e 100644 --- a/packages/ore-rs/fuzz/Cargo.lock +++ b/packages/ore-rs/fuzz/Cargo.lock @@ -4,12 +4,12 @@ version = 4 [[package]] name = "aes" -version = "0.8.4" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +checksum = "35f0f96ce78e38c3dc6d8948aa8163d06385be74000f3c7a95bf1eef35d3ea32" dependencies = [ - "cfg-if", "cipher", + "cpubits", "cpufeatures", "zeroize", ] @@ -26,12 +26,6 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" -[[package]] -name = "block-modes" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e2211b0817f061502a8dd9f11a37e879e79763e3c698d2418cf824d8cb2f21e" - [[package]] name = "byteorder" version = "1.5.0" @@ -58,31 +52,36 @@ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" [[package]] name = "cipher" -version = "0.4.4" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" dependencies = [ "crypto-common", "inout", ] +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + [[package]] name = "cpufeatures" -version = "0.2.17" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" dependencies = [ "libc", ] [[package]] name = "crypto-common" -version = "0.1.7" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" dependencies = [ - "generic-array", - "typenum", + "hybrid-array", ] [[package]] @@ -91,16 +90,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484" -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.17" @@ -129,13 +118,22 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hybrid-array" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" +dependencies = [ + "typenum", +] + [[package]] name = "inout" -version = "0.1.4" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7" dependencies = [ - "generic-array", + "hybrid-array", ] [[package]] @@ -242,10 +240,9 @@ version = "0.2.0" [[package]] name = "ore-rs" -version = "0.8.4" +version = "0.9.0-rc.1" dependencies = [ "aes", - "block-modes", "byteorder", "hex", "num", @@ -383,12 +380,6 @@ version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" diff --git a/packages/ore-rs/src/lib.rs b/packages/ore-rs/src/lib.rs index c5dfdd1d..ae5de60e 100644 --- a/packages/ore-rs/src/lib.rs +++ b/packages/ore-rs/src/lib.rs @@ -91,7 +91,7 @@ //! ## Serializing/Deserializing //! //! *Note: this library doesn't use [Serde](https://crates.io/crates/serde) due to some complexities -//! with GenericArray used in the [AES](https://crates.io/crates/aes) library. This may change in the future.* +//! with the array types used by the [AES](https://crates.io/crates/aes) library. This may change in the future.* //! //! To serialize a [`CipherText`] to a vector of bytes: //! diff --git a/packages/ore-rs/src/primitives.rs b/packages/ore-rs/src/primitives.rs index b45ffeb7..39ed8013 100644 --- a/packages/ore-rs/src/primitives.rs +++ b/packages/ore-rs/src/primitives.rs @@ -5,14 +5,21 @@ pub mod prp; pub mod simd; pub(crate) mod stack; -use aes::cipher::{consts::U16, generic_array::GenericArray}; +use aes::cipher::{consts::U16, Array}; use aes::Block; +use core::convert::TryFrom; use thiserror::Error; pub type AesBlock = Block; -pub type PrfKey = GenericArray; -pub type HashKey = GenericArray; +pub type PrfKey = Array; +pub type HashKey = Array; pub const NONCE_SIZE: usize = 16; +/// View a 16-byte slice as an AES-sized array. Panics on any other length, +/// as `GenericArray::from_slice` did; every caller passes a fixed 16-byte range. +pub(crate) fn block_ref(s: &[u8]) -> &Array { + <&Array>::try_from(s).expect("AES block slice must be 16 bytes") +} + pub trait Prf { fn new(key: &PrfKey) -> Self; fn encrypt_all(&self, data: &mut [AesBlock]); diff --git a/packages/ore-rs/src/primitives/cmac.rs b/packages/ore-rs/src/primitives/cmac.rs index d4c89ceb..ce30e5bc 100644 --- a/packages/ore-rs/src/primitives/cmac.rs +++ b/packages/ore-rs/src/primitives/cmac.rs @@ -12,7 +12,7 @@ //! the σ-MMO GF(2^128) doubling. use crate::primitives::hash::gf128_double_u128; -use aes::cipher::{generic_array::GenericArray, BlockEncrypt, KeyInit}; +use aes::cipher::{BlockCipherEncrypt, KeyInit}; use aes::Aes128Enc; use zeroize::Zeroize; @@ -73,7 +73,7 @@ impl CmacAccumulator { /// at the all-zero CBC IV (empty prefix). pub(crate) fn new(key: &[u8; 16]) -> Self { // Encryption only: CMAC never decrypts, so build no decryption schedule. - let cipher = Aes128Enc::new(GenericArray::from_slice(key)); + let cipher = Aes128Enc::new(key.into()); let mut acc = Self { cipher, k1: [0u8; 16], @@ -87,8 +87,7 @@ impl CmacAccumulator { #[inline] fn encrypt(&self, mut b: [u8; 16]) -> [u8; 16] { - self.cipher - .encrypt_block(GenericArray::from_mut_slice(&mut b)); + self.cipher.encrypt_block((&mut b).into()); b } @@ -102,8 +101,7 @@ impl CmacAccumulator { pub(crate) fn absorb(&mut self, block: &[u8; 16]) { let mut mixed = (u128::from_be_bytes(self.state) ^ u128::from_be_bytes(*block)).to_be_bytes(); - self.cipher - .encrypt_block(GenericArray::from_mut_slice(&mut mixed)); + self.cipher.encrypt_block((&mut mixed).into()); self.state = mixed; } @@ -119,8 +117,7 @@ impl CmacAccumulator { ^ u128::from_be_bytes(*final_block) ^ u128::from_be_bytes(self.k1)) .to_be_bytes(); - self.cipher - .encrypt_block(GenericArray::from_mut_slice(&mut mixed)); + self.cipher.encrypt_block((&mut mixed).into()); mixed } @@ -203,9 +200,9 @@ mod tests { /// NIST construction without reusing the accumulator's state threading, so /// it can validate that threading for any block count (not just t∈{1,4}). fn reference_cmac(key: &[u8; 16], blocks: &[[u8; 16]]) -> [u8; 16] { - let cipher = aes::Aes128::new(GenericArray::from_slice(key)); + let cipher = aes::Aes128::new(key.into()); let enc = |mut b: [u8; 16]| { - cipher.encrypt_block(GenericArray::from_mut_slice(&mut b)); + cipher.encrypt_block((&mut b).into()); b }; let k1 = gf128_double_u128(u128::from_be_bytes(enc([0u8; 16]))).to_be_bytes(); diff --git a/packages/ore-rs/src/primitives/hash.rs b/packages/ore-rs/src/primitives/hash.rs index 898c6765..a782a6ce 100644 --- a/packages/ore-rs/src/primitives/hash.rs +++ b/packages/ore-rs/src/primitives/hash.rs @@ -1,5 +1,5 @@ use crate::primitives::{AesBlock, Hash, HashKey}; -use aes::cipher::{generic_array::GenericArray, BlockEncrypt, KeyInit}; +use aes::cipher::{BlockCipherEncrypt, KeyInit}; use aes::Aes128; use zeroize::ZeroizeOnDrop; @@ -10,8 +10,7 @@ pub struct Aes128Z2Hash { impl Hash for Aes128Z2Hash { fn new(key: &HashKey) -> Self { - let key_array = GenericArray::from_slice(key); - let cipher = Aes128::new(key_array); + let cipher = Aes128::new(key); Self { cipher } } @@ -23,10 +22,10 @@ impl Hash for Aes128Z2Hash { * See https://stackoverflow.com/questions/38168956/take-slice-of-certain-length-known-at-compile-time */ assert_eq!(data.len(), 16); - // Can we clone into GenericArray directly? Are we doing an extra copy? + // Can we clone into an AES block directly? Are we doing an extra copy? let mut output = [0u8; 16]; output.clone_from_slice(data); - let block = GenericArray::from_mut_slice(&mut output); + let block = (&mut output).into(); self.cipher.encrypt_block(block); output[0] & 1u8 } @@ -89,7 +88,7 @@ pub const PI_KEY: [u8; 16] = *b"ORE-rs.v2.H-pi.1"; fn pi() -> &'static Aes128 { use std::sync::OnceLock; static PI: OnceLock = OnceLock::new(); - PI.get_or_init(|| Aes128::new(GenericArray::from_slice(&PI_KEY))) + PI.get_or_init(|| Aes128::new(&PI_KEY.into())) } /// GF(2^128) doubling `2·x` on a big-endian field element packed in a `u128` @@ -134,7 +133,7 @@ impl Hash for FixedPiZ2Hash { *slot ^= r; // m = σ(x) ⊕ r } let m_lsb = block[0] & 1u8; - let block = GenericArray::from_mut_slice(&mut block); + let block: &mut AesBlock = (&mut block).into(); pi().encrypt_block(block); (block[0] & 1u8) ^ m_lsb } @@ -185,7 +184,7 @@ mod tests { fn init_hash() -> Aes128Z2Hash { let key: [u8; 16] = hex!("00010203 04050607 08090a0b 0c0d0e0f"); - let key_array = GenericArray::from_slice(&key); + let key_array = &key.into(); Hash::new(key_array) } @@ -230,7 +229,7 @@ mod tests { #[test] fn fixed_pi_scalar_matches_bulk() { let nonce: [u8; 16] = hex!("0f0e0d0c 0b0a0908 07060504 03020100"); - let h: FixedPiZ2Hash = Hash::new(GenericArray::from_slice(&nonce)); + let h: FixedPiZ2Hash = Hash::new(&nonce.into()); for &n in &[64usize, 256usize] { let mut blocks: Vec = (0..n) @@ -239,7 +238,7 @@ mod tests { for (j, slot) in b.iter_mut().enumerate() { *slot = (i.wrapping_mul(31).wrapping_add(j)) as u8; } - *GenericArray::from_slice(&b) + AesBlock::from(b) }) .collect(); diff --git a/packages/ore-rs/src/primitives/prf.rs b/packages/ore-rs/src/primitives/prf.rs index 2edf5656..83fd41b4 100644 --- a/packages/ore-rs/src/primitives/prf.rs +++ b/packages/ore-rs/src/primitives/prf.rs @@ -1,5 +1,5 @@ use crate::primitives::{AesBlock, Prf, PrfKey}; -use aes::cipher::{BlockEncrypt, KeyInit}; +use aes::cipher::{BlockCipherEncrypt, KeyInit}; use aes::Aes128; use zeroize::ZeroizeOnDrop; @@ -8,13 +8,8 @@ pub struct Aes128Prf { cipher: Aes128, } -/* - * This can be made a whole lot simpler - * when the AES crate supports const generics and we don't have to deal with GenericArray. -*/ impl Prf for Aes128Prf { fn new(key: &PrfKey) -> Self { - //let key_array = GenericArray::from_slice(key); let cipher = Aes128::new(key); Self { cipher } } @@ -27,32 +22,36 @@ impl Prf for Aes128Prf { #[cfg(test)] mod tests { use super::*; - use aes::cipher::generic_array::{arr, GenericArray}; + use aes::cipher::Array; use hex_literal::hex; fn init_prf() -> Aes128Prf { let key: [u8; 16] = hex!("00010203 04050607 08090a0b 0c0d0e0f"); - let key_array = GenericArray::from_slice(&key); + let key_array = &key.into(); Prf::new(key_array) } #[test] fn prf_test_single_block() { - let mut input = [arr![u8; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 170]]; + let mut input = [Array([ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 170, + ])]; let prf = init_prf(); prf.encrypt_all(&mut input); assert_eq!( input, - [arr![u8; 183, 103, 151, 211, 249, 253, 170, 135, 117, 243, 131, 50, 27, 15, 170, 59]] + [Array([ + 183, 103, 151, 211, 249, 253, 170, 135, 117, 243, 131, 50, 27, 15, 170, 59 + ])] ); } #[test] fn prf_test_2_blocks() { let mut input = [ - arr![u8; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 170], - arr![u8; 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 170, 255, 221, 97, 170], + Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 170]), + Array([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 170, 255, 221, 97, 170]), ]; let prf = init_prf(); @@ -60,8 +59,8 @@ mod tests { assert_eq!( input, [ - arr![u8; 183, 103, 151, 211, 249, 253, 170, 135, 117, 243, 131, 50, 27, 15, 170, 59], - arr![u8; 100, 192, 41, 108, 208, 245, 146, 251, 188, 245, 156, 28, 33, 210, 70, 50] + Array([183, 103, 151, 211, 249, 253, 170, 135, 117, 243, 131, 50, 27, 15, 170, 59]), + Array([100, 192, 41, 108, 208, 245, 146, 251, 188, 245, 156, 28, 33, 210, 70, 50]) ] ); } diff --git a/packages/ore-rs/src/primitives/prp.rs b/packages/ore-rs/src/primitives/prp.rs index ed269d6e..6b9dd976 100644 --- a/packages/ore-rs/src/primitives/prp.rs +++ b/packages/ore-rs/src/primitives/prp.rs @@ -2,7 +2,7 @@ pub(crate) mod oblivious; pub mod prng; use crate::primitives::prp::prng::Aes128Prng; use crate::primitives::{AesBlock, Prp, PrpError, PrpResult, Symbol}; -use aes::cipher::{generic_array::GenericArray, BlockEncrypt, KeyInit}; +use aes::cipher::{BlockCipherEncrypt, KeyInit}; use aes::Aes128Enc; use zeroize::{Zeroize, ZeroizeOnDrop}; @@ -237,7 +237,7 @@ macro_rules! impl_lemire_fy_prp { // PRNG's counter convention. Shape (i): a fresh key schedule // per call. Shape (ii) skips this via `from_stream`. // Encryption only: no decryption schedule is built or copied. - let cipher = Aes128Enc::new(GenericArray::from_slice(&key[0..16])); + let cipher = Aes128Enc::new(crate::primitives::block_ref(&key[0..16])); let mut blocks = [AesBlock::default(); $stream_blocks]; for (i, b) in blocks.iter_mut().enumerate() { b[0..4].copy_from_slice(&(i as u32).to_be_bytes()); diff --git a/packages/ore-rs/src/primitives/prp/prng.rs b/packages/ore-rs/src/primitives/prp/prng.rs index b16f8b88..54f84ba7 100644 --- a/packages/ore-rs/src/primitives/prp/prng.rs +++ b/packages/ore-rs/src/primitives/prp/prng.rs @@ -1,10 +1,10 @@ -use aes::cipher::{consts::U16, generic_array::GenericArray, BlockEncrypt, KeyInit}; +use aes::cipher::{consts::U16, Array, BlockCipherEncrypt, KeyInit}; use aes::Aes128; use zeroize::{Zeroize, ZeroizeOnDrop}; pub struct Aes128Prng { cipher: Aes128, - data: [GenericArray; 16], + data: [Array; 16], ptr: usize, // flat index into the 256 buffered bytes (block = ptr >> 4) ctr: u32, // increments with each new encryption } @@ -51,7 +51,7 @@ const _: fn() = || { */ impl Aes128Prng { pub fn init(key: &[u8]) -> Self { - let key_array = GenericArray::from_slice(key); + let key_array = crate::primitives::block_ref(key); let cipher = Aes128::new(key_array); let mut prng = Self { cipher, @@ -193,7 +193,7 @@ mod tests { // the destructor and reading the bytes stays provenance-clean. let p: *mut Aes128Prng = &mut *prng as *mut Aes128Prng; let data_ptr = unsafe { ptr::addr_of!((*p).data) as *const u8 }; - let data_len = size_of::<[GenericArray; 16]>(); + let data_len = size_of::<[Array; 16]>(); let survived = unsafe { ptr::drop_in_place(p); // runs Drop -> zeroize(); storage stays owned diff --git a/packages/ore-rs/src/scheme/bit2.rs b/packages/ore-rs/src/scheme/bit2.rs index 42e0abd4..e96953ef 100644 --- a/packages/ore-rs/src/scheme/bit2.rs +++ b/packages/ore-rs/src/scheme/bit2.rs @@ -7,13 +7,12 @@ use crate::{ ciphertext::*, primitives::{ - hash::Aes128Z2Hash, prf::Aes128Prf, AesBlock, Hash, HashKey, Prf, Prp, Symbol, NONCE_SIZE, + block_ref, hash::Aes128Z2Hash, prf::Aes128Prf, AesBlock, Hash, Prf, Prp, Symbol, NONCE_SIZE, }, scheme::width::{AesBlockBuf, Bit8, BlockWidth, FirstDiff, RightBitVec}, OreCipher, OreError, PlainText, }; -use aes::cipher::generic_array::GenericArray; use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha20Rng; use std::cell::RefCell; @@ -143,8 +142,8 @@ impl OreCipher for OreAes128 { let rng: R = SeedableRng::from_entropy(); Ok(OreAes128 { - prf1: Prf::new(GenericArray::from_slice(k1)), - prf2: Prf::new(GenericArray::from_slice(k2)), + prf1: Prf::new(k1.into()), + prf2: Prf::new(k2.into()), rng: RefCell::new(rng), }) } @@ -175,7 +174,7 @@ impl OreCipher for OreAes128 { * there for new schemes; this scheme keeps the construction for * wire compatibility. */ - let hasher: Aes128Z2Hash = Hash::new(AesBlock::from_slice(&right.nonce)); + let hasher: Aes128Z2Hash = Hash::new((&right.nonce).into()); // RO key template: entry `j` of the template holds the *input* // `(x[0..n] ‖ j ‖ n)` for the current block. Between blocks only @@ -290,7 +289,7 @@ impl OreCipher for OreAes128 { return Some(Ordering::Equal); } - let hash_key = HashKey::from_slice(&b_right[0..NONCE_SIZE]); + let hash_key = block_ref(&b_right[0..NONCE_SIZE]); let hash: Aes128Z2Hash = Hash::new(hash_key); if diff.resolve(&hash) == 1 { @@ -347,7 +346,7 @@ impl Ord for CipherText { return Ordering::Equal; } - let hash: Aes128Z2Hash = Hash::new(AesBlock::from_slice(&b.right.nonce)); + let hash: Aes128Z2Hash = Hash::new((&b.right.nonce).into()); if diff.resolve(&hash) == 1 { return Ordering::Greater; } diff --git a/packages/ore-rs/src/scheme/bit2/block_types.rs b/packages/ore-rs/src/scheme/bit2/block_types.rs index 4de40211..52e8adb3 100644 --- a/packages/ore-rs/src/scheme/bit2/block_types.rs +++ b/packages/ore-rs/src/scheme/bit2/block_types.rs @@ -64,7 +64,7 @@ impl CipherTextBlock for LeftBlock16 { if data.len() != Self::BLOCK_SIZE { Err(ParseError) } else { - Ok(Self::clone_from_slice(data)) + Ok(*crate::primitives::block_ref(data)) } } diff --git a/packages/ore-rs/src/scheme/bit2_w6.rs b/packages/ore-rs/src/scheme/bit2_w6.rs index 868e56e9..9e94e631 100644 --- a/packages/ore-rs/src/scheme/bit2_w6.rs +++ b/packages/ore-rs/src/scheme/bit2_w6.rs @@ -28,14 +28,13 @@ use crate::{ ciphertext::*, primitives::{ - hash::FixedPiZ2Hash, prf::Aes128Prf, stack, AesBlock, Hash, HashKey, Prf, Prp, NONCE_SIZE, + block_ref, hash::FixedPiZ2Hash, prf::Aes128Prf, stack, AesBlock, Hash, Prf, Prp, NONCE_SIZE, }, scheme::decompose::Blocks6, scheme::width::{AesBlockBuf, Bit6, BlockWidth, FirstDiff}, OreCipher, OreError, PlainText, }; -use aes::cipher::generic_array::GenericArray; use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha20Rng; use std::cell::RefCell; @@ -116,8 +115,8 @@ const PRF2_LABEL: [u8; 16] = *b"ORE.v2.bit6.prf2"; /// `Aes128Prf` keyed by `AES_k(label)`, wiping the derived key bytes. fn derive_prf(k: &[u8; 16], label: &[u8; 16]) -> Aes128Prf { - let kdf: Aes128Prf = Prf::new(GenericArray::from_slice(k)); - let mut derived = [AesBlock::clone_from_slice(label)]; + let kdf: Aes128Prf = Prf::new(k.into()); + let mut derived = [AesBlock::from(*label)]; kdf.encrypt_all(&mut derived); let prf = Prf::new(&derived[0]); derived[0].as_mut_slice().zeroize(); @@ -184,7 +183,7 @@ impl OreAes128Bit6 { self.rng.borrow_mut().try_fill(&mut right.nonce)?; let seeds = self.derive_prp_seeds(x.inner()); - let hasher: Z2Hash = Hash::new(HashKey::from_slice(&right.nonce)); + let hasher: Z2Hash = Hash::new((&right.nonce).into()); // RO key template, maintained incrementally (see the bit2 sibling). // Entry j for block n is (x[0..n] ‖ j ‖ 0… ‖ n@N ‖ N@15). @@ -340,7 +339,7 @@ impl OreCipher for OreAes128Bit6 { return Some(Ordering::Equal); } - let hash: Z2Hash = Hash::new(HashKey::from_slice(&b_right[0..NONCE_SIZE])); + let hash: Z2Hash = Hash::new(block_ref(&b_right[0..NONCE_SIZE])); if diff.resolve(&hash) == 1 { return Some(Ordering::Greater); @@ -395,7 +394,7 @@ impl Ord for CipherText { return Ordering::Equal; } - let hash: Z2Hash = Hash::new(HashKey::from_slice(&b.right.nonce)); + let hash: Z2Hash = Hash::new((&b.right.nonce).into()); if diff.resolve(&hash) == 1 { return Ordering::Greater; } diff --git a/packages/ore-rs/src/scheme/chained.rs b/packages/ore-rs/src/scheme/chained.rs index ec5278b4..ac6eaa44 100644 --- a/packages/ore-rs/src/scheme/chained.rs +++ b/packages/ore-rs/src/scheme/chained.rs @@ -43,14 +43,14 @@ use rand_chacha::ChaCha20Rng; use subtle_ng::{Choice, ConditionallySelectable, ConstantTimeEq}; use zeroize::{Zeroize, Zeroizing}; -use aes::cipher::{generic_array::GenericArray, BlockEncrypt, KeyInit}; +use aes::cipher::{BlockCipherEncrypt, KeyInit}; use aes::Aes128Enc; use crate::ciphertext::{parse_header, ParseError}; use crate::primitives::cmac::{final_block, prefix_block, Branch, CmacAccumulator, WIDTH_BIT6}; use crate::primitives::hash::FixedPiZ2Hash; use crate::primitives::prp::LemireFyPrp; -use crate::primitives::{stack, AesBlock, Hash, HashKey, Prp}; +use crate::primitives::{block_ref, stack, AesBlock, Hash, Prp}; use crate::scheme::decompose::{num_blocks_6bit, Blocks6}; use crate::scheme::width::FirstDiff; use crate::OreError; @@ -209,9 +209,9 @@ impl OreAes128Bit6Chained { /// (spec §3), so there is no second key. The accumulator key is `k1` run /// through a labelled AES call for domain separation. pub fn init(k1: &[u8; 16]) -> Result { - let cipher = Aes128Enc::new(GenericArray::from_slice(k1)); + let cipher = Aes128Enc::new(k1.into()); let mut k_acc = ACC_KEY_LABEL; - cipher.encrypt_block(GenericArray::from_mut_slice(&mut k_acc)); + cipher.encrypt_block((&mut k_acc).into()); Ok(Self { k_acc, rng: RefCell::new(R::from_entropy()), @@ -254,7 +254,7 @@ impl OreAes128Bit6Chained { let mut acc = CmacAccumulator::new(&self.k_acc); let mut nonce = [0u8; NONCE_LEN]; self.rng.borrow_mut().try_fill(&mut nonce)?; - let hasher = FixedPiZ2Hash::new(HashKey::from_slice(&nonce)); + let hasher = FixedPiZ2Hash::new((&nonce).into()); let mut xt = Vec::with_capacity(count); let mut f = Vec::with_capacity(count); @@ -440,7 +440,7 @@ impl OreAes128Bit6Chained { return ca.cmp(&cb); } - let hasher = FixedPiZ2Hash::new(HashKey::from_slice(nonce_at(b, cb))); + let hasher = FixedPiZ2Hash::new(block_ref(nonce_at(b, cb))); if diff.resolve(&hasher) == 1 { Ordering::Greater } else {