Changed retry count for RDRAND and RDSEED. RDSEED appears to fail to fulfill requests at about 6 to 8 times the rate of RDRAND.

pull/65/head
Jeffrey Walton 2015-11-29 14:43:12 -05:00
parent ed6c1de915
commit 8ba4232386
2 changed files with 33 additions and 10 deletions

View File

@ -17,8 +17,8 @@
// indirectly uses CRYPTOPP_BOOL_{X86|X32|X64} (via CRYPTOPP_CPUID_AVAILABLE) // indirectly uses CRYPTOPP_BOOL_{X86|X32|X64} (via CRYPTOPP_CPUID_AVAILABLE)
// to select an implementation or "throw NotImplemented". At runtime, the // to select an implementation or "throw NotImplemented". At runtime, the
// class uses the result of CPUID to determine if RDRAND or RDSEED are // class uses the result of CPUID to determine if RDRAND or RDSEED are
// available. A lazy throw strategy is used in case the CPU does not support // available. If not available, a lazy throw strategy is used. I.e., the
// the instruction. I.e., the throw is deferred until GenerateBlock is called. // throw is deferred until GenerateBlock() is called.
// Here's the naming convention for the functions.... // Here's the naming convention for the functions....
// MSC = Microsoft Compiler (and compatibles) // MSC = Microsoft Compiler (and compatibles)
@ -196,7 +196,10 @@ static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
else else
{ {
if (!safety--) if (!safety--)
{
assert(0);
return 0; return 0;
}
} }
} }
@ -214,7 +217,10 @@ static int ALL_RRI_GenerateBlock(byte *output, size_t size, unsigned int safety)
else else
{ {
if (!safety--) if (!safety--)
{
assert(0);
return 0; return 0;
}
} }
} }
@ -275,7 +281,10 @@ static int GCC_RRA_GenerateBlock(byte *output, size_t size, unsigned int safety)
else else
{ {
if (!safety--) if (!safety--)
break; {
assert(0);
return 0;
}
} }
} }
@ -368,7 +377,10 @@ static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety)
else else
{ {
if (!safety--) if (!safety--)
{
assert(0);
return 0; return 0;
}
} }
} }
@ -386,7 +398,10 @@ static int ALL_RSI_GenerateBlock(byte *output, size_t size, unsigned int safety)
else else
{ {
if (!safety--) if (!safety--)
{
assert(0);
return 0; return 0;
}
} }
} }
@ -447,7 +462,10 @@ static int GCC_RSA_GenerateBlock(byte *output, size_t size, unsigned int safety)
else else
{ {
if (!safety--) if (!safety--)
break; {
assert(0);
return 0;
}
} }
} }

View File

@ -1,8 +1,7 @@
// rdrand.h - written and placed in public domain by Jeffrey Walton and Uri Blumenthal. // rdrand.h - written and placed in public domain by Jeffrey Walton and Uri Blumenthal.
// Copyright assigned to Crypto++ project. // Copyright assigned to Crypto++ project.
//! \file //! \file rdrand.h
//! \headerfile rdrand.h
//! \brief Classes for RDRAND and RDSEED //! \brief Classes for RDRAND and RDSEED
#ifndef CRYPTOPP_RDRAND_H #ifndef CRYPTOPP_RDRAND_H
@ -15,8 +14,8 @@
// indirectly uses CRYPTOPP_BOOL_{X86|X32|X64} (via CRYPTOPP_CPUID_AVAILABLE) // indirectly uses CRYPTOPP_BOOL_{X86|X32|X64} (via CRYPTOPP_CPUID_AVAILABLE)
// to select an implementation or "throw NotImplemented". At runtime, the // to select an implementation or "throw NotImplemented". At runtime, the
// class uses the result of CPUID to determine if RDRAND or RDSEED are // class uses the result of CPUID to determine if RDRAND or RDSEED are
// available. A lazy throw strategy is used in case the CPU does not support // available. If not available, a lazy throw strategy is used. I.e., the
// the instruction. I.e., the throw is deferred until GenerateBlock() is called. // throw is deferred until GenerateBlock() is called.
// Microsoft added RDRAND in August 2012, VS2012. GCC added RDRAND in December 2010, GCC 4.6. // Microsoft added RDRAND in August 2012, VS2012. GCC added RDRAND in December 2010, GCC 4.6.
// Clang added RDRAND in July 2012, Clang 3.2. Intel added RDRAND in September 2011, ICC 12.1. // Clang added RDRAND in July 2012, Clang 3.2. Intel added RDRAND in September 2011, ICC 12.1.
@ -43,7 +42,10 @@ public:
//! \param retries the number of retries for failed calls to the hardware //! \param retries the number of retries for failed calls to the hardware
//! \details RDRAND() constructs a generator with a maximum number of retires //! \details RDRAND() constructs a generator with a maximum number of retires
//! for failed generation attempts. //! for failed generation attempts.
RDRAND(unsigned int retries = 8) : m_retries(retries) {} //! \details Empirical testing under a 6th generaton i7 (6200U) shows RDSEED fails
//! to fulfill requests at about 6 to 8 times the rate of RDRAND. The default
//! retries reflects the difference.
RDRAND(unsigned int retries = 12) : m_retries(retries) {}
virtual ~RDRAND() {} virtual ~RDRAND() {}
@ -122,7 +124,10 @@ public:
//! \param retries the number of retries for failed calls to the hardware //! \param retries the number of retries for failed calls to the hardware
//! \details RDSEED() constructs a generator with a maximum number of retires //! \details RDSEED() constructs a generator with a maximum number of retires
//! for failed generation attempts. //! for failed generation attempts.
RDSEED(unsigned int retries = 8) : m_retries(retries) {} //! \details Empirical testing under a 6th generaton i7 (6200U) shows RDSEED fails
//! to fulfill requests at about 6 to 8 times the rate of RDRAND. The default
//! retries reflects the difference.
RDSEED(unsigned int retries = 64) : m_retries(retries) {}
virtual ~RDSEED() {} virtual ~RDSEED() {}