Skip to content

Commit 5657fa4

Browse files
feat(sha2): use latest sha2-asm and enable M1
1 parent ee361ed commit 5657fa4

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

Cargo.lock

+15-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ members = [
2020

2121
[profile.dev]
2222
opt-level = 2
23+
24+
[patch.crates-io]
25+
sha2-asm = { path = "../asm-hashes/sha2" }

sha2/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ digest = "0.9"
1919
block-buffer = "0.9"
2020
opaque-debug = "0.3"
2121
cfg-if = "1.0"
22-
sha2-asm = { version = "0.5", optional = true }
22+
sha2-asm = { version = "0.6", optional = true }
2323

2424
[target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies]
2525
cpuid-bool = "0.2"
@@ -38,3 +38,4 @@ asm = ["sha2-asm", "libc"]
3838
compress = [] # Expose compress function
3939
force-soft = [] # Force software implementation
4040
asm-aarch64 = ["asm"] # DEPRECATED: use `asm` instead
41+

sha2/src/sha256.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ cfg_if::cfg_if! {
155155
}
156156
mod x86;
157157
use x86::compress;
158-
} else if #[cfg(all(feature = "asm", target_arch = "aarch64", target_os = "linux"))] {
158+
} else if #[cfg(all(feature = "asm", target_arch = "aarch64", any(target_os = "macos", target_os = "linux")))] {
159159
mod soft;
160160
mod aarch64;
161161
use aarch64::compress;

sha2/src/sha256/aarch64.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
use libc::{getauxval, AT_HWCAP, HWCAP_SHA2};
2-
1+
#[cfg(target_os = "linux")]
32
#[inline(always)]
43
pub fn sha2_supported() -> bool {
4+
use libc::{getauxval, AT_HWCAP, HWCAP_SHA2};
5+
56
let hwcaps: u64 = unsafe { getauxval(AT_HWCAP) };
67
(hwcaps & HWCAP_SHA2) != 0
78
}
89

10+
#[cfg(target_os = "macos")]
11+
#[inline(always)]
12+
pub fn sha2_supported() -> bool {
13+
// TODO: Verify this is true for all available chips.
14+
true
15+
}
16+
917
pub fn compress(state: &mut [u32; 8], blocks: &[[u8; 64]]) {
1018
// TODO: Replace with https://github.com/rust-lang/rfcs/pull/2725
1119
// after stabilization
1220
if sha2_supported() {
13-
for block in blocks {
14-
sha2_asm::compress256(state, block);
15-
}
21+
sha2_asm::compress256(state, blocks);
1622
} else {
1723
super::soft::compress(state, blocks);
1824
}

0 commit comments

Comments
 (0)