Skip to content

Commit

Permalink
sha1: bump sha1-asm to v0.5 (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri authored Jul 18, 2021
1 parent 5f9d064 commit 1b4a55c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions sha1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ digest = "0.9"
block-buffer = "0.9"
opaque-debug = "0.3"
cfg-if = "1.0"
sha1-asm = { version = "0.4", optional = true }
sha1-asm = { version = "0.5", optional = true }

[target.'cfg(any(target_arch = "aarch64", target_arch = "x86_64", target_arch = "x86"))'.dependencies]
[target.'cfg(any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64"))'.dependencies]
cpufeatures = "0.1.5"

[dev-dependencies]
Expand Down
4 changes: 1 addition & 3 deletions sha1/src/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ cfg_if::cfg_if! {
#[cfg(feature = "asm")]
mod soft {
pub(crate) fn compress(state: &mut [u32; 5], blocks: &[[u8; 64]]) {
for block in blocks {
sha1_asm::compress(state, block);
}
sha1_asm::compress(state, blocks)
}
}
mod x86;
Expand Down
20 changes: 9 additions & 11 deletions sha1/src/compress/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
//! SHA-1 `aarch64` backend.

/// Per rustc target feature docs for `aarch64-unknown-linux-gnu` and
/// `aarch64-apple-darwin` platforms, the `sha2` target feature enables
/// SHA-1 as well:
///
/// > Enable SHA1 and SHA256 support.
cpufeatures::new!(sha2_hwcap, "sha2");
// Per rustc target feature docs for `aarch64-unknown-linux-gnu` and
// `aarch64-apple-darwin` platforms, the `sha2` target feature enables
// SHA-1 as well:
//
// > Enable SHA1 and SHA256 support.
cpufeatures::new!(sha1_hwcap, "sha2");

pub fn compress(state: &mut [u32; 5], blocks: &[u8; 64]) {
pub fn compress(state: &mut [u32; 5], blocks: &[[u8; 64]]) {
// TODO: Replace with https://github.com/rust-lang/rfcs/pull/2725
// after stabilization
if sha2_hwcap::get() {
for block in blocks {
sha1_asm::compress(state, block);
}
if sha1_hwcap::get() {
sha1_asm::compress(state, blocks);
} else {
super::soft::compress(state, blocks);
}
Expand Down
7 changes: 1 addition & 6 deletions sha1/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#![allow(clippy::unreadable_literal)]
#![allow(clippy::unreadable_literal, dead_code)]

pub const STATE_LEN: usize = 5;

#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))]
pub const BLOCK_LEN: usize = 16;

#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))]
pub const K0: u32 = 0x5A827999u32;
#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))]
pub const K1: u32 = 0x6ED9EBA1u32;
#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))]
pub const K2: u32 = 0x8F1BBCDCu32;
#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))]
pub const K3: u32 = 0xCA62C1D6u32;

pub const H: [u32; STATE_LEN] = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0];

0 comments on commit 1b4a55c

Please sign in to comment.