Changed every memcpy to SCA equivalent mbedtls_platform_memcpy
This makes physical attacks more difficult.
diff --git a/library/des.c b/library/des.c
index 62bc10d..e6dcc05 100644
--- a/library/des.c
+++ b/library/des.c
@@ -684,7 +684,7 @@
output[i] = (unsigned char)( input[i] ^ iv[i] );
mbedtls_des_crypt_ecb( ctx, output, output );
- memcpy( iv, output, 8 );
+ mbedtls_platform_memcpy( iv, output, 8 );
input += 8;
output += 8;
@@ -695,13 +695,13 @@
{
while( length > 0 )
{
- memcpy( temp, input, 8 );
+ mbedtls_platform_memcpy( temp, input, 8 );
mbedtls_des_crypt_ecb( ctx, input, output );
for( i = 0; i < 8; i++ )
output[i] = (unsigned char)( output[i] ^ iv[i] );
- memcpy( iv, temp, 8 );
+ mbedtls_platform_memcpy( iv, temp, 8 );
input += 8;
output += 8;
@@ -783,7 +783,7 @@
output[i] = (unsigned char)( input[i] ^ iv[i] );
mbedtls_des3_crypt_ecb( ctx, output, output );
- memcpy( iv, output, 8 );
+ mbedtls_platform_memcpy( iv, output, 8 );
input += 8;
output += 8;
@@ -794,13 +794,13 @@
{
while( length > 0 )
{
- memcpy( temp, input, 8 );
+ mbedtls_platform_memcpy( temp, input, 8 );
mbedtls_des3_crypt_ecb( ctx, input, output );
for( i = 0; i < 8; i++ )
output[i] = (unsigned char)( output[i] ^ iv[i] );
- memcpy( iv, temp, 8 );
+ mbedtls_platform_memcpy( iv, temp, 8 );
input += 8;
output += 8;
@@ -896,7 +896,7 @@
( u == 0 ) ? ' ' : '3', 56 + u * 56,
( v == MBEDTLS_DES_DECRYPT ) ? "dec" : "enc" );
- memcpy( buf, des3_test_buf, 8 );
+ mbedtls_platform_memcpy( buf, des3_test_buf, 8 );
switch( i )
{
@@ -969,9 +969,9 @@
( u == 0 ) ? ' ' : '3', 56 + u * 56,
( v == MBEDTLS_DES_DECRYPT ) ? "dec" : "enc" );
- memcpy( iv, des3_test_iv, 8 );
- memcpy( prv, des3_test_iv, 8 );
- memcpy( buf, des3_test_buf, 8 );
+ mbedtls_platform_memcpy( iv, des3_test_iv, 8 );
+ mbedtls_platform_memcpy( prv, des3_test_iv, 8 );
+ mbedtls_platform_memcpy( buf, des3_test_buf, 8 );
switch( i )
{
@@ -1024,12 +1024,12 @@
else
mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
- memcpy( tmp, prv, 8 );
- memcpy( prv, buf, 8 );
- memcpy( buf, tmp, 8 );
+ mbedtls_platform_memcpy( tmp, prv, 8 );
+ mbedtls_platform_memcpy( prv, buf, 8 );
+ mbedtls_platform_memcpy( buf, tmp, 8 );
}
- memcpy( buf, prv, 8 );
+ mbedtls_platform_memcpy( buf, prv, 8 );
}
if( ( v == MBEDTLS_DES_DECRYPT &&