Repository navigation
mbedtls: release the previous PSA key on re-init, map HMAC init errors - #825
Merged
Merged
Conversation
Contributor
Author
|
@pabuhler PTAL |
pabuhler
approved these changes
Oct 9, 2026
srtp_hmac_mbedtls_init() and srtp_aes_gcm_mbedtls_context_init() imported a new PSA key without destroying the one from a previous init, so re-keying an auth or a GCM cipher leaked a key slot each time. Destroy the old key first, as the AES-ICM backend already does. srtp_hmac_mbedtls_init() also returned the raw psa_status_t, a negative PSA error, as an srtp_err_status_t. Return srtp_err_status_auth_fail, matching the OpenSSL and wolfSSL backends. test_srtp gains mbedTLS-only tests that count volatile PSA keys around a double init, and check the status of a rejected (zero-length) HMAC key.
vikramdattu
force-pushed
the
fix/hmac-mbedtls-init
branch
from
October 9, 2026 07:21
d8a3a61 to
80c827b
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.
Two problems in the mbedTLS (PSA) backend:
srtp_hmac_mbedtls_init()andsrtp_aes_gcm_mbedtls_context_init()import a new PSA key without destroying the key from an earlier init. Re-keying an auth or GCM cipher therefore leaks one PSA key slot per init. The AES-ICM backend already destroys the old key first; this applies the same pattern to both.srtp_hmac_mbedtls_init()returns the rawpsa_status_t(a negative PSA error) as ansrtp_err_status_t. It now returnssrtp_err_status_auth_fail, as the OpenSSL and wolfSSL backends do.This brings
mainin line with2_x_dev, whose mbedTLS 4 / PSA path (#813) already destroys the previous key before importing and returnssrtp_err_status_auth_fail.Tests (
test_srtp, mbedTLS builds only):srtp_hmac_mbedtls_reinit_does_not_leak_key,srtp_aes_gcm_mbedtls_reinit_does_not_leak_key: count volatile PSA keys withmbedtls_psa_get_stats()around two inits and the dealloc.srtp_hmac_mbedtls_init_failure_returns_srtp_status: a zero-length HMAC key, which PSA rejects, must returnsrtp_err_status_auth_fail.All three fail without the fix and pass with it. Tested on mbedTLS 4.0.0 (as in the CI workflow): all 13 ctest suites pass, and
./format.sh -dwith clang-format 14 is clean. A non-mbedTLS build compiles with the tests guarded out.mbedtls_psa_get_stats()is an mbedTLS extension, and its fields areMBEDTLS_PRIVATE. The tests depend on it only under#ifdef MBEDTLS.