VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Pkcs5.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2014-10-05 00:34:41 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2014-11-08 23:23:40 +0100
commit50ca9fe46f457a773ab15f4569205c51bf9f96ea (patch)
treece0dca96cbb4c66c3ef00e8cbc7fc03e2081d3d9 /src/Common/Pkcs5.c
parent0178a6d33ff6afc7d0305619d3d250235ae55d09 (diff)
downloadVeraCrypt-50ca9fe46f457a773ab15f4569205c51bf9f96ea.tar.gz
VeraCrypt-50ca9fe46f457a773ab15f4569205c51bf9f96ea.zip
Optimization to reduce code size of derive_u_ripemd160. Useful for boatloader.
Diffstat (limited to 'src/Common/Pkcs5.c')
-rw-r--r--src/Common/Pkcs5.c45
1 files changed, 20 insertions, 25 deletions
diff --git a/src/Common/Pkcs5.c b/src/Common/Pkcs5.c
index 8f21bb80..c1222a03 100644
--- a/src/Common/Pkcs5.c
+++ b/src/Common/Pkcs5.c
@@ -247,8 +247,20 @@ void derive_u_ripemd160 (BOOL bNotTest, char *pwd, int pwd_len, char *salt, int
char j[RIPEMD160_DIGESTSIZE], k[RIPEMD160_DIGESTSIZE];
char init[128];
char counter[4];
- int c, i, l;
- int EnhanceSecurityLoops = (bNotTest)? 20 : 1;
+ uint32 c;
+ int i;
+
+ if (bNotTest)
+ {
+ if (iterations == 32767)
+ c = 655331;
+ else
+ c = 327661;
+ }
+ else
+ {
+ c = iterations;
+ }
/* iteration 1 */
memset (counter, 0, 4);
@@ -259,34 +271,17 @@ void derive_u_ripemd160 (BOOL bNotTest, char *pwd, int pwd_len, char *salt, int
memcpy (u, j, RIPEMD160_DIGESTSIZE);
/* remaining iterations */
- for (l = 0; l < EnhanceSecurityLoops; l++)
+ while ( c > 1)
{
- for (c = 1; c < iterations; c++)
+ hmac_ripemd160 (pwd, pwd_len, j, RIPEMD160_DIGESTSIZE, k);
+ for (i = 0; i < RIPEMD160_DIGESTSIZE; i++)
{
- hmac_ripemd160 (pwd, pwd_len, j, RIPEMD160_DIGESTSIZE, k);
- for (i = 0; i < RIPEMD160_DIGESTSIZE; i++)
- {
- u[i] ^= k[i];
- j[i] = k[i];
- }
+ u[i] ^= k[i];
+ j[i] = k[i];
}
+ c--;
}
- /* add extra 10 loops to ensure backward compatibilty with the previous count (327661 for boot, 655331 for normal) */
- if (iterations == 32767)
- {
- /* case of normal partition : add 10 iterations to have a total of 655331 = (32767 - 1)*20 + 1 + 10 */
- for (c = 0; c < 10; c++)
- {
- hmac_ripemd160 (pwd, pwd_len, j, RIPEMD160_DIGESTSIZE, k);
- for (i = 0; i < RIPEMD160_DIGESTSIZE; i++)
- {
- u[i] ^= k[i];
- j[i] = k[i];
- }
- }
- }
-
/* Prevent possible leaks. */
burn (j, sizeof(j));
burn (k, sizeof(k));