Skip to content

Commit 0294d09

Browse files
authored
Merge pull request #232 from ARMmbed/tls-client_psa
Allow the use of PSA Crypto in TLS client example
2 parents 8f275cf + 4dc9aeb commit 0294d09

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tls-client/main.cpp

Lines changed: 22 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

@@ -56,6 +59,25 @@ int main()
5659
printf("Platform initialization failed with error %d\r\n", exit_code);
5760
return MBEDTLS_EXIT_FAILURE;
5861
}
62+
63+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
64+
/*
65+
* Initialize underlying PSA Crypto implementation.
66+
* Even if the HTTPS client doesn't make use of
67+
* PSA-specific API, for example for setting opaque PSKs
68+
* or opaque private keys, Mbed TLS will use PSA
69+
* for public and symmetric key operations as well as
70+
* hashing.
71+
*/
72+
psa_status_t status;
73+
status = psa_crypto_init();
74+
if( status != PSA_SUCCESS )
75+
{
76+
printf("psa_crypto_init() failed with %d\r\n", status );
77+
return MBEDTLS_EXIT_FAILURE;
78+
}
79+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
80+
5981
/*
6082
* The default 9600 bps is too slow to print full TLS debug info and could
6183
* cause the other party to time out.

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)