@@ -84,6 +84,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
8484
8585#if defined(WOLFSSL_MAX3266X ) || defined(WOLFSSL_MAX3266X_OLD )
8686 #include <wolfssl/wolfcrypt/port/maxim/max3266x.h>
87+ #ifdef WOLF_CRYPTO_CB
88+ /* Revert back to SW so HW CB works */
89+ /* HW only works for AES: ECB, CBC, and partial via ECB for other modes */
90+ #include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
91+ /* Turn off MAX3266X_AES in the context of this file when using CB */
92+ #undef MAX3266X_AES
93+ #endif
8794#endif
8895
8996#if defined(WOLFSSL_TI_CRYPT )
@@ -2794,9 +2801,12 @@ extern void AesEncryptBlocks_C(Aes* aes, const byte* in, byte* out, word32 sz);
27942801static WARN_UNUSED_RESULT int wc_AesEncrypt (
27952802 Aes * aes , const byte * inBlock , byte * outBlock )
27962803{
2797- #if defined(MAX3266X_AES )
2804+ #if defined(MAX3266X_AES )
27982805 word32 keySize ;
2799- #endif
2806+ #endif
2807+ #if defined(MAX3266X_CB )
2808+ int ret_cb ;
2809+ #endif
28002810 word32 r ;
28012811
28022812 if (aes == NULL ) {
@@ -2907,6 +2917,18 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt(
29072917 outBlock , (unsigned int )keySize );
29082918 }
29092919#endif
2920+ #ifdef MAX3266X_CB /* Can do a basic ECB block */
2921+ #ifndef WOLF_CRYPTO_CB_FIND
2922+ if (aes -> devId != INVALID_DEVID )
2923+ #endif
2924+ {
2925+ ret_cb = wc_CryptoCb_AesEcbEncrypt (aes , outBlock , inBlock ,
2926+ AES_BLOCK_SIZE );
2927+ if (ret_cb != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
2928+ return ret_cb ;
2929+ /* fall-through when unavailable */
2930+ }
2931+ #endif
29102932
29112933 AesEncrypt_C (aes , inBlock , outBlock , r );
29122934
@@ -3556,9 +3578,12 @@ static void AesDecryptBlocks_C(Aes* aes, const byte* in, byte* out, word32 sz)
35563578static WARN_UNUSED_RESULT int wc_AesDecrypt (
35573579 Aes * aes , const byte * inBlock , byte * outBlock )
35583580{
3559- #if defined(MAX3266X_AES )
3581+ #if defined(MAX3266X_AES )
35603582 word32 keySize ;
3561- #endif
3583+ #endif
3584+ #if defined(MAX3266X_CB )
3585+ int ret_cb ;
3586+ #endif
35623587 word32 r ;
35633588
35643589 if (aes == NULL ) {
@@ -3643,6 +3668,19 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
36433668 }
36443669#endif
36453670
3671+ #ifdef MAX3266X_CB /* Can do a basic ECB block */
3672+ #ifndef WOLF_CRYPTO_CB_FIND
3673+ if (aes -> devId != INVALID_DEVID )
3674+ #endif
3675+ {
3676+ ret_cb = wc_CryptoCb_AesEcbDecrypt (aes , outBlock , inBlock ,
3677+ AES_BLOCK_SIZE );
3678+ if (ret_cb != WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE ))
3679+ return ret_cb ;
3680+ /* fall-through when unavailable */
3681+ }
3682+ #endif
3683+
36463684 AesDecrypt_C (aes , inBlock , outBlock , r );
36473685
36483686 return 0 ;
@@ -4130,6 +4168,9 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
41304168 unsigned int i = 0 ;
41314169
41324170 XMEMCPY (rk , key , keySz );
4171+ #ifdef MAX3266X_CB /* Copies needed values to use later if CB is used */
4172+ XMEMCPY (aes -> cb_key , key , keySz );
4173+ #endif
41334174#if defined(LITTLE_ENDIAN_ORDER ) && !defined(WOLFSSL_PIC32MZ_CRYPT ) && \
41344175 (!defined(WOLFSSL_ESP32_CRYPT ) || defined(NO_WOLFSSL_ESP32_CRYPT_AES )) && \
41354176 !defined(MAX3266X_AES )
@@ -4572,6 +4613,9 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
45724613#endif
45734614
45744615 XMEMCPY (aes -> key , userKey , keylen );
4616+ #ifdef MAX3266X_CB /* Copy Key for CB for use later if needed */
4617+ XMEMCMP (aes -> cb_key , userKey , keylen );
4618+ #endif
45754619
45764620#ifndef WC_AES_BITSLICED
45774621 #if defined(LITTLE_ENDIAN_ORDER ) && !defined(WOLFSSL_PIC32MZ_CRYPT ) && \
0 commit comments