Skip to content

Commit 6b1f3c3

Browse files
author
Hanno Becker
committed
Allow the use of PSA Crypto in TLS client example
1 parent 8f275cf commit 6b1f3c3

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tls-client/main.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#include "mbed.h"
3636

3737
#include "mbedtls/platform.h"
38+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
39+
#include "psa/crypto.h"
40+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
3841

3942
#include "HelloHttpsClient.h"
4043

@@ -52,6 +55,24 @@ int main()
5255
{
5356
int exit_code = MBEDTLS_EXIT_FAILURE;
5457

58+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
59+
/*
60+
* Initialize underlying PSA Crypto implementation.
61+
* Even if the HTTPS client doesn't make use of
62+
* PSA-specific API, for example for setting opaque PSKs
63+
* or opaque private keys, Mbed TLS will use PSA
64+
* for public and symmetric key operations as well as
65+
* hashing.
66+
*/
67+
psa_status_t status;
68+
status = psa_crypto_init();
69+
if( status != PSA_SUCCESS )
70+
{
71+
printf("psa_crypto_init() failed with %d\r\n", status );
72+
return MBEDTLS_EXIT_FAILURE;
73+
}
74+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
75+
5576
if((exit_code = mbedtls_platform_setup(NULL)) != 0) {
5677
printf("Platform initialization failed with error %d\r\n", exit_code);
5778
return MBEDTLS_EXIT_FAILURE;

tls-client/mbedtls_entropy_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,14 @@
3636
#undef MBEDTLS_MPI_MAX_SIZE
3737
#define MBEDTLS_MPI_MAX_SIZE 256
3838

39+
/* This macro determines whether Mbed TLS uses its own legacy crypto library
40+
* or an implementation of the PSA Crypto API such as Mbed Crypto.
41+
*
42+
* To confirm the use of PSA Crypto, you may enable debugging by setting
43+
* HELLO_HTTPS_CLIENT_DEBUG_LEVEL in HelloHttpsClient.h and look for
44+
* PSA-related debugging output on the serial line.
45+
*
46+
* Uncomment this to use the PSA Crypto API. */
47+
//#define MBEDTLS_USE_PSA_CRYPTO
48+
3949
#define MBEDTLS_MPI_WINDOW_SIZE 1

0 commit comments

Comments
 (0)