Skip to content

Commit

Permalink
Initial PR for MAX32665 and MAX32666 TPU HW Support
Browse files Browse the repository at this point in the history
  • Loading branch information
msi-debian authored and msi-debian committed Jul 25, 2024
1 parent 7c6eb7c commit 18752ce
Show file tree
Hide file tree
Showing 14 changed files with 1,347 additions and 15 deletions.
8 changes: 8 additions & 0 deletions wolfcrypt/benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -14236,6 +14236,14 @@ void bench_sphincsKeySign(byte level, byte optim)
return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
}

#elif (defined(WOLFSSL_MAX3266X_OLD) || defined(WOLFSSL_MAX3266X)) \
&& defined(MAX3266X_RTC)

double current_time(int reset)
{
return wc_MXC_RTC_Time();
}

#elif defined(FREESCALE_KSDK_BM)

double current_time(int reset)
Expand Down
86 changes: 83 additions & 3 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
#include <wolfssl/wolfcrypt/port/psa/psa.h>
#endif

#if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
#include <wolfssl/wolfcrypt/port/maxim/max3266x.h>
#endif

#if defined(WOLFSSL_TI_CRYPT)
#include <wolfcrypt/src/port/ti/ti-aes.c>
#else
Expand Down Expand Up @@ -4537,13 +4541,12 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
return ret;
}
#endif

XMEMCPY(aes->key, userKey, keylen);

#ifndef WC_AES_BITSLICED
#if defined(LITTLE_ENDIAN_ORDER) && !defined(WOLFSSL_PIC32MZ_CRYPT) && \
(!defined(WOLFSSL_ESP32_CRYPT) || \
defined(NO_WOLFSSL_ESP32_CRYPT_AES))
(!defined(WOLFSSL_ESP32_CRYPT) || defined(NO_WOLFSSL_ESP32_CRYPT_AES)) \
&& !defined(MAX3266X_AES)

/* software */
ByteReverseWords(aes->key, aes->key, keylen);
Expand Down Expand Up @@ -5374,6 +5377,83 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
}
#endif /* HAVE_AES_DECRYPT */

#elif defined(MAX3266X_AES)
int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
{
word32 keySize;
int status;
byte *iv;
word32 blocks = (sz / AES_BLOCK_SIZE);

#ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
if (sz % AES_BLOCK_SIZE) {
return BAD_LENGTH_E;
}
#endif
if (blocks == 0)
return 0;

iv = (byte*)aes->reg;

status = wc_AesGetKeySize(aes, &keySize);
if (status != 0) {
return status;
}

status = wc_MXC_TPU_AesEncrypt(in, iv, aes->key, MXC_TPU_MODE_CBC,
MXC_AES_DATA_LEN, out,
(unsigned int)keySize);

/* store iv for next call */
if (status == E_SUCCESS) {
XMEMCPY(iv, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
}

return (status == E_SUCCESS) ? 0 : -1;
}

#ifdef HAVE_AES_DECRYPT
int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
{
word32 keySize;
int status;
byte *iv;
byte temp_block[AES_BLOCK_SIZE];
word32 blocks = (sz / AES_BLOCK_SIZE);

#ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
if (sz % AES_BLOCK_SIZE) {
return BAD_LENGTH_E;
}
#endif
if (blocks == 0)
return 0;

iv = (byte*)aes->reg;

status = wc_AesGetKeySize(aes, &keySize);
if (status != 0) {
return status;
}

/* get IV for next call */
XMEMCPY(temp_block, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);

status = wc_MXC_TPU_AesDecrypt(in, iv, aes->key, MXC_TPU_MODE_CBC,
MXC_AES_DATA_LEN, out, keySize);


/* store iv for next call */
if (status == E_SUCCESS) {
XMEMCPY(iv, temp_block, AES_BLOCK_SIZE);
}

return (status == E_SUCCESS) ? 0 : -1;
}
#endif /* HAVE_AES_DECRYPT */



#elif defined(WOLFSSL_PIC32MZ_CRYPT)

int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
Expand Down
3 changes: 2 additions & 1 deletion wolfcrypt/src/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ EXTRA_DIST += wolfcrypt/src/port/ti/ti-aes.c \
wolfcrypt/src/port/Renesas/renesas_rx64_hw_util.c \
wolfcrypt/src/port/Renesas/README.md \
wolfcrypt/src/port/cypress/psoc6_crypto.c \
wolfcrypt/src/port/liboqs/liboqs.c
wolfcrypt/src/port/liboqs/liboqs.c \
wolfcrypt/src/port/maxim/max3266x.c

$(ASYNC_FILES):
$(AM_V_at)touch $(srcdir)/$@
Expand Down
Loading

0 comments on commit 18752ce

Please sign in to comment.