Skip to content

Commit f3db9a1

Browse files
Ron EldorArto Kinnunen
authored andcommitted
(via Mbed OS) Add mbedtls platform setup and teardown to modules
Add calls to `mbedtls_platform_setup()` and `mbedtls_platform_teardown()` to all modules and tests using Mbed TLS.
1 parent 5feb8dd commit f3db9a1

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

source/coap_security_handler.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ static int coap_security_handler_init(coap_security_t *sec)
102102
const int entropy_source_type = MBEDTLS_ENTROPY_SOURCE_WEAK;
103103
#endif
104104

105+
#if defined(MBEDTLS_PLATFORM_C)
106+
if (mbedtls_platform_setup(NULL) != 0)
107+
return -1;
108+
#endif /* MBEDTLS_PLATFORM_C */
109+
105110
mbedtls_ssl_init(&sec->_ssl);
106111
mbedtls_ssl_config_init(&sec->_conf);
107112
mbedtls_ctr_drbg_init(&sec->_ctr_drbg);
@@ -153,6 +158,9 @@ static void coap_security_handler_reset(coap_security_t *sec)
153158
mbedtls_ctr_drbg_free(&sec->_ctr_drbg);
154159
mbedtls_ssl_config_free(&sec->_conf);
155160
mbedtls_ssl_free(&sec->_ssl);
161+
#if defined(MBEDTLS_PLATFORM_C)
162+
mbedtls_platform_teardown(NULL);
163+
#endif /* MBEDTLS_PLATFORM_C */
156164
}
157165

158166

test/coap-service/unittest/stub/mbedtls_stub.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,15 @@ int mbedtls_ssl_session_reset(mbedtls_ssl_context *ssl)
387387
void mbedtls_strerror(int ret, char *buf, size_t buflen)
388388
{
389389
}
390+
391+
int mbedtls_platform_setup( mbedtls_platform_context *ctx )
392+
{
393+
(void)ctx;
394+
395+
return( 0 );
396+
}
397+
398+
void mbedtls_platform_teardown( mbedtls_platform_context *ctx )
399+
{
400+
(void)ctx;
401+
}

test/coap-service/unittest/stub/mbedtls_stub.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "mbedtls/sha256.h"
2929
#include "mbedtls/entropy.h"
3030
#include "mbedtls/pk.h"
31-
31+
#include "mbedtls/platform.h"
3232

3333

3434
#define HANDSHAKE_FINISHED_VALUE 8888

0 commit comments

Comments
 (0)