Repository navigation
Add HKDF key derivation function (RFC 5869) - #46
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
|
dipu-bd
force-pushed
the
ccr-3e9bf447-zsxg7p-hkdf
branch
2 times, most recently
from
December 3, 2026 15:32
c23a331 to
e1a258d
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dipu-bd
force-pushed
the
ccr-3e9bf447-zsxg7p-hkdf
branch
from
December 3, 2026 15:38
e1a258d to
7a983f9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds HKDF (RFC 5869), the extract-and-expand key derivation function used for Diffie-Hellman/KEM shared secrets, TLS 1.3 key schedules and AEAD key derivation. It follows the existing PBKDF2 API shape.
HKDF(lib/src/algorithms/hkdf.dart) extendsKeyDerivatorBase. It exposesextract()andexpand()as well asconvert(), so it also covers expand-only uses where the input is already a pseudorandom key.HashLenzero bytes,infodefaults to empty, andkeyLengthdefaults toHashLen.keyLengthmust be between 1 and255 × HashLen, as the RFC requires. Anything else throwsArgumentError.lib/src/hkdf.dart):.hkdf(...)extensions onMACHashandBlockHashBasehkdf()defaulting to HMAC-SHA256package:hashlib.Test vectors (all from verified sources, nothing invented)
test/fixures/hkdf_vectors.dartis generated from these files, with each source URL and its SHA-256 recorded in the header:vectors/cryptography_vectors/KDF/rfc-5869-HKDF-SHA{1,256}.txt). The tests check the intermediate PRK, the final OKM, andexpand()from the published PRK. (rfc-editor.org and ietf.org are blocked from this environment's network, so I used pyca's verbatim copy. Its first case matches Wycheproof's "RFC 5869" case exactly.)hkdf_sha{1,256,384,512}_test.json. They include empty salts, salts longer than the block size, salts that collide, maximal output sizes, andinvalidcases with oversized outputs, which must throw.The vector tests are not tagged
vm-only, so they also run on node and dart2wasm. There they exercise HKDF on top of the 32-bit SHA-384/512 code.There is also a differential test (
test/compare/compare_hkdf_test.dart, vm-only) against pointycastle'sHKDFKeyDerivator. It covers SHA-1/256/384/512 × 100 random combinations of IKM, salt, info and output lengths up to 600 bytes. All matched.Verification
dart format --output=none --set-exit-if-changed .makes no changesdart analyze --fatal-infosreports no issuesdart test -p vm: all tests pass (365 new)dart test -p node: all tests passdart test -P wasm: all tests passbash scripts/coverage.shreports 100% oflib/covered (5998/5998 lines)Benchmark (
benchmark/hkdf.dart, HKDF-SHA256,dart runin a cloud container, not the reference machine):It is a standalone benchmark, not wired into the aggregator, whose KDF section is built around password-hash security levels.
BENCHMARK.mdis untouched.Notes
HKDF(RFC 5869) withextract/expand,#.hkdf()extensions and a top-levelhkdf()".KeyDerivatorBase.verifycompares with an early-exit loop, so it isn't constant-time. HKDF inherits it, as PBKDF2 already does.Generated by Claude Code