Skip to content

Commit 7943c6f

Browse files
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 7943c6f

File tree

10 files changed

+7662
-4
lines changed

10 files changed

+7662
-4
lines changed

Cargo.lock

Lines changed: 114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blake2/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@ digest = { version = "0.11.0-rc.0", features = ["mac"] }
1818
[dev-dependencies]
1919
digest = { version = "0.11.0-rc.0", features = ["dev"] }
2020
hex-literal = "1"
21+
hex = "0.4"
2122
base16ct = { version = "0.2", features = ["alloc"] }
23+
b2rs = { git = "https://github.com/veorq/b2rs.git", branch = "master" }
24+
rand = "0.8"
25+
paste = "1.0"
26+
serde = { version = "1.0", features = ["derive"] }
27+
serde_json = "1.0"
2228

2329
[features]
2430
default = ["alloc"]
2531
alloc = ["digest/alloc"]
2632
zeroize = ["digest/zeroize"]
2733
reset = [] # Enable reset functionality
34+
blake2x = [] # Enable Blake2X XOF functionality
2835
#simd = []
2936
#simd_opt = ["simd"]
3037
#simd_asm = ["simd_opt"]

0 commit comments

Comments
 (0)