Set PKCS#8 version correctly in SetAsymKeyDer() when publicKey is bundled#10427
Merged
dgarske merged 1 commit intowolfSSL:masterfrom May 7, 2026
Merged
Set PKCS#8 version correctly in SetAsymKeyDer() when publicKey is bundled#10427dgarske merged 1 commit intowolfSSL:masterfrom
dgarske merged 1 commit intowolfSSL:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes RFC 5958 (PKCS#8 OneAsymmetricKey) encoding by correctly setting the version field to 1 when the optional publicKey element is included, while keeping 0 for private-only encodings, and it updates decoding logic/tests to be compatible with both versions on input.
Changes:
- Update
SetAsymKeyDer()to emitversion=1whenpubKeyis present andversion=0otherwise. - Relax
DecodeAsymKey_Assign()to accept bothversion=0andversion=1for compatibility. - Add/extend API tests across ASN, Ed25519/Ed448, Curve25519/Curve448, and ML-DSA (Dilithium) to validate version handling and round-trips.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
wolfcrypt/src/asn.c |
Correct PKCS#8 OneAsymmetricKey version emission based on bundled publicKey; accept both v0/v1 on decode. |
tests/api/test_mldsa.h |
Register new ML-DSA OneAsymmetricKey version regression test. |
tests/api/test_mldsa.c |
Add ML-DSA OneAsymmetricKey version checks and byte-exact round-trip validation. |
tests/api/test_ed448.h |
Register Ed448 OneAsymmetricKey version regression test. |
tests/api/test_ed448.c |
Add Ed448 bundled vs private-only version assertions with round-trip. |
tests/api/test_ed25519.h |
Register Ed25519 OneAsymmetricKey version regression test. |
tests/api/test_ed25519.c |
Add Ed25519 bundled vs private-only version assertions with round-trip. |
tests/api/test_curve448.h |
Register Curve448 private-only OneAsymmetricKey version regression test. |
tests/api/test_curve448.c |
Add Curve448 private-only version assertion and round-trip. |
tests/api/test_curve25519.h |
Register Curve25519 OneAsymmetricKey version regression test. |
tests/api/test_curve25519.c |
Add Curve25519 bundled vs private-only version assertions with round-trip. |
tests/api/test_asn.h |
Register new ASN DecodeAsymKey leniency/negative tests. |
tests/api/test_asn.c |
Add DecodeAsymKey lenient version acceptance and negative parsing tests. |
tests/api/api.h |
Add small PKCS#8 test helpers to read/patch the OneAsymmetricKey version byte. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7f114e6 to
7cc84d3
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #10427
Scan targets checked: wolfcrypt-bugs, wolfcrypt-src
No new issues found in the changed files. ✅
dgarske
approved these changes
May 7, 2026
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.
Description
This PR fixes a bug in wolfSSL's PKCS#8 / RFC 5958 OneAsymmetricKey output. When a private-key DER bundles the optional publicKey field (Ed25519, Ed448, Curve25519, ML-DSA, Falcon), it was tagged as v1 (
version=0) instead of v2 (version=1). The malformed envelope is rejected by JDK 24 SunJCE and is non-conformant with other implementations as well.SetAsymKeyDer()to writeversion=1whenpubKey != NULL,version=0otherwise.DecodeAsymKey_Assign()to accept bothversion=0andversion=1on input, for backwards compatibility with pre-fix wolfSSL and liboqs DER.Testing
test_SetAsymKeyDer()conditions 6-8 (bundled publicKey) to expectversion=1test_DecodeAsymKey_lenient_versions()covering all four{v=0,v=1} × {pub absent,present}variantstest_DecodeAsymKey_negative()for truncated, over-claimed length (short and long form), and non-SEQUENCE inputstest_wc_dilithium_oneasymkey_version()for ML-DSA-44/65/87 (bundled v=1, priv-only v=0, byte-exact round-trip).tests/api/test_ed25519.c,test_ed448.c,test_curve25519.c, andtest_curve448.cwith per-algorithm*_oneasymkey_versionregression tests with the same bundled/private-only assertions.Checklist