Skip to content

Commit

Permalink
use blake2b_simd and blake2s_simd internally
Browse files Browse the repository at this point in the history
Replace the internal implementation of BLAKE2b and BLAKE2s with calls to
the blake2b_simd and blake2s_simd crates. Those crates contain optimized
implementations for SSE4.1 and AVX2, and they use runtime CPU feature
detection to select the best implementation.

Running the long-input benchmarks on an Intel i9-9880H with AVX2
support, this change is a performance improvement of about 1.5x for
BLAKE2b and 1.35x for BLAKE2s.

This change deletes the undocumented `with_parameter_block` method, as
the raw parameter block is not exposed by blake2b_simd or blak2s_simd.
Callers who need BLAKE2 tree mode parameters can use the upstream crates
directly. They provide a complete set of parameter methods.

This change also deletes the `finalize_last_node` method. This method
was arguably attached to the wrong types, `VarBlake2b` and `VarBlake2s`,
where it would panic with a non-default output length. It's not very
useful without the other tree parameters, so rather than moving it to
the fixed-length `Blake2b` and `Blake2s` types where it belongs, we just
delete it. This also simplifies the addition of BLAKE2bp and BLAKE2sp
support in the following commit, as those algorithms use the last node
flag internally and cannot expose it.
  • Loading branch information
oconnor663-zoom committed Jun 15, 2020
1 parent feea49e commit 5b06106
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 979 deletions.
44 changes: 43 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion blake2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ keywords = ["crypto", "blake2", "hash", "digest"]
categories = ["cryptography", "no-std"]

[dependencies]
blake2b_simd = { version = "0.5.10", default-features = false }
blake2s_simd = { version = "0.5.10", default-features = false }
digest = "0.9"
crypto-mac = "0.8"
opaque-debug = "0.3"
Expand All @@ -23,7 +25,7 @@ hex-literal = "0.2"

[features]
default = ["std"]
std = ["digest/std", "crypto-mac/std"]
std = ["digest/std", "crypto-mac/std", "blake2b_simd/std", "blake2s_simd/std"]
simd = []
simd_opt = ["simd"]
simd_asm = ["simd_opt"]
44 changes: 0 additions & 44 deletions blake2/src/as_bytes.rs

This file was deleted.

Loading

0 comments on commit 5b06106

Please sign in to comment.