forked from wolfSSL/wolfssl
Crypto Callback Support for ARM ASM: AES-ECB/CBC, SHA-1/256/384/512 + Fix SP SHA CB Bug
This commit is contained in:
@ -84,7 +84,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
|||||||
|
|
||||||
#if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
|
#if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
|
||||||
#include <wolfssl/wolfcrypt/port/maxim/max3266x.h>
|
#include <wolfssl/wolfcrypt/port/maxim/max3266x.h>
|
||||||
#ifdef WOLF_CRYPTO_CB
|
#ifdef MAX3266X_CB
|
||||||
/* Revert back to SW so HW CB works */
|
/* Revert back to SW so HW CB works */
|
||||||
/* HW only works for AES: ECB, CBC, and partial via ECB for other modes */
|
/* HW only works for AES: ECB, CBC, and partial via ECB for other modes */
|
||||||
#include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
|
#include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
|
||||||
@ -4168,9 +4168,6 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
|
|||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
|
|
||||||
XMEMCPY(rk, key, keySz);
|
XMEMCPY(rk, key, keySz);
|
||||||
#ifdef MAX3266X_CB /* Copies needed values to use later if CB is used */
|
|
||||||
XMEMCPY(aes->cb_key, key, keySz);
|
|
||||||
#endif
|
|
||||||
#if defined(LITTLE_ENDIAN_ORDER) && !defined(WOLFSSL_PIC32MZ_CRYPT) && \
|
#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)
|
!defined(MAX3266X_AES)
|
||||||
@ -4613,9 +4610,6 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
XMEMCPY(aes->key, userKey, keylen);
|
XMEMCPY(aes->key, userKey, keylen);
|
||||||
#ifdef MAX3266X_CB /* Copy Key for CB for use later if needed */
|
|
||||||
XMEMCMP(aes->cb_key, userKey, keylen);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef WC_AES_BITSLICED
|
#ifndef WC_AES_BITSLICED
|
||||||
#if defined(LITTLE_ENDIAN_ORDER) && !defined(WOLFSSL_PIC32MZ_CRYPT) && \
|
#if defined(LITTLE_ENDIAN_ORDER) && !defined(WOLFSSL_PIC32MZ_CRYPT) && \
|
||||||
|
@ -55,11 +55,6 @@
|
|||||||
#ifdef WOLFSSL_CAAM
|
#ifdef WOLFSSL_CAAM
|
||||||
#include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
|
#include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (WOLFSSL_MAX3266X) || defined (WOLFSSL_MAX3266X_OLD)
|
|
||||||
#include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* TODO: Consider linked list with mutex */
|
/* TODO: Consider linked list with mutex */
|
||||||
#ifndef MAX_CRYPTO_DEVID_CALLBACKS
|
#ifndef MAX_CRYPTO_DEVID_CALLBACKS
|
||||||
#define MAX_CRYPTO_DEVID_CALLBACKS 8
|
#define MAX_CRYPTO_DEVID_CALLBACKS 8
|
||||||
|
@ -44,6 +44,17 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#include <wolfssl/wolfcrypt/cryptocb.h>
|
||||||
|
|
||||||
|
/* Enable Hardware Callback */
|
||||||
|
#if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
|
||||||
|
/* Revert back to SW so HW CB works */
|
||||||
|
/* HW only works for AES: ECB, CBC, and partial via ECB for other modes */
|
||||||
|
#include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <wolfssl/wolfcrypt/aes.h>
|
#include <wolfssl/wolfcrypt/aes.h>
|
||||||
#include <wolfssl/wolfcrypt/logging.h>
|
#include <wolfssl/wolfcrypt/logging.h>
|
||||||
|
|
||||||
@ -14928,6 +14939,20 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (aes->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int crypto_cb_ret =
|
||||||
|
wc_CryptoCb_AesCcmEncrypt(aes, out, in, inSz, nonce, nonceSz,
|
||||||
|
authTag, authTagSz, authIn, authInSz);
|
||||||
|
if (crypto_cb_ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return crypto_cb_ret;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
XMEMCPY(B+1, nonce, nonceSz);
|
XMEMCPY(B+1, nonce, nonceSz);
|
||||||
lenSz = AES_BLOCK_SIZE - 1 - (byte)nonceSz;
|
lenSz = AES_BLOCK_SIZE - 1 - (byte)nonceSz;
|
||||||
B[0] = (authInSz > 0 ? 64 : 0)
|
B[0] = (authInSz > 0 ? 64 : 0)
|
||||||
@ -15000,6 +15025,20 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (aes->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int crypto_cb_ret =
|
||||||
|
wc_CryptoCb_AesCcmDecrypt(aes, out, in, inSz, nonce, nonceSz,
|
||||||
|
authTag, authTagSz, authIn, authInSz);
|
||||||
|
if (crypto_cb_ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return crypto_cb_ret;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
o = out;
|
o = out;
|
||||||
oSz = inSz;
|
oSz = inSz;
|
||||||
XMEMCPY(B+1, nonce, nonceSz);
|
XMEMCPY(B+1, nonce, nonceSz);
|
||||||
@ -16534,7 +16573,14 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
if (aes->devId != INVALID_DEVID) {
|
||||||
|
if (keylen > sizeof(aes->devKey)) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
XMEMCPY(aes->devKey, userKey, keylen);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef WOLFSSL_AES_COUNTER
|
#ifdef WOLFSSL_AES_COUNTER
|
||||||
aes->left = 0;
|
aes->left = 0;
|
||||||
#endif /* WOLFSSL_AES_COUNTER */
|
#endif /* WOLFSSL_AES_COUNTER */
|
||||||
@ -16584,6 +16630,20 @@ static int wc_AesEncrypt(Aes* aes, const byte* inBlock, byte* outBlock)
|
|||||||
return KEYUSAGE_E;
|
return KEYUSAGE_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MAX3266X_CB /* Can do a basic ECB block */
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (aes->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int ret_cb = wc_CryptoCb_AesEcbEncrypt(aes, outBlock, inBlock,
|
||||||
|
AES_BLOCK_SIZE);
|
||||||
|
if (ret_cb != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
|
||||||
|
return ret_cb;
|
||||||
|
}
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
AES_ECB_encrypt(inBlock, outBlock, AES_BLOCK_SIZE,
|
AES_ECB_encrypt(inBlock, outBlock, AES_BLOCK_SIZE,
|
||||||
(const unsigned char*)aes->key, aes->rounds);
|
(const unsigned char*)aes->key, aes->rounds);
|
||||||
return 0;
|
return 0;
|
||||||
@ -16598,6 +16658,19 @@ static int wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
|
|||||||
return KEYUSAGE_E;
|
return KEYUSAGE_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MAX3266X_CB /* Can do a basic ECB block */
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (aes->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int ret_cb = wc_CryptoCb_AesEcbDecrypt(aes, outBlock, inBlock,
|
||||||
|
AES_BLOCK_SIZE);
|
||||||
|
if (ret_cb != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return ret_cb;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
AES_ECB_decrypt(inBlock, outBlock, AES_BLOCK_SIZE,
|
AES_ECB_decrypt(inBlock, outBlock, AES_BLOCK_SIZE,
|
||||||
(const unsigned char*)aes->key, aes->rounds);
|
(const unsigned char*)aes->key, aes->rounds);
|
||||||
return 0;
|
return 0;
|
||||||
@ -16652,6 +16725,18 @@ int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (aes->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int crypto_cb_ret = wc_CryptoCb_AesCbcEncrypt(aes, out, in, sz);
|
||||||
|
if (crypto_cb_ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return crypto_cb_ret;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
AES_CBC_encrypt(in, out, sz, (const unsigned char*)aes->key, aes->rounds,
|
AES_CBC_encrypt(in, out, sz, (const unsigned char*)aes->key, aes->rounds,
|
||||||
(unsigned char*)aes->reg);
|
(unsigned char*)aes->reg);
|
||||||
|
|
||||||
@ -16681,6 +16766,18 @@ int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (aes->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int crypto_cb_ret = wc_CryptoCb_AesCbcDecrypt(aes, out, in, sz);
|
||||||
|
if (crypto_cb_ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return crypto_cb_ret;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
AES_CBC_decrypt(in, out, sz, (const unsigned char*)aes->key, aes->rounds,
|
AES_CBC_decrypt(in, out, sz, (const unsigned char*)aes->key, aes->rounds,
|
||||||
(unsigned char*)aes->reg);
|
(unsigned char*)aes->reg);
|
||||||
|
|
||||||
@ -16703,6 +16800,18 @@ int wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
|||||||
WOLFSSL_ERROR_VERBOSE(KEYUSAGE_E);
|
WOLFSSL_ERROR_VERBOSE(KEYUSAGE_E);
|
||||||
return KEYUSAGE_E;
|
return KEYUSAGE_E;
|
||||||
}
|
}
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (aes->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int crypto_cb_ret = wc_CryptoCb_AesCtrEncrypt(aes, out, in, sz);
|
||||||
|
if (crypto_cb_ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return crypto_cb_ret;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
tmp = (byte*)aes->tmp + AES_BLOCK_SIZE - aes->left;
|
tmp = (byte*)aes->tmp + AES_BLOCK_SIZE - aes->left;
|
||||||
/* consume any unused bytes left in aes->tmp */
|
/* consume any unused bytes left in aes->tmp */
|
||||||
@ -17080,6 +17189,13 @@ int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len)
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
if (aes->devId != INVALID_DEVID) {
|
||||||
|
XMEMCPY(aes->devKey, key, len);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
XMEMSET(iv, 0, AES_BLOCK_SIZE);
|
XMEMSET(iv, 0, AES_BLOCK_SIZE);
|
||||||
ret = wc_AesSetKey(aes, key, len, iv, AES_ENCRYPTION);
|
ret = wc_AesSetKey(aes, key, len, iv, AES_ENCRYPTION);
|
||||||
|
|
||||||
@ -17241,6 +17357,20 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
|||||||
return KEYUSAGE_E;
|
return KEYUSAGE_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (aes->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int crypto_cb_ret =
|
||||||
|
wc_CryptoCb_AesGcmEncrypt(aes, out, in, sz, iv, ivSz, authTag,
|
||||||
|
authTagSz, authIn, authInSz);
|
||||||
|
if (crypto_cb_ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return crypto_cb_ret;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
XMEMSET(initialCounter, 0, AES_BLOCK_SIZE);
|
XMEMSET(initialCounter, 0, AES_BLOCK_SIZE);
|
||||||
if (ivSz == GCM_NONCE_MID_SZ) {
|
if (ivSz == GCM_NONCE_MID_SZ) {
|
||||||
XMEMCPY(initialCounter, iv, ivSz);
|
XMEMCPY(initialCounter, iv, ivSz);
|
||||||
@ -17329,6 +17459,20 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (aes->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int crypto_cb_ret =
|
||||||
|
wc_CryptoCb_AesGcmDecrypt(aes, out, in, sz, iv, ivSz,
|
||||||
|
authTag, authTagSz, authIn, authInSz);
|
||||||
|
if (crypto_cb_ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return crypto_cb_ret;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
XMEMSET(initialCounter, 0, AES_BLOCK_SIZE);
|
XMEMSET(initialCounter, 0, AES_BLOCK_SIZE);
|
||||||
if (ivSz == GCM_NONCE_MID_SZ) {
|
if (ivSz == GCM_NONCE_MID_SZ) {
|
||||||
XMEMCPY(initialCounter, iv, ivSz);
|
XMEMCPY(initialCounter, iv, ivSz);
|
||||||
|
@ -57,6 +57,10 @@
|
|||||||
#include <wolfcrypt/src/misc.c>
|
#include <wolfcrypt/src/misc.c>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#include <wolfssl/wolfcrypt/cryptocb.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(FREESCALE_MMCAU_SHA)
|
#if defined(FREESCALE_MMCAU_SHA)
|
||||||
#ifdef FREESCALE_MMCAU_CLASSIC_SHA
|
#ifdef FREESCALE_MMCAU_CLASSIC_SHA
|
||||||
#include "cau_api.h"
|
#include "cau_api.h"
|
||||||
@ -1513,25 +1517,44 @@ static WC_INLINE int Sha256Final(wc_Sha256* sha256, byte* hash)
|
|||||||
|
|
||||||
int wc_InitSha256_ex(wc_Sha256* sha256, void* heap, int devId)
|
int wc_InitSha256_ex(wc_Sha256* sha256, void* heap, int devId)
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
if (sha256 == NULL)
|
if (sha256 == NULL)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
|
ret = InitSha256(sha256);
|
||||||
|
if (ret != 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
sha256->heap = heap;
|
sha256->heap = heap;
|
||||||
#ifdef WOLF_CRYPTO_CB
|
#ifdef WOLF_CRYPTO_CB
|
||||||
sha256->devId = devId;
|
sha256->devId = devId;
|
||||||
|
sha256->devCtx = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
ret = wc_MXC_TPU_SHA_Init(&(sha256->mxcCtx));
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
(void)devId;
|
(void)devId;
|
||||||
|
return ret;
|
||||||
return InitSha256(sha256);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int wc_InitSha256(wc_Sha256* sha256)
|
int wc_InitSha256(wc_Sha256* sha256)
|
||||||
{
|
{
|
||||||
return wc_InitSha256_ex(sha256, NULL, INVALID_DEVID);
|
int devId = INVALID_DEVID;
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
devId = wc_CryptoCb_DefaultDevID();
|
||||||
|
#endif
|
||||||
|
return wc_InitSha256_ex(sha256, NULL, devId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wc_Sha256Free(wc_Sha256* sha256)
|
void wc_Sha256Free(wc_Sha256* sha256)
|
||||||
{
|
{
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
wc_MXC_TPU_SHA_Free(&(sha256->mxcCtx));
|
||||||
|
#endif
|
||||||
(void)sha256;
|
(void)sha256;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1541,6 +1564,18 @@ int wc_Sha256Update(wc_Sha256* sha256, const byte* data, word32 len)
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (sha256->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int ret = wc_CryptoCb_Sha256Hash(sha256, data, len, NULL);
|
||||||
|
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return ret;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return Sha256Update(sha256, data, len);
|
return Sha256Update(sha256, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1573,6 +1608,18 @@ int wc_Sha256Final(wc_Sha256* sha256, byte* hash)
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (sha256->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
ret = wc_CryptoCb_Sha256Hash(sha256, NULL, 0, hash);
|
||||||
|
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return ret;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ret = Sha256Final(sha256, hash);
|
ret = Sha256Final(sha256, hash);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
@ -1621,6 +1668,13 @@ int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst)
|
|||||||
|
|
||||||
XMEMCPY(dst, src, sizeof(wc_Sha256));
|
XMEMCPY(dst, src, sizeof(wc_Sha256));
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
ret = wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,6 +172,10 @@ static int InitSha512_Family(wc_Sha512* sha512, void* heap, int devId,
|
|||||||
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
||||||
sha512->W = NULL;
|
sha512->W = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
sha512->devId = devId;
|
||||||
|
sha512->devCtx = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (type == WC_HASH_TYPE_SHA512) {
|
if (type == WC_HASH_TYPE_SHA512) {
|
||||||
ret = InitSha512(sha512);
|
ret = InitSha512(sha512);
|
||||||
@ -201,6 +205,12 @@ static int InitSha512_Family(wc_Sha512* sha512, void* heap, int devId,
|
|||||||
|
|
||||||
int wc_InitSha512_ex(wc_Sha512* sha512, void* heap, int devId)
|
int wc_InitSha512_ex(wc_Sha512* sha512, void* heap, int devId)
|
||||||
{
|
{
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
if (wc_MXC_TPU_SHA_Init(&(sha512->mxcCtx)) != 0) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return InitSha512_Family(sha512, heap, devId, WC_HASH_TYPE_SHA512);
|
return InitSha512_Family(sha512, heap, devId, WC_HASH_TYPE_SHA512);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,6 +518,18 @@ int wc_Sha512Update(wc_Sha512* sha512, const byte* data, word32 len)
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (sha512->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int ret = wc_CryptoCb_Sha512Hash(sha512, data, len, NULL);
|
||||||
|
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return ret;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return Sha512Update(sha512, data, len);
|
return Sha512Update(sha512, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,13 +648,20 @@ static int Sha512_Family_Final(wc_Sha512* sha512, byte* hash,
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
#ifdef WOLF_CRYPTO_CB
|
#ifdef WOLF_CRYPTO_CB
|
||||||
if (sha512->devId != INVALID_DEVID) {
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
ret = wc_CryptoCb_Sha512Hash(sha512, NULL, 0, hash);
|
if (sha512->devId != INVALID_DEVID)
|
||||||
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
#endif
|
||||||
|
{
|
||||||
|
byte localHash[WC_SHA512_DIGEST_SIZE];
|
||||||
|
ret = wc_CryptoCb_Sha512Hash(sha512, NULL, 0, localHash);
|
||||||
|
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
|
||||||
|
XMEMCPY(hash, localHash, digestSz);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
/* fall-through when unavailable */
|
/* fall-through when unavailable */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
|
||||||
if (sha512->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA512) {
|
if (sha512->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA512) {
|
||||||
#if defined(HAVE_INTEL_QA)
|
#if defined(HAVE_INTEL_QA)
|
||||||
@ -661,7 +690,12 @@ int wc_Sha512Final(wc_Sha512* sha512, byte* hash)
|
|||||||
|
|
||||||
int wc_InitSha512(wc_Sha512* sha512)
|
int wc_InitSha512(wc_Sha512* sha512)
|
||||||
{
|
{
|
||||||
return wc_InitSha512_ex(sha512, NULL, INVALID_DEVID);
|
int devId = INVALID_DEVID;
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
devId = wc_CryptoCb_DefaultDevID();
|
||||||
|
#endif
|
||||||
|
return wc_InitSha512_ex(sha512, NULL, devId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wc_Sha512Free(wc_Sha512* sha512)
|
void wc_Sha512Free(wc_Sha512* sha512)
|
||||||
@ -673,6 +707,11 @@ void wc_Sha512Free(wc_Sha512* sha512)
|
|||||||
XFREE(sha512->W, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(sha512->W, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
sha512->W = NULL;
|
sha512->W = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
wc_MXC_TPU_SHA_Free(&(sha512->mxcCtx));
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OPENSSL_EXTRA
|
#ifdef OPENSSL_EXTRA
|
||||||
@ -724,6 +763,18 @@ int wc_Sha384Update(wc_Sha384* sha384, const byte* data, word32 len)
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (sha384->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int ret = wc_CryptoCb_Sha384Hash(sha384, data, len, NULL);
|
||||||
|
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return ret;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return Sha512Update((wc_Sha512*)sha384, data, len);
|
return Sha512Update((wc_Sha512*)sha384, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -757,6 +808,18 @@ int wc_Sha384Final(wc_Sha384* sha384, byte* hash)
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
#ifndef WOLF_CRYPTO_CB_FIND
|
||||||
|
if (sha384->devId != INVALID_DEVID)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
ret = wc_CryptoCb_Sha384Hash(sha384, NULL, 0, hash);
|
||||||
|
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
|
||||||
|
return ret;
|
||||||
|
/* fall-through when unavailable */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ret = Sha512Final((wc_Sha512*)sha384);
|
ret = Sha512Final((wc_Sha512*)sha384);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
@ -782,7 +845,16 @@ int wc_InitSha384_ex(wc_Sha384* sha384, void* heap, int devId)
|
|||||||
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
||||||
sha384->W = NULL;
|
sha384->W = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
sha384->devId = devId;
|
||||||
|
sha384->devCtx = NULL;
|
||||||
|
#endif
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
ret = wc_MXC_TPU_SHA_Init(&(sha384->mxcCtx));
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
(void)devId;
|
(void)devId;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -790,7 +862,12 @@ int wc_InitSha384_ex(wc_Sha384* sha384, void* heap, int devId)
|
|||||||
|
|
||||||
int wc_InitSha384(wc_Sha384* sha384)
|
int wc_InitSha384(wc_Sha384* sha384)
|
||||||
{
|
{
|
||||||
return wc_InitSha384_ex(sha384, NULL, INVALID_DEVID);
|
int devId = INVALID_DEVID;
|
||||||
|
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
devId = wc_CryptoCb_DefaultDevID();
|
||||||
|
#endif
|
||||||
|
return wc_InitSha384_ex(sha384, NULL, devId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wc_Sha384Free(wc_Sha384* sha384)
|
void wc_Sha384Free(wc_Sha384* sha384)
|
||||||
@ -802,6 +879,11 @@ void wc_Sha384Free(wc_Sha384* sha384)
|
|||||||
XFREE(sha384->W, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(sha384->W, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
sha384->W = NULL;
|
sha384->W = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
wc_MXC_TPU_SHA_Free(&(sha384->mxcCtx));
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* WOLFSSL_SHA384 */
|
#endif /* WOLFSSL_SHA384 */
|
||||||
@ -880,6 +962,13 @@ int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst)
|
|||||||
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
ret = wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1037,6 +1126,13 @@ int wc_Sha384Copy(wc_Sha384* src, wc_Sha384* dst)
|
|||||||
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
ret = wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,9 +34,10 @@ this can be done by adding any combination of these defines:
|
|||||||
#define MAX3266X_SHA - Allows usage of TPU for Hash Acceleration
|
#define MAX3266X_SHA - Allows usage of TPU for Hash Acceleration
|
||||||
#define MAX3266X_MATH - Allows usage of MAA for MOD based Math Acceleration
|
#define MAX3266X_MATH - Allows usage of MAA for MOD based Math Acceleration
|
||||||
```
|
```
|
||||||
For this you will still need to use `#define WOLFSSL_MAX3266X` or `#define WOLFSSL_MAX3266X_OLD`. When you use a specific hardware define like
|
For this you will still need to use `#define WOLFSSL_MAX3266X` or `#define WOLFSSL_MAX3266X_OLD`.
|
||||||
`#define MAX3266X_RNG` this will mean only the TRNG device is being used, and
|
When you use a specific hardware define like `#define MAX3266X_RNG` this will
|
||||||
all other operations will use the default software implementations.
|
mean only the TRNG device is being used, and all other operations will use the
|
||||||
|
default software implementations.
|
||||||
|
|
||||||
The other prerequisite is that a change needs to be made to the Maxim SDK. This
|
The other prerequisite is that a change needs to be made to the Maxim SDK. This
|
||||||
is to use the MAA Math Accelerator, this change only needs to be made if you are
|
is to use the MAA Math Accelerator, this change only needs to be made if you are
|
||||||
@ -97,6 +98,32 @@ like RSA and ECC key generation):
|
|||||||
- sqrmod: `(b^2)mod m = r`
|
- sqrmod: `(b^2)mod m = r`
|
||||||
- exptmod: `(b^e)mod m = r`
|
- exptmod: `(b^e)mod m = r`
|
||||||
|
|
||||||
|
## Crypto Callback Support
|
||||||
|
This port also supports using the Crypto Callback functionality in wolfSSL.
|
||||||
|
When `WOLF_CRYPTO_CB` is defined in `user_settings.h` along with
|
||||||
|
`WOLFSSL_MAX3266X` or `WOLFSSL_MAX3266X_OLD` it will build the library to allow
|
||||||
|
the ability to switch between hardware and software implementations.
|
||||||
|
|
||||||
|
Crypto Callbacks only support using the hardware for these Algorithms:
|
||||||
|
|
||||||
|
- AES ECB: 128, 192, 256
|
||||||
|
- AES CBC: 128, 192, 256
|
||||||
|
- SHA-1
|
||||||
|
- SHA-256
|
||||||
|
- SHA-384
|
||||||
|
- SHA-512
|
||||||
|
|
||||||
|
When using `WOLF_CRYPTO_CB` and `WOLFSSL_MAX3266X` or `WOLFSSL_MAX3266X_OLD`,
|
||||||
|
`MAX3266X_MATH` is turned off and is is currently not supported to use with
|
||||||
|
`WOLF_CRYPTO_CB`.
|
||||||
|
|
||||||
|
The Hardware of the port will be used by default when no devId is set.
|
||||||
|
To use software versions of the support Callback Algorithms the devId will need
|
||||||
|
to be set to `INVALID_DEVID`.
|
||||||
|
|
||||||
|
For more information about Crypto Callbacks and how to use them please refer to
|
||||||
|
the [wolfSSL manual](https://www.wolfssl.com/documentation/manuals/wolfssl/chapter06.html).
|
||||||
|
|
||||||
## Extra Information
|
## Extra Information
|
||||||
For more Verbose info you can use `#define DEBUG_WOLFSSL` in combination with
|
For more Verbose info you can use `#define DEBUG_WOLFSSL` in combination with
|
||||||
`#define MAX3266X_VERBOSE` to see if errors are occurring during the hardware
|
`#define MAX3266X_VERBOSE` to see if errors are occurring during the hardware
|
||||||
|
@ -134,6 +134,112 @@ int wc_MxcAesCryptoCb(wc_CryptoInfo* info)
|
|||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
|
||||||
|
int wc_MxcShaCryptoCb(wc_CryptoInfo* info)
|
||||||
|
{
|
||||||
|
switch (info->hash.type) {
|
||||||
|
#ifndef NO_SHA
|
||||||
|
case WC_HASH_TYPE_SHA:
|
||||||
|
MAX3266X_MSG("SHA-1 CB:");
|
||||||
|
/* Update Case */
|
||||||
|
if (info->hash.in != NULL && info->hash.digest == NULL) {
|
||||||
|
MAX3266X_MSG("Update CB");
|
||||||
|
return wc_MXC_TPU_SHA_Update(&(info->hash.sha1->mxcCtx),
|
||||||
|
info->hash.in, info->hash.inSz);
|
||||||
|
}
|
||||||
|
/* Sha 1 Final Case */
|
||||||
|
if (info->hash.in == NULL && info->hash.digest != NULL) {
|
||||||
|
MAX3266X_MSG("Final CB");
|
||||||
|
return wc_MXC_TPU_SHA_Final(&(info->hash.sha1->mxcCtx),
|
||||||
|
info->hash.digest,
|
||||||
|
MXC_TPU_HASH_SHA1);
|
||||||
|
}
|
||||||
|
break; /* Break Out and Return Error */
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_SHA224
|
||||||
|
case WC_HASH_TYPE_SHA224:
|
||||||
|
MAX3266X_MSG("SHA-224 CB:");
|
||||||
|
/* Update Case */
|
||||||
|
if (info->hash.in != NULL && info->hash.digest == NULL) {
|
||||||
|
MAX3266X_MSG("Update CB");
|
||||||
|
return wc_MXC_TPU_SHA_Update(&(info->hash.sha224->mxcCtx),
|
||||||
|
info->hash.in, info->hash.inSz);
|
||||||
|
}
|
||||||
|
/* Sha 256 Final Case */
|
||||||
|
if (info->hash.in == NULL && info->hash.digest != NULL) {
|
||||||
|
MAX3266X_MSG("Final CB");
|
||||||
|
return wc_MXC_TPU_SHA_Final(&(info->hash.sha224->mxcCtx),
|
||||||
|
info->hash.digest,
|
||||||
|
MXC_TPU_HASH_SHA224);
|
||||||
|
}
|
||||||
|
break; /* Break Out and Return Error */
|
||||||
|
#endif
|
||||||
|
#ifndef NO_SHA256
|
||||||
|
case WC_HASH_TYPE_SHA256:
|
||||||
|
MAX3266X_MSG("SHA-256 CB:");
|
||||||
|
/* Update Case */
|
||||||
|
if (info->hash.in != NULL && info->hash.digest == NULL) {
|
||||||
|
MAX3266X_MSG("Update CB");
|
||||||
|
return wc_MXC_TPU_SHA_Update(&(info->hash.sha256->mxcCtx),
|
||||||
|
info->hash.in, info->hash.inSz);
|
||||||
|
}
|
||||||
|
/* Sha 256 Final Case */
|
||||||
|
if (info->hash.in == NULL && info->hash.digest != NULL) {
|
||||||
|
MAX3266X_MSG("Final CB");
|
||||||
|
return wc_MXC_TPU_SHA_Final(&(info->hash.sha256->mxcCtx),
|
||||||
|
info->hash.digest,
|
||||||
|
MXC_TPU_HASH_SHA256);
|
||||||
|
}
|
||||||
|
break; /* Break Out and Return Error */
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_SHA384
|
||||||
|
case WC_HASH_TYPE_SHA384:
|
||||||
|
MAX3266X_MSG("SHA-384 CB:");
|
||||||
|
/* Update Case */
|
||||||
|
if (info->hash.in != NULL && info->hash.digest == NULL) {
|
||||||
|
MAX3266X_MSG("Update CB");
|
||||||
|
return wc_MXC_TPU_SHA_Update(&(info->hash.sha384->mxcCtx),
|
||||||
|
info->hash.in, info->hash.inSz);
|
||||||
|
}
|
||||||
|
/* Sha 384 Final Case */
|
||||||
|
if (info->hash.in == NULL && info->hash.digest != NULL) {
|
||||||
|
MAX3266X_MSG("Final CB");
|
||||||
|
return wc_MXC_TPU_SHA_Final(&(info->hash.sha384->mxcCtx),
|
||||||
|
info->hash.digest,
|
||||||
|
MXC_TPU_HASH_SHA384);
|
||||||
|
}
|
||||||
|
break; /* Break Out and Return Error */
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_SHA512
|
||||||
|
case WC_HASH_TYPE_SHA512:
|
||||||
|
MAX3266X_MSG("SHA-512 CB:");
|
||||||
|
/* Update Case */
|
||||||
|
if (info->hash.in != NULL && info->hash.digest == NULL) {
|
||||||
|
MAX3266X_MSG("Update CB");
|
||||||
|
return wc_MXC_TPU_SHA_Update(&(info->hash.sha512->mxcCtx),
|
||||||
|
info->hash.in, info->hash.inSz);
|
||||||
|
}
|
||||||
|
/* Sha 512 Final Case */
|
||||||
|
if (info->hash.in == NULL && info->hash.digest != NULL) {
|
||||||
|
MAX3266X_MSG("Final CB");
|
||||||
|
return wc_MXC_TPU_SHA_Final(&(info->hash.sha512->mxcCtx),
|
||||||
|
info->hash.digest,
|
||||||
|
MXC_TPU_HASH_SHA512);
|
||||||
|
}
|
||||||
|
break; /* Break Out and Return Error */
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
/* Hash type not supported */
|
||||||
|
return WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
|
||||||
|
}
|
||||||
|
if (info->hash.inSz == 0) {
|
||||||
|
return 0; /* Dont need to Update when Size is Zero */
|
||||||
|
}
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
#endif /* MAX3266X_SHA_CB */
|
||||||
|
|
||||||
/* Determines AES Type for Callback */
|
/* Determines AES Type for Callback */
|
||||||
/* General Callback Function to determine ALGO Type */
|
/* General Callback Function to determine ALGO Type */
|
||||||
int wc_MxcCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
int wc_MxcCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
||||||
@ -151,10 +257,15 @@ int wc_MxcCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
|
|||||||
|
|
||||||
switch (info->algo_type) {
|
switch (info->algo_type) {
|
||||||
case WC_ALGO_TYPE_CIPHER:
|
case WC_ALGO_TYPE_CIPHER:
|
||||||
/* return this to bypass HW and use SW */
|
MAX3266X_MSG("Using MXC AES HW Callback:");
|
||||||
MAX3266X_MSG("Using MXC HW Callback:");
|
|
||||||
ret = wc_MxcAesCryptoCb(info); /* Determine AES HW or SW */
|
ret = wc_MxcAesCryptoCb(info); /* Determine AES HW or SW */
|
||||||
break;
|
break;
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
case WC_ALGO_TYPE_HASH:
|
||||||
|
MAX3266X_MSG("Using MXC SHA HW Callback:");
|
||||||
|
ret = wc_MxcShaCryptoCb(info); /* Determine SHA HW or SW */
|
||||||
|
break;
|
||||||
|
#endif /* MAX3266X_SHA_CB */
|
||||||
default:
|
default:
|
||||||
MAX3266X_MSG("Callback not support with MXC, using SW");
|
MAX3266X_MSG("Callback not support with MXC, using SW");
|
||||||
/* return this to bypass HW and use SW */
|
/* return this to bypass HW and use SW */
|
||||||
@ -305,7 +416,7 @@ int wc_MxcCb_AesEcbEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = wc_MXC_TPU_AesEncrypt(in, (byte*)aes->reg, (byte*)aes->cb_key,
|
status = wc_MXC_TPU_AesEncrypt(in, (byte*)aes->reg, (byte*)aes->devKey,
|
||||||
MXC_TPU_MODE_ECB, sz, out, keySize);
|
MXC_TPU_MODE_ECB, sz, out, keySize);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@ -341,7 +452,7 @@ int wc_MxcCb_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = wc_MXC_TPU_AesEncrypt(in, iv, (byte*)aes->cb_key,
|
status = wc_MXC_TPU_AesEncrypt(in, iv, (byte*)aes->devKey,
|
||||||
MXC_TPU_MODE_CBC, sz, out,
|
MXC_TPU_MODE_CBC, sz, out,
|
||||||
(unsigned int)keySize);
|
(unsigned int)keySize);
|
||||||
/* store iv for next call */
|
/* store iv for next call */
|
||||||
@ -421,7 +532,7 @@ int wc_MxcCb_AesEcbDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = wc_MXC_TPU_AesDecrypt(in, (byte*)aes->reg, (byte*)aes->cb_key,
|
status = wc_MXC_TPU_AesDecrypt(in, (byte*)aes->reg, (byte*)aes->devKey,
|
||||||
MXC_TPU_MODE_ECB, sz, out, keySize);
|
MXC_TPU_MODE_ECB, sz, out, keySize);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@ -460,7 +571,7 @@ int wc_MxcCb_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
|||||||
|
|
||||||
/* get IV for next call */
|
/* get IV for next call */
|
||||||
XMEMCPY(temp_block, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
|
XMEMCPY(temp_block, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
|
||||||
status = wc_MXC_TPU_AesDecrypt(in, iv, (byte*)aes->cb_key,
|
status = wc_MXC_TPU_AesDecrypt(in, iv, (byte*)aes->devKey,
|
||||||
MXC_TPU_MODE_CBC, sz, out,
|
MXC_TPU_MODE_CBC, sz, out,
|
||||||
keySize);
|
keySize);
|
||||||
|
|
||||||
@ -475,7 +586,7 @@ int wc_MxcCb_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
|||||||
#endif /* HAVE_AES_DECRYPT */
|
#endif /* HAVE_AES_DECRYPT */
|
||||||
#endif /* MAX3266X_AES */
|
#endif /* MAX3266X_AES */
|
||||||
|
|
||||||
#if defined(MAX3266X_SHA)
|
#if defined(MAX3266X_SHA) || defined(MAX3266X_SHA_CB)
|
||||||
|
|
||||||
int wc_MXC_TPU_SHA_Init(wc_MXC_Sha *hash)
|
int wc_MXC_TPU_SHA_Init(wc_MXC_Sha *hash)
|
||||||
{
|
{
|
||||||
@ -521,7 +632,7 @@ int wc_MXC_TPU_SHA_Update(wc_MXC_Sha *hash, const unsigned char* data,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
return -1;
|
return MEMORY_E;
|
||||||
}
|
}
|
||||||
hash->msg = p;
|
hash->msg = p;
|
||||||
hash->size = hash->used+size;
|
hash->size = hash->used+size;
|
||||||
@ -599,7 +710,16 @@ int wc_MXC_TPU_SHA_Copy(wc_MXC_Sha* src, wc_MXC_Sha* dst)
|
|||||||
}
|
}
|
||||||
dst->used = src->used;
|
dst->used = src->used;
|
||||||
dst->size = src->size;
|
dst->size = src->size;
|
||||||
XMEMCPY(dst->hash, src->hash, sizeof(dst->hash));
|
if (dst->msg == src->msg && src->msg != 0) {
|
||||||
|
/* Allocate new memory for dst->msg if it points to the same location */
|
||||||
|
/* as src->msg */
|
||||||
|
dst->msg = (unsigned char*)XMALLOC(src->size, NULL,
|
||||||
|
DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
if (dst->msg == NULL) {
|
||||||
|
return MEMORY_E; /* Handle memory allocation failure */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XMEMCPY(dst->msg, src->msg, src->size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,6 +779,7 @@ int wc_MXC_TPU_SHA_GetDigest(wc_MXC_Sha *hash, unsigned char* digest,
|
|||||||
return 0; /* False */
|
return 0; /* False */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef MAX3266X_SHA_CB
|
||||||
#if !defined(NO_SHA)
|
#if !defined(NO_SHA)
|
||||||
|
|
||||||
WOLFSSL_API int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId)
|
WOLFSSL_API int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId)
|
||||||
@ -893,8 +1014,8 @@ WOLFSSL_API void wc_Sha512Free(wc_Sha512* sha512)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* WOLFSSL_SHA512 */
|
#endif /* WOLFSSL_SHA512 */
|
||||||
|
#endif /* !MAX3266X_SHA_CB*/
|
||||||
#endif /* MAX3266X_SHA */
|
#endif /* MAX3266X_SHA || MAX3266X_SHA_CB */
|
||||||
|
|
||||||
#if defined(MAX3266X_MATH)
|
#if defined(MAX3266X_MATH)
|
||||||
|
|
||||||
@ -995,7 +1116,7 @@ int wc_MXC_MAA_zeroPad(mp_int* multiplier, mp_int* multiplicand,
|
|||||||
DYNAMIC_TYPE_TMP_BUFFER);
|
DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
if (zero_tmp == NULL) {
|
if (zero_tmp == NULL) {
|
||||||
MAX3266X_MSG("NULL pointer found after XMALLOC call");
|
MAX3266X_MSG("NULL pointer found after XMALLOC call");
|
||||||
return WC_HW_E;
|
return MEMORY_E;
|
||||||
}
|
}
|
||||||
XMEMSET(zero_tmp, 0x00, multiplier->size*sizeof(mp_digit));
|
XMEMSET(zero_tmp, 0x00, multiplier->size*sizeof(mp_digit));
|
||||||
|
|
||||||
@ -1428,4 +1549,4 @@ double wc_MXC_RTC_Time(void)
|
|||||||
|
|
||||||
#endif /* MAX3266X_RTC */
|
#endif /* MAX3266X_RTC */
|
||||||
|
|
||||||
#endif /* WOLFSSL_MAX32665 || WOLFSSL_MAX32666 */
|
#endif /* WOLFSSL_MAX32665 || WOLFSSL_MAX32666 */
|
||||||
|
@ -564,6 +564,13 @@ int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId)
|
|||||||
sha->devCtx = NULL;
|
sha->devCtx = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
ret = wc_MXC_TPU_SHA_Init(&(sha->mxcCtx));
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WOLFSSL_USE_ESP32_CRYPT_HASH_HW
|
#ifdef WOLFSSL_USE_ESP32_CRYPT_HASH_HW
|
||||||
if (sha->ctx.mode != ESP32_SHA_INIT) {
|
if (sha->ctx.mode != ESP32_SHA_INIT) {
|
||||||
/* it may be interesting to see old values during debugging */
|
/* it may be interesting to see old values during debugging */
|
||||||
@ -1057,6 +1064,9 @@ void wc_ShaFree(wc_Sha* sha)
|
|||||||
#ifdef WOLFSSL_PIC32MZ_HASH
|
#ifdef WOLFSSL_PIC32MZ_HASH
|
||||||
wc_ShaPic32Free(sha);
|
wc_ShaPic32Free(sha);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
wc_MXC_TPU_SHA_Free(&(sha->mxcCtx));
|
||||||
|
#endif
|
||||||
#if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH)
|
#if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH)
|
||||||
se050_hash_free(&sha->se050Ctx);
|
se050_hash_free(&sha->se050Ctx);
|
||||||
#endif
|
#endif
|
||||||
@ -1153,6 +1163,13 @@ int wc_ShaCopy(wc_Sha* src, wc_Sha* dst)
|
|||||||
esp_sha_ctx_copy(src, dst);
|
esp_sha_ctx_copy(src, dst);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
ret = wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WOLFSSL_HASH_FLAGS
|
#ifdef WOLFSSL_HASH_FLAGS
|
||||||
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
||||||
#endif
|
#endif
|
||||||
|
@ -279,10 +279,6 @@ static int InitSha256(wc_Sha256* sha256)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WOLF_CRYPTO_CB
|
|
||||||
sha256->devId = wc_CryptoCb_DefaultDevID();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WOLFSSL_MAXQ10XX_CRYPTO
|
#ifdef WOLFSSL_MAXQ10XX_CRYPTO
|
||||||
XMEMSET(&sha256->maxq_ctx, 0, sizeof(sha256->maxq_ctx));
|
XMEMSET(&sha256->maxq_ctx, 0, sizeof(sha256->maxq_ctx));
|
||||||
#endif
|
#endif
|
||||||
@ -1096,6 +1092,12 @@ static int InitSha256(wc_Sha256* sha256)
|
|||||||
sha256->devId = devId;
|
sha256->devId = devId;
|
||||||
sha256->devCtx = NULL;
|
sha256->devCtx = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
ret = wc_MXC_TPU_SHA_Init(&(sha256->mxcCtx));
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
||||||
sha256->W = NULL;
|
sha256->W = NULL;
|
||||||
#endif
|
#endif
|
||||||
@ -2246,6 +2248,10 @@ void wc_Sha256Free(wc_Sha256* sha256)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
wc_MXC_TPU_SHA_Free(&(sha256->mxcCtx));
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA256)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA256)
|
||||||
wolfAsync_DevCtxFree(&sha256->asyncDev, WOLFSSL_ASYNC_MARKER_SHA256);
|
wolfAsync_DevCtxFree(&sha256->asyncDev, WOLFSSL_ASYNC_MARKER_SHA256);
|
||||||
#endif /* WOLFSSL_ASYNC_CRYPT */
|
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||||
@ -2547,6 +2553,13 @@ int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst)
|
|||||||
wc_MAXQ10XX_Sha256Copy(src);
|
wc_MAXQ10XX_Sha256Copy(src);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
ret = wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
||||||
dst->W = NULL;
|
dst->W = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
@ -773,6 +773,12 @@ int wc_InitSha512_ex(wc_Sha512* sha512, void* heap, int devId)
|
|||||||
sha512->ctx.mode = ESP32_SHA_INIT;
|
sha512->ctx.mode = ESP32_SHA_INIT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
if (wc_MXC_TPU_SHA_Init(&(sha512->mxcCtx)) != 0){
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return InitSha512_Family(sha512, heap, devId, InitSha512);
|
return InitSha512_Family(sha512, heap, devId, InitSha512);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1454,6 +1460,10 @@ void wc_Sha512Free(wc_Sha512* sha512)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
wc_MXC_TPU_SHA_Free(&(sha512->mxcCtx));
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
|
||||||
wolfAsync_DevCtxFree(&sha512->asyncDev, WOLFSSL_ASYNC_MARKER_SHA512);
|
wolfAsync_DevCtxFree(&sha512->asyncDev, WOLFSSL_ASYNC_MARKER_SHA512);
|
||||||
#endif /* WOLFSSL_ASYNC_CRYPT */
|
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||||
@ -1759,6 +1769,13 @@ int wc_InitSha384_ex(wc_Sha384* sha384, void* heap, int devId)
|
|||||||
sha384->ctx.mode = ESP32_SHA_INIT;
|
sha384->ctx.mode = ESP32_SHA_INIT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
ret = wc_MXC_TPU_SHA_Init(&(sha384->mxcCtx));
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ret = InitSha384(sha384);
|
ret = InitSha384(sha384);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return ret;
|
return ret;
|
||||||
@ -1837,6 +1854,10 @@ void wc_Sha384Free(wc_Sha384* sha384)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
wc_MXC_TPU_SHA_Free(&(sha384->mxcCtx));
|
||||||
|
#endif
|
||||||
|
|
||||||
ForceZero(sha384, sizeof(*sha384));
|
ForceZero(sha384, sizeof(*sha384));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1958,6 +1979,13 @@ int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
ret = wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2247,6 +2275,13 @@ int wc_Sha384Copy(wc_Sha384* src, wc_Sha384* dst)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
ret = wc_MXC_TPU_SHA_Copy(&(src->mxcCtx), &(dst->mxcCtx));
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,11 +263,6 @@ struct Aes {
|
|||||||
word32 rounds;
|
word32 rounds;
|
||||||
#ifdef WC_C_DYNAMIC_FALLBACK
|
#ifdef WC_C_DYNAMIC_FALLBACK
|
||||||
word32 key_C_fallback[60];
|
word32 key_C_fallback[60];
|
||||||
#endif
|
|
||||||
#if (defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
|
|
||||||
defined(WOLF_CRYPTO_CB)
|
|
||||||
/* Need backup key for MXC CB */
|
|
||||||
word32 cb_key[60];
|
|
||||||
#endif
|
#endif
|
||||||
int keylen;
|
int keylen;
|
||||||
|
|
||||||
|
@ -24,13 +24,9 @@
|
|||||||
|
|
||||||
#if (defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
|
#if (defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
|
||||||
defined(WOLF_CRYPTO_CB)
|
defined(WOLF_CRYPTO_CB)
|
||||||
|
|
||||||
#ifndef WOLFSSL_MAX3266X_DEVID
|
#ifndef WOLFSSL_MAX3266X_DEVID
|
||||||
#define WOLFSSL_MAX3266X_DEVID 9
|
#define WOLFSSL_MAX3266X_DEVID 9
|
||||||
#endif
|
#endif
|
||||||
#ifndef MAX_CRYPTO_DEVID_CALLBACKS
|
|
||||||
#define MAX_CRYPTO_DEVID_CALLBACKS WOLFSSL_MAX3266X_DEVID
|
|
||||||
#endif
|
|
||||||
#define WC_USE_DEVID WOLFSSL_MAX3266X_DEVID
|
#define WC_USE_DEVID WOLFSSL_MAX3266X_DEVID
|
||||||
#include <wolfssl/wolfcrypt/types.h>
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
#include <wolfssl/wolfcrypt/cryptocb.h>
|
#include <wolfssl/wolfcrypt/cryptocb.h>
|
||||||
@ -62,6 +58,13 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif /* HAVE_AES_DECRYPT */
|
#endif /* HAVE_AES_DECRYPT */
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int wc_MXC_Sha256Update(wc_MXC_Sha* sha256,
|
||||||
|
const unsigned char* data,
|
||||||
|
unsigned int len);
|
||||||
|
WOLFSSL_LOCAL int wc_MXC_Sha256Final(wc_MXC_Sha* sha256,
|
||||||
|
unsigned char* hash);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,20 +30,31 @@
|
|||||||
|
|
||||||
#if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
|
#if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
|
||||||
|
|
||||||
|
/* Some extra conditions when using callbacks */
|
||||||
|
#if defined(WOLF_CRYPTO_CB)
|
||||||
|
#define MAX3266X_CB
|
||||||
|
#ifdef MAX3266X_MATH
|
||||||
|
#error Cannot have MAX3266X_MATH and MAX3266X_CB
|
||||||
|
#endif
|
||||||
|
#ifdef MAX3266X_SHA
|
||||||
|
#undef MAX3266X_SHA /* Turn Off Normal Sha Definition */
|
||||||
|
#define MAX3266X_SHA_CB /* Turn On Callback for SHA */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Default to all HW acceleration on unless specified in user_settings */
|
/* Default to all HW acceleration on unless specified in user_settings */
|
||||||
#if !defined(MAX3266X_RNG) && !defined(MAX3266X_AES) && \
|
#if !defined(MAX3266X_RNG) && !defined(MAX3266X_AES) && \
|
||||||
!defined(MAX3266X_AESGCM) && !defined(MAX3266X_SHA) && \
|
!defined(MAX3266X_AESGCM) && !defined(MAX3266X_SHA) && \
|
||||||
!defined(MAX3266X_MATH)
|
!defined(MAX3266X_MATH)
|
||||||
#define MAX3266X_RNG
|
#define MAX3266X_RNG
|
||||||
#define MAX3266X_AES
|
#define MAX3266X_AES
|
||||||
#define MAX3266X_SHA
|
#ifndef MAX3266X_CB
|
||||||
#define MAX3266X_ECDSA
|
#define MAX3266X_SHA /* SHA is Supported, but need new definitions */
|
||||||
#define MAX3266X_MATH
|
#define MAX3266X_MATH /* MATH is not supported with callbacks */
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MAX3266X_CB
|
||||||
/* Some extra conditions when using callbacks */
|
#define MAX3266X_SHA_CB /* Turn on Callback for SHA */
|
||||||
#if defined(WOLF_CRYPTO_CB)
|
#endif
|
||||||
#define MAX3266X_CB
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Crypto HW can be used in parallel on this device */
|
/* Crypto HW can be used in parallel on this device */
|
||||||
@ -92,7 +103,7 @@
|
|||||||
#define MXC_TPU_Cipher_AES_Decrypt TPU_AES_Decrypt
|
#define MXC_TPU_Cipher_AES_Decrypt TPU_AES_Decrypt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(MAX3266X_SHA)
|
#if defined(MAX3266X_SHA) || defined(MAX3266X_SHA_CB)
|
||||||
#include "hash.h" /* Proivdes Drivers for SHA */
|
#include "hash.h" /* Proivdes Drivers for SHA */
|
||||||
/* SHA Defines */
|
/* SHA Defines */
|
||||||
#define MXC_TPU_HASH_TYPE tpu_hashfunsel_t
|
#define MXC_TPU_HASH_TYPE tpu_hashfunsel_t
|
||||||
@ -141,7 +152,7 @@
|
|||||||
#include "trng.h" /* Provides Drivers for TRNG */
|
#include "trng.h" /* Provides Drivers for TRNG */
|
||||||
#endif
|
#endif
|
||||||
#if defined(MAX3266X_AES) || defined(MAX3266X_SHA) || \
|
#if defined(MAX3266X_AES) || defined(MAX3266X_SHA) || \
|
||||||
defined(MAX3266X_ECDSA) || defined(MAX3266X_RSA) || \
|
defined(MAX3266X_MATH) || defined(MAX3266X_RSA) || \
|
||||||
defined(MAX3266X_RNG)
|
defined(MAX3266X_RNG)
|
||||||
#include "tpu.h" /* SDK Drivers for the TPU unit */
|
#include "tpu.h" /* SDK Drivers for the TPU unit */
|
||||||
/* Handles AES, SHA, and */
|
/* Handles AES, SHA, and */
|
||||||
@ -223,25 +234,22 @@
|
|||||||
#endif /* HAVE_AES_DECRYPT */
|
#endif /* HAVE_AES_DECRYPT */
|
||||||
#endif /* MAX3266X_AES */
|
#endif /* MAX3266X_AES */
|
||||||
|
|
||||||
#ifdef MAX3266X_SHA
|
#if defined(MAX3266X_SHA) || defined(MAX3266X_SHA_CB)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned char *msg;
|
unsigned char *msg;
|
||||||
unsigned int used;
|
unsigned int used;
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
unsigned char hash[WOLFSSL_MAX_HASH_SIZE];
|
|
||||||
#ifdef WOLF_CRYPTO_CB
|
|
||||||
int devId;
|
|
||||||
void* devCtx; /* generic crypto callback context */
|
|
||||||
#endif
|
|
||||||
#ifdef WOLFSSL_HASH_FLAGS
|
#ifdef WOLFSSL_HASH_FLAGS
|
||||||
unsigned int flags; /* enum wc_HashFlags in hash.h */
|
unsigned int flags; /* enum wc_HashFlags in hash.h */
|
||||||
#endif
|
#endif
|
||||||
} wc_MXC_Sha;
|
} wc_MXC_Sha;
|
||||||
|
|
||||||
#if !defined(NO_SHA)
|
#if !defined(NO_SHA)
|
||||||
|
#ifndef MAX3266X_SHA_CB
|
||||||
typedef wc_MXC_Sha wc_Sha;
|
typedef wc_MXC_Sha wc_Sha;
|
||||||
#define WC_SHA_TYPE_DEFINED
|
#define WC_SHA_TYPE_DEFINED
|
||||||
|
#endif /* !MAX3266X_SHA_CB */
|
||||||
|
|
||||||
/* Define the SHA digest for an empty string */
|
/* Define the SHA digest for an empty string */
|
||||||
/* as a constant byte array */
|
/* as a constant byte array */
|
||||||
@ -252,8 +260,10 @@
|
|||||||
#endif /* NO_SHA */
|
#endif /* NO_SHA */
|
||||||
|
|
||||||
#if defined(WOLFSSL_SHA224)
|
#if defined(WOLFSSL_SHA224)
|
||||||
|
#ifndef MAX3266X_SHA_CB
|
||||||
typedef wc_MXC_Sha wc_Sha224;
|
typedef wc_MXC_Sha wc_Sha224;
|
||||||
#define WC_SHA224_TYPE_DEFINED
|
#define WC_SHA224_TYPE_DEFINED
|
||||||
|
#endif /* !MAX3266X_SHA_CB */
|
||||||
|
|
||||||
/* Define the SHA-224 digest for an empty string */
|
/* Define the SHA-224 digest for an empty string */
|
||||||
/* as a constant byte array */
|
/* as a constant byte array */
|
||||||
@ -265,8 +275,10 @@
|
|||||||
#endif /* WOLFSSL_SHA224 */
|
#endif /* WOLFSSL_SHA224 */
|
||||||
|
|
||||||
#if !defined(NO_SHA256)
|
#if !defined(NO_SHA256)
|
||||||
|
#ifndef MAX3266X_SHA_CB
|
||||||
typedef wc_MXC_Sha wc_Sha256;
|
typedef wc_MXC_Sha wc_Sha256;
|
||||||
#define WC_SHA256_TYPE_DEFINED
|
#define WC_SHA256_TYPE_DEFINED
|
||||||
|
#endif /* !MAX3266X_SHA_CB */
|
||||||
|
|
||||||
/* Define the SHA-256 digest for an empty string */
|
/* Define the SHA-256 digest for an empty string */
|
||||||
/* as a constant byte array */
|
/* as a constant byte array */
|
||||||
@ -278,8 +290,10 @@
|
|||||||
#endif /* NO_SHA256 */
|
#endif /* NO_SHA256 */
|
||||||
|
|
||||||
#if defined(WOLFSSL_SHA384)
|
#if defined(WOLFSSL_SHA384)
|
||||||
|
#ifndef MAX3266X_SHA_CB
|
||||||
typedef wc_MXC_Sha wc_Sha384;
|
typedef wc_MXC_Sha wc_Sha384;
|
||||||
#define WC_SHA384_TYPE_DEFINED
|
#define WC_SHA384_TYPE_DEFINED
|
||||||
|
#endif /* !MAX3266X_SHA_CB */
|
||||||
|
|
||||||
/* Define the SHA-384 digest for an empty string */
|
/* Define the SHA-384 digest for an empty string */
|
||||||
/* as a constant byte array */
|
/* as a constant byte array */
|
||||||
@ -293,10 +307,12 @@
|
|||||||
#endif /* WOLFSSL_SHA384 */
|
#endif /* WOLFSSL_SHA384 */
|
||||||
|
|
||||||
#if defined(WOLFSSL_SHA512)
|
#if defined(WOLFSSL_SHA512)
|
||||||
|
#ifndef MAX3266X_SHA_CB
|
||||||
typedef wc_MXC_Sha wc_Sha512;
|
typedef wc_MXC_Sha wc_Sha512;
|
||||||
typedef wc_MXC_Sha wc_Sha512_224;
|
typedef wc_MXC_Sha wc_Sha512_224;
|
||||||
typedef wc_MXC_Sha wc_Sha512_256;
|
typedef wc_MXC_Sha wc_Sha512_256;
|
||||||
#define WC_SHA512_TYPE_DEFINED
|
#define WC_SHA512_TYPE_DEFINED
|
||||||
|
#endif /* !MAX3266X_SHA_CB */
|
||||||
|
|
||||||
/* Does not support these SHA512 Macros */
|
/* Does not support these SHA512 Macros */
|
||||||
#ifndef WOLFSSL_NOSHA512_224
|
#ifndef WOLFSSL_NOSHA512_224
|
||||||
@ -339,7 +355,7 @@
|
|||||||
MXC_TPU_HASH_TYPE algo);
|
MXC_TPU_HASH_TYPE algo);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif /* defined(MAX3266X_SHA) && !defined(WOLF_CRYPTO_CB) */
|
||||||
|
|
||||||
#if defined(MAX3266X_MATH)
|
#if defined(MAX3266X_MATH)
|
||||||
#define WOLFSSL_USE_HW_MP
|
#define WOLFSSL_USE_HW_MP
|
||||||
@ -369,4 +385,4 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* WOLFSSL_MAX32665 || WOLFSSL_MAX32666 */
|
#endif /* WOLFSSL_MAX32665 || WOLFSSL_MAX32666 */
|
||||||
#endif /* _WOLFPORT_MAX3266X_H_ */
|
#endif /* _WOLFPORT_MAX3266X_H_ */
|
||||||
|
@ -163,6 +163,9 @@ struct wc_Sha {
|
|||||||
int devId;
|
int devId;
|
||||||
void* devCtx; /* generic crypto callback context */
|
void* devCtx; /* generic crypto callback context */
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
wc_MXC_Sha mxcCtx;
|
||||||
|
#endif
|
||||||
#ifdef WOLFSSL_IMXRT1170_CAAM
|
#ifdef WOLFSSL_IMXRT1170_CAAM
|
||||||
caam_hash_ctx_t ctx;
|
caam_hash_ctx_t ctx;
|
||||||
caam_handle_t hndl;
|
caam_handle_t hndl;
|
||||||
|
@ -213,6 +213,9 @@ struct wc_Sha256 {
|
|||||||
#ifdef WOLFSSL_DEVCRYPTO_HASH
|
#ifdef WOLFSSL_DEVCRYPTO_HASH
|
||||||
WC_CRYPTODEV ctx;
|
WC_CRYPTODEV ctx;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
wc_MXC_Sha mxcCtx;
|
||||||
|
#endif
|
||||||
#if defined(WOLFSSL_DEVCRYPTO_HASH) || defined(WOLFSSL_HASH_KEEP)
|
#if defined(WOLFSSL_DEVCRYPTO_HASH) || defined(WOLFSSL_HASH_KEEP)
|
||||||
byte* msg;
|
byte* msg;
|
||||||
word32 used;
|
word32 used;
|
||||||
|
@ -188,6 +188,9 @@ struct wc_Sha512 {
|
|||||||
int devId;
|
int devId;
|
||||||
void* devCtx; /* generic crypto callback context */
|
void* devCtx; /* generic crypto callback context */
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MAX3266X_SHA_CB
|
||||||
|
wc_MXC_Sha mxcCtx;
|
||||||
|
#endif
|
||||||
#ifdef WOLFSSL_HASH_FLAGS
|
#ifdef WOLFSSL_HASH_FLAGS
|
||||||
word32 flags; /* enum wc_HashFlags in hash.h */
|
word32 flags; /* enum wc_HashFlags in hash.h */
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user