Add CRYPTOPP_LEA_ARM_SPLAT_ROUNDKEYS for LEA

This commit is contained in:
Jeffrey Walton 2018-06-23 14:19:18 -04:00
parent 2d0d87b57a
commit d9797c414a
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
3 changed files with 19 additions and 1 deletions

View File

@ -140,7 +140,11 @@ uint32x4_t UnpackHigh64(uint32x4_t a, uint32x4_t b)
template <unsigned int IDX>
inline uint32x4_t LoadKey(const word32 rkey[])
{
#if (CRYPTOPP_LEA_ARM_SPLAT_ROUNDKEYS)
return vld1q_u32(&rkey[IDX*4]);
#else
return vdupq_n_u32(rkey[IDX]);
#endif
}
template <unsigned int IDX>
@ -1012,15 +1016,17 @@ size_t LEA_Dec_AdvancedProcessBlocks_SSSE3(const word32* subKeys, size_t rounds,
#endif // CRYPTOPP_SSSE3_AVAILABLE
#if defined(CRYPTOPP_ARM_NEON_AVAILABLE)
# if (CRYPTOPP_LEA_ARM_SPLAT_ROUNDKEYS)
void LEA_SplatKeys_NEON(SecBlock<word32>& rkeys)
{
SecBlock<word32> temp(rkeys.size() * 4);
for (size_t i=0, j=0; i<rkeys.size(); i++, j+=4)
{
vst1q_u32(&temp[j], vdupq_n_u32(rkeys[i]));
vst1q_u32(&temp[j], vdupq_n_u32(rkeys[i]));
}
std::swap(rkeys, temp);
}
# endif // CRYPTOPP_LEA_ARM_SPLAT_ROUNDKEYS
size_t LEA_Enc_AdvancedProcessBlocks_NEON(const word32* subKeys, size_t rounds,
const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags)

View File

@ -567,7 +567,9 @@ extern size_t LEA_Dec_AdvancedProcessBlocks_SSSE3(const word32* subKeys, size_t
# endif
# if (CRYPTOPP_ARM_NEON_AVAILABLE)
# if (CRYPTOPP_LEA_ARM_SPLAT_ROUNDKEYS)
extern void LEA_SplatKeys_NEON(SecBlock<word32>& rkeys);
# endif // CRYPTOPP_LEA_ARM_SPLAT_ROUNDKEYS
extern size_t LEA_Enc_AdvancedProcessBlocks_NEON(const word32* subKeys, size_t rounds,
const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags);
@ -616,8 +618,10 @@ void LEA::Base::UncheckedSetKey(const byte *userKey, unsigned int keyLength, con
LEA_SplatKeys_SSSE3(m_rkey);
#endif
#if (CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS) && (CRYPTOPP_ARM_NEON_AVAILABLE)
# if (CRYPTOPP_LEA_ARM_SPLAT_ROUNDKEYS)
if (HasNEON())
LEA_SplatKeys_NEON(m_rkey);
# endif // CRYPTOPP_LEA_ARM_SPLAT_ROUNDKEYS
#endif
}

8
lea.h
View File

@ -19,6 +19,14 @@
# define CRYPTOPP_LEA_ADVANCED_PROCESS_BLOCKS 1
#endif
// Define this if you want to pre-splat the round key table
// for NEON and Aarch64. Pre-splatting the round key increases
// performance by about 0.7 cpb on ARM server boards like an
// AMD Opteron A1100. However, it crushes performance on ARM
// dev-boards like LeMaker HiKey and Pine64. HiKey and Pine64
// run about 8 cpb slower when pre-splatting the round keys.
// # define CRYPTOPP_LEA_ARM_SPLAT_ROUNDKEYS 1
NAMESPACE_BEGIN(CryptoPP)
/// \brief LEA block cipher information