Skip to content

Commit

Permalink
sha2: replace soft crate feature with configuration flag
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Aug 23, 2024
1 parent 03e1d29 commit b286ffa
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
25 changes: 19 additions & 6 deletions .github/workflows/sha2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -94,9 +97,10 @@ jobs:
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 hack test --feature-powerset
- run: cargo test --all-features
env:
RUSTFLAGS: -Dwarnings --cfg sha2_backend="soft"

# Windows tests
windows:
Expand All @@ -118,6 +122,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:
Expand Down Expand Up @@ -159,10 +166,13 @@ 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="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" -C target-feature=+zknh'
- 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-compact" -C target-feature=+zknh'

Expand All @@ -175,10 +185,13 @@ 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
- 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'

Expand Down
7 changes: 7 additions & 0 deletions sha2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions sha2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions sha2/src/sha256.rs
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions sha2/src/sha512.rs
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
File renamed without changes.

0 comments on commit b286ffa

Please sign in to comment.