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 23, 2024
1 parent 7c6eb7c commit a41b459
Show file tree
Hide file tree
Showing 12 changed files with 1,357 additions and 4 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_MAX32665) || defined(WOLFSSL_MAX32666)) \
&& 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: 84 additions & 2 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_MAX32665) || defined(WOLFSSL_MAX32666)
#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,13 @@ 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(NO_WOLFSSL_ESP32_CRYPT_AES)) && \
(!defined(WOLFSSL_MAX32665) && !defined(WOLFSSL_MAX32666))

/* software */
ByteReverseWords(aes->key, aes->key, keylen);
Expand Down Expand Up @@ -5374,6 +5378,84 @@ 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
Loading

0 comments on commit a41b459

Please sign in to comment.