VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Crypto
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2014-09-27 16:04:07 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2014-11-08 23:23:37 +0100
commit0178a6d33ff6afc7d0305619d3d250235ae55d09 (patch)
tree5c0cdc28b7ff07b02de5f05f70f16a46416f97b6 /src/Crypto
parent411e8599f39a601b26429b3d1183488c413eb21b (diff)
downloadVeraCrypt-0178a6d33ff6afc7d0305619d3d250235ae55d09.tar.gz
VeraCrypt-0178a6d33ff6afc7d0305619d3d250235ae55d09.zip
Optimize code space and solve the Serpent issue (https://sourceforge.net/p/veracrypt/discussion/technical/thread/fb09633a/#6406) by removing key length parameter from serpent_set_key and twofish_set_key
Diffstat (limited to 'src/Crypto')
-rw-r--r--src/Crypto/Serpent.c14
-rw-r--r--src/Crypto/Serpent.h3
-rw-r--r--src/Crypto/Twofish.c4
-rw-r--r--src/Crypto/Twofish.h3
4 files changed, 10 insertions, 14 deletions
diff --git a/src/Crypto/Serpent.c b/src/Crypto/Serpent.c
index ac77b397..91a4eadf 100644
--- a/src/Crypto/Serpent.c
+++ b/src/Crypto/Serpent.c
@@ -630,19 +630,16 @@ static void KXf (const unsigned __int32 *k, unsigned int r, unsigned __int32 *a,
#ifndef TC_MINIMIZE_CODE_SIZE
-void serpent_set_key(const unsigned __int8 userKey[], int keylen, unsigned __int8 *ks)
+void serpent_set_key(const unsigned __int8 userKey[],unsigned __int8 *ks)
{
unsigned __int32 a,b,c,d,e;
unsigned __int32 *k = (unsigned __int32 *)ks;
unsigned __int32 t;
int i;
- for (i = 0; i < keylen / (int)sizeof(__int32); i++)
+ for (i = 0; i < 8; i++)
k[i] = LE32(((unsigned __int32*)userKey)[i]);
- if (keylen < 32)
- k[keylen/4] |= (unsigned __int32)1 << ((keylen%4)*8);
-
k += 8;
t = k[-1];
for (i = 0; i < 132; ++i)
@@ -694,19 +691,16 @@ static void SKf (unsigned __int32 *k, unsigned int r, unsigned __int32 *a, unsig
k[r + 7] = *d;
}
-void serpent_set_key(const unsigned __int8 userKey[], int keylen, unsigned __int8 *ks)
+void serpent_set_key(const unsigned __int8 userKey[], unsigned __int8 *ks)
{
unsigned __int32 a,b,c,d,e;
unsigned __int32 *k = (unsigned __int32 *)ks;
unsigned __int32 t;
int i;
- for (i = 0; i < keylen / (int)sizeof(__int32); i++)
+ for (i = 0; i < 8; i++)
k[i] = LE32(((unsigned __int32*)userKey)[i]);
- if (keylen < 32)
- k[keylen/4] |= (unsigned __int32)1 << ((keylen%4)*8);
-
k += 8;
t = k[-1];
for (i = 0; i < 132; ++i)
diff --git a/src/Crypto/Serpent.h b/src/Crypto/Serpent.h
index 7c64d195..b88ddc4d 100644
--- a/src/Crypto/Serpent.h
+++ b/src/Crypto/Serpent.h
@@ -8,7 +8,8 @@ extern "C"
{
#endif
-void serpent_set_key(const unsigned __int8 userKey[], int keylen, unsigned __int8 *ks);
+/* userKey is always 32-bytes long */
+void serpent_set_key(const unsigned __int8 userKey[], unsigned __int8 *ks);
void serpent_encrypt(const unsigned __int8 *inBlock, unsigned __int8 *outBlock, unsigned __int8 *ks);
void serpent_decrypt(const unsigned __int8 *inBlock, unsigned __int8 *outBlock, unsigned __int8 *ks);
diff --git a/src/Crypto/Twofish.c b/src/Crypto/Twofish.c
index 7e438d1a..de5b1b66 100644
--- a/src/Crypto/Twofish.c
+++ b/src/Crypto/Twofish.c
@@ -369,7 +369,7 @@ static u4byte mds_rem(u4byte p0, u4byte p1)
/* initialise the key schedule from the user supplied key */
-u4byte *twofish_set_key(TwofishInstance *instance, const u4byte in_key[], const u4byte key_len)
+u4byte *twofish_set_key(TwofishInstance *instance, const u4byte in_key[])
{ u4byte i, a, b, me_key[4], mo_key[4];
u4byte *l_key, *s_key;
@@ -390,7 +390,7 @@ u4byte *twofish_set_key(TwofishInstance *instance, const u4byte in_key[], const
}
#endif
- instance->k_len = key_len / 64; /* 2, 3 or 4 */
+ instance->k_len = 4;
for(i = 0; i < instance->k_len; ++i)
{
diff --git a/src/Crypto/Twofish.h b/src/Crypto/Twofish.h
index b4d6cfc3..ed400257 100644
--- a/src/Crypto/Twofish.h
+++ b/src/Crypto/Twofish.h
@@ -44,7 +44,8 @@ typedef struct
#define TWOFISH_KS sizeof(TwofishInstance)
-u4byte * twofish_set_key(TwofishInstance *instance, const u4byte in_key[], const u4byte key_len);
+/* in_key must be 32-bytes long */
+u4byte * twofish_set_key(TwofishInstance *instance, const u4byte in_key[]);
void twofish_encrypt(TwofishInstance *instance, const u4byte in_blk[4], u4byte out_blk[]);
void twofish_decrypt(TwofishInstance *instance, const u4byte in_blk[4], u4byte out_blk[4]);