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/sha512.c b/library/sha512.c
index bdd20b2..44c087d 100644
--- a/library/sha512.c
+++ b/library/sha512.c
@@ -96,7 +96,7 @@
{
SHA512_VALIDATE( ctx != NULL );
- memset( ctx, 0, sizeof( mbedtls_sha512_context ) );
+ mbedtls_platform_memset( ctx, 0, sizeof( mbedtls_sha512_context ) );
}
void mbedtls_sha512_free( mbedtls_sha512_context *ctx )
@@ -383,17 +383,17 @@
if( used <= 112 )
{
/* Enough room for padding + length in current block */
- memset( ctx->buffer + used, 0, 112 - used );
+ mbedtls_platform_memset( ctx->buffer + used, 0, 112 - used );
}
else
{
/* We'll need an extra block */
- memset( ctx->buffer + used, 0, 128 - used );
+ mbedtls_platform_memset( ctx->buffer + used, 0, 128 - used );
if( ( ret = mbedtls_internal_sha512_process( ctx, ctx->buffer ) ) != 0 )
return( ret );
- memset( ctx->buffer, 0, 112 );
+ mbedtls_platform_memset( ctx->buffer, 0, 112 );
}
/*
@@ -585,7 +585,7 @@
if( j == 2 )
{
- memset( buf, 'a', buflen = 1000 );
+ mbedtls_platform_memset( buf, 'a', buflen = 1000 );
for( j = 0; j < 1000; j++ )
{