5 #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 56 #if (CRYPTOPP_MSC_VERSION >= 1410) 57 # pragma strict_gs_check (on) 63 bool ValidateAll(
bool thorough)
65 bool pass=TestSettings();
66 pass=TestOS_RNG() && pass;
67 pass=TestAutoSeeded() && pass;
69 #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) 70 pass=TestRDRAND() && pass;
71 pass=TestRDSEED() && pass;
76 #if !defined(NDEBUG) && !defined(CRYPTOPP_IMPORTS) 78 pass=TestPolynomialMod2() && pass;
81 pass=ValidateCRC32() && pass;
82 pass=ValidateAdler32() && pass;
83 pass=ValidateMD2() && pass;
84 pass=ValidateMD5() && pass;
85 pass=ValidateSHA() && pass;
86 pass=RunTestDataFile(PACKAGE_DATA_DIR
"TestVectors/sha3.txt") && pass;
87 pass=ValidateTiger() && pass;
88 pass=ValidateRIPEMD() && pass;
89 pass=ValidatePanama() && pass;
90 pass=ValidateWhirlpool() && pass;
92 pass=ValidateHMAC() && pass;
93 pass=ValidateTTMAC() && pass;
95 pass=ValidatePBKDF() && pass;
96 pass=ValidateHKDF() && pass;
98 pass=ValidateDES() && pass;
99 pass=ValidateCipherModes() && pass;
100 pass=ValidateIDEA() && pass;
101 pass=ValidateSAFER() && pass;
102 pass=ValidateRC2() && pass;
103 pass=ValidateARC4() && pass;
104 pass=ValidateRC5() && pass;
105 pass=ValidateBlowfish() && pass;
106 pass=ValidateThreeWay() && pass;
107 pass=ValidateGOST() && pass;
108 pass=ValidateSHARK() && pass;
109 pass=ValidateCAST() && pass;
110 pass=ValidateSquare() && pass;
111 pass=ValidateSKIPJACK() && pass;
112 pass=ValidateSEAL() && pass;
113 pass=ValidateRC6() && pass;
114 pass=ValidateMARS() && pass;
115 pass=ValidateRijndael() && pass;
116 pass=ValidateTwofish() && pass;
117 pass=ValidateSerpent() && pass;
118 pass=ValidateSHACAL2() && pass;
119 pass=ValidateCamellia() && pass;
120 pass=ValidateSalsa() && pass;
121 pass=ValidateSosemanuk() && pass;
122 pass=ValidateVMAC() && pass;
123 pass=ValidateCCM() && pass;
124 pass=ValidateGCM() && pass;
125 pass=ValidateCMAC() && pass;
126 pass=RunTestDataFile(PACKAGE_DATA_DIR
"TestVectors/eax.txt") && pass;
127 pass=RunTestDataFile(PACKAGE_DATA_DIR
"TestVectors/seed.txt") && pass;
129 pass=ValidateBBS() && pass;
130 pass=ValidateDH() && pass;
131 pass=ValidateMQV() && pass;
132 pass=ValidateRSA() && pass;
133 pass=ValidateElGamal() && pass;
134 pass=ValidateDLIES() && pass;
135 pass=ValidateNR() && pass;
136 pass=ValidateDSA(thorough) && pass;
137 pass=ValidateLUC() && pass;
138 pass=ValidateLUC_DH() && pass;
139 pass=ValidateLUC_DL() && pass;
140 pass=ValidateXTR_DH() && pass;
141 pass=ValidateRabin() && pass;
142 pass=ValidateRW() && pass;
144 pass=ValidateECP() && pass;
145 pass=ValidateEC2N() && pass;
146 pass=ValidateECDSA() && pass;
147 pass=ValidateESIGN() && pass;
150 cout <<
"\nAll tests passed!\n";
152 cout <<
"\nOops! Not all tests passed.\n";
160 #if defined(__MINGW32__) 166 cout <<
"\nTesting Settings...\n\n";
169 memcpy_s(&w,
sizeof(w),
"\x01\x02\x03\x04", 4);
171 if (w == 0x04030201L)
173 #ifdef IS_LITTLE_ENDIAN 179 cout <<
"Your machine is little endian.\n";
181 else if (w == 0x01020304L)
183 #ifndef IS_LITTLE_ENDIAN 189 cout <<
"Your machine is big endian.\n";
193 cout <<
"FAILED: Your machine is neither big endian nor little endian.\n";
197 #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS 198 byte testvals[10] = {1,2,2,3,3,3,3,2,2,1};
199 if (*(word32 *)(testvals+3) == 0x03030303 && *(word64 *)(testvals+1) == W64LIT(0x0202030303030202))
200 cout <<
"passed: Your machine allows unaligned data access.\n";
203 cout <<
"FAILED: Unaligned data access gave incorrect results.\n";
207 cout <<
"passed: CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS is not defined. Will restrict to aligned data access.\n";
210 if (
sizeof(byte) == 1)
217 cout <<
"sizeof(byte) == " <<
sizeof(byte) << endl;
219 if (
sizeof(word16) == 2)
226 cout <<
"sizeof(word16) == " <<
sizeof(word16) << endl;
228 if (
sizeof(word32) == 4)
235 cout <<
"sizeof(word32) == " <<
sizeof(word32) << endl;
237 if (
sizeof(word64) == 8)
244 cout <<
"sizeof(word64) == " <<
sizeof(word64) << endl;
246 #ifdef CRYPTOPP_WORD128_AVAILABLE 247 if (
sizeof(word128) == 16)
254 cout <<
"sizeof(word128) == " <<
sizeof(word128) << endl;
257 if (
sizeof(word) == 2*
sizeof(hword)
258 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE
259 &&
sizeof(dword) == 2*
sizeof(word)
268 cout <<
"sizeof(hword) == " <<
sizeof(hword) <<
", sizeof(word) == " <<
sizeof(word);
269 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE 270 cout <<
", sizeof(dword) == " <<
sizeof(dword);
274 #ifdef CRYPTOPP_CPUID_AVAILABLE 275 bool hasMMX = HasMMX();
276 bool hasISSE = HasISSE();
277 bool hasSSE2 = HasSSE2();
278 bool hasSSSE3 = HasSSSE3();
280 int cacheLineSize = GetCacheLineSize();
282 if ((isP4 && (!hasMMX || !hasSSE2)) || (hasSSE2 && !hasMMX) || (cacheLineSize < 16 || cacheLineSize > 256 || !
IsPowerOf2(cacheLineSize)))
290 cout <<
"hasMMX == " << hasMMX <<
", hasISSE == " << hasISSE <<
", hasSSE2 == " << hasSSE2 <<
", hasSSSE3 == " << hasSSSE3 <<
", hasAESNI == " << HasAESNI() <<
", hasRDRAND == " << HasRDRAND() <<
", hasRDSEED == " << HasRDSEED() <<
", hasCLMUL == " << HasCLMUL() <<
", isP4 == " << isP4 <<
", cacheLineSize == " << cacheLineSize;
291 cout <<
", AESNI_INTRINSICS == " << CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE << endl;
296 cout <<
"Some critical setting in config.h is in error. Please fix it and recompile." << endl;
308 #ifdef BLOCKING_RNG_AVAILABLE 315 cout <<
"\nTesting operating system provided blocking random number generator...\n\n";
319 unsigned long total=0, length=0;
320 time_t t = time(NULL), t1 = 0;
321 CRYPTOPP_UNUSED(length);
324 while (total < 16 && (t1 < 10 || total*8 > (
unsigned long)t1))
338 cout <<
" it took " << long(t1) <<
" seconds to generate " << total <<
" bytes" << endl;
340 #if 0 // disable this part. it's causing an unpredictable pause during the validation testing 346 while (time(NULL) - t < 2)
355 while (time(NULL) - t < 2)
368 cout <<
" it generated " << length <<
" bytes in " << long(time(NULL) - t) <<
" seconds" << endl;
372 test.AttachedTransformation()->MessageEnd();
374 if (meter.GetTotalBytes() < total)
381 cout <<
" " << total <<
" generated bytes compressed to " << meter.GetTotalBytes() <<
" bytes by DEFLATE" << endl;
384 cout <<
"\nNo operating system provided blocking random number generator, skipping test." << endl;
387 #ifdef NONBLOCKING_RNG_AVAILABLE 394 cout <<
"\nTesting operating system provided nonblocking random number generator...\n\n";
399 if (meter.GetTotalBytes() < 100000)
406 cout <<
" 100000 generated bytes compressed to " << meter.GetTotalBytes() <<
" bytes by DEFLATE" << endl;
409 cout <<
"\nNo operating system provided nonblocking random number generator, skipping test." << endl;
415 bool TestAutoSeeded()
420 bool TestAutoSeeded()
423 cout <<
"\nTesting AutoSeeded generator...\n\n";
426 bool generate =
true, discard =
true;
431 if (meter.GetTotalBytes() < 100000)
438 cout <<
" 100000 generated bytes compressed to " << meter.GetTotalBytes() <<
" bytes by DEFLATE" << endl;
453 cout <<
" discarded 10000 bytes" << endl;
455 return generate && discard;
457 #endif // NO_OS_DEPENDENCE 459 #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) 463 bool maurer =
true, generate =
true, discard =
true;
464 static const unsigned int SIZE = 10000;
468 cout <<
"\nTesting RDRAND generator...\n\n";
477 const double mv = mt.GetTestValue();
486 const std::streamsize oldp = cout.precision(5);
487 const std::ios::fmtflags oldf = cout.setf(std::ios::fixed, std::ios::floatfield);
488 cout <<
" Maurer Randomness Test value of " << mv << endl;
489 cout.precision(oldp);
490 cout.setf(oldf, std::ios::floatfield);
495 if (meter.GetTotalBytes() < SIZE)
502 cout <<
" " << SIZE <<
" generated bytes compressed to " << meter.GetTotalBytes() <<
" bytes by DEFLATE\n";
517 cout <<
" discarded " << SIZE <<
" bytes\n";
520 cout <<
"\nRDRAND generator not available, skipping test.\n";
522 if (!(maurer && generate && discard))
525 return maurer && generate && discard;
529 #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) 533 bool maurer =
true, generate =
true, discard =
true;
534 static const unsigned int SIZE = 10000;
538 cout <<
"\nTesting RDSEED generator...\n\n";
547 const double mv = mt.GetTestValue();
556 const std::streamsize oldp = cout.precision(5);
557 const std::ios::fmtflags oldf = cout.setf(std::ios::fixed, std::ios::floatfield);
558 cout <<
" Maurer Randomness Test value of " << mv << endl;
559 cout.precision(oldp);
560 cout.setf(oldf, std::ios::floatfield);
565 if (meter.GetTotalBytes() < SIZE)
572 cout <<
" " << SIZE <<
" generated bytes compressed to " << meter.GetTotalBytes() <<
" bytes by DEFLATE\n";
587 cout <<
" discarded " << SIZE <<
" bytes\n";
590 cout <<
"\nRDSEED generator not available, skipping test.\n";
592 if (!(maurer && generate && discard))
595 return maurer && generate && discard;
600 typedef auto_ptr<BlockTransformation> apbt;
605 virtual unsigned int BlockSize()
const =0;
606 virtual unsigned int KeyLength()
const =0;
608 virtual apbt NewEncryption(
const byte *key)
const =0;
609 virtual apbt NewDecryption(
const byte *key)
const =0;
616 unsigned int BlockSize()
const {
return E::BLOCKSIZE;}
617 unsigned int KeyLength()
const {
return m_keylen;}
619 apbt NewEncryption(
const byte *key)
const 620 {
return apbt(
new E(key, m_keylen));}
621 apbt NewDecryption(
const byte *key)
const 622 {
return apbt(
new D(key, m_keylen));}
624 unsigned int m_keylen;
631 : m_keylen(keylen ? keylen : E::DEFAULT_KEYLENGTH), m_rounds(rounds ? rounds : E::DEFAULT_ROUNDS) {}
632 unsigned int BlockSize()
const {
return E::BLOCKSIZE;}
633 unsigned int KeyLength()
const {
return m_keylen;}
635 apbt NewEncryption(
const byte *key)
const 636 {
return apbt(
new E(key, m_keylen, m_rounds));}
637 apbt NewDecryption(
const byte *key)
const 638 {
return apbt(
new D(key, m_keylen, m_rounds));}
640 unsigned int m_keylen, m_rounds;
646 SecByteBlock plain(cg.BlockSize()), cipher(cg.BlockSize()), out(cg.BlockSize()), outplain(cg.BlockSize());
648 bool pass=
true, fail;
652 valdata.
Get(key, cg.KeyLength());
653 valdata.
Get(plain, cg.BlockSize());
654 valdata.
Get(cipher, cg.BlockSize());
656 apbt transE = cg.NewEncryption(key);
657 transE->ProcessBlock(plain, out);
658 fail = memcmp(out, cipher, cg.BlockSize()) != 0;
660 apbt transD = cg.NewDecryption(key);
661 transD->ProcessBlock(out, outplain);
662 fail=fail || memcmp(outplain, plain, cg.BlockSize());
664 pass = pass && !fail;
666 cout << (fail ?
"FAILED " :
"passed ");
667 output.
Put(key, cg.KeyLength());
669 output.
Put(outplain, cg.BlockSize());
671 output.
Put(out, cg.BlockSize());
681 : validOutput(validOutput), outputLen(outputLen), counter(0), fail(
false) {}
682 void PutByte(byte inByte)
684 if (counter >= outputLen || validOutput[counter] != inByte)
686 std::cerr <<
"incorrect output " << counter <<
", " << (word16)validOutput[counter] <<
", " << (word16)inByte <<
"\n";
692 size_t Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking)
694 CRYPTOPP_UNUSED(messageEnd), CRYPTOPP_UNUSED(blocking);
697 FilterTester::PutByte(*inString++);
700 if (counter != outputLen)
713 const byte *validOutput;
714 size_t outputLen, counter;
726 bt.
Put(in, randomLen);
731 return ft->GetResult();
736 cout <<
"\nDES validation suite running...\n\n";
741 cout <<
"\nTesting EDE2, EDE3, and XEX3 variants...\n\n";
759 for (
unsigned int i=1; i<20480; i*=2)
773 if (!TestFilter(filter, plaintext, length, plaintext, length))
780 bool ValidateCipherModes()
782 cout <<
"\nTesting DES modes...\n\n";
783 const byte key[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
784 const byte iv[] = {0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
785 const byte plain[] = {
786 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
787 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
788 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20};
791 bool pass=
true, fail;
795 const byte encrypted[] = {
796 0x3f, 0xa4, 0x0e, 0x8a, 0x98, 0x4d, 0x48, 0x15,
797 0x6a, 0x27, 0x17, 0x87, 0xab, 0x88, 0x83, 0xf9,
798 0x89, 0x3d, 0x51, 0xec, 0x4b, 0x56, 0x3b, 0x53};
802 plain,
sizeof(plain), encrypted,
sizeof(encrypted));
803 pass = pass && !fail;
804 cout << (fail ?
"FAILED " :
"passed ") <<
"ECB encryption" << endl;
808 encrypted,
sizeof(encrypted), plain,
sizeof(plain));
809 pass = pass && !fail;
810 cout << (fail ?
"FAILED " :
"passed ") <<
"ECB decryption" << endl;
814 const byte encrypted[] = {
815 0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C,
816 0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F,
817 0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6};
821 plain,
sizeof(plain), encrypted,
sizeof(encrypted));
822 pass = pass && !fail;
823 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC encryption with no padding" << endl;
827 encrypted,
sizeof(encrypted), plain,
sizeof(plain));
828 pass = pass && !fail;
829 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC decryption with no padding" << endl;
831 fail = !TestModeIV(modeE, modeD);
832 pass = pass && !fail;
833 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC mode IV generation" << endl;
838 const byte encrypted[] = {
839 0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C,
840 0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F,
841 0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6,
842 0x62, 0xC1, 0x6A, 0x27, 0xE4, 0xFC, 0xF2, 0x77};
846 plain,
sizeof(plain), encrypted,
sizeof(encrypted));
847 pass = pass && !fail;
848 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC encryption with PKCS #7 padding" << endl;
852 encrypted,
sizeof(encrypted), plain,
sizeof(plain));
853 pass = pass && !fail;
854 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC decryption with PKCS #7 padding" << endl;
859 const byte encrypted[] = {
860 0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C,
861 0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F,
862 0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6,
863 0xcf, 0xb7, 0xc7, 0x64, 0x0e, 0x7c, 0xd9, 0xa7};
867 plain,
sizeof(plain), encrypted,
sizeof(encrypted));
868 pass = pass && !fail;
869 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC encryption with one-and-zeros padding" << endl;
873 encrypted,
sizeof(encrypted), plain,
sizeof(plain));
874 pass = pass && !fail;
875 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC decryption with one-and-zeros padding" << endl;
878 const byte plain_1[] = {
'a', 0, 0, 0, 0, 0, 0, 0};
880 const byte encrypted[] = {
881 0x9B, 0x47, 0x57, 0x59, 0xD6, 0x9C, 0xF6, 0xD0};
885 plain_1, 1, encrypted,
sizeof(encrypted));
886 pass = pass && !fail;
887 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC encryption with zeros padding" << endl;
891 encrypted,
sizeof(encrypted), plain_1,
sizeof(plain_1));
892 pass = pass && !fail;
893 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC decryption with zeros padding" << endl;
898 const byte encrypted[] = {
899 0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C,
900 0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6,
901 0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F};
905 plain,
sizeof(plain), encrypted,
sizeof(encrypted));
906 pass = pass && !fail;
907 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC encryption with ciphertext stealing (CTS)" << endl;
911 encrypted,
sizeof(encrypted), plain,
sizeof(plain));
912 pass = pass && !fail;
913 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC decryption with ciphertext stealing (CTS)" << endl;
915 fail = !TestModeIV(modeE, modeD);
916 pass = pass && !fail;
917 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC CTS IV generation" << endl;
921 const byte decryptionIV[] = {0x4D, 0xD0, 0xAC, 0x8F, 0x47, 0xCF, 0x79, 0xCE};
922 const byte encrypted[] = {0x12, 0x34, 0x56};
927 modeE.SetStolenIV(stolenIV);
929 plain, 3, encrypted,
sizeof(encrypted));
930 fail = memcmp(stolenIV, decryptionIV, 8) != 0 || fail;
931 pass = pass && !fail;
932 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC encryption with ciphertext and IV stealing" << endl;
936 encrypted,
sizeof(encrypted), plain, 3);
937 pass = pass && !fail;
938 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC decryption with ciphertext and IV stealing" << endl;
941 const byte encrypted[] = {
942 0xF3,0x09,0x62,0x49,0xC7,0xF4,0x6E,0x51,
943 0xA6,0x9E,0x83,0x9B,0x1A,0x92,0xF7,0x84,
944 0x03,0x46,0x71,0x33,0x89,0x8E,0xA6,0x22};
948 plain,
sizeof(plain), encrypted,
sizeof(encrypted));
949 pass = pass && !fail;
950 cout << (fail ?
"FAILED " :
"passed ") <<
"CFB encryption" << endl;
954 encrypted,
sizeof(encrypted), plain,
sizeof(plain));
955 pass = pass && !fail;
956 cout << (fail ?
"FAILED " :
"passed ") <<
"CFB decryption" << endl;
958 fail = !TestModeIV(modeE, modeD);
959 pass = pass && !fail;
960 cout << (fail ?
"FAILED " :
"passed ") <<
"CFB mode IV generation" << endl;
963 const byte plain_2[] = {
964 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,0x68,0x65};
965 const byte encrypted[] = {
966 0xf3,0x1f,0xda,0x07,0x01,0x14,0x62,0xee,0x18,0x7f};
970 plain_2,
sizeof(plain_2), encrypted,
sizeof(encrypted));
971 pass = pass && !fail;
972 cout << (fail ?
"FAILED " :
"passed ") <<
"CFB (8-bit feedback) encryption" << endl;
976 encrypted,
sizeof(encrypted), plain_2,
sizeof(plain_2));
977 pass = pass && !fail;
978 cout << (fail ?
"FAILED " :
"passed ") <<
"CFB (8-bit feedback) decryption" << endl;
980 fail = !TestModeIV(modeE, modeD);
981 pass = pass && !fail;
982 cout << (fail ?
"FAILED " :
"passed ") <<
"CFB (8-bit feedback) IV generation" << endl;
985 const byte encrypted[] = {
986 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
987 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
988 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3};
992 plain,
sizeof(plain), encrypted,
sizeof(encrypted));
993 pass = pass && !fail;
994 cout << (fail ?
"FAILED " :
"passed ") <<
"OFB encryption" << endl;
998 encrypted,
sizeof(encrypted), plain,
sizeof(plain));
999 pass = pass && !fail;
1000 cout << (fail ?
"FAILED " :
"passed ") <<
"OFB decryption" << endl;
1002 fail = !TestModeIV(modeE, modeD);
1003 pass = pass && !fail;
1004 cout << (fail ?
"FAILED " :
"passed ") <<
"OFB IV generation" << endl;
1007 const byte encrypted[] = {
1008 0xF3, 0x09, 0x62, 0x49, 0xC7, 0xF4, 0x6E, 0x51,
1009 0x16, 0x3A, 0x8C, 0xA0, 0xFF, 0xC9, 0x4C, 0x27,
1010 0xFA, 0x2F, 0x80, 0xF4, 0x80, 0xB8, 0x6F, 0x75};
1014 plain,
sizeof(plain), encrypted,
sizeof(encrypted));
1015 pass = pass && !fail;
1016 cout << (fail ?
"FAILED " :
"passed ") <<
"Counter Mode encryption" << endl;
1020 encrypted,
sizeof(encrypted), plain,
sizeof(plain));
1021 pass = pass && !fail;
1022 cout << (fail ?
"FAILED " :
"passed ") <<
"Counter Mode decryption" << endl;
1024 fail = !TestModeIV(modeE, modeD);
1025 pass = pass && !fail;
1026 cout << (fail ?
"FAILED " :
"passed ") <<
"Counter Mode IV generation" << endl;
1029 const byte plain_3[] = {
1030 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20,
1031 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
1032 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20,
1033 0x66, 0x6f, 0x72, 0x20};
1034 const byte mac1[] = {
1035 0xf1, 0xd3, 0x0f, 0x68, 0x49, 0x31, 0x2c, 0xa4};
1036 const byte mac2[] = {
1037 0x35, 0x80, 0xC5, 0xC4, 0x6B, 0x81, 0x24, 0xE2};
1041 fail = !TestFilter(cbcmacFilter, plain_3,
sizeof(plain_3), mac1,
sizeof(mac1));
1042 pass = pass && !fail;
1043 cout << (fail ?
"FAILED " :
"passed ") <<
"CBC MAC" << endl;
1047 fail = !TestFilter(dmacFilter, plain_3,
sizeof(plain_3), mac2,
sizeof(mac2));
1048 pass = pass && !fail;
1049 cout << (fail ?
"FAILED " :
"passed ") <<
"DMAC" << endl;
1054 fail = !TestModeIV(modeE, modeD);
1055 pass = pass && !fail;
1056 cout << (fail ?
"FAILED " :
"passed ") <<
"AES CTR Mode" << endl;
1061 fail = !TestModeIV(modeE, modeD);
1062 pass = pass && !fail;
1063 cout << (fail ?
"FAILED " :
"passed ") <<
"AES OFB Mode" << endl;
1068 fail = !TestModeIV(modeE, modeD);
1069 pass = pass && !fail;
1070 cout << (fail ?
"FAILED " :
"passed ") <<
"AES CFB Mode" << endl;
1075 fail = !TestModeIV(modeE, modeD);
1076 pass = pass && !fail;
1077 cout << (fail ?
"FAILED " :
"passed ") <<
"AES CBC Mode" << endl;
1085 cout <<
"\nIDEA validation suite running...\n\n";
1091 bool ValidateSAFER()
1093 cout <<
"\nSAFER validation suite running...\n\n";
1106 cout <<
"\nRC2 validation suite running...\n\n";
1110 SecByteBlock plain(RC2Encryption::BLOCKSIZE), cipher(RC2Encryption::BLOCKSIZE), out(RC2Encryption::BLOCKSIZE), outplain(RC2Encryption::BLOCKSIZE);
1112 bool pass=
true, fail;
1116 byte keyLen, effectiveLen;
1118 valdata.
Get(keyLen);
1119 valdata.
Get(effectiveLen);
1120 valdata.
Get(key, keyLen);
1121 valdata.
Get(plain, RC2Encryption::BLOCKSIZE);
1122 valdata.
Get(cipher, RC2Encryption::BLOCKSIZE);
1125 transE->ProcessBlock(plain, out);
1126 fail = memcmp(out, cipher, RC2Encryption::BLOCKSIZE) != 0;
1129 transD->ProcessBlock(out, outplain);
1130 fail=fail || memcmp(outplain, plain, RC2Encryption::BLOCKSIZE);
1132 pass = pass && !fail;
1134 cout << (fail ?
"FAILED " :
"passed ");
1135 output.
Put(key, keyLen);
1137 output.
Put(outplain, RC2Encryption::BLOCKSIZE);
1139 output.
Put(out, RC2Encryption::BLOCKSIZE);
1147 unsigned char Key0[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef };
1148 unsigned char Input0[]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
1149 unsigned char Output0[] = {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96};
1151 unsigned char Key1[]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
1152 unsigned char Input1[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
1153 unsigned char Output1[]={0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79};
1155 unsigned char Key2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
1156 unsigned char Input2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
1157 unsigned char Output2[]={0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a};
1159 unsigned char Key3[]={0xef,0x01,0x23,0x45};
1160 unsigned char Input3[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
1161 unsigned char Output3[]={0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,0xbd,0x61};
1163 unsigned char Key4[]={ 0x01,0x23,0x45,0x67,0x89,0xab, 0xcd,0xef };
1164 unsigned char Input4[] =
1165 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1166 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1167 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1168 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1169 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1170 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1171 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1172 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1173 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1174 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1175 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1176 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1177 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1178 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1179 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1180 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1181 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1182 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1183 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1184 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1185 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1186 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1187 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1188 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1189 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1190 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1191 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1192 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1193 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1194 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1195 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1196 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1197 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1198 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1199 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1200 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1201 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1202 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1203 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1204 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1205 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1206 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1207 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1208 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1209 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1210 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1211 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1212 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1213 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1214 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1215 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
1217 unsigned char Output4[]= {
1218 0x75,0x95,0xc3,0xe6,0x11,0x4a,0x09,0x78,0x0c,0x4a,0xd4,
1219 0x52,0x33,0x8e,0x1f,0xfd,0x9a,0x1b,0xe9,0x49,0x8f,
1220 0x81,0x3d,0x76,0x53,0x34,0x49,0xb6,0x77,0x8d,0xca,
1221 0xd8,0xc7,0x8a,0x8d,0x2b,0xa9,0xac,0x66,0x08,0x5d,
1222 0x0e,0x53,0xd5,0x9c,0x26,0xc2,0xd1,0xc4,0x90,0xc1,
1223 0xeb,0xbe,0x0c,0xe6,0x6d,0x1b,0x6b,0x1b,0x13,0xb6,
1224 0xb9,0x19,0xb8,0x47,0xc2,0x5a,0x91,0x44,0x7a,0x95,
1225 0xe7,0x5e,0x4e,0xf1,0x67,0x79,0xcd,0xe8,0xbf,0x0a,
1226 0x95,0x85,0x0e,0x32,0xaf,0x96,0x89,0x44,0x4f,0xd3,
1227 0x77,0x10,0x8f,0x98,0xfd,0xcb,0xd4,0xe7,0x26,0x56,
1228 0x75,0x00,0x99,0x0b,0xcc,0x7e,0x0c,0xa3,0xc4,0xaa,
1229 0xa3,0x04,0xa3,0x87,0xd2,0x0f,0x3b,0x8f,0xbb,0xcd,
1230 0x42,0xa1,0xbd,0x31,0x1d,0x7a,0x43,0x03,0xdd,0xa5,
1231 0xab,0x07,0x88,0x96,0xae,0x80,0xc1,0x8b,0x0a,0xf6,
1232 0x6d,0xff,0x31,0x96,0x16,0xeb,0x78,0x4e,0x49,0x5a,
1233 0xd2,0xce,0x90,0xd7,0xf7,0x72,0xa8,0x17,0x47,0xb6,
1234 0x5f,0x62,0x09,0x3b,0x1e,0x0d,0xb9,0xe5,0xba,0x53,
1235 0x2f,0xaf,0xec,0x47,0x50,0x83,0x23,0xe6,0x71,0x32,
1236 0x7d,0xf9,0x44,0x44,0x32,0xcb,0x73,0x67,0xce,0xc8,
1237 0x2f,0x5d,0x44,0xc0,0xd0,0x0b,0x67,0xd6,0x50,0xa0,
1238 0x75,0xcd,0x4b,0x70,0xde,0xdd,0x77,0xeb,0x9b,0x10,
1239 0x23,0x1b,0x6b,0x5b,0x74,0x13,0x47,0x39,0x6d,0x62,
1240 0x89,0x74,0x21,0xd4,0x3d,0xf9,0xb4,0x2e,0x44,0x6e,
1241 0x35,0x8e,0x9c,0x11,0xa9,0xb2,0x18,0x4e,0xcb,0xef,
1242 0x0c,0xd8,0xe7,0xa8,0x77,0xef,0x96,0x8f,0x13,0x90,
1243 0xec,0x9b,0x3d,0x35,0xa5,0x58,0x5c,0xb0,0x09,0x29,
1244 0x0e,0x2f,0xcd,0xe7,0xb5,0xec,0x66,0xd9,0x08,0x4b,
1245 0xe4,0x40,0x55,0xa6,0x19,0xd9,0xdd,0x7f,0xc3,0x16,
1246 0x6f,0x94,0x87,0xf7,0xcb,0x27,0x29,0x12,0x42,0x64,
1247 0x45,0x99,0x85,0x14,0xc1,0x5d,0x53,0xa1,0x8c,0x86,
1248 0x4c,0xe3,0xa2,0xb7,0x55,0x57,0x93,0x98,0x81,0x26,
1249 0x52,0x0e,0xac,0xf2,0xe3,0x06,0x6e,0x23,0x0c,0x91,
1250 0xbe,0xe4,0xdd,0x53,0x04,0xf5,0xfd,0x04,0x05,0xb3,
1251 0x5b,0xd9,0x9c,0x73,0x13,0x5d,0x3d,0x9b,0xc3,0x35,
1252 0xee,0x04,0x9e,0xf6,0x9b,0x38,0x67,0xbf,0x2d,0x7b,
1253 0xd1,0xea,0xa5,0x95,0xd8,0xbf,0xc0,0x06,0x6f,0xf8,
1254 0xd3,0x15,0x09,0xeb,0x0c,0x6c,0xaa,0x00,0x6c,0x80,
1255 0x7a,0x62,0x3e,0xf8,0x4c,0x3d,0x33,0xc1,0x95,0xd2,
1256 0x3e,0xe3,0x20,0xc4,0x0d,0xe0,0x55,0x81,0x57,0xc8,
1257 0x22,0xd4,0xb8,0xc5,0x69,0xd8,0x49,0xae,0xd5,0x9d,
1258 0x4e,0x0f,0xd7,0xf3,0x79,0x58,0x6b,0x4b,0x7f,0xf6,
1259 0x84,0xed,0x6a,0x18,0x9f,0x74,0x86,0xd4,0x9b,0x9c,
1260 0x4b,0xad,0x9b,0xa2,0x4b,0x96,0xab,0xf9,0x24,0x37,
1261 0x2c,0x8a,0x8f,0xff,0xb1,0x0d,0x55,0x35,0x49,0x00,
1262 0xa7,0x7a,0x3d,0xb5,0xf2,0x05,0xe1,0xb9,0x9f,0xcd,
1263 0x86,0x60,0x86,0x3a,0x15,0x9a,0xd4,0xab,0xe4,0x0f,
1264 0xa4,0x89,0x34,0x16,0x3d,0xdd,0xe5,0x42,0xa6,0x58,
1265 0x55,0x40,0xfd,0x68,0x3c,0xbf,0xd8,0xc0,0x0f,0x12,
1266 0x12,0x9a,0x28,0x4d,0xea,0xcc,0x4c,0xde,0xfe,0x58,
1267 0xbe,0x71,0x37,0x54,0x1c,0x04,0x71,0x26,0xc8,0xd4,
1268 0x9e,0x27,0x55,0xab,0x18,0x1a,0xb7,0xe9,0x40,0xb0,
1273 bool pass=
true, fail;
1276 cout <<
"\nARC4 validation suite running...\n\n";
1278 arc4.reset(
new Weak::ARC4(Key0,
sizeof(Key0)));
1279 arc4->ProcessString(Input0,
sizeof(Input0));
1280 fail = memcmp(Input0, Output0,
sizeof(Input0)) != 0;
1281 cout << (fail ?
"FAILED" :
"passed") <<
" Test 0" << endl;
1282 pass = pass && !fail;
1284 arc4.reset(
new Weak::ARC4(Key1,
sizeof(Key1)));
1285 arc4->ProcessString(Key1, Input1,
sizeof(Key1));
1286 fail = memcmp(Output1, Key1,
sizeof(Key1)) != 0;
1287 cout << (fail ?
"FAILED" :
"passed") <<
" Test 1" << endl;
1288 pass = pass && !fail;
1290 arc4.reset(
new Weak::ARC4(Key2,
sizeof(Key2)));
1291 for (i=0, fail=
false; i<
sizeof(Input2); i++)
1292 if (arc4->ProcessByte(Input2[i]) != Output2[i])
1294 cout << (fail ?
"FAILED" :
"passed") <<
" Test 2" << endl;
1295 pass = pass && !fail;
1297 arc4.reset(
new Weak::ARC4(Key3,
sizeof(Key3)));
1298 for (i=0, fail=
false; i<
sizeof(Input3); i++)
1299 if (arc4->ProcessByte(Input3[i]) != Output3[i])
1301 cout << (fail ?
"FAILED" :
"passed") <<
" Test 3" << endl;
1302 pass = pass && !fail;
1304 arc4.reset(
new Weak::ARC4(Key4,
sizeof(Key4)));
1305 for (i=0, fail=
false; i<
sizeof(Input4); i++)
1306 if (arc4->ProcessByte(Input4[i]) != Output4[i])
1308 cout << (fail ?
"FAILED" :
"passed") <<
" Test 4" << endl;
1309 pass = pass && !fail;
1316 cout <<
"\nRC5 validation suite running...\n\n";
1324 cout <<
"\nRC6 validation suite running...\n\n";
1336 cout <<
"\nMARS validation suite running...\n\n";
1346 bool ValidateRijndael()
1348 cout <<
"\nRijndael (AES) validation suite running...\n\n";
1355 pass = RunTestDataFile(PACKAGE_DATA_DIR
"TestVectors/aes.txt") && pass;
1359 bool ValidateTwofish()
1361 cout <<
"\nTwofish validation suite running...\n\n";
1371 bool ValidateSerpent()
1373 cout <<
"\nSerpent validation suite running...\n\n";
1383 bool ValidateBlowfish()
1385 cout <<
"\nBlowfish validation suite running...\n\n";
1388 const char *key[]={
"abcdefghijklmnopqrstuvwxyz",
"Who is John Galt?"};
1389 byte *plain[]={(byte *)
"BLOWFISH", (byte *)
"\xfe\xdc\xba\x98\x76\x54\x32\x10"};
1390 byte *cipher[]={(byte *)
"\x32\x4e\xd0\xfe\xf4\x13\xa2\x03", (byte *)
"\xcc\x91\x73\x2b\x80\x22\xf6\x84"};
1391 byte out[8], outplain[8];
1392 bool pass=
true, fail;
1394 for (
int i=0; i<2; i++)
1397 enc.ProcessData(out, plain[i], 8);
1398 fail = memcmp(out, cipher[i], 8) != 0;
1401 dec.ProcessData(outplain, cipher[i], 8);
1402 fail = fail || memcmp(outplain, plain[i], 8);
1403 pass = pass && !fail;
1405 cout << (fail ?
"FAILED " :
"passed ");
1406 cout <<
'\"' << key[i] <<
'\"';
1407 for (
int j=0; j<(
signed int)(30-strlen(key[i])); j++)
1409 output.
Put(outplain, 8);
1417 bool ValidateThreeWay()
1419 cout <<
"\n3-WAY validation suite running...\n\n";
1427 cout <<
"\nGOST validation suite running...\n\n";
1433 bool ValidateSHARK()
1435 cout <<
"\nSHARK validation suite running...\n\n";
1445 cout <<
"\nCAST-128 validation suite running...\n\n";
1452 cout <<
"\nCAST-256 validation suite running...\n\n";
1462 bool ValidateSquare()
1464 cout <<
"\nSquare validation suite running...\n\n";
1470 bool ValidateSKIPJACK()
1472 cout <<
"\nSKIPJACK validation suite running...\n\n";
1480 byte input[] = {0x37,0xa0,0x05,0x95,0x9b,0x84,0xc4,0x9c,0xa4,0xbe,0x1e,0x05,0x06,0x73,0x53,0x0f,0x5f,0xb0,0x97,0xfd,0xf6,0xa1,0x3f,0xbd,0x6c,0x2c,0xde,0xcd,0x81,0xfd,0xee,0x7c};
1482 byte key[] = {0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x89, 0x98, 0xba, 0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76, 0xc3, 0xd2, 0xe1, 0xf0};
1483 byte iv[] = {0x01, 0x35, 0x77, 0xaf};
1485 cout <<
"\nSEAL validation suite running...\n\n";
1488 unsigned int size =
sizeof(input);
1491 memset(output, 1, size);
1492 seal.ProcessString(output, input, size);
1493 for (
unsigned int i=0; i<size; i++)
1498 output[1] = seal.ProcessByte(output[1]);
1499 seal.ProcessString(output+2, size-2);
1500 pass = pass && memcmp(output+1, input+1, size-1) == 0;
1502 cout << (pass ?
"passed" :
"FAILED") << endl;
1506 bool ValidateBaseCode()
1508 bool pass =
true, fail;
1510 for (
unsigned int i=0; i<255; i++)
1512 static const char hexEncoded[] =
1513 "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627" 1514 "28292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F" 1515 "505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F7071727374757677" 1516 "78797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F" 1517 "A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7" 1518 "C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF" 1519 "F0F1F2F3F4F5F6F7F8F9FAFBFCFDFE";
1520 static const char base32Encoded[] =
1521 "AAASEA2EAWDAQCAJBIFS2DIQB6IBCESVCSKTNF22DEPBYHA7D2RUAIJCENUCKJTHFAWUWK3NFWZC8NBT" 1522 "GI3VIPJYG66DUQT5HS8V6R4AIFBEGTCFI3DWSUKKJPGE4VURKBIXEW4WKXMFQYC3MJPX2ZK8M7SGC2VD" 1523 "NTUYN35IPFXGY5DPP3ZZA6MUQP4HK7VZRB6ZW856RX9H9AEBSKB2JBNGS8EIVCWMTUG27D6SUGJJHFEX" 1524 "U4M3TGN4VQQJ5HW9WCS4FI7EWYVKRKFJXKX43MPQX82MDNXVYU45PP72ZG7MZRF7Z496BSQC2RCNMTYH" 1525 "3DE6XU8N3ZHN9WGT4MJ7JXQY49NPVYY55VQ77Z9A6HTQH3HF65V8T4RK7RYQ55ZR8D29F69W8Z5RR8H3" 1527 const char *base64AndHexEncoded =
1528 "41414543417751464267634943516F4C4441304F4478415245684D554652595847426B6147787764" 1529 "486838674953496A4A43556D4A7967704B6973734C5334764D4445794D7A51310A4E6A63344F546F" 1530 "375044302B50304242516B4E4552555A4853456C4B5330784E546B395155564A5456465657563168" 1531 "5A576C746358563566594746695932526C5A6D646F615770720A6247317562334278636E4E306458" 1532 "5A3365486C3665337839666E2B4167594B44684957476834694A696F754D6A5936506B4A47536B35" 1533 "53566C7065596D5A71626E4A32656E3643680A6F714F6B7061616E714B6D717136797472712B7773" 1534 "624B7A744C573274376935757275387662362F774D484377385446787366497963724C7A4D334F7A" 1535 "39445230745055316462580A324E6E6132397A6433742F6734654C6A354F586D352B6A7036757673" 1536 "3765377638504879382F5431397666342B6672372F50332B0A";
1538 cout <<
"\nBase64, base32 and hex coding validation suite running...\n\n";
1540 fail = !TestFilter(
HexEncoder().Ref(), data, 255, (
const byte *)hexEncoded, strlen(hexEncoded));
1541 cout << (fail ?
"FAILED " :
"passed ");
1542 cout <<
"Hex Encoding\n";
1543 pass = pass && !fail;
1545 fail = !TestFilter(
HexDecoder().Ref(), (
const byte *)hexEncoded, strlen(hexEncoded), data, 255);
1546 cout << (fail ?
"FAILED " :
"passed ");
1547 cout <<
"Hex Decoding\n";
1548 pass = pass && !fail;
1550 fail = !TestFilter(
Base32Encoder().Ref(), data, 255, (
const byte *)base32Encoded, strlen(base32Encoded));
1551 cout << (fail ?
"FAILED " :
"passed ");
1552 cout <<
"Base32 Encoding\n";
1553 pass = pass && !fail;
1555 fail = !TestFilter(
Base32Decoder().Ref(), (
const byte *)base32Encoded, strlen(base32Encoded), data, 255);
1556 cout << (fail ?
"FAILED " :
"passed ");
1557 cout <<
"Base32 Decoding\n";
1558 pass = pass && !fail;
1560 fail = !TestFilter(
Base64Encoder(
new HexEncoder).Ref(), data, 255, (
const byte *)base64AndHexEncoded, strlen(base64AndHexEncoded));
1561 cout << (fail ?
"FAILED " :
"passed ");
1562 cout <<
"Base64 Encoding\n";
1563 pass = pass && !fail;
1565 fail = !TestFilter(
HexDecoder(
new Base64Decoder).Ref(), (
const byte *)base64AndHexEncoded, strlen(base64AndHexEncoded), data, 255);
1566 cout << (fail ?
"FAILED " :
"passed ");
1567 cout <<
"Base64 Decoding\n";
1568 pass = pass && !fail;
1573 bool ValidateSHACAL2()
1575 cout <<
"\nSHACAL-2 validation suite running...\n\n";
1584 bool ValidateCamellia()
1586 cout <<
"\nCamellia validation suite running...\n\n";
1596 bool ValidateSalsa()
1598 cout <<
"\nSalsa validation suite running...\n";
1600 return RunTestDataFile(PACKAGE_DATA_DIR
"TestVectors/salsa.txt");
1603 bool ValidateSosemanuk()
1605 cout <<
"\nSosemanuk validation suite running...\n";
1606 return RunTestDataFile(PACKAGE_DATA_DIR
"TestVectors/sosemanuk.txt");
1611 cout <<
"\nVMAC validation suite running...\n";
1612 return RunTestDataFile(PACKAGE_DATA_DIR
"TestVectors/vmac.txt");
1617 cout <<
"\nAES/CCM validation suite running...\n";
1618 return RunTestDataFile(PACKAGE_DATA_DIR
"TestVectors/ccm.txt");
1623 cout <<
"\nAES/GCM validation suite running...\n";
1624 cout <<
"\n2K tables:";
1626 cout <<
"\n64K tables:";
1632 cout <<
"\nCMAC validation suite running...\n";
1633 return RunTestDataFile(PACKAGE_DATA_DIR
"TestVectors/cmac.txt");
Base class for all exceptions thrown by Crypto++.
OFB block cipher mode of operation.
Wrapper class for /dev/random and /dev/srandom.
Class file for modes of operation.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
This file contains helper classes/functions for implementing public key algorithms.
Hardware generated random numbers using RDRAND instruction.
file-based implementation of Source interface
Converts given data to base 16.
Classes for the RC5 block cipher.
virtual word32 GenerateWord32(word32 min=0, word32 max=0xffffffffUL)
Generate a random 32 bit word in the range min to max, inclusive.
Decode base 16 data back to bytes.
Abstract base classes that provide a uniform interface to this library.
void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memcpy()
Classes for the RC2 block cipher.
BufferedTransformation & TheBitBucket()
An input discarding BufferedTransformation.
Manages resources for an array of objects.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
virtual void DiscardBytes(size_t n)
Generate and discard n bytes.
Classes for automatic resource management.
DEFLATE (RFC 1951) compressor.
Classes for the GIST block cipher.
Classes for the Cameliia block cipher.
Classes for RDRAND and RDSEED.
Classes for Base32Encoder and Base32Decoder.
SecByteBlock is a SecBlock<byte> typedef.
Classes for the RC6 block cipher.
Classes for the Twofish block cipher.
1 and 0's padding added to a block
Classes for the Blowfish block cipher.
Copy input to a memory buffer.
Classes for the MARS block cipher (IBM AES submission)
const char * TableSize()
int, in bytes
Classes for the SKIPJACK block cipher.
virtual void DiscardBytes(size_t n)
Generate and discard n bytes.
Filter Wrapper for HashTransformation.
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Exception thrown when an operating system error is encountered.
virtual void Resynchronize(const byte *iv, int ivLength=-1)
resynchronize with an IV. ivLength=-1 means use IVSize()
Classes for HexEncoder and HexDecoder.
Maurer's Universal Statistical Test for Random Bit Generators.
virtual void DiscardBytes(size_t n)
Generate and discard n bytes.
Automatically Seeded Randomness Pool.
Class file for the AES cipher (Rijndael)
Classes for the CAST-128 and CAST-256 block ciphers.
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Provides class member functions to key a block cipher.
Classes for DMAC message authentication code.
Implementation of schemes based on DL over GF(p)
bool IsPowerOf2(const T &value)
Tests whether a value is a power of 2.
Miscellaneous classes for RNGs.
Classes for SEAL stream cipher.
Redirect input to another BufferedTransformation without owning it.
Classes for Rijndael encryption algorithm.
Classes, functions, intrinsics and features for X86, X32 nd X64 assembly.
Classes for DES, 2-key Triple-DES, 3-key Triple-DES and DESX.
Implementation of BufferedTransformation's attachment interface in cryptlib.h.
Hardware generated random numbers using RDSEED instruction.
Classes for the Base64Encoder, Base64Decoder, Base64URLEncoder and Base64URLDecoder.
Classes for the SAFER block cipher.
Base class for unflushable filters.
Wrapper class for /dev/random and /dev/srandom.
0's padding added to a block
measure how many byte and messages pass through, also serves as valve
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
Classes for the 3-Way block cipher.
No padding added to a block.
Classes and functions for Elliptic Curves over prime and binary fields.
Classes for the Serpent block cipher.
Crypto++ library namespace.
Class specific methods used to operate the cipher in the reverse direction.
RNG-based implementation of Source interface.
Classes for the SHARK block cipher.
Class specific methods used to operate the cipher in the forward direction.
file-based implementation of Sink interface
Classes for the Square block cipher.
virtual void GetNextIV(RandomNumberGenerator &rng, byte *iv)
Gets a secure IV for the next message.
virtual unsigned int IVSize() const
Returns length of the IV accepted by this object.
Classes for access to the operating system's random number generators.
Classes for the IDEA block cipher.