mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-01-27 18:42:21 +01:00
Merge pull request #2070 from dgarske/fix_cryptocb
Fixes and improvements to Crypto Callbacks and STM32 RNG performance
This commit is contained in:
@@ -6528,6 +6528,7 @@ int wc_AesInit(Aes* aes, void* heap, int devId)
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
aes->devId = devId;
|
||||
aes->devCtx = NULL;
|
||||
#else
|
||||
(void)devId;
|
||||
#endif
|
||||
@@ -6589,6 +6590,9 @@ void wc_AesFree(Aes* aes)
|
||||
#if defined(WOLFSSL_DEVCRYPTO) && \
|
||||
(defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_DEVCRYPTO_CBC))
|
||||
wc_DevCryptoFree(&aes->ctx);
|
||||
#endif
|
||||
#if defined(WOLF_CRYPTO_CB) || (defined(WOLFSSL_DEVCRYPTO) && \
|
||||
(defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_DEVCRYPTO_CBC)))
|
||||
ForceZero((byte*)aes->devKey, AES_MAX_KEY_SIZE/WOLFSSL_BIT_SIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -102,6 +102,10 @@ ASN Options:
|
||||
#include <wolfssl/wolfcrypt/rsa.h>
|
||||
#endif
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
#include <wolfssl/wolfcrypt/cryptocb.h>
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_DEBUG_ENCODING
|
||||
#if defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
|
||||
#if MQX_USE_IO_OLD
|
||||
@@ -4545,6 +4549,28 @@ WOLFSSL_LOCAL int OBJ_sn2nid(const char *sn)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Routine for calculating hashId */
|
||||
int CalcHashId(const byte* data, word32 len, byte* hash)
|
||||
{
|
||||
int ret = NOT_COMPILED_IN;
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
/* try to use a registered crypto callback */
|
||||
ret = wc_CryptoCb_Sha256Hash(NULL, data, len, hash);
|
||||
if (ret != NOT_COMPILED_IN)
|
||||
return ret;
|
||||
/* for not compiled in case, use software method below */
|
||||
#endif
|
||||
|
||||
#if defined(NO_SHA) && !defined(NO_SHA256)
|
||||
ret = wc_Sha256Hash(data, len, hash);
|
||||
#elif !defined(NO_SHA)
|
||||
ret = wc_ShaHash(data, len, hash);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* process NAME, either issuer or subject */
|
||||
static int GetName(DecodedCert* cert, int nameType)
|
||||
{
|
||||
|
||||
@@ -55,6 +55,15 @@ static CryptoCb* wc_CryptoCb_FindDevice(int devId)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
static CryptoCb* wc_CryptoCb_FindDeviceByIndex(int startIdx)
|
||||
{
|
||||
int i;
|
||||
for (i=startIdx; i<MAX_CRYPTO_DEVID_CALLBACKS; i++) {
|
||||
if (gCryptoDev[i].devId != INVALID_DEVID)
|
||||
return &gCryptoDev[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void wc_CryptoCb_Init(void)
|
||||
{
|
||||
@@ -97,24 +106,25 @@ int wc_CryptoCb_Rsa(const byte* in, word32 inLen, byte* out,
|
||||
int ret = NOT_COMPILED_IN;
|
||||
CryptoCb* dev;
|
||||
|
||||
if (key == NULL)
|
||||
return ret;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(key->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_RSA;
|
||||
cryptoInfo.pk.rsa.in = in;
|
||||
cryptoInfo.pk.rsa.inLen = inLen;
|
||||
cryptoInfo.pk.rsa.out = out;
|
||||
cryptoInfo.pk.rsa.outLen = outLen;
|
||||
cryptoInfo.pk.rsa.type = type;
|
||||
cryptoInfo.pk.rsa.key = key;
|
||||
cryptoInfo.pk.rsa.rng = rng;
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_RSA;
|
||||
cryptoInfo.pk.rsa.in = in;
|
||||
cryptoInfo.pk.rsa.inLen = inLen;
|
||||
cryptoInfo.pk.rsa.out = out;
|
||||
cryptoInfo.pk.rsa.outLen = outLen;
|
||||
cryptoInfo.pk.rsa.type = type;
|
||||
cryptoInfo.pk.rsa.key = key;
|
||||
cryptoInfo.pk.rsa.rng = rng;
|
||||
|
||||
ret = dev->cb(key->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -126,21 +136,22 @@ int wc_CryptoCb_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
|
||||
int ret = NOT_COMPILED_IN;
|
||||
CryptoCb* dev;
|
||||
|
||||
if (key == NULL)
|
||||
return ret;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(key->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_RSA_KEYGEN;
|
||||
cryptoInfo.pk.rsakg.key = key;
|
||||
cryptoInfo.pk.rsakg.size = size;
|
||||
cryptoInfo.pk.rsakg.e = e;
|
||||
cryptoInfo.pk.rsakg.rng = rng;
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_RSA_KEYGEN;
|
||||
cryptoInfo.pk.rsakg.key = key;
|
||||
cryptoInfo.pk.rsakg.size = size;
|
||||
cryptoInfo.pk.rsakg.e = e;
|
||||
cryptoInfo.pk.rsakg.rng = rng;
|
||||
|
||||
ret = dev->cb(key->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -154,21 +165,22 @@ int wc_CryptoCb_MakeEccKey(WC_RNG* rng, int keySize, ecc_key* key, int curveId)
|
||||
int ret = NOT_COMPILED_IN;
|
||||
CryptoCb* dev;
|
||||
|
||||
if (key == NULL)
|
||||
return ret;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(key->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_EC_KEYGEN;
|
||||
cryptoInfo.pk.eckg.rng = rng;
|
||||
cryptoInfo.pk.eckg.size = keySize;
|
||||
cryptoInfo.pk.eckg.key = key;
|
||||
cryptoInfo.pk.eckg.curveId = curveId;
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_EC_KEYGEN;
|
||||
cryptoInfo.pk.eckg.rng = rng;
|
||||
cryptoInfo.pk.eckg.size = keySize;
|
||||
cryptoInfo.pk.eckg.key = key;
|
||||
cryptoInfo.pk.eckg.curveId = curveId;
|
||||
|
||||
ret = dev->cb(key->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -180,21 +192,22 @@ int wc_CryptoCb_Ecdh(ecc_key* private_key, ecc_key* public_key,
|
||||
int ret = NOT_COMPILED_IN;
|
||||
CryptoCb* dev;
|
||||
|
||||
if (private_key == NULL)
|
||||
return ret;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(private_key->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_ECDH;
|
||||
cryptoInfo.pk.ecdh.private_key = private_key;
|
||||
cryptoInfo.pk.ecdh.public_key = public_key;
|
||||
cryptoInfo.pk.ecdh.out = out;
|
||||
cryptoInfo.pk.ecdh.outlen = outlen;
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_ECDH;
|
||||
cryptoInfo.pk.ecdh.private_key = private_key;
|
||||
cryptoInfo.pk.ecdh.public_key = public_key;
|
||||
cryptoInfo.pk.ecdh.out = out;
|
||||
cryptoInfo.pk.ecdh.outlen = outlen;
|
||||
|
||||
ret = dev->cb(private_key->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -206,23 +219,24 @@ int wc_CryptoCb_EccSign(const byte* in, word32 inlen, byte* out,
|
||||
int ret = NOT_COMPILED_IN;
|
||||
CryptoCb* dev;
|
||||
|
||||
if (key == NULL)
|
||||
return ret;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(key->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_ECDSA_SIGN;
|
||||
cryptoInfo.pk.eccsign.in = in;
|
||||
cryptoInfo.pk.eccsign.inlen = inlen;
|
||||
cryptoInfo.pk.eccsign.out = out;
|
||||
cryptoInfo.pk.eccsign.outlen = outlen;
|
||||
cryptoInfo.pk.eccsign.rng = rng;
|
||||
cryptoInfo.pk.eccsign.key = key;
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_ECDSA_SIGN;
|
||||
cryptoInfo.pk.eccsign.in = in;
|
||||
cryptoInfo.pk.eccsign.inlen = inlen;
|
||||
cryptoInfo.pk.eccsign.out = out;
|
||||
cryptoInfo.pk.eccsign.outlen = outlen;
|
||||
cryptoInfo.pk.eccsign.rng = rng;
|
||||
cryptoInfo.pk.eccsign.key = key;
|
||||
|
||||
ret = dev->cb(key->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -234,23 +248,24 @@ int wc_CryptoCb_EccVerify(const byte* sig, word32 siglen,
|
||||
int ret = NOT_COMPILED_IN;
|
||||
CryptoCb* dev;
|
||||
|
||||
if (key == NULL)
|
||||
return ret;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(key->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_ECDSA_VERIFY;
|
||||
cryptoInfo.pk.eccverify.sig = sig;
|
||||
cryptoInfo.pk.eccverify.siglen = siglen;
|
||||
cryptoInfo.pk.eccverify.hash = hash;
|
||||
cryptoInfo.pk.eccverify.hashlen = hashlen;
|
||||
cryptoInfo.pk.eccverify.res = res;
|
||||
cryptoInfo.pk.eccverify.key = key;
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_PK;
|
||||
cryptoInfo.pk.type = WC_PK_TYPE_ECDSA_VERIFY;
|
||||
cryptoInfo.pk.eccverify.sig = sig;
|
||||
cryptoInfo.pk.eccverify.siglen = siglen;
|
||||
cryptoInfo.pk.eccverify.hash = hash;
|
||||
cryptoInfo.pk.eccverify.hashlen = hashlen;
|
||||
cryptoInfo.pk.eccverify.res = res;
|
||||
cryptoInfo.pk.eccverify.key = key;
|
||||
|
||||
ret = dev->cb(key->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -269,27 +284,32 @@ int wc_CryptoCb_AesGcmEncrypt(Aes* aes, byte* out,
|
||||
CryptoCb* dev;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(aes->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_CIPHER;
|
||||
cryptoInfo.cipher.type = WC_CIPHER_AES_GCM;
|
||||
cryptoInfo.cipher.enc = 1;
|
||||
cryptoInfo.cipher.aesgcm_enc.aes = aes;
|
||||
cryptoInfo.cipher.aesgcm_enc.out = out;
|
||||
cryptoInfo.cipher.aesgcm_enc.in = in;
|
||||
cryptoInfo.cipher.aesgcm_enc.sz = sz;
|
||||
cryptoInfo.cipher.aesgcm_enc.iv = iv;
|
||||
cryptoInfo.cipher.aesgcm_enc.ivSz = ivSz;
|
||||
cryptoInfo.cipher.aesgcm_enc.authTag = authTag;
|
||||
cryptoInfo.cipher.aesgcm_enc.authTagSz = authTagSz;
|
||||
cryptoInfo.cipher.aesgcm_enc.authIn = authIn;
|
||||
cryptoInfo.cipher.aesgcm_enc.authInSz = authInSz;
|
||||
if (aes) {
|
||||
dev = wc_CryptoCb_FindDevice(aes->devId);
|
||||
}
|
||||
else {
|
||||
/* locate first callback and try using it */
|
||||
dev = wc_CryptoCb_FindDeviceByIndex(0);
|
||||
}
|
||||
|
||||
ret = dev->cb(aes->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_CIPHER;
|
||||
cryptoInfo.cipher.type = WC_CIPHER_AES_GCM;
|
||||
cryptoInfo.cipher.enc = 1;
|
||||
cryptoInfo.cipher.aesgcm_enc.aes = aes;
|
||||
cryptoInfo.cipher.aesgcm_enc.out = out;
|
||||
cryptoInfo.cipher.aesgcm_enc.in = in;
|
||||
cryptoInfo.cipher.aesgcm_enc.sz = sz;
|
||||
cryptoInfo.cipher.aesgcm_enc.iv = iv;
|
||||
cryptoInfo.cipher.aesgcm_enc.ivSz = ivSz;
|
||||
cryptoInfo.cipher.aesgcm_enc.authTag = authTag;
|
||||
cryptoInfo.cipher.aesgcm_enc.authTagSz = authTagSz;
|
||||
cryptoInfo.cipher.aesgcm_enc.authIn = authIn;
|
||||
cryptoInfo.cipher.aesgcm_enc.authInSz = authInSz;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -305,27 +325,32 @@ int wc_CryptoCb_AesGcmDecrypt(Aes* aes, byte* out,
|
||||
CryptoCb* dev;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(aes->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_CIPHER;
|
||||
cryptoInfo.cipher.type = WC_CIPHER_AES_GCM;
|
||||
cryptoInfo.cipher.enc = 0;
|
||||
cryptoInfo.cipher.aesgcm_dec.aes = aes;
|
||||
cryptoInfo.cipher.aesgcm_dec.out = out;
|
||||
cryptoInfo.cipher.aesgcm_dec.in = in;
|
||||
cryptoInfo.cipher.aesgcm_dec.sz = sz;
|
||||
cryptoInfo.cipher.aesgcm_dec.iv = iv;
|
||||
cryptoInfo.cipher.aesgcm_dec.ivSz = ivSz;
|
||||
cryptoInfo.cipher.aesgcm_dec.authTag = authTag;
|
||||
cryptoInfo.cipher.aesgcm_dec.authTagSz = authTagSz;
|
||||
cryptoInfo.cipher.aesgcm_dec.authIn = authIn;
|
||||
cryptoInfo.cipher.aesgcm_dec.authInSz = authInSz;
|
||||
if (aes) {
|
||||
dev = wc_CryptoCb_FindDevice(aes->devId);
|
||||
}
|
||||
else {
|
||||
/* locate first callback and try using it */
|
||||
dev = wc_CryptoCb_FindDeviceByIndex(0);
|
||||
}
|
||||
|
||||
ret = dev->cb(aes->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_CIPHER;
|
||||
cryptoInfo.cipher.type = WC_CIPHER_AES_GCM;
|
||||
cryptoInfo.cipher.enc = 0;
|
||||
cryptoInfo.cipher.aesgcm_dec.aes = aes;
|
||||
cryptoInfo.cipher.aesgcm_dec.out = out;
|
||||
cryptoInfo.cipher.aesgcm_dec.in = in;
|
||||
cryptoInfo.cipher.aesgcm_dec.sz = sz;
|
||||
cryptoInfo.cipher.aesgcm_dec.iv = iv;
|
||||
cryptoInfo.cipher.aesgcm_dec.ivSz = ivSz;
|
||||
cryptoInfo.cipher.aesgcm_dec.authTag = authTag;
|
||||
cryptoInfo.cipher.aesgcm_dec.authTagSz = authTagSz;
|
||||
cryptoInfo.cipher.aesgcm_dec.authIn = authIn;
|
||||
cryptoInfo.cipher.aesgcm_dec.authInSz = authInSz;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -340,21 +365,27 @@ int wc_CryptoCb_AesCbcEncrypt(Aes* aes, byte* out,
|
||||
CryptoCb* dev;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(aes->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_CIPHER;
|
||||
cryptoInfo.cipher.type = WC_CIPHER_AES_CBC;
|
||||
cryptoInfo.cipher.enc = 1;
|
||||
cryptoInfo.cipher.aescbc.aes = aes;
|
||||
cryptoInfo.cipher.aescbc.out = out;
|
||||
cryptoInfo.cipher.aescbc.in = in;
|
||||
cryptoInfo.cipher.aescbc.sz = sz;
|
||||
if (aes) {
|
||||
dev = wc_CryptoCb_FindDevice(aes->devId);
|
||||
}
|
||||
else {
|
||||
/* locate first callback and try using it */
|
||||
dev = wc_CryptoCb_FindDeviceByIndex(0);
|
||||
}
|
||||
|
||||
ret = dev->cb(aes->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
dev = wc_CryptoCb_FindDevice(aes->devId);
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_CIPHER;
|
||||
cryptoInfo.cipher.type = WC_CIPHER_AES_CBC;
|
||||
cryptoInfo.cipher.enc = 1;
|
||||
cryptoInfo.cipher.aescbc.aes = aes;
|
||||
cryptoInfo.cipher.aescbc.out = out;
|
||||
cryptoInfo.cipher.aescbc.in = in;
|
||||
cryptoInfo.cipher.aescbc.sz = sz;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -367,21 +398,26 @@ int wc_CryptoCb_AesCbcDecrypt(Aes* aes, byte* out,
|
||||
CryptoCb* dev;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(aes->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_CIPHER;
|
||||
cryptoInfo.cipher.type = WC_CIPHER_AES_CBC;
|
||||
cryptoInfo.cipher.enc = 0;
|
||||
cryptoInfo.cipher.aescbc.aes = aes;
|
||||
cryptoInfo.cipher.aescbc.out = out;
|
||||
cryptoInfo.cipher.aescbc.in = in;
|
||||
cryptoInfo.cipher.aescbc.sz = sz;
|
||||
if (aes) {
|
||||
dev = wc_CryptoCb_FindDevice(aes->devId);
|
||||
}
|
||||
else {
|
||||
/* locate first callback and try using it */
|
||||
dev = wc_CryptoCb_FindDeviceByIndex(0);
|
||||
}
|
||||
|
||||
ret = dev->cb(aes->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_CIPHER;
|
||||
cryptoInfo.cipher.type = WC_CIPHER_AES_CBC;
|
||||
cryptoInfo.cipher.enc = 0;
|
||||
cryptoInfo.cipher.aescbc.aes = aes;
|
||||
cryptoInfo.cipher.aescbc.out = out;
|
||||
cryptoInfo.cipher.aescbc.in = in;
|
||||
cryptoInfo.cipher.aescbc.sz = sz;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -397,20 +433,25 @@ int wc_CryptoCb_ShaHash(wc_Sha* sha, const byte* in,
|
||||
CryptoCb* dev;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(sha->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_HASH;
|
||||
cryptoInfo.hash.type = WC_HASH_TYPE_SHA;
|
||||
cryptoInfo.hash.sha1 = sha;
|
||||
cryptoInfo.hash.in = in;
|
||||
cryptoInfo.hash.inSz = inSz;
|
||||
cryptoInfo.hash.digest = digest;
|
||||
if (sha) {
|
||||
dev = wc_CryptoCb_FindDevice(sha->devId);
|
||||
}
|
||||
else {
|
||||
/* locate first callback and try using it */
|
||||
dev = wc_CryptoCb_FindDeviceByIndex(0);
|
||||
}
|
||||
|
||||
ret = dev->cb(sha->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_HASH;
|
||||
cryptoInfo.hash.type = WC_HASH_TYPE_SHA;
|
||||
cryptoInfo.hash.sha1 = sha;
|
||||
cryptoInfo.hash.in = in;
|
||||
cryptoInfo.hash.inSz = inSz;
|
||||
cryptoInfo.hash.digest = digest;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -425,26 +466,60 @@ int wc_CryptoCb_Sha256Hash(wc_Sha256* sha256, const byte* in,
|
||||
CryptoCb* dev;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(sha256->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_HASH;
|
||||
cryptoInfo.hash.type = WC_HASH_TYPE_SHA256;
|
||||
cryptoInfo.hash.sha256 = sha256;
|
||||
cryptoInfo.hash.in = in;
|
||||
cryptoInfo.hash.inSz = inSz;
|
||||
cryptoInfo.hash.digest = digest;
|
||||
if (sha256) {
|
||||
dev = wc_CryptoCb_FindDevice(sha256->devId);
|
||||
}
|
||||
else {
|
||||
/* locate first callback and try using it */
|
||||
dev = wc_CryptoCb_FindDeviceByIndex(0);
|
||||
}
|
||||
|
||||
ret = dev->cb(sha256->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_HASH;
|
||||
cryptoInfo.hash.type = WC_HASH_TYPE_SHA256;
|
||||
cryptoInfo.hash.sha256 = sha256;
|
||||
cryptoInfo.hash.in = in;
|
||||
cryptoInfo.hash.inSz = inSz;
|
||||
cryptoInfo.hash.digest = digest;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* !NO_SHA256 */
|
||||
|
||||
#ifndef NO_HMAC
|
||||
int wc_CryptoCb_Hmac(Hmac* hmac, int macType, const byte* in, word32 inSz,
|
||||
byte* digest)
|
||||
{
|
||||
int ret = NOT_COMPILED_IN;
|
||||
CryptoCb* dev;
|
||||
|
||||
if (hmac == NULL)
|
||||
return ret;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(hmac->devId);
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_HMAC;
|
||||
cryptoInfo.hmac.macType = macType;
|
||||
cryptoInfo.hmac.in = in;
|
||||
cryptoInfo.hmac.inSz = inSz;
|
||||
cryptoInfo.hmac.digest = digest;
|
||||
cryptoInfo.hmac.hmac = hmac;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* !NO_HMAC */
|
||||
|
||||
#ifndef WC_NO_RNG
|
||||
int wc_CryptoCb_RandomBlock(WC_RNG* rng, byte* out, word32 sz)
|
||||
{
|
||||
@@ -452,18 +527,23 @@ int wc_CryptoCb_RandomBlock(WC_RNG* rng, byte* out, word32 sz)
|
||||
CryptoCb* dev;
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(rng->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_RNG;
|
||||
cryptoInfo.rng.rng = rng;
|
||||
cryptoInfo.rng.out = out;
|
||||
cryptoInfo.rng.sz = sz;
|
||||
if (rng) {
|
||||
dev = wc_CryptoCb_FindDevice(rng->devId);
|
||||
}
|
||||
else {
|
||||
/* locate first callback and try using it */
|
||||
dev = wc_CryptoCb_FindDeviceByIndex(0);
|
||||
}
|
||||
|
||||
ret = dev->cb(rng->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_RNG;
|
||||
cryptoInfo.rng.rng = rng;
|
||||
cryptoInfo.rng.out = out;
|
||||
cryptoInfo.rng.sz = sz;
|
||||
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -476,17 +556,15 @@ int wc_CryptoCb_RandomSeed(OS_Seed* os, byte* seed, word32 sz)
|
||||
|
||||
/* locate registered callback */
|
||||
dev = wc_CryptoCb_FindDevice(os->devId);
|
||||
if (dev) {
|
||||
if (dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_SEED;
|
||||
cryptoInfo.seed.os = os;
|
||||
cryptoInfo.seed.seed = seed;
|
||||
cryptoInfo.seed.sz = sz;
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
cryptoInfo.algo_type = WC_ALGO_TYPE_SEED;
|
||||
cryptoInfo.seed.os = os;
|
||||
cryptoInfo.seed.seed = seed;
|
||||
cryptoInfo.seed.sz = sz;
|
||||
|
||||
ret = dev->cb(os->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -691,6 +691,119 @@ int wc_HashFree(wc_HashAlg* hash, enum wc_HashType type)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
int wc_HashSetFlags(wc_HashAlg* hash, enum wc_HashType type, word32 flags)
|
||||
{
|
||||
int ret = HASH_TYPE_E; /* Default to hash type error */
|
||||
|
||||
if (hash == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
switch (type) {
|
||||
case WC_HASH_TYPE_MD5:
|
||||
#ifndef NO_MD5
|
||||
ret = wc_Md5SetFlags(&hash->md5, flags);
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA:
|
||||
#ifndef NO_SHA
|
||||
ret = wc_ShaSetFlags(&hash->sha, flags);
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA224:
|
||||
#ifdef WOLFSSL_SHA224
|
||||
ret = wc_Sha224SetFlags(&hash->sha224, flags);
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA256:
|
||||
#ifndef NO_SHA256
|
||||
ret = wc_Sha256SetFlags(&hash->sha256, flags);
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA384:
|
||||
#ifdef WOLFSSL_SHA384
|
||||
ret = wc_Sha384SetFlags(&hash->sha384, flags);
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA512:
|
||||
#ifdef WOLFSSL_SHA512
|
||||
ret = wc_Sha512SetFlags(&hash->sha512, flags);
|
||||
#endif
|
||||
break;
|
||||
|
||||
/* not supported */
|
||||
case WC_HASH_TYPE_MD5_SHA:
|
||||
case WC_HASH_TYPE_MD2:
|
||||
case WC_HASH_TYPE_MD4:
|
||||
case WC_HASH_TYPE_SHA3_224:
|
||||
case WC_HASH_TYPE_SHA3_256:
|
||||
case WC_HASH_TYPE_SHA3_384:
|
||||
case WC_HASH_TYPE_SHA3_512:
|
||||
case WC_HASH_TYPE_BLAKE2B:
|
||||
case WC_HASH_TYPE_NONE:
|
||||
default:
|
||||
ret = BAD_FUNC_ARG;
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
|
||||
{
|
||||
int ret = HASH_TYPE_E; /* Default to hash type error */
|
||||
|
||||
if (hash == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
switch (type) {
|
||||
case WC_HASH_TYPE_MD5:
|
||||
#ifndef NO_MD5
|
||||
ret = wc_Md5GetFlags(&hash->md5, flags);
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA:
|
||||
#ifndef NO_SHA
|
||||
ret = wc_ShaGetFlags(&hash->sha, flags);
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA224:
|
||||
#ifdef WOLFSSL_SHA224
|
||||
ret = wc_Sha224GetFlags(&hash->sha224, flags);
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA256:
|
||||
#ifndef NO_SHA256
|
||||
ret = wc_Sha256GetFlags(&hash->sha256, flags);
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA384:
|
||||
#ifdef WOLFSSL_SHA384
|
||||
ret = wc_Sha384GetFlags(&hash->sha384, flags);
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA512:
|
||||
#ifdef WOLFSSL_SHA512
|
||||
ret = wc_Sha512GetFlags(&hash->sha512, flags);
|
||||
#endif
|
||||
break;
|
||||
|
||||
/* not supported */
|
||||
case WC_HASH_TYPE_MD5_SHA:
|
||||
case WC_HASH_TYPE_MD2:
|
||||
case WC_HASH_TYPE_MD4:
|
||||
case WC_HASH_TYPE_SHA3_224:
|
||||
case WC_HASH_TYPE_SHA3_256:
|
||||
case WC_HASH_TYPE_SHA3_384:
|
||||
case WC_HASH_TYPE_SHA3_512:
|
||||
case WC_HASH_TYPE_BLAKE2B:
|
||||
case WC_HASH_TYPE_NONE:
|
||||
default:
|
||||
ret = BAD_FUNC_ARG;
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(WOLFSSL_TI_HASH)
|
||||
|
||||
|
||||
@@ -43,6 +43,10 @@
|
||||
|
||||
#include <wolfssl/wolfcrypt/hmac.h>
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
#include <wolfssl/wolfcrypt/cryptocb.h>
|
||||
#endif
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
@@ -321,6 +325,11 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
return HMAC_MIN_KEYLEN_E;
|
||||
#endif
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
hmac->keyRaw = key; /* use buffer directly */
|
||||
hmac->keyLen = length;
|
||||
#endif
|
||||
|
||||
ip = (byte*)hmac->ipad;
|
||||
op = (byte*)hmac->opad;
|
||||
|
||||
@@ -691,6 +700,15 @@ int wc_HmacUpdate(Hmac* hmac, const byte* msg, word32 length)
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
if (hmac->devId != INVALID_DEVID) {
|
||||
ret = wc_CryptoCb_Hmac(hmac, hmac->macType, msg, length, NULL);
|
||||
if (ret != NOT_COMPILED_IN)
|
||||
return ret;
|
||||
/* fall-through on not compiled in */
|
||||
ret = 0; /* reset error code */
|
||||
}
|
||||
#endif
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC)
|
||||
if (hmac->asyncDev.marker == WOLFSSL_ASYNC_MARKER_HMAC) {
|
||||
#if defined(HAVE_CAVIUM)
|
||||
@@ -791,6 +809,15 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
if (hmac->devId != INVALID_DEVID) {
|
||||
ret = wc_CryptoCb_Hmac(hmac, hmac->macType, NULL, 0, hash);
|
||||
if (ret != NOT_COMPILED_IN)
|
||||
return ret;
|
||||
/* fall-through on not compiled in */
|
||||
ret = 0; /* reset error code */
|
||||
}
|
||||
#endif
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC)
|
||||
if (hmac->asyncDev.marker == WOLFSSL_ASYNC_MARKER_HMAC) {
|
||||
int hashLen = wc_HmacSizeByType(hmac->macType);
|
||||
@@ -1028,10 +1055,12 @@ int wc_HmacInit(Hmac* hmac, void* heap, int devId)
|
||||
|
||||
XMEMSET(hmac, 0, sizeof(Hmac));
|
||||
hmac->heap = heap;
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
hmac->devId = devId;
|
||||
hmac->devCtx = NULL;
|
||||
#endif
|
||||
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC)
|
||||
hmac->keyLen = 0;
|
||||
|
||||
ret = wolfAsync_DevCtxInit(&hmac->asyncDev, WOLFSSL_ASYNC_MARKER_HMAC,
|
||||
hmac->heap, devId);
|
||||
#else
|
||||
@@ -1047,6 +1076,17 @@ void wc_HmacFree(Hmac* hmac)
|
||||
if (hmac == NULL)
|
||||
return;
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
/* handle cleanup case where final is not called */
|
||||
if (hmac->devId != INVALID_DEVID && hmac->devCtx != NULL) {
|
||||
int ret;
|
||||
byte finalHash[WC_HMAC_BLOCK_SIZE];
|
||||
ret = wc_CryptoCb_Hmac(hmac, hmac->macType, NULL, 0, finalHash);
|
||||
(void)ret; /* must ignore return code here */
|
||||
(void)finalHash;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (hmac->macType) {
|
||||
#ifndef NO_MD5
|
||||
case WC_MD5:
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <wolfssl/wolfcrypt/md5.h>
|
||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||
#include <wolfssl/wolfcrypt/logging.h>
|
||||
#include <wolfssl/wolfcrypt/hash.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
@@ -50,7 +51,7 @@
|
||||
#if defined(STM32_HASH)
|
||||
|
||||
/* Supports CubeMX HAL or Standard Peripheral Library */
|
||||
#define HAVE_MD5_CUST_API
|
||||
#define HAVE_MD5_CUST_API
|
||||
|
||||
int wc_InitMd5_ex(wc_Md5* md5, void* heap, int devId)
|
||||
{
|
||||
@@ -436,9 +437,29 @@ int wc_Md5Copy(wc_Md5* src, wc_Md5* dst)
|
||||
#ifdef WOLFSSL_PIC32MZ_HASH
|
||||
ret = wc_Pic32HashCopy(&src->cache, &dst->cache);
|
||||
#endif
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
int wc_Md5SetFlags(wc_Md5* md5, word32 flags)
|
||||
{
|
||||
if (md5) {
|
||||
md5->flags = flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int wc_Md5GetFlags(wc_Md5* md5, word32* flags)
|
||||
{
|
||||
if (md5 && flags) {
|
||||
*flags = md5->flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WOLFSSL_TI_HASH */
|
||||
#endif /* NO_MD5 */
|
||||
|
||||
45
wolfcrypt/src/random.c
Executable file → Normal file
45
wolfcrypt/src/random.c
Executable file → Normal file
@@ -1741,30 +1741,47 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
|
||||
#elif defined(STM32_RNG)
|
||||
/* Generate a RNG seed using the hardware random number generator
|
||||
* on the STM32F2/F4/F7. */
|
||||
* on the STM32F2/F4/F7/L4. */
|
||||
|
||||
#ifdef WOLFSSL_STM32_CUBEMX
|
||||
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
{
|
||||
RNG_HandleTypeDef hrng;
|
||||
int i;
|
||||
word32 i = 0;
|
||||
(void)os;
|
||||
|
||||
/* enable RNG clock source */
|
||||
__HAL_RCC_RNG_CLK_ENABLE();
|
||||
|
||||
/* enable RNG peripheral */
|
||||
XMEMSET(&hrng, 0, sizeof(hrng));
|
||||
hrng.Instance = RNG;
|
||||
HAL_RNG_Init(&hrng);
|
||||
|
||||
for (i = 0; i < (int)sz; i++) {
|
||||
/* get value */
|
||||
output[i] = (byte)HAL_RNG_GetRandomNumber(&hrng);
|
||||
}
|
||||
while (i < sz) {
|
||||
/* If not aligned or there is odd/remainder */
|
||||
if( (i + sizeof(word32)) > sz ||
|
||||
((wolfssl_word)&output[i] % sizeof(word32)) != 0
|
||||
) {
|
||||
/* Single byte at a time */
|
||||
uint32_t tmpRng = 0;
|
||||
if (HAL_RNG_GenerateRandomNumber(&hrng, &tmpRng) != HAL_OK) {
|
||||
return RAN_BLOCK_E;
|
||||
}
|
||||
output[i++] = (byte)tmpRng;
|
||||
}
|
||||
else {
|
||||
/* Use native 32 instruction */
|
||||
if (HAL_RNG_GenerateRandomNumber(&hrng, (uint32_t*)&output[i]) != HAL_OK) {
|
||||
return RAN_BLOCK_E;
|
||||
}
|
||||
i += sizeof(word32);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#elif defined(WOLFSSL_STM32F427_RNG)
|
||||
#elif defined(WOLFSSL_STM32F427_RNG) || defined(WOLFSSL_STM32_RNG_NOLIB)
|
||||
|
||||
/* Generate a RNG seed using the hardware RNG on the STM32F427
|
||||
* directly, following steps outlined in STM32F4 Reference
|
||||
@@ -2159,11 +2176,13 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
int ret = 0;
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
if (os != NULL && os->devId != INVALID_DEVID) {
|
||||
ret = wc_CryptoCb_RandomSeed(os, output, sz);
|
||||
if (ret != NOT_COMPILED_IN)
|
||||
return ret;
|
||||
}
|
||||
if (os != NULL && os->devId != INVALID_DEVID) {
|
||||
ret = wc_CryptoCb_RandomSeed(os, output, sz);
|
||||
if (ret != NOT_COMPILED_IN)
|
||||
return ret;
|
||||
/* fall-through on not compiled in */
|
||||
ret = 0; /* reset error code */
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_INTEL_RDSEED
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#include <wolfssl/wolfcrypt/sha.h>
|
||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||
#include <wolfssl/wolfcrypt/hash.h>
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
#include <wolfssl/wolfcrypt/cryptocb.h>
|
||||
@@ -713,8 +714,30 @@ int wc_ShaCopy(wc_Sha* src, wc_Sha* dst)
|
||||
dst->ctx.isfirstblock = src->ctx.isfirstblock;
|
||||
dst->ctx.sha_type = src->ctx.sha_type;
|
||||
#endif
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* !WOLFSSL_TI_HASH */
|
||||
|
||||
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
int wc_ShaSetFlags(wc_Sha* sha, word32 flags)
|
||||
{
|
||||
if (sha) {
|
||||
sha->flags = flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int wc_ShaGetFlags(wc_Sha* sha, word32* flags)
|
||||
{
|
||||
if (sha && flags) {
|
||||
*flags = sha->flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !NO_SHA */
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <wolfssl/wolfcrypt/sha256.h>
|
||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||
#include <wolfssl/wolfcrypt/cpuid.h>
|
||||
#include <wolfssl/wolfcrypt/hash.h>
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
#include <wolfssl/wolfcrypt/cryptocb.h>
|
||||
@@ -543,6 +544,7 @@ static int InitSha256(wc_Sha256* sha256)
|
||||
sha256->heap = heap;
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
sha256->devId = devId;
|
||||
sha256->devCtx = NULL;
|
||||
#endif
|
||||
|
||||
ret = InitSha256(sha256);
|
||||
@@ -1296,9 +1298,30 @@ void wc_Sha256Free(wc_Sha256* sha256)
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
ret = wolfAsync_DevCopy(&src->asyncDev, &dst->asyncDev);
|
||||
#endif
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
int wc_Sha224SetFlags(wc_Sha224* sha224, word32 flags)
|
||||
{
|
||||
if (sha224) {
|
||||
sha224->flags = flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int wc_Sha224GetFlags(wc_Sha224* sha224, word32* flags)
|
||||
{
|
||||
if (sha224 && flags) {
|
||||
*flags = sha224->flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
||||
#ifdef WOLFSSL_AFALG_HASH
|
||||
@@ -1362,9 +1385,30 @@ int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst)
|
||||
dst->ctx.isfirstblock = src->ctx.isfirstblock;
|
||||
dst->ctx.sha_type = src->ctx.sha_type;
|
||||
#endif
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
int wc_Sha256SetFlags(wc_Sha256* sha256, word32 flags)
|
||||
{
|
||||
if (sha256) {
|
||||
sha256->flags = flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int wc_Sha256GetFlags(wc_Sha256* sha256, word32* flags)
|
||||
{
|
||||
if (sha256 && flags) {
|
||||
*flags = sha256->flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* !WOLFSSL_TI_HASH */
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
|
||||
#include <wolfssl/wolfcrypt/sha3.h>
|
||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||
#include <wolfssl/wolfcrypt/hash.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
@@ -793,6 +794,9 @@ static int wc_Sha3Copy(wc_Sha3* src, wc_Sha3* dst)
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
ret = wolfAsync_DevCopy(&src->asyncDev, &dst->asyncDev);
|
||||
#endif
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -830,7 +834,7 @@ static int wc_Sha3GetHash(wc_Sha3* sha3, byte* hash, byte p, byte len)
|
||||
* devId Device identifier for asynchronous operation.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_InitSha3_224(wc_Sha3* sha3, void* heap, int devId)
|
||||
int wc_InitSha3_224(wc_Sha3* sha3, void* heap, int devId)
|
||||
{
|
||||
return wc_InitSha3(sha3, heap, devId);
|
||||
}
|
||||
@@ -842,7 +846,7 @@ WOLFSSL_API int wc_InitSha3_224(wc_Sha3* sha3, void* heap, int devId)
|
||||
* len Length of the message data.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_224_Update(wc_Sha3* sha3, const byte* data, word32 len)
|
||||
int wc_Sha3_224_Update(wc_Sha3* sha3, const byte* data, word32 len)
|
||||
{
|
||||
return wc_Sha3Update(sha3, data, len, WC_SHA3_224_COUNT);
|
||||
}
|
||||
@@ -854,7 +858,7 @@ WOLFSSL_API int wc_Sha3_224_Update(wc_Sha3* sha3, const byte* data, word32 len)
|
||||
* hash Buffer to hold the hash result. Must be at least 28 bytes.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_224_Final(wc_Sha3* sha3, byte* hash)
|
||||
int wc_Sha3_224_Final(wc_Sha3* sha3, byte* hash)
|
||||
{
|
||||
return wc_Sha3Final(sha3, hash, WC_SHA3_224_COUNT, WC_SHA3_224_DIGEST_SIZE);
|
||||
}
|
||||
@@ -865,7 +869,7 @@ WOLFSSL_API int wc_Sha3_224_Final(wc_Sha3* sha3, byte* hash)
|
||||
* sha3 wc_Sha3 object holding state.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API void wc_Sha3_224_Free(wc_Sha3* sha3)
|
||||
void wc_Sha3_224_Free(wc_Sha3* sha3)
|
||||
{
|
||||
wc_Sha3Free(sha3);
|
||||
}
|
||||
@@ -878,7 +882,7 @@ WOLFSSL_API void wc_Sha3_224_Free(wc_Sha3* sha3)
|
||||
* hash Buffer to hold the hash result. Must be at least 28 bytes.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_224_GetHash(wc_Sha3* sha3, byte* hash)
|
||||
int wc_Sha3_224_GetHash(wc_Sha3* sha3, byte* hash)
|
||||
{
|
||||
return wc_Sha3GetHash(sha3, hash, WC_SHA3_224_COUNT, WC_SHA3_224_DIGEST_SIZE);
|
||||
}
|
||||
@@ -889,7 +893,7 @@ WOLFSSL_API int wc_Sha3_224_GetHash(wc_Sha3* sha3, byte* hash)
|
||||
* dst wc_Sha3 object to copy into.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_224_Copy(wc_Sha3* src, wc_Sha3* dst)
|
||||
int wc_Sha3_224_Copy(wc_Sha3* src, wc_Sha3* dst)
|
||||
{
|
||||
return wc_Sha3Copy(src, dst);
|
||||
}
|
||||
@@ -902,7 +906,7 @@ WOLFSSL_API int wc_Sha3_224_Copy(wc_Sha3* src, wc_Sha3* dst)
|
||||
* devId Device identifier for asynchronous operation.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_InitSha3_256(wc_Sha3* sha3, void* heap, int devId)
|
||||
int wc_InitSha3_256(wc_Sha3* sha3, void* heap, int devId)
|
||||
{
|
||||
return wc_InitSha3(sha3, heap, devId);
|
||||
}
|
||||
@@ -914,7 +918,7 @@ WOLFSSL_API int wc_InitSha3_256(wc_Sha3* sha3, void* heap, int devId)
|
||||
* len Length of the message data.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_256_Update(wc_Sha3* sha3, const byte* data, word32 len)
|
||||
int wc_Sha3_256_Update(wc_Sha3* sha3, const byte* data, word32 len)
|
||||
{
|
||||
return wc_Sha3Update(sha3, data, len, WC_SHA3_256_COUNT);
|
||||
}
|
||||
@@ -926,7 +930,7 @@ WOLFSSL_API int wc_Sha3_256_Update(wc_Sha3* sha3, const byte* data, word32 len)
|
||||
* hash Buffer to hold the hash result. Must be at least 32 bytes.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_256_Final(wc_Sha3* sha3, byte* hash)
|
||||
int wc_Sha3_256_Final(wc_Sha3* sha3, byte* hash)
|
||||
{
|
||||
return wc_Sha3Final(sha3, hash, WC_SHA3_256_COUNT, WC_SHA3_256_DIGEST_SIZE);
|
||||
}
|
||||
@@ -937,7 +941,7 @@ WOLFSSL_API int wc_Sha3_256_Final(wc_Sha3* sha3, byte* hash)
|
||||
* sha3 wc_Sha3 object holding state.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API void wc_Sha3_256_Free(wc_Sha3* sha3)
|
||||
void wc_Sha3_256_Free(wc_Sha3* sha3)
|
||||
{
|
||||
wc_Sha3Free(sha3);
|
||||
}
|
||||
@@ -950,7 +954,7 @@ WOLFSSL_API void wc_Sha3_256_Free(wc_Sha3* sha3)
|
||||
* hash Buffer to hold the hash result. Must be at least 32 bytes.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_256_GetHash(wc_Sha3* sha3, byte* hash)
|
||||
int wc_Sha3_256_GetHash(wc_Sha3* sha3, byte* hash)
|
||||
{
|
||||
return wc_Sha3GetHash(sha3, hash, WC_SHA3_256_COUNT, WC_SHA3_256_DIGEST_SIZE);
|
||||
}
|
||||
@@ -961,7 +965,7 @@ WOLFSSL_API int wc_Sha3_256_GetHash(wc_Sha3* sha3, byte* hash)
|
||||
* dst wc_Sha3 object to copy into.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_256_Copy(wc_Sha3* src, wc_Sha3* dst)
|
||||
int wc_Sha3_256_Copy(wc_Sha3* src, wc_Sha3* dst)
|
||||
{
|
||||
return wc_Sha3Copy(src, dst);
|
||||
}
|
||||
@@ -974,7 +978,7 @@ WOLFSSL_API int wc_Sha3_256_Copy(wc_Sha3* src, wc_Sha3* dst)
|
||||
* devId Device identifier for asynchronous operation.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_InitSha3_384(wc_Sha3* sha3, void* heap, int devId)
|
||||
int wc_InitSha3_384(wc_Sha3* sha3, void* heap, int devId)
|
||||
{
|
||||
return wc_InitSha3(sha3, heap, devId);
|
||||
}
|
||||
@@ -986,7 +990,7 @@ WOLFSSL_API int wc_InitSha3_384(wc_Sha3* sha3, void* heap, int devId)
|
||||
* len Length of the message data.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_384_Update(wc_Sha3* sha3, const byte* data, word32 len)
|
||||
int wc_Sha3_384_Update(wc_Sha3* sha3, const byte* data, word32 len)
|
||||
{
|
||||
return wc_Sha3Update(sha3, data, len, WC_SHA3_384_COUNT);
|
||||
}
|
||||
@@ -998,7 +1002,7 @@ WOLFSSL_API int wc_Sha3_384_Update(wc_Sha3* sha3, const byte* data, word32 len)
|
||||
* hash Buffer to hold the hash result. Must be at least 48 bytes.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_384_Final(wc_Sha3* sha3, byte* hash)
|
||||
int wc_Sha3_384_Final(wc_Sha3* sha3, byte* hash)
|
||||
{
|
||||
return wc_Sha3Final(sha3, hash, WC_SHA3_384_COUNT, WC_SHA3_384_DIGEST_SIZE);
|
||||
}
|
||||
@@ -1009,7 +1013,7 @@ WOLFSSL_API int wc_Sha3_384_Final(wc_Sha3* sha3, byte* hash)
|
||||
* sha3 wc_Sha3 object holding state.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API void wc_Sha3_384_Free(wc_Sha3* sha3)
|
||||
void wc_Sha3_384_Free(wc_Sha3* sha3)
|
||||
{
|
||||
wc_Sha3Free(sha3);
|
||||
}
|
||||
@@ -1022,7 +1026,7 @@ WOLFSSL_API void wc_Sha3_384_Free(wc_Sha3* sha3)
|
||||
* hash Buffer to hold the hash result. Must be at least 48 bytes.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_384_GetHash(wc_Sha3* sha3, byte* hash)
|
||||
int wc_Sha3_384_GetHash(wc_Sha3* sha3, byte* hash)
|
||||
{
|
||||
return wc_Sha3GetHash(sha3, hash, WC_SHA3_384_COUNT, WC_SHA3_384_DIGEST_SIZE);
|
||||
}
|
||||
@@ -1033,7 +1037,7 @@ WOLFSSL_API int wc_Sha3_384_GetHash(wc_Sha3* sha3, byte* hash)
|
||||
* dst wc_Sha3 object to copy into.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_384_Copy(wc_Sha3* src, wc_Sha3* dst)
|
||||
int wc_Sha3_384_Copy(wc_Sha3* src, wc_Sha3* dst)
|
||||
{
|
||||
return wc_Sha3Copy(src, dst);
|
||||
}
|
||||
@@ -1046,7 +1050,7 @@ WOLFSSL_API int wc_Sha3_384_Copy(wc_Sha3* src, wc_Sha3* dst)
|
||||
* devId Device identifier for asynchronous operation.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_InitSha3_512(wc_Sha3* sha3, void* heap, int devId)
|
||||
int wc_InitSha3_512(wc_Sha3* sha3, void* heap, int devId)
|
||||
{
|
||||
return wc_InitSha3(sha3, heap, devId);
|
||||
}
|
||||
@@ -1058,7 +1062,7 @@ WOLFSSL_API int wc_InitSha3_512(wc_Sha3* sha3, void* heap, int devId)
|
||||
* len Length of the message data.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_512_Update(wc_Sha3* sha3, const byte* data, word32 len)
|
||||
int wc_Sha3_512_Update(wc_Sha3* sha3, const byte* data, word32 len)
|
||||
{
|
||||
return wc_Sha3Update(sha3, data, len, WC_SHA3_512_COUNT);
|
||||
}
|
||||
@@ -1070,7 +1074,7 @@ WOLFSSL_API int wc_Sha3_512_Update(wc_Sha3* sha3, const byte* data, word32 len)
|
||||
* hash Buffer to hold the hash result. Must be at least 64 bytes.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_512_Final(wc_Sha3* sha3, byte* hash)
|
||||
int wc_Sha3_512_Final(wc_Sha3* sha3, byte* hash)
|
||||
{
|
||||
return wc_Sha3Final(sha3, hash, WC_SHA3_512_COUNT, WC_SHA3_512_DIGEST_SIZE);
|
||||
}
|
||||
@@ -1081,7 +1085,7 @@ WOLFSSL_API int wc_Sha3_512_Final(wc_Sha3* sha3, byte* hash)
|
||||
* sha3 wc_Sha3 object holding state.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API void wc_Sha3_512_Free(wc_Sha3* sha3)
|
||||
void wc_Sha3_512_Free(wc_Sha3* sha3)
|
||||
{
|
||||
wc_Sha3Free(sha3);
|
||||
}
|
||||
@@ -1094,7 +1098,7 @@ WOLFSSL_API void wc_Sha3_512_Free(wc_Sha3* sha3)
|
||||
* hash Buffer to hold the hash result. Must be at least 64 bytes.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_512_GetHash(wc_Sha3* sha3, byte* hash)
|
||||
int wc_Sha3_512_GetHash(wc_Sha3* sha3, byte* hash)
|
||||
{
|
||||
return wc_Sha3GetHash(sha3, hash, WC_SHA3_512_COUNT, WC_SHA3_512_DIGEST_SIZE);
|
||||
}
|
||||
@@ -1105,9 +1109,26 @@ WOLFSSL_API int wc_Sha3_512_GetHash(wc_Sha3* sha3, byte* hash)
|
||||
* dst wc_Sha3 object to copy into.
|
||||
* returns 0 on success.
|
||||
*/
|
||||
WOLFSSL_API int wc_Sha3_512_Copy(wc_Sha3* src, wc_Sha3* dst)
|
||||
int wc_Sha3_512_Copy(wc_Sha3* src, wc_Sha3* dst)
|
||||
{
|
||||
return wc_Sha3Copy(src, dst);
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
int wc_Sha3_SetFlags(wc_Sha3* sha3, word32 flags)
|
||||
{
|
||||
if (sha3) {
|
||||
sha3->flags = flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int wc_Sha3_GetFlags(wc_Sha3* sha3, word32* flags)
|
||||
{
|
||||
if (sha3 && flags) {
|
||||
*flags = sha3->flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WOLFSSL_SHA3 */
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <wolfssl/wolfcrypt/sha512.h>
|
||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||
#include <wolfssl/wolfcrypt/cpuid.h>
|
||||
#include <wolfssl/wolfcrypt/hash.h>
|
||||
|
||||
/* deprecated USE_SLOW_SHA2 (replaced with USE_SLOW_SHA512) */
|
||||
#if defined(USE_SLOW_SHA2) && !defined(USE_SLOW_SHA512)
|
||||
@@ -1110,9 +1111,30 @@ int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst)
|
||||
dst->ctx.isfirstblock = src->ctx.isfirstblock;
|
||||
dst->ctx.sha_type = src->ctx.sha_type;
|
||||
#endif
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
int wc_Sha512SetFlags(wc_Sha512* sha512, word32 flags)
|
||||
{
|
||||
if (sha512) {
|
||||
sha512->flags = flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int wc_Sha512GetFlags(wc_Sha512* sha512, word32* flags)
|
||||
{
|
||||
if (sha512 && flags) {
|
||||
*flags = sha512->flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WOLFSSL_SHA512 */
|
||||
|
||||
#ifdef WOLFSSL_SHA384
|
||||
@@ -1165,9 +1187,30 @@ int wc_Sha384Copy(wc_Sha384* src, wc_Sha384* dst)
|
||||
dst->ctx.isfirstblock = src->ctx.isfirstblock;
|
||||
dst->ctx.sha_type = src->ctx.sha_type;
|
||||
#endif
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
dst->flags |= WC_HASH_FLAG_ISCOPY;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
|
||||
int wc_Sha384SetFlags(wc_Sha384* sha384, word32 flags)
|
||||
{
|
||||
if (sha384) {
|
||||
sha384->flags = flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int wc_Sha384GetFlags(wc_Sha384* sha384, word32* flags)
|
||||
{
|
||||
if (sha384 && flags) {
|
||||
*flags = sha384->flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WOLFSSL_SHA384 */
|
||||
|
||||
#endif /* WOLFSSL_SHA512 || WOLFSSL_SHA384 */
|
||||
|
||||
Reference in New Issue
Block a user