summaryrefslogtreecommitdiff
path: root/fipstest.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-04-15 00:38:48 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-04-15 00:38:48 +0000
commit78cbd84a0068db09b6d08ff14a316800ad9be89a (patch)
tree2be608b49b99003d7d6f49ac33abd7bbe763d7d9 /fipstest.cpp
parent0a0244dacface689335de6e0edf978b29ddb66e1 (diff)
downloadcryptopp-78cbd84a0068db09b6d08ff14a316800ad9be89a.tar.gz
fix bug in Grouper
add RIPEMD-???, Whirlpool, Shacal2, Camellia, Two-Track MAC (Kevin Springle) change ChannelSwitch to allow non-blocking input (denis bider) change Redirector to allow more options (denis bider) fix MaurerRandomnessTest optimize MD2 (Kevin Springle) git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@55 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'fipstest.cpp')
-rw-r--r--fipstest.cpp42
1 files changed, 39 insertions, 3 deletions
diff --git a/fipstest.cpp b/fipstest.cpp
index 10368ae..9f740f0 100644
--- a/fipstest.cpp
+++ b/fipstest.cpp
@@ -42,6 +42,7 @@ void X917RNG_KnownAnswerTest(
unsigned int deterministicTimeVector,
CIPHER *dummy = NULL)
{
+#ifdef OS_RNG_AVAILABLE
std::string decodedKey, decodedSeed;
StringSource(key, true, new HexDecoder(new StringSink(decodedKey)));
StringSource(seed, true, new HexDecoder(new StringSink(decodedSeed)));
@@ -49,6 +50,9 @@ void X917RNG_KnownAnswerTest(
AutoSeededX917RNG<CIPHER> rng;
rng.Reseed((const byte *)decodedKey.data(), decodedKey.size(), (const byte *)decodedSeed.data(), deterministicTimeVector);
KnownAnswerTest(rng, output);
+#else
+ throw 0;
+#endif
}
void KnownAnswerTest(StreamTransformation &encryption, StreamTransformation &decryption, const char *plaintext, const char *ciphertext)
@@ -128,19 +132,25 @@ void MAC_KnownAnswerTest(const char *key, const char *message, const char *diges
template <class SCHEME>
void SignatureKnownAnswerTest(const char *key, const char *message, const char *signature, SCHEME *dummy = NULL)
{
+#ifdef OS_RNG_AVAILABLE
+ AutoSeededX917RNG<DES_EDE3> rng;
+#else
+ RandomNumberGenerator &rng = NullRNG();
+#endif
+
typename SCHEME::Signer signer(StringSource(key, true, new HexDecoder).Ref());
typename SCHEME::Verifier verifier(signer);
EqualityComparisonFilter comparison;
- StringSource(message, true, new SignerFilter(NullRNG(), signer, new ChannelSwitch(comparison, "0")));
+ StringSource(message, true, new SignerFilter(rng, signer, new ChannelSwitch(comparison, "0")));
StringSource(signature, true, new HexDecoder(new ChannelSwitch(comparison, "1")));
comparison.ChannelMessageSeriesEnd("0");
comparison.ChannelMessageSeriesEnd("1");
VerifierFilter verifierFilter(verifier, NULL, VerifierFilter::SIGNATURE_AT_BEGIN | VerifierFilter::THROW_EXCEPTION);
- StringSource(signature, true, new HexDecoder(new Redirector(verifierFilter, false)));
+ StringSource(signature, true, new HexDecoder(new Redirector(verifierFilter, Redirector::DATA_ONLY)));
StringSource(message, true, new Redirector(verifierFilter));
}
@@ -222,7 +232,33 @@ void DoPowerUpSelfTest(const char *moduleFilename, const byte *expectedModuleSha
SHA1 sha;
HashVerifier verifier(sha);
verifier.Put(expectedModuleSha1Digest, sha.DigestSize());
- FileStore(moduleFilename).TransferAllTo(verifier);
+ FileStore file(moduleFilename);
+
+#ifdef CRYPTOPP_WIN32_AVAILABLE
+ // try to hash from memory first
+ HMODULE h = GetModuleHandle(moduleFilename);
+ IMAGE_DOS_HEADER *ph = (IMAGE_DOS_HEADER *)h;
+ IMAGE_NT_HEADERS *phnt = (IMAGE_NT_HEADERS *)((byte *)h + ph->e_lfanew);
+ IMAGE_SECTION_HEADER *phs = (IMAGE_SECTION_HEADER *)((byte *)&phnt->OptionalHeader + phnt->FileHeader.SizeOfOptionalHeader);
+ DWORD SectionSize = STDMIN(phs->SizeOfRawData, phs->Misc.VirtualSize);
+
+ file.TransferTo(verifier, phs->PointerToRawData);
+ verifier.Put((const byte *)h + phs->VirtualAddress, SectionSize);
+ file.Skip(SectionSize);
+#endif
+ file.TransferAllTo(verifier);
+
+#ifdef CRYPTOPP_WIN32_AVAILABLE
+ // if that fails (could be caused by debug breakpoints or DLL base relocation modifying image in memory),
+ // hash from disk instead
+ if (!verifier.GetLastResult())
+ {
+ verifier.Put(expectedModuleSha1Digest, sha.DigestSize());
+ file.Initialize(MakeParameters(Name::InputFileName(), moduleFilename));
+ file.TransferAllTo(verifier);
+ }
+#endif
+
if (!verifier.GetLastResult())
{
#ifdef CRYPTOPP_WIN32_AVAILABLE