Commit 2336212
committed
feat: Implement BLAKE2X XOF
This commit introduces an implementation of Blake2X, the extensible-output
function (XOF) variant of the BLAKE2 hash function. Blake2X is specified
in the official BLAKE2 paper and is designed to produce hash outputs of
arbitrary length.
It is useful for applications requiring digests longer than the standard
BLAKE2 output sizes, such as in certain digital signature schemes (e.g.,
EdDSA with large curves) or as a Key Derivation Function (KDF).
The implementation provides `Blake2xb` (64-bit) and `Blake2xs` (32-bit)
variants, along with their corresponding `XofReader`s. Both are accessible
under a new `blake2x` feature flag.
The core logic is consolidated within a `blake2x_impl!` macro to generate
the necessary structures and trait implementations for both variants,
minimizing code duplication. The implementation correctly handles the
Blake2X tree-hashing mode:
- The initial root hash is computed using a standard BLAKE2 core with the
XOF output length encoded in the parameter block.
- Subsequent output blocks are generated by creating and hashing expansion
nodes using the root hash as input, as per the specification.
Keyed hashing is supported through `new_with_key` constructors for both
`Blake2xb` and `Blake2xs`.
A comprehensive test suite has been added, including:
- Test vectors) for both keyed and unkeyed hashing, sourced
from new JSON test vector files.
- Comparison tests against the `b2rs` reference implementation to ensure
correctness.
- Functional tests for progressive output reads and constructor
parameterization.1 parent bf1b257 commit 2336212
File tree
10 files changed
+7677
-4
lines changed- blake2
- src
- simd
- tests
- data
- blake2xb
- blake2xs
10 files changed
+7677
-4
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| 22 | + | |
21 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
25 | 32 | | |
26 | 33 | | |
27 | 34 | | |
| 35 | + | |
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
| |||
0 commit comments