Build RDRAND for all platofrms (Issue 419, PR 424)

We have not been able to determine a reliable way to detect cpu's and platforms with Cmake. We are side stepping the Cmake problem by building rdrand.cpp all the time. If its not avilable for a cpu or platform, then RDRAND or RDSEED throw an exception.
pull/425/head
Jeffrey Walton 2017-05-17 16:21:20 -04:00
parent 03a6a8fb73
commit 1b1c32d7cf
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
4 changed files with 40 additions and 18 deletions

View File

@ -522,10 +522,6 @@ SRCS := cryptlib.cpp cpu.cpp integer.cpp $(filter-out cryptlib.cpp cpu.cpp integ
ifeq ($(IS_X86)$(IS_X32)$(IS_X64)$(IS_ARM32)$(IS_ARM64),00000) ifeq ($(IS_X86)$(IS_X32)$(IS_X64)$(IS_ARM32)$(IS_ARM64),00000)
SRCS := $(filter-out cpu.cpp, $(SRCS)) SRCS := $(filter-out cpu.cpp, $(SRCS))
endif endif
# Need RDRAND for X86/X64/X32
ifeq ($(IS_X86)$(IS_X32)$(IS_X64),000)
SRCS := $(filter-out rdrand.cpp, $(SRCS))
endif
ifneq ($(IS_MINGW),0) ifneq ($(IS_MINGW),0)
SRCS += winpipes.cpp SRCS += winpipes.cpp
@ -766,13 +762,11 @@ endif
trim: trim:
ifneq ($(IS_DARWIN),0) ifneq ($(IS_DARWIN),0)
sed -i '' -e's/[[:space:]]*$$//' *.sh *.h *.cpp *.asm *.s *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross sed -i '' -e's/[[:space:]]*$$//' *.sh *.h *.cpp *.asm *.s *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross
sed -i '' -e's/[[:space:]]*$$//' *.sh TestData/*.dat sed -i '' -e's/[[:space:]]*$$//' TestData/*.dat TestVectors/*.txt TestScripts/*.sh
sed -i '' -e's/[[:space:]]*$$//' *.sh TestVectors/*.txt
make convert make convert
else else
sed -i -e's/[[:space:]]*$$//' *.sh *.h *.cpp *.asm *.s *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross sed -i -e's/[[:space:]]*$$//' *.sh *.h *.cpp *.asm *.s *.sln *.vcxproj *.filters GNUmakefile GNUmakefile-cross
sed -i -e's/[[:space:]]*$$//' *.sh TestData/*.dat sed -i -e's/[[:space:]]*$$//' TestData/*.dat TestVectors/*.txt TestScripts/*.sh
sed -i -e's/[[:space:]]*$$//' *.sh TestVectors/*.txt
make convert make convert
endif endif

View File

@ -69,12 +69,12 @@
# define GCC_RDSEED_ASM_AVAILABLE 1 # define GCC_RDSEED_ASM_AVAILABLE 1
# endif # endif
# elif defined(CRYPTOPP_GCC_VERSION) # elif defined(CRYPTOPP_GCC_VERSION)
# if defined(__RDRND__) && (CRYPTOPP_GCC_VERSION >= 40600) && !defined(__OPTIMIZE_SIZE__) # if defined(__RDRND__) && (CRYPTOPP_GCC_VERSION >= 40600) && !defined(__OPTIMIZE__)
# define ALL_RDRAND_INTRIN_AVAILABLE 1 # define ALL_RDRAND_INTRIN_AVAILABLE 1
# else # else
# define GCC_RDRAND_ASM_AVAILABLE 1 # define GCC_RDRAND_ASM_AVAILABLE 1
# endif # endif
# if defined(__RDSEED__) && (CRYPTOPP_GCC_VERSION >= 40600) && !defined(__OPTIMIZE_SIZE__) # if defined(__RDSEED__) && (CRYPTOPP_GCC_VERSION >= 40600) && !defined(__OPTIMIZE__)
# define ALL_RDSEED_INTRIN_AVAILABLE 1 # define ALL_RDSEED_INTRIN_AVAILABLE 1
# else # else
# define GCC_RDSEED_ASM_AVAILABLE 1 # define GCC_RDSEED_ASM_AVAILABLE 1
@ -118,6 +118,8 @@ extern "C" void NASM_RDSEED_GenerateBlock(byte*, size_t);
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
#if defined(CRYPTOPP_CPUID_AVAILABLE)
// Fills 4 bytes // Fills 4 bytes
inline void RDRAND32(void* output) inline void RDRAND32(void* output)
{ {
@ -425,4 +427,38 @@ void RDSEED::DiscardBytes(size_t n)
} }
} }
#else // CRYPTOPP_CPUID_AVAILABLE
RDRAND::RDRAND()
{
throw RDRAND_Err("HasRDRAND");
}
void RDRAND::GenerateBlock(byte *output, size_t size)
{
CRYPTOPP_UNUSED(output); CRYPTOPP_UNUSED(size);
}
void RDRAND::DiscardBytes(size_t n)
{
CRYPTOPP_UNUSED(n);
}
RDSEED::RDSEED()
{
throw RDSEED_Err("HasRDSEED");
}
void RDSEED::GenerateBlock(byte *output, size_t size)
{
CRYPTOPP_UNUSED(output); CRYPTOPP_UNUSED(size);
}
void RDSEED::DiscardBytes(size_t n)
{
CRYPTOPP_UNUSED(n);
}
#endif
NAMESPACE_END NAMESPACE_END

View File

@ -79,10 +79,8 @@ bool ValidateAll(bool thorough)
#if defined(CRYPTOPP_EXTENDED_VALIDATION) #if defined(CRYPTOPP_EXTENDED_VALIDATION)
pass=TestMersenne() && pass; pass=TestMersenne() && pass;
#endif #endif
#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
pass=TestRDRAND() && pass; pass=TestRDRAND() && pass;
pass=TestRDSEED() && pass; pass=TestRDSEED() && pass;
#endif
#if defined(CRYPTOPP_EXTENDED_VALIDATION) #if defined(CRYPTOPP_EXTENDED_VALIDATION)
// http://github.com/weidai11/cryptopp/issues/92 // http://github.com/weidai11/cryptopp/issues/92
@ -927,7 +925,6 @@ bool TestMersenne()
} }
#endif #endif
#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
bool TestRDRAND() bool TestRDRAND()
{ {
std::cout << "\nTesting RDRAND generator...\n\n"; std::cout << "\nTesting RDRAND generator...\n\n";
@ -1030,9 +1027,7 @@ bool TestRDRAND()
std::cout.flush(); std::cout.flush();
return pass; return pass;
} }
#endif
#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
bool TestRDSEED() bool TestRDSEED()
{ {
std::cout << "\nTesting RDSEED generator...\n\n"; std::cout << "\nTesting RDSEED generator...\n\n";
@ -1135,7 +1130,6 @@ bool TestRDSEED()
std::cout.flush(); std::cout.flush();
return pass; return pass;
} }
#endif
bool ValidateHashDRBG() bool ValidateHashDRBG()
{ {

View File

@ -22,10 +22,8 @@ bool TestRandomPool();
#if !defined(NO_OS_DEPENDENCE) #if !defined(NO_OS_DEPENDENCE)
bool TestAutoSeededX917(); bool TestAutoSeededX917();
#endif #endif
#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
bool TestRDRAND(); bool TestRDRAND();
bool TestRDSEED(); bool TestRDSEED();
#endif
bool ValidateBaseCode(); bool ValidateBaseCode();
bool ValidateCRC32(); bool ValidateCRC32();