VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Tests.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-02-22 00:23:19 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-02-22 01:03:19 +0100
commitcb9859fa0e061fa3b068447c3860588cf3522f4e (patch)
tree3e4e6fa8c279827863255c8894cffe9cb54a2fec /src/Common/Tests.c
parent717ffadf931407bb2e5684f3fcdef86b37e8213a (diff)
downloadVeraCrypt-cb9859fa0e061fa3b068447c3860588cf3522f4e.tar.gz
VeraCrypt-cb9859fa0e061fa3b068447c3860588cf3522f4e.zip
Speed and memory usage optimization for key derivation based on patches by Nils Maier. 20% improvement on 64-bit CPU for SHA512 and SHA256, 11% for Whirlpool and 13% for RIPEMD-160.
Diffstat (limited to 'src/Common/Tests.c')
-rw-r--r--src/Common/Tests.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/Common/Tests.c b/src/Common/Tests.c
index c5aea91d..6e2b0d95 100644
--- a/src/Common/Tests.c
+++ b/src/Common/Tests.c
@@ -1016,8 +1016,9 @@ BOOL test_hmac_sha256 ()
for (i = 0; i < sizeof (hmac_sha256_test_data) / sizeof(char *); i++)
{
- char digest[SHA256_DIGESTSIZE];
- hmac_sha256 (hmac_sha256_test_keys[i], (int) strlen (hmac_sha256_test_keys[i]), hmac_sha256_test_data[i], (int) strlen (hmac_sha256_test_data[i]), digest);
+ char digest[1024]; /* large enough to hold digets and test vector inputs */
+ memcpy (digest, hmac_sha256_test_data[i], strlen (hmac_sha256_test_data[i]));
+ hmac_sha256 (hmac_sha256_test_keys[i], (int) strlen (hmac_sha256_test_keys[i]), digest, (int) strlen (hmac_sha256_test_data[i]));
if (memcmp (digest, hmac_sha256_test_vectors[i], SHA256_DIGESTSIZE) != 0)
return FALSE;
else
@@ -1034,8 +1035,9 @@ BOOL test_hmac_sha512 ()
for (i = 0; i < sizeof (hmac_sha512_test_data) / sizeof(char *); i++)
{
- char digest[SHA512_DIGESTSIZE];
- hmac_sha512 (hmac_sha512_test_keys[i], (int) strlen (hmac_sha512_test_keys[i]), hmac_sha512_test_data[i], (int) strlen (hmac_sha512_test_data[i]), digest, SHA512_DIGESTSIZE);
+ char digest[1024]; /* large enough to hold digets and test vector inputs */
+ memcpy (digest, hmac_sha512_test_data[i], (int) strlen (hmac_sha512_test_data[i]));
+ hmac_sha512 (hmac_sha512_test_keys[i], (int) strlen (hmac_sha512_test_keys[i]), digest, (int) strlen (hmac_sha512_test_data[i]));
if (memcmp (digest, hmac_sha512_test_vectors[i], SHA512_DIGESTSIZE) != 0)
return FALSE;
else
@@ -1052,8 +1054,9 @@ BOOL test_hmac_ripemd160 ()
for (i = 0; i < sizeof (hmac_ripemd160_test_data) / sizeof(char *); i++)
{
- char digest[RIPEMD160_DIGESTSIZE];
- hmac_ripemd160 (hmac_ripemd160_test_keys[i], RIPEMD160_DIGESTSIZE, hmac_ripemd160_test_data[i], (int) strlen (hmac_ripemd160_test_data[i]), digest);
+ char digest[1024]; /* large enough to hold digets and test vector inputs */
+ memcpy (digest, hmac_ripemd160_test_data[i], strlen (hmac_ripemd160_test_data[i]));
+ hmac_ripemd160 (hmac_ripemd160_test_keys[i], RIPEMD160_DIGESTSIZE, digest, (int) strlen (hmac_ripemd160_test_data[i]));
if (memcmp (digest, hmac_ripemd160_test_vectors[i], RIPEMD160_DIGESTSIZE) != 0)
return FALSE;
else
@@ -1065,9 +1068,10 @@ BOOL test_hmac_ripemd160 ()
BOOL test_hmac_whirlpool ()
{
- unsigned char digest[WHIRLPOOL_DIGESTSIZE];
+ unsigned char digest[1024]; /* large enough to hold digets and test vector inputs */
- hmac_whirlpool (hmac_whirlpool_test_key, 64, hmac_whirlpool_test_data, (int) strlen (hmac_whirlpool_test_data), digest, WHIRLPOOL_DIGESTSIZE);
+ memcpy (digest, hmac_whirlpool_test_data, strlen (hmac_whirlpool_test_data));
+ hmac_whirlpool (hmac_whirlpool_test_key, 64, digest, (int) strlen (hmac_whirlpool_test_data));
if (memcmp (digest, hmac_whirlpool_test_vectors, WHIRLPOOL_DIGESTSIZE) != 0)
return FALSE;