Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the Diffie–Hellman public-value validation fix.
No open issues 🎉
What changed in this PR
Fixes wolfCrypt’s Diffie–Hellman public-value validation so leading-zero padding on a prime cannot let invalid public values bypass range checks.
Changes:
- Strip leading zeros from the prime before comparing lengths in
wc_DhCheckPubValue(). - Run existing valid and invalid test vectors with zero, one, and two leading-zero bytes on the prime.
- Document rejected values and leading-zero handling.
| File | Description |
|---|---|
wolfcrypt/test/test.c |
Extends public-value regression tests to padded primes. |
wolfcrypt/src/dh.c |
Normalizes the prime before validation and documents padding behavior. |
doc/dox_comments/header_files/dh.h |
Clarifies validation bounds and ignored leading zeros. |
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12173
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/dh.h
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Max
|
Description
wc_DhCheckPubValue()strips leading zeros frompubbut not fromprime. When the prime carries DER-style padding (for example a 2048-bit modulus passed as 257 bytes), a 256-byteytakes thepubSz < primeSzpath. The function then returns 0 without comparing magnitudes, sop-1,pandy > pare accepted.In the TLS path,
wc_DhAgree_Sync()still rejects these values through its numericwc_DhCheckPubKey_ex()check. Direct callers of the public API have no such backstop. Neither do builds using aDhAgreeCbPK callback.Fixes zd22857
Testing
dh_test_check_pubvalue()now runs every existing vector against the prime with zero, one and two leading zero bytes.Checklist