Skip to content

sha1: pass block slices to sha1_asm + remove cfg toggle for constants #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 2 additions & 4 deletions sha1/src/compress/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
/// > Enable SHA1 and SHA256 support.
cpufeatures::new!(sha2_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);
}
sha1_asm::compress(state, blocks);
} else {
super::soft::compress(state, blocks);
}
Expand Down
8 changes: 2 additions & 6 deletions sha1/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#![allow(clippy::unreadable_literal)]

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"))]
/// Magic constants necessary for SHA-1.
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;

/// Magic reset constants necessary for SHA-1.
pub const H: [u32; STATE_LEN] = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0];