Skip to content

Commit 50ea2ee

Browse files
authored
sha2: document available backends (#690)
1 parent d656e7c commit 50ea2ee

File tree

7 files changed

+31
-8
lines changed

7 files changed

+31
-8
lines changed

sha2/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ assert_eq!(hash512, hex!(
5959

6060
Also, see the [examples section] in the RustCrypto/hashes readme.
6161

62+
## Backends
63+
64+
This crate supports the following backends:
65+
- `soft`: portable implementation with fully unrolled rounds
66+
- `soft-compact`: portable implementation which produces smaller binaries
67+
- `aarch64-sha2`: uses the AArch64 `sha2` extension, fallbacks to the `soft` backend
68+
if the extension is not available
69+
- `loongarch64-asm`: `asm!`-based implementation for LoongArch64 targets
70+
- `riscv-zknh`: uses the RISC-V `Zknh` scalar crypto extension (experimental)
71+
- `riscv-zknh-compact`: same as `riscv_zknh` but does not unroll rounds (experimental)
72+
- `wasm32-simd`: uses the WASM `simd128` extension
73+
- `x86-shani`: uses the x86 SHA-NI extension, fallbacks to the `soft` backend
74+
if the extension is not available (SHA-256 only)
75+
- `x86-avx2`: uses the x86 AVX2 extension, fallbacks to the `soft` backend
76+
if the extension is not available (SHA-512 only)
77+
78+
You can force backend selection using the `sha2_backend` configuration flag. It can be enabled
79+
using either environment variable (e.g. `RUSTFLAGS='--cfg sha2_backend="soft"' cargo build`), or
80+
by modifying your `.cargo/config.toml` file. Currently the flag supports the following values:
81+
`soft`, `soft-compact`, `riscv-zknh`, and `riscv-zknh-compact`.
82+
83+
Note that the RISC-V backends are experimental and require Nightly compiler.
84+
6285
## License
6386

6487
The crate is licensed under either of:

sha2/src/sha256.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ cfg_if::cfg_if! {
2525
use riscv_zknh_compact::compress;
2626
} else if #[cfg(target_arch = "aarch64")] {
2727
mod soft;
28-
mod aarch64;
29-
use aarch64::compress;
28+
mod aarch64_sha2;
29+
use aarch64_sha2::compress;
3030
} else if #[cfg(target_arch = "loongarch64")] {
3131
mod loongarch64_asm;
3232
use loongarch64_asm::compress;
3333
} else if #[cfg(all(target_arch = "wasm32", target_feature = "simd128"))] {
34-
mod wasm32;
35-
use wasm32::compress;
34+
mod wasm32_simd128;
35+
use wasm32_simd128::compress;
3636
} else {
3737
mod soft;
3838
use soft::compress;
File renamed without changes.
File renamed without changes.

sha2/src/sha512.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ cfg_if::cfg_if! {
2525
use riscv_zknh_compact::compress;
2626
} else if #[cfg(target_arch = "aarch64")] {
2727
mod soft;
28-
mod aarch64;
29-
use aarch64::compress;
28+
mod aarch64_sha2;
29+
use aarch64_sha2::compress;
3030
} else if #[cfg(target_arch = "loongarch64")] {
3131
mod loongarch64_asm;
3232
use loongarch64_asm::compress;
3333
} else if #[cfg(all(target_arch = "wasm32", target_feature = "simd128"))] {
34-
mod wasm32;
35-
use wasm32::compress;
34+
mod wasm32_simd128;
35+
use wasm32_simd128::compress;
3636
} else {
3737
mod soft;
3838
use soft::compress;
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)