VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/Tests.c')
-rw-r--r--src/Common/Tests.c646
1 files changed, 1 insertions, 645 deletions
diff --git a/src/Common/Tests.c b/src/Common/Tests.c
index dd4f1621..226b3e09 100644
--- a/src/Common/Tests.c
+++ b/src/Common/Tests.c
@@ -290,91 +290,6 @@ BOOL XTSAesTest (PCRYPTO_INFO ci)
290 return TRUE; 290 return TRUE;
291} 291}
292 292
293/* Blowfish Test Vectors (deprecated/legacy) */
294
295/* Blowfish test vectors from www.counterpane.com/blowfish.html */
296
297#define BF_TEST_COUNT 34
298
299typedef struct {
300 unsigned char key[8];
301 unsigned char plaintext[8];
302 unsigned char ciphertext[8];
303 } BF_TEST;
304
305#pragma warning(disable:4295)
306
307BF_TEST bf_ecb_vectors[BF_TEST_COUNT] = {
308"\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00","\x4E\xF9\x97\x45\x61\x98\xDD\x78",
309"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF","\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF","\x51\x86\x6F\xD5\xB8\x5E\xCB\x8A",
310"\x30\x00\x00\x00\x00\x00\x00\x00","\x10\x00\x00\x00\x00\x00\x00\x01","\x7D\x85\x6F\x9A\x61\x30\x63\xF2",
311"\x11\x11\x11\x11\x11\x11\x11\x11","\x11\x11\x11\x11\x11\x11\x11\x11","\x24\x66\xDD\x87\x8B\x96\x3C\x9D",
312"\x01\x23\x45\x67\x89\xAB\xCD\xEF","\x11\x11\x11\x11\x11\x11\x11\x11","\x61\xF9\xC3\x80\x22\x81\xB0\x96",
313"\x11\x11\x11\x11\x11\x11\x11\x11","\x01\x23\x45\x67\x89\xAB\xCD\xEF","\x7D\x0C\xC6\x30\xAF\xDA\x1E\xC7",
314"\x00\x00\x00\x00\x00\x00\x00\x00","\x00\x00\x00\x00\x00\x00\x00\x00","\x4E\xF9\x97\x45\x61\x98\xDD\x78",
315"\xFE\xDC\xBA\x98\x76\x54\x32\x10","\x01\x23\x45\x67\x89\xAB\xCD\xEF","\x0A\xCE\xAB\x0F\xC6\xA0\xA2\x8D",
316"\x7C\xA1\x10\x45\x4A\x1A\x6E\x57","\x01\xA1\xD6\xD0\x39\x77\x67\x42","\x59\xC6\x82\x45\xEB\x05\x28\x2B",
317"\x01\x31\xD9\x61\x9D\xC1\x37\x6E","\x5C\xD5\x4C\xA8\x3D\xEF\x57\xDA","\xB1\xB8\xCC\x0B\x25\x0F\x09\xA0",
318"\x07\xA1\x13\x3E\x4A\x0B\x26\x86","\x02\x48\xD4\x38\x06\xF6\x71\x72","\x17\x30\xE5\x77\x8B\xEA\x1D\xA4",
319"\x38\x49\x67\x4C\x26\x02\x31\x9E","\x51\x45\x4B\x58\x2D\xDF\x44\x0A","\xA2\x5E\x78\x56\xCF\x26\x51\xEB",
320"\x04\xB9\x15\xBA\x43\xFE\xB5\xB6","\x42\xFD\x44\x30\x59\x57\x7F\xA2","\x35\x38\x82\xB1\x09\xCE\x8F\x1A",
321"\x01\x13\xB9\x70\xFD\x34\xF2\xCE","\x05\x9B\x5E\x08\x51\xCF\x14\x3A","\x48\xF4\xD0\x88\x4C\x37\x99\x18",
322"\x01\x70\xF1\x75\x46\x8F\xB5\xE6","\x07\x56\xD8\xE0\x77\x47\x61\xD2","\x43\x21\x93\xB7\x89\x51\xFC\x98",
323"\x43\x29\x7F\xAD\x38\xE3\x73\xFE","\x76\x25\x14\xB8\x29\xBF\x48\x6A","\x13\xF0\x41\x54\xD6\x9D\x1A\xE5",
324"\x07\xA7\x13\x70\x45\xDA\x2A\x16","\x3B\xDD\x11\x90\x49\x37\x28\x02","\x2E\xED\xDA\x93\xFF\xD3\x9C\x79",
325"\x04\x68\x91\x04\xC2\xFD\x3B\x2F","\x26\x95\x5F\x68\x35\xAF\x60\x9A","\xD8\x87\xE0\x39\x3C\x2D\xA6\xE3",
326"\x37\xD0\x6B\xB5\x16\xCB\x75\x46","\x16\x4D\x5E\x40\x4F\x27\x52\x32","\x5F\x99\xD0\x4F\x5B\x16\x39\x69",
327"\x1F\x08\x26\x0D\x1A\xC2\x46\x5E","\x6B\x05\x6E\x18\x75\x9F\x5C\xCA","\x4A\x05\x7A\x3B\x24\xD3\x97\x7B",
328"\x58\x40\x23\x64\x1A\xBA\x61\x76","\x00\x4B\xD6\xEF\x09\x17\x60\x62","\x45\x20\x31\xC1\xE4\xFA\xDA\x8E",
329"\x02\x58\x16\x16\x46\x29\xB0\x07","\x48\x0D\x39\x00\x6E\xE7\x62\xF2","\x75\x55\xAE\x39\xF5\x9B\x87\xBD",
330"\x49\x79\x3E\xBC\x79\xB3\x25\x8F","\x43\x75\x40\xC8\x69\x8F\x3C\xFA","\x53\xC5\x5F\x9C\xB4\x9F\xC0\x19",
331"\x4F\xB0\x5E\x15\x15\xAB\x73\xA7","\x07\x2D\x43\xA0\x77\x07\x52\x92","\x7A\x8E\x7B\xFA\x93\x7E\x89\xA3",
332"\x49\xE9\x5D\x6D\x4C\xA2\x29\xBF","\x02\xFE\x55\x77\x81\x17\xF1\x2A","\xCF\x9C\x5D\x7A\x49\x86\xAD\xB5",
333"\x01\x83\x10\xDC\x40\x9B\x26\xD6","\x1D\x9D\x5C\x50\x18\xF7\x28\xC2","\xD1\xAB\xB2\x90\x65\x8B\xC7\x78",
334"\x1C\x58\x7F\x1C\x13\x92\x4F\xEF","\x30\x55\x32\x28\x6D\x6F\x29\x5A","\x55\xCB\x37\x74\xD1\x3E\xF2\x01",
335"\x01\x01\x01\x01\x01\x01\x01\x01","\x01\x23\x45\x67\x89\xAB\xCD\xEF","\xFA\x34\xEC\x48\x47\xB2\x68\xB2",
336"\x1F\x1F\x1F\x1F\x0E\x0E\x0E\x0E","\x01\x23\x45\x67\x89\xAB\xCD\xEF","\xA7\x90\x79\x51\x08\xEA\x3C\xAE",
337"\xE0\xFE\xE0\xFE\xF1\xFE\xF1\xFE","\x01\x23\x45\x67\x89\xAB\xCD\xEF","\xC3\x9E\x07\x2D\x9F\xAC\x63\x1D",
338"\x00\x00\x00\x00\x00\x00\x00\x00","\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF","\x01\x49\x33\xE0\xCD\xAF\xF6\xE4",
339"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF","\x00\x00\x00\x00\x00\x00\x00\x00","\xF2\x1E\x9A\x77\xB7\x1C\x49\xBC",
340"\x01\x23\x45\x67\x89\xAB\xCD\xEF","\x00\x00\x00\x00\x00\x00\x00\x00","\x24\x59\x46\x88\x57\x54\x36\x9A",
341"\xFE\xDC\xBA\x98\x76\x54\x32\x10","\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF","\x6B\x5C\x5A\x9C\x5D\x9E\x0A\x5A"
342};
343
344
345#define TRIPLEDES_TEST_COUNT 1
346
347typedef struct {
348 unsigned char key[24];
349 unsigned char plaintext[8];
350 unsigned char ciphertext[8];
351 } TRIPLEDES_TEST;
352
353TRIPLEDES_TEST tripledes_vectors[TRIPLEDES_TEST_COUNT] = {
3540x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98,
3550x76, 0x54, 0x32, 0x10, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67,
356
3570x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7,
358
3590xde, 0x0b, 0x7c, 0x06, 0xae, 0x5e, 0x0e, 0xd5
360};
361
362/* CAST-128 Test Vectors from RFC2144 (deprecated/legacy) */
363
364#define CAST_TEST_COUNT 1
365
366typedef struct {
367 unsigned char key[16];
368 unsigned char plaintext[8];
369 unsigned char ciphertext[8];
370 } CAST_TEST;
371
372
373CAST_TEST cast_ecb_vectors[CAST_TEST_COUNT] = {
374 "\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A",
375 "\x01\x23\x45\x67\x89\xAB\xCD\xEF",
376 "\x23\x8B\x4F\xE5\x84\x7E\x44\xB2"
377 };
378 293
379// AES ECB test vectors FIPS-197 294// AES ECB test vectors FIPS-197
380 295
@@ -463,35 +378,6 @@ char *hmac_sha512_test_vectors[] =
463 "\xe3\x7b\x6a\x77\x5d\xc8\x7d\xba\xa4\xdf\xa9\xf9\x6e\x5e\x3f\xfd\xde\xbd\x71\xf8\x86\x72\x89\x86\x5d\xf5\xa3\x2d\x20\xcd\xc9\x44\xb6\x02\x2c\xac\x3c\x49\x82\xb1\x0d\x5e\xeb\x55\xc3\xe4\xde\x15\x13\x46\x76\xfb\x6d\xe0\x44\x60\x65\xc9\x74\x40\xfa\x8c\x6a\x58", 378 "\xe3\x7b\x6a\x77\x5d\xc8\x7d\xba\xa4\xdf\xa9\xf9\x6e\x5e\x3f\xfd\xde\xbd\x71\xf8\x86\x72\x89\x86\x5d\xf5\xa3\x2d\x20\xcd\xc9\x44\xb6\x02\x2c\xac\x3c\x49\x82\xb1\x0d\x5e\xeb\x55\xc3\xe4\xde\x15\x13\x46\x76\xfb\x6d\xe0\x44\x60\x65\xc9\x74\x40\xfa\x8c\x6a\x58",
464}; 379};
465 380
466char *hmac_sha1_test_keys[] =
467{
468 // Deprecated/legacy
469 "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3",
470 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
471 "Jefe",
472 "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
473};
474
475char *hmac_sha1_test_data[] =
476{
477 // Deprecated/legacy
478 "Sample #3",
479 "Hi There",
480 "what do ya want for nothing?",
481 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
482 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
483 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
484};
485
486char *hmac_sha1_test_vectors[] =
487{
488 // Deprecated/legacy
489 "\xbc\xf4\x1e\xab\x8b\xb2\xd8\x02\xf3\xd0\x5c\xaf\x7c\xb0\x92\xec\xf8\xd1\xa3\xaa",
490 "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00",
491 "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79",
492 "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3"
493};
494
495char *hmac_ripemd160_test_keys[] = 381char *hmac_ripemd160_test_keys[] =
496{ 382{
497 "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x01\x23\x45\x67", 383 "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x01\x23\x45\x67",
@@ -534,29 +420,15 @@ void CipherInit2(int cipher, void* key, void* ks, int key_len)
534{ 420{
535 switch (cipher) 421 switch (cipher)
536 { 422 {
537 case BLOWFISH:
538 /* Deprecated/legacy */
539 BlowfishSetKey (ks, key_len, key);
540 break;
541 423
542 case AES: 424 case AES:
543 CipherInit(cipher,key,ks); 425 CipherInit(cipher,key,ks);
544 break; 426 break;
545 427
546 case CAST:
547 /* Deprecated/legacy */
548 CipherInit(cipher,key,ks);
549 break;
550
551 case SERPENT: 428 case SERPENT:
552 CipherInit(cipher,key,ks); 429 CipherInit(cipher,key,ks);
553 break; 430 break;
554 431
555 case TRIPLEDES:
556 /* Deprecated/legacy */
557 CipherInit(cipher,key,ks);
558 break;
559
560 case TWOFISH: 432 case TWOFISH:
561 CipherInit(cipher,key,ks); 433 CipherInit(cipher,key,ks);
562 break; 434 break;
@@ -568,72 +440,6 @@ void CipherInit2(int cipher, void* key, void* ks, int key_len)
568} 440}
569 441
570 442
571/* Deprecated/legacy */
572typedef struct {
573 unsigned __int8 key1[32];
574 unsigned __int8 key2[16];
575 unsigned __int8 index[16];
576 unsigned __int8 plaintext[16];
577 unsigned __int8 ciphertext[16];
578} LRW_TEST;
579
580#define LRW_TEST_COUNT 2
581
582/* Deprecated/legacy */
583LRW_TEST lrw_vectors[LRW_TEST_COUNT] = {
584 {
585 { 0xf8, 0xd4, 0x76, 0xff, 0xd6, 0x46, 0xee, 0x6c, 0x23, 0x84, 0xcb, 0x1c, 0x77, 0xd6, 0x19, 0x5d,
586 0xfe, 0xf1, 0xa9, 0xf3, 0x7b, 0xbc, 0x8d, 0x21, 0xa7, 0x9c, 0x21, 0xf8, 0xcb, 0x90, 0x02, 0x89 },
587 { 0xa8, 0x45, 0x34, 0x8e, 0xc8, 0xc5, 0xb5, 0xf1, 0x26, 0xf5, 0x0e, 0x76, 0xfe, 0xfd, 0x1b, 0x1e },
588 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
589 { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 },
590 { 0xbd, 0x06, 0xb8, 0xe1, 0xdb, 0x98, 0x89, 0x9e, 0xc4, 0x98, 0xe4, 0x91, 0xcf, 0x1c, 0x70, 0x2b }
591 },
592 {
593 { 0xfb, 0x76, 0x15, 0xb2, 0x3d, 0x80, 0x89, 0x1d, 0xd4, 0x70, 0x98, 0x0b, 0xc7, 0x95, 0x84, 0xc8,
594 0xb2, 0xfb, 0x64, 0xce, 0x60, 0x97, 0x87, 0x8d, 0x17, 0xfc, 0xe4, 0x5a, 0x49, 0xe8, 0x30, 0xb7 },
595 { 0x6e, 0x78, 0x17, 0xe7, 0x2d, 0x5e, 0x12, 0xd4, 0x60, 0x64, 0x04, 0x7a, 0xf1, 0x2f, 0x9e, 0x0c },
596 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 },
597 { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 },
598 { 0x5b, 0x90, 0x8e, 0xc1, 0xab, 0xdd, 0x67, 0x5f, 0x3d, 0x69, 0x8a, 0x95, 0x53, 0xc8, 0x9c, 0xe5 }
599 }
600};
601
602
603BOOL LRWAesTest (PCRYPTO_INFO ci)
604{
605 /* Deprecated/legacy */
606
607 unsigned __int8 p[16];
608 int i;
609
610 for (i = 0; i < LRW_TEST_COUNT; i++)
611 {
612 ci->ea = EAGetByName ("AES");
613 if (ci->ea == 0)
614 return FALSE;
615
616 ci->mode = LRW;
617
618 if (EAInit (ci->ea, lrw_vectors[i].key1, ci->ks) != ERR_SUCCESS)
619 return FALSE;
620
621 memcpy (&ci->k2, lrw_vectors[i].key2, sizeof (lrw_vectors[i].key2));
622 if (!EAInitMode (ci))
623 return FALSE;
624
625 memcpy (p, lrw_vectors[i].plaintext, sizeof (p));
626
627 EncryptBufferLRW128 (p, sizeof (p), BE64(((unsigned __int64 *)(lrw_vectors[i].index))[1]), ci);
628
629 if (memcmp (lrw_vectors[i].ciphertext, p, sizeof (p)) != 0)
630 return FALSE;
631 }
632
633 return TRUE;
634}
635
636
637BOOL TestSectorBufEncryption (PCRYPTO_INFO ci) 443BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
638{ 444{
639 unsigned char buf [ENCRYPTION_DATA_UNIT_SIZE * 4]; 445 unsigned char buf [ENCRYPTION_DATA_UNIT_SIZE * 4];
@@ -653,15 +459,12 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
653 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 459 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13
654 }; 460 };
655 461
656 if (!TestLegacySectorBufEncryption (ci))
657 return FALSE;
658
659 462
660 /* Encryption/decryption of data units (typically, volume data sectors) */ 463 /* Encryption/decryption of data units (typically, volume data sectors) */
661 464
662 nbrUnits = sizeof (buf) / ENCRYPTION_DATA_UNIT_SIZE; 465 nbrUnits = sizeof (buf) / ENCRYPTION_DATA_UNIT_SIZE;
663 466
664 ci->mode = XTS; // Other modes of operation are tested in TestLegacySectorBufEncryption() 467 ci->mode = XTS; // we only implement XTS
665 468
666 /* The buffer can accommodate 4 data units and we'll test 4 cases by "scrolling". The data unit 0xFFFFFFFFFF 469 /* The buffer can accommodate 4 data units and we'll test 4 cases by "scrolling". The data unit 0xFFFFFFFFFF
667 will "move" from the start of the buffer to its end. For a 512-byte data unit, the byte offset 562949953420800 470 will "move" from the start of the buffer to its end. For a 512-byte data unit, the byte offset 562949953420800
@@ -1029,340 +832,6 @@ BOOL TestSectorBufEncryption (PCRYPTO_INFO ci)
1029 return (nTestsPerformed == 80); 832 return (nTestsPerformed == 80);
1030} 833}
1031 834
1032
1033BOOL TestLegacySectorBufEncryption (PCRYPTO_INFO ci)
1034{
1035 unsigned char buf [ENCRYPTION_DATA_UNIT_SIZE * 2];
1036 unsigned int i;
1037 char name[64];
1038 unsigned __int32 crc;
1039 UINT64_STRUCT unitNo;
1040 uint32 nbrUnits;
1041 int blockSize;
1042 BOOL lrw64InitDone = FALSE;
1043 BOOL lrw128InitDone = FALSE;
1044 int nTestsPerformed = 0;
1045
1046 unitNo.Value = 0x0234567890ABCDEFull;
1047 nbrUnits = sizeof (buf) / ENCRYPTION_DATA_UNIT_SIZE;
1048
1049 for (i = 0; i < sizeof (buf); i++)
1050 buf[i] = (unsigned char) i;
1051
1052 for (i = 0; i < sizeof (ci->k2); i++)
1053 ci->k2[i] = (unsigned char) i;
1054
1055 // Test all EAs
1056 for (ci->ea = EAGetFirst (); ci->ea != 0; ci->ea = EAGetNext (ci->ea))
1057 {
1058 EAGetName (name, ci->ea);
1059 blockSize = CipherGetBlockSize (EAGetFirstCipher (ci->ea));
1060
1061 if (EAInit (ci->ea, (unsigned char *)buf, ci->ks) == ERR_CIPHER_INIT_FAILURE)
1062 return FALSE;
1063
1064 // Test all deprecated modes of operation
1065 for (ci->mode = EAGetFirstMode (ci->ea);
1066 ci->mode != 0;
1067 ci->mode = EAGetNextMode (ci->ea, ci->mode))
1068 {
1069 // Skip modes that are not deprecated
1070 if (ci->mode == XTS)
1071 continue;
1072
1073 if (ci->mode == LRW
1074 && (blockSize == 8 && !lrw64InitDone || blockSize == 16 && !lrw128InitDone ))
1075 {
1076 if (!EAInitMode (ci))
1077 return FALSE;
1078
1079 if (blockSize == 8)
1080 lrw64InitDone = TRUE;
1081 else if (blockSize == 16)
1082 lrw128InitDone = TRUE;
1083 }
1084
1085 EncryptDataUnits (buf, &unitNo, nbrUnits, ci);
1086 crc = GetCrc32 (buf, sizeof (buf));
1087
1088 switch (ci->mode)
1089 {
1090 case LRW: // Deprecated/legacy
1091 if (strcmp (name, "AES") == 0)
1092 {
1093 if (crc != 0x5237acf9)
1094 return FALSE;
1095 nTestsPerformed++;
1096 }
1097 else if (strcmp (name, "Blowfish") == 0) // Deprecated/legacy
1098 {
1099 if (crc != 0xf94d5300)
1100 return FALSE;
1101 nTestsPerformed++;
1102 }
1103 else if (strcmp (name, "CAST5") == 0) // Deprecated/legacy
1104 {
1105 if (crc != 0x33971e82)
1106 return FALSE;
1107 nTestsPerformed++;
1108 }
1109 else if (strcmp (name, "Serpent") == 0)
1110 {
1111 if (crc != 0x7fb86805)
1112 return FALSE;
1113 nTestsPerformed++;
1114 }
1115 else if (strcmp (name, "Triple DES") == 0) // Deprecated/legacy
1116 {
1117 if (crc != 0x2b20bb84)
1118 return FALSE;
1119 nTestsPerformed++;
1120 }
1121 else if (strcmp (name, "Twofish") == 0)
1122 {
1123 if (crc != 0xa9de0f0b)
1124 return FALSE;
1125 nTestsPerformed++;
1126 }
1127 else if (strcmp (name, "AES-Twofish") == 0)
1128 {
1129 if (crc != 0x4ed0fd80)
1130 return FALSE;
1131 nTestsPerformed++;
1132 }
1133 else if (strcmp (name, "AES-Twofish-Serpent") == 0)
1134 {
1135 if (crc != 0xea04b3cf)
1136 return FALSE;
1137 nTestsPerformed++;
1138 }
1139 else if (strcmp (name, "Serpent-AES") == 0)
1140 {
1141 if (crc != 0x0d33596a)
1142 return FALSE;
1143 nTestsPerformed++;
1144 }
1145 else if (strcmp (name, "Serpent-Twofish-AES") == 0)
1146 {
1147 if (crc != 0x2845d0e3)
1148 return FALSE;
1149 nTestsPerformed++;
1150 }
1151 else if (strcmp (name, "Twofish-Serpent") == 0)
1152 {
1153 if (crc != 0xca65c5cd)
1154 return FALSE;
1155 nTestsPerformed++;
1156 }
1157 break;
1158
1159 case CBC: // Deprecated/legacy
1160 case INNER_CBC: // Deprecated/legacy
1161 case OUTER_CBC: // Deprecated/legacy
1162 if (strcmp (name, "AES") == 0)
1163 {
1164 if (crc != 0x2274f53d)
1165 return FALSE;
1166 nTestsPerformed++;
1167 }
1168 else if (strcmp (name, "Blowfish") == 0) // Deprecated/legacy
1169 {
1170 if (crc != 0x033899a1)
1171 return FALSE;
1172 nTestsPerformed++;
1173 }
1174 else if (strcmp (name, "CAST5") == 0) // Deprecated/legacy
1175 {
1176 if (crc != 0x331cecc7)
1177 return FALSE;
1178 nTestsPerformed++;
1179 }
1180 else if (strcmp (name, "Serpent") == 0)
1181 {
1182 if (crc != 0x42dff3d4)
1183 return FALSE;
1184 nTestsPerformed++;
1185 }
1186 else if (strcmp (name, "Triple DES") == 0) // Deprecated/legacy
1187 {
1188 if (crc != 0xfe497d0c)
1189 return FALSE;
1190 nTestsPerformed++;
1191 }
1192 else if (strcmp (name, "AES-Blowfish") == 0) // Deprecated/legacy
1193 {
1194 if (crc != 0xa7a80c84)
1195 return FALSE;
1196 nTestsPerformed++;
1197 }
1198 else if (strcmp (name, "AES-Blowfish-Serpent") == 0) // Deprecated/legacy
1199 {
1200 if (crc != 0xa0584562)
1201 return FALSE;
1202 nTestsPerformed++;
1203 }
1204 else if (strcmp (name, "AES-Twofish") == 0)
1205 {
1206 if (crc != 0x3c226444)
1207 return FALSE;
1208 nTestsPerformed++;
1209 }
1210 else if (strcmp (name, "AES-Twofish-Serpent") == 0)
1211 {
1212 if (crc != 0x5e5e77fd)
1213 return FALSE;
1214 nTestsPerformed++;
1215 }
1216 else if (strcmp (name, "Serpent-AES") == 0)
1217 {
1218 if (crc != 0x57c612d5)
1219 return FALSE;
1220 nTestsPerformed++;
1221 }
1222 else if (strcmp (name, "Serpent-Twofish-AES") == 0)
1223 {
1224 if (crc != 0x081e045a)
1225 return FALSE;
1226 nTestsPerformed++;
1227 }
1228 else if (strcmp (name, "Twofish-Serpent") == 0)
1229 {
1230 if (crc != 0xa7b659f3)
1231 return FALSE;
1232 nTestsPerformed++;
1233 }
1234 break;
1235 }
1236
1237 if (crc == 0xb70b4c26)
1238 return FALSE;
1239
1240 DecryptDataUnits (buf, &unitNo, nbrUnits, ci);
1241
1242 if (GetCrc32 (buf, sizeof (buf)) != 0xb70b4c26)
1243 return FALSE;
1244
1245 nTestsPerformed++;
1246
1247 EncryptBuffer (buf, sizeof (buf), ci);
1248 crc = GetCrc32 (buf, sizeof (buf));
1249
1250 switch (ci->mode)
1251 {
1252 case LRW: // Deprecated/legacy
1253 if (strcmp (name, "AES") == 0)
1254 {
1255 if (crc != 0x5ae1e3d8)
1256 return FALSE;
1257 nTestsPerformed++;
1258 }
1259 else if (strcmp (name, "Blowfish") == 0) // Deprecated/legacy
1260 {
1261 if (crc != 0x2738426f)
1262 return FALSE;
1263 nTestsPerformed++;
1264 }
1265 else if (strcmp (name, "AES-Twofish-Serpent") == 0)
1266 {
1267 if (crc != 0x14f2948a)
1268 return FALSE;
1269 nTestsPerformed++;
1270 }
1271 break;
1272
1273 case CBC: // Deprecated/legacy
1274 case INNER_CBC: // Deprecated/legacy
1275 case OUTER_CBC: // Deprecated/legacy
1276 if (strcmp (name, "AES") == 0)
1277 {
1278 if (crc != 0x960f740e)
1279 return FALSE;
1280 nTestsPerformed++;
1281 }
1282 else if (strcmp (name, "Blowfish") == 0) // Deprecated/legacy
1283 {
1284 if (crc != 0x7e1cfabb)
1285 return FALSE;
1286 nTestsPerformed++;
1287 }
1288 else if (strcmp (name, "CAST5") == 0) // Deprecated/legacy
1289 {
1290 if (crc != 0xeaae21c8)
1291 return FALSE;
1292 nTestsPerformed++;
1293 }
1294 else if (strcmp (name, "Serpent") == 0)
1295 {
1296 if (crc != 0xa8139d62)
1297 return FALSE;
1298 nTestsPerformed++;
1299 }
1300 else if (strcmp (name, "Triple DES") == 0) // Deprecated/legacy
1301 {
1302 if (crc != 0xecf5d7d0)
1303 return FALSE;
1304 nTestsPerformed++;
1305 }
1306 else if (strcmp (name, "AES-Blowfish") == 0) // Deprecated/legacy
1307 {
1308 if (crc != 0xb70171b6)
1309 return FALSE;
1310 nTestsPerformed++;
1311 }
1312 else if (strcmp (name, "AES-Blowfish-Serpent") == 0) // Deprecated/legacy
1313 {
1314 if (crc != 0x1e749a87)
1315 return FALSE;
1316 nTestsPerformed++;
1317 }
1318 else if (strcmp (name, "AES-Twofish") == 0)
1319 {
1320 if (crc != 0xb4b8bb9b)
1321 return FALSE;
1322 nTestsPerformed++;
1323 }
1324 else if (strcmp (name, "AES-Twofish-Serpent") == 0)
1325 {
1326 if (crc != 0x76b6c1cb)
1327 return FALSE;
1328 nTestsPerformed++;
1329 }
1330 else if (strcmp (name, "Serpent-AES") == 0)
1331 {
1332 if (crc != 0x634f12ed)
1333 return FALSE;
1334 nTestsPerformed++;
1335 }
1336 else if (strcmp (name, "Serpent-Twofish-AES") == 0)
1337 {
1338 if (crc != 0xe54bc1b9)
1339 return FALSE;
1340 nTestsPerformed++;
1341 }
1342 else if (strcmp (name, "Twofish-Serpent") == 0)
1343 {
1344 if (crc != 0x21cdb382)
1345 return FALSE;
1346 nTestsPerformed++;
1347 }
1348 break;
1349 }
1350
1351 if (crc == 0xb70b4c26)
1352 return FALSE;
1353
1354 DecryptBuffer (buf, sizeof (buf), ci);
1355
1356 if (GetCrc32 (buf, sizeof (buf)) != 0xb70b4c26)
1357 return FALSE;
1358
1359 nTestsPerformed++;
1360 }
1361 }
1362 return (nTestsPerformed == 86);
1363}
1364
1365
1366static BOOL DoAutoTestAlgorithms (void) 835static BOOL DoAutoTestAlgorithms (void)
1367{ 836{
1368 PCRYPTO_INFO ci; 837 PCRYPTO_INFO ci;
@@ -1377,74 +846,6 @@ static BOOL DoAutoTestAlgorithms (void)
1377 846
1378 memset (ci, 0, sizeof (*ci)); 847 memset (ci, 0, sizeof (*ci));
1379 848
1380 /* Blowfish (deprecated/legacy) */
1381
1382 for (i=0;i<BF_TEST_COUNT;i++)
1383 {
1384 memcpy(key, bf_ecb_vectors[i].key, 8);
1385 memcpy(tmp, bf_ecb_vectors[i].plaintext, 8);
1386 CipherInit2(BLOWFISH, key, ks_tmp, 8);
1387
1388 ((uint32 *)tmp)[0] = BE32 (((uint32 *)tmp)[0]);
1389 ((uint32 *)tmp)[1] = BE32 (((uint32 *)tmp)[1]);
1390
1391 BlowfishEncryptLE (tmp,tmp,(BF_KEY *)ks_tmp,1);
1392 BlowfishEncryptLE (tmp,tmp,(BF_KEY *)ks_tmp,0);
1393 BlowfishEncryptLE (tmp,tmp,(BF_KEY *)ks_tmp,1);
1394
1395 ((uint32 *)tmp)[0] = BE32 (((uint32 *)tmp)[0]);
1396 ((uint32 *)tmp)[1] = BE32 (((uint32 *)tmp)[1]);
1397
1398 if (memcmp(bf_ecb_vectors[i].ciphertext,tmp,8)!=0)
1399 break;
1400 }
1401
1402 if (i != BF_TEST_COUNT)
1403 bFailed = TRUE;
1404
1405 /* CAST5 (deprecated/legacy) */
1406
1407 for (i=0;i<CAST_TEST_COUNT;i++)
1408 {
1409 int cipher = CAST;
1410 memcpy(key, cast_ecb_vectors[i].key, 16);
1411 memcpy(tmp, cast_ecb_vectors[i].plaintext, 8);
1412 CipherInit2(cipher, key, ks_tmp, 16);
1413
1414 EncipherBlock(cipher, tmp, ks_tmp);
1415 DecipherBlock(cipher, tmp, ks_tmp);
1416 EncipherBlock(cipher, tmp, ks_tmp);
1417
1418 if (memcmp(cast_ecb_vectors[i].ciphertext, tmp,8)!=0)
1419 break;
1420 }
1421
1422 if (i!=CAST_TEST_COUNT)
1423 bFailed = TRUE;
1424
1425
1426 /* Triple DES (TECB, EDE) - deprecated/legacy */
1427
1428 for (i = 0; i < TRIPLEDES_TEST_COUNT; i++)
1429 {
1430 int cipher = TRIPLEDES;
1431 memcpy(key, tripledes_vectors[i].key, sizeof(tripledes_vectors->key));
1432 memcpy(tmp, tripledes_vectors[i].plaintext, sizeof(tripledes_vectors->plaintext));
1433
1434 CipherInit(cipher, key, ks_tmp);
1435
1436 EncipherBlock(cipher, tmp, ks_tmp);
1437 if (memcmp(tripledes_vectors[i].ciphertext, tmp, sizeof(tripledes_vectors->ciphertext)) != 0)
1438 break;
1439
1440 DecipherBlock(cipher, tmp, ks_tmp);
1441 if (memcmp(tripledes_vectors[i].plaintext, tmp, sizeof(tripledes_vectors->plaintext)) != 0)
1442 break;
1443 }
1444 if (i != TRIPLEDES_TEST_COUNT)
1445 bFailed = TRUE;
1446
1447
1448 /* AES */ 849 /* AES */
1449 850
1450 for (i = 0; i < AES_TEST_COUNT; i++) 851 for (i = 0; i < AES_TEST_COUNT; i++)
@@ -1550,10 +951,6 @@ static BOOL DoAutoTestAlgorithms (void)
1550 if (!XTSAesTest (ci)) 951 if (!XTSAesTest (ci))
1551 bFailed = TRUE; 952 bFailed = TRUE;
1552 953
1553 /* LRW-AES (deprecated/legacy) */
1554 if (!LRWAesTest (ci))
1555 bFailed = TRUE;
1556
1557 /* Sector and buffer related algorithms */ 954 /* Sector and buffer related algorithms */
1558 if (!TestSectorBufEncryption (ci)) 955 if (!TestSectorBufEncryption (ci))
1559 bFailed = TRUE; 956 bFailed = TRUE;
@@ -1601,26 +998,6 @@ BOOL test_hmac_sha512 ()
1601 return (nTestsPerformed == 6); 998 return (nTestsPerformed == 6);
1602} 999}
1603 1000
1604BOOL test_hmac_sha1 ()
1605{
1606 // Deprecated/legacy
1607
1608 int nTestsPerformed = 0;
1609 int i;
1610
1611 for (i = 0; i < 3; i++)
1612 {
1613 char digest[SHA1_DIGESTSIZE];
1614 hmac_sha1 (hmac_sha1_test_keys[i], (int) strlen (hmac_sha1_test_keys[i]), hmac_sha1_test_data[i], (int) strlen (hmac_sha1_test_data[i]), digest, SHA1_DIGESTSIZE);
1615 if (memcmp (digest, hmac_sha1_test_vectors[i], SHA1_DIGESTSIZE) != 0)
1616 return FALSE;
1617 else
1618 nTestsPerformed++;
1619 }
1620
1621 return (nTestsPerformed == 3);
1622}
1623
1624BOOL test_hmac_ripemd160 () 1001BOOL test_hmac_ripemd160 ()
1625{ 1002{
1626 int nTestsPerformed = 0; 1003 int nTestsPerformed = 0;
@@ -1658,10 +1035,6 @@ BOOL test_pkcs5 ()
1658 if (!test_hmac_sha512()) 1035 if (!test_hmac_sha512())
1659 return FALSE; 1036 return FALSE;
1660 1037
1661 /* HMAC-SHA-1 tests (deprecated/legacy) */
1662 if (test_hmac_sha1() == FALSE)
1663 return FALSE;
1664
1665 /* HMAC-RIPEMD-160 tests */ 1038 /* HMAC-RIPEMD-160 tests */
1666 if (test_hmac_ripemd160() == FALSE) 1039 if (test_hmac_ripemd160() == FALSE)
1667 return FALSE; 1040 return FALSE;
@@ -1681,23 +1054,6 @@ BOOL test_pkcs5 ()
1681 if (memcmp (dk, "\x13\x64\xae\xf8\x0d\xf5\x57\x6c\x30\xd5\x71\x4c\xa7\x75\x3f\xfd\x00\xe5\x25\x8b\x39\xc7\x44\x7f\xce\x23\x3d\x08\x75\xe0\x2f\x48\xd6\x30\xd7\x00\xb6\x24\xdb\xe0\x5a\xd7\x47\xef\x52\xca\xa6\x34\x83\x47\xe5\xcb\xe9\x87\xf1\x20\x59\x6a\xe6\xa9\xcf\x51\x78\xc6\xb6\x23\xa6\x74\x0d\xe8\x91\xbe\x1a\xd0\x28\xcc\xce\x16\x98\x9a\xbe\xfb\xdc\x78\xc9\xe1\x7d\x72\x67\xce\xe1\x61\x56\x5f\x96\x68\xe6\xe1\xdd\xf4\xbf\x1b\x80\xe0\x19\x1c\xf4\xc4\xd3\xdd\xd5\xd5\x57\x2d\x83\xc7\xa3\x37\x87\xf4\x4e\xe0\xf6\xd8\x6d\x65\xdc\xa0\x52\xa3\x13\xbe\x81\xfc\x30\xbe\x7d\x69\x58\x34\xb6\xdd\x41\xc6", 144) != 0) 1054 if (memcmp (dk, "\x13\x64\xae\xf8\x0d\xf5\x57\x6c\x30\xd5\x71\x4c\xa7\x75\x3f\xfd\x00\xe5\x25\x8b\x39\xc7\x44\x7f\xce\x23\x3d\x08\x75\xe0\x2f\x48\xd6\x30\xd7\x00\xb6\x24\xdb\xe0\x5a\xd7\x47\xef\x52\xca\xa6\x34\x83\x47\xe5\xcb\xe9\x87\xf1\x20\x59\x6a\xe6\xa9\xcf\x51\x78\xc6\xb6\x23\xa6\x74\x0d\xe8\x91\xbe\x1a\xd0\x28\xcc\xce\x16\x98\x9a\xbe\xfb\xdc\x78\xc9\xe1\x7d\x72\x67\xce\xe1\x61\x56\x5f\x96\x68\xe6\xe1\xdd\xf4\xbf\x1b\x80\xe0\x19\x1c\xf4\xc4\xd3\xdd\xd5\xd5\x57\x2d\x83\xc7\xa3\x37\x87\xf4\x4e\xe0\xf6\xd8\x6d\x65\xdc\xa0\x52\xa3\x13\xbe\x81\xfc\x30\xbe\x7d\x69\x58\x34\xb6\xdd\x41\xc6", 144) != 0)
1682 return FALSE; 1055 return FALSE;
1683 1056
1684 /* PKCS-5 test 1 with HMAC-SHA-1 (deprecated/legacy) used as the PRF (derives a key longer than the underlying hash) */
1685 derive_key_sha1 ("password", 8, "\x12\x34\x56\x78", 4, 5, dk, 48);
1686 if (memcmp (dk, "\x5c\x75\xce\xf0\x1a\x96\x0d\xf7\x4c\xb6\xb4\x9b\x9e\x38\xe6\xb5\x3b\x11\x80\xe3\x2f\xf7\xe0\xdd\xaa\xca\x8f\x81\x27\xf6\x9f\x4f\x1d\xc8\x2f\x48\x2d\xdb\x1a\x0a\xca\x90\xcb\x80\xb9\x2e\x90\x9e", 48) != 0)
1687 return FALSE;
1688
1689 /* PKCS-5 test 2 with HMAC-SHA-1 (deprecated/legacy) used as the PRF */
1690 derive_key_sha1 ("password", 8, "\x12\x34\x56\x78", 4, 5, dk, 4);
1691 if (memcmp (dk, "\x5c\x75\xce\xf0", 4) != 0)
1692 return FALSE;
1693
1694#if 0 // This test is disabled because it uses 1200 iterations (to prevent startup slowdown)
1695 /* PKCS-5 test 3 with HMAC-SHA-1 (deprecated/legacy) used as the PRF */
1696 derive_key_sha1 ("password", 8, "ATHENA.MIT.EDUraeburn", 21, 1200, dk, 16);
1697 if (memcmp (dk, "\x5c\x08\xeb\x61\xfd\xf7\x1e\x4e\x4e\xc3\xcf\x6b\xa1\xf5\x51\x2b", 16) != 0)
1698 return FALSE;
1699#endif
1700
1701 /* PKCS-5 test 1 with HMAC-RIPEMD-160 used as the PRF */ 1057 /* PKCS-5 test 1 with HMAC-RIPEMD-160 used as the PRF */
1702 derive_key_ripemd160 (FALSE, "password", 8, "\x12\x34\x56\x78", 4, 5, dk, 4); 1058 derive_key_ripemd160 (FALSE, "password", 8, "\x12\x34\x56\x78", 4, 5, dk, 4);
1703 if (memcmp (dk, "\x7a\x3d\x7c\x03", 4) != 0) 1059 if (memcmp (dk, "\x7a\x3d\x7c\x03", 4) != 0)