Replace memset() with mbedtls_platform_memset()
Steps:
1. sed -i 's/\bmemset(\([^)]\)/mbedtls_platform_memset(\1/g' library/*.c tinycrypt/*.c include/mbedtls/*.h scripts/data_files/*.fmt
2. Manually edit library/platform_util.c to revert to memset() in the
implementations of mbedtls_platform_memset() and mbedtls_platform_memcpy()
3. egrep -n '\<memset\>' library/*.c include/mbedtls/*.h tinycrypt/*.c
The remaining occurrences are in three categories:
a. From point 2 above.
b. In comments.
c. In the initialisation of memset_func, to be changed in a future commit.
diff --git a/library/aes.c b/library/aes.c
index aff0a99..4850fab 100644
--- a/library/aes.c
+++ b/library/aes.c
@@ -519,7 +519,7 @@
{
AES_VALIDATE( ctx != NULL );
- memset( ctx, 0, sizeof( mbedtls_aes_context ) );
+ mbedtls_platform_memset( ctx, 0, sizeof( mbedtls_aes_context ) );
}
void mbedtls_aes_free( mbedtls_aes_context *ctx )
@@ -1809,7 +1809,7 @@
#endif
mbedtls_aes_context ctx;
- memset( key, 0, 32 );
+ mbedtls_platform_memset( key, 0, 32 );
mbedtls_aes_init( &ctx );
/*
@@ -1825,7 +1825,7 @@
mbedtls_printf( " AES-ECB-%3d (%s): ", keybits,
( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
- memset( buf, 0, 16 );
+ mbedtls_platform_memset( buf, 0, 16 );
if( mode == MBEDTLS_AES_DECRYPT )
{
@@ -1887,9 +1887,9 @@
mbedtls_printf( " AES-CBC-%3d (%s): ", keybits,
( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
- memset( iv , 0, 16 );
- memset( prv, 0, 16 );
- memset( buf, 0, 16 );
+ mbedtls_platform_memset( iv , 0, 16 );
+ mbedtls_platform_memset( prv, 0, 16 );
+ mbedtls_platform_memset( buf, 0, 16 );
if( mode == MBEDTLS_AES_DECRYPT )
{
@@ -2147,7 +2147,7 @@
mbedtls_printf( " AES-XTS-128 (%s): ",
( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
- memset( key, 0, sizeof( key ) );
+ mbedtls_platform_memset( key, 0, sizeof( key ) );
memcpy( key, aes_test_xts_key[u], 32 );
data_unit = aes_test_xts_data_unit[u];