VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Volume/EncryptionTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Volume/EncryptionTest.cpp')
-rw-r--r--src/Volume/EncryptionTest.cpp127
1 files changed, 61 insertions, 66 deletions
diff --git a/src/Volume/EncryptionTest.cpp b/src/Volume/EncryptionTest.cpp
index 22aea220..c900885e 100644
--- a/src/Volume/EncryptionTest.cpp
+++ b/src/Volume/EncryptionTest.cpp
@@ -16,6 +16,9 @@
#include "EncryptionAlgorithm.h"
#include "EncryptionMode.h"
#include "EncryptionModeXTS.h"
+#ifdef WOLFCRYPT_BACKEND
+#include "EncryptionModeWolfCryptXTS.h"
+#endif
#include "EncryptionTest.h"
#include "Pkcs5Kdf.h"
@@ -64,6 +67,7 @@ namespace VeraCrypt
}
};
+ #ifndef WOLFCRYPT_BACKEND
static const CipherTestVector SerpentTestVectors[] =
{
{
@@ -123,23 +127,7 @@ namespace VeraCrypt
}
}
};
-
- static const CipherTestVector GOST89TestVectors[] =
- {
- {
- {
- 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00,
- 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
- },
- {
- 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88
- },
- {
- 0x8F, 0xC6, 0xFE, 0xB8, 0x91, 0x51, 0x4C, 0x37, 0x4D, 0x51, 0x46, 0xEF, 0x02, 0x9D, 0xBD, 0x9F
- }
- }
- };
-
+
static const CipherTestVector KuznyechikTestVectors[] =
{
{
@@ -167,6 +155,7 @@ namespace VeraCrypt
}
}
};
+ #endif
static void TestCipher (Cipher &cipher, const CipherTestVector *testVector, size_t testVectorCount)
{
@@ -206,6 +195,7 @@ namespace VeraCrypt
if (origCrc != Crc32::ProcessBuffer (testData))
throw TestFailed (SRC_POS);
+ #ifndef WOLFCRYPT_BACKEND
CipherSerpent serpent;
TestCipher (serpent, SerpentTestVectors, array_capacity (SerpentTestVectors));
@@ -215,11 +205,9 @@ namespace VeraCrypt
CipherCamellia camellia;
TestCipher (camellia, CamelliaTestVectors, array_capacity (CamelliaTestVectors));
- CipherGost89StaticSBOX gost89;
- TestCipher (gost89, GOST89TestVectors, array_capacity (GOST89TestVectors));
-
CipherKuznyechik kuznyechik;
TestCipher (kuznyechik, KuznyechikTestVectors, array_capacity (KuznyechikTestVectors));
+ #endif
}
const EncryptionTest::XtsTestVector EncryptionTest::XtsTestVectors[] =
@@ -456,9 +444,16 @@ namespace VeraCrypt
for (i = 0; i < array_capacity (XtsTestVectors); i++)
{
AES aes;
- shared_ptr <EncryptionMode> xts (new EncryptionModeXTS);
-
- aes.SetKey (ConstBufferPtr (XtsTestVectors[i].key1, sizeof (XtsTestVectors[i].key1)));
+ #ifdef WOLFCRYPT_BACKEND
+ shared_ptr <EncryptionMode> xts (new EncryptionModeWolfCryptXTS);
+ #else
+ shared_ptr <EncryptionMode> xts (new EncryptionModeXTS);
+ #endif
+
+ aes.SetKey (ConstBufferPtr (XtsTestVectors[i].key1, sizeof (XtsTestVectors[i].key1)));
+ #ifdef WOLFCRYPT_BACKEND
+ aes.SetKeyXTS (ConstBufferPtr (XtsTestVectors[i].key2, sizeof (XtsTestVectors[i].key2)));
+ #endif
xts->SetKey (ConstBufferPtr (XtsTestVectors[i].key2, sizeof (XtsTestVectors[i].key2)));
aes.SetMode (xts);
@@ -513,7 +508,11 @@ namespace VeraCrypt
// Test all EAs that support this mode of operation
foreach_ref (EncryptionAlgorithm &ea, EncryptionAlgorithm::GetAvailableAlgorithms())
{
- shared_ptr <EncryptionMode> mode (new EncryptionModeXTS);
+ #ifdef WOLFCRYPT_BACKEND
+ shared_ptr <EncryptionMode> mode (new EncryptionModeWolfCryptXTS);
+ #else
+ shared_ptr <EncryptionMode> mode (new EncryptionModeXTS);
+ #endif
if (!ea.IsModeSupported (mode))
continue;
@@ -527,8 +526,11 @@ namespace VeraCrypt
mode->SetKey (modeKey);
ea.SetMode (mode);
+ #ifdef WOLFCRYPT_BACKEND
+ ea.SetKeyXTS (modeKey);
+ #endif
- // Each data unit will contain the same plaintext
+ // Each data unit will contain the same plaintext
for (i = 0; i < nbrUnits; i++)
{
memcpy ((unsigned char *) buf + i * ENCRYPTION_DATA_UNIT_SIZE,
@@ -575,6 +577,7 @@ namespace VeraCrypt
break;
}
}
+ #ifndef WOLFCRYPT_BACKEND
else if (typeid (ea) == typeid (Serpent))
{
switch (testCase)
@@ -653,32 +656,6 @@ namespace VeraCrypt
break;
}
}
- else if (typeid (ea) == typeid (GOST89))
- {
- switch (testCase)
- {
- case 0:
- if (crc != 0x12194ef5)
- throw TestFailed (SRC_POS);
- nTestsPerformed++;
- break;
- case 1:
- if (crc != 0xda8d429b)
- throw TestFailed (SRC_POS);
- nTestsPerformed++;
- break;
- case 2:
- if (crc != 0xdbf0b12e)
- throw TestFailed (SRC_POS);
- nTestsPerformed++;
- break;
- case 3:
- if (crc != 0xb986eb4a)
- throw TestFailed (SRC_POS);
- nTestsPerformed++;
- break;
- }
- }
else if (typeid (ea) == typeid (Kuznyechik))
{
switch (testCase)
@@ -965,7 +942,7 @@ namespace VeraCrypt
break;
}
}
-
+ #endif
if (crc == 0x9f5edd58)
throw TestFailed (SRC_POS);
@@ -986,7 +963,11 @@ namespace VeraCrypt
// Test all EAs that support this mode of operation
foreach_ref (EncryptionAlgorithm &ea, EncryptionAlgorithm::GetAvailableAlgorithms())
{
+ #ifdef WOLFCRYPT_BACKEND
+ shared_ptr <EncryptionMode> mode (new EncryptionModeWolfCryptXTS);
+ #else
shared_ptr <EncryptionMode> mode (new EncryptionModeXTS);
+ #endif
if (!ea.IsModeSupported (mode))
continue;
@@ -1000,6 +981,9 @@ namespace VeraCrypt
mode->SetKey (modeKey);
ea.SetMode (mode);
+ #ifdef WOLFCRYPT_BACKEND
+ ea.SetKeyXTS (modeKey);
+ #endif
// Each data unit will contain the same plaintext
for (i = 0; i < nbrUnits; i++)
@@ -1019,6 +1003,7 @@ namespace VeraCrypt
throw TestFailed (SRC_POS);
nTestsPerformed++;
}
+ #ifndef WOLFCRYPT_BACKEND
else if (typeid (ea) == typeid (Serpent))
{
if (crc != 0x3494d480)
@@ -1037,12 +1022,6 @@ namespace VeraCrypt
throw TestFailed (SRC_POS);
nTestsPerformed++;
}
- else if (typeid (ea) == typeid (GOST89))
- {
- if (crc != 0x9e8653cb)
- throw TestFailed (SRC_POS);
- nTestsPerformed++;
- }
else if (typeid (ea) == typeid (Kuznyechik))
{
if (crc != 0xd6d39cdb)
@@ -1109,6 +1088,7 @@ namespace VeraCrypt
throw TestFailed (SRC_POS);
nTestsPerformed++;
}
+ #endif
if (crc == 0x9f5edd58)
throw TestFailed (SRC_POS);
@@ -1120,8 +1100,11 @@ namespace VeraCrypt
nTestsPerformed++;
}
-
- if (nTestsPerformed != 160)
+ #ifndef WOLFCRYPT_BACKEND
+ if (nTestsPerformed != 150)
+ #else
+ if (nTestsPerformed != 10)
+ #endif
throw TestFailed (SRC_POS);
}
@@ -1132,17 +1115,18 @@ namespace VeraCrypt
ConstBufferPtr salt (saltData, sizeof (saltData));
Buffer derivedKey (4);
- Pkcs5HmacRipemd160 pkcs5HmacRipemd160(false);
- pkcs5HmacRipemd160.DeriveKey (derivedKey, password, salt, 5);
- if (memcmp (derivedKey.Ptr(), "\x7a\x3d\x7c\x03", 4) != 0)
+ #ifndef WOLFCRYPT_BACKEND
+ Pkcs5HmacBlake2s pkcs5HmacBlake2s;
+ pkcs5HmacBlake2s.DeriveKey (derivedKey, password, salt, 5);
+ if (memcmp (derivedKey.Ptr(), "\x8d\x51\xfa\x31", 4) != 0)
throw TestFailed (SRC_POS);
- Pkcs5HmacSha512 pkcs5HmacSha512(false);
+ Pkcs5HmacSha512 pkcs5HmacSha512;
pkcs5HmacSha512.DeriveKey (derivedKey, password, salt, 5);
if (memcmp (derivedKey.Ptr(), "\x13\x64\xae\xf8", 4) != 0)
throw TestFailed (SRC_POS);
- Pkcs5HmacWhirlpool pkcs5HmacWhirlpool(false);
+ Pkcs5HmacWhirlpool pkcs5HmacWhirlpool;
pkcs5HmacWhirlpool.DeriveKey (derivedKey, password, salt, 5);
if (memcmp (derivedKey.Ptr(), "\x50\x7c\x36\x6f", 4) != 0)
throw TestFailed (SRC_POS);
@@ -1156,5 +1140,16 @@ namespace VeraCrypt
pkcs5HmacStreebog.DeriveKey (derivedKey, password, salt, 5);
if (memcmp (derivedKey.Ptr(), "\xd0\x53\xa2\x30", 4) != 0)
throw TestFailed (SRC_POS);
- }
+ #else
+ Pkcs5HmacSha256 pkcs5HmacSha256;
+ pkcs5HmacSha256.DeriveKey (derivedKey, password, salt, 5);
+ if (memcmp (derivedKey.Ptr(), "\x64\xf3\xa5\xa3", 4) != 0)
+ throw TestFailed (SRC_POS);
+
+ Pkcs5HmacSha512 pkcs5HmacSha512;
+ pkcs5HmacSha512.DeriveKey (derivedKey, password, salt, 5);
+ if (memcmp (derivedKey.Ptr(), "\x55\xa1\x76\xbb", 4) != 0)
+ throw TestFailed (SRC_POS);
+ #endif
+ }
}