Skip to content

Commit

Permalink
sha2: Fix bug in the AVX2 backend (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Sep 9, 2021
1 parent 726e3c3 commit 93d895d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sha2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.9.7 (2021-09-08)
## 0.9.7 (2021-09-08) [YANKED]
### Added
- x86 intrinsics support for SHA-512 ([#312])

Expand Down
4 changes: 2 additions & 2 deletions sha2/src/sha512/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ unsafe fn load_data_avx2(

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

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

Expand Down
16 changes: 16 additions & 0 deletions sha2/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ fn sha256_1million_a() {
one_million_a::<sha2::Sha256>(output);
}

#[test]
#[rustfmt::skip]
fn sha512_avx2_bug() {
use sha2::Digest;
use hex_literal::hex;

let mut msg = [0u8; 256];
msg[0] = 42;
let expected = hex!("
2a3e943072f30afa45f2bf57ccd386f29b76dbcdb3a861224ca0b77bc3f55c7a
d3880a49c0c9c166eedf7f209c41b380896886155acb8f6c7c07044343a3e692
");
let res = sha2::Sha512::digest(&msg);
assert_eq!(res[..], expected[..]);
}

#[test]
fn sha512_1million_a() {
let output = include_bytes!("data/sha512_one_million_a.bin");
Expand Down

0 comments on commit 93d895d

Please sign in to comment.