Changed every memcpy to SCA equivalent mbedtls_platform_memcpy
This makes physical attacks more difficult.
diff --git a/library/aes.c b/library/aes.c
index 97d9e25..33eeb24 100644
--- a/library/aes.c
+++ b/library/aes.c
@@ -1113,13 +1113,13 @@
{
while( length > 0 )
{
- memcpy( temp, input, 16 );
+ mbedtls_platform_memcpy( temp, input, 16 );
mbedtls_aes_crypt_ecb( ctx, mode, input, output );
for( i = 0; i < 16; i++ )
output[i] = (unsigned char)( output[i] ^ iv[i] );
- memcpy( iv, temp, 16 );
+ mbedtls_platform_memcpy( iv, temp, 16 );
input += 16;
output += 16;
@@ -1134,7 +1134,7 @@
output[i] = (unsigned char)( input[i] ^ iv[i] );
mbedtls_aes_crypt_ecb( ctx, mode, output, output );
- memcpy( iv, output, 16 );
+ mbedtls_platform_memcpy( iv, output, 16 );
input += 16;
output += 16;
@@ -1251,7 +1251,7 @@
* and this tweak for the lefover bytes. Save the current tweak for
* the leftovers and then update the current tweak for use on this,
* the last full block. */
- memcpy( prev_tweak, tweak, sizeof( tweak ) );
+ mbedtls_platform_memcpy( prev_tweak, tweak, sizeof( tweak ) );
mbedtls_gf128mul_x_ble( tweak, tweak );
}
@@ -1393,7 +1393,7 @@
AES_VALIDATE_RET( output != NULL );
while( length-- )
{
- memcpy( ov, iv, 16 );
+ mbedtls_platform_memcpy( ov, iv, 16 );
mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv );
if( mode == MBEDTLS_AES_DECRYPT )
@@ -1404,7 +1404,7 @@
if( mode == MBEDTLS_AES_ENCRYPT )
ov[16] = c;
- memcpy( iv, ov + 1, 16 );
+ mbedtls_platform_memcpy( iv, ov + 1, 16 );
}
return( 0 );
@@ -1992,9 +1992,9 @@
{
unsigned char tmp[16];
- memcpy( tmp, prv, 16 );
- memcpy( prv, buf, 16 );
- memcpy( buf, tmp, 16 );
+ mbedtls_platform_memcpy( tmp, prv, 16 );
+ mbedtls_platform_memcpy( prv, buf, 16 );
+ mbedtls_platform_memcpy( buf, tmp, 16 );
}
ret = mbedtls_aes_crypt_cbc( &ctx, mode, 16, iv, buf, buf );
@@ -2069,12 +2069,12 @@
if( mode == MBEDTLS_AES_DECRYPT )
{
- memcpy( buf, aes_test_cfb128_ct[u], 64 );
+ mbedtls_platform_memcpy( buf, aes_test_cfb128_ct[u], 64 );
aes_tests = aes_test_cfb128_pt;
}
else
{
- memcpy( buf, aes_test_cfb128_pt, 64 );
+ mbedtls_platform_memcpy( buf, aes_test_cfb128_pt, 64 );
aes_tests = aes_test_cfb128_ct[u];
}
@@ -2148,12 +2148,12 @@
if( mode == MBEDTLS_AES_DECRYPT )
{
- memcpy( buf, aes_test_ofb_ct[u], 64 );
+ mbedtls_platform_memcpy( buf, aes_test_ofb_ct[u], 64 );
aes_tests = aes_test_ofb_pt;
}
else
{
- memcpy( buf, aes_test_ofb_pt, 64 );
+ mbedtls_platform_memcpy( buf, aes_test_ofb_pt, 64 );
aes_tests = aes_test_ofb_ct[u];
}
@@ -2215,12 +2215,12 @@
if( mode == MBEDTLS_AES_DECRYPT )
{
- memcpy( buf, aes_test_ctr_ct[u], len );
+ mbedtls_platform_memcpy( buf, aes_test_ctr_ct[u], len );
aes_tests = aes_test_ctr_pt[u];
}
else
{
- memcpy( buf, aes_test_ctr_pt[u], len );
+ mbedtls_platform_memcpy( buf, aes_test_ctr_pt[u], len );
aes_tests = aes_test_ctr_ct[u];
}
@@ -2273,7 +2273,7 @@
#endif /* MBEDTLS_AES_ONLY_ENCRYPT */
mbedtls_platform_memset( key, 0, sizeof( key ) );
- memcpy( key, aes_test_xts_key[u], 32 );
+ mbedtls_platform_memcpy( key, aes_test_xts_key[u], 32 );
data_unit = aes_test_xts_data_unit[u];
len = sizeof( *aes_test_xts_ct32 );
@@ -2283,7 +2283,7 @@
ret = mbedtls_aes_xts_setkey_dec( &ctx_xts, key, 256 );
if( ret != 0)
goto exit;
- memcpy( buf, aes_test_xts_ct32[u], len );
+ mbedtls_platform_memcpy( buf, aes_test_xts_ct32[u], len );
aes_tests = aes_test_xts_pt32[u];
}
else
@@ -2291,7 +2291,7 @@
ret = mbedtls_aes_xts_setkey_enc( &ctx_xts, key, 256 );
if( ret != 0)
goto exit;
- memcpy( buf, aes_test_xts_pt32[u], len );
+ mbedtls_platform_memcpy( buf, aes_test_xts_pt32[u], len );
aes_tests = aes_test_xts_ct32[u];
}