Add StaticAlgorithmName to select RNGs for object registry (Issue 386)

This commit is contained in:
Jeffrey Walton 2017-03-07 04:52:37 -05:00
parent 585b23d7b1
commit 78823bfd0c
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
4 changed files with 28 additions and 9 deletions

10
drbg.h
View File

@ -11,6 +11,8 @@
#include "cryptlib.h" #include "cryptlib.h"
#include "secblock.h" #include "secblock.h"
#include "hmac.h"
#include "sha.h"
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
@ -170,6 +172,8 @@ public:
CRYPTOPP_CONSTANT(MAXIMUM_BYTES_PER_REQUEST=65536) CRYPTOPP_CONSTANT(MAXIMUM_BYTES_PER_REQUEST=65536)
CRYPTOPP_CONSTANT(MAXIMUM_REQUESTS_BEFORE_RESEED=INT_MAX) CRYPTOPP_CONSTANT(MAXIMUM_REQUESTS_BEFORE_RESEED=INT_MAX)
static std::string StaticAlgorithmName() { return std::string("Hash_DRBG(") + HASH::StaticAlgorithmName() + std::string(")"); }
//! \brief Construct a Hash DRBG //! \brief Construct a Hash DRBG
//! \param entropy the entropy to instantiate the generator //! \param entropy the entropy to instantiate the generator
//! \param entropyLength the size of the entropy buffer //! \param entropyLength the size of the entropy buffer
@ -281,6 +285,8 @@ public:
CRYPTOPP_CONSTANT(MAXIMUM_BYTES_PER_REQUEST=65536) CRYPTOPP_CONSTANT(MAXIMUM_BYTES_PER_REQUEST=65536)
CRYPTOPP_CONSTANT(MAXIMUM_REQUESTS_BEFORE_RESEED=INT_MAX) CRYPTOPP_CONSTANT(MAXIMUM_REQUESTS_BEFORE_RESEED=INT_MAX)
static std::string StaticAlgorithmName() { return std::string("HMAC_DRBG(") + HASH::StaticAlgorithmName() + std::string(")"); }
//! \brief Construct a HMAC DRBG //! \brief Construct a HMAC DRBG
//! \param entropy the entropy to instantiate the generator //! \param entropy the entropy to instantiate the generator
//! \param entropyLength the size of the entropy buffer //! \param entropyLength the size of the entropy buffer
@ -537,8 +543,8 @@ void Hash_DRBG<HASH, STRENGTH, SEEDLENGTH>::Hash_Update(const byte* input1, size
size_t count = STDMIN(outlen, (size_t)HASH::DIGESTSIZE); size_t count = STDMIN(outlen, (size_t)HASH::DIGESTSIZE);
hash.TruncatedFinal(output, count); hash.TruncatedFinal(output, count);
output += count; outlen -= count; output += count; outlen -= count;
counter++; counter++;
} }
} }

View File

@ -30,6 +30,10 @@ template <unsigned int K, unsigned int M, unsigned int N, unsigned int F, unsign
class MersenneTwister : public RandomNumberGenerator class MersenneTwister : public RandomNumberGenerator
{ {
public: public:
CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "MT19937"; }
~MersenneTwister() {}
//! \brief Construct a Mersenne Twister //! \brief Construct a Mersenne Twister
//! \param seed 32-bit seed //! \param seed 32-bit seed
//! \details Defaults to template parameter S due to changing algorithm //! \details Defaults to template parameter S due to changing algorithm

View File

@ -20,9 +20,6 @@
#include "rng.h" #include "rng.h"
#ifdef CRYPTOPP_WIN32_AVAILABLE #ifdef CRYPTOPP_WIN32_AVAILABLE
//#ifndef _WIN32_WINNT
//#define _WIN32_WINNT 0x0400
//#endif
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#if defined(USE_MS_CRYPTOAPI) #if defined(USE_MS_CRYPTOAPI)
@ -34,7 +31,6 @@
# define CRYPT_MACHINE_KEYSET 0x00000020 # define CRYPT_MACHINE_KEYSET 0x00000020
#endif #endif
#elif defined(USE_MS_CNGAPI) #elif defined(USE_MS_CNGAPI)
//#include <ntdef.h>
#include <bcrypt.h> #include <bcrypt.h>
#ifndef BCRYPT_SUCCESS #ifndef BCRYPT_SUCCESS
# define BCRYPT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0) # define BCRYPT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)

19
osrng.h
View File

@ -87,9 +87,12 @@ private:
class CRYPTOPP_DLL NonblockingRng : public RandomNumberGenerator class CRYPTOPP_DLL NonblockingRng : public RandomNumberGenerator
{ {
public: public:
CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "NonblockingRng"; }
~NonblockingRng();
//! \brief Construct a NonblockingRng //! \brief Construct a NonblockingRng
NonblockingRng(); NonblockingRng();
~NonblockingRng();
//! \brief Generate random array of bytes //! \brief Generate random array of bytes
//! \param output the byte buffer //! \param output the byte buffer
@ -115,9 +118,12 @@ protected:
class CRYPTOPP_DLL BlockingRng : public RandomNumberGenerator class CRYPTOPP_DLL BlockingRng : public RandomNumberGenerator
{ {
public: public:
CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "BlockingRng"; }
~BlockingRng();
//! \brief Construct a BlockingRng //! \brief Construct a BlockingRng
BlockingRng(); BlockingRng();
~BlockingRng();
//! \brief Generate random array of bytes //! \brief Generate random array of bytes
//! \param output the byte buffer //! \param output the byte buffer
@ -143,7 +149,6 @@ protected:
//! by way of BlockingRng, if available. //! by way of BlockingRng, if available.
CRYPTOPP_DLL void CRYPTOPP_API OS_GenerateRandomBlock(bool blocking, byte *output, size_t size); CRYPTOPP_DLL void CRYPTOPP_API OS_GenerateRandomBlock(bool blocking, byte *output, size_t size);
//! \class AutoSeededRandomPool //! \class AutoSeededRandomPool
//! \brief Automatically Seeded Randomness Pool //! \brief Automatically Seeded Randomness Pool
//! \details This class seeds itself using an operating system provided RNG. //! \details This class seeds itself using an operating system provided RNG.
@ -151,6 +156,10 @@ CRYPTOPP_DLL void CRYPTOPP_API OS_GenerateRandomBlock(bool blocking, byte *outpu
class CRYPTOPP_DLL AutoSeededRandomPool : public RandomPool class CRYPTOPP_DLL AutoSeededRandomPool : public RandomPool
{ {
public: public:
CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "AutoSeededRandomPool"; }
~AutoSeededRandomPool() {}
//! \brief Construct an AutoSeededRandomPool //! \brief Construct an AutoSeededRandomPool
//! \param blocking controls seeding with BlockingRng or NonblockingRng //! \param blocking controls seeding with BlockingRng or NonblockingRng
//! \param seedSize the size of the seed, in bytes //! \param seedSize the size of the seed, in bytes
@ -178,6 +187,10 @@ template <class BLOCK_CIPHER>
class AutoSeededX917RNG : public RandomNumberGenerator, public NotCopyable class AutoSeededX917RNG : public RandomNumberGenerator, public NotCopyable
{ {
public: public:
static std::string StaticAlgorithmName() { return std::string("AutoSeededX917RNG(") + BLOCK_CIPHER::StaticAlgorithmName() + std::string(")"); }
~AutoSeededX917RNG() {}
//! \brief Construct an AutoSeededX917RNG //! \brief Construct an AutoSeededX917RNG
//! \param blocking controls seeding with BlockingRng or NonblockingRng //! \param blocking controls seeding with BlockingRng or NonblockingRng
//! \param autoSeed controls auto seeding of the generator //! \param autoSeed controls auto seeding of the generator