blake2b_simd
An implementation of the BLAKE2b hash with:
- 100% stable Rust.
- A fast AVX2 implementation ported from libsodium.
- A portable, safe implementation for other platforms.
- Dynamic CPU feature detection. Binaries for x86 include the AVX2 implementation by default and call it if the processor supports it at runtime.
no_std
support.std
is on by default, for feature detection andstd::io::Write
.- All the features from the the BLAKE2 spec, like adjustable length, keying, and associated data for tree hashing.
Performance
The AVX2 implementation in this crate is ported from the C implementation in libsodium. That implementation was originally written by Samuel Neves and integrated into libsodium by Frank Denis. All credit for performance goes to those authors.
The benchmark_gig
binary in this crate allocates a gigabyte (10⁹) array and repeatedly hashes
it to measure throughput. A similar C program, benches/bench_libsodium.c
, does the same thing
using libsodium's implementation of BLAKE2b. Here are the results from my laptop:
- Intel Core i5-8250U, Arch Linux, kernel version 4.17.13
- libsodium version 1.0.16, gcc 8.2.0,
gcc -O3 -lsodium benches/bench_libsodium.c
(via the helper scriptbenches/bench_libsodium.sh
) - rustc 1.30.0-nightly (73c78734b 2018-08-05),
cargo +nightly run --release --bin benchmark_gig
╭────────────┬────────────╮
│ portable │ AVX2 │
╭──────────────┼────────────┼────────────┤
│ blake2b_simd │ 0.771 GB/s │ 1.005 GB/s │
│ libsodium │ 0.743 GB/s │ 0.939 GB/s │
╰──────────────┴────────────┴────────────╯
Example
let mut params = default;
params.hash_length;
params.key;
params.personal;
let mut state = with_params;
state.update;
state.update;
state.update;
let hash = state.finalize;
assert_eq!;