Skip to content
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

Add x86 intrinsics support for sha2-512 #312

Merged
merged 6 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
50 changes: 50 additions & 0 deletions sha2/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,56 @@ pub const K64X2: [[u64; 2]; 40] = [
[K64[79], K64[78]],
];

macro_rules! dup_array {
([$([$a:expr, $b:expr]),*,]) => {[
$($b, $a, $b, $a),*,
]}
}

/// Constants necessary for SHA-512 family of digests.
pub const K64X4: [u64; 160] = dup_array!([
[K64[1], K64[0]],
newpavlov marked this conversation as resolved.
Show resolved Hide resolved
[K64[3], K64[2]],
[K64[5], K64[4]],
[K64[7], K64[6]],
[K64[9], K64[8]],
[K64[11], K64[10]],
[K64[13], K64[12]],
[K64[15], K64[14]],
[K64[17], K64[16]],
[K64[19], K64[18]],
[K64[21], K64[20]],
[K64[23], K64[22]],
[K64[25], K64[24]],
[K64[27], K64[26]],
[K64[29], K64[28]],
[K64[31], K64[30]],
[K64[33], K64[32]],
[K64[35], K64[34]],
[K64[37], K64[36]],
[K64[39], K64[38]],
[K64[41], K64[40]],
[K64[43], K64[42]],
[K64[45], K64[44]],
[K64[47], K64[46]],
[K64[49], K64[48]],
[K64[51], K64[50]],
[K64[53], K64[52]],
[K64[55], K64[54]],
[K64[57], K64[56]],
[K64[59], K64[58]],
[K64[61], K64[60]],
[K64[63], K64[62]],
[K64[65], K64[64]],
[K64[67], K64[66]],
[K64[69], K64[68]],
[K64[71], K64[70]],
[K64[73], K64[72]],
[K64[75], K64[74]],
[K64[77], K64[76]],
[K64[79], K64[78]],
]);

pub static H224: [u32; STATE_LEN] = [
0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4,
];
Expand Down
13 changes: 10 additions & 3 deletions sha2/src/sha512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,17 @@ cfg_if::cfg_if! {
if #[cfg(feature = "force-soft")] {
mod soft;
use soft::compress;
} else if #[cfg(all(feature = "asm", any(target_arch = "x86", target_arch = "x86_64")))] {
fn compress(state: &mut [u64; 8], blocks: &[[u8; 128]]) {
sha2_asm::compress512(state, blocks);
} else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
#[cfg(not(feature = "asm"))]
mod soft;
#[cfg(feature = "asm")]
mod soft {
pub(crate) fn compress(state: &mut [u64; 8], blocks: &[[u8; 128]]) {
sha2_asm::compress512(state, blocks);
}
}
mod x86;
use x86::compress;
} else {
mod soft;
use soft::compress;
Expand Down
Loading