Skip to content

Commit 93d895d

Browse files
authored
sha2: Fix bug in the AVX2 backend (#314)
1 parent 726e3c3 commit 93d895d

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

sha2/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## 0.9.7 (2021-09-08)
8+
## 0.9.7 (2021-09-08) [YANKED]
99
### Added
1010
- x86 intrinsics support for SHA-512 ([#312])
1111

sha2/src/sha512/x86.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ unsafe fn load_data_avx2(
106106

107107
macro_rules! unrolled_iterations {
108108
($($i:literal),*) => {$(
109-
x[$i] = _mm256_insertf128_si256(x[$i], _mm_loadu_si128(data.add($i) as *const _), 1);
110-
x[$i] = _mm256_insertf128_si256(x[$i], _mm_loadu_si128(data.add($i + 1) as *const _), 0);
109+
x[$i] = _mm256_insertf128_si256(x[$i], _mm_loadu_si128(data.add(8 + $i) as *const _), 1);
110+
x[$i] = _mm256_insertf128_si256(x[$i], _mm_loadu_si128(data.add($i) as *const _), 0);
111111

112112
x[$i] = _mm256_shuffle_epi8(x[$i], MASK);
113113

sha2/tests/lib.rs

+16
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ fn sha256_1million_a() {
2424
one_million_a::<sha2::Sha256>(output);
2525
}
2626

27+
#[test]
28+
#[rustfmt::skip]
29+
fn sha512_avx2_bug() {
30+
use sha2::Digest;
31+
use hex_literal::hex;
32+
33+
let mut msg = [0u8; 256];
34+
msg[0] = 42;
35+
let expected = hex!("
36+
2a3e943072f30afa45f2bf57ccd386f29b76dbcdb3a861224ca0b77bc3f55c7a
37+
d3880a49c0c9c166eedf7f209c41b380896886155acb8f6c7c07044343a3e692
38+
");
39+
let res = sha2::Sha512::digest(&msg);
40+
assert_eq!(res[..], expected[..]);
41+
}
42+
2743
#[test]
2844
fn sha512_1million_a() {
2945
let output = include_bytes!("data/sha512_one_million_a.bin");

0 commit comments

Comments
 (0)