@@ -233,6 +233,16 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
233233 static WARN_UNUSED_RESULT int wc_AesEncrypt(
234234 Aes* aes, const byte* inBlock, byte* outBlock)
235235 {
236+ #ifdef WOLFSSL_STM32_BARE
237+ /* Bare-metal driver handles mutex, clock and key/IV internally. */
238+ #ifdef WOLFSSL_DHUK
239+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID) {
240+ return wc_Stm32_Aes_DhukOp(aes, outBlock, inBlock,
241+ WC_AES_BLOCK_SIZE, 1 /* encrypt */);
242+ }
243+ #endif
244+ return wc_Stm32_Aes_Ecb(aes, outBlock, inBlock, WC_AES_BLOCK_SIZE, 1);
245+ #else
236246 int ret = 0;
237247 #ifdef WOLFSSL_STM32_CUBEMX
238248 CRYP_HandleTypeDef hcryp;
@@ -247,13 +257,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
247257 return ret;
248258#endif
249259
250- #ifdef WOLFSSL_STM32U5_DHUK
260+ #ifdef WOLFSSL_DHUK
251261 ret = wolfSSL_CryptHwMutexLock();
252262 if (ret != 0)
253263 return ret;
254264
255265 /* Handle making use of wrapped key */
256- if (aes->devId == WOLFSSL_STM32U5_DHUK_WRAPPED_DEVID ) {
266+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID ) {
257267 CRYP_ConfigTypeDef Config = {0};
258268
259269 ret = wc_Stm32_Aes_UnWrap(aes, &hcryp, (const byte*)aes->key,
@@ -373,6 +383,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
373383 wc_Stm32_Aes_Cleanup();
374384
375385 return ret;
386+ #endif /* !WOLFSSL_STM32_BARE */
376387 }
377388#endif /* WOLFSSL_AES_DIRECT || HAVE_AESGCM || HAVE_AESCCM */
378389
@@ -381,6 +392,15 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
381392 static WARN_UNUSED_RESULT int wc_AesDecrypt(
382393 Aes* aes, const byte* inBlock, byte* outBlock)
383394 {
395+ #ifdef WOLFSSL_STM32_BARE
396+ #ifdef WOLFSSL_DHUK
397+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID) {
398+ return wc_Stm32_Aes_DhukOp(aes, outBlock, inBlock,
399+ WC_AES_BLOCK_SIZE, 0 /* decrypt */);
400+ }
401+ #endif
402+ return wc_Stm32_Aes_Ecb(aes, outBlock, inBlock, WC_AES_BLOCK_SIZE, 0);
403+ #else
384404 int ret = 0;
385405 #ifdef WOLFSSL_STM32_CUBEMX
386406 CRYP_HandleTypeDef hcryp;
@@ -395,13 +415,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
395415 return ret;
396416#endif
397417
398- #ifdef WOLFSSL_STM32U5_DHUK
418+ #ifdef WOLFSSL_DHUK
399419 ret = wolfSSL_CryptHwMutexLock();
400420 if (ret != 0)
401421 return ret;
402422
403423 /* Handle making use of wrapped key */
404- if (aes->devId == WOLFSSL_STM32U5_DHUK_WRAPPED_DEVID ) {
424+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID ) {
405425 CRYP_ConfigTypeDef Config;
406426
407427 XMEMSET(&Config, 0, sizeof(Config));
@@ -527,6 +547,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
527547 wc_Stm32_Aes_Cleanup();
528548
529549 return ret;
550+ #endif /* !WOLFSSL_STM32_BARE */
530551 }
531552 #endif /* WOLFSSL_AES_DIRECT */
532553#endif /* HAVE_AES_DECRYPT */
@@ -5594,7 +5615,34 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
55945615#ifdef HAVE_AES_CBC
55955616#if defined(STM32_CRYPTO)
55965617
5597- #ifdef WOLFSSL_STM32U5_DHUK
5618+ #ifdef WOLFSSL_STM32_BARE
5619+ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
5620+ {
5621+ #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
5622+ if (sz % WC_AES_BLOCK_SIZE) {
5623+ return BAD_LENGTH_E;
5624+ }
5625+ #endif
5626+ if (sz == 0) {
5627+ return 0;
5628+ }
5629+ return wc_Stm32_Aes_Cbc(aes, out, in, sz, 1);
5630+ }
5631+ #ifdef HAVE_AES_DECRYPT
5632+ int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
5633+ {
5634+ #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
5635+ if (sz % WC_AES_BLOCK_SIZE) {
5636+ return BAD_LENGTH_E;
5637+ }
5638+ #endif
5639+ if (sz == 0) {
5640+ return 0;
5641+ }
5642+ return wc_Stm32_Aes_Cbc(aes, out, in, sz, 0);
5643+ }
5644+ #endif /* HAVE_AES_DECRYPT */
5645+ #elif defined(WOLFSSL_DHUK)
55985646 int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
55995647 {
56005648 int ret = 0;
@@ -5614,7 +5662,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
56145662 return ret;
56155663 }
56165664
5617- if (aes->devId == WOLFSSL_STM32U5_DHUK_WRAPPED_DEVID ) {
5665+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID ) {
56185666 CRYP_ConfigTypeDef Config;
56195667
56205668 XMEMSET(&Config, 0, sizeof(Config));
@@ -5680,7 +5728,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
56805728 return ret;
56815729 }
56825730
5683- if (aes->devId == WOLFSSL_STM32U5_DHUK_WRAPPED_DEVID ) {
5731+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID ) {
56845732 CRYP_ConfigTypeDef Config;
56855733
56865734 XMEMSET(&Config, 0, sizeof(Config));
@@ -6977,6 +7025,11 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
69777025
69787026 int wc_AesCtrEncryptBlock(Aes* aes, byte* out, const byte* in)
69797027 {
7028+ #ifdef WOLFSSL_STM32_BARE
7029+ /* CTR per-block transform: ECB-encrypt the counter (passed in
7030+ * 'in'); aes.c handles counter increment and XOR with plaintext. */
7031+ return wc_Stm32_Aes_Ecb(aes, out, in, WC_AES_BLOCK_SIZE, 1);
7032+ #else
69807033 int ret = 0;
69817034 #ifdef WOLFSSL_STM32_CUBEMX
69827035 CRYP_HandleTypeDef hcryp;
@@ -7087,6 +7140,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
70877140 wolfSSL_CryptHwMutexUnLock();
70887141 wc_Stm32_Aes_Cleanup();
70897142 return ret;
7143+ #endif /* !WOLFSSL_STM32_BARE */
70907144 }
70917145
70927146
@@ -10166,6 +10220,7 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
1016610220 authTag, authTagSz,
1016710221 authIn, authInSz);
1016810222#endif
10223+
1016910224#if defined(WOLFSSL_MICROCHIP_TA100) && defined(WOLFSSL_MICROCHIP_AESGCM)
1017010225#ifndef TA_AES_GCM_MAX_DATA_SIZE
1017110226 #define TA_AES_GCM_MAX_DATA_SIZE 996u
@@ -10183,6 +10238,17 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
1018310238 authIn, authInSz);
1018410239 }
1018510240#endif
10241+
10242+ #if defined(WOLFSSL_STM32_BARE) && defined(STM32_CRYPTO)
10243+ ret = wc_Stm32_Aes_Gcm(aes, out, in, sz, iv, ivSz,
10244+ authTag, authTagSz,
10245+ authIn, authInSz, 1 /* enc */);
10246+ if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
10247+ return ret;
10248+ /* fall through to SW GCM (still uses HW AES via wc_AesEncrypt) */
10249+ #endif /* WOLFSSL_STM32_BARE && STM32_CRYPTO */
10250+
10251+
1018610252#ifdef STM32_CRYPTO_AES_GCM
1018710253 return wc_AesGcmEncrypt_STM32(
1018810254 aes, out, in, sz, iv, ivSz,
@@ -10927,6 +10993,10 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
1092710993 }
1092810994#endif
1092910995
10996+ /* BARE: GCM decrypt always uses SW path (with HW AES blocks via
10997+ * wc_AesEncrypt). Encrypt is HW-accelerated above; decrypt + tag
10998+ * verification stays in well-tested SW for now. */
10999+
1093011000#ifdef STM32_CRYPTO_AES_GCM
1093111001 /* The STM standard peripheral library API's doesn't support partial blocks */
1093211002 return wc_AesGcmDecrypt_STM32(
@@ -13751,7 +13821,7 @@ int wc_AesInit(Aes* aes, void* heap, int devId)
1375113821
1375213822 aes->heap = heap;
1375313823
13754- #if defined(WOLF_CRYPTO_CB) || defined(WOLFSSL_STM32U5_DHUK )
13824+ #if defined(WOLF_CRYPTO_CB) || defined(WOLFSSL_DHUK )
1375513825 aes->devId = devId;
1375613826 aes->devCtx = NULL;
1375713827#else
0 commit comments