mirror of
https://github.com/shadps4-emu/ext-cryptopp.git
synced 2024-11-26 19:30:21 +00:00
Add ByteReverse(word128 value)
This speeds up XTS mode on x86_64 by 0.11 cpb
This commit is contained in:
parent
230c558a4b
commit
8f7304b61e
13
misc.h
13
misc.h
@ -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
11
xts.cpp
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user