Skip to content

Commit

Permalink
Merge pull request #109 from linkmauve/use-libc
Browse files Browse the repository at this point in the history
sha1, sha2: Use libc for AArch64 consts too
  • Loading branch information
tarcieri committed May 6, 2020
2 parents 30b416a + afe50ee commit 5502150
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sha1/Cargo.toml
Expand Up @@ -18,7 +18,7 @@ block-buffer = "0.7"
fake-simd = "0.1"
sha1-asm = { version = "0.4", optional = true }
opaque-debug = "0.2"
libc = { version = "0.2", optional = true }
libc = { version = "0.2.68", optional = true }

[dev-dependencies]
digest = { version = "0.8", features = ["dev"] }
Expand Down
6 changes: 2 additions & 4 deletions sha1/src/aarch64.rs
@@ -1,9 +1,7 @@
// TODO: Import those from libc, see https://github.com/rust-lang/libc/pull/1638
const AT_HWCAP: u64 = 16;
const HWCAP_SHA1: u64 = 32;
use libc::{getauxval, AT_HWCAP, HWCAP_SHA1};

#[inline(always)]
pub fn sha1_supported() -> bool {
let hwcaps: u64 = unsafe { ::libc::getauxval(AT_HWCAP) };
let hwcaps: u64 = unsafe { getauxval(AT_HWCAP) };
(hwcaps & HWCAP_SHA1) != 0
}
2 changes: 1 addition & 1 deletion sha2/Cargo.toml
Expand Up @@ -15,7 +15,7 @@ block-buffer = "0.7"
fake-simd = "0.1"
opaque-debug = "0.2"
sha2-asm = { version="0.5", optional=true }
libc = { version = "0.2", optional = true }
libc = { version = "0.2.68", optional = true }

[dev-dependencies]
digest = { version = "0.8", features = ["dev"] }
Expand Down
6 changes: 2 additions & 4 deletions sha2/src/aarch64.rs
@@ -1,9 +1,7 @@
// TODO: Import those from libc, see https://github.com/rust-lang/libc/pull/1638
const AT_HWCAP: u64 = 16;
const HWCAP_SHA2: u64 = 64;
use libc::{getauxval, AT_HWCAP, HWCAP_SHA2};

#[inline(always)]
pub fn sha2_supported() -> bool {
let hwcaps: u64 = unsafe { ::libc::getauxval(AT_HWCAP) };
let hwcaps: u64 = unsafe { getauxval(AT_HWCAP) };
(hwcaps & HWCAP_SHA2) != 0
}

0 comments on commit 5502150

Please sign in to comment.