Skip to content

Commit 1e247c2

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 1e247c2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

connectivity/netsocket/source/TLSSocketWrapper.cpp

Lines changed: 11 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,13 @@ 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+
psa_status_t status = psa_crypto_init();
50+
if (status != PSA_SUCCESS) {
51+
tr_err("psa_crypto_init() failed (" PRIu32 ")", status);
52+
}
53+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
54+
4455
#if defined(MBEDTLS_PLATFORM_C)
4556
int ret = mbedtls_platform_setup(nullptr);
4657
if (ret != 0) {

0 commit comments

Comments
 (0)