Skip to content

Commit 929956d

Browse files
committed
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.
1 parent fbca8e9 commit 929956d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

connectivity/netsocket/source/TLSSocketWrapper.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#include "mbed_error.h"
2929
#include "rtos/Kernel.h"
3030

31+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
32+
#include "psa/crypto.h"
33+
#endif
34+
3135
// This class requires Mbed TLS SSL/TLS client code
3236
#if defined(MBEDTLS_SSL_CLI_C)
3337

@@ -41,6 +45,16 @@ TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, cont
4145
_clicert_allocated(false),
4246
_ssl_conf_allocated(false)
4347
{
48+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
49+
// It is safe to call psa_crypto_init() any number of times as
50+
// defined by the PSA Crypto API. There is no standard "deinit"
51+
// function.
52+
psa_status_t status = psa_crypto_init();
53+
if (status != PSA_SUCCESS) {
54+
tr_err("psa_crypto_init() failed (" PRIu32 ")", status);
55+
}
56+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
57+
4458
#if defined(MBEDTLS_PLATFORM_C)
4559
int ret = mbedtls_platform_setup(nullptr);
4660
if (ret != 0) {

0 commit comments

Comments
 (0)