Merge pull request #6854 from SparkiDev/aes_bit_sliced
AES bitsliced implementation added
This commit is contained in:
commit
c903a8c4a6
11
configure.ac
11
configure.ac
@ -2493,6 +2493,16 @@ then
|
||||
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_AES_CFB"
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE([aes-bitsliced],
|
||||
[AS_HELP_STRING([--enable-aes-bitsliced],[Enable bitsliced implementation of AES (default: disabled)])],
|
||||
[ ENABLED_AESBS=$enableval ],
|
||||
[ ENABLED_AESBS=no ]
|
||||
)
|
||||
|
||||
if test "$ENABLED_AESBS" = "yes"
|
||||
then
|
||||
AM_CFLAGS="$AM_CFLAGS -DWC_AES_BITSLICED -DHAVE_AES_ECB"
|
||||
fi
|
||||
|
||||
# SM4
|
||||
ENABLED_SM4="no"
|
||||
@ -9563,6 +9573,7 @@ echo " * AES-CFB: $ENABLED_AESCFB"
|
||||
echo " * AES-OFB: $ENABLED_AESOFB"
|
||||
echo " * AES-SIV: $ENABLED_AESSIV"
|
||||
echo " * AES-EAX: $ENABLED_AESEAX"
|
||||
echo " * AES Bitspliced: $ENABLED_AESBS"
|
||||
echo " * ARIA: $ENABLED_ARIA"
|
||||
echo " * DES3: $ENABLED_DES3"
|
||||
echo " * Camellia: $ENABLED_CAMELLIA"
|
||||
|
1853
wolfcrypt/src/aes.c
1853
wolfcrypt/src/aes.c
File diff suppressed because it is too large
Load Diff
@ -11089,6 +11089,35 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_AES_ECB
|
||||
{
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb[AES_BLOCK_SIZE] = {
|
||||
0xd0, 0xc9, 0xd9, 0xc9, 0x40, 0xe8, 0x97, 0xb6,
|
||||
0xc8, 0x8c, 0x33, 0x3b, 0xb5, 0x8f, 0x85, 0xd1
|
||||
};
|
||||
XMEMSET(cipher, 0, AES_BLOCK_SIZE * 4);
|
||||
ret = wc_AesEcbEncrypt(enc, cipher, msg, AES_BLOCK_SIZE);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
if (XMEMCMP(cipher, verify_ecb, AES_BLOCK_SIZE))
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
#ifdef HAVE_AES_DECRYPT
|
||||
XMEMSET(plain, 0, AES_BLOCK_SIZE * 4);
|
||||
ret = wc_AesEcbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
#endif /* HAVE_AES_DECRYPT */
|
||||
}
|
||||
#endif
|
||||
|
||||
XMEMSET(cipher, 0, AES_BLOCK_SIZE * 4);
|
||||
ret = wc_AesCbcEncrypt(enc, cipher, msg, AES_BLOCK_SIZE);
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||
|
@ -205,9 +205,50 @@ enum {
|
||||
WOLF_ENUM_DUMMY_LAST_ELEMENT(AES)
|
||||
};
|
||||
|
||||
#ifdef WC_AES_BITSLICED
|
||||
#ifdef WC_AES_BS_WORD_SIZE
|
||||
#define BS_WORD_SIZE WC_AES_BS_WORD_SIZE
|
||||
#elif defined(NO_64BIT)
|
||||
#define BS_WORD_SIZE 32
|
||||
#else
|
||||
#define BS_WORD_SIZE 64
|
||||
#endif
|
||||
|
||||
/* Number of bits to a block. */
|
||||
#define AES_BLOCK_BITS (AES_BLOCK_SIZE * 8)
|
||||
/* Number of bytes of input that can be processed in one call. */
|
||||
#define BS_BLOCK_SIZE (AES_BLOCK_SIZE * BS_WORD_SIZE)
|
||||
/* Number of words in a block. */
|
||||
#define BS_BLOCK_WORDS (AES_BLOCK_BITS / BS_WORD_SIZE)
|
||||
|
||||
#if BS_WORD_SIZE == 64
|
||||
typedef word64 bs_word;
|
||||
#define BS_WORD_SHIFT 6
|
||||
#define bs_bswap(x) ByteReverseWord64(x)
|
||||
#elif BS_WORD_SIZE == 32
|
||||
typedef word32 bs_word;
|
||||
#define BS_WORD_SHIFT 5
|
||||
#define bs_bswap(x) ByteReverseWord32(x)
|
||||
#elif BS_WORD_SIZE == 16
|
||||
typedef word16 bs_word;
|
||||
#define BS_WORD_SHIFT 4
|
||||
#define bs_bswap(x) ByteReverseWord16(x)
|
||||
#elif BS_WORD_SIZE == 8
|
||||
typedef word8 bs_word;
|
||||
#define BS_WORD_SHIFT 3
|
||||
#define bs_bswap(x) (x)
|
||||
#else
|
||||
#error "Word size not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct Aes {
|
||||
/* AESNI needs key first, rounds 2nd, not sure why yet */
|
||||
ALIGN16 word32 key[60];
|
||||
#ifdef WC_AES_BITSLICED
|
||||
/* Extra key schedule space required for bit-slicing technique. */
|
||||
ALIGN16 bs_word bs_key[15 * AES_BLOCK_SIZE * BS_WORD_SIZE];
|
||||
#endif
|
||||
word32 rounds;
|
||||
int keylen;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user