| 1 |
# blake2b_simd [](https://github.com/oconnor663/blake2_simd) [](https://crates.io/crates/blake2b_simd) [](https://github.com/oconnor663/blake2_simd/actions) |
| 2 |
|
| 3 |
An implementation of the BLAKE2b and BLAKE2bp hash functions. See also |
| 4 |
[`blake2s_simd`](../blake2s). |
| 5 |
|
| 6 |
This crate includes: |
| 7 |
|
| 8 |
- 100% stable Rust. |
| 9 |
- SIMD implementations based on Samuel Neves' [`blake2-avx2`](https://github.com/sneves/blake2-avx2). |
| 10 |
These are very fast. For benchmarks, see [the Performance section of the |
| 11 |
README](https://github.com/oconnor663/blake2_simd#performance). |
| 12 |
- Portable, safe implementations for other platforms. |
| 13 |
- Dynamic CPU feature detection. Binaries include multiple implementations by default and |
| 14 |
choose the fastest one the processor supports at runtime. |
| 15 |
- All the features from the [the BLAKE2 spec](https://blake2.net/blake2.pdf), like adjustable |
| 16 |
length, keying, and associated data for tree hashing. |
| 17 |
- `no_std` support. The `std` Cargo feature is on by default, for CPU feature detection and |
| 18 |
for implementing `std::io::Write`. |
| 19 |
- Support for computing multiple BLAKE2b hashes in parallel, matching the efficiency of |
| 20 |
BLAKE2bp. See the [`many`](many/index.html) module. |
| 21 |
|
| 22 |
# Example |
| 23 |
|
| 24 |
``` |
| 25 |
use blake2b_simd::{blake2b, Params}; |
| 26 |
|
| 27 |
let expected = "ca002330e69d3e6b84a46a56a6533fd79d51d97a3bb7cad6c2ff43b354185d6d\ |
| 28 |
c1e723fb3db4ae0737e120378424c714bb982d9dc5bbd7a0ab318240ddd18f8d"; |
| 29 |
let hash = blake2b(b"foo"); |
| 30 |
assert_eq!(expected, &hash.to_hex()); |
| 31 |
|
| 32 |
let hash = Params::new() |
| 33 |
.hash_length(16) |
| 34 |
.key(b"The Magic Words are Squeamish Ossifrage") |
| 35 |
.personal(b"L. P. Waterhouse") |
| 36 |
.to_state() |
| 37 |
.update(b"foo") |
| 38 |
.update(b"bar") |
| 39 |
.update(b"baz") |
| 40 |
.finalize(); |
| 41 |
assert_eq!("ee8ff4e9be887297cf79348dc35dab56", &hash.to_hex()); |
| 42 |
``` |