Repository navigation
Add Mbed TLS pk key writing, DER and PEM - #84
Merged
Merged
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Security-sensitive EC public-point derivation, RNG/blinding requirements, and DER encoding contracts need crypto-maintainer review and validation against the supported wolfCrypt revision, which could not be completed with the available implementation access and backend environment.
No open issues 🎉
What changed in this PR
Adds key writing to wolfPSA’s Mbed TLS compatibility layer, complementing existing key parsing with DER and PEM export.
Changes:
- Adds RSA and EC private-key export and RSA, EC, X25519, and X448 public-key export.
- Exposes feature-gated writing APIs, buffer-sizing constants, and the Mbed TLS 3 public-key writer.
- Adds round-trip, buffer-boundary, certificate-key, and allocation-failure tests, plus compatibility documentation.
| File | Description |
|---|---|
wolfpsa/tf-psa-crypto/build_info.h |
Clarifies the source of the key-writing feature macro in a comment. |
wolfpsa/mbedtls/pk.h |
Declares writing APIs and buffer-sizing constants. |
tools/psa_want_probe.c |
Detects backend support for key writing. |
test/mbedtls_compat/pk_test.c |
Adds export, buffer-size, certificate-key, and error tests. |
test/mbedtls_compat/mbedtls3_test.c |
Tests generated-key export, allocation failures, and raw public-key writing. |
test/mbedtls_compat/Makefile |
Supplies wolfSSL test-key paths to pk_test. |
src/psa_tf_psa.c |
Implements DER and PEM key writers using wolfCrypt. |
src/psa_tf_psa_internal.h |
Declares shared encoding forms and the internal DER writer. |
src/mbedtls/mbedtls3.c |
Implements the Mbed TLS 3 public-key writing wrapper. |
README.md |
Lists key writing among supported compatibility features. |
docs/mbedtls-compatibility.md |
Documents APIs, feature requirements, compatibility differences, and tests. |
Review effort: Balanced
Frauschi
reviewed
Dec 1, 2026
Frauschi
left a comment
Member
There was a problem hiding this comment.
6 comments inline, nothing blocking.
…AX_BYTES to 1 without EC, update docs
Frauschi
approved these changes
Dec 2, 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.
Adds
mbedtls/pk.hkey writing, withMBEDTLS_PK_WRITE_C:mbedtls_pk_write_key_derandmbedtls_pk_write_pubkey_der. Private keys are RSA or EC, written as PKCS11 or SEC1, also when parsed from PKCS8. Public keys are RSA, EC, X25519 or X448, written as SubjectPublicKeyInfo from a public or private key or a certificate'spkmbedtls_pk_write_key_pemandmbedtls_pk_write_pubkey_pem, withMBEDTLS_BASE64_Cmbedtls_pk_write_pubkey, withWOLFPSA_MBEDTLS_3MBEDTLS_ERR_ASN1_BUF_TOO_SMALL,MBEDTLS_MPI_MAX_SIZEandMBEDTLS_ECP_MAX_BYTES, which applications use to size the buffers