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/aria.c b/library/aria.c
index aff66d6..90501f8 100644
--- a/library/aria.c
+++ b/library/aria.c
@@ -467,7 +467,7 @@
GET_UINT32_LE( w[0][2], key, 8 );
GET_UINT32_LE( w[0][3], key, 12 );
- memset( w[1], 0, 16 );
+ mbedtls_platform_memset( w[1], 0, 16 );
if( keybits >= 192 )
{
GET_UINT32_LE( w[1][0], key, 16 ); // 192 bit key
@@ -600,7 +600,7 @@
void mbedtls_aria_init( mbedtls_aria_context *ctx )
{
ARIA_VALIDATE( ctx != NULL );
- memset( ctx, 0, sizeof( mbedtls_aria_context ) );
+ mbedtls_platform_memset( ctx, 0, sizeof( mbedtls_aria_context ) );
}
/* Clear context */
@@ -987,7 +987,7 @@
mbedtls_printf( " ARIA-CBC-%d (enc): ", 128 + 64 * i );
mbedtls_aria_setkey_enc( &ctx, aria_test2_key, 128 + 64 * i );
memcpy( iv, aria_test2_iv, MBEDTLS_ARIA_BLOCKSIZE );
- memset( buf, 0x55, sizeof( buf ) );
+ mbedtls_platform_memset( buf, 0x55, sizeof( buf ) );
mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, 48, iv,
aria_test2_pt, buf );
if( memcmp( buf, aria_test2_cbc_ct[i], 48 ) != 0 )
@@ -998,7 +998,7 @@
mbedtls_printf( " ARIA-CBC-%d (dec): ", 128 + 64 * i );
mbedtls_aria_setkey_dec( &ctx, aria_test2_key, 128 + 64 * i );
memcpy( iv, aria_test2_iv, MBEDTLS_ARIA_BLOCKSIZE );
- memset( buf, 0xAA, sizeof( buf ) );
+ mbedtls_platform_memset( buf, 0xAA, sizeof( buf ) );
mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, 48, iv,
aria_test2_cbc_ct[i], buf );
if( memcmp( buf, aria_test2_pt, 48 ) != 0 )
@@ -1017,7 +1017,7 @@
mbedtls_printf( " ARIA-CFB-%d (enc): ", 128 + 64 * i );
mbedtls_aria_setkey_enc( &ctx, aria_test2_key, 128 + 64 * i );
memcpy( iv, aria_test2_iv, MBEDTLS_ARIA_BLOCKSIZE );
- memset( buf, 0x55, sizeof( buf ) );
+ mbedtls_platform_memset( buf, 0x55, sizeof( buf ) );
j = 0;
mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT, 48, &j, iv,
aria_test2_pt, buf );
@@ -1029,7 +1029,7 @@
mbedtls_printf( " ARIA-CFB-%d (dec): ", 128 + 64 * i );
mbedtls_aria_setkey_enc( &ctx, aria_test2_key, 128 + 64 * i );
memcpy( iv, aria_test2_iv, MBEDTLS_ARIA_BLOCKSIZE );
- memset( buf, 0xAA, sizeof( buf ) );
+ mbedtls_platform_memset( buf, 0xAA, sizeof( buf ) );
j = 0;
mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT, 48, &j,
iv, aria_test2_cfb_ct[i], buf );
@@ -1047,8 +1047,8 @@
if( verbose )
mbedtls_printf( " ARIA-CTR-%d (enc): ", 128 + 64 * i );
mbedtls_aria_setkey_enc( &ctx, aria_test2_key, 128 + 64 * i );
- memset( iv, 0, MBEDTLS_ARIA_BLOCKSIZE ); // IV = 0
- memset( buf, 0x55, sizeof( buf ) );
+ mbedtls_platform_memset( iv, 0, MBEDTLS_ARIA_BLOCKSIZE ); // IV = 0
+ mbedtls_platform_memset( buf, 0x55, sizeof( buf ) );
j = 0;
mbedtls_aria_crypt_ctr( &ctx, 48, &j, iv, blk,
aria_test2_pt, buf );
@@ -1059,8 +1059,8 @@
if( verbose )
mbedtls_printf( " ARIA-CTR-%d (dec): ", 128 + 64 * i );
mbedtls_aria_setkey_enc( &ctx, aria_test2_key, 128 + 64 * i );
- memset( iv, 0, MBEDTLS_ARIA_BLOCKSIZE ); // IV = 0
- memset( buf, 0xAA, sizeof( buf ) );
+ mbedtls_platform_memset( iv, 0, MBEDTLS_ARIA_BLOCKSIZE ); // IV = 0
+ mbedtls_platform_memset( buf, 0xAA, sizeof( buf ) );
j = 0;
mbedtls_aria_crypt_ctr( &ctx, 48, &j, iv, blk,
aria_test2_ctr_ct[i], buf );