Skip to content

Commit a1d000c

Browse files
Merge pull request #9343 from dgarske/silabs_aesdirect
Fixed issue with SiLibs AES Direct (required by DTLS v1.3)
2 parents c825d0b + 76abc43 commit a1d000c

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
@@ -15752,6 +15752,7 @@ void bench_sphincsKeySign(byte level, byte optim)
1575215752
double current_time(int reset)
1575315753
{
1575415754
portTickType tickCount = xTaskGetTickCount();
15755+
(void)reset;
1575515756
/* if configTICK_RATE_HZ is available use if (default is 1000) */
1575615757
#ifdef configTICK_RATE_HZ
1575715758
return (double)tickCount / configTICK_RATE_HZ;

wolfcrypt/src/aes.c

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

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

655-
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
657+
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
656658
ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
657659
if (ret < 0)
658660
return ret;
659-
#endif
661+
#endif
660662

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

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

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

11171123
/* using wolfCrypt software implementation */
@@ -1128,17 +1134,17 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(Aes* aes, const byte* inBlock,
11281134

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

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

1414-
#if defined(HAVE_AES_DECRYPT) && !defined(WOLFSSL_SILABS_SE_ACCEL)
1420+
#ifdef HAVE_AES_DECRYPT
14151421
#if defined(__aarch64__) || !defined(WOLFSSL_ARMASM)
14161422
static const FLASH_QUALIFIER word32 Td[4][256] = {
14171423
{
@@ -1680,14 +1686,13 @@ static const FLASH_QUALIFIER word32 Td[4][256] = {
16801686
0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
16811687
}
16821688
};
1683-
#endif
1689+
#endif /* __aarch64__ || !WOLFSSL_ARMASM */
16841690
#endif /* HAVE_AES_DECRYPT */
16851691
#endif /* WOLFSSL_AES_SMALL_TABLES */
16861692

16871693
#ifdef HAVE_AES_DECRYPT
1688-
#if (defined(HAVE_AES_CBC) && !defined(WOLFSSL_DEVCRYPTO_CBC) && \
1689-
!defined(WOLFSSL_SILABS_SE_ACCEL)) || \
1690-
defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
1694+
#if (defined(HAVE_AES_CBC) && !defined(WOLFSSL_DEVCRYPTO_CBC)) || \
1695+
defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
16911696
#if defined(__aarch64__) || !defined(WOLFSSL_ARMASM)
16921697
static const FLASH_QUALIFIER byte Td4[256] =
16931698
{
@@ -3092,8 +3097,7 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt(
30923097
#endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT || HAVE_AESGCM */
30933098

30943099
#if defined(HAVE_AES_DECRYPT)
3095-
#if ((defined(HAVE_AES_CBC) && !defined(WOLFSSL_DEVCRYPTO_CBC) && \
3096-
!defined(WOLFSSL_SILABS_SE_ACCEL)) || \
3100+
#if ((defined(HAVE_AES_CBC) && !defined(WOLFSSL_DEVCRYPTO_CBC)) || \
30973101
defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)) && \
30983102
(defined(__aarch64__) || !defined(WOLFSSL_ARMASM))
30993103

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

3735-
#if (defined(HAVE_AES_CBC) && !defined(WOLFSSL_DEVCRYPTO_CBC) && \
3736-
!defined(WOLFSSL_SILABS_SE_ACCEL)) || \
3739+
#if (defined(HAVE_AES_CBC) && !defined(WOLFSSL_DEVCRYPTO_CBC)) || \
37373740
defined(WOLFSSL_AES_DIRECT)
37383741
#if defined(__aarch64__) || !defined(WOLFSSL_ARMASM)
37393742
#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)