• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H03-May-2022-359314

benches/H03-May-2022-518431

c/H03-May-2022-31,50230,542

media/H03-May-2022-

src/H03-May-2022-5,6034,337

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D01-Jan-197074 65

.gitignoreH A D01-Jan-197018 32

CONTRIBUTING.mdH A D01-Jan-19701.1 KiB3218

Cargo.tomlH A D01-Jan-19701.6 KiB7462

Cargo.toml.orig-cargoH A D01-Jan-19704.1 KiB9985

LICENSEH A D01-Jan-197018.3 KiB331282

README.mdH A D01-Jan-19707.7 KiB202157

build.rsH A D01-Jan-19708.3 KiB261194

README.md

1# <a href="#"><img src="media/BLAKE3.svg" alt="BLAKE3" height=50></a>
2
3BLAKE3 is a cryptographic hash function that is:
4
5- **Much faster** than MD5, SHA-1, SHA-2, SHA-3, and BLAKE2.
6- **Secure**, unlike MD5 and SHA-1. And secure against length extension,
7  unlike SHA-2.
8- **Highly parallelizable** across any number of threads and SIMD lanes,
9  because it's a Merkle tree on the inside.
10- Capable of **verified streaming** and **incremental updates**, again
11  because it's a Merkle tree.
12- A **PRF**, **MAC**, **KDF**, and **XOF**, as well as a regular hash.
13- **One algorithm with no variants**, which is fast on x86-64 and also
14  on smaller architectures.
15
16The [chart below](https://github.com/BLAKE3-team/BLAKE3-specs/blob/master/benchmarks/bar_chart.py)
17is an example benchmark of 16 KiB inputs on modern server hardware (a Cascade
18Lake-SP 8275CL processor). For more detailed benchmarks, see the
19[BLAKE3 paper](https://github.com/BLAKE3-team/BLAKE3-specs/blob/master/blake3.pdf).
20
21<p align="center">
22<img src="media/speed.svg" alt="performance graph">
23</p>
24
25BLAKE3 is based on an optimized instance of the established hash
26function [BLAKE2](https://blake2.net) and on the [original Bao tree
27mode](https://github.com/oconnor663/bao/blob/master/docs/spec_0.9.1.md).
28The specifications and design rationale are available in the [BLAKE3
29paper](https://github.com/BLAKE3-team/BLAKE3-specs/blob/master/blake3.pdf).
30The default output size is 256 bits. The current version of
31[Bao](https://github.com/oconnor663/bao) implements verified streaming
32with BLAKE3.
33
34This repository is the official implementation of BLAKE3. It includes:
35
36* The [`blake3`](https://crates.io/crates/blake3) Rust crate, which
37  includes optimized implementations for SSE2, SSE4.1, AVX2, AVX-512,
38  and NEON, with automatic runtime CPU feature detection on x86. The
39  `rayon` feature provides multithreading.
40
41* The [`b3sum`](https://crates.io/crates/b3sum) Rust crate, which
42  provides a command line interface. It uses multithreading by default,
43  making it an order of magnitude faster than e.g. `sha256sum` on
44  typical desktop hardware.
45
46* The [C implementation](c), which like the Rust implementation includes
47  SIMD code and runtime CPU feature detection on x86. Unlike the Rust
48  implementation, it's not currently multithreaded. See
49  [`c/README.md`](c/README.md).
50
51* The [reference implementation](reference_impl/reference_impl.rs),
52  which is discussed in Section 5.1 of the [BLAKE3
53  paper](https://github.com/BLAKE3-team/BLAKE3-specs/blob/master/blake3.pdf).
54  This implementation is much smaller and simpler than the optimized
55  ones above. If you want to see how BLAKE3 works, or you're writing a
56  port that doesn't need multithreading or SIMD optimizations, start
57  here.
58
59* A [set of test
60  vectors](https://github.com/BLAKE3-team/BLAKE3/blob/master/test_vectors/test_vectors.json)
61  that covers extended outputs, all three modes, and a variety of input
62  lengths.
63
64* [![Actions Status](https://github.com/BLAKE3-team/BLAKE3/workflows/tests/badge.svg)](https://github.com/BLAKE3-team/BLAKE3/actions)
65
66BLAKE3 was designed by:
67
68* [@oconnor663 ](https://github.com/oconnor663) (Jack O'Connor)
69* [@sneves](https://github.com/sneves) (Samuel Neves)
70* [@veorq](https://github.com/veorq) (Jean-Philippe Aumasson)
71* [@zookozcash](https://github.com/zookozcash) (Zooko)
72
73The development of BLAKE3 was sponsored by
74[Teserakt](https://teserakt.io) and [Electric Coin Company](https://electriccoin.co).
75
76*NOTE: BLAKE3 is not a password hashing algorithm, because it's
77designed to be fast, whereas password hashing should not be fast. If you
78hash passwords to store the hashes or if you derive keys from passwords,
79we recommend [Argon2](https://github.com/P-H-C/phc-winner-argon2).*
80
81## Usage
82
83### The `b3sum` utility
84
85The `b3sum` command line utility prints the BLAKE3 hashes of files or of
86standard input. Prebuilt binaries are available for Linux, Windows, and
87macOS (requiring the [unidentified developer
88workaround](https://support.apple.com/guide/mac-help/open-a-mac-app-from-an-unidentified-developer-mh40616/mac))
89on the [releases page](https://github.com/BLAKE3-team/BLAKE3/releases).
90If you've [installed Rust and
91Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html),
92you can also build `b3sum` yourself with:
93
94```bash
95cargo install b3sum
96```
97
98If `rustup` didn't configure your `PATH` for you, you might need to go
99looking for the installed binary in e.g. `~/.cargo/bin`. You can test
100out how fast BLAKE3 is on your machine by creating a big file and
101hashing it, for example:
102
103```bash
104# Create a 1 GB file.
105head -c 1000000000 /dev/zero > /tmp/bigfile
106# Hash it with SHA-256.
107time openssl sha256 /tmp/bigfile
108# Hash it with BLAKE3.
109time b3sum /tmp/bigfile
110```
111
112### The `blake3` crate [![docs.rs](https://docs.rs/blake3/badge.svg)](https://docs.rs/blake3)
113
114To use BLAKE3 from Rust code, add a dependency on the `blake3` crate to
115your `Cargo.toml`. Here's an example of hashing some input bytes:
116
117```rust
118// Hash an input all at once.
119let hash1 = blake3::hash(b"foobarbaz");
120
121// Hash an input incrementally.
122let mut hasher = blake3::Hasher::new();
123hasher.update(b"foo");
124hasher.update(b"bar");
125hasher.update(b"baz");
126let hash2 = hasher.finalize();
127assert_eq!(hash1, hash2);
128
129// Extended output. OutputReader also implements Read and Seek.
130let mut output = [0; 1000];
131let mut output_reader = hasher.finalize_xof();
132output_reader.fill(&mut output);
133assert_eq!(&output[..32], hash1.as_bytes());
134
135// Print a hash as hex.
136println!("{}", hash1);
137```
138
139Besides `hash`, BLAKE3 provides two other modes, `keyed_hash` and
140`derive_key`. The `keyed_hash` mode takes a 256-bit key:
141
142```rust
143// MAC an input all at once.
144let example_key = [42u8; 32];
145let mac1 = blake3::keyed_hash(&example_key, b"example input");
146
147// MAC incrementally.
148let mut hasher = blake3::Hasher::new_keyed(&example_key);
149hasher.update(b"example input");
150let mac2 = hasher.finalize();
151assert_eq!(mac1, mac2);
152```
153
154The `derive_key` mode takes a context string and some key material (not a
155password). The context string should be hardcoded, globally unique, and
156application-specific. A good default format for the context string is
157`"[application] [commit timestamp] [purpose]"`:
158
159```rust
160// Derive a couple of subkeys for different purposes.
161const EMAIL_CONTEXT: &str = "BLAKE3 example 2020-01-07 17:10:44 email key";
162const API_CONTEXT: &str = "BLAKE3 example 2020-01-07 17:11:21 API key";
163let input_key_material = b"usually at least 32 random bytes, not a password";
164let email_key = blake3::derive_key(EMAIL_CONTEXT, input_key_material);
165let api_key = blake3::derive_key(API_CONTEXT, input_key_material);
166assert!(email_key != api_key);
167```
168
169### The C implementation
170
171See [`c/README.md`](c/README.md).
172
173### Other implementations
174
175We post links to third-party bindings and implementations on the
176[@BLAKE3team Twitter account](https://twitter.com/BLAKE3team) whenever
177we hear about them. Some highlights include [an optimized Go
178implementation](https://github.com/zeebo/blake3), [Wasm bindings for
179Node.js and browsers](https://github.com/connor4312/blake3), [binary
180wheels for Python](https://github.com/oconnor663/blake3-py), [.NET
181bindings](https://github.com/xoofx/Blake3.NET), and [JNI
182bindings](https://github.com/sken77/BLAKE3jni).
183
184## Contributing
185
186Please see [CONTRIBUTING.md](CONTRIBUTING.md).
187
188## Intellectual property
189
190The Rust code is copyright Jack O'Connor, 2019-2020. The C code is
191copyright Samuel Neves and Jack O'Connor, 2019-2020. The assembly code
192is copyright Samuel Neves, 2019-2020.
193
194This work is released into the public domain with CC0 1.0.
195Alternatively, it is licensed under the Apache License 2.0.
196
197## Miscellany
198
199- [@veorq](https://github.com/veorq) and
200  [@oconnor663](https://github.com/oconnor663) did [a podcast
201  interview](https://www.cryptography.fm/3) about designing BLAKE3.
202