@@ -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 */
@@ -5663,7 +5684,34 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
56635684#ifdef HAVE_AES_CBC
56645685#if defined(STM32_CRYPTO)
56655686
5666- #ifdef WOLFSSL_STM32U5_DHUK
5687+ #ifdef WOLFSSL_STM32_BARE
5688+ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
5689+ {
5690+ #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
5691+ if (sz % WC_AES_BLOCK_SIZE) {
5692+ return BAD_LENGTH_E;
5693+ }
5694+ #endif
5695+ if (sz == 0) {
5696+ return 0;
5697+ }
5698+ return wc_Stm32_Aes_Cbc(aes, out, in, sz, 1);
5699+ }
5700+ #ifdef HAVE_AES_DECRYPT
5701+ int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
5702+ {
5703+ #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
5704+ if (sz % WC_AES_BLOCK_SIZE) {
5705+ return BAD_LENGTH_E;
5706+ }
5707+ #endif
5708+ if (sz == 0) {
5709+ return 0;
5710+ }
5711+ return wc_Stm32_Aes_Cbc(aes, out, in, sz, 0);
5712+ }
5713+ #endif /* HAVE_AES_DECRYPT */
5714+ #elif defined(WOLFSSL_DHUK)
56675715 int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
56685716 {
56695717 int ret = 0;
@@ -5683,7 +5731,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
56835731 return ret;
56845732 }
56855733
5686- if (aes->devId == WOLFSSL_STM32U5_DHUK_WRAPPED_DEVID ) {
5734+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID ) {
56875735 CRYP_ConfigTypeDef Config;
56885736
56895737 XMEMSET(&Config, 0, sizeof(Config));
@@ -5749,7 +5797,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
57495797 return ret;
57505798 }
57515799
5752- if (aes->devId == WOLFSSL_STM32U5_DHUK_WRAPPED_DEVID ) {
5800+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID ) {
57535801 CRYP_ConfigTypeDef Config;
57545802
57555803 XMEMSET(&Config, 0, sizeof(Config));
@@ -7046,6 +7094,11 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
70467094
70477095 int wc_AesCtrEncryptBlock(Aes* aes, byte* out, const byte* in)
70487096 {
7097+ #ifdef WOLFSSL_STM32_BARE
7098+ /* CTR per-block transform: ECB-encrypt the counter (passed in
7099+ * 'in'); aes.c handles counter increment and XOR with plaintext. */
7100+ return wc_Stm32_Aes_Ecb(aes, out, in, WC_AES_BLOCK_SIZE, 1);
7101+ #else
70497102 int ret = 0;
70507103 #ifdef WOLFSSL_STM32_CUBEMX
70517104 CRYP_HandleTypeDef hcryp;
@@ -7156,6 +7209,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
71567209 wolfSSL_CryptHwMutexUnLock();
71577210 wc_Stm32_Aes_Cleanup();
71587211 return ret;
7212+ #endif /* !WOLFSSL_STM32_BARE */
71597213 }
71607214
71617215
@@ -10246,6 +10300,7 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
1024610300 authTag, authTagSz,
1024710301 authIn, authInSz);
1024810302#endif
10303+
1024910304#if defined(WOLFSSL_MICROCHIP_TA100) && defined(WOLFSSL_MICROCHIP_AESGCM)
1025010305#ifndef TA_AES_GCM_MAX_DATA_SIZE
1025110306 #define TA_AES_GCM_MAX_DATA_SIZE 996u
@@ -10263,6 +10318,17 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
1026310318 authIn, authInSz);
1026410319 }
1026510320#endif
10321+
10322+ #if defined(WOLFSSL_STM32_BARE) && defined(STM32_CRYPTO)
10323+ ret = wc_Stm32_Aes_Gcm(aes, out, in, sz, iv, ivSz,
10324+ authTag, authTagSz,
10325+ authIn, authInSz, 1 /* enc */);
10326+ if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
10327+ return ret;
10328+ /* fall through to SW GCM (still uses HW AES via wc_AesEncrypt) */
10329+ #endif /* WOLFSSL_STM32_BARE && STM32_CRYPTO */
10330+
10331+
1026610332#ifdef STM32_CRYPTO_AES_GCM
1026710333 return wc_AesGcmEncrypt_STM32(
1026810334 aes, out, in, sz, iv, ivSz,
@@ -11007,6 +11073,10 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
1100711073 }
1100811074#endif
1100911075
11076+ /* BARE: GCM decrypt always uses SW path (with HW AES blocks via
11077+ * wc_AesEncrypt). Encrypt is HW-accelerated above; decrypt + tag
11078+ * verification stays in well-tested SW for now. */
11079+
1101011080#ifdef STM32_CRYPTO_AES_GCM
1101111081 /* The STM standard peripheral library API's doesn't support partial blocks */
1101211082 return wc_AesGcmDecrypt_STM32(
@@ -13831,7 +13901,7 @@ int wc_AesInit(Aes* aes, void* heap, int devId)
1383113901
1383213902 aes->heap = heap;
1383313903
13834- #if defined(WOLF_CRYPTO_CB) || defined(WOLFSSL_STM32U5_DHUK )
13904+ #if defined(WOLF_CRYPTO_CB) || defined(WOLFSSL_DHUK )
1383513905 aes->devId = devId;
1383613906 aes->devCtx = NULL;
1383713907#else
0 commit comments