| 1 | blake3 |
| 2 | ------ |
| 3 | |
| 4 | [](https://godoc.org/lukechampine.com/blake3) |
| 5 | [](https://goreportcard.com/report/lukechampine.com/blake3) |
| 6 | |
| 7 | ``` |
| 8 | go get lukechampine.com/blake3 |
| 9 | ``` |
| 10 | |
| 11 | `blake3` implements the [BLAKE3 cryptographic hash function](https://github.com/BLAKE3-team/BLAKE3). |
| 12 | This implementation aims to be performant without sacrificing (too much) |
| 13 | readability, in the hopes of eventually landing in `x/crypto`. |
| 14 | |
| 15 | In addition to the pure-Go implementation, this package also contains AVX-512 |
| 16 | and AVX2 routines (generated by [`avo`](https://github.com/mmcloughlin/avo)) |
| 17 | that greatly increase performance for large inputs and outputs. |
| 18 | |
| 19 | ## Benchmarks |
| 20 | |
| 21 | Tested on a 2020 MacBook Air (i5-7600K @ 3.80GHz). Benchmarks will improve as |
| 22 | soon as I get access to a beefier AVX-512 machine. :wink: |
| 23 | |
| 24 | ### AVX-512 |
| 25 | |
| 26 | ``` |
| 27 | BenchmarkSum256/64 120 ns/op 533.00 MB/s |
| 28 | BenchmarkSum256/1024 2229 ns/op 459.36 MB/s |
| 29 | BenchmarkSum256/65536 16245 ns/op 4034.11 MB/s |
| 30 | BenchmarkWrite 245 ns/op 4177.38 MB/s |
| 31 | BenchmarkXOF 246 ns/op 4159.30 MB/s |
| 32 | ``` |
| 33 | |
| 34 | ### AVX2 |
| 35 | |
| 36 | ``` |
| 37 | BenchmarkSum256/64 120 ns/op 533.00 MB/s |
| 38 | BenchmarkSum256/1024 2229 ns/op 459.36 MB/s |
| 39 | BenchmarkSum256/65536 31137 ns/op 2104.76 MB/s |
| 40 | BenchmarkWrite 487 ns/op 2103.12 MB/s |
| 41 | BenchmarkXOF 329 ns/op 3111.27 MB/s |
| 42 | ``` |
| 43 | |
| 44 | ### Pure Go |
| 45 | |
| 46 | ``` |
| 47 | BenchmarkSum256/64 120 ns/op 533.00 MB/s |
| 48 | BenchmarkSum256/1024 2229 ns/op 459.36 MB/s |
| 49 | BenchmarkSum256/65536 133505 ns/op 490.89 MB/s |
| 50 | BenchmarkWrite 2022 ns/op 506.36 MB/s |
| 51 | BenchmarkXOF 1914 ns/op 534.98 MB/s |
| 52 | ``` |
| 53 | |
| 54 | ## Shortcomings |
| 55 | |
| 56 | There is no assembly routine for single-block compressions. This is most |
| 57 | noticeable for ~1KB inputs. |
| 58 | |
| 59 | Each assembly routine inlines all 7 rounds, causing thousands of lines of |
| 60 | duplicated code. Ideally the routines could be merged such that only a single |
| 61 | routine is generated for AVX-512 and AVX2, without sacrificing too much |
| 62 | performance. |