@@ -82,6 +82,10 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
8282 #include <wolfssl/wolfcrypt/port/psa/psa.h>
8383#endif
8484
85+ #if defined(WOLFSSL_MAX3266X ) || defined(WOLFSSL_MAX3266X_OLD )
86+ #include <wolfssl/wolfcrypt/port/maxim/max3266x.h>
87+ #endif
88+
8589#if defined(WOLFSSL_TI_CRYPT )
8690 #include <wolfcrypt/src/port/ti/ti-aes.c>
8791#else
@@ -2789,6 +2793,9 @@ extern void AesEncryptBlocks_C(Aes* aes, const byte* in, byte* out, word32 sz);
27892793static WARN_UNUSED_RESULT int wc_AesEncrypt (
27902794 Aes * aes , const byte * inBlock , byte * outBlock )
27912795{
2796+ #if defined(MAX3266X_AES )
2797+ word32 keySize ;
2798+ #endif
27922799 word32 r ;
27932800
27942801 if (aes == NULL ) {
@@ -2892,6 +2899,14 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt(
28922899 }
28932900#endif
28942901
2902+ #if defined(MAX3266X_AES )
2903+ if (wc_AesGetKeySize (aes , & keySize ) == 0 ) {
2904+ return wc_MXC_TPU_AesEncrypt (inBlock , (byte * )aes -> reg , (byte * )aes -> key ,
2905+ MXC_TPU_MODE_ECB , AES_BLOCK_SIZE ,
2906+ outBlock , (unsigned int )keySize );
2907+ }
2908+ #endif
2909+
28952910 AesEncrypt_C (aes , inBlock , outBlock , r );
28962911
28972912 return 0 ;
@@ -3539,6 +3554,9 @@ static void AesDecryptBlocks_C(Aes* aes, const byte* in, byte* out, word32 sz)
35393554static WARN_UNUSED_RESULT int wc_AesDecrypt (
35403555 Aes * aes , const byte * inBlock , byte * outBlock )
35413556{
3557+ #if defined(MAX3266X_AES )
3558+ word32 keySize ;
3559+ #endif
35423560 word32 r ;
35433561
35443562 if (aes == NULL ) {
@@ -3615,6 +3633,14 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
36153633 } /* else !wc_esp32AesSupportedKeyLen for ESP32 */
36163634#endif
36173635
3636+ #if defined(MAX3266X_AES )
3637+ if (wc_AesGetKeySize (aes , & keySize ) == 0 ) {
3638+ return wc_MXC_TPU_AesDecrypt (inBlock , (byte * )aes -> reg , (byte * )aes -> key ,
3639+ MXC_TPU_MODE_ECB , AES_BLOCK_SIZE ,
3640+ outBlock , (unsigned int )keySize );
3641+ }
3642+ #endif
3643+
36183644 AesDecrypt_C (aes , inBlock , outBlock , r );
36193645
36203646 return 0 ;
@@ -4103,7 +4129,8 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
41034129
41044130 XMEMCPY (rk , key , keySz );
41054131#if defined(LITTLE_ENDIAN_ORDER ) && !defined(WOLFSSL_PIC32MZ_CRYPT ) && \
4106- (!defined(WOLFSSL_ESP32_CRYPT ) || defined(NO_WOLFSSL_ESP32_CRYPT_AES ))
4132+ (!defined(WOLFSSL_ESP32_CRYPT ) || defined(NO_WOLFSSL_ESP32_CRYPT_AES )) && \
4133+ !defined(MAX3266X_AES )
41074134 /* Always reverse words when using only SW */
41084135 {
41094136 ByteReverseWords (rk , rk , keySz );
@@ -4250,7 +4277,7 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
42504277 } /* switch */
42514278 ForceZero (& temp , sizeof (temp ));
42524279
4253- #if defined(HAVE_AES_DECRYPT )
4280+ #if defined(HAVE_AES_DECRYPT ) && !defined( MAX3266X_AES )
42544281 if (dir == AES_DECRYPTION ) {
42554282 unsigned int j ;
42564283
@@ -4546,8 +4573,8 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
45464573
45474574#ifndef WC_AES_BITSLICED
45484575 #if defined(LITTLE_ENDIAN_ORDER ) && !defined(WOLFSSL_PIC32MZ_CRYPT ) && \
4549- (!defined(WOLFSSL_ESP32_CRYPT ) || \
4550- defined(NO_WOLFSSL_ESP32_CRYPT_AES ) )
4576+ (!defined(WOLFSSL_ESP32_CRYPT ) || defined( NO_WOLFSSL_ESP32_CRYPT_AES )) \
4577+ && ! defined(MAX3266X_AES )
45514578
45524579 /* software */
45534580 ByteReverseWords (aes -> key , aes -> key , keylen );
@@ -5378,6 +5405,82 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
53785405 }
53795406 #endif /* HAVE_AES_DECRYPT */
53805407
5408+ #elif defined(MAX3266X_AES )
5409+ int wc_AesCbcEncrypt (Aes * aes , byte * out , const byte * in , word32 sz )
5410+ {
5411+ word32 keySize ;
5412+ int status ;
5413+ byte * iv ;
5414+
5415+ #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
5416+ if (sz % AES_BLOCK_SIZE ) {
5417+ return BAD_LENGTH_E ;
5418+ }
5419+ #endif
5420+ if (sz == 0 )
5421+ return 0 ;
5422+
5423+ iv = (byte * )aes -> reg ;
5424+
5425+ status = wc_AesGetKeySize (aes , & keySize );
5426+ if (status != 0 ) {
5427+ return status ;
5428+ }
5429+
5430+ status = wc_MXC_TPU_AesEncrypt (in , iv , (byte * )aes -> key ,
5431+ MXC_TPU_MODE_CBC , sz , out ,
5432+ (unsigned int )keySize );
5433+
5434+ /* store iv for next call */
5435+ if (status == 0 ) {
5436+ XMEMCPY (iv , out + sz - AES_BLOCK_SIZE , AES_BLOCK_SIZE );
5437+ }
5438+
5439+ return (status == 0 ) ? 0 : -1 ;
5440+ }
5441+
5442+ #ifdef HAVE_AES_DECRYPT
5443+ int wc_AesCbcDecrypt (Aes * aes , byte * out , const byte * in , word32 sz )
5444+ {
5445+ word32 keySize ;
5446+ int status ;
5447+ byte * iv ;
5448+ byte temp_block [AES_BLOCK_SIZE ];
5449+
5450+ #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
5451+ if (sz % AES_BLOCK_SIZE ) {
5452+ return BAD_LENGTH_E ;
5453+ }
5454+ #endif
5455+ if (sz == 0 )
5456+ return 0 ;
5457+
5458+ iv = (byte * )aes -> reg ;
5459+
5460+ status = wc_AesGetKeySize (aes , & keySize );
5461+ if (status != 0 ) {
5462+ return status ;
5463+ }
5464+
5465+ /* get IV for next call */
5466+ XMEMCPY (temp_block , in + sz - AES_BLOCK_SIZE , AES_BLOCK_SIZE );
5467+
5468+ status = wc_MXC_TPU_AesDecrypt (in , iv , (byte * )aes -> key ,
5469+ MXC_TPU_MODE_CBC , sz , out ,
5470+ keySize );
5471+
5472+
5473+ /* store iv for next call */
5474+ if (status == 0 ) {
5475+ XMEMCPY (iv , temp_block , AES_BLOCK_SIZE );
5476+ }
5477+
5478+ return (status == 0 ) ? 0 : -1 ;
5479+ }
5480+ #endif /* HAVE_AES_DECRYPT */
5481+
5482+
5483+
53815484#elif defined(WOLFSSL_PIC32MZ_CRYPT )
53825485
53835486 int wc_AesCbcEncrypt (Aes * aes , byte * out , const byte * in , word32 sz )
0 commit comments