void RDSEED::GenerateBlock(byte *output, size_t size) { CRYPTOPP_UNUSED(output), CRYPTOPP_UNUSED(size); CRYPTOPP_ASSERT((output && size) || !(output || size)); if(!HasRDSEED()) throw NotImplemented("RDSEED: rdseed is not available on this platform"); int rc; CRYPTOPP_UNUSED(rc); #if MASM_RDSEED_ASM_AVAILABLE rc = MASM_RSA_GenerateBlock(output, size, m_retries); if (!rc) { throw RDSEED_Err("MASM_RSA_GenerateBlock"); } #elif NASM_RDSEED_ASM_AVAILABLE rc = NASM_RSA_GenerateBlock(output, size, m_retries); if (!rc) { throw RDRAND_Err("NASM_RSA_GenerateBlock"); } #elif ALL_RDSEED_INTRIN_AVAILABLE rc = ALL_RSI_GenerateBlock(output, size, m_retries); if (!rc) { throw RDSEED_Err("ALL_RSI_GenerateBlock"); } #elif GCC_RDSEED_ASM_AVAILABLE rc = GCC_RSA_GenerateBlock(output, size, m_retries); if (!rc) { throw RDSEED_Err("GCC_RSA_GenerateBlock"); } #else // RDSEED not detected at compile time, and no suitable compiler found throw NotImplemented("RDSEED: failed to find a suitable implementation???"); #endif }
void RDSEED::DiscardBytes(size_t n) { // RoundUpToMultipleOf is used because a full word is read, and its cheaper // to discard full words. There's no sense in dealing with tail bytes. CRYPTOPP_ASSERT(HasRDSEED()); #if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 FixedSizeSecBlock<word64, 16> discard; n = RoundUpToMultipleOf(n, sizeof(word64)); #else FixedSizeSecBlock<word32, 16> discard; n = RoundUpToMultipleOf(n, sizeof(word32)); #endif size_t count = STDMIN(n, discard.SizeInBytes()); while (count) { GenerateBlock(discard.BytePtr(), count); n -= count; count = STDMIN(n, discard.SizeInBytes()); } }
void Benchmark1(double t, double hertz) { g_allocatedTime = t; g_hertz = hertz; const char *cpb; if (g_hertz > 1.0f) cpb = "<TH>Cycles Per Byte"; else cpb = ""; std::cout << "\n<TABLE>"; std::cout << "\n<COLGROUP><COL style=\"text-align: left;\"><COL style=\"text-align: right;\">"; std::cout << "<COL style=\"text-align: right;\">"; std::cout << "\n<THEAD style=\"background: #F0F0F0\">"; std::cout << "\n<TR><TH>Algorithm<TH>MiB/Second" << cpb; std::cout << "\n<TBODY style=\"background: white;\">"; { #ifdef NONBLOCKING_RNG_AVAILABLE BenchMarkByNameKeyLess<RandomNumberGenerator>("NonblockingRng"); #endif #ifdef OS_RNG_AVAILABLE BenchMarkByNameKeyLess<RandomNumberGenerator>("AutoSeededRandomPool"); BenchMarkByNameKeyLess<RandomNumberGenerator>("AutoSeededX917RNG(AES)"); #endif BenchMarkByNameKeyLess<RandomNumberGenerator>("MT19937"); #if (CRYPTOPP_BOOL_X86) if (HasPadlockRNG()) BenchMarkByNameKeyLess<RandomNumberGenerator>("PadlockRNG"); #endif #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) if (HasRDRAND()) BenchMarkByNameKeyLess<RandomNumberGenerator>("RDRAND"); if (HasRDSEED()) BenchMarkByNameKeyLess<RandomNumberGenerator>("RDSEED"); #endif BenchMarkByNameKeyLess<RandomNumberGenerator>("AES/OFB RNG"); BenchMarkByNameKeyLess<NIST_DRBG>("Hash_DRBG(SHA1)"); BenchMarkByNameKeyLess<NIST_DRBG>("Hash_DRBG(SHA256)"); BenchMarkByNameKeyLess<NIST_DRBG>("HMAC_DRBG(SHA1)"); BenchMarkByNameKeyLess<NIST_DRBG>("HMAC_DRBG(SHA256)"); } std::cout << "\n<TBODY style=\"background: yellow;\">"; { BenchMarkByNameKeyLess<HashTransformation>("CRC32"); BenchMarkByNameKeyLess<HashTransformation>("CRC32C"); BenchMarkByNameKeyLess<HashTransformation>("Adler32"); BenchMarkByNameKeyLess<HashTransformation>("MD5"); BenchMarkByNameKeyLess<HashTransformation>("SHA-1"); BenchMarkByNameKeyLess<HashTransformation>("SHA-256"); BenchMarkByNameKeyLess<HashTransformation>("SHA-512"); BenchMarkByNameKeyLess<HashTransformation>("SHA3-224"); BenchMarkByNameKeyLess<HashTransformation>("SHA3-256"); BenchMarkByNameKeyLess<HashTransformation>("SHA3-384"); BenchMarkByNameKeyLess<HashTransformation>("SHA3-512"); BenchMarkByNameKeyLess<HashTransformation>("Keccak-224"); BenchMarkByNameKeyLess<HashTransformation>("Keccak-256"); BenchMarkByNameKeyLess<HashTransformation>("Keccak-384"); BenchMarkByNameKeyLess<HashTransformation>("Keccak-512"); BenchMarkByNameKeyLess<HashTransformation>("Tiger"); BenchMarkByNameKeyLess<HashTransformation>("Whirlpool"); BenchMarkByNameKeyLess<HashTransformation>("RIPEMD-160"); BenchMarkByNameKeyLess<HashTransformation>("RIPEMD-320"); BenchMarkByNameKeyLess<HashTransformation>("RIPEMD-128"); BenchMarkByNameKeyLess<HashTransformation>("RIPEMD-256"); BenchMarkByNameKeyLess<HashTransformation>("SM3"); BenchMarkByNameKeyLess<HashTransformation>("BLAKE2s"); BenchMarkByNameKeyLess<HashTransformation>("BLAKE2b"); } std::cout << "\n</TABLE>" << std::endl; }