Changed every memcpy to SCA equivalent mbedtls_platform_memcpy
This makes physical attacks more difficult.
diff --git a/library/rsa.c b/library/rsa.c
index 02e758b..9cadd1b 100644
--- a/library/rsa.c
+++ b/library/rsa.c
@@ -1171,7 +1171,7 @@
p += hlen;
p += olen - 2 * hlen - 2 - ilen;
*p++ = 1;
- memcpy( p, input, ilen );
+ mbedtls_platform_memcpy( p, input, ilen );
mbedtls_md_init( &md_ctx );
if( ( ret = mbedtls_md_setup( &md_ctx, md_info, 0 ) ) != 0 )
@@ -1263,7 +1263,7 @@
}
*p++ = 0;
- memcpy( p, input, ilen );
+ mbedtls_platform_memcpy( p, input, ilen );
return( ( mode == MBEDTLS_RSA_PUBLIC )
? mbedtls_rsa_public( ctx, output, output )
@@ -1441,7 +1441,7 @@
}
*olen = ilen - (p - buf);
- memcpy( output, p, *olen );
+ mbedtls_platform_memcpy( output, p, *olen );
ret = 0;
cleanup:
@@ -1695,7 +1695,7 @@
/* Finally copy the decrypted plaintext plus trailing zeros
* into the output buffer. */
- memcpy( output, buf + ilen - plaintext_max_size, plaintext_max_size );
+ mbedtls_platform_memcpy( output, buf + ilen - plaintext_max_size, plaintext_max_size );
/* Report the amount of data we copied to the output buffer. In case
* of errors (bad padding or output too large), the value of *olen
@@ -1825,7 +1825,7 @@
msb = mbedtls_mpi_bitlen( &ctx->N ) - 1;
p += olen - hlen - slen - 2;
*p++ = 0x01;
- memcpy( p, salt, slen );
+ mbedtls_platform_memcpy( p, salt, slen );
p += slen;
mbedtls_md_init( &md_ctx );
@@ -1965,7 +1965,7 @@
/* Are we signing raw data? */
if( md_alg == MBEDTLS_MD_NONE )
{
- memcpy( p, hash, hashlen );
+ mbedtls_platform_memcpy( p, hash, hashlen );
return( 0 );
}
@@ -1988,13 +1988,13 @@
*p++ = (unsigned char)( 0x04 + oid_size );
*p++ = MBEDTLS_ASN1_OID;
*p++ = (unsigned char) oid_size;
- memcpy( p, oid, oid_size );
+ mbedtls_platform_memcpy( p, oid, oid_size );
p += oid_size;
*p++ = MBEDTLS_ASN1_NULL;
*p++ = 0x00;
*p++ = MBEDTLS_ASN1_OCTET_STRING;
*p++ = (unsigned char) hashlen;
- memcpy( p, hash, hashlen );
+ mbedtls_platform_memcpy( p, hash, hashlen );
p += hashlen;
/* Just a sanity-check, should be automatic
@@ -2078,7 +2078,7 @@
goto cleanup;
}
- memcpy( sig, sig_try, ctx->len );
+ mbedtls_platform_memcpy( sig, sig_try, ctx->len );
cleanup:
mbedtls_free( sig_try );
@@ -2623,7 +2623,7 @@
if( verbose != 0 )
mbedtls_printf( "passed\n PKCS#1 encryption : " );
- memcpy( rsa_plaintext, RSA_PT, PT_LEN );
+ mbedtls_platform_memcpy( rsa_plaintext, RSA_PT, PT_LEN );
if( mbedtls_rsa_pkcs1_encrypt( &rsa, myrand, NULL, MBEDTLS_RSA_PUBLIC,
PT_LEN, rsa_plaintext,