Add algorithm provider member function to Algorithm class

This commit is contained in:
Jeffrey Walton 2018-07-06 09:23:37 -04:00 committed by GitHub
parent 6d9047b444
commit b74a6f4445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 558 additions and 125 deletions

View File

@ -48,8 +48,8 @@ void Benchmark2(double t, double hertz);
// Public key systems
void Benchmark3(double t, double hertz);
void OutputResultBytes(const char *name, double length, double timeTaken);
void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken);
void OutputResultBytes(const char *name, const char* provider, double length, double timeTaken);
void OutputResultOperations(const char *name, const char* provider, const char *operation, bool pc, unsigned long iterations, double timeTaken);
NAMESPACE_END // Test
NAMESPACE_END // CryptoPP

View File

@ -49,7 +49,7 @@ double g_allocatedTime = 0.0, g_hertz = 0.0, g_logTotal = 0.0;
unsigned int g_logCount = 0;
time_t g_testBegin, g_testEnd;
void OutputResultBytes(const char *name, double length, double timeTaken)
void OutputResultBytes(const char *name, const char *provider, double length, double timeTaken)
{
// Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
StreamState ss(std::cout);
@ -59,7 +59,7 @@ void OutputResultBytes(const char *name, double length, double timeTaken)
if (timeTaken < 0.000001f) timeTaken = 0.000001f;
double mbs = length / timeTaken / (1024*1024);
std::cout << "\n<TR><TD>" << name;
std::cout << "\n<TR><TD>" << name << "<TD>" << provider;
std::cout << std::setiosflags(std::ios::fixed);
std::cout << "<TD>" << std::setprecision(0) << std::setiosflags(std::ios::fixed) << mbs;
if (g_hertz > 1.0f)
@ -90,7 +90,7 @@ void OutputResultKeying(double iterations, double timeTaken)
std::cout << "<TD>" << std::setprecision(0) << std::setiosflags(std::ios::fixed) << timeTaken * g_hertz / iterations;
}
void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken)
void OutputResultOperations(const char *name, const char *provider, const char *operation, bool pc, unsigned long iterations, double timeTaken)
{
// Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
StreamState ss(std::cout);
@ -100,6 +100,7 @@ void OutputResultOperations(const char *name, const char *operation, bool pc, un
if (timeTaken < 0.000001f) timeTaken = 0.000001f;
std::cout << "\n<TR><TD>" << name << " " << operation << (pc ? " with precomputation" : "");
std::cout << "<TD>" << provider;
std::cout << "<TD>" << std::setprecision(2) << std::setiosflags(std::ios::fixed) << (1000*timeTaken/iterations);
// Coverity finding
@ -158,7 +159,8 @@ void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal)
}
while (timeTaken < 2.0/3*timeTotal);
OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken);
std::string provider = cipher.AlgorithmProvider();
OutputResultBytes(name, provider.c_str(), double(blocks) * BUF_SIZE, timeTaken);
}
void BenchMark(const char *name, AuthenticatedSymmetricCipher &cipher, double timeTotal)
@ -189,7 +191,8 @@ void BenchMark(const char *name, HashTransformation &ht, double timeTotal)
}
while (timeTaken < 2.0/3*timeTotal);
OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken);
std::string provider = ht.AlgorithmProvider();
OutputResultBytes(name, provider.c_str(), double(blocks) * BUF_SIZE, timeTaken);
}
void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal)
@ -212,7 +215,8 @@ void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal)
}
while (timeTaken < 2.0/3*timeTotal);
OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken);
std::string provider = bt.AlgorithmProvider();
OutputResultBytes(name, provider.c_str(), double(blocks) * BUF_SIZE, timeTaken);
}
void BenchMark(const char *name, RandomNumberGenerator &rng, double timeTotal)
@ -243,7 +247,8 @@ void BenchMark(const char *name, RandomNumberGenerator &rng, double timeTotal)
timeTaken = double(::clock() - start) / CLOCK_TICKS_PER_SECOND;
} while (timeTaken < timeTotal);
OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken);
std::string provider = rng.AlgorithmProvider();
OutputResultBytes(name, provider.c_str(), double(blocks) * BUF_SIZE, timeTaken);
}
// Hack, but we probably need a KeyedRandomNumberGenerator interface
@ -269,7 +274,8 @@ void BenchMark(const char *name, NIST_DRBG &rng, double timeTotal)
timeTaken = double(::clock() - start) / CLOCK_TICKS_PER_SECOND;
} while (timeTaken < timeTotal);
OutputResultBytes(name, double(blocks) * BUF_SIZE, timeTaken);
std::string provider = rng.AlgorithmProvider();
OutputResultBytes(name, provider.c_str(), double(blocks) * BUF_SIZE, timeTaken);
}
void BenchMarkKeying(SimpleKeyingInterface &c, size_t keyLength, const NameValuePairs &params)
@ -310,14 +316,14 @@ void BenchMarkByName2(const char *factoryName, size_t keyLength = 0, const char
}
template <class T_FactoryOutput>
void BenchMarkByName(const char *factoryName, size_t keyLength = 0, const char *displayName=NULLPTR, const NameValuePairs &params = g_nullNameValuePairs)
void BenchMarkByName(const char *factoryName, size_t keyLength = 0, const char *displayName = NULLPTR, const NameValuePairs &params = g_nullNameValuePairs)
{
CRYPTOPP_UNUSED(params);
BenchMarkByName2<T_FactoryOutput, T_FactoryOutput>(factoryName, keyLength, displayName, params);
}
template <class T>
void BenchMarkByNameKeyLess(const char *factoryName, const char *displayName=NULLPTR, const NameValuePairs &params = g_nullNameValuePairs)
void BenchMarkByNameKeyLess(const char *factoryName, const char *displayName = NULLPTR, const NameValuePairs &params = g_nullNameValuePairs)
{
CRYPTOPP_UNUSED(params);
std::string name = factoryName;
@ -441,7 +447,7 @@ void Benchmark1(double t, double hertz)
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<TR><TH>Algorithm<TH>Provider<TH>MiB/Second" << cpb;
std::cout << "\n<TBODY style=\"background: white;\">";
{
@ -521,7 +527,7 @@ void Benchmark2(double t, double hertz)
std::cout << "\n<COLGROUP><COL style=\"text-align: left;\"><COL style=\"text-align: right;\"><COL style=";
std::cout << "\"text-align: right;\"><COL style=\"text-align: right;\"><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<TR><TH>Algorithm<TH>Provider<TH>MiB/Second" << cpb;
std::cout << "<TH>Microseconds to<BR>Setup Key and IV" << cpk;
std::cout << "\n<TBODY style=\"background: white;\">";
@ -561,9 +567,9 @@ void Benchmark2(double t, double hertz)
BenchMarkByName<SymmetricCipher>("Salsa20");
BenchMarkByName<SymmetricCipher>("Salsa20", 0, "Salsa20/12", MakeParameters(Name::Rounds(), 12));
BenchMarkByName<SymmetricCipher>("Salsa20", 0, "Salsa20/8", MakeParameters(Name::Rounds(), 8));
BenchMarkByName<SymmetricCipher>("ChaCha20");
BenchMarkByName<SymmetricCipher>("ChaCha12");
BenchMarkByName<SymmetricCipher>("ChaCha8");
BenchMarkByName<SymmetricCipher>("ChaCha");
BenchMarkByName<SymmetricCipher>("ChaCha", 0, "ChaCha/12", MakeParameters(Name::Rounds(), 12));
BenchMarkByName<SymmetricCipher>("ChaCha", 0, "ChaCha/8", MakeParameters(Name::Rounds(), 8));
BenchMarkByName<SymmetricCipher>("Sosemanuk");
BenchMarkByName<SymmetricCipher>("Rabbit");
BenchMarkByName<SymmetricCipher>("RabbitWithIV");

View File

@ -40,7 +40,7 @@
NAMESPACE_BEGIN(CryptoPP)
NAMESPACE_BEGIN(Test)
void BenchMarkEncryption(const char *name, PK_Encryptor &key, double timeTotal, bool pc=false)
void BenchMarkEncryption(const char *name, PK_Encryptor &key, double timeTotal, bool pc = false)
{
unsigned int len = 16;
SecByteBlock plaintext(len), ciphertext(key.CiphertextLength(len));
@ -59,7 +59,8 @@ void BenchMarkEncryption(const char *name, PK_Encryptor &key, double timeTotal,
}
while (timeTaken < timeTotal);
OutputResultOperations(name, "Encryption", pc, i, timeTaken);
std::string provider = key.AlgorithmProvider();
OutputResultOperations(name, provider.c_str(), "Encryption", pc, i, timeTaken);
if (!pc && key.GetMaterial().SupportsPrecomputation())
{
@ -89,7 +90,8 @@ void BenchMarkDecryption(const char *name, PK_Decryptor &priv, PK_Encryptor &pub
}
while (timeTaken < timeTotal);
OutputResultOperations(name, "Decryption", false, i, timeTaken);
std::string provider = priv.AlgorithmProvider();
OutputResultOperations(name, provider.c_str(), "Decryption", false, i, timeTaken);
}
void BenchMarkSigning(const char *name, PK_Signer &key, double timeTotal, bool pc=false)
@ -111,7 +113,8 @@ void BenchMarkSigning(const char *name, PK_Signer &key, double timeTotal, bool p
}
while (timeTaken < timeTotal);
OutputResultOperations(name, "Signature", pc, i, timeTaken);
std::string provider = key.AlgorithmProvider();
OutputResultOperations(name, provider.c_str(), "Signature", pc, i, timeTaken);
if (!pc && key.GetMaterial().SupportsPrecomputation())
{
@ -140,7 +143,8 @@ void BenchMarkVerification(const char *name, const PK_Signer &priv, PK_Verifier
}
while (timeTaken < timeTotal);
OutputResultOperations(name, "Verification", pc, i, timeTaken);
std::string provider = pub.AlgorithmProvider();
OutputResultOperations(name, provider.c_str(), "Verification", pc, i, timeTaken);
if (!pc && pub.GetMaterial().SupportsPrecomputation())
{
@ -166,7 +170,8 @@ void BenchMarkKeyGen(const char *name, SimpleKeyAgreementDomain &d, double timeT
}
while (timeTaken < timeTotal);
OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken);
std::string provider = d.AlgorithmProvider();
OutputResultOperations(name, provider.c_str(), "Key-Pair Generation", pc, i, timeTaken);
if (!pc && d.GetMaterial().SupportsPrecomputation())
{
@ -192,7 +197,8 @@ void BenchMarkKeyGen(const char *name, AuthenticatedKeyAgreementDomain &d, doubl
}
while (timeTaken < timeTotal);
OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken);
std::string provider = d.AlgorithmProvider();
OutputResultOperations(name, provider.c_str(), "Key-Pair Generation", pc, i, timeTaken);
if (!pc && d.GetMaterial().SupportsPrecomputation())
{
@ -223,7 +229,8 @@ void BenchMarkAgreement(const char *name, SimpleKeyAgreementDomain &d, double ti
}
while (timeTaken < timeTotal);
OutputResultOperations(name, "Key Agreement", pc, i, timeTaken);
std::string provider = d.AlgorithmProvider();
OutputResultOperations(name, provider.c_str(), "Key Agreement", pc, i, timeTaken);
}
void BenchMarkAgreement(const char *name, AuthenticatedKeyAgreementDomain &d, double timeTotal, bool pc=false)
@ -252,7 +259,8 @@ void BenchMarkAgreement(const char *name, AuthenticatedKeyAgreementDomain &d, do
}
while (timeTaken < timeTotal);
OutputResultOperations(name, "Key Agreement", pc, i, timeTaken);
std::string provider = d.AlgorithmProvider();
OutputResultOperations(name, provider.c_str(), "Key Agreement", pc, i, timeTaken);
}
template <class SCHEME>
@ -299,7 +307,7 @@ void Benchmark3(double t, double hertz)
std::cout << "\n<COLGROUP><COL style=\"text-align: left;\"><COL style=";
std::cout << "\"text-align: right;\"><COL style=\"text-align: right;\">";
std::cout << "\n<THEAD style=\"background: #F0F0F0\">";
std::cout << "\n<TR><TH>Operation<TH>Milliseconds/Operation" << mco;
std::cout << "\n<TR><TH>Operation<TH>Provider<TH>Milliseconds/Operation" << mco;
std::cout << "\n<TBODY style=\"background: white;\">";
{

View File

@ -284,6 +284,25 @@ void BLAKE2_Base<W, T_64bit>::UncheckedSetKey(const byte *key, unsigned int leng
}
}
std::string BLAKE2_Base_AlgorithmProvider()
{
#if defined(CRYPTOPP_SSE41_AVAILABLE)
if (HasSSE41())
return "SSE4.1";
#endif
#if (CRYPTOPP_ARM_NEON_AVAILABLE)
if (HasNEON())
return "NEON";
#endif
return "C++";
}
template <class W, bool T_64bit>
std::string BLAKE2_Base<W, T_64bit>::AlgorithmProvider() const
{
return BLAKE2_Base_AlgorithmProvider();
}
template <class W, bool T_64bit>
BLAKE2_Base<W, T_64bit>::BLAKE2_Base() : m_state(1), m_block(1), m_digestSize(DIGESTSIZE), m_treeMode(false)
{

View File

@ -211,6 +211,8 @@ public:
void TruncatedFinal(byte *hash, size_t size);
std::string AlgorithmProvider() const;
protected:
BLAKE2_Base();
BLAKE2_Base(bool treeMode, unsigned int digestSize);

2
ccm.h
View File

@ -24,6 +24,8 @@ public:
// AuthenticatedSymmetricCipher
std::string AlgorithmName() const
{return GetBlockCipher().AlgorithmName() + std::string("/CCM");}
std::string AlgorithmProvider() const
{return GetBlockCipher().AlgorithmProvider();}
size_t MinKeyLength() const
{return GetBlockCipher().MinKeyLength();}
size_t MaxKeyLength() const

View File

@ -20,18 +20,20 @@ NAMESPACE_BEGIN(CryptoPP)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
void ChaCha_TestInstantiations()
{
ChaCha8::Encryption x1;
ChaCha12::Encryption x2;
ChaCha20::Encryption x3;
ChaCha::Encryption x;
}
#endif
template <unsigned int R>
void ChaCha_Policy<R>::CipherSetKey(const NameValuePairs &params, const byte *key, size_t length)
void ChaCha_Policy::CipherSetKey(const NameValuePairs &params, const byte *key, size_t length)
{
CRYPTOPP_UNUSED(params);
CRYPTOPP_ASSERT(length == 16 || length == 32);
m_rounds = params.GetIntValueWithDefault(Name::Rounds(), 20);
if (!(m_rounds == 8 || m_rounds == 12 || m_rounds == 20))
throw InvalidRounds(ChaCha::StaticAlgorithmName(), m_rounds);
// "expand 16-byte k" or "expand 32-byte k"
m_state[0] = 0x61707865;
m_state[1] = (length == 16) ? 0x3120646e : 0x3320646e;
@ -45,8 +47,7 @@ void ChaCha_Policy<R>::CipherSetKey(const NameValuePairs &params, const byte *ke
get2(m_state[8])(m_state[9])(m_state[10])(m_state[11]);
}
template <unsigned int R>
void ChaCha_Policy<R>::CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length)
void ChaCha_Policy::CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length)
{
CRYPTOPP_UNUSED(keystreamBuffer), CRYPTOPP_UNUSED(length);
CRYPTOPP_ASSERT(length==8);
@ -56,11 +57,10 @@ void ChaCha_Policy<R>::CipherResynchronize(byte *keystreamBuffer, const byte *IV
get(m_state[14])(m_state[15]);
}
template<unsigned int R>
void ChaCha_Policy<R>::SeekToIteration(lword iterationCount)
void ChaCha_Policy::SeekToIteration(lword iterationCount)
{
CRYPTOPP_UNUSED(iterationCount);
throw NotImplemented(std::string(ChaCha_Info<R>::StaticAlgorithmName()) + ": SeekToIteration is not yet implemented");
throw NotImplemented(std::string(ChaCha_Info::StaticAlgorithmName()) + ": SeekToIteration is not yet implemented");
// TODO: these were Salsa20, and Wei re-arranged the state array for SSE2 operations.
// If we can generate some out-of-band test vectors, then test and implement. Also
@ -69,8 +69,7 @@ void ChaCha_Policy<R>::SeekToIteration(lword iterationCount)
// m_state[5] = (word32)SafeRightShift<32>(iterationCount);
}
template<unsigned int R>
unsigned int ChaCha_Policy<R>::GetAlignment() const
unsigned int ChaCha_Policy::GetAlignment() const
{
#if CRYPTOPP_SSE2_ASM_AVAILABLE && 0
if (HasSSE2())
@ -80,8 +79,7 @@ unsigned int ChaCha_Policy<R>::GetAlignment() const
return GetAlignmentOf<word32>();
}
template<unsigned int R>
unsigned int ChaCha_Policy<R>::GetOptimalBlockSize() const
unsigned int ChaCha_Policy::GetOptimalBlockSize() const
{
#if CRYPTOPP_SSE2_ASM_AVAILABLE && 0
if (HasSSE2())
@ -91,8 +89,7 @@ unsigned int ChaCha_Policy<R>::GetOptimalBlockSize() const
return BYTES_PER_ITERATION;
}
template<unsigned int R>
void ChaCha_Policy<R>::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount)
void ChaCha_Policy::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount)
{
word32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
@ -103,7 +100,7 @@ void ChaCha_Policy<R>::OperateKeystream(KeystreamOperation operation, byte *outp
x8 = m_state[8]; x9 = m_state[9]; x10 = m_state[10]; x11 = m_state[11];
x12 = m_state[12]; x13 = m_state[13]; x14 = m_state[14]; x15 = m_state[15];
for (int i = static_cast<int>(ROUNDS); i > 0; i -= 2)
for (int i = static_cast<int>(m_rounds); i > 0; i -= 2)
{
CHACHA_QUARTER_ROUND(x0, x4, x8, x12);
CHACHA_QUARTER_ROUND(x1, x5, x9, x13);
@ -144,9 +141,5 @@ void ChaCha_Policy<R>::OperateKeystream(KeystreamOperation operation, byte *outp
}
}
template class ChaCha_Policy<8>;
template class ChaCha_Policy<12>;
template class ChaCha_Policy<20>;
NAMESPACE_END

View File

@ -20,21 +20,18 @@ NAMESPACE_BEGIN(CryptoPP)
/// \brief ChaCha stream cipher information
/// \since Crypto++ 5.6.4
template <unsigned int R>
struct ChaCha_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>, public FixedRounds<R>
struct ChaCha_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>
{
CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {
return (R==8?"ChaCha8":(R==12?"ChaCha12":(R==20?"ChaCha20":"ChaCha")));
return "ChaCha";
}
};
/// \brief ChaCha stream cipher implementation
/// \since Crypto++ 5.6.4
template <unsigned int R>
class CRYPTOPP_NO_VTABLE ChaCha_Policy : public AdditiveCipherConcretePolicy<word32, 16>
{
protected:
CRYPTOPP_CONSTANT(ROUNDS=FixedRounds<R>::ROUNDS)
void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
@ -45,38 +42,18 @@ protected:
unsigned int GetOptimalBlockSize() const;
FixedSizeAlignedSecBlock<word32, 16> m_state;
int m_rounds;
};
/// \brief ChaCha8 stream cipher
/// \sa <a href="http://cr.yp.to/chacha/chacha-20080128.pdf">ChaCha, a variant of Salsa20</a> (2008.01.28).
/// \since Crypto++ 5.6.4
struct ChaCha8 : public ChaCha_Info<8>, public SymmetricCipherDocumentation
{
typedef SymmetricCipherFinal<ConcretePolicyHolder<ChaCha_Policy<8>, AdditiveCipherTemplate<> >, ChaCha_Info<8> > Encryption;
typedef Encryption Decryption;
};
/// \brief ChaCha12 stream cipher
/// \details Bernstein and ECRYPT's ChaCha is _slightly_ different from the TLS working group's implementation for
/// cipher suites <tt>TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256</tt>,
/// <tt>TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256</tt>, and <tt>TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256</tt>.
/// \sa <a href="http://cr.yp.to/chacha/chacha-20080128.pdf">ChaCha, a variant of Salsa20</a> (2008.01.28).
/// \since Crypto++ 5.6.4
struct ChaCha12 : public ChaCha_Info<12>, public SymmetricCipherDocumentation
{
typedef SymmetricCipherFinal<ConcretePolicyHolder<ChaCha_Policy<12>, AdditiveCipherTemplate<> >, ChaCha_Info<12> > Encryption;
typedef Encryption Decryption;
};
/// \brief ChaCha20 stream cipher
/// \brief ChaCha stream cipher
/// \sa <a href="http://cr.yp.to/chacha/chacha-20080128.pdf">ChaCha, a variant of Salsa20</a> (2008.01.28).
/// \details Bernstein and ECRYPT's ChaCha is _slightly_ different from the TLS working group's implementation for
/// cipher suites <tt>TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256</tt>,
/// <tt>TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256</tt>, and <tt>TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256</tt>.
/// \since Crypto++ 5.6.4
struct ChaCha20 : public ChaCha_Info<20>, public SymmetricCipherDocumentation
struct ChaCha : public ChaCha_Info, public SymmetricCipherDocumentation
{
typedef SymmetricCipherFinal<ConcretePolicyHolder<ChaCha_Policy<20>, AdditiveCipherTemplate<> >, ChaCha_Info<20> > Encryption;
typedef SymmetricCipherFinal<ConcretePolicyHolder<ChaCha_Policy, AdditiveCipherTemplate<> >, ChaCha_Info> Encryption;
typedef Encryption Decryption;
};

View File

@ -112,6 +112,15 @@ extern size_t CHAM128_Dec_AdvancedProcessBlocks_SSSE3(const word32* subKeys, siz
# endif // CRYPTOPP_SSSE3_AVAILABLE
#endif // CRYPTOPP_CHAM_ADVANCED_PROCESS_BLOCKS
std::string CHAM64::Base::AlgorithmProvider() const
{
#if defined(CRYPTOPP_SSSE3_AVAILABLE)
if (HasSSSE3())
return "SSSE3";
#endif
return "C++";
}
void CHAM64::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params)
{
CRYPTOPP_UNUSED(params);
@ -189,6 +198,15 @@ void CHAM64::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock,
oblock(m_x[0])(m_x[1])(m_x[2])(m_x[3]);
}
std::string CHAM128::Base::AlgorithmProvider() const
{
#if defined(CRYPTOPP_SSSE3_AVAILABLE)
if (HasSSSE3())
return "SSSE3";
#endif
return "C++";
}
void CHAM128::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params)
{
CRYPTOPP_UNUSED(params);

2
cham.h
View File

@ -60,6 +60,7 @@ public:
{
protected:
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
std::string AlgorithmProvider() const;
SecBlock<word16> m_rk;
mutable FixedSizeSecBlock<word16, 4> m_x;
@ -118,6 +119,7 @@ public:
{
protected:
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
std::string AlgorithmProvider() const;
SecBlock<word32> m_rk;
mutable FixedSizeSecBlock<word32, 4> m_x;

4
cmac.h
View File

@ -17,6 +17,9 @@ NAMESPACE_BEGIN(CryptoPP)
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CMAC_Base : public MessageAuthenticationCode
{
public:
virtual ~CMAC_Base() {}
CMAC_Base() : m_counter(0) {}
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
@ -25,6 +28,7 @@ public:
unsigned int DigestSize() const {return GetCipher().BlockSize();}
unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();}
unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();}
std::string AlgorithmProvider() const {return GetCipher().AlgorithmProvider();}
protected:
friend class EAX_Base;

22
crc.cpp
View File

@ -130,6 +130,15 @@ const word32 CRC32::m_tab[] = {
#endif
};
std::string CRC32::AlgorithmProvider() const
{
#if (CRYPTOPP_ARM_CRC32_AVAILABLE)
if (HasCRC32())
return "ARMv8";
#endif
return "C++";
}
CRC32::CRC32()
{
Reset();
@ -289,6 +298,19 @@ const word32 CRC32C::m_tab[] = {
#endif
};
std::string CRC32C::AlgorithmProvider() const
{
#if (CRYPTOPP_ARM_CRC32_AVAILABLE)
if (HasCRC32())
return "ARMv8";
#endif
#if (CRYPTOPP_SSE42_AVAILABLE)
if (HasSSE42())
return "SSE4.2";
#endif
return "C++";
}
CRC32C::CRC32C()
{
Reset();

4
crc.h
View File

@ -36,6 +36,8 @@ public:
void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
byte GetCrcByte(size_t i) const {return reinterpret_cast<const byte *>(&m_crc)[i];}
std::string AlgorithmProvider() const;
protected:
void Reset() {m_crc = CRC32_NEGL;}
@ -61,6 +63,8 @@ public:
void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
byte GetCrcByte(size_t i) const {return reinterpret_cast<const byte *>(&m_crc)[i];}
std::string AlgorithmProvider() const;
protected:
void Reset() {m_crc = CRC32_NEGL;}

View File

@ -588,11 +588,27 @@ public:
/// \brief Provides the name of this algorithm
/// \return the standard algorithm name
/// \details The standard algorithm name can be a name like \a AES or \a AES/GCM. Some algorithms
/// do not have standard names yet. For example, there is no standard algorithm name for
/// Shoup's ECIES.
/// \note AlgorithmName is not universally implemented yet
/// \details The standard algorithm name can be a name like <tt>AES<tt> or <tt>AES/GCM</tt>.
/// Some algorithms do not have standard names yet. For example, there is no standard
/// algorithm name for Shoup's ECIES.
/// \note AlgorithmName is not universally implemented yet.
virtual std::string AlgorithmName() const {return "unknown";}
/// \brief Retrieve the provider of this algorithm
/// \return the algorithm provider
/// \details The algorithm provider can be a name like "C++", "SSE", "NEON", "AESNI",
/// "ARMv8" and "Power8". C++ is standard C++ code. Other labels, like SSE,
/// usually indicate a specialized implementation using instructions from a higher
/// instruction set architecture (ISA). Future labels may include external hardware
/// like a hardware security module (HSM).
/// \details Generally speaking Wei Dai's original IA-32 ASM code falls under "SSE2".
/// Labels like "SSSE3" and "SSE4.1" follow after Wei's code and use intrinsics
/// instead of ASM.
/// \details Algorithms which combine different instructions or ISAs provide the
/// dominant one. For example on x86 <tt>AES/GCM</tt> returns "AESNI" rather than
/// "CLMUL" or "AES+SSE4.1" or "AES+CLMUL" or "AES+SSE4.1+CLMUL".
/// \note Provider is not universally implemented yet.
virtual std::string AlgorithmProvider() const {return "C++";}
};
/// \brief Interface for algorithms that take byte strings as keys

8
dmac.h
View File

@ -28,6 +28,8 @@ public:
void TruncatedFinal(byte *mac, size_t size);
unsigned int DigestSize() const {return DIGESTSIZE;}
std::string AlgorithmProvider() const;
private:
byte *GenerateSubKeys(const byte *key, size_t keylength);
@ -38,6 +40,12 @@ private:
unsigned int m_counter;
};
template <class T>
std::string DMAC_Base<T>::AlgorithmProvider() const
{
return m_f2.AlgorithmProvider();
}
/// \brief DMAC message authentication code
/// \tparam T class derived from BlockCipherDocumentation
/// \sa <A HREF="https://eprint.iacr.org/1997/010">CBC MAC for Real-Time Data Sources (08.15.1997)</A>

6
drbg.h
View File

@ -232,6 +232,9 @@ public:
void GenerateBlock(const byte* additional, size_t additionaLength, byte *output, size_t size)
{return Hash_Generate(additional, additionaLength, output, size);}
std::string AlgorithmProvider() const
{/*Hack*/HASH hash; return hash.AlgorithmProvider();}
protected:
// 10.1.1.2 Instantiation of Hash_DRBG (p.39)
void DRBG_Instantiate(const byte* entropy, size_t entropyLength, const byte* nonce, size_t nonceLength,
@ -345,6 +348,9 @@ public:
void GenerateBlock(const byte* additional, size_t additionaLength, byte *output, size_t size)
{return HMAC_Generate(additional, additionaLength, output, size);}
std::string AlgorithmProvider() const
{/*Hack*/HASH hash; return hash.AlgorithmProvider();}
protected:
// 10.1.2.3 Instantiation of HMAC_DRBG (p.45)
void DRBG_Instantiate(const byte* entropy, size_t entropyLength, const byte* nonce, size_t nonceLength,

4
eax.h
View File

@ -21,6 +21,8 @@ public:
// AuthenticatedSymmetricCipher
std::string AlgorithmName() const
{return GetMAC().GetCipher().AlgorithmName() + std::string("/EAX");}
std::string AlgorithmProvider() const
{return GetMAC().GetCipher().AlgorithmProvider();}
size_t MinKeyLength() const
{return GetMAC().MinKeyLength();}
size_t MaxKeyLength() const
@ -76,6 +78,8 @@ class EAX_Final : public EAX_Base
public:
static std::string StaticAlgorithmName()
{return T_BlockCipher::StaticAlgorithmName() + std::string("/EAX");}
std::string AlgorithmProvider() const
{return m_cmac.AlgorithmProvider();}
bool IsForwardTransformation() const
{return T_IsEncryption;}

2
gcm.h
View File

@ -29,6 +29,8 @@ public:
// AuthenticatedSymmetricCipher
std::string AlgorithmName() const
{return GetBlockCipher().AlgorithmName() + std::string("/GCM");}
std::string AlgorithmProvider() const
{return GetBlockCipher().AlgorithmProvider();}
size_t MinKeyLength() const
{return GetBlockCipher().MinKeyLength();}
size_t MaxKeyLength() const

5
hmac.h
View File

@ -17,6 +17,8 @@ NAMESPACE_BEGIN(CryptoPP)
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE HMAC_Base : public VariableKeyLength<16, 0, INT_MAX>, public MessageAuthenticationCode
{
public:
virtual ~HMAC_Base() {}
/// \brief Construct a HMAC_Base
HMAC_Base() : m_innerHashKeyed(false) {}
void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &params);
@ -53,6 +55,8 @@ public:
CRYPTOPP_CONSTANT(DIGESTSIZE=T::DIGESTSIZE)
CRYPTOPP_CONSTANT(BLOCKSIZE=T::BLOCKSIZE)
virtual ~HMAC() {}
/// \brief Construct a HMAC
HMAC() {}
/// \brief Construct a HMAC
@ -63,6 +67,7 @@ public:
static std::string StaticAlgorithmName() {return std::string("HMAC(") + T::StaticAlgorithmName() + ")";}
std::string AlgorithmName() const {return std::string("HMAC(") + m_hash.AlgorithmName() + ")";}
std::string AlgorithmProvider() const {return m_hash.AlgorithmProvider();}
private:
HashTransformation & AccessHash() {return m_hash;}

View File

@ -41,6 +41,8 @@ class CRYPTOPP_NO_VTABLE IteratedHashBase : public BASE
public:
typedef T HashWordType;
virtual ~IteratedHashBase() {}
/// \brief Construct an IteratedHashBase
IteratedHashBase() : m_countLo(0), m_countHi(0) {}
@ -82,6 +84,16 @@ public:
/// The hash is restarted the hash for the next message.
void TruncatedFinal(byte *digest, size_t digestSize);
/// \brief Retrieve the provider of this algorithm
/// \return the algorithm provider
/// \details The algorithm provider can be a name like "C++", "SSE", "NEON", "AESNI",
/// "ARMv8" and "Power8". C++ is standard C++ code. Other labels, like SSE,
/// usually indicate a specialized implementation using instructions from a higher
/// instruction set architecture (ISA). Future labels may include external hardware
/// like a hardware security module (HSM).
/// \note Provider is not universally implemented yet.
virtual std::string AlgorithmProvider() const { return "C++"; }
protected:
inline T GetBitCountHi() const {return (m_countLo >> (8*sizeof(T)-3)) + (m_countHi << 3);}
inline T GetBitCountLo() const {return m_countLo << 3;}

13
lea.cpp
View File

@ -573,6 +573,19 @@ extern size_t LEA_Dec_AdvancedProcessBlocks_NEON(const word32* subKeys, size_t r
# endif
#endif
std::string LEA::Base::AlgorithmProvider() const
{
#if defined(CRYPTOPP_SSSE3_AVAILABLE)
if (HasSSSE3())
return "SSSE3";
#endif
#if (CRYPTOPP_ARM_NEON_AVAILABLE)
if (HasNEON())
return "NEON";
#endif
return "C++";
}
void LEA::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params)
{
CRYPTOPP_UNUSED(params);

1
lea.h
View File

@ -49,6 +49,7 @@ public:
{
protected:
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
std::string AlgorithmProvider() const;
SecBlock<word32> m_rkey;
mutable SecBlock<word32> m_temp;

10
modes.h
View File

@ -157,6 +157,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_ModePolicy : public ModePolicyCommonTe
{
public:
CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CFB";}
std::string AlgorithmProvider() const { return m_cipher->AlgorithmProvider(); }
virtual ~CFB_ModePolicy() {}
IV_Requirement IVRequirement() const {return RANDOM_IV;}
@ -191,6 +192,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : public ModePolicyCommonTe
{
public:
CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "OFB";}
std::string AlgorithmProvider() const { return m_cipher->AlgorithmProvider(); }
bool CipherIsRandomAccess() const {return false;}
IV_Requirement IVRequirement() const {return UNIQUE_IV;}
@ -207,6 +209,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTe
{
public:
CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CTR";}
std::string AlgorithmProvider() const { return m_cipher->AlgorithmProvider(); }
virtual ~CTR_ModePolicy() {}
bool CipherIsRandomAccess() const {return true;}
@ -251,6 +254,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ECB_OneWay : public BlockOrientedCipherMod
{
public:
CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "ECB";}
std::string AlgorithmProvider() const { return m_cipher->AlgorithmProvider(); }
void SetKey(const byte *key, size_t length, const NameValuePairs &params = g_nullNameValuePairs)
{m_cipher->SetKey(key, length, params); BlockOrientedCipherModeBase::ResizeBuffers();}
@ -264,6 +268,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_ModeBase : public BlockOrientedCipherM
{
public:
CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CBC";}
std::string AlgorithmProvider() const { return m_cipher->AlgorithmProvider(); }
IV_Requirement IVRequirement() const {return UNPREDICTABLE_RANDOM_IV;}
bool RequireAlignedInput() const {return false;}
@ -283,6 +288,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Encryption : public CBC_Encryption
{
public:
CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CBC/CTS";}
std::string AlgorithmProvider() const { return m_cipher->AlgorithmProvider(); }
void SetStolenIV(byte *iv) {m_stolenIV = iv;}
unsigned int MinLastBlockSize() const {return BlockSize()+1;}
@ -332,6 +338,8 @@ public:
/// Shoup's ECIES.
static std::string CRYPTOPP_API StaticAlgorithmName()
{return CIPHER::StaticAlgorithmName() + "/" + BASE::StaticAlgorithmName();}
std::string AlgorithmProvider() const
{ return this->m_cipher->AlgorithmProvider(); }
/// \brief Construct a CipherModeFinalTemplate
CipherModeFinalTemplate_CipherHolder()
@ -406,6 +414,8 @@ public:
/// \note AlgorithmName is not universally implemented yet
std::string AlgorithmName() const
{return (this->m_cipher ? this->m_cipher->AlgorithmName() + "/" : std::string("")) + BASE::StaticAlgorithmName();}
std::string AlgorithmProvider() const
{ return this->m_cipher ? this->m_cipher->AlgorithmProvider() : "C++"; }
};
CRYPTOPP_DLL_TEMPLATE_CLASS CFB_CipherTemplate<AbstractPolicyHolder<CFB_CipherAbstractPolicy, CFB_ModePolicy> >;

10
osrng.h
View File

@ -221,6 +221,8 @@ public:
void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length)
{m_rng->GenerateIntoBufferedTransformation(target, channel, length);}
std::string AlgorithmProvider() const;
private:
member_ptr<RandomNumberGenerator> m_rng;
};
@ -253,6 +255,14 @@ void AutoSeededX917RNG<BLOCK_CIPHER>::Reseed(bool blocking, const byte *input, s
Reseed(key, BLOCK_CIPHER::DEFAULT_KEYLENGTH, seed, NULLPTR);
}
template <class BLOCK_CIPHER>
std::string AutoSeededX917RNG<BLOCK_CIPHER>::AlgorithmProvider() const
{
// Hack for now... We need to instantiate one
typename BLOCK_CIPHER::Encryption bc;
return bc.AlgorithmProvider();
}
CRYPTOPP_DLL_TEMPLATE_CLASS AutoSeededX917RNG<AES>;
#if defined(CRYPTOPP_DOXYGEN_PROCESSING)

View File

@ -17,6 +17,11 @@
NAMESPACE_BEGIN(CryptoPP)
std::string PadlockRNG::AlgorithmProvider() const
{
return "Padlock";
}
PadlockRNG::PadlockRNG(word32 divisor)
: m_divisor(DivisorHelper(divisor)), m_msr(0)
{

View File

@ -96,6 +96,8 @@ public:
CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
}
std::string AlgorithmProvider() const;
/// \brief Set the XSTORE divisor
/// \param divisor the XSTORE divisor
/// \returns the old XSTORE divisor

View File

@ -11,6 +11,12 @@ NAMESPACE_BEGIN(CryptoPP)
#define CONSTANT_TIME_CARRY(a,b) ((a ^ ((a ^ b) | ((a - b) ^ b))) >> (sizeof(a) * 8 - 1))
template <class T>
std::string Poly1305_Base<T>::AlgorithmProvider() const
{
return m_cipher.AlgorithmProvider();
}
template <class T>
void Poly1305_Base<T>::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
{

View File

@ -80,6 +80,8 @@ public:
unsigned int BlockSize() const {return BLOCKSIZE;}
unsigned int DigestSize() const {return DIGESTSIZE;}
std::string AlgorithmProvider() const;
protected:
void HashBlocks(const byte *input, size_t length, word32 padbit);
void HashFinal(byte *mac, size_t length);

View File

@ -206,6 +206,11 @@ inline void RDRAND64(void* output)
}
#endif // CRYPTOPP_BOOL_X64, CRYPTOPP_BOOL_X32 and RDRAND64
std::string RDRAND::AlgorithmProvider() const
{
return "RDRAND";
}
RDRAND::RDRAND()
{
if (!HasRDRAND())
@ -363,6 +368,11 @@ inline void RDSEED64(void* output)
}
#endif // CRYPTOPP_BOOL_X64 and RDSEED64
std::string RDSEED::AlgorithmProvider() const
{
return "RDSEED";
}
RDSEED::RDSEED()
{
if (!HasRDSEED())

View File

@ -80,6 +80,8 @@ public:
// Override to avoid the base class' throw.
CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
}
std::string AlgorithmProvider() const;
};
/// \brief Exception thrown when a RDSEED generator encounters
@ -130,6 +132,8 @@ public:
// Override to avoid the base class' throw.
CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
}
std::string AlgorithmProvider() const;
};
NAMESPACE_END

View File

@ -118,9 +118,7 @@ void RegisterFactories2()
RegisterSymmetricCipherDefaultFactories<CTR_Mode<AES> >();
RegisterSymmetricCipherDefaultFactories<Salsa20>();
RegisterSymmetricCipherDefaultFactories<XSalsa20>();
RegisterSymmetricCipherDefaultFactories<ChaCha8>();
RegisterSymmetricCipherDefaultFactories<ChaCha12>();
RegisterSymmetricCipherDefaultFactories<ChaCha20>();
RegisterSymmetricCipherDefaultFactories<ChaCha>();
RegisterSymmetricCipherDefaultFactories<Sosemanuk>();
RegisterSymmetricCipherDefaultFactories<Rabbit>();
RegisterSymmetricCipherDefaultFactories<RabbitWithIV>();

View File

@ -310,6 +310,27 @@ extern size_t Rijndael_Dec_AdvancedProcessBlocks128_6x1_ALTIVEC(const word32 *su
const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
#endif
std::string Rijndael::Base::AlgorithmProvider() const
{
#if (CRYPTOPP_AESNI_AVAILABLE)
if (HasAESNI())
return "AESNI";
#endif
#if CRYPTOPP_SSE2_ASM_AVAILABLE && !defined(CRYPTOPP_DISABLE_RIJNDAEL_ASM)
if (HasSSE2())
return "SSE2";
#endif
#if (CRYPTOPP_ARM_AES_AVAILABLE)
if (HasAES())
return "ARMv8";
#endif
#if (CRYPTOPP_POWER8_AES_AVAILABLE)
if (HasAES())
return "Power8";
#endif
return "C++";
}
void Rijndael::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLen, const NameValuePairs &)
{
AssertValidKeyLength(keyLen);

View File

@ -44,6 +44,7 @@ class CRYPTOPP_DLL Rijndael : public Rijndael_Info, public BlockCipherDocumentat
{
public:
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
std::string AlgorithmProvider() const;
protected:
static void FillEncTable();

View File

@ -95,6 +95,15 @@ void Salsa20_Core(word32* data, unsigned int rounds)
data[i] += x[i];
}
std::string Salsa20_Policy::AlgorithmProvider() const
{
#if CRYPTOPP_SSE2_ASM_AVAILABLE && !defined(CRYPTOPP_DISABLE_SALSA_ASM)
if (HasSSE2())
return "SSE2";
#endif
return "C++";
}
void Salsa20_Policy::CipherSetKey(const NameValuePairs &params, const byte *key, size_t length)
{
m_rounds = params.GetIntValueWithDefault(Name::Rounds(), 20);

View File

@ -45,6 +45,8 @@ protected:
unsigned int GetOptimalBlockSize() const;
#endif
std::string AlgorithmProvider() const;
FixedSizeAlignedSecBlock<word32, 16> m_state;
int m_rounds;
};

71
sha.cpp
View File

@ -151,6 +151,23 @@ ANONYMOUS_NAMESPACE_END
// end of Steve Reid's code //
//////////////////////////////
std::string SHA1::AlgorithmProvider() const
{
#if CRYPTOPP_SHANI_AVAILABLE
if (HasSHA())
return "SHANI";
#endif
#if CRYPTOPP_SSE2_ASM_AVAILABLE && !defined(CRYPTOPP_DISABLE_SHA_ASM)
if (HasSSE2())
return "SSE2";
#endif
#if CRYPTOPP_ARM_SHA_AVAILABLE
if (HasSHA1())
return "ARMv8";
#endif
return "C++";
}
void SHA1::InitState(HashWordType *state)
{
state[0] = 0x67452301;
@ -320,6 +337,32 @@ void SHA256_HashBlock_CXX(word32 *state, const word32 *data)
ANONYMOUS_NAMESPACE_END
std::string SHA256_AlgorithmProvider()
{
#if CRYPTOPP_SHANI_AVAILABLE
if (HasSHA())
return "SHANI";
#endif
#if CRYPTOPP_SSE2_ASM_AVAILABLE && !defined(CRYPTOPP_DISABLE_SHA_ASM)
if (HasSSE2())
return "SSE2";
#endif
#if CRYPTOPP_ARM_SHA_AVAILABLE
if (HasSHA2())
return "ARMv8";
#endif
#if (CRYPTOPP_POWER8_SHA_AVAILABLE)
if (HasSHA256())
return "Power8";
#endif
return "C++";
}
std::string SHA224::AlgorithmProvider() const
{
return SHA256_AlgorithmProvider();
}
void SHA224::InitState(HashWordType *state)
{
static const word32 s[8] = {0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4};
@ -668,6 +711,11 @@ void CRYPTOPP_FASTCALL SHA256_HashMultipleBlocks_SSE2(word32 *state, const word3
}
#endif
std::string SHA256::AlgorithmProvider() const
{
return SHA256_AlgorithmProvider();
}
void SHA256::Transform(word32 *state, const word32 *data)
{
CRYPTOPP_ASSERT(state);
@ -812,6 +860,29 @@ size_t SHA224::HashMultipleBlocks(const word32 *input, size_t length)
// *************************************************************
std::string SHA512_AlgorithmProvider()
{
#if CRYPTOPP_SSE2_ASM_AVAILABLE && !defined(CRYPTOPP_DISABLE_SHA_ASM)
if (HasSSE2())
return "SSE2";
#endif
#if (CRYPTOPP_POWER8_SHA_AVAILABLE)
if (HasSHA512())
return "Power8";
#endif
return "C++";
}
std::string SHA384::AlgorithmProvider() const
{
return SHA512_AlgorithmProvider();
}
std::string SHA512::AlgorithmProvider() const
{
return SHA512_AlgorithmProvider();
}
void SHA384::InitState(HashWordType *state)
{
const word64 s[8] = {

14
sha.h
View File

@ -50,6 +50,8 @@ public:
/// \brief The algorithm name
/// \returns C-style string "SHA-1"
CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";}
// Algorithm class
std::string AlgorithmProvider() const;
protected:
size_t HashMultipleBlocks(const HashWordType *input, size_t length);
@ -87,6 +89,9 @@ public:
/// \returns C-style string "SHA-256"
CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";}
// Algorithm class
std::string AlgorithmProvider() const;
protected:
size_t HashMultipleBlocks(const HashWordType *input, size_t length);
};
@ -123,6 +128,9 @@ public:
/// \returns C-style string "SHA-224"
CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";}
// Algorithm class
std::string AlgorithmProvider() const;
protected:
size_t HashMultipleBlocks(const HashWordType *input, size_t length);
};
@ -157,6 +165,9 @@ public:
/// \brief The algorithm name
/// \returns C-style string "SHA-512"
CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";}
// Algorithm class
std::string AlgorithmProvider() const;
};
/// \brief SHA-384 message digest
@ -189,6 +200,9 @@ public:
/// \brief The algorithm name
/// \returns C-style string "SHA-384"
CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";}
// Algorithm class
std::string AlgorithmProvider() const;
};
NAMESPACE_END

View File

@ -43,6 +43,11 @@ extern size_t SIMECK64_Dec_AdvancedProcessBlocks_SSSE3(const word32* subKeys, si
# endif // CRYPTOPP_SSSE3_AVAILABLE
#endif // CRYPTOPP_SIMECK_ADVANCED_PROCESS_BLOCKS
std::string SIMECK32::Base::AlgorithmProvider() const
{
return "C++";
}
void SIMECK32::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params)
{
CRYPTOPP_UNUSED(params);
@ -97,6 +102,15 @@ void SIMECK32::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock
oblock(m_t[0])(m_t[1]);
}
std::string SIMECK64::Base::AlgorithmProvider() const
{
#if (CRYPTOPP_SSSE3_AVAILABLE)
if (HasSSSE3())
return "SSSE3";
#endif
return "C++";
}
void SIMECK64::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params)
{
CRYPTOPP_UNUSED(params);

View File

@ -62,6 +62,7 @@ public:
{
protected:
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
std::string AlgorithmProvider() const;
FixedSizeSecBlock<word16, ROUNDS> m_rk;
mutable FixedSizeSecBlock<word16, 5> m_t;
@ -111,6 +112,7 @@ public:
{
protected:
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
std::string AlgorithmProvider() const;
FixedSizeSecBlock<word32, ROUNDS> m_rk;
mutable FixedSizeSecBlock<word32, 5> m_t;

View File

@ -225,6 +225,19 @@ extern size_t SIMON128_Dec_AdvancedProcessBlocks_SSSE3(const word64* subKeys, si
const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
#endif
std::string SIMON64::Base::AlgorithmProvider() const
{
#if defined(CRYPTOPP_SSE41_AVAILABLE)
if (HasSSE41())
return "SSE4.1";
#endif
#if (CRYPTOPP_ARM_NEON_AVAILABLE)
if (HasNEON())
return "NEON";
#endif
return "C++";
}
void SIMON64::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params)
{
CRYPTOPP_ASSERT(keyLength == 12 || keyLength == 16);
@ -304,6 +317,19 @@ void SIMON64::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock,
///////////////////////////////////////////////////////////
std::string SIMON128::Base::AlgorithmProvider() const
{
#if defined(CRYPTOPP_SSSE3_AVAILABLE)
if (HasSSSE3())
return "SSSE3";
#endif
#if (CRYPTOPP_ARM_NEON_AVAILABLE)
if (HasNEON())
return "NEON";
#endif
return "C++";
}
void SIMON128::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params)
{
CRYPTOPP_ASSERT(keyLength == 16 || keyLength == 24 || keyLength == 32);

View File

@ -84,6 +84,8 @@ public:
"(" + IntToString(m_kwords*sizeof(word32)*8) + ")");
}
std::string AlgorithmProvider() const;
protected:
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
};
@ -107,7 +109,7 @@ public:
/// \since Crypto++ 6.0
class CRYPTOPP_NO_VTABLE Dec : public Base
{
public:
public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
#if CRYPTOPP_SIMON64_ADVANCED_PROCESS_BLOCKS
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
@ -141,6 +143,8 @@ public:
"(" + IntToString(m_kwords*sizeof(word64)*8) + ")");
}
std::string AlgorithmProvider() const;
protected:
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
};
@ -164,7 +168,7 @@ public:
/// \since Crypto++ 6.0
class CRYPTOPP_NO_VTABLE Dec : public Base
{
public:
public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
#if CRYPTOPP_SIMON128_ADVANCED_PROCESS_BLOCKS
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;

View File

@ -19,6 +19,15 @@
NAMESPACE_BEGIN(CryptoPP)
std::string SosemanukPolicy::AlgorithmProvider() const
{
#if CRYPTOPP_SSE2_ASM_AVAILABLE
if (HasSSE2())
return "SSE2";
#endif
return "C++";
}
void SosemanukPolicy::CipherSetKey(const NameValuePairs &params, const byte *userKey, size_t keylen)
{
CRYPTOPP_UNUSED(params);

View File

@ -39,6 +39,8 @@ protected:
unsigned int GetOptimalBlockSize() const;
#endif
std::string AlgorithmProvider() const;
FixedSizeSecBlock<word32, 25*4> m_key;
FixedSizeAlignedSecBlock<word32, 12> m_state;
};

View File

@ -200,6 +200,19 @@ extern size_t SPECK128_Dec_AdvancedProcessBlocks_SSSE3(const word64* subKeys, si
const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
#endif
std::string SPECK64::Base::AlgorithmProvider() const
{
#if defined(CRYPTOPP_SSE41_AVAILABLE)
if (HasSSE41())
return "SSE4.1";
#endif
#if (CRYPTOPP_ARM_NEON_AVAILABLE)
if (HasNEON())
return "NEON";
#endif
return "C++";
}
void SPECK64::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params)
{
CRYPTOPP_ASSERT(keyLength == 12 || keyLength == 16);
@ -279,6 +292,19 @@ void SPECK64::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock,
///////////////////////////////////////////////////////////
std::string SPECK128::Base::AlgorithmProvider() const
{
#if defined(CRYPTOPP_SSSE3_AVAILABLE)
if (HasSSSE3())
return "SSSE3";
#endif
#if (CRYPTOPP_ARM_NEON_AVAILABLE)
if (HasNEON())
return "NEON";
#endif
return "C++";
}
void SPECK128::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params)
{
CRYPTOPP_ASSERT(keyLength == 16 || keyLength == 24 || keyLength == 32);

12
speck.h
View File

@ -84,6 +84,8 @@ public:
"(" + IntToString(m_kwords*sizeof(word32)*8) + ")");
}
std::string AlgorithmProvider() const;
protected:
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
};
@ -94,7 +96,7 @@ public:
/// \since Crypto++ 6.0
class CRYPTOPP_NO_VTABLE Enc : public Base
{
public:
public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
#if CRYPTOPP_SPECK64_ADVANCED_PROCESS_BLOCKS
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
@ -107,7 +109,7 @@ public:
/// \since Crypto++ 6.0
class CRYPTOPP_NO_VTABLE Dec : public Base
{
public:
public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
#if CRYPTOPP_SPECK64_ADVANCED_PROCESS_BLOCKS
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
@ -141,6 +143,8 @@ public:
"(" + IntToString(m_kwords*sizeof(word64)*8) + ")");
}
std::string AlgorithmProvider() const;
protected:
void UncheckedSetKey(const byte *userKey, unsigned int keyLength, const NameValuePairs &params);
};
@ -151,7 +155,7 @@ public:
/// \since Crypto++ 6.0
class CRYPTOPP_NO_VTABLE Enc : public Base
{
public:
public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
#if CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;
@ -164,7 +168,7 @@ public:
/// \since Crypto++ 6.0
class CRYPTOPP_NO_VTABLE Dec : public Base
{
public:
public:
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
#if CRYPTOPP_SPECK128_ADVANCED_PROCESS_BLOCKS
size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;

View File

@ -5,25 +5,25 @@
/// \details This file contains helper classes for implementing stream ciphers.
/// All this infrastructure may look very complex compared to what's in Crypto++ 4.x,
/// but stream ciphers implementations now support a lot of new functionality,
/// including better performance (minimizing copying), resetting of keys and IVs, and methods to
/// query which features are supported by a cipher.
/// \details Here's an explanation of these classes. The word "policy" is used here to mean a class with a
/// set of methods that must be implemented by individual stream cipher implementations.
/// This is usually much simpler than the full stream cipher API, which is implemented by
/// either AdditiveCipherTemplate or CFB_CipherTemplate using the policy. So for example, an
/// implementation of SEAL only needs to implement the AdditiveCipherAbstractPolicy interface
/// (since it's an additive cipher, i.e., it xors a keystream into the plaintext).
/// See this line in seal.h:
/// including better performance (minimizing copying), resetting of keys and IVs, and
/// methods to query which features are supported by a cipher.
/// \details Here's an explanation of these classes. The word "policy" is used here to
/// mean a class with a set of methods that must be implemented by individual stream
/// cipher implementations. This is usually much simpler than the full stream cipher
/// API, which is implemented by either AdditiveCipherTemplate or CFB_CipherTemplate
/// using the policy. So for example, an implementation of SEAL only needs to implement
/// the AdditiveCipherAbstractPolicy interface (since it's an additive cipher, i.e., it
/// xors a keystream into the plaintext). See this line in seal.h:
/// <pre>
/// typedef SymmetricCipherFinal\<ConcretePolicyHolder\<SEAL_Policy\<B\>, AdditiveCipherTemplate\<\> \> \> Encryption;
/// </pre>
/// \details AdditiveCipherTemplate and CFB_CipherTemplate are designed so that they don't need
/// to take a policy class as a template parameter (although this is allowed), so that
/// their code is not duplicated for each new cipher. Instead they each
/// get a reference to an abstract policy interface by calling AccessPolicy() on itself, so
/// \details AdditiveCipherTemplate and CFB_CipherTemplate are designed so that they don't
/// need to take a policy class as a template parameter (although this is allowed), so
/// that their code is not duplicated for each new cipher. Instead they each get a
/// reference to an abstract policy interface by calling AccessPolicy() on itself, so
/// AccessPolicy() must be overridden to return the actual policy reference. This is done
/// by the ConceretePolicyHolder class. Finally, SymmetricCipherFinal implements the constructors and
/// other functions that must be implemented by the most derived class.
/// by the ConceretePolicyHolder class. Finally, SymmetricCipherFinal implements the
/// constructors and other functions that must be implemented by the most derived class.
#ifndef CRYPTOPP_STRCIPHR_H
#define CRYPTOPP_STRCIPHR_H
@ -174,6 +174,22 @@ struct CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AdditiveCipherAbstractPolicy
virtual void SeekToIteration(lword iterationCount)
{CRYPTOPP_UNUSED(iterationCount); CRYPTOPP_ASSERT(!CipherIsRandomAccess());
throw NotImplemented("StreamTransformation: this object doesn't support random access");}
/// \brief Retrieve the provider of this algorithm
/// \return the algorithm provider
/// \details The algorithm provider can be a name like "C++", "SSE", "NEON", "AESNI",
/// "ARMv8" and "Power8". C++ is standard C++ code. Other labels, like SSE,
/// usually indicate a specialized implementation using instructions from a higher
/// instruction set architecture (ISA). Future labels may include external hardware
/// like a hardware security module (HSM).
/// \details Generally speaking Wei Dai's original IA-32 ASM code falls under "SSE2".
/// Labels like "SSSE3" and "SSE4.1" follow after Wei's code and use intrinsics
/// instead of ASM.
/// \details Algorithms which combine different instructions or ISAs provide the
/// dominant one. For example on x86 <tt>AES/GCM</tt> returns "AESNI" rather than
/// "CLMUL" or "AES+SSE4.1" or "AES+CLMUL" or "AES+SSE4.1+CLMUL".
/// \note Provider is not universally implemented yet.
virtual std::string AlgorithmProvider() const { return "C++"; }
};
/// \brief Base class for additive stream ciphers
@ -277,8 +293,8 @@ public:
/// \brief Generate random array of bytes
/// \param output the byte buffer
/// \param size the length of the buffer, in bytes
/// \details All generated values are uniformly distributed over the range specified within the
/// the constraints of a particular generator.
/// \details All generated values are uniformly distributed over the range specified
/// within the constraints of a particular generator.
void GenerateBlock(byte *output, size_t size);
/// \brief Apply keystream to data
@ -336,6 +352,22 @@ public:
/// \sa IsRandomAccess()
void Seek(lword position);
/// \brief Retrieve the provider of this algorithm
/// \return the algorithm provider
/// \details The algorithm provider can be a name like "C++", "SSE", "NEON", "AESNI",
/// "ARMv8" and "Power8". C++ is standard C++ code. Other labels, like SSE,
/// usually indicate a specialized implementation using instructions from a higher
/// instruction set architecture (ISA). Future labels may include external hardware
/// like a hardware security module (HSM).
/// \details Generally speaking Wei Dai's original IA-32 ASM code falls under "SSE2".
/// Labels like "SSSE3" and "SSE4.1" follow after Wei's code and use intrinsics
/// instead of ASM.
/// \details Algorithms which combine different instructions or ISAs provide the
/// dominant one. For example on x86 <tt>AES/GCM</tt> returns "AESNI" rather than
/// "CLMUL" or "AES+SSE4.1" or "AES+CLMUL" or "AES+SSE4.1+CLMUL".
/// \note Provider is not universally implemented yet.
virtual std::string AlgorithmProvider() const { return this->GetPolicy().AlgorithmProvider(); }
typedef typename BASE::PolicyInterface PolicyInterface;
protected:
@ -401,6 +433,22 @@ public:
virtual void CipherResynchronize(const byte *iv, size_t length)
{CRYPTOPP_UNUSED(iv); CRYPTOPP_UNUSED(length);
throw NotImplemented("SimpleKeyingInterface: this object doesn't support resynchronization");}
/// \brief Retrieve the provider of this algorithm
/// \return the algorithm provider
/// \details The algorithm provider can be a name like "C++", "SSE", "NEON", "AESNI",
/// "ARMv8" and "Power8". C++ is standard C++ code. Other labels, like SSE,
/// usually indicate a specialized implementation using instructions from a higher
/// instruction set architecture (ISA). Future labels may include external hardware
/// like a hardware security module (HSM).
/// \details Generally speaking Wei Dai's original IA-32 ASM code falls under "SSE2".
/// Labels like "SSSE3" and "SSE4.1" follow after Wei's code and use intrinsics
/// instead of ASM.
/// \details Algorithms which combine different instructions or ISAs provide the
/// dominant one. For example on x86 <tt>AES/GCM</tt> returns "AESNI" rather than
/// "CLMUL" or "AES+SSE4.1" or "AES+CLMUL" or "AES+SSE4.1+CLMUL".
/// \note Provider is not universally implemented yet.
virtual std::string AlgorithmProvider() const { return "C++"; }
};
/// \brief Base class for feedback based stream ciphers
@ -539,6 +587,22 @@ public:
/// \returns true if the stream cipher is self inverting, false otherwise
bool IsSelfInverting() const {return false;}
/// \brief Retrieve the provider of this algorithm
/// \return the algorithm provider
/// \details The algorithm provider can be a name like "C++", "SSE", "NEON", "AESNI",
/// "ARMv8" and "Power8". C++ is standard C++ code. Other labels, like SSE,
/// usually indicate a specialized implementation using instructions from a higher
/// instruction set architecture (ISA). Future labels may include external hardware
/// like a hardware security module (HSM).
/// \details Generally speaking Wei Dai's original IA-32 ASM code falls under "SSE2".
/// Labels like "SSSE3" and "SSE4.1" follow after Wei's code and use intrinsics
/// instead of ASM.
/// \details Algorithms which combine different instructions or ISAs provide the
/// dominant one. For example on x86 <tt>AES/GCM</tt> returns "AESNI" rather than
/// "CLMUL" or "AES+SSE4.1" or "AES+CLMUL" or "AES+SSE4.1+CLMUL".
/// \note Provider is not universally implemented yet.
virtual std::string AlgorithmProvider() const { return this->GetPolicy().AlgorithmProvider(); }
typedef typename BASE::PolicyInterface PolicyInterface;
protected:

1
vmac.h
View File

@ -25,6 +25,7 @@ class VMAC_Base : public IteratedHashBase<word64, MessageAuthenticationCode>
{
public:
std::string AlgorithmName() const {return std::string("VMAC(") + GetCipher().AlgorithmName() + ")-" + IntToString(DigestSize()*8);}
std::string AlgorithmProvider() const {return GetCipher().AlgorithmProvider();}
unsigned int IVSize() const {return GetCipher().BlockSize();}
unsigned int MinIVLength() const {return 1;}
void Resynchronize(const byte *nonce, int length=-1);

View File

@ -108,7 +108,5 @@ void WAKE_ROFB_Policy<B>::Iterate(KeystreamOperation operation, byte *output, co
*/
template class WAKE_Policy<BigEndian>;
template class WAKE_Policy<LittleEndian>;
//template class WAKE_ROFB_Policy<BigEndian>;
//template class WAKE_ROFB_Policy<LittleEndian>;
NAMESPACE_END

16
wake.h
View File

@ -54,22 +54,6 @@ struct WAKE_OFB : public WAKE_OFB_Info<B>, public SymmetricCipherDocumentation
typedef Encryption Decryption;
};
/*
template <class B = BigEndian>
class WAKE_ROFB_Policy : public WAKE_Policy<B>
{
protected:
void Iterate(KeystreamOperation operation, byte *output, const byte *input, unsigned int iterationCount);
};
template <class B = BigEndian>
struct WAKE_ROFB : public WAKE_Info<B>
{
typedef SymmetricCipherTemplate<ConcretePolicyHolder<AdditiveCipherTemplate<>, WAKE_ROFB_Policy<B> > > Encryption;
typedef Encryption Decryption;
};
*/
NAMESPACE_END
#endif

View File

@ -89,6 +89,15 @@ void Whirlpool_TestInstantiations()
}
#endif
std::string Whirlpool::AlgorithmProvider() const
{
#if CRYPTOPP_SSE2_ASM_AVAILABLE
if (HasSSE2())
return "SSE2";
#endif
return "C++";
}
void Whirlpool::InitState(HashWordType *state)
{
memset(state, 0, 8*sizeof(state[0]));

View File

@ -27,6 +27,7 @@ public:
static void Transform(word64 *digest, const word64 *data);
void TruncatedFinal(byte *hash, size_t size);
CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Whirlpool";}
std::string AlgorithmProvider() const;
};
NAMESPACE_END