AES-GCM: GMULT using 4-bit table

When 64-bit data type available and not big endian code is faster.
--enable-aesgcm=4bit
This commit is contained in:
Sean Parkinson
2020-10-14 14:08:06 +10:00
parent c17f8b58e4
commit d0703f8931
8 changed files with 666 additions and 102 deletions

View File

@@ -127,6 +127,20 @@ WC_STATIC WC_INLINE word32 ByteReverseWord32(word32 value)
#elif defined(WOLF_ALLOW_BUILTIN) && \
defined(__GNUC_PREREQ) && __GNUC_PREREQ(4, 3)
return (word32)__builtin_bswap32(value);
#elif defined(__arm__) && defined(__GNUC__)
__asm__ volatile (
"REV %0, %0 \n"
: "+r" (value)
:
);
return value;
#elif defined(__aarch64__) && defined(__GNUC__)
__asm__ volatile (
"REV %w0, %w0 \n"
: "+r" (value)
:
);
return value;
#elif defined(FAST_ROTATE)
/* 5 instructions with rotate instruction, 9 without */
return (rotrFixed(value, 8U) & 0xff00ff00) |
@@ -193,6 +207,36 @@ WC_STATIC WC_INLINE void ByteReverseWords64(word64* out, const word64* in,
#endif /* WORD64_AVAILABLE && !WOLFSSL_NO_WORD64_OPS */
#ifndef WOLFSSL_NO_XOR_OPS
/* This routine performs a bitwise XOR operation of <*r> and <*a> for <n> number
of wolfssl_words, placing the result in <*r>. */
WC_STATIC WC_INLINE void XorWordsOut(wolfssl_word* r, const wolfssl_word* a,
const wolfssl_word* b, word32 n)
{
word32 i;
for (i = 0; i < n; i++) r[i] = a[i] ^ b[i];
}
/* This routine performs a bitwise XOR operation of <*buf> and <*mask> of n
counts, placing the result in <*buf>. */
WC_STATIC WC_INLINE void xorbufout(void*out, const void* buf, const void* mask,
word32 count)
{
if (((wolfssl_word)out | (wolfssl_word)buf | (wolfssl_word)mask | count) % \
WOLFSSL_WORD_SIZE == 0)
XorWordsOut( (wolfssl_word*)out, (wolfssl_word*)buf,
(const wolfssl_word*)mask, count / WOLFSSL_WORD_SIZE);
else {
word32 i;
byte* o = (byte*)out;
byte* b = (byte*)buf;
const byte* m = (const byte*)mask;
for (i = 0; i < count; i++) o[i] = b[i] ^ m[i];
}
}
/* This routine performs a bitwise XOR operation of <*r> and <*a> for <n> number
of wolfssl_words, placing the result in <*r>. */
WC_STATIC WC_INLINE void XorWords(wolfssl_word* r, const wolfssl_word* a, word32 n)