Skip to content

Commit d62b106

Browse files
committed
Fixed issue with SiLibs AES Direct (required by DTLS v1.3). ZD 20695
1 parent a28e107 commit d62b106

4 files changed

Lines changed: 54 additions & 19 deletions

File tree

wolfcrypt/benchmark/benchmark.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15758,6 +15758,7 @@ void bench_sphincsKeySign(byte level, byte optim)
1575815758
#else
1575915759
return (double)tickCount / 1000;
1576015760
#endif
15761+
(void)reset;
1576115762
}
1576215763
#endif
1576315764

wolfcrypt/src/aes.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -645,17 +645,19 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
645645
#define WOLFSSL_AES_DIRECT
646646

647647
/* Encrypt: If we choose to never have a fallback to SW: */
648-
#if !defined(NEED_AES_HW_FALLBACK) && (defined(HAVE_AESGCM) || defined(WOLFSSL_AES_DIRECT))
649-
static WARN_UNUSED_RESULT int wc_AesEncrypt( /* calling this one when NO_AES_192 is defined */
648+
#if !defined(NEED_AES_HW_FALLBACK) && \
649+
(defined(HAVE_AESGCM) || defined(WOLFSSL_AES_DIRECT))
650+
/* calling this one when NO_AES_192 is defined */
651+
static WARN_UNUSED_RESULT int wc_AesEncrypt(
650652
Aes* aes, const byte* inBlock, byte* outBlock)
651653
{
652654
int ret;
653655

654-
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
656+
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
655657
ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
656658
if (ret < 0)
657659
return ret;
658-
#endif
660+
#endif
659661

660662
/* Thread mutex protection handled in esp_aes_hw_InUse */
661663
#ifdef NEED_AES_HW_FALLBACK
@@ -670,7 +672,8 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
670672
#endif
671673

672674
/* Decrypt: If we choose to never have a fallback to SW: */
673-
#if !defined(NEED_AES_HW_FALLBACK) && (defined(HAVE_AES_DECRYPT) && defined(WOLFSSL_AES_DIRECT))
675+
#if !defined(NEED_AES_HW_FALLBACK) && \
676+
(defined(HAVE_AES_DECRYPT) && defined(WOLFSSL_AES_DIRECT))
674677
static WARN_UNUSED_RESULT int wc_AesDecrypt(
675678
Aes* aes, const byte* inBlock, byte* outBlock)
676679
{
@@ -1111,6 +1114,9 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(Aes* aes, const byte* inBlock,
11111114
#elif defined(WOLFSSL_RISCV_ASM)
11121115
/* implemented in wolfcrypt/src/port/risc-v/riscv-64-aes.c */
11131116

1117+
#elif defined(WOLFSSL_SILABS_SE_ACCEL)
1118+
/* implemented in wolfcrypt/src/port/silabs/silabs_aes.c */
1119+
11141120
#else
11151121

11161122
/* using wolfCrypt software implementation */
@@ -1127,17 +1133,17 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(Aes* aes, const byte* inBlock,
11271133

11281134
#ifndef WC_AES_BITSLICED
11291135
#if defined(__aarch64__) || !defined(WOLFSSL_ARMASM)
1130-
#if !defined(WOLFSSL_SILABS_SE_ACCEL) || \
1131-
defined(NO_ESP32_CRYPT) || defined(NO_WOLFSSL_ESP32_CRYPT_AES) || \
1132-
defined(NEED_AES_HW_FALLBACK)
1136+
#if !defined(WOLFSSL_ESP32_CRYPT) || \
1137+
(defined(NO_ESP32_CRYPT) || defined(NO_WOLFSSL_ESP32_CRYPT_AES) || \
1138+
defined(NEED_AES_HW_FALLBACK))
11331139
static const FLASH_QUALIFIER word32 rcon[] = {
11341140
0x01000000, 0x02000000, 0x04000000, 0x08000000,
11351141
0x10000000, 0x20000000, 0x40000000, 0x80000000,
11361142
0x1B000000, 0x36000000,
11371143
/* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
11381144
};
1139-
#endif
1140-
#endif
1145+
#endif /* ESP32 */
1146+
#endif /* __aarch64__ || !WOLFSSL_ARMASM */
11411147

11421148
#if defined(__aarch64__) || !defined(WOLFSSL_ARMASM) || \
11431149
defined(WOLFSSL_ARMASM_NO_HW_CRYPTO) || defined(WOLFSSL_AES_DIRECT) || \
@@ -1410,7 +1416,7 @@ static const FLASH_QUALIFIER word32 Te[4][256] = {
14101416
}
14111417
};
14121418

1413-
#if defined(HAVE_AES_DECRYPT) && !defined(WOLFSSL_SILABS_SE_ACCEL)
1419+
#ifdef HAVE_AES_DECRYPT
14141420
#if defined(__aarch64__) || !defined(WOLFSSL_ARMASM)
14151421
static const FLASH_QUALIFIER word32 Td[4][256] = {
14161422
{
@@ -1679,14 +1685,13 @@ static const FLASH_QUALIFIER word32 Td[4][256] = {
16791685
0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
16801686
}
16811687
};
1682-
#endif
1688+
#endif /* __aarch64__ || !WOLFSSL_ARMASM */
16831689
#endif /* HAVE_AES_DECRYPT */
16841690
#endif /* WOLFSSL_AES_SMALL_TABLES */
16851691

16861692
#ifdef HAVE_AES_DECRYPT
1687-
#if (defined(HAVE_AES_CBC) && !defined(WOLFSSL_DEVCRYPTO_CBC) && \
1688-
!defined(WOLFSSL_SILABS_SE_ACCEL)) || \
1689-
defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
1693+
#if (defined(HAVE_AES_CBC) && !defined(WOLFSSL_DEVCRYPTO_CBC)) || \
1694+
defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
16901695
#if defined(__aarch64__) || !defined(WOLFSSL_ARMASM)
16911696
static const FLASH_QUALIFIER byte Td4[256] =
16921697
{
@@ -3091,8 +3096,7 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt(
30913096
#endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT || HAVE_AESGCM */
30923097

30933098
#if defined(HAVE_AES_DECRYPT)
3094-
#if ((defined(HAVE_AES_CBC) && !defined(WOLFSSL_DEVCRYPTO_CBC) && \
3095-
!defined(WOLFSSL_SILABS_SE_ACCEL)) || \
3099+
#if ((defined(HAVE_AES_CBC) && !defined(WOLFSSL_DEVCRYPTO_CBC)) || \
30963100
defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)) && \
30973101
(defined(__aarch64__) || !defined(WOLFSSL_ARMASM))
30983102

@@ -3731,8 +3735,7 @@ static void AesDecryptBlocks_C(Aes* aes, const byte* in, byte* out, word32 sz)
37313735
#endif /* !WC_AES_BITSLICED */
37323736
#endif
37333737

3734-
#if (defined(HAVE_AES_CBC) && !defined(WOLFSSL_DEVCRYPTO_CBC) && \
3735-
!defined(WOLFSSL_SILABS_SE_ACCEL)) || \
3738+
#if (defined(HAVE_AES_CBC) && !defined(WOLFSSL_DEVCRYPTO_CBC)) || \
37363739
defined(WOLFSSL_AES_DIRECT)
37373740
#if defined(__aarch64__) || !defined(WOLFSSL_ARMASM)
37383741
#if !defined(WC_AES_BITSLICED) || defined(WOLFSSL_AES_DIRECT)

wolfcrypt/src/port/silabs/silabs_aes.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,32 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
8989
return ret;
9090
}
9191

92+
#ifdef WOLFSSL_AES_DIRECT
93+
int wc_AesEncrypt(Aes* aes, const byte* inBlock, byte* outBlock)
94+
{
95+
sl_status_t status = sl_se_aes_crypt_ecb(
96+
&(aes->ctx.cmd_ctx),
97+
&(aes->ctx.key),
98+
SL_SE_ENCRYPT,
99+
WC_AES_BLOCK_SIZE,
100+
inBlock,
101+
outBlock);
102+
return (status != SL_STATUS_OK) ? WC_HW_E : 0;
103+
}
104+
105+
int wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
106+
{
107+
sl_status_t status = sl_se_aes_crypt_ecb(
108+
&(aes->ctx.cmd_ctx),
109+
&(aes->ctx.key),
110+
SL_SE_DECRYPT,
111+
WC_AES_BLOCK_SIZE,
112+
inBlock,
113+
outBlock);
114+
return (status != SL_STATUS_OK) ? WC_HW_E : 0;
115+
}
116+
#endif /* WOLFSSL_AES_DIRECT */
117+
92118
int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
93119
{
94120
sl_status_t status = sl_se_aes_crypt_cbc(

wolfssl/wolfcrypt/port/silabs/silabs_aes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ typedef struct {
3838

3939
typedef struct Aes Aes;
4040

41+
#ifdef WOLFSSL_AES_DIRECT
42+
int wc_AesEncrypt(Aes* aes, const byte* inBlock, byte* outBlock);
43+
int wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock);
44+
#endif
45+
4146
#ifdef HAVE_AESGCM
4247
int wc_AesGcmEncrypt_silabs (Aes* aes, byte* out, const byte* in, word32 sz,
4348
const byte* iv, word32 ivSz,

0 commit comments

Comments
 (0)