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/sha256.c b/library/sha256.c
index 98965f7..10d3ff5 100644
--- a/library/sha256.c
+++ b/library/sha256.c
@@ -59,7 +59,7 @@
{
SHA256_VALIDATE( ctx != NULL );
- memset( ctx, 0, sizeof( mbedtls_sha256_context ) );
+ mbedtls_platform_memset( ctx, 0, sizeof( mbedtls_sha256_context ) );
}
void mbedtls_sha256_free( mbedtls_sha256_context *ctx )
@@ -337,17 +337,17 @@
if( used <= 56 )
{
/* Enough room for padding + length in current block */
- memset( ctx->buffer + used, 0, 56 - used );
+ mbedtls_platform_memset( ctx->buffer + used, 0, 56 - used );
}
else
{
/* We'll need an extra block */
- memset( ctx->buffer + used, 0, 64 - used );
+ mbedtls_platform_memset( ctx->buffer + used, 0, 64 - used );
if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 )
return( ret );
- memset( ctx->buffer, 0, 56 );
+ mbedtls_platform_memset( ctx->buffer, 0, 56 );
}
/*
@@ -527,7 +527,7 @@
if( j == 2 )
{
- memset( buf, 'a', buflen = 1000 );
+ mbedtls_platform_memset( buf, 'a', buflen = 1000 );
for( j = 0; j < 1000; j++ )
{