VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Tests.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2016-09-25 22:37:45 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2016-10-17 18:40:16 +0200
commitb65eabe23d5910a26d741439b1f5ea45ba4a0777 (patch)
treebd63c2de5b151657d294f1a56040fc4c6db4c893 /src/Common/Tests.c
parentd18ecc1a37b5f83d70b204f0bcb097fb8525314f (diff)
downloadVeraCrypt-b65eabe23d5910a26d741439b1f5ea45ba4a0777.tar.gz
VeraCrypt-b65eabe23d5910a26d741439b1f5ea45ba4a0777.zip
Add test vectors for Kuznyechik and GOST89 (the later is deprecated)
Diffstat (limited to 'src/Common/Tests.c')
-rw-r--r--src/Common/Tests.c178
1 files changed, 176 insertions, 2 deletions
diff --git a/src/Common/Tests.c b/src/Common/Tests.c
index bd159137..cf0c8699 100644
--- a/src/Common/Tests.c
+++ b/src/Common/Tests.c
@@ -376,6 +376,71 @@ CAMELLIA_TEST camellia_vectors[CAMELLIA_TEST_COUNT] = {
0xAD, 0x5C, 0x4D, 0x84
}
};
+#if defined(CIPHER_GOST89)
+// GOST89 ECB test vectors
+#define GOST89_TEST_COUNT 1
+
+typedef struct {
+ unsigned char key[32];
+ unsigned char plaintext[16];
+ unsigned char ciphertext[16];
+ } GOST89_TEST;
+
+GOST89_TEST gost89_vectors[GOST89_TEST_COUNT] = {
+{
+ 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
+}
+};
+#endif
+
+// Kuznyechik ECB test vectors
+#define KUZNYECHIK_TEST_COUNT 4
+
+typedef struct {
+ unsigned char key[32];
+ unsigned char plaintext[16];
+ unsigned char ciphertext[16];
+ } KUZNYECHIK_TEST;
+
+KUZNYECHIK_TEST kuznyechik_vectors[KUZNYECHIK_TEST_COUNT] = {
+{
+ 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33,
+ 0x44, 0x55, 0x66, 0x77, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
+ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x11, 0x22, 0x33, 0x44,
+ 0x55, 0x66, 0x77, 0x00, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88,
+ 0x7F, 0x67, 0x9D, 0x90, 0xBE, 0xBC, 0x24, 0x30, 0x5A, 0x46, 0x8D, 0x42,
+ 0xB9, 0xD4, 0xED, 0xCD
+},
+{
+ 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33,
+ 0x44, 0x55, 0x66, 0x77, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
+ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x00, 0x11, 0x22, 0x33,
+ 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xEE, 0xFF, 0x0A,
+ 0xB4, 0x29, 0x91, 0x2C, 0x6E, 0x00, 0x32, 0xF9, 0x28, 0x54, 0x52, 0xD7,
+ 0x67, 0x18, 0xD0, 0x8B
+},
+{
+ 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33,
+ 0x44, 0x55, 0x66, 0x77, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
+ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x11, 0x22, 0x33, 0x44,
+ 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xEE, 0xFF, 0x0A, 0x00,
+ 0xF0, 0xCA, 0x33, 0x54, 0x9D, 0x24, 0x7C, 0xEE, 0xF3, 0xF5, 0xA5, 0x31,
+ 0x3B, 0xD4, 0xB1, 0x57
+},
+{
+ 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33,
+ 0x44, 0x55, 0x66, 0x77, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
+ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x22, 0x33, 0x44, 0x55,
+ 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xEE, 0xFF, 0x0A, 0x00, 0x11,
+ 0xD0, 0xB0, 0x9C, 0xCD, 0xE8, 0x30, 0xB9, 0xEB, 0x3A, 0x02, 0xC4, 0xC5,
+ 0xAA, 0x8A, 0xDA, 0x98
+}
+};
/* Test vectors from FIPS 198a, RFC 4231, RFC 2104, RFC 2202, and other sources. */
@@ -781,6 +846,60 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
break;
}
}
+#if defined(CIPHER_GOST89)
+ else if (wcscmp (name, L"GOST89") == 0)
+ {
+ switch (testCase)
+ {
+ case 0:
+ if (crc != 0x12194ef5)
+ return FALSE;
+ nTestsPerformed++;
+ break;
+ case 1:
+ if (crc != 0xda8d429b)
+ return FALSE;
+ nTestsPerformed++;
+ break;
+ case 2:
+ if (crc != 0xdbf0b12e)
+ return FALSE;
+ nTestsPerformed++;
+ break;
+ case 3:
+ if (crc != 0xb986eb4a)
+ return FALSE;
+ nTestsPerformed++;
+ break;
+ }
+ }
+#endif
+ else if (wcscmp (name, L"Kuznyechik") == 0)
+ {
+ switch (testCase)
+ {
+ case 0:
+ if (crc != 0x6b86e72e)
+ return FALSE;
+ nTestsPerformed++;
+ break;
+ case 1:
+ if (crc != 0xa4f8637d)
+ return FALSE;
+ nTestsPerformed++;
+ break;
+ case 2:
+ if (crc != 0xfd83e76d)
+ return FALSE;
+ nTestsPerformed++;
+ break;
+ case 3:
+ if (crc != 0xb24fc47b)
+ return FALSE;
+ nTestsPerformed++;
+ break;
+ }
+ }
else if (wcscmp (name, L"AES-Twofish") == 0)
{
switch (testCase)
@@ -981,6 +1100,20 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
return FALSE;
nTestsPerformed++;
}
+#if defined(CIPHER_GOST89)
+ else if (wcscmp (name, L"GOST89") == 0)
+ {
+ if (crc != 0x9e8653cb)
+ return FALSE;
+ nTestsPerformed++;
+ }
+#endif
+ else if (wcscmp (name, L"Kuznyechik") == 0)
+ {
+ if (crc != 0xd6d39cdb)
+ return FALSE;
+ nTestsPerformed++;
+ }
else if (wcscmp (name, L"AES-Twofish") == 0)
{
if (crc != 0x14ce7385)
@@ -1023,9 +1156,9 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
nTestsPerformed++;
}
#if defined(CIPHER_GOST89)
- return (nTestsPerformed == 100);
+ return (nTestsPerformed == 110);
#else
- return (nTestsPerformed == 95);
+ return (nTestsPerformed == 105);
#endif
}
@@ -1149,6 +1282,47 @@ static BOOL DoAutoTestAlgorithms (void)
if (i != CAMELLIA_TEST_COUNT)
bFailed = TRUE;
+ /* Kuznyechik */
+
+ for (i = 0; i < KUZNYECHIK_TEST_COUNT; i++)
+ {
+ int cipher = KUZNYECHIK;
+ memcpy(key, kuznyechik_vectors[i].key, 32);
+ memcpy(tmp, kuznyechik_vectors[i].plaintext, 16);
+ CipherInit(cipher, key, ks_tmp);
+
+ EncipherBlock(cipher, tmp, ks_tmp);
+ if (memcmp(kuznyechik_vectors[i].ciphertext, tmp, 16) != 0)
+ break;
+
+ DecipherBlock(cipher, tmp, ks_tmp);
+ if (memcmp(kuznyechik_vectors[i].plaintext, tmp, 16) != 0)
+ break;
+ }
+ if (i != KUZNYECHIK_TEST_COUNT)
+ bFailed = TRUE;
+
+#if defined(CIPHER_GOST89)
+ /* GOST89 */
+
+ for (i = 0; i < GOST89_TEST_COUNT; i++)
+ {
+ int cipher = GOST89;
+ memcpy(key, gost89_vectors[i].key, 32);
+ memcpy(tmp, gost89_vectors[i].plaintext, 16);
+ gost_set_key(key, (gost_kds*)ks_tmp, 0);
+
+ EncipherBlock(cipher, tmp, ks_tmp);
+ if (memcmp(gost89_vectors[i].ciphertext, tmp, 16) != 0)
+ break;
+
+ DecipherBlock(cipher, tmp, ks_tmp);
+ if (memcmp(gost89_vectors[i].plaintext, tmp, 16) != 0)
+ break;
+ }
+ if (i != GOST89_TEST_COUNT)
+ bFailed = TRUE;
+#endif
/* PKCS #5 and HMACs */
if (!test_pkcs5 ())