Skip to content

fix(hkdf): accept a zero-length input keying material - #1080

Merged
boorad merged 2 commits into
margelo:mainfrom
matthiasgeihs:fix/hkdf-empty-ikm
Oct 26, 2026
Merged

boorad merged 2 commits into
margelo:mainfrom
matthiasgeihs:fix/hkdf-empty-ikm

Conversation

@matthiasgeihs

Copy link
Copy Markdown
Contributor

Summary

  • HybridHkdf::deriveKeySync passed a null pointer for a zero-length key. OpenSSL 3.6.2 (the version this package vendors) rejects that with passed a null parameter, so EVP_KDF_derive fails and callers see HKDF derivation failed.
  • RFC 5869 allows a zero-length IKM. A non-null pointer with length 0 derives the same bytes as Node.js crypto.hkdfSync. Empty salt is unchanged: it is still omitted, and OpenSSL uses HashLen zero bytes.
  • This is the WebCrypto path subtle.importKey({ name: 'HKDF' }) hits for an empty key, including Noise Split (HKDF(chaining key, empty)).

Test plan

  • Example suite: hkdfSync: zero-length IKM and empty salt matches eb70f01d…
  • Example suite: hkdfSync: zero-length IKM with salt matches b5a5789a…
  • Example suite: WebCrypto HKDF deriveBits: zero-length IKM imports an empty raw key and derives the salted vector
  • Existing RFC 5869 cases still pass (non-empty IKM is unchanged)

The new vectors were checked against Node.js crypto.hkdfSync on OpenSSL 3.6.2. The null-pointer call fails there; the non-null empty buffer succeeds. The example tests need a native rebuild.

Made with Cursor

OpenSSL rejects a null key pointer even when the length is 0, so empty
IKM derivation failed. Pass a non-null empty buffer instead.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Oct 23, 2026

Copy link
Copy Markdown

@matthiasgeihs is attempting to deploy a commit to the Margelo Team on Vercel.

A member of the Team first needs to authorize it.

@boorad
boorad merged commit 707226d into margelo:main Oct 26, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants