diff --git a/.github/workflows/sha2.yml b/.github/workflows/sha2.yml index 981228ab..3efb039e 100644 --- a/.github/workflows/sha2.yml +++ b/.github/workflows/sha2.yml @@ -14,7 +14,7 @@ defaults: working-directory: sha2 env: - RUSTFLAGS: "-Dwarnings" + RUSTFLAGS: -Dwarnings CARGO_INCREMENTAL: 0 jobs: @@ -76,6 +76,9 @@ jobs: - uses: RustCrypto/actions/cargo-hack-install@master - run: ${{ matrix.deps }} - run: cargo hack test --feature-powerset + - run: cargo test --all-features + env: + RUSTFLAGS: -Dwarnings --cfg sha2_backend="soft" # macOS tests macos: @@ -93,10 +96,12 @@ jobs: with: toolchain: ${{ matrix.rust }} targets: x86_64-apple-darwin - - uses: RustCrypto/actions/cargo-hack-install@master - run: cargo test --no-default-features - run: cargo test - run: cargo test --all-features + - run: cargo test --all-features + env: + RUSTFLAGS: -Dwarnings --cfg sha2_backend="soft" # Windows tests windows: @@ -118,6 +123,9 @@ jobs: targets: ${{ matrix.target }} - uses: msys2/setup-msys2@v2 - run: cargo test --target ${{ matrix.target }} + - run: cargo test --all-features + env: + RUSTFLAGS: -Dwarnings --cfg sha2_backend="soft" # Cross-compiled tests cross: @@ -159,12 +167,15 @@ jobs: with: toolchain: nightly - run: cargo install cross --git https://github.com/cross-rs/cross - - run: cross test --package sha2 --target riscv64gc-unknown-linux-gnu + - run: cross test --package sha2 --all-features --target riscv64gc-unknown-linux-gnu env: - RUSTFLAGS: '-Dwarnings --cfg sha2_backend="riscv-zknh" -C target-feature=+zknh' - - run: cross test --package sha2 --target riscv64gc-unknown-linux-gnu + RUSTFLAGS: -Dwarnings --cfg sha2_backend="soft" -C target-feature=+zknh + - run: cross test --package sha2 --all-features --target riscv64gc-unknown-linux-gnu env: - RUSTFLAGS: '-Dwarnings --cfg sha2_backend="riscv-zknh-compact" -C target-feature=+zknh' + RUSTFLAGS: -Dwarnings --cfg sha2_backend="riscv-zknh" -C target-feature=+zknh + - run: cross test --package sha2 --all-features --target riscv64gc-unknown-linux-gnu + env: + RUSTFLAGS: -Dwarnings --cfg sha2_backend="riscv-zknh-compact" -C target-feature=+zknh riscv32-zknh: runs-on: ubuntu-latest @@ -175,12 +186,15 @@ jobs: with: toolchain: nightly components: rust-src - - run: cargo build --target riscv32gc-unknown-linux-gnu -Z build-std + - run: cargo build --all-features --target riscv32gc-unknown-linux-gnu -Z build-std + env: + RUSTFLAGS: -Dwarnings --cfg sha2_backend="soft" -C target-feature=+zknh + - run: cargo build --all-features --target riscv32gc-unknown-linux-gnu -Z build-std env: - RUSTFLAGS: '-Dwarnings --cfg sha2_backend="riscv-zknh" -C target-feature=+zknh' - - run: cargo build --target riscv32gc-unknown-linux-gnu -Z build-std + RUSTFLAGS: -Dwarnings --cfg sha2_backend="riscv-zknh" -C target-feature=+zknh + - run: cargo build --all-features --target riscv32gc-unknown-linux-gnu -Z build-std env: - RUSTFLAGS: '-Dwarnings --cfg sha2_backend="riscv-zknh-compact" -C target-feature=+zknh' + RUSTFLAGS: -Dwarnings --cfg sha2_backend="riscv-zknh-compact" -C target-feature=+zknh minimal-versions: uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master diff --git a/sha2/CHANGELOG.md b/sha2/CHANGELOG.md index d467c24d..b0d906d6 100644 --- a/sha2/CHANGELOG.md +++ b/sha2/CHANGELOG.md @@ -6,10 +6,17 @@ 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). ## UNRELEASED +### Added +- RISC-V scalar crypto extension support gated behind `sha2_backend = "riscv-zknh"` or + `sha2_backend = "riscv-zknh-compact"` configuration flags [#614] + ### Removed - `asm`, `asm-aarch64`, `loongarch64_asm`, and `compress` crate features [#542] +- `soft` crate feature. Replaced with `sha2_backend = "soft"` configuration flag [#615] [#542]: https://github.com/RustCrypto/hashes/pull/542 +[#614]: https://github.com/RustCrypto/hashes/pull/614 +[#615]: https://github.com/RustCrypto/hashes/pull/615 ## 0.10.8 (2023-09-26) ### Added diff --git a/sha2/Cargo.toml b/sha2/Cargo.toml index 3bc42abd..ae56a8ac 100644 --- a/sha2/Cargo.toml +++ b/sha2/Cargo.toml @@ -30,13 +30,14 @@ base16ct = { version = "0.2", features = ["alloc"] } [features] default = ["oid", "std"] std = ["digest/std"] -oid = ["digest/oid"] # Enable OID support zeroize = ["digest/zeroize"] -force-soft = [] # Force software implementation +oid = ["digest/oid"] [lints.rust.unexpected_cfgs] level = "warn" -check-cfg = ['cfg(sha2_backend, values("riscv-zknh", "riscv-zknh-compact"))'] +check-cfg = [ + 'cfg(sha2_backend, values("soft", "riscv-zknh", "riscv-zknh-compact"))', +] [package.metadata.docs.rs] all-features = true diff --git a/sha2/src/sha256.rs b/sha2/src/sha256.rs index 016fabaf..5d009ed7 100644 --- a/sha2/src/sha256.rs +++ b/sha2/src/sha256.rs @@ -1,11 +1,11 @@ cfg_if::cfg_if! { - if #[cfg(feature = "force-soft")] { + if #[cfg(sha2_backend = "soft")] { mod soft; use soft::compress; } else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { mod soft; - mod x86; - use x86::compress; + mod x86_shani; + use x86_shani::compress; } else if #[cfg(all( any(target_arch = "riscv32", target_arch = "riscv64"), sha2_backend = "riscv-zknh" diff --git a/sha2/src/sha256/x86.rs b/sha2/src/sha256/x86_shani.rs similarity index 100% rename from sha2/src/sha256/x86.rs rename to sha2/src/sha256/x86_shani.rs diff --git a/sha2/src/sha512.rs b/sha2/src/sha512.rs index 8d0fdbb3..f0daee1e 100644 --- a/sha2/src/sha512.rs +++ b/sha2/src/sha512.rs @@ -1,11 +1,11 @@ cfg_if::cfg_if! { - if #[cfg(feature = "force-soft")] { + if #[cfg(sha2_backend = "soft")] { mod soft; use soft::compress; } else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { mod soft; - mod x86; - use x86::compress; + mod x86_avx2; + use x86_avx2::compress; } else if #[cfg(all( any(target_arch = "riscv32", target_arch = "riscv64"), sha2_backend = "riscv-zknh" diff --git a/sha2/src/sha512/x86.rs b/sha2/src/sha512/x86_avx2.rs similarity index 100% rename from sha2/src/sha512/x86.rs rename to sha2/src/sha512/x86_avx2.rs