00001
00002
00003 #include "pch.h"
00004
00005 #ifndef CRYPTOPP_IMPORTS
00006
00007 #define CRYPTOPP_DEFAULT_NO_DLL
00008 #include "dll.h"
00009 #include "cryptlib.h"
00010 #include "filters.h"
00011 #include "smartptr.h"
00012 #include "misc.h"
00013
00014 #ifdef CRYPTOPP_WIN32_AVAILABLE
00015 #define _WIN32_WINNT 0x0400
00016 #include <windows.h>
00017
00018 #if defined(_MSC_VER) && _MSC_VER >= 1400
00019 #ifdef _M_IX86
00020 #define _CRT_DEBUGGER_HOOK _crt_debugger_hook
00021 #else
00022 #define _CRT_DEBUGGER_HOOK __crt_debugger_hook
00023 #endif
00024 extern "C" {_CRTIMP void __cdecl _CRT_DEBUGGER_HOOK(int);}
00025 #endif
00026 #endif
00027
00028 #include <iostream>
00029
00030 #if CRYPTOPP_MSC_VERSION
00031 # pragma warning(disable: 4100)
00032 #endif
00033
00034 NAMESPACE_BEGIN(CryptoPP)
00035
00036 extern PowerUpSelfTestStatus g_powerUpSelfTestStatus;
00037 SecByteBlock g_actualMac;
00038 unsigned long g_macFileLocation = 0;
00039
00040
00041 static const byte s_moduleMac[CryptoPP::HMAC<CryptoPP::SHA1>::DIGESTSIZE] = CRYPTOPP_DUMMY_DLL_MAC;
00042 CRYPTOPP_COMPILE_ASSERT(sizeof(s_moduleMac) == CryptoPP::SHA1::DIGESTSIZE);
00043
00044 #ifdef CRYPTOPP_WIN32_AVAILABLE
00045 static HMODULE s_hModule = NULL;
00046 #endif
00047
00048 const byte * CRYPTOPP_API GetActualMacAndLocation(unsigned int &macSize, unsigned int &fileLocation)
00049 {
00050 macSize = (unsigned int)g_actualMac.size();
00051 fileLocation = g_macFileLocation;
00052 return g_actualMac;
00053 }
00054
00055 void KnownAnswerTest(RandomNumberGenerator &rng, const char *output)
00056 {
00057 EqualityComparisonFilter comparison;
00058
00059 RandomNumberStore(rng, strlen(output)/2).TransferAllTo(comparison, "0");
00060 StringSource(output, true, new HexDecoder(new ChannelSwitch(comparison, "1")));
00061
00062 comparison.ChannelMessageSeriesEnd("0");
00063 comparison.ChannelMessageSeriesEnd("1");
00064 }
00065
00066 template <class CIPHER>
00067 void X917RNG_KnownAnswerTest(
00068 const char *key,
00069 const char *seed,
00070 const char *deterministicTimeVector,
00071 const char *output,
00072 CIPHER *dummy = NULL)
00073 {
00074 CRYPTOPP_UNUSED(dummy);
00075 #ifdef OS_RNG_AVAILABLE
00076 std::string decodedKey, decodedSeed, decodedDeterministicTimeVector;
00077 StringSource(key, true, new HexDecoder(new StringSink(decodedKey)));
00078 StringSource(seed, true, new HexDecoder(new StringSink(decodedSeed)));
00079 StringSource(deterministicTimeVector, true, new HexDecoder(new StringSink(decodedDeterministicTimeVector)));
00080
00081 AutoSeededX917RNG<CIPHER> rng(false, false);
00082 rng.Reseed((const byte *)decodedKey.data(), decodedKey.size(), (const byte *)decodedSeed.data(), (const byte *)decodedDeterministicTimeVector.data());
00083 KnownAnswerTest(rng, output);
00084 #else
00085 throw 0;
00086 #endif
00087 }
00088
00089 void KnownAnswerTest(StreamTransformation &encryption, StreamTransformation &decryption, const char *plaintext, const char *ciphertext)
00090 {
00091 EqualityComparisonFilter comparison;
00092
00093 StringSource(plaintext, true, new HexDecoder(new StreamTransformationFilter(encryption, new ChannelSwitch(comparison, "0"), StreamTransformationFilter::NO_PADDING)));
00094 StringSource(ciphertext, true, new HexDecoder(new ChannelSwitch(comparison, "1")));
00095
00096 StringSource(ciphertext, true, new HexDecoder(new StreamTransformationFilter(decryption, new ChannelSwitch(comparison, "0"), StreamTransformationFilter::NO_PADDING)));
00097 StringSource(plaintext, true, new HexDecoder(new ChannelSwitch(comparison, "1")));
00098
00099 comparison.ChannelMessageSeriesEnd("0");
00100 comparison.ChannelMessageSeriesEnd("1");
00101 }
00102
00103 template <class CIPHER>
00104 void SymmetricEncryptionKnownAnswerTest(
00105 const char *key,
00106 const char *hexIV,
00107 const char *plaintext,
00108 const char *ecb,
00109 const char *cbc,
00110 const char *cfb,
00111 const char *ofb,
00112 const char *ctr,
00113 CIPHER *dummy = NULL)
00114 {
00115 CRYPTOPP_UNUSED(dummy);
00116 std::string decodedKey;
00117 StringSource(key, true, new HexDecoder(new StringSink(decodedKey)));
00118
00119 typename CIPHER::Encryption encryption((const byte *)decodedKey.data(), decodedKey.size());
00120 typename CIPHER::Decryption decryption((const byte *)decodedKey.data(), decodedKey.size());
00121
00122 SecByteBlock iv(encryption.BlockSize());
00123 StringSource(hexIV, true, new HexDecoder(new ArraySink(iv, iv.size())));
00124
00125 if (ecb)
00126 KnownAnswerTest(ECB_Mode_ExternalCipher::Encryption(encryption).Ref(), ECB_Mode_ExternalCipher::Decryption(decryption).Ref(), plaintext, ecb);
00127 if (cbc)
00128 KnownAnswerTest(CBC_Mode_ExternalCipher::Encryption(encryption, iv).Ref(), CBC_Mode_ExternalCipher::Decryption(decryption, iv).Ref(), plaintext, cbc);
00129 if (cfb)
00130 KnownAnswerTest(CFB_Mode_ExternalCipher::Encryption(encryption, iv).Ref(), CFB_Mode_ExternalCipher::Decryption(encryption, iv).Ref(), plaintext, cfb);
00131 if (ofb)
00132 KnownAnswerTest(OFB_Mode_ExternalCipher::Encryption(encryption, iv).Ref(), OFB_Mode_ExternalCipher::Decryption(encryption, iv).Ref(), plaintext, ofb);
00133 if (ctr)
00134 KnownAnswerTest(CTR_Mode_ExternalCipher::Encryption(encryption, iv).Ref(), CTR_Mode_ExternalCipher::Decryption(encryption, iv).Ref(), plaintext, ctr);
00135 }
00136
00137 void KnownAnswerTest(HashTransformation &hash, const char *message, const char *digest)
00138 {
00139 EqualityComparisonFilter comparison;
00140 StringSource(digest, true, new HexDecoder(new ChannelSwitch(comparison, "1")));
00141 StringSource(message, true, new HashFilter(hash, new ChannelSwitch(comparison, "0")));
00142
00143 comparison.ChannelMessageSeriesEnd("0");
00144 comparison.ChannelMessageSeriesEnd("1");
00145 }
00146
00147 template <class HASH>
00148 void SecureHashKnownAnswerTest(const char *message, const char *digest, HASH *dummy = NULL)
00149 {
00150 CRYPTOPP_UNUSED(dummy);
00151 HASH hash;
00152 KnownAnswerTest(hash, message, digest);
00153 }
00154
00155 template <class MAC>
00156 void MAC_KnownAnswerTest(const char *key, const char *message, const char *digest, MAC *dummy = NULL)
00157 {
00158 CRYPTOPP_UNUSED(dummy);
00159 std::string decodedKey;
00160 StringSource(key, true, new HexDecoder(new StringSink(decodedKey)));
00161
00162 MAC mac((const byte *)decodedKey.data(), decodedKey.size());
00163 KnownAnswerTest(mac, message, digest);
00164 }
00165
00166 template <class SCHEME>
00167 void SignatureKnownAnswerTest(const char *key, const char *message, const char *signature, SCHEME *dummy = NULL)
00168 {
00169 typename SCHEME::Signer signer(StringSource(key, true, new HexDecoder).Ref());
00170 typename SCHEME::Verifier verifier(signer);
00171
00172 CRYPTOPP_UNUSED(dummy);
00173 RandomPool rng;
00174 EqualityComparisonFilter comparison;
00175
00176 StringSource(message, true, new SignerFilter(rng, signer, new ChannelSwitch(comparison, "0")));
00177 StringSource(signature, true, new HexDecoder(new ChannelSwitch(comparison, "1")));
00178
00179 comparison.ChannelMessageSeriesEnd("0");
00180 comparison.ChannelMessageSeriesEnd("1");
00181
00182 VerifierFilter verifierFilter(verifier, NULL, VerifierFilter::SIGNATURE_AT_BEGIN | VerifierFilter::THROW_EXCEPTION);
00183 StringSource(signature, true, new HexDecoder(new Redirector(verifierFilter, Redirector::DATA_ONLY)));
00184 StringSource(message, true, new Redirector(verifierFilter));
00185 }
00186
00187 void EncryptionPairwiseConsistencyTest(const PK_Encryptor &encryptor, const PK_Decryptor &decryptor)
00188 {
00189 try
00190 {
00191 RandomPool rng;
00192 const char *testMessage ="test message";
00193 std::string ciphertext, decrypted;
00194
00195 StringSource(
00196 testMessage,
00197 true,
00198 new PK_EncryptorFilter(
00199 rng,
00200 encryptor,
00201 new StringSink(ciphertext)));
00202
00203 if (ciphertext == testMessage)
00204 throw 0;
00205
00206 StringSource(
00207 ciphertext,
00208 true,
00209 new PK_DecryptorFilter(
00210 rng,
00211 decryptor,
00212 new StringSink(decrypted)));
00213
00214 if (decrypted != testMessage)
00215 throw 0;
00216 }
00217 catch (...)
00218 {
00219 throw SelfTestFailure(encryptor.AlgorithmName() + ": pairwise consistency test failed");
00220 }
00221 }
00222
00223 void SignaturePairwiseConsistencyTest(const PK_Signer &signer, const PK_Verifier &verifier)
00224 {
00225 try
00226 {
00227 RandomPool rng;
00228
00229 StringSource(
00230 "test message",
00231 true,
00232 new SignerFilter(
00233 rng,
00234 signer,
00235 new VerifierFilter(verifier, NULL, VerifierFilter::THROW_EXCEPTION),
00236 true));
00237 }
00238 catch (...)
00239 {
00240 throw SelfTestFailure(signer.AlgorithmName() + ": pairwise consistency test failed");
00241 }
00242 }
00243
00244 template <class SCHEME>
00245 void SignaturePairwiseConsistencyTest(const char *key, SCHEME *dummy = NULL)
00246 {
00247 typename SCHEME::Signer signer(StringSource(key, true, new HexDecoder).Ref());
00248 typename SCHEME::Verifier verifier(signer);
00249
00250 CRYPTOPP_UNUSED(dummy);
00251 SignaturePairwiseConsistencyTest(signer, verifier);
00252 }
00253
00254 MessageAuthenticationCode * NewIntegrityCheckingMAC()
00255 {
00256 byte key[] = {0x47, 0x1E, 0x33, 0x96, 0x65, 0xB1, 0x6A, 0xED, 0x0B, 0xF8, 0x6B, 0xFD, 0x01, 0x65, 0x05, 0xCC};
00257 return new HMAC<SHA1>(key, sizeof(key));
00258 }
00259
00260 bool IntegrityCheckModule(const char *moduleFilename, const byte *expectedModuleMac, SecByteBlock *pActualMac, unsigned long *pMacFileLocation)
00261 {
00262 member_ptr<MessageAuthenticationCode> mac(NewIntegrityCheckingMAC());
00263 unsigned int macSize = mac->DigestSize();
00264
00265 SecByteBlock tempMac;
00266 SecByteBlock &actualMac = pActualMac ? *pActualMac : tempMac;
00267 actualMac.resize(macSize);
00268
00269 unsigned long tempLocation = 0;
00270 unsigned long &macFileLocation = pMacFileLocation ? *pMacFileLocation : tempLocation;
00271 macFileLocation = 0;
00272
00273 MeterFilter verifier(new HashFilter(*mac, new ArraySink(actualMac, actualMac.size())));
00274
00275 std::ifstream moduleStream;
00276
00277 #ifdef CRYPTOPP_WIN32_AVAILABLE
00278 HMODULE h = NULL;
00279 {
00280 char moduleFilenameBuf[MAX_PATH] = "";
00281 if (moduleFilename == NULL)
00282 {
00283 #if (_MSC_VER >= 1400 && !defined(_STLPORT_VERSION)) // ifstream doesn't support wide filename on other compilers
00284 wchar_t wideModuleFilename[MAX_PATH];
00285 if (GetModuleFileNameW(s_hModule, wideModuleFilename, MAX_PATH) > 0)
00286 {
00287 moduleStream.open(wideModuleFilename, std::ios::in | std::ios::binary);
00288 h = GetModuleHandleW(wideModuleFilename);
00289 }
00290 else
00291 #endif
00292 {
00293 GetModuleFileNameA(s_hModule, moduleFilenameBuf, MAX_PATH);
00294 moduleFilename = moduleFilenameBuf;
00295 }
00296 }
00297 #endif
00298 if (moduleFilename != NULL)
00299 {
00300 moduleStream.open(moduleFilename, std::ios::in | std::ios::binary);
00301 #ifdef CRYPTOPP_WIN32_AVAILABLE
00302 h = GetModuleHandleA(moduleFilename);
00303 moduleFilename = NULL;
00304 }
00305 #endif
00306 }
00307
00308 if (!moduleStream)
00309 {
00310 #ifdef CRYPTOPP_WIN32_AVAILABLE
00311 OutputDebugString("Crypto++ DLL integrity check failed. Cannot open file for reading.");
00312 #endif
00313 return false;
00314 }
00315 FileStore file(moduleStream);
00316
00317 #ifdef CRYPTOPP_WIN32_AVAILABLE
00318
00319 const byte *memBase = (const byte *)h;
00320 const IMAGE_DOS_HEADER *ph = (IMAGE_DOS_HEADER *)memBase;
00321 const IMAGE_NT_HEADERS *phnt = (IMAGE_NT_HEADERS *)(memBase + ph->e_lfanew);
00322 const IMAGE_SECTION_HEADER *phs = IMAGE_FIRST_SECTION(phnt);
00323 DWORD nSections = phnt->FileHeader.NumberOfSections;
00324 size_t currentFilePos = 0;
00325
00326 size_t checksumPos = (byte *)&phnt->OptionalHeader.CheckSum - memBase;
00327 size_t checksumSize = sizeof(phnt->OptionalHeader.CheckSum);
00328 size_t certificateTableDirectoryPos = (byte *)&phnt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY] - memBase;
00329 size_t certificateTableDirectorySize = sizeof(phnt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
00330 size_t certificateTablePos = phnt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress;
00331 size_t certificateTableSize = phnt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY].Size;
00332
00333 verifier.AddRangeToSkip(0, checksumPos, checksumSize);
00334 verifier.AddRangeToSkip(0, certificateTableDirectoryPos, certificateTableDirectorySize);
00335 verifier.AddRangeToSkip(0, certificateTablePos, certificateTableSize);
00336
00337 while (nSections--)
00338 {
00339 switch (phs->Characteristics)
00340 {
00341 default:
00342 break;
00343 case IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ:
00344 case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ:
00345 unsigned int sectionSize = STDMIN(phs->SizeOfRawData, phs->Misc.VirtualSize);
00346 const byte *sectionMemStart = memBase + phs->VirtualAddress;
00347 unsigned int sectionFileStart = phs->PointerToRawData;
00348 size_t subSectionStart = 0, nextSubSectionStart;
00349
00350 do
00351 {
00352 const byte *subSectionMemStart = sectionMemStart + subSectionStart;
00353 size_t subSectionFileStart = sectionFileStart + subSectionStart;
00354 size_t subSectionSize = sectionSize - subSectionStart;
00355 nextSubSectionStart = 0;
00356
00357 unsigned int entriesToReadFromDisk[] = {IMAGE_DIRECTORY_ENTRY_IMPORT, IMAGE_DIRECTORY_ENTRY_IAT};
00358 for (unsigned int i=0; i<sizeof(entriesToReadFromDisk)/sizeof(entriesToReadFromDisk[0]); i++)
00359 {
00360 const IMAGE_DATA_DIRECTORY &entry = phnt->OptionalHeader.DataDirectory[entriesToReadFromDisk[i]];
00361 const byte *entryMemStart = memBase + entry.VirtualAddress;
00362 if (subSectionMemStart <= entryMemStart && entryMemStart < subSectionMemStart + subSectionSize)
00363 {
00364 subSectionSize = entryMemStart - subSectionMemStart;
00365 nextSubSectionStart = entryMemStart - sectionMemStart + entry.Size;
00366 }
00367 }
00368
00369 #if defined(_MSC_VER) && _MSC_VER >= 1400
00370
00371 if (IsDebuggerPresent())
00372 {
00373 if (subSectionMemStart <= (byte *)&_CRT_DEBUGGER_HOOK && (byte *)&_CRT_DEBUGGER_HOOK < subSectionMemStart + subSectionSize)
00374 {
00375 subSectionSize = (byte *)&_CRT_DEBUGGER_HOOK - subSectionMemStart;
00376 nextSubSectionStart = (byte *)&_CRT_DEBUGGER_HOOK - sectionMemStart + 1;
00377 }
00378 }
00379 #endif
00380
00381 if (subSectionMemStart <= expectedModuleMac && expectedModuleMac < subSectionMemStart + subSectionSize)
00382 {
00383
00384 macFileLocation = (unsigned long)(subSectionFileStart + (expectedModuleMac - subSectionMemStart));
00385 verifier.AddRangeToSkip(0, macFileLocation, macSize);
00386 }
00387
00388 file.TransferTo(verifier, subSectionFileStart - currentFilePos);
00389 verifier.Put(subSectionMemStart, subSectionSize);
00390 file.Skip(subSectionSize);
00391 currentFilePos = subSectionFileStart + subSectionSize;
00392 subSectionStart = nextSubSectionStart;
00393 } while (nextSubSectionStart != 0);
00394 }
00395 phs++;
00396 }
00397 #endif
00398 file.TransferAllTo(verifier);
00399
00400 #ifdef CRYPTOPP_WIN32_AVAILABLE
00401
00402
00403 if (!VerifyBufsEqual(expectedModuleMac, actualMac, macSize))
00404 {
00405 OutputDebugString("In memory integrity check failed. This may be caused by debug breakpoints or DLL relocation.\n");
00406 moduleStream.clear();
00407 moduleStream.seekg(0);
00408 verifier.Initialize(MakeParameters(Name::OutputBuffer(), ByteArrayParameter(actualMac, (unsigned int)actualMac.size())));
00409
00410 verifier.AddRangeToSkip(0, checksumPos, checksumSize);
00411 verifier.AddRangeToSkip(0, certificateTableDirectoryPos, certificateTableDirectorySize);
00412 verifier.AddRangeToSkip(0, certificateTablePos, certificateTableSize);
00413 verifier.AddRangeToSkip(0, macFileLocation, macSize);
00414 FileStore(moduleStream).TransferAllTo(verifier);
00415 }
00416 #endif
00417
00418 if (VerifyBufsEqual(expectedModuleMac, actualMac, macSize))
00419 return true;
00420
00421 #ifdef CRYPTOPP_WIN32_AVAILABLE
00422 std::string hexMac;
00423 HexEncoder(new StringSink(hexMac)).PutMessageEnd(actualMac, actualMac.size());
00424 OutputDebugString((("Crypto++ DLL integrity check failed. Actual MAC is: " + hexMac) + "\n").c_str());
00425 #endif
00426 return false;
00427 }
00428
00429 void DoPowerUpSelfTest(const char *moduleFilename, const byte *expectedModuleMac)
00430 {
00431 g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_NOT_DONE;
00432 SetPowerUpSelfTestInProgressOnThisThread(true);
00433
00434 try
00435 {
00436 if (FIPS_140_2_ComplianceEnabled() || expectedModuleMac != NULL)
00437 {
00438 if (!IntegrityCheckModule(moduleFilename, expectedModuleMac, &g_actualMac, &g_macFileLocation))
00439 throw 0;
00440 }
00441
00442
00443
00444 X917RNG_KnownAnswerTest<AES>(
00445 "2b7e151628aed2a6abf7158809cf4f3c",
00446 "000102030405060708090a0b0c0d0e0f",
00447 "00000000000000000000000000000001",
00448 "D176EDD27493B0395F4D10546232B0693DC7061C03C3A554F09CECF6F6B46D945A");
00449
00450 SymmetricEncryptionKnownAnswerTest<DES_EDE3>(
00451 "385D7189A5C3D485E1370AA5D408082B5CCCCB5E19F2D90E",
00452 "C141B5FCCD28DC8A",
00453 "6E1BD7C6120947A464A6AAB293A0F89A563D8D40D3461B68",
00454 "64EAAD4ACBB9CEAD6C7615E7C7E4792FE587D91F20C7D2F4",
00455 "6235A461AFD312973E3B4F7AA7D23E34E03371F8E8C376C9",
00456 "E26BA806A59B0330DE40CA38E77A3E494BE2B212F6DD624B",
00457 "E26BA806A59B03307DE2BCC25A08BA40A8BA335F5D604C62",
00458 "E26BA806A59B03303C62C2EFF32D3ACDD5D5F35EBCC53371");
00459
00460 SymmetricEncryptionKnownAnswerTest<SKIPJACK>(
00461 "1555E5531C3A169B2D65",
00462 "6EC9795701F49864",
00463 "00AFA48E9621E52E8CBDA312660184EDDB1F33D9DACDA8DA",
00464 "DBEC73562EFCAEB56204EB8AE9557EBF77473FBB52D17CD1",
00465 "0C7B0B74E21F99B8F2C8DF37879F6C044967F42A796DCA8B",
00466 "79FDDA9724E36CC2E023E9A5C717A8A8A7FDA465CADCBF63",
00467 "79FDDA9724E36CC26CACBD83C1ABC06EAF5B249BE5B1E040",
00468 "79FDDA9724E36CC211B0AEC607B95A96BCDA318440B82F49");
00469
00470 SymmetricEncryptionKnownAnswerTest<AES>(
00471 "2b7e151628aed2a6abf7158809cf4f3c",
00472 "000102030405060708090a0b0c0d0e0f",
00473 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710",
00474 "3ad77bb40d7a3660a89ecaf32466ef97f5d3d58503b9699de785895a96fdbaaf43b1cd7f598ece23881b00e3ed0306887b0c785e27e8ad3f8223207104725dd4",
00475 "7649abac8119b246cee98e9b12e9197d5086cb9b507219ee95db113a917678b273bed6b8e3c1743b7116e69e222295163ff1caa1681fac09120eca307586e1a7",
00476 "3b3fd92eb72dad20333449f8e83cfb4ac8a64537a0b3a93fcde3cdad9f1ce58b26751f67a3cbb140b1808cf187a4f4dfc04b05357c5d1c0eeac4c66f9ff7f2e6",
00477 "3b3fd92eb72dad20333449f8e83cfb4a7789508d16918f03f53c52dac54ed8259740051e9c5fecf64344f7a82260edcc304c6528f659c77866a510d9c1d6ae5e",
00478 NULL);
00479
00480 SymmetricEncryptionKnownAnswerTest<AES>(
00481 "2b7e151628aed2a6abf7158809cf4f3c",
00482 "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff",
00483 "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710",
00484 NULL,
00485 NULL,
00486 NULL,
00487 NULL,
00488 "874d6191b620e3261bef6864990db6ce9806f66b7970fdff8617187bb9fffdff5ae4df3edbd5d35e5b4f09020db03eab1e031dda2fbe03d1792170a0f3009cee");
00489
00490
00491 SecureHashKnownAnswerTest<SHA1>(
00492 "abc",
00493 "A9993E364706816ABA3E25717850C26C9CD0D89D");
00494
00495 SecureHashKnownAnswerTest<SHA224>(
00496 "abc",
00497 "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7");
00498
00499 SecureHashKnownAnswerTest<SHA256>(
00500 "abc",
00501 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
00502
00503 SecureHashKnownAnswerTest<SHA384>(
00504 "abc",
00505 "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7");
00506
00507 SecureHashKnownAnswerTest<SHA512>(
00508 "abc",
00509 "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f");
00510
00511 MAC_KnownAnswerTest<HMAC<SHA1> >(
00512 "303132333435363738393a3b3c3d3e3f40414243",
00513 "Sample #2",
00514 "0922d3405faa3d194f82a45830737d5cc6c75d24");
00515
00516 const char *keyRSA1 =
00517 "30820150020100300d06092a864886f70d01010105000482013a3082013602010002400a66791dc6988168de7ab77419bb7fb0"
00518 "c001c62710270075142942e19a8d8c51d053b3e3782a1de5dc5af4ebe99468170114a1dfe67cdc9a9af55d655620bbab0203010001"
00519 "02400123c5b61ba36edb1d3679904199a89ea80c09b9122e1400c09adcf7784676d01d23356a7d44d6bd8bd50e94bfc723fa"
00520 "87d8862b75177691c11d757692df8881022033d48445c859e52340de704bcdda065fbb4058d740bd1d67d29e9c146c11cf61"
00521 "0220335e8408866b0fd38dc7002d3f972c67389a65d5d8306566d5c4f2a5aa52628b0220045ec90071525325d3d46db79695e9af"
00522 "acc4523964360e02b119baa366316241022015eb327360c7b60d12e5e2d16bdcd97981d17fba6b70db13b20b436e24eada590220"
00523 "2ca6366d72781dfa24d34a9a24cbc2ae927a9958af426563ff63fb11658a461d";
00524
00525 const char *keyRSA2 =
00526 "30820273020100300D06092A864886F70D01010105000482025D3082025902010002818100D40AF9"
00527 "A2B713034249E5780056D70FC7DE75D76E44565AA6A6B8ED9646F3C19F9E254D72D7DE6E49DB2264"
00528 "0C1D05AB9E2A5F901D8F3FE1F7AE02CEE2ECCE54A40ABAE55A004692752E70725AEEE7CDEA67628A"
00529 "82A9239B4AB660C2BC56D9F01E90CBAAB9BF0FC8E17173CEFC5709A29391A7DDF3E0B758691AAF30"
00530 "725B292F4F020111027F18C0BA087D082C45D75D3594E0767E4820818EB35612B80CEAB8C880ACA5"
00531 "44B6876DFFEF85A576C0D45B551AFAA1FD63209CD745DF75C5A0F0B580296EA466CD0338207E4752"
00532 "FF4E7DB724D8AE18CE5CF4153BB94C27869FBB50E64F02546E4B02997A0B8623E64017CC770759C6"
00533 "695DB649EEFD829D688D441BCC4E7348F1024100EF86DD7AF3F32CDE8A9F6564E43A559A0C9F8BAD"
00534 "36CC25330548B347AC158A345631FA90F7B873C36EFFAE2F7823227A3F580B5DD18304D5932751E7"
00535 "43E9234F024100E2A039854B55688740E32A51DF4AF88613D91A371CF8DDD95D780A89D7CF2119A9"
00536 "54F1AC0F3DCDB2F6959926E6D9D37D8BC07A4C634DE6F16315BD5F0DAC340102407ECEEDB9903572"
00537 "1B76909F174BA6698DCA72953D957B22C0A871C8531EDE3A1BB52984A719BC010D1CA57A555DB83F"
00538 "6DE54CBAB932AEC652F38D497A6F3F30CF024100854F30E4FF232E6DADB2CD99926855F484255AB7"
00539 "01FBCDCB27EC426F33A7046972AA700ADBCA008763DF87440F52F4E070531AC385B55AAC1C2AE7DD"
00540 "8F9278F1024100C313F4AF9E4A9DE1253C21080CE524251560C111550772FD08690F13FBE658342E"
00541 "BD2D41C9DCB12374E871B1839E26CAE252E1AE3DAAD5F1EE1F42B4D0EE7581";
00542
00543 SignatureKnownAnswerTest<RSASS<PKCS1v15, SHA1> >(
00544 keyRSA1,
00545 "Everyone gets Friday off.",
00546 "0610761F95FFD1B8F29DA34212947EC2AA0E358866A722F03CC3C41487ADC604A48FF54F5C6BEDB9FB7BD59F82D6E55D8F3174BA361B2214B2D74E8825E04E81");
00547
00548 SignatureKnownAnswerTest<RSASS_ISO<SHA1> >(
00549 keyRSA2,
00550 "test",
00551 "32F6BA41C8930DE71EE67F2627172CC539EDE04267FDE03AC295E3C50311F26C3B275D3AF513AC96"
00552 "8EE493BAB7DA3A754661D1A7C4A0D1A2B7EE8B313AACD8CB8BFBC5C15EFB0EF15C86A9334A1E87AD"
00553 "291EB961B5CA0E84930429B28780816AA94F96FC2367B71E2D2E4866FA966795B147F00600E5207E"
00554 "2F189C883B37477C");
00555
00556 SignaturePairwiseConsistencyTest<DSA>(
00557 "3082014A0201003082012B06072A8648CE3804013082011E02818100F468699A6F6EBCC0120D3B34C8E007F125EC7D81F763B8D0F33869AE3BD6B9F2ECCC7DF34DF84C0307449E9B85D30D57194BCCEB310F48141914DD13A077AAF9B624A6CBE666BBA1D7EBEA95B5BA6F54417FD5D4E4220C601E071D316A24EA814E8B0122DBF47EE8AEEFD319EBB01DD95683F10DBB4FEB023F8262A07EAEB7FD02150082AD4E034DA6EEACDFDAE68C36F2BAD614F9E53B02818071AAF73361A26081529F7D84078ADAFCA48E031DB54AD57FB1A833ADBD8672328AABAA0C756247998D7A5B10DACA359D231332CE8120B483A784FE07D46EEBFF0D7D374A10691F78653E6DC29E27CCB1B174923960DFE5B959B919B2C3816C19251832AFD8E35D810E598F82877ABF7D40A041565168BD7F0E21E3FE2A8D8C1C0416021426EBA66E846E755169F84A1DA981D86502405DDF");
00558
00559 SignaturePairwiseConsistencyTest<ECDSA<EC2N, SHA1> >(
00560 "302D020100301006072A8648CE3D020106052B8104000404163014020101040F0070337065E1E196980A9D00E37211");
00561
00562 SignaturePairwiseConsistencyTest<ECDSA<ECP, SHA1> >(
00563 "3039020100301306072A8648CE3D020106082A8648CE3D030101041F301D02010104182BB8A13C8B867010BD9471D9E81FDB01ABD0538C64D6249A");
00564
00565 SignaturePairwiseConsistencyTest<RSASS<PSS, SHA1> >(keyRSA1);
00566 }
00567 catch (...)
00568 {
00569 g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_FAILED;
00570 goto done;
00571 }
00572
00573 g_powerUpSelfTestStatus = POWER_UP_SELF_TEST_PASSED;
00574
00575 done:
00576 SetPowerUpSelfTestInProgressOnThisThread(false);
00577 return;
00578 }
00579
00580 #ifdef CRYPTOPP_WIN32_AVAILABLE
00581
00582 void DoDllPowerUpSelfTest()
00583 {
00584 CryptoPP::DoPowerUpSelfTest(NULL, s_moduleMac);
00585 }
00586
00587 #else
00588
00589 void DoDllPowerUpSelfTest()
00590 {
00591 throw NotImplemented("DoDllPowerUpSelfTest() only available on Windows");
00592 }
00593
00594 #endif // #ifdef CRYPTOPP_WIN32_AVAILABLE
00595
00596 NAMESPACE_END
00597
00598 #ifdef CRYPTOPP_WIN32_AVAILABLE
00599
00600
00601 BOOL APIENTRY DllMain(HANDLE hModule,
00602 DWORD dwReason,
00603 LPVOID )
00604 {
00605 if (dwReason == DLL_PROCESS_ATTACH)
00606 {
00607 CryptoPP::s_hModule = (HMODULE)hModule;
00608 CryptoPP::DoDllPowerUpSelfTest();
00609 }
00610 return TRUE;
00611 }
00612
00613 #endif // #ifdef CRYPTOPP_WIN32_AVAILABLE
00614
00615 #endif // #ifndef CRYPTOPP_IMPORTS