VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2016-08-09 09:54:00 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2016-08-15 01:09:10 +0200
commit0b2c8b09c6eb3ddce22fa88c34a640881f8f2177 (patch)
tree9985d4c18308f1e052fea3a6a3a05b45df80cb55 /src/Common
parent460f552a4173f8d798f52c2ad82c06a240094b17 (diff)
downloadVeraCrypt-0b2c8b09c6eb3ddce22fa88c34a640881f8f2177.tar.gz
VeraCrypt-0b2c8b09c6eb3ddce22fa88c34a640881f8f2177.zip
Windows: Add Magma cipher (GOST-89)
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Crypto.c36
-rw-r--r--src/Common/Crypto.h8
-rw-r--r--src/Common/Tests.c13
3 files changed, 50 insertions, 7 deletions
diff --git a/src/Common/Crypto.c b/src/Common/Crypto.c
index dea4ff02..16115bf6 100644
--- a/src/Common/Crypto.c
+++ b/src/Common/Crypto.c
@@ -23,6 +23,7 @@
#include "Volumes.h"
#include "cpu.h"
+#pragma warning (disable:4706) // assignment within conditional expression
/* Update the following when adding a new cipher or EA:
Crypto.h:
@@ -54,6 +55,9 @@ static Cipher Ciphers[] =
{ SERPENT, L"Serpent", 16, 32, 140*4 },
{ TWOFISH, L"Twofish", 16, 32, TWOFISH_KS },
{ CAMELLIA, L"Camellia", 16, 32, CAMELLIA_KS },
+#if defined(CIPHER_GOST89)
+ { GOST89, L"GOST89", 16, 32, GOST_KS },
+#endif // defined(CIPHER_GOST89)
#endif
{ 0, 0, 0, 0, 0 }
};
@@ -71,6 +75,9 @@ static EncryptionAlgorithm EncryptionAlgorithms[] =
{ { SERPENT, 0 }, { XTS, 0 }, 1 },
{ { TWOFISH, 0 }, { XTS, 0 }, 1 },
{ { CAMELLIA, 0 }, { XTS, 0 }, 1 },
+#if defined(CIPHER_GOST89)
+ { { GOST89, 0 }, { XTS, 0 }, 1 },
+#endif // defined(CIPHER_GOST89)
{ { TWOFISH, AES, 0 }, { XTS, 0 }, 1 },
{ { SERPENT, TWOFISH, AES, 0 }, { XTS, 0 }, 1 },
{ { AES, SERPENT, 0 }, { XTS, 0 }, 1 },
@@ -143,6 +150,14 @@ int CipherInit (int cipher, unsigned char *key, unsigned __int8 *ks)
break;
#endif
+#if !defined(TC_WINDOWS_BOOT)
+#if defined(CIPHER_GOST89)
+ case GOST89:
+ gost_set_key(key, (gost_kds*)ks);
+ break;
+#endif // && defined(CIPHER_GOST89)
+#endif // !defined(TC_WINDOWS_BOOT)
+
default:
// Unknown/wrong cipher ID
return ERR_CIPHER_INIT_FAILURE;
@@ -170,6 +185,11 @@ void EncipherBlock(int cipher, void *data, void *ks)
#if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_CAMELLIA)
case CAMELLIA: camellia_encrypt (data, data, ks); break;
#endif
+#if !defined(TC_WINDOWS_BOOT)
+#if defined(CIPHER_GOST89)
+ case GOST89: gost_encrypt(data, data, ks, 1); break;
+#endif // defined(CIPHER_GOST89)
+#endif // !defined(TC_WINDOWS_BOOT)
default: TC_THROW_FATAL_EXCEPTION; // Unknown/wrong ID
}
}
@@ -203,6 +223,9 @@ void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount)
KeRestoreFloatingPointState (&floatingPointState);
#endif
}
+ else if (cipher == GOST89) {
+ gost_encrypt(data, data, ks, (int)blockCount);
+ }
else
{
size_t blockSize = CipherGetBlockSize (cipher);
@@ -225,6 +248,13 @@ void DecipherBlock(int cipher, void *data, void *ks)
#if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_CAMELLIA)
case CAMELLIA: camellia_decrypt (data, data, ks); break;
#endif
+#if !defined(TC_WINDOWS_BOOT)
+#if defined(CIPHER_GOST89)
+ case GOST89: gost_decrypt(data, data, ks, 1); break;
+#endif // defined(CIPHER_GOST89)
+#endif // !defined(TC_WINDOWS_BOOT)
+
+
#ifndef TC_WINDOWS_BOOT
case AES:
@@ -272,6 +302,9 @@ void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount)
KeRestoreFloatingPointState (&floatingPointState);
#endif
}
+ else if (cipher == GOST89) {
+ gost_decrypt(data, data, ks, (int)blockCount);
+ }
else
{
size_t blockSize = CipherGetBlockSize (cipher);
@@ -340,7 +373,8 @@ int CipherGetKeyScheduleSize (int cipherId)
BOOL CipherSupportsIntraDataUnitParallelization (int cipher)
{
- return cipher == AES && IsAesHwCpuSupported();
+ return cipher == AES && IsAesHwCpuSupported() ||
+ cipher == GOST89;
}
#endif
diff --git a/src/Common/Crypto.h b/src/Common/Crypto.h
index 28b5f8c4..9b5fbace 100644
--- a/src/Common/Crypto.h
+++ b/src/Common/Crypto.h
@@ -107,7 +107,8 @@ enum
AES,
SERPENT,
TWOFISH,
- CAMELLIA
+ CAMELLIA,
+ GOST89
};
typedef struct
@@ -189,9 +190,10 @@ typedef struct
#ifndef TC_WINDOWS_BOOT
# include "Sha2.h"
# include "Whirlpool.h"
-# include "Camellia.h"
+# include "GostCipher.h"
+# include "Camellia.h"
#else
-# include "CamelliaSmall.h"
+# include "CamelliaSmall.h"
#endif
#include "GfMul.h"
diff --git a/src/Common/Tests.c b/src/Common/Tests.c
index 81ba4161..02f893c7 100644
--- a/src/Common/Tests.c
+++ b/src/Common/Tests.c
@@ -497,7 +497,11 @@ void CipherInit2(int cipher, void* key, void* ks, int key_len)
case CAMELLIA:
CipherInit(cipher,key,ks);
break;
-
+#if defined(CIPHER_GOST89)
+ case GOST89:
+ CipherInit(cipher,key,ks);
+ break;
+#endif // defined(CIPHER_GOST89)
default:
/* Unknown/wrong ID */
TC_THROW_FATAL_EXCEPTION;
@@ -925,8 +929,11 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
nTestsPerformed++;
}
-
- return (nTestsPerformed == 90);
+#if defined(CIPHER_GOST89)
+ return (nTestsPerformed == 100);
+#else
+ return (nTestsPerformed == 95);
+#endif
}
static BOOL DoAutoTestAlgorithms (void)