Add Panama cipher AlgorithmProvider()

pull/709/head
Jeffrey Walton 2018-08-18 14:31:00 -04:00
parent a6fadbad77
commit 03d78fb783
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
2 changed files with 27 additions and 9 deletions

View File

@ -17,6 +17,21 @@ NAMESPACE_BEGIN(CryptoPP)
# pragma warning(disable: 4731) # pragma warning(disable: 4731)
#endif #endif
template <class B>
std::string Panama<B>::AlgorithmProvider() const
{
#ifndef CRYPTOPP_DISABLE_PANAMA_ASM
# if CRYPTOPP_SSSE3_ASM_AVAILABLE
if(HasSSSE3())
return "SSSE3";
# elif CRYPTOPP_SSE2_ASM_AVAILABLE
if(HasSSE2())
return "SSE2";
# endif
#endif
return "C++";
}
template <class B> template <class B>
void Panama<B>::Reset() void Panama<B>::Reset()
{ {
@ -57,9 +72,7 @@ void CRYPTOPP_NOINLINE Panama_SSE2_Pull(size_t count, word32 *state, word32 *z,
#endif #endif
#endif // #ifdef CRYPTOPP_GENERATE_X64_MASM #endif // #ifdef CRYPTOPP_GENERATE_X64_MASM
#if CRYPTOPP_BOOL_X32 #if CRYPTOPP_BOOL_X86
#define REG_loopEnd r8d
#elif CRYPTOPP_BOOL_X86
#define REG_loopEnd [esp] #define REG_loopEnd [esp]
#elif defined(CRYPTOPP_GENERATE_X64_MASM) #elif defined(CRYPTOPP_GENERATE_X64_MASM)
#define REG_loopEnd rdi #define REG_loopEnd rdi
@ -286,10 +299,7 @@ void CRYPTOPP_NOINLINE Panama_SSE2_Pull(size_t count, word32 *state, word32 *z,
AS2( movdqa XMMWORD_PTR [AS_REG_2+1*16], xmm1) AS2( movdqa XMMWORD_PTR [AS_REG_2+1*16], xmm1)
AS2( movdqa XMMWORD_PTR [AS_REG_2+0*16], xmm0) AS2( movdqa XMMWORD_PTR [AS_REG_2+0*16], xmm0)
#if CRYPTOPP_BOOL_X32 #if CRYPTOPP_BOOL_X86
AS2( add esp, 8)
AS_POP_IF86( bp)
#elif CRYPTOPP_BOOL_X86
AS2( add esp, 4) AS2( add esp, 4)
AS_POP_IF86( bp) AS_POP_IF86( bp)
#endif #endif
@ -420,7 +430,7 @@ void Panama<B>::Iterate(size_t count, const word32 *p, byte *output, const byte
m_state[17] = bstart; m_state[17] = bstart;
} }
namespace Weak { NAMESPACE_BEGIN(Weak)
template <class B> template <class B>
size_t PanamaHash<B>::HashMultipleBlocks(const word32 *input, size_t length) size_t PanamaHash<B>::HashMultipleBlocks(const word32 *input, size_t length)
{ {
@ -446,7 +456,7 @@ void PanamaHash<B>::TruncatedFinal(byte *hash, size_t size)
this->Restart(); // reinit for next use this->Restart(); // reinit for next use
} }
} NAMESPACE_END
template <class B> template <class B>
void PanamaCipherPolicy<B>::CipherSetKey(const NameValuePairs &params, const byte *key, size_t length) void PanamaCipherPolicy<B>::CipherSetKey(const NameValuePairs &params, const byte *key, size_t length)
@ -485,6 +495,12 @@ void PanamaCipherPolicy<B>::CipherResynchronize(byte *keystreamBuffer, const byt
this->Iterate(32); this->Iterate(32);
} }
template <class B>
std::string PanamaCipherPolicy<B>::AlgorithmProvider() const
{
return Panama<B>::AlgorithmProvider();
}
template <class B> template <class B>
unsigned int PanamaCipherPolicy<B>::GetAlignment() const unsigned int PanamaCipherPolicy<B>::GetAlignment() const
{ {

View File

@ -22,6 +22,7 @@ template <class B>
class CRYPTOPP_NO_VTABLE Panama class CRYPTOPP_NO_VTABLE Panama
{ {
public: public:
std::string AlgorithmProvider() const;
void Reset(); void Reset();
void Iterate(size_t count, const word32 *p=NULLPTR, byte *output=NULLPTR, const byte *input=NULLPTR, KeystreamOperation operation=WRITE_KEYSTREAM); void Iterate(size_t count, const word32 *p=NULLPTR, byte *output=NULLPTR, const byte *input=NULLPTR, KeystreamOperation operation=WRITE_KEYSTREAM);
@ -134,6 +135,7 @@ class PanamaCipherPolicy : public AdditiveCipherConcretePolicy<word32, 8>,
protected Panama<B> protected Panama<B>
{ {
protected: protected:
std::string AlgorithmProvider() const;
void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length); void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
bool CipherIsRandomAccess() const {return false;} bool CipherIsRandomAccess() const {return false;}