TLSSocketWrapper: Initialize PSA Crypto if used by Mbed TLS

When `MBEDTLS_USE_PSA_CRYPTO` is set, Mbed TLS uses the PSA Crypto API
where possible. It is necessary to initialize PSA Crypto beforehand.
pull/14815/head
Lingkai Dong 2021-06-29 17:43:10 +01:00
parent fbca8e9c84
commit 929956d16a
1 changed files with 14 additions and 0 deletions

View File

@ -28,6 +28,10 @@
#include "mbed_error.h"
#include "rtos/Kernel.h"
#if defined(MBEDTLS_USE_PSA_CRYPTO)
#include "psa/crypto.h"
#endif
// This class requires Mbed TLS SSL/TLS client code
#if defined(MBEDTLS_SSL_CLI_C)
@ -41,6 +45,16 @@ TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, cont
_clicert_allocated(false),
_ssl_conf_allocated(false)
{
#if defined(MBEDTLS_USE_PSA_CRYPTO)
// It is safe to call psa_crypto_init() any number of times as
// defined by the PSA Crypto API. There is no standard "deinit"
// function.
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
tr_err("psa_crypto_init() failed (" PRIu32 ")", status);
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#if defined(MBEDTLS_PLATFORM_C)
int ret = mbedtls_platform_setup(nullptr);
if (ret != 0) {