@@ -227,6 +227,16 @@ 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+ #ifdef WOLFSSL_DHUK
233+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID) {
234+ return wc_Stm32_Aes_DhukOp(aes, outBlock, inBlock,
235+ WC_AES_BLOCK_SIZE, 1 /* encrypt */);
236+ }
237+ #endif
238+ return wc_Stm32_Aes_Ecb(aes, outBlock, inBlock, WC_AES_BLOCK_SIZE, 1);
239+ #else
230240 int ret = 0;
231241 #ifdef WOLFSSL_STM32_CUBEMX
232242 CRYP_HandleTypeDef hcryp;
@@ -241,13 +251,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
241251 return ret;
242252#endif
243253
244- #ifdef WOLFSSL_STM32U5_DHUK
254+ #ifdef WOLFSSL_DHUK
245255 ret = wolfSSL_CryptHwMutexLock();
246256 if (ret != 0)
247257 return ret;
248258
249259 /* Handle making use of wrapped key */
250- if (aes->devId == WOLFSSL_STM32U5_DHUK_WRAPPED_DEVID ) {
260+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID ) {
251261 CRYP_ConfigTypeDef Config = {0};
252262
253263 ret = wc_Stm32_Aes_UnWrap(aes, &hcryp, (const byte*)aes->key,
@@ -367,6 +377,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
367377 wc_Stm32_Aes_Cleanup();
368378
369379 return ret;
380+ #endif /* !WOLFSSL_STM32_BARE */
370381 }
371382#endif /* WOLFSSL_AES_DIRECT || HAVE_AESGCM || HAVE_AESCCM */
372383
@@ -375,6 +386,15 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
375386 static WARN_UNUSED_RESULT int wc_AesDecrypt(
376387 Aes* aes, const byte* inBlock, byte* outBlock)
377388 {
389+ #ifdef WOLFSSL_STM32_BARE
390+ #ifdef WOLFSSL_DHUK
391+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID) {
392+ return wc_Stm32_Aes_DhukOp(aes, outBlock, inBlock,
393+ WC_AES_BLOCK_SIZE, 0 /* decrypt */);
394+ }
395+ #endif
396+ return wc_Stm32_Aes_Ecb(aes, outBlock, inBlock, WC_AES_BLOCK_SIZE, 0);
397+ #else
378398 int ret = 0;
379399 #ifdef WOLFSSL_STM32_CUBEMX
380400 CRYP_HandleTypeDef hcryp;
@@ -389,13 +409,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
389409 return ret;
390410#endif
391411
392- #ifdef WOLFSSL_STM32U5_DHUK
412+ #ifdef WOLFSSL_DHUK
393413 ret = wolfSSL_CryptHwMutexLock();
394414 if (ret != 0)
395415 return ret;
396416
397417 /* Handle making use of wrapped key */
398- if (aes->devId == WOLFSSL_STM32U5_DHUK_WRAPPED_DEVID ) {
418+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID ) {
399419 CRYP_ConfigTypeDef Config;
400420
401421 XMEMSET(&Config, 0, sizeof(Config));
@@ -521,6 +541,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
521541 wc_Stm32_Aes_Cleanup();
522542
523543 return ret;
544+ #endif /* !WOLFSSL_STM32_BARE */
524545 }
525546 #endif /* WOLFSSL_AES_DIRECT */
526547#endif /* HAVE_AES_DECRYPT */
@@ -5576,7 +5597,34 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
55765597#ifdef HAVE_AES_CBC
55775598#if defined(STM32_CRYPTO)
55785599
5579- #ifdef WOLFSSL_STM32U5_DHUK
5600+ #ifdef WOLFSSL_STM32_BARE
5601+ int wc_AesCbcEncrypt(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, 1);
5612+ }
5613+ #ifdef HAVE_AES_DECRYPT
5614+ int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
5615+ {
5616+ #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
5617+ if (sz % WC_AES_BLOCK_SIZE) {
5618+ return BAD_LENGTH_E;
5619+ }
5620+ #endif
5621+ if (sz == 0) {
5622+ return 0;
5623+ }
5624+ return wc_Stm32_Aes_Cbc(aes, out, in, sz, 0);
5625+ }
5626+ #endif /* HAVE_AES_DECRYPT */
5627+ #elif defined(WOLFSSL_DHUK)
55805628 int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
55815629 {
55825630 int ret = 0;
@@ -5596,7 +5644,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
55965644 return ret;
55975645 }
55985646
5599- if (aes->devId == WOLFSSL_STM32U5_DHUK_WRAPPED_DEVID ) {
5647+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID ) {
56005648 CRYP_ConfigTypeDef Config;
56015649
56025650 XMEMSET(&Config, 0, sizeof(Config));
@@ -5662,7 +5710,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
56625710 return ret;
56635711 }
56645712
5665- if (aes->devId == WOLFSSL_STM32U5_DHUK_WRAPPED_DEVID ) {
5713+ if (aes->devId == WOLFSSL_DHUK_WRAPPED_DEVID ) {
56665714 CRYP_ConfigTypeDef Config;
56675715
56685716 XMEMSET(&Config, 0, sizeof(Config));
@@ -6956,6 +7004,11 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
69567004
69577005 int wc_AesCtrEncryptBlock(Aes* aes, byte* out, const byte* in)
69587006 {
7007+ #ifdef WOLFSSL_STM32_BARE
7008+ /* CTR per-block transform: ECB-encrypt the counter (passed in
7009+ * 'in'); aes.c handles counter increment and XOR with plaintext. */
7010+ return wc_Stm32_Aes_Ecb(aes, out, in, WC_AES_BLOCK_SIZE, 1);
7011+ #else
69597012 int ret = 0;
69607013 #ifdef WOLFSSL_STM32_CUBEMX
69617014 CRYP_HandleTypeDef hcryp;
@@ -7066,6 +7119,7 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
70667119 wolfSSL_CryptHwMutexUnLock();
70677120 wc_Stm32_Aes_Cleanup();
70687121 return ret;
7122+ #endif /* !WOLFSSL_STM32_BARE */
70697123 }
70707124
70717125
@@ -10142,6 +10196,15 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
1014210196 authIn, authInSz);
1014310197#endif
1014410198
10199+ #if defined(WOLFSSL_STM32_BARE) && defined(STM32_CRYPTO)
10200+ ret = wc_Stm32_Aes_Gcm(aes, out, in, sz, iv, ivSz,
10201+ authTag, authTagSz,
10202+ authIn, authInSz, 1 /* enc */);
10203+ if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
10204+ return ret;
10205+ /* fall through to SW GCM (still uses HW AES via wc_AesEncrypt) */
10206+ #endif /* WOLFSSL_STM32_BARE && STM32_CRYPTO */
10207+
1014510208#ifdef STM32_CRYPTO_AES_GCM
1014610209 return wc_AesGcmEncrypt_STM32(
1014710210 aes, out, in, sz, iv, ivSz,
@@ -10871,6 +10934,10 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
1087110934
1087210935#endif
1087310936
10937+ /* BARE: GCM decrypt always uses SW path (with HW AES blocks via
10938+ * wc_AesEncrypt). Encrypt is HW-accelerated above; decrypt + tag
10939+ * verification stays in well-tested SW for now. */
10940+
1087410941#ifdef STM32_CRYPTO_AES_GCM
1087510942 /* The STM standard peripheral library API's doesn't support partial blocks */
1087610943 return wc_AesGcmDecrypt_STM32(
@@ -13695,7 +13762,7 @@ int wc_AesInit(Aes* aes, void* heap, int devId)
1369513762
1369613763 aes->heap = heap;
1369713764
13698- #if defined(WOLF_CRYPTO_CB) || defined(WOLFSSL_STM32U5_DHUK )
13765+ #if defined(WOLF_CRYPTO_CB) || defined(WOLFSSL_DHUK )
1369913766 aes->devId = devId;
1370013767 aes->devCtx = NULL;
1370113768#else
0 commit comments