Skip to content

Commit 4dc9aeb

Browse files
author
Hanno Becker
committed
Swap initializations of PSA Crypto and Mbed TLS platform
As PSA Crypto is independent of Mbed TLS, `psa_crypto_init()` must eventually work standalone, and in particular not require a prior call to `mbedtls_platform_init()`. At the moment, however, it might still rely on HW drivers being initialized by `mbedtls_platform_init()`, and so the latter should be invoked before `psa_crypto_init()`. This commit changes the order of the calls accordingly. In general, the relation between of `psa_crypto_init()` and `mbedtls_platform_init()` still needs to be discussed and documented, and once that's done, the code might need revision. As it stands, however, it should work with current implementations of `psa_crypto_init()` and `mbedtls_platform_init()`.
1 parent 6b1f3c3 commit 4dc9aeb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tls-client/main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ int main()
5555
{
5656
int exit_code = MBEDTLS_EXIT_FAILURE;
5757

58+
if((exit_code = mbedtls_platform_setup(NULL)) != 0) {
59+
printf("Platform initialization failed with error %d\r\n", exit_code);
60+
return MBEDTLS_EXIT_FAILURE;
61+
}
62+
5863
#if defined(MBEDTLS_USE_PSA_CRYPTO)
5964
/*
6065
* Initialize underlying PSA Crypto implementation.
@@ -73,10 +78,6 @@ int main()
7378
}
7479
#endif /* MBEDTLS_USE_PSA_CRYPTO */
7580

76-
if((exit_code = mbedtls_platform_setup(NULL)) != 0) {
77-
printf("Platform initialization failed with error %d\r\n", exit_code);
78-
return MBEDTLS_EXIT_FAILURE;
79-
}
8081
/*
8182
* The default 9600 bps is too slow to print full TLS debug info and could
8283
* cause the other party to time out.

0 commit comments

Comments
 (0)