From c490c45917d7be5cc84657b27c03feceada2545a Mon Sep 17 00:00:00 2001 From: Vikram Dattu Date: Mon, 12 Oct 2026 14:22:07 +0530 Subject: [PATCH] mbedtls: call psa_crypto_init() in the AES-GCM and HMAC init paths Only the AES-ICM backend initialized PSA. AES-GCM and HMAC relied on it having run first, which srtp_init() guarantees by self-testing AES-ICM before them. Using either type without srtp_init() made the key import fail: AES-GCM init returned srtp_err_status_init_fail and HMAC init srtp_err_status_auth_fail. Call psa_crypto_init() in both, as AES-ICM does. It is idempotent. 2_x_dev already does this (#813). --- crypto/cipher/aes_gcm_mbedtls.c | 6 ++++++ crypto/hash/hmac_mbedtls.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/crypto/cipher/aes_gcm_mbedtls.c b/crypto/cipher/aes_gcm_mbedtls.c index 13465f1da..04ff98b6a 100644 --- a/crypto/cipher/aes_gcm_mbedtls.c +++ b/crypto/cipher/aes_gcm_mbedtls.c @@ -293,6 +293,12 @@ static srtp_err_status_t srtp_aes_gcm_mbedtls_context_init(void *cv, break; } + status = psa_crypto_init(); + if (status != PSA_SUCCESS) { + debug_print(srtp_mod_aes_gcm, "psa_crypto_init failed: %d", status); + return srtp_err_status_cipher_fail; + } + psa_key_attributes_t attr = PSA_KEY_ATTRIBUTES_INIT; psa_set_key_usage_flags(&attr, diff --git a/crypto/hash/hmac_mbedtls.c b/crypto/hash/hmac_mbedtls.c index b7733b2ff..af4db2cf1 100644 --- a/crypto/hash/hmac_mbedtls.c +++ b/crypto/hash/hmac_mbedtls.c @@ -148,6 +148,12 @@ static srtp_err_status_t srtp_hmac_mbedtls_init(void *statev, psa_status_t status = PSA_SUCCESS; psa_key_attributes_t attr = PSA_KEY_ATTRIBUTES_INIT; + status = psa_crypto_init(); + if (status != PSA_SUCCESS) { + debug_print(srtp_mod_hmac, "psa_crypto_init failed: %d", status); + return srtp_err_status_auth_fail; + } + psa_set_key_type(&attr, PSA_KEY_TYPE_HMAC); psa_set_key_usage_flags(&attr, PSA_KEY_USAGE_SIGN_MESSAGE); psa_set_key_algorithm(&attr, PSA_ALG_HMAC(PSA_ALG_SHA_1));