Changed to dynamic_cast for GlobalRNG()
parent
c8860d6fa9
commit
fd300a1c90
20
test.cpp
20
test.cpp
|
|
@ -22,7 +22,7 @@
|
||||||
#include "validate.h"
|
#include "validate.h"
|
||||||
#include "bench.h"
|
#include "bench.h"
|
||||||
|
|
||||||
// CRYPTOPP_ASSERT
|
// CRYPTOPP_ASSERT, includes <signal.h> for BSD, Linux and Unix
|
||||||
#include "trap.h"
|
#include "trap.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
@ -58,10 +58,6 @@ USING_NAMESPACE(CryptoPP)
|
||||||
|
|
||||||
const int MAX_PHRASE_LENGTH=250;
|
const int MAX_PHRASE_LENGTH=250;
|
||||||
|
|
||||||
#if !defined(NDEBUG) && defined(CRYPTOPP_UNIX_AVAILABLE)
|
|
||||||
# include <signal.h> // SIGTRAP handler
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void RegisterFactories();
|
void RegisterFactories();
|
||||||
|
|
||||||
void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed);
|
void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed);
|
||||||
|
|
@ -102,11 +98,11 @@ void FIPS140_GenerateRandomFiles();
|
||||||
|
|
||||||
bool Validate(int, bool, const char *);
|
bool Validate(int, bool, const char *);
|
||||||
|
|
||||||
#if !defined(NDEBUG) && defined(CRYPTOPP_UNIX_AVAILABLE)
|
#if defined(CRYPTOPP_DEBUG) && (defined(CRYPTOPP_BSD_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE))
|
||||||
// Add a SIGTRAP handler for *nix, used by CRYPTOPP_ASSERT.
|
// Add a SIGTRAP handler for BSD, Linux, Unix; used by CRYPTOPP_ASSERT.
|
||||||
struct DebugTrapHandler
|
struct DebugTrapHandler
|
||||||
{
|
{
|
||||||
DebugTrapHandler()
|
explicit DebugTrapHandler()
|
||||||
{
|
{
|
||||||
// http://pubs.opengroup.org/onlinepubs/007908799/xsh/sigaction.html
|
// http://pubs.opengroup.org/onlinepubs/007908799/xsh/sigaction.html
|
||||||
struct sigaction old_handler, new_handler;
|
struct sigaction old_handler, new_handler;
|
||||||
|
|
@ -120,7 +116,7 @@ struct DebugTrapHandler
|
||||||
ret = sigaction (SIGTRAP, NULL, &old_handler);
|
ret = sigaction (SIGTRAP, NULL, &old_handler);
|
||||||
if (ret != 0) break; // Failed
|
if (ret != 0) break; // Failed
|
||||||
|
|
||||||
// Don't step on another's handler
|
// Don't step on another's handler (like a debugger)
|
||||||
if (old_handler.sa_handler != NULL) break;
|
if (old_handler.sa_handler != NULL) break;
|
||||||
|
|
||||||
// Set up the structure to specify the null action.
|
// Set up the structure to specify the null action.
|
||||||
|
|
@ -130,7 +126,7 @@ struct DebugTrapHandler
|
||||||
ret = sigemptyset (&new_handler.sa_mask);
|
ret = sigemptyset (&new_handler.sa_mask);
|
||||||
if (ret != 0) break; // Failed
|
if (ret != 0) break; // Failed
|
||||||
|
|
||||||
// Install i
|
// Install it.
|
||||||
ret = sigaction (SIGTRAP, &new_handler, NULL);
|
ret = sigaction (SIGTRAP, &new_handler, NULL);
|
||||||
if (ret != 0) break; // Failed
|
if (ret != 0) break; // Failed
|
||||||
|
|
||||||
|
|
@ -179,7 +175,7 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||||
std::string seed = IntToString(time(NULL));
|
std::string seed = IntToString(time(NULL));
|
||||||
seed.resize(16);
|
seed.resize(16);
|
||||||
|
|
||||||
OFB_Mode<AES>::Encryption& prng = static_cast<OFB_Mode<AES>::Encryption&>(GlobalRNG());
|
OFB_Mode<AES>::Encryption& prng = dynamic_cast<OFB_Mode<AES>::Encryption&>(GlobalRNG());
|
||||||
prng.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data());
|
prng.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data());
|
||||||
|
|
||||||
std::string command, executableName, macFilename;
|
std::string command, executableName, macFilename;
|
||||||
|
|
@ -831,7 +827,7 @@ bool Validate(int alg, bool thorough, const char *seedInput)
|
||||||
|
|
||||||
std::cout << "Using seed: " << seed << std::endl;
|
std::cout << "Using seed: " << seed << std::endl;
|
||||||
|
|
||||||
OFB_Mode<AES>::Encryption& prng = static_cast<OFB_Mode<AES>::Encryption&>(GlobalRNG());
|
OFB_Mode<AES>::Encryption& prng = dynamic_cast<OFB_Mode<AES>::Encryption&>(GlobalRNG());
|
||||||
prng.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data());
|
prng.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data());
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue