Refactor and rename of cryptodev to cryptocb. Refactor API names from `wc_CryptoDev` to use `wc_CryptoCb`. Backwards compatibility is retained for anyone using old `WOLF_CRYPTO_DEV` name. Added comment about fall-through case when CryptoCb return `NOT_COMPILED_IN`.

pull/2041/head
David Garske 2019-01-17 11:01:14 -08:00
parent 91573735b1
commit ee45cfdbcb
26 changed files with 213 additions and 180 deletions

View File

@ -110,7 +110,7 @@ SRC_C += ../../wolfcrypt/src/cmac.c
SRC_C += ../../wolfcrypt/src/coding.c SRC_C += ../../wolfcrypt/src/coding.c
SRC_C += ../../wolfcrypt/src/compress.c SRC_C += ../../wolfcrypt/src/compress.c
SRC_C += ../../wolfcrypt/src/cpuid.c SRC_C += ../../wolfcrypt/src/cpuid.c
SRC_C += ../../wolfcrypt/src/cryptodev.c SRC_C += ../../wolfcrypt/src/cryptocb.c
SRC_C += ../../wolfcrypt/src/curve25519.c SRC_C += ../../wolfcrypt/src/curve25519.c
SRC_C += ../../wolfcrypt/src/ed25519.c SRC_C += ../../wolfcrypt/src/ed25519.c
SRC_C += ../../wolfcrypt/src/error.c SRC_C += ../../wolfcrypt/src/error.c

View File

@ -130,9 +130,9 @@
<locationURI>PARENT-5-PROJECT_LOC/wolfcrypt/src/cpuid.c</locationURI> <locationURI>PARENT-5-PROJECT_LOC/wolfcrypt/src/cpuid.c</locationURI>
</link> </link>
<link> <link>
<name>wolfcrypt/src/cryptodev.c</name> <name>wolfcrypt/src/cryptocb.c</name>
<type>1</type> <type>1</type>
<locationURI>PARENT-5-PROJECT_LOC/wolfcrypt/src/cryptodev.c</locationURI> <locationURI>PARENT-5-PROJECT_LOC/wolfcrypt/src/cryptocb.c</locationURI>
</link> </link>
<link> <link>
<name>wolfcrypt/src/curve25519.c</name> <name>wolfcrypt/src/curve25519.c</name>

View File

@ -4233,22 +4233,24 @@ else
fi fi
# Support for crypto device hardware # Support for crypto callbacks
AC_ARG_ENABLE([cryptodev], AC_ARG_ENABLE([cryptocb],
[AS_HELP_STRING([--enable-cryptodev],[Enable crypto hardware support (default: disabled)])], [AS_HELP_STRING([--enable-cryptocb],[Enable crypto callbacks (default: disabled)])],
[ ENABLED_CRYPTODEV=$enableval ], [ ENABLED_CRYPTOCB=$enableval ],
[ ENABLED_CRYPTODEV=no ] [ ENABLED_CRYPTOCB=no ]
) )
# cryptodev is old name, replaced with cryptocb
AC_ARG_ENABLE([cryptodev],,[ ENABLED_CRYPTOCB=$enableval ],[ ENABLED_CRYPTOCB=no ])
if test "x$ENABLED_PKCS11" = "xyes" if test "x$ENABLED_PKCS11" = "xyes"
then then
ENABLED_CRYPTODEV=yes ENABLED_CRYPTOCB=yes
fi fi
if test "$ENABLED_CRYPTODEV" = "yes" if test "$ENABLED_CRYPTOCB" = "yes"
then then
AM_CFLAGS="$AM_CFLAGS -DWOLF_CRYPTO_DEV" AM_CFLAGS="$AM_CFLAGS -DWOLF_CRYPTO_CB"
fi fi
AM_CONDITIONAL([BUILD_CRYPTODEV], [test "x$ENABLED_CRYPTODEV" = "xyes"]) AM_CONDITIONAL([BUILD_CRYPTOCB], [test "x$ENABLED_CRYPTOCB" = "xyes"])
# Session Export # Session Export

View File

@ -190,7 +190,7 @@ mkdir -p $RPM_BUILD_ROOT/
%{_includedir}/wolfssl/wolfcrypt/compress.h %{_includedir}/wolfssl/wolfcrypt/compress.h
%{_includedir}/wolfssl/wolfcrypt/cpuid.h %{_includedir}/wolfssl/wolfcrypt/cpuid.h
%{_includedir}/wolfssl/wolfcrypt/curve25519.h %{_includedir}/wolfssl/wolfcrypt/curve25519.h
%{_includedir}/wolfssl/wolfcrypt/cryptodev.h %{_includedir}/wolfssl/wolfcrypt/cryptocb.h
%{_includedir}/wolfssl/wolfcrypt/des3.h %{_includedir}/wolfssl/wolfcrypt/des3.h
%{_includedir}/wolfssl/wolfcrypt/dh.h %{_includedir}/wolfssl/wolfcrypt/dh.h
%{_includedir}/wolfssl/wolfcrypt/dsa.h %{_includedir}/wolfssl/wolfcrypt/dsa.h
@ -291,7 +291,7 @@ mkdir -p $RPM_BUILD_ROOT/
* Thu Dec 20 2018 Jacob Barthelmeh <jacob@wolfssl.com> * Thu Dec 20 2018 Jacob Barthelmeh <jacob@wolfssl.com>
- Remove wolfssl/wolfcrypt/fips.h, add wolfssl/openssl/pkcs7.h - Remove wolfssl/wolfcrypt/fips.h, add wolfssl/openssl/pkcs7.h
* Wed Jun 20 2018 Jacob Barthelmeh <jacob@wolfssl.com> * Wed Jun 20 2018 Jacob Barthelmeh <jacob@wolfssl.com>
- Remove NEWS, update ChangeLog to ChangeLog.md, remove wolfssl/wolfcrypt/fips.h, add wolfssl/wolfcrypt/cryptodev.h - Remove NEWS, update ChangeLog to ChangeLog.md, remove wolfssl/wolfcrypt/fips.h, add wolfssl/wolfcrypt/cryptocb.h
* Thu May 31 2018 John Safranek <john@wolfssl.com> * Thu May 31 2018 John Safranek <john@wolfssl.com>
- Update the version number on the library SO file. - Update the version number on the library SO file.
* Fri Mar 02 2018 Jacob Barthelmeh <jacob@wolfssl.com> * Fri Mar 02 2018 Jacob Barthelmeh <jacob@wolfssl.com>

View File

@ -46,8 +46,8 @@
#include <wolfssl/wolfcrypt/aes.h> #include <wolfssl/wolfcrypt/aes.h>
#include <wolfssl/wolfcrypt/cpuid.h> #include <wolfssl/wolfcrypt/cpuid.h>
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
#include <wolfssl/wolfcrypt/cryptodev.h> #include <wolfssl/wolfcrypt/cryptocb.h>
#endif #endif
@ -2210,7 +2210,7 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
XMEMCPY(aes->asyncIv, iv, AES_BLOCK_SIZE); XMEMCPY(aes->asyncIv, iv, AES_BLOCK_SIZE);
} }
#endif /* WOLFSSL_ASYNC_CRYPT */ #endif /* WOLFSSL_ASYNC_CRYPT */
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (aes->devId != INVALID_DEVID) { if (aes->devId != INVALID_DEVID) {
XMEMCPY(aes->devKey, userKey, keylen); XMEMCPY(aes->devKey, userKey, keylen);
} }
@ -2909,11 +2909,12 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (aes->devId != INVALID_DEVID) { if (aes->devId != INVALID_DEVID) {
int ret = wc_CryptoDev_AesCbcEncrypt(aes, out, in, sz); int ret = wc_CryptoCb_AesCbcEncrypt(aes, out, in, sz);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
} }
#endif #endif
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES) #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES)
@ -3007,11 +3008,12 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (aes->devId != INVALID_DEVID) { if (aes->devId != INVALID_DEVID) {
int ret = wc_CryptoDev_AesCbcDecrypt(aes, out, in, sz); int ret = wc_CryptoCb_AesCbcDecrypt(aes, out, in, sz);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
} }
#endif #endif
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES) #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES)
@ -8508,12 +8510,13 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (aes->devId != INVALID_DEVID) { if (aes->devId != INVALID_DEVID) {
int ret = wc_CryptoDev_AesGcmEncrypt(aes, out, in, sz, iv, ivSz, int ret = wc_CryptoCb_AesGcmEncrypt(aes, out, in, sz, iv, ivSz,
authTag, authTagSz, authIn, authInSz); authTag, authTagSz, authIn, authInSz);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
} }
#endif #endif
@ -8910,12 +8913,13 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (aes->devId != INVALID_DEVID) { if (aes->devId != INVALID_DEVID) {
int ret = wc_CryptoDev_AesGcmDecrypt(aes, out, in, sz, iv, ivSz, int ret = wc_CryptoCb_AesGcmDecrypt(aes, out, in, sz, iv, ivSz,
authTag, authTagSz, authIn, authInSz); authTag, authTagSz, authIn, authInSz);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
} }
#endif #endif
@ -9598,7 +9602,7 @@ int wc_AesInit(Aes* aes, void* heap, int devId)
aes->heap = heap; aes->heap = heap;
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
aes->devId = devId; aes->devId = devId;
#else #else
(void)devId; (void)devId;

View File

@ -1,4 +1,4 @@
/* cryptodev.c /* cryptocb.c
* *
* Copyright (C) 2006-2018 wolfSSL Inc. * Copyright (C) 2006-2018 wolfSSL Inc.
* *
@ -27,49 +27,49 @@
#include <wolfssl/wolfcrypt/settings.h> #include <wolfssl/wolfcrypt/settings.h>
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
#include <wolfssl/wolfcrypt/cryptodev.h> #include <wolfssl/wolfcrypt/cryptocb.h>
#include <wolfssl/wolfcrypt/error-crypt.h> #include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/wolfcrypt/logging.h> #include <wolfssl/wolfcrypt/logging.h>
/* TODO: Consider linked list with mutex */ /* TODO: Consider linked list with mutex */
#ifndef MAX_CRYPTO_DEVICES #ifndef MAX_CRYPTO_DEVID_CALLBACKS
#define MAX_CRYPTO_DEVICES 8 #define MAX_CRYPTO_DEVID_CALLBACKS 8
#endif #endif
typedef struct CryptoDev { typedef struct CryptoCb {
int devId; int devId;
CryptoDevCallbackFunc cb; wc_CryptoCallbackFunc cb;
void* ctx; void* ctx;
} CryptoDev; } CryptoCb;
static CryptoDev gCryptoDev[MAX_CRYPTO_DEVICES]; static CryptoCb gCryptoDev[MAX_CRYPTO_DEVID_CALLBACKS];
static CryptoDev* wc_CryptoDev_FindDevice(int devId) static CryptoCb* wc_CryptoCb_FindDevice(int devId)
{ {
int i; int i;
for (i=0; i<MAX_CRYPTO_DEVICES; i++) { for (i=0; i<MAX_CRYPTO_DEVID_CALLBACKS; i++) {
if (gCryptoDev[i].devId == devId) if (gCryptoDev[i].devId == devId)
return &gCryptoDev[i]; return &gCryptoDev[i];
} }
return NULL; return NULL;
} }
void wc_CryptoDev_Init(void) void wc_CryptoCb_Init(void)
{ {
int i; int i;
for (i=0; i<MAX_CRYPTO_DEVICES; i++) { for (i=0; i<MAX_CRYPTO_DEVID_CALLBACKS; i++) {
gCryptoDev[i].devId = INVALID_DEVID; gCryptoDev[i].devId = INVALID_DEVID;
} }
} }
int wc_CryptoDev_RegisterDevice(int devId, CryptoDevCallbackFunc cb, void* ctx) int wc_CryptoCb_RegisterDevice(int devId, wc_CryptoCallbackFunc cb, void* ctx)
{ {
/* find existing or new */ /* find existing or new */
CryptoDev* dev = wc_CryptoDev_FindDevice(devId); CryptoCb* dev = wc_CryptoCb_FindDevice(devId);
if (dev == NULL) if (dev == NULL)
dev = wc_CryptoDev_FindDevice(INVALID_DEVID); dev = wc_CryptoCb_FindDevice(INVALID_DEVID);
if (dev == NULL) if (dev == NULL)
return BUFFER_E; /* out of devices */ return BUFFER_E; /* out of devices */
@ -81,9 +81,9 @@ int wc_CryptoDev_RegisterDevice(int devId, CryptoDevCallbackFunc cb, void* ctx)
return 0; return 0;
} }
void wc_CryptoDev_UnRegisterDevice(int devId) void wc_CryptoCb_UnRegisterDevice(int devId)
{ {
CryptoDev* dev = wc_CryptoDev_FindDevice(devId); CryptoCb* dev = wc_CryptoCb_FindDevice(devId);
if (dev) { if (dev) {
XMEMSET(dev, 0, sizeof(*dev)); XMEMSET(dev, 0, sizeof(*dev));
dev->devId = INVALID_DEVID; dev->devId = INVALID_DEVID;
@ -91,14 +91,14 @@ void wc_CryptoDev_UnRegisterDevice(int devId)
} }
#ifndef NO_RSA #ifndef NO_RSA
int wc_CryptoDev_Rsa(const byte* in, word32 inLen, byte* out, int wc_CryptoCb_Rsa(const byte* in, word32 inLen, byte* out,
word32* outLen, int type, RsaKey* key, WC_RNG* rng) word32* outLen, int type, RsaKey* key, WC_RNG* rng)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(key->devId); dev = wc_CryptoCb_FindDevice(key->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -121,13 +121,13 @@ int wc_CryptoDev_Rsa(const byte* in, word32 inLen, byte* out,
} }
#ifdef WOLFSSL_KEY_GEN #ifdef WOLFSSL_KEY_GEN
int wc_CryptoDev_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng) int wc_CryptoCb_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(key->devId); dev = wc_CryptoCb_FindDevice(key->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -149,13 +149,13 @@ int wc_CryptoDev_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
#endif /* !NO_RSA */ #endif /* !NO_RSA */
#ifdef HAVE_ECC #ifdef HAVE_ECC
int wc_CryptoDev_MakeEccKey(WC_RNG* rng, int keySize, ecc_key* key, int curveId) int wc_CryptoCb_MakeEccKey(WC_RNG* rng, int keySize, ecc_key* key, int curveId)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(key->devId); dev = wc_CryptoCb_FindDevice(key->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -174,14 +174,14 @@ int wc_CryptoDev_MakeEccKey(WC_RNG* rng, int keySize, ecc_key* key, int curveId)
return ret; return ret;
} }
int wc_CryptoDev_Ecdh(ecc_key* private_key, ecc_key* public_key, int wc_CryptoCb_Ecdh(ecc_key* private_key, ecc_key* public_key,
byte* out, word32* outlen) byte* out, word32* outlen)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(private_key->devId); dev = wc_CryptoCb_FindDevice(private_key->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -200,14 +200,14 @@ int wc_CryptoDev_Ecdh(ecc_key* private_key, ecc_key* public_key,
return ret; return ret;
} }
int wc_CryptoDev_EccSign(const byte* in, word32 inlen, byte* out, int wc_CryptoCb_EccSign(const byte* in, word32 inlen, byte* out,
word32 *outlen, WC_RNG* rng, ecc_key* key) word32 *outlen, WC_RNG* rng, ecc_key* key)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(key->devId); dev = wc_CryptoCb_FindDevice(key->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -228,14 +228,14 @@ int wc_CryptoDev_EccSign(const byte* in, word32 inlen, byte* out,
return ret; return ret;
} }
int wc_CryptoDev_EccVerify(const byte* sig, word32 siglen, int wc_CryptoCb_EccVerify(const byte* sig, word32 siglen,
const byte* hash, word32 hashlen, int* res, ecc_key* key) const byte* hash, word32 hashlen, int* res, ecc_key* key)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(key->devId); dev = wc_CryptoCb_FindDevice(key->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -259,17 +259,17 @@ int wc_CryptoDev_EccVerify(const byte* sig, word32 siglen,
#ifndef NO_AES #ifndef NO_AES
#ifdef HAVE_AESGCM #ifdef HAVE_AESGCM
int wc_CryptoDev_AesGcmEncrypt(Aes* aes, byte* out, int wc_CryptoCb_AesGcmEncrypt(Aes* aes, byte* out,
const byte* in, word32 sz, const byte* in, word32 sz,
const byte* iv, word32 ivSz, const byte* iv, word32 ivSz,
byte* authTag, word32 authTagSz, byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz) const byte* authIn, word32 authInSz)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(aes->devId); dev = wc_CryptoCb_FindDevice(aes->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -295,17 +295,17 @@ int wc_CryptoDev_AesGcmEncrypt(Aes* aes, byte* out,
return ret; return ret;
} }
int wc_CryptoDev_AesGcmDecrypt(Aes* aes, byte* out, int wc_CryptoCb_AesGcmDecrypt(Aes* aes, byte* out,
const byte* in, word32 sz, const byte* in, word32 sz,
const byte* iv, word32 ivSz, const byte* iv, word32 ivSz,
const byte* authTag, word32 authTagSz, const byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz) const byte* authIn, word32 authInSz)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(aes->devId); dev = wc_CryptoCb_FindDevice(aes->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -333,14 +333,14 @@ int wc_CryptoDev_AesGcmDecrypt(Aes* aes, byte* out,
#endif /* HAVE_AESGCM */ #endif /* HAVE_AESGCM */
#ifdef HAVE_AES_CBC #ifdef HAVE_AES_CBC
int wc_CryptoDev_AesCbcEncrypt(Aes* aes, byte* out, int wc_CryptoCb_AesCbcEncrypt(Aes* aes, byte* out,
const byte* in, word32 sz) const byte* in, word32 sz)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(aes->devId); dev = wc_CryptoCb_FindDevice(aes->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -360,14 +360,14 @@ int wc_CryptoDev_AesCbcEncrypt(Aes* aes, byte* out,
return ret; return ret;
} }
int wc_CryptoDev_AesCbcDecrypt(Aes* aes, byte* out, int wc_CryptoCb_AesCbcDecrypt(Aes* aes, byte* out,
const byte* in, word32 sz) const byte* in, word32 sz)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(aes->devId); dev = wc_CryptoCb_FindDevice(aes->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -390,14 +390,14 @@ int wc_CryptoDev_AesCbcDecrypt(Aes* aes, byte* out,
#endif /* !NO_AES */ #endif /* !NO_AES */
#ifndef NO_SHA #ifndef NO_SHA
int wc_CryptoDev_ShaHash(wc_Sha* sha, const byte* in, int wc_CryptoCb_ShaHash(wc_Sha* sha, const byte* in,
word32 inSz, byte* digest) word32 inSz, byte* digest)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(sha->devId); dev = wc_CryptoCb_FindDevice(sha->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -418,14 +418,14 @@ int wc_CryptoDev_ShaHash(wc_Sha* sha, const byte* in,
#endif /* !NO_SHA */ #endif /* !NO_SHA */
#ifndef NO_SHA256 #ifndef NO_SHA256
int wc_CryptoDev_Sha256Hash(wc_Sha256* sha256, const byte* in, int wc_CryptoCb_Sha256Hash(wc_Sha256* sha256, const byte* in,
word32 inSz, byte* digest) word32 inSz, byte* digest)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(sha256->devId); dev = wc_CryptoCb_FindDevice(sha256->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -446,13 +446,13 @@ int wc_CryptoDev_Sha256Hash(wc_Sha256* sha256, const byte* in,
#endif /* !NO_SHA256 */ #endif /* !NO_SHA256 */
#ifndef WC_NO_RNG #ifndef WC_NO_RNG
int wc_CryptoDev_RandomBlock(WC_RNG* rng, byte* out, word32 sz) int wc_CryptoCb_RandomBlock(WC_RNG* rng, byte* out, word32 sz)
{ {
int ret = NOT_COMPILED_IN; int ret = NOT_COMPILED_IN;
CryptoDev* dev; CryptoCb* dev;
/* locate registered callback */ /* locate registered callback */
dev = wc_CryptoDev_FindDevice(rng->devId); dev = wc_CryptoCb_FindDevice(rng->devId);
if (dev) { if (dev) {
if (dev->cb) { if (dev->cb) {
wc_CryptoInfo cryptoInfo; wc_CryptoInfo cryptoInfo;
@ -470,4 +470,4 @@ int wc_CryptoDev_RandomBlock(WC_RNG* rng, byte* out, word32 sz)
} }
#endif /* !WC_NO_RNG */ #endif /* !WC_NO_RNG */
#endif /* WOLF_CRYPTO_DEV */ #endif /* WOLF_CRYPTO_CB */

View File

@ -122,8 +122,8 @@ ECC Curve Sizes:
#include <wolfssl/wolfcrypt/hash.h> #include <wolfssl/wolfcrypt/hash.h>
#endif #endif
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
#include <wolfssl/wolfcrypt/cryptodev.h> #include <wolfssl/wolfcrypt/cryptocb.h>
#endif #endif
#ifdef NO_INLINE #ifdef NO_INLINE
@ -3388,9 +3388,9 @@ int wc_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out,
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (private_key->devId != INVALID_DEVID) { if (private_key->devId != INVALID_DEVID) {
err = wc_CryptoDev_Ecdh(private_key, public_key, out, outlen); err = wc_CryptoCb_Ecdh(private_key, public_key, out, outlen);
if (err != NOT_COMPILED_IN) if (err != NOT_COMPILED_IN)
return err; return err;
} }
@ -3949,9 +3949,9 @@ int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key, int curve_id)
return err; return err;
} }
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (key->devId != INVALID_DEVID) { if (key->devId != INVALID_DEVID) {
err = wc_CryptoDev_MakeEccKey(rng, keysize, key, curve_id); err = wc_CryptoCb_MakeEccKey(rng, keysize, key, curve_id);
if (err != NOT_COMPILED_IN) if (err != NOT_COMPILED_IN)
return err; return err;
} }
@ -4142,7 +4142,7 @@ int wc_ecc_init_ex(ecc_key* key, void* heap, int devId)
XMEMSET(key, 0, sizeof(ecc_key)); XMEMSET(key, 0, sizeof(ecc_key));
key->state = ECC_STATE_NONE; key->state = ECC_STATE_NONE;
#if defined(PLUTON_CRYPTO_ECC) || defined(WOLF_CRYPTO_DEV) #if defined(PLUTON_CRYPTO_ECC) || defined(WOLF_CRYPTO_CB)
key->devId = devId; key->devId = devId;
#else #else
(void)devId; (void)devId;
@ -4314,9 +4314,9 @@ int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen,
return ECC_BAD_ARG_E; return ECC_BAD_ARG_E;
} }
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (key->devId != INVALID_DEVID) { if (key->devId != INVALID_DEVID) {
err = wc_CryptoDev_EccSign(in, inlen, out, outlen, rng, key); err = wc_CryptoCb_EccSign(in, inlen, out, outlen, rng, key);
if (err != NOT_COMPILED_IN) if (err != NOT_COMPILED_IN)
return err; return err;
} }
@ -5152,9 +5152,9 @@ int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash,
return ECC_BAD_ARG_E; return ECC_BAD_ARG_E;
} }
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (key->devId != INVALID_DEVID) { if (key->devId != INVALID_DEVID) {
err = wc_CryptoDev_EccVerify(sig, siglen, hash, hashlen, res, key); err = wc_CryptoCb_EccVerify(sig, siglen, hash, hashlen, res, key);
if (err != NOT_COMPILED_IN) if (err != NOT_COMPILED_IN)
return err; return err;
} }

View File

@ -74,8 +74,8 @@ EXTRA_DIST += wolfcrypt/src/port/ti/ti-aes.c \
wolfcrypt/src/port/Espressif/esp32_util.c wolfcrypt/src/port/Espressif/esp32_util.c
if BUILD_CRYPTODEV if BUILD_CRYPTOCB
src_libwolfssl_la_SOURCES += wolfcrypt/src/cryptodev.c src_libwolfssl_la_SOURCES += wolfcrypt/src/cryptocb.c
endif endif
if BUILD_PKCS11 if BUILD_PKCS11

View File

@ -104,8 +104,8 @@ int wc_RNG_GenerateByte(WC_RNG* rng, byte* b)
#include <wolfssl/wolfcrypt/sha256.h> #include <wolfssl/wolfcrypt/sha256.h>
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
#include <wolfssl/wolfcrypt/cryptodev.h> #include <wolfssl/wolfcrypt/cryptocb.h>
#endif #endif
#ifdef NO_INLINE #ifdef NO_INLINE
@ -276,7 +276,7 @@ typedef struct DRBG {
word32 lastBlock; word32 lastBlock;
byte V[DRBG_SEED_LEN]; byte V[DRBG_SEED_LEN];
byte C[DRBG_SEED_LEN]; byte C[DRBG_SEED_LEN];
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_DEV) #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
void* heap; void* heap;
int devId; int devId;
#endif #endif
@ -325,7 +325,7 @@ static int Hash_df(DRBG* drbg, byte* out, word32 outSz, byte type,
for (i = 0, ctr = 1; i < len; i++, ctr++) { for (i = 0, ctr = 1; i < len; i++, ctr++) {
#ifndef WOLFSSL_SMALL_STACK_CACHE #ifndef WOLFSSL_SMALL_STACK_CACHE
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_DEV) #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
ret = wc_InitSha256_ex(sha, drbg->heap, drbg->devId); ret = wc_InitSha256_ex(sha, drbg->heap, drbg->devId);
#else #else
ret = wc_InitSha256(sha); ret = wc_InitSha256(sha);
@ -453,7 +453,7 @@ static int Hash_gen(DRBG* drbg, byte* out, word32 outSz, const byte* V)
XMEMCPY(data, V, sizeof(data)); XMEMCPY(data, V, sizeof(data));
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
#ifndef WOLFSSL_SMALL_STACK_CACHE #ifndef WOLFSSL_SMALL_STACK_CACHE
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_DEV) #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
ret = wc_InitSha256_ex(sha, drbg->heap, drbg->devId); ret = wc_InitSha256_ex(sha, drbg->heap, drbg->devId);
#else #else
ret = wc_InitSha256(sha); ret = wc_InitSha256(sha);
@ -556,7 +556,7 @@ static int Hash_DRBG_Generate(DRBG* drbg, byte* out, word32 outSz)
ret = Hash_gen(drbg, out, outSz, drbg->V); ret = Hash_gen(drbg, out, outSz, drbg->V);
if (ret == DRBG_SUCCESS) { if (ret == DRBG_SUCCESS) {
#ifndef WOLFSSL_SMALL_STACK_CACHE #ifndef WOLFSSL_SMALL_STACK_CACHE
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_DEV) #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
ret = wc_InitSha256_ex(sha, drbg->heap, drbg->devId); ret = wc_InitSha256_ex(sha, drbg->heap, drbg->devId);
#else #else
ret = wc_InitSha256(sha); ret = wc_InitSha256(sha);
@ -602,7 +602,7 @@ static int Hash_DRBG_Instantiate(DRBG* drbg, const byte* seed, word32 seedSz,
int ret = DRBG_FAILURE; int ret = DRBG_FAILURE;
XMEMSET(drbg, 0, sizeof(DRBG)); XMEMSET(drbg, 0, sizeof(DRBG));
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_DEV) #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
drbg->heap = heap; drbg->heap = heap;
drbg->devId = devId; drbg->devId = devId;
#else #else
@ -611,7 +611,7 @@ static int Hash_DRBG_Instantiate(DRBG* drbg, const byte* seed, word32 seedSz,
#endif #endif
#ifdef WOLFSSL_SMALL_STACK_CACHE #ifdef WOLFSSL_SMALL_STACK_CACHE
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_DEV) #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
ret = wc_InitSha256_ex(&drbg->sha256, drbg->heap, drbg->devId); ret = wc_InitSha256_ex(&drbg->sha256, drbg->heap, drbg->devId);
#else #else
ret = wc_InitSha256(&drbg->sha256); ret = wc_InitSha256(&drbg->sha256);
@ -701,7 +701,7 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
#else #else
rng->heap = heap; rng->heap = heap;
#endif #endif
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_DEV) #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
rng->devId = devId; rng->devId = devId;
#else #else
(void)devId; (void)devId;
@ -831,11 +831,12 @@ int wc_RNG_GenerateBlock(WC_RNG* rng, byte* output, word32 sz)
if (rng == NULL || output == NULL) if (rng == NULL || output == NULL)
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (rng->devId != INVALID_DEVID) { if (rng->devId != INVALID_DEVID) {
ret = wc_CryptoDev_RandomBlock(rng, output, sz); ret = wc_CryptoCb_RandomBlock(rng, output, sz);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
} }
#endif #endif

View File

@ -198,8 +198,8 @@ int wc_RsaFlattenPublicKey(RsaKey* key, byte* a, word32* aSz, byte* b,
#include <wolfssl/wolfcrypt/random.h> #include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/logging.h> #include <wolfssl/wolfcrypt/logging.h>
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
#include <wolfssl/wolfcrypt/cryptodev.h> #include <wolfssl/wolfcrypt/cryptocb.h>
#endif #endif
#ifdef NO_INLINE #ifdef NO_INLINE
#include <wolfssl/wolfcrypt/misc.h> #include <wolfssl/wolfcrypt/misc.h>
@ -266,7 +266,7 @@ int wc_InitRsaKey_ex(RsaKey* key, void* heap, int devId)
key->rng = NULL; key->rng = NULL;
#endif #endif
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
key->devId = devId; key->devId = devId;
#else #else
(void)devId; (void)devId;
@ -1962,11 +1962,12 @@ int wc_RsaFunction(const byte* in, word32 inLen, byte* out,
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (key->devId != INVALID_DEVID) { if (key->devId != INVALID_DEVID) {
ret = wc_CryptoDev_Rsa(in, inLen, out, outLen, type, key, rng); ret = wc_CryptoCb_Rsa(in, inLen, out, outLen, type, key, rng);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
ret = 0; /* reset error code and try using software */ ret = 0; /* reset error code and try using software */
} }
#endif #endif
@ -2818,7 +2819,7 @@ int wc_RsaEncryptSize(RsaKey* key)
ret = mp_unsigned_bin_size(&key->n); ret = mp_unsigned_bin_size(&key->n);
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (ret == 0 && key->devId != INVALID_DEVID) { if (ret == 0 && key->devId != INVALID_DEVID) {
ret = 2048/8; /* hardware handles, use 2048-bit as default */ ret = 2048/8; /* hardware handles, use 2048-bit as default */
} }
@ -3170,11 +3171,12 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
if (e < 3 || (e & 1) == 0) if (e < 3 || (e & 1) == 0)
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (key->devId != INVALID_DEVID) { if (key->devId != INVALID_DEVID) {
int ret = wc_CryptoDev_MakeRsaKey(key, size, e, rng); int ret = wc_CryptoCb_MakeRsaKey(key, size, e, rng);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
} }
#endif #endif

View File

@ -43,8 +43,8 @@
#include <wolfssl/wolfcrypt/sha.h> #include <wolfssl/wolfcrypt/sha.h>
#include <wolfssl/wolfcrypt/error-crypt.h> #include <wolfssl/wolfcrypt/error-crypt.h>
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
#include <wolfssl/wolfcrypt/cryptodev.h> #include <wolfssl/wolfcrypt/cryptocb.h>
#endif #endif
/* fips wrapper calls, user can call direct */ /* fips wrapper calls, user can call direct */
@ -434,7 +434,7 @@ int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId)
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
sha->heap = heap; sha->heap = heap;
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
sha->devId = devId; sha->devId = devId;
#endif #endif
@ -468,11 +468,12 @@ int wc_ShaUpdate(wc_Sha* sha, const byte* data, word32 len)
/* do block size increments */ /* do block size increments */
local = (byte*)sha->buffer; local = (byte*)sha->buffer;
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (sha->devId != INVALID_DEVID) { if (sha->devId != INVALID_DEVID) {
int ret = wc_CryptoDev_ShaHash(sha, data, len, NULL); int ret = wc_CryptoCb_ShaHash(sha, data, len, NULL);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
} }
#endif #endif
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA) #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA)
@ -550,11 +551,12 @@ int wc_ShaFinal(wc_Sha* sha, byte* hash)
local = (byte*)sha->buffer; local = (byte*)sha->buffer;
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (sha->devId != INVALID_DEVID) { if (sha->devId != INVALID_DEVID) {
int ret = wc_CryptoDev_ShaHash(sha, NULL, 0, hash); int ret = wc_CryptoCb_ShaHash(sha, NULL, 0, hash);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
} }
#endif #endif
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA) #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA)

View File

@ -46,8 +46,8 @@
#include <wolfssl/wolfcrypt/error-crypt.h> #include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/wolfcrypt/cpuid.h> #include <wolfssl/wolfcrypt/cpuid.h>
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
#include <wolfssl/wolfcrypt/cryptodev.h> #include <wolfssl/wolfcrypt/cryptocb.h>
#endif #endif
/* fips wrapper calls, user can call direct */ /* fips wrapper calls, user can call direct */
@ -312,7 +312,7 @@ static int InitSha256(wc_Sha256* sha256)
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
sha256->heap = heap; sha256->heap = heap;
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
sha256->devId = devId; sha256->devId = devId;
#endif #endif
@ -527,7 +527,7 @@ static int InitSha256(wc_Sha256* sha256)
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
sha256->heap = heap; sha256->heap = heap;
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
sha256->devId = devId; sha256->devId = devId;
#endif #endif
@ -818,11 +818,12 @@ static int InitSha256(wc_Sha256* sha256)
return 0; return 0;
} }
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (sha256->devId != INVALID_DEVID) { if (sha256->devId != INVALID_DEVID) {
int ret = wc_CryptoDev_Sha256Hash(sha256, data, len, NULL); int ret = wc_CryptoCb_Sha256Hash(sha256, data, len, NULL);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
} }
#endif #endif
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA256) #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA256)
@ -965,11 +966,12 @@ static int InitSha256(wc_Sha256* sha256)
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if (sha256->devId != INVALID_DEVID) { if (sha256->devId != INVALID_DEVID) {
ret = wc_CryptoDev_Sha256Hash(sha256, NULL, 0, hash); ret = wc_CryptoCb_Sha256Hash(sha256, NULL, 0, hash);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
} }
#endif #endif

View File

@ -706,6 +706,7 @@ static int wc_Sha3Update(wc_Sha3* sha3, const byte* data, word32 len, byte p)
ret = IntelQaSymSha3(&sha3->asyncDev, NULL, data, len); ret = IntelQaSymSha3(&sha3->asyncDev, NULL, data, len);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
} }
#endif #endif
} }
@ -741,6 +742,7 @@ static int wc_Sha3Final(wc_Sha3* sha3, byte* hash, byte p, byte len)
ret = IntelQaSymSha3(&sha3->asyncDev, hash, NULL, len); ret = IntelQaSymSha3(&sha3->asyncDev, hash, NULL, len);
if (ret != NOT_COMPILED_IN) if (ret != NOT_COMPILED_IN)
return ret; return ret;
/* fall-through on not compiled in */
} }
#endif #endif
} }

View File

@ -68,8 +68,8 @@
#include <wolfssl/wolfcrypt/port/caam/wolfcaam.h> #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
#endif #endif
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
#include <wolfssl/wolfcrypt/cryptodev.h> #include <wolfssl/wolfcrypt/cryptocb.h>
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
@ -101,8 +101,8 @@ int wolfCrypt_Init(void)
} }
#endif #endif
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
wc_CryptoDev_Init(); wc_CryptoCb_Init();
#endif #endif
#ifdef WOLFSSL_ASYNC_CRYPT #ifdef WOLFSSL_ASYNC_CRYPT

View File

@ -119,8 +119,8 @@
#ifdef WOLFSSL_IMX6_CAAM_BLOB #ifdef WOLFSSL_IMX6_CAAM_BLOB
#include <wolfssl/wolfcrypt/port/caam/wolfcaam.h> #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
#endif #endif
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
#include <wolfssl/wolfcrypt/cryptodev.h> #include <wolfssl/wolfcrypt/cryptocb.h>
#endif #endif
/* only for stack size check */ /* only for stack size check */
@ -370,8 +370,8 @@ int memcb_test(void);
int blob_test(void); int blob_test(void);
#endif #endif
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
int cryptodev_test(void); int cryptocb_test(void);
#endif #endif
#ifdef WOLFSSL_CERT_PIV #ifdef WOLFSSL_CERT_PIV
int certpiv_test(void); int certpiv_test(void);
@ -1039,11 +1039,11 @@ initDefaultName();
printf( "blob test passed!\n"); printf( "blob test passed!\n");
#endif #endif
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
if ( (ret = cryptodev_test()) != 0) if ( (ret = cryptocb_test()) != 0)
return err_sys("crypto dev test failed!\n", ret); return err_sys("crypto callback test failed!\n", ret);
else else
printf( "crypto dev test passed!\n"); printf( "crypto callback test passed!\n");
#endif #endif
#ifdef WOLFSSL_CERT_PIV #ifdef WOLFSSL_CERT_PIV
@ -9260,7 +9260,7 @@ static int rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng)
* -101 = USER_CRYPTO_ERROR * -101 = USER_CRYPTO_ERROR
*/ */
if (ret == 0) if (ret == 0)
#elif defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_DEV) #elif defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
/* async may not require RNG */ /* async may not require RNG */
if (ret != 0 && ret != MISSING_RNG_E) if (ret != 0 && ret != MISSING_RNG_E)
#elif defined(HAVE_FIPS) || defined(WOLFSSL_ASYNC_CRYPT) || \ #elif defined(HAVE_FIPS) || defined(WOLFSSL_ASYNC_CRYPT) || \
@ -22808,7 +22808,7 @@ int blob_test(void)
} }
#endif /* WOLFSSL_IMX6_CAAM_BLOB */ #endif /* WOLFSSL_IMX6_CAAM_BLOB */
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
/* Example custom context for crypto callback */ /* Example custom context for crypto callback */
typedef struct { typedef struct {
@ -23059,7 +23059,7 @@ static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
return ret; return ret;
} }
int cryptodev_test(void) int cryptocb_test(void)
{ {
int ret = 0; int ret = 0;
myCryptoDevCtx myCtx; myCryptoDevCtx myCtx;
@ -23069,7 +23069,7 @@ int cryptodev_test(void)
/* set devId to something other than INVALID_DEVID */ /* set devId to something other than INVALID_DEVID */
devId = 1; devId = 1;
ret = wc_CryptoDev_RegisterDevice(devId, myCryptoDevCb, &myCtx); ret = wc_CryptoCb_RegisterDevice(devId, myCryptoDevCb, &myCtx);
#ifndef WC_NO_RNG #ifndef WC_NO_RNG
if (ret == 0) if (ret == 0)
@ -23109,7 +23109,7 @@ int cryptodev_test(void)
return ret; return ret;
} }
#endif /* WOLF_CRYPTO_DEV */ #endif /* WOLF_CRYPTO_CB */
#ifdef WOLFSSL_CERT_PIV #ifdef WOLFSSL_CERT_PIV
int certpiv_test(void) int certpiv_test(void)

View File

@ -150,7 +150,7 @@ typedef struct Aes {
#ifdef WOLFSSL_AESNI #ifdef WOLFSSL_AESNI
byte use_aesni; byte use_aesni;
#endif /* WOLFSSL_AESNI */ #endif /* WOLFSSL_AESNI */
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
int devId; int devId;
word32 devKey[AES_MAX_KEY_SIZE/WOLFSSL_BIT_SIZE/sizeof(word32)]; /* raw key */ word32 devKey[AES_MAX_KEY_SIZE/WOLFSSL_BIT_SIZE/sizeof(word32)]; /* raw key */
#endif #endif

View File

@ -945,7 +945,7 @@ struct TrustedPeerCert {
/* Macro for calculating hashId */ /* Macro for calculating hashId */
#if defined(NO_SHA) && defined(NO_SHA256) #if defined(NO_SHA) && defined(NO_SHA256)
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
#define CalcHashId(data, len, hash) wc_CryptoDevSha256Hash(data, len, hash) #define CalcHashId(data, len, hash) wc_CryptoDevSha256Hash(data, len, hash)
#else #else
#define CalcHashId(data, len, hash) NOT_COMPILED_IN #define CalcHashId(data, len, hash) NOT_COMPILED_IN

View File

@ -1,4 +1,4 @@
/* cryptodev.h /* cryptocb.h
* *
* Copyright (C) 2006-2018 wolfSSL Inc. * Copyright (C) 2006-2018 wolfSSL Inc.
* *
@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _WOLF_CRYPTO_DEV_H_ #ifndef _WOLF_CRYPTO_CB_H_
#define _WOLF_CRYPTO_DEV_H_ #define _WOLF_CRYPTO_CB_H_
#include <wolfssl/wolfcrypt/types.h> #include <wolfssl/wolfcrypt/types.h>
@ -27,7 +27,7 @@
extern "C" { extern "C" {
#endif #endif
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
#ifndef NO_RSA #ifndef NO_RSA
#include <wolfssl/wolfcrypt/rsa.h> #include <wolfssl/wolfcrypt/rsa.h>
@ -172,76 +172,84 @@ typedef struct wc_CryptoInfo {
#endif #endif
} wc_CryptoInfo; } wc_CryptoInfo;
/* old naming */
#ifdef WOLF_CRYPTO_DEV
/* old callback function name */
typedef int (*CryptoDevCallbackFunc)(int devId, wc_CryptoInfo* info, void* ctx); typedef int (*CryptoDevCallbackFunc)(int devId, wc_CryptoInfo* info, void* ctx);
/* old function names */
#define wc_CryptoDev_RegisterDevice wc_CryptoCb_RegisterDevice
#define wc_CryptoDev_UnRegisterDevice wc_CryptoCb_UnRegisterDevice
#endif
typedef int (*wc_CryptoCallbackFunc)(int devId, wc_CryptoInfo* info, void* ctx);
WOLFSSL_LOCAL void wc_CryptoCb_Init(void);
WOLFSSL_LOCAL void wc_CryptoDev_Init(void); WOLFSSL_API int wc_CryptoCb_RegisterDevice(int devId, wc_CryptoCallbackFunc cb, void* ctx);
WOLFSSL_API void wc_CryptoCb_UnRegisterDevice(int devId);
WOLFSSL_API int wc_CryptoDev_RegisterDevice(int devId, CryptoDevCallbackFunc cb, void* ctx);
WOLFSSL_API void wc_CryptoDev_UnRegisterDevice(int devId);
#ifndef NO_RSA #ifndef NO_RSA
WOLFSSL_LOCAL int wc_CryptoDev_Rsa(const byte* in, word32 inLen, byte* out, WOLFSSL_LOCAL int wc_CryptoCb_Rsa(const byte* in, word32 inLen, byte* out,
word32* outLen, int type, RsaKey* key, WC_RNG* rng); word32* outLen, int type, RsaKey* key, WC_RNG* rng);
#ifdef WOLFSSL_KEY_GEN #ifdef WOLFSSL_KEY_GEN
WOLFSSL_LOCAL int wc_CryptoDev_MakeRsaKey(RsaKey* key, int size, long e, WOLFSSL_LOCAL int wc_CryptoCb_MakeRsaKey(RsaKey* key, int size, long e,
WC_RNG* rng); WC_RNG* rng);
#endif /* WOLFSSL_KEY_GEN */ #endif /* WOLFSSL_KEY_GEN */
#endif /* !NO_RSA */ #endif /* !NO_RSA */
#ifdef HAVE_ECC #ifdef HAVE_ECC
WOLFSSL_LOCAL int wc_CryptoDev_MakeEccKey(WC_RNG* rng, int keySize, WOLFSSL_LOCAL int wc_CryptoCb_MakeEccKey(WC_RNG* rng, int keySize,
ecc_key* key, int curveId); ecc_key* key, int curveId);
WOLFSSL_LOCAL int wc_CryptoDev_Ecdh(ecc_key* private_key, ecc_key* public_key, WOLFSSL_LOCAL int wc_CryptoCb_Ecdh(ecc_key* private_key, ecc_key* public_key,
byte* out, word32* outlen); byte* out, word32* outlen);
WOLFSSL_LOCAL int wc_CryptoDev_EccSign(const byte* in, word32 inlen, byte* out, WOLFSSL_LOCAL int wc_CryptoCb_EccSign(const byte* in, word32 inlen, byte* out,
word32 *outlen, WC_RNG* rng, ecc_key* key); word32 *outlen, WC_RNG* rng, ecc_key* key);
WOLFSSL_LOCAL int wc_CryptoDev_EccVerify(const byte* sig, word32 siglen, WOLFSSL_LOCAL int wc_CryptoCb_EccVerify(const byte* sig, word32 siglen,
const byte* hash, word32 hashlen, int* res, ecc_key* key); const byte* hash, word32 hashlen, int* res, ecc_key* key);
#endif /* HAVE_ECC */ #endif /* HAVE_ECC */
#ifndef NO_AES #ifndef NO_AES
#ifdef HAVE_AESGCM #ifdef HAVE_AESGCM
WOLFSSL_LOCAL int wc_CryptoDev_AesGcmEncrypt(Aes* aes, byte* out, WOLFSSL_LOCAL int wc_CryptoCb_AesGcmEncrypt(Aes* aes, byte* out,
const byte* in, word32 sz, const byte* iv, word32 ivSz, const byte* in, word32 sz, const byte* iv, word32 ivSz,
byte* authTag, word32 authTagSz, const byte* authIn, word32 authInSz); byte* authTag, word32 authTagSz, const byte* authIn, word32 authInSz);
WOLFSSL_LOCAL int wc_CryptoDev_AesGcmDecrypt(Aes* aes, byte* out, WOLFSSL_LOCAL int wc_CryptoCb_AesGcmDecrypt(Aes* aes, byte* out,
const byte* in, word32 sz, const byte* iv, word32 ivSz, const byte* in, word32 sz, const byte* iv, word32 ivSz,
const byte* authTag, word32 authTagSz, const byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz); const byte* authIn, word32 authInSz);
#endif /* HAVE_AESGCM */ #endif /* HAVE_AESGCM */
#ifdef HAVE_AES_CBC #ifdef HAVE_AES_CBC
WOLFSSL_LOCAL int wc_CryptoDev_AesCbcEncrypt(Aes* aes, byte* out, WOLFSSL_LOCAL int wc_CryptoCb_AesCbcEncrypt(Aes* aes, byte* out,
const byte* in, word32 sz); const byte* in, word32 sz);
WOLFSSL_LOCAL int wc_CryptoDev_AesCbcDecrypt(Aes* aes, byte* out, WOLFSSL_LOCAL int wc_CryptoCb_AesCbcDecrypt(Aes* aes, byte* out,
const byte* in, word32 sz); const byte* in, word32 sz);
#endif /* HAVE_AES_CBC */ #endif /* HAVE_AES_CBC */
#endif /* !NO_AES */ #endif /* !NO_AES */
#ifndef NO_SHA #ifndef NO_SHA
WOLFSSL_LOCAL int wc_CryptoDev_ShaHash(wc_Sha* sha, const byte* in, WOLFSSL_LOCAL int wc_CryptoCb_ShaHash(wc_Sha* sha, const byte* in,
word32 inSz, byte* digest); word32 inSz, byte* digest);
#endif /* !NO_SHA */ #endif /* !NO_SHA */
#ifndef NO_SHA256 #ifndef NO_SHA256
WOLFSSL_LOCAL int wc_CryptoDev_Sha256Hash(wc_Sha256* sha256, const byte* in, WOLFSSL_LOCAL int wc_CryptoCb_Sha256Hash(wc_Sha256* sha256, const byte* in,
word32 inSz, byte* digest); word32 inSz, byte* digest);
#endif /* !NO_SHA256 */ #endif /* !NO_SHA256 */
#ifndef WC_NO_RNG #ifndef WC_NO_RNG
WOLFSSL_LOCAL int wc_CryptoDev_RandomBlock(WC_RNG* rng, byte* out, word32 sz); WOLFSSL_LOCAL int wc_CryptoCb_RandomBlock(WC_RNG* rng, byte* out, word32 sz);
#endif #endif
#endif /* WOLF_CRYPTO_DEV */ #endif /* WOLF_CRYPTO_CB */
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif
#endif /* _WOLF_CRYPTO_DEV_H_ */ #endif /* _WOLF_CRYPTO_CB_H_ */

View File

@ -357,7 +357,7 @@ struct ecc_key {
int slot; /* Key Slot Number (-1 unknown) */ int slot; /* Key Slot Number (-1 unknown) */
byte pubkey_raw[ECC_MAX_CRYPTO_HW_PUBKEY_SIZE]; byte pubkey_raw[ECC_MAX_CRYPTO_HW_PUBKEY_SIZE];
#endif #endif
#if defined(PLUTON_CRYPTO_ECC) || defined(WOLF_CRYPTO_DEV) #if defined(PLUTON_CRYPTO_ECC) || defined(WOLF_CRYPTO_CB)
int devId; int devId;
#endif #endif
#ifdef WOLFSSL_ASYNC_CRYPT #ifdef WOLFSSL_ASYNC_CRYPT

View File

@ -62,7 +62,7 @@ nobase_include_HEADERS+= \
wolfssl/wolfcrypt/wolfmath.h \ wolfssl/wolfcrypt/wolfmath.h \
wolfssl/wolfcrypt/sha3.h \ wolfssl/wolfcrypt/sha3.h \
wolfssl/wolfcrypt/cpuid.h \ wolfssl/wolfcrypt/cpuid.h \
wolfssl/wolfcrypt/cryptodev.h wolfssl/wolfcrypt/cryptocb.h
noinst_HEADERS+= \ noinst_HEADERS+= \
wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h \ wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h \

View File

@ -158,7 +158,7 @@ struct WC_RNG {
#ifdef WOLFSSL_ASYNC_CRYPT #ifdef WOLFSSL_ASYNC_CRYPT
WC_ASYNC_DEV asyncDev; WC_ASYNC_DEV asyncDev;
#endif #endif
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_DEV) #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
int devId; int devId;
#endif #endif
}; };

View File

@ -155,7 +155,7 @@ struct RsaKey {
#ifdef WC_RSA_BLINDING #ifdef WC_RSA_BLINDING
WC_RNG* rng; /* for PrivateDecrypt blinding */ WC_RNG* rng; /* for PrivateDecrypt blinding */
#endif #endif
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
int devId; int devId;
#endif #endif
#ifdef WOLFSSL_ASYNC_CRYPT #ifdef WOLFSSL_ASYNC_CRYPT

View File

@ -1863,6 +1863,12 @@ extern void uITRON4_free(void *p) ;
#define WOLFSSL_NO_FORCE_ZERO #define WOLFSSL_NO_FORCE_ZERO
#endif #endif
/* Detect old cryptodev name */
#if defined(WOLF_CRYPTO_DEV) && !defined(WOLF_CRYPTO_CB)
#define WOLF_CRYPTO_CB
#endif
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif

View File

@ -123,7 +123,7 @@ typedef struct wc_Sha {
#ifdef WOLFSSL_ASYNC_CRYPT #ifdef WOLFSSL_ASYNC_CRYPT
WC_ASYNC_DEV asyncDev; WC_ASYNC_DEV asyncDev;
#endif /* WOLFSSL_ASYNC_CRYPT */ #endif /* WOLFSSL_ASYNC_CRYPT */
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
int devId; int devId;
void* devCtx; /* generic crypto callback context */ void* devCtx; /* generic crypto callback context */
#endif #endif

View File

@ -158,7 +158,7 @@ typedef struct wc_Sha256 {
!defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH) !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)
WC_ESP32SHA ctx; WC_ESP32SHA ctx;
#endif #endif
#ifdef WOLF_CRYPTO_DEV #ifdef WOLF_CRYPTO_CB
int devId; int devId;
void* devCtx; /* generic crypto callback context */ void* devCtx; /* generic crypto callback context */
#endif #endif

View File

@ -26,7 +26,11 @@
#ifdef HAVE_PKCS11 #ifdef HAVE_PKCS11
#include <wolfssl/wolfcrypt/cryptodev.h> #ifndef WOLF_CRYPTO_CB
#error PKCS11 support requires ./configure --enable-cryptocb or WOLF_CRYPTO_CB to be defined
#endif
#include <wolfssl/wolfcrypt/cryptocb.h>
#include <wolfssl/wolfcrypt/pkcs11.h> #include <wolfssl/wolfcrypt/pkcs11.h>
typedef struct Pkcs11Dev { typedef struct Pkcs11Dev {