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