VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Crypto.c
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/Crypto.c
parent460f552a4173f8d798f52c2ad82c06a240094b17 (diff)
downloadVeraCrypt-0b2c8b09c6eb3ddce22fa88c34a640881f8f2177.tar.gz
VeraCrypt-0b2c8b09c6eb3ddce22fa88c34a640881f8f2177.zip
Windows: Add Magma cipher (GOST-89)
Diffstat (limited to 'src/Common/Crypto.c')
-rw-r--r--src/Common/Crypto.c36
1 files changed, 35 insertions, 1 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