@@ -227,6 +227,10 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
227227 static WARN_UNUSED_RESULT int wc_AesEncrypt(
228228 Aes* aes, const byte* inBlock, byte* outBlock)
229229 {
230+ #ifdef WOLFSSL_STM32_BARE
231+ /* Bare-metal driver handles mutex, clock and key/IV internally. */
232+ return wc_Stm32_Aes_Ecb(aes, outBlock, inBlock, WC_AES_BLOCK_SIZE, 1);
233+ #else
230234 int ret = 0;
231235 #ifdef WOLFSSL_STM32_CUBEMX
232236 CRYP_HandleTypeDef hcryp;
@@ -367,6 +371,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
367371 wc_Stm32_Aes_Cleanup();
368372
369373 return ret;
374+ #endif /* !WOLFSSL_STM32_BARE */
370375 }
371376#endif /* WOLFSSL_AES_DIRECT || HAVE_AESGCM || HAVE_AESCCM */
372377
@@ -375,6 +380,9 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
375380 static WARN_UNUSED_RESULT int wc_AesDecrypt(
376381 Aes* aes, const byte* inBlock, byte* outBlock)
377382 {
383+ #ifdef WOLFSSL_STM32_BARE
384+ return wc_Stm32_Aes_Ecb(aes, outBlock, inBlock, WC_AES_BLOCK_SIZE, 0);
385+ #else
378386 int ret = 0;
379387 #ifdef WOLFSSL_STM32_CUBEMX
380388 CRYP_HandleTypeDef hcryp;
@@ -521,6 +529,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
521529 wc_Stm32_Aes_Cleanup();
522530
523531 return ret;
532+ #endif /* !WOLFSSL_STM32_BARE */
524533 }
525534 #endif /* WOLFSSL_AES_DIRECT */
526535#endif /* HAVE_AES_DECRYPT */
@@ -5575,7 +5584,34 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
55755584#ifdef HAVE_AES_CBC
55765585#if defined(STM32_CRYPTO)
55775586
5578- #ifdef WOLFSSL_STM32U5_DHUK
5587+ #ifdef WOLFSSL_STM32_BARE
5588+ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
5589+ {
5590+ #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
5591+ if (sz % WC_AES_BLOCK_SIZE) {
5592+ return BAD_LENGTH_E;
5593+ }
5594+ #endif
5595+ if (sz == 0) {
5596+ return 0;
5597+ }
5598+ return wc_Stm32_Aes_Cbc(aes, out, in, sz, 1);
5599+ }
5600+ #ifdef HAVE_AES_DECRYPT
5601+ int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
5602+ {
5603+ #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
5604+ if (sz % WC_AES_BLOCK_SIZE) {
5605+ return BAD_LENGTH_E;
5606+ }
5607+ #endif
5608+ if (sz == 0) {
5609+ return 0;
5610+ }
5611+ return wc_Stm32_Aes_Cbc(aes, out, in, sz, 0);
5612+ }
5613+ #endif /* HAVE_AES_DECRYPT */
5614+ #elif defined(WOLFSSL_STM32U5_DHUK)
55795615 int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
55805616 {
55815617 int ret = 0;
@@ -6955,6 +6991,11 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
69556991
69566992 int wc_AesCtrEncryptBlock(Aes* aes, byte* out, const byte* in)
69576993 {
6994+ #ifdef WOLFSSL_STM32_BARE
6995+ /* CTR per-block transform: ECB-encrypt the counter (passed in
6996+ * 'in'); aes.c handles counter increment and XOR with plaintext. */
6997+ return wc_Stm32_Aes_Ecb(aes, out, in, WC_AES_BLOCK_SIZE, 1);
6998+ #else
69586999 int ret = 0;
69597000 #ifdef WOLFSSL_STM32_CUBEMX
69607001 CRYP_HandleTypeDef hcryp;
@@ -7065,6 +7106,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
70657106 wolfSSL_CryptHwMutexUnLock();
70667107 wc_Stm32_Aes_Cleanup();
70677108 return ret;
7109+ #endif /* !WOLFSSL_STM32_BARE */
70687110 }
70697111
70707112
@@ -10141,6 +10183,15 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
1014110183 authIn, authInSz);
1014210184#endif
1014310185
10186+ #if defined(WOLFSSL_STM32_BARE) && defined(STM32_CRYPTO)
10187+ ret = wc_Stm32_Aes_Gcm(aes, out, in, sz, iv, ivSz,
10188+ authTag, authTagSz,
10189+ authIn, authInSz, 1 /* enc */);
10190+ if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
10191+ return ret;
10192+ /* fall through to SW GCM (still uses HW AES via wc_AesEncrypt) */
10193+ #endif /* WOLFSSL_STM32_BARE && STM32_CRYPTO */
10194+
1014410195#ifdef STM32_CRYPTO_AES_GCM
1014510196 return wc_AesGcmEncrypt_STM32(
1014610197 aes, out, in, sz, iv, ivSz,
@@ -10870,6 +10921,10 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
1087010921
1087110922#endif
1087210923
10924+ /* BARE: GCM decrypt always uses SW path (with HW AES blocks via
10925+ * wc_AesEncrypt). Encrypt is HW-accelerated above; decrypt + tag
10926+ * verification stays in well-tested SW for now. */
10927+
1087310928#ifdef STM32_CRYPTO_AES_GCM
1087410929 /* The STM standard peripheral library API's doesn't support partial blocks */
1087510930 return wc_AesGcmDecrypt_STM32(
0 commit comments