Add ByteReverse(word128 value)

This speeds up XTS mode on x86_64 by 0.11 cpb
This commit is contained in:
Jeffrey Walton 2022-01-12 10:26:25 -05:00
parent 230c558a4b
commit 8f7304b61e
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
2 changed files with 23 additions and 1 deletions

13
misc.h
View File

@ -2089,6 +2089,19 @@ inline word64 ByteReverse(word64 value)
#endif
}
#if defined(CRYPTOPP_WORD128_AVAILABLE)
/// \brief Reverses bytes in a 128-bit value
/// \param value the 128-bit value to reverse
/// \details ByteReverse calls bswap if available. Otherwise the function uses
/// a combination of rotates on the word128.
/// \since Crypto++ 8.7
inline word128 ByteReverse(word128 value)
{
// TODO: speed this up
return (word128(ByteReverse(word64(value))) << 64) | ByteReverse(word64(value>>64));
}
#endif
/// \brief Reverses bits in a 8-bit value
/// \param value the 8-bit value to reverse
/// \details BitReverse performs a combination of shifts on the byte.

11
xts.cpp
View File

@ -93,7 +93,16 @@ inline void XorBuffer(byte *buf, const byte *mask, size_t count)
// Borrowed from CMAC, but little-endian representation
inline void GF_Double(byte *out, const byte* in, unsigned int len)
{
#if defined(_M_X64) || defined(_M_ARM64) || defined(_LP64) || defined(__LP64__)
#if defined(CRYPTOPP_WORD128_AVAILABLE)
word128 carry = 0, x;
for (size_t i=0, idx=0; i<len/16; ++i, idx+=16)
{
x = GetWord<word128>(false, LITTLE_ENDIAN_ORDER, in+idx);
word128 y = (x >> 127); x = (x << 1) + carry;
PutWord<word128>(false, LITTLE_ENDIAN_ORDER, out+idx, x);
carry = y;
}
#elif defined(_M_X64) || defined(_M_ARM64) || defined(_LP64) || defined(__LP64__)
word64 carry = 0, x;
for (size_t i=0, idx=0; i<len/8; ++i, idx+=8)
{