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

Conversation

Rexagon
Copy link
Contributor

@Rexagon Rexagon commented Sep 6, 2021

This version is a port of this implementation (src/sha512_compress_x86_64_avx2.c) https://github.com/aws-samples/sha2-with-c-intrinsic which is based on this document https://eprint.iacr.org/2012/067.pdf. It uses avx impl for single odd block and then avx2 for the rest.

Benchmarks:

CPU: Ryzen 9 5950X

cargo +nightly bench -p sha2 --features force-soft

     Running unittests (target/release/deps/sha512-0451eb22388b5224)

running 4 tests
test bench1_10    ... bench:          22 ns/iter (+/- 0) = 454 MB/s
test bench2_100   ... bench:         184 ns/iter (+/- 8) = 543 MB/s
test bench3_1000  ... bench:       1,869 ns/iter (+/- 5) = 535 MB/s
test bench4_10000 ... bench:      18,226 ns/iter (+/- 54) = 548 MB/s

test result: ok. 0 passed; 0 failed; 0 ignored; 4 measured; 0 filtered out; finished in 5.02s

cargo +nightly bench -p sha2

     Running unittests (target/release/deps/sha512-fc38283933ec7290)

running 4 tests
test bench1_10    ... bench:          18 ns/iter (+/- 0) = 555 MB/s
test bench2_100   ... bench:         148 ns/iter (+/- 1) = 675 MB/s
test bench3_1000  ... bench:       1,317 ns/iter (+/- 11) = 759 MB/s
test bench4_10000 ... bench:      12,836 ns/iter (+/- 156) = 779 MB/s

test result: ok. 0 passed; 0 failed; 0 ignored; 4 measured; 0 filtered out; finished in 3.06s

@Rexagon
Copy link
Contributor Author

Rexagon commented Sep 6, 2021

Hopefully related to #311

Copy link
Member

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@newpavlov WDYT?

Copy link
Member

@newpavlov newpavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked deep into implementation itself and would like to try some minor tweaks, but I think we can merge it after the target_feature(enable = "..") nitpick will be fixed.

sha2/src/sha512/x86.rs Outdated Show resolved Hide resolved
sha2/src/consts.rs Outdated Show resolved Hide resolved
@newpavlov newpavlov merged commit efda00d into RustCrypto:master Sep 8, 2021
@newpavlov
Copy link
Member

Thank you! I will soon release it as v0.9.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants