Skip to content

Commit

Permalink
Use libc for AArch64 consts too
Browse files Browse the repository at this point in the history
Now that rust-lang/libc#1638 got merged and a
new libc release got made, we can use them instead of hardcoding their
values.

This bumps the libc dependency to the earliest version with these
consts.
  • Loading branch information
linkmauve committed May 6, 2020
1 parent 30b416a commit afe50ee
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 afe50ee

Please sign in to comment.