Skip to content

Commit 1cb324a

Browse files
night1riderZackLabPC
authored andcommitted
Expanding mutexing and Adding in AES Callbacks for HW
1 parent a7ef540 commit 1cb324a

12 files changed

Lines changed: 689 additions & 32 deletions

File tree

wolfcrypt/benchmark/benchmark.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@
220220
#ifdef HAVE_RENESAS_SYNC
221221
#include <wolfssl/wolfcrypt/port/renesas/renesas_sync.h>
222222
#endif
223+
#if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
224+
#include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
225+
#endif
223226
#endif
224227

225228
#ifdef WOLFSSL_ASYNC_CRYPT
@@ -3167,8 +3170,9 @@ static void* benchmarks_do(void* args)
31673170
#endif
31683171
#if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
31693172
defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
3170-
defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) && \
3171-
!defined(NO_HW_BENCH)
3173+
defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) || \
3174+
((defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
3175+
defined(WOLF_CRYPTO_CB)) && !defined(NO_HW_BENCH)
31723176
bench_aes_aad_options_wrap(bench_aesgcm, 1);
31733177
#endif
31743178
#ifndef NO_SW_BENCH

wolfcrypt/src/aes.c

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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);
27942801
static 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)
35563578
static 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) && \

wolfcrypt/src/cryptocb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
#include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
5757
#endif
5858

59+
#if defined (WOLFSSL_MAX3266X) || defined (WOLFSSL_MAX3266X_OLD)
60+
#include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
61+
#endif
62+
5963
/* TODO: Consider linked list with mutex */
6064
#ifndef MAX_CRYPTO_DEVID_CALLBACKS
6165
#define MAX_CRYPTO_DEVID_CALLBACKS 8

0 commit comments

Comments
 (0)