add macro guards to handle build with QNX CAAM

This commit is contained in:
Jacob Barthelmeh
2022-03-09 16:48:58 -07:00
parent 9bf2962852
commit 40c79b1134
4 changed files with 42 additions and 16 deletions

View File

@ -1891,12 +1891,14 @@ AC_ARG_ENABLE([caam],
)
if test "$ENABLED_CAAM" = "yes"
then
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_IMX6_CAAM"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CAAM -DWOLFSSL_IMX6_CAAM"
fi
if test "$ENABLED_CAAM" = "qnx"
then
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_IMX6_CAAM -DWOLFSSL_QNX_CAAM"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CAAM -DWOLFSSL_IMX6_CAAM -DWOLFSSL_QNX_CAAM"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CAAM_ECC"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CAAM_CMAC"
fi
if test "$ENABLED_CAAM" = "seco"
@ -1904,6 +1906,12 @@ then
SECO_DIR=$trylibsecodir
AM_CPPFLAGS="$AM_CPPFLAGS -I$SECO_DIR/include"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CAAM -DWOLFSSL_SECO_CAAM -DWOLFSSL_HASH_KEEP"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CAAM_ECC"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CAAM_CMAC"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CAAM_CIPHER"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CAAM_HMAC"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CAAM_HASH"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CAAM_CURVE25519"
AC_CHECK_LIB([hsm_lib],[hsm_open_session])
AC_CHECK_LIB([seco_nvm_manager],[seco_nvm_manager])

View File

@ -25,7 +25,7 @@
#include <wolfssl/wolfcrypt/settings.h>
#if defined(WOLFSSL_CAAM)
#if defined(WOLFSSL_CAAM) && defined(WOLFSSL_CAAM_HASH)
#include <wolfssl/wolfcrypt/logging.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
@ -74,9 +74,11 @@ static int _InitSha(byte* ctx, word32 ctxSz, void* heap, int devId,
/* Set buffer for context */
buf[0].BufferType = DataBuffer | LastBuffer;
buf[0].TheAddress = (Address)ctx;
buf[0].TheAddress = (CAAM_ADDRESS)ctx;
buf[0].Length = ctxSz + WC_CAAM_CTXLEN;
#if defined(__INTEGRITY) || defined(INTEGRITY)
buf[0].Transferred = 0;
#endif
arg[0] = CAAM_ALG_INIT;
arg[1] = ctxSz + WC_CAAM_CTXLEN;
@ -118,15 +120,19 @@ static int _ShaUpdate(wc_Sha* sha, const byte* data, word32 len, word32 digestSz
if (sha->buffLen == WC_CAAM_HASH_BLOCK) {
/* Set buffer for context */
buf[0].BufferType = DataBuffer;
buf[0].TheAddress = (Address)sha->ctx;
buf[0].TheAddress = (CAAM_ADDRESS)sha->ctx;
buf[0].Length = digestSz + WC_CAAM_CTXLEN;
#if defined(__INTEGRITY) || defined(INTEGRITY)
buf[0].Transferred = 0;
#endif
/* data to update with */
buf[1].BufferType = DataBuffer | LastBuffer;
buf[1].TheAddress = (Address)sha->buffer;
buf[1].TheAddress = (CAAM_ADDRESS)sha->buffer;
buf[1].Length = sha->buffLen;
#if defined(__INTEGRITY) || defined(INTEGRITY)
buf[1].Transferred = 0;
#endif
arg[0] = CAAM_ALG_UPDATE;
arg[1] = digestSz + WC_CAAM_CTXLEN;
@ -146,15 +152,19 @@ static int _ShaUpdate(wc_Sha* sha, const byte* data, word32 len, word32 digestSz
/* Set buffer for context */
buf[0].BufferType = DataBuffer;
buf[0].TheAddress = (Address)sha->ctx;
buf[0].TheAddress = (CAAM_ADDRESS)sha->ctx;
buf[0].Length = digestSz + WC_CAAM_CTXLEN;
#if defined(__INTEGRITY) || defined(INTEGRITY)
buf[0].Transferred = 0;
#endif
/* data to update with */
buf[1].BufferType = DataBuffer | LastBuffer;
buf[1].TheAddress = (Address)data;
buf[1].TheAddress = (CAAM_ADDRESS)data;
buf[1].Length = sz;
#if defined(__INTEGRITY) || defined(INTEGRITY)
buf[1].Transferred = 0;
#endif
arg[0] = CAAM_ALG_UPDATE;
arg[1] = digestSz + WC_CAAM_CTXLEN;
@ -407,5 +417,5 @@ int wc_CAAM_Sha512Hash(wc_Sha512* sha512, const byte* in, word32 inSz,
}
#endif /* WOLFSSL_SHA512 */
#endif /* WOLFSSL_CAAM */
#endif /* WOLFSSL_CAAM && WOLFSSL_CAAM_HASH */

View File

@ -25,7 +25,7 @@
#include <wolfssl/wolfcrypt/settings.h>
#if defined(WOLFSSL_CAAM) && !defined(NO_HMAC)
#if defined(WOLFSSL_CAAM) && !defined(NO_HMAC) && defined(WOLFSSL_CAAM_HMAC)
#include <wolfssl/wolfcrypt/logging.h>
#include <wolfssl/wolfcrypt/error-crypt.h>

View File

@ -73,7 +73,7 @@ static int wc_CAAM_router(int devId, wc_CryptoInfo* info, void* ctx)
switch (info->algo_type) {
case WC_ALGO_TYPE_PK:
switch (info->pk.type) {
#ifdef HAVE_ECC
#if defined(HAVE_ECC) && defined(WOLFSSL_CAAM_ECC)
case WC_PK_TYPE_ECDSA_SIGN:
ret = wc_CAAM_EccSign(info->pk.eccsign.in,
info->pk.eccsign.inlen, info->pk.eccsign.out,
@ -108,8 +108,8 @@ static int wc_CAAM_router(int devId, wc_CryptoInfo* info, void* ctx)
info->pk.ecc_check.pubKey,
info->pk.ecc_check.pubKeySz);
break;
#endif /* HAVE_ECC */
#ifndef NO_RSA
#endif /* HAVE_ECC && WOLFSSL_CAAM_ECC */
#if !defined(NO_RSA) && defined(WOLFSSL_DEVCRYPTO_RSA)
case WC_PK_TYPE_RSA:
ret = wc_CAAM_Rsa(info->pk.rsa.in,
info->pk.rsa.inLen,
@ -129,7 +129,7 @@ static int wc_CAAM_router(int devId, wc_CryptoInfo* info, void* ctx)
break;
#endif
#endif /* !NO_RSA */
#ifdef HAVE_CURVE25519
#if defined(HAVE_CURVE25519) && defined(WOLFSSL_CAAM_CURVE25519)
case WC_PK_TYPE_CURVE25519_KEYGEN:
ret = wc_CAAM_MakeCurve25519Key(info->pk.curve25519kg.key,
info->pk.curve25519kg.size,
@ -143,13 +143,14 @@ static int wc_CAAM_router(int devId, wc_CryptoInfo* info, void* ctx)
info->pk.curve25519.public_key,
info->pk.curve25519.endian);
break;
#endif /* HAVE_CURVE25519 */
#endif /* HAVE_CURVE25519 && WOLFSSL_CAAM_CURVE25519 */
default:
WOLFSSL_MSG("unsupported public key operation");
}
break;
case WC_ALGO_TYPE_CMAC:
#ifdef WOLFSSL_CAAM_CMAC
#ifdef WOLFSSL_SECO_CAAM
if (devId != WOLFSSL_SECO_DEVID)
break;
@ -169,9 +170,11 @@ static int wc_CAAM_router(int devId, wc_CryptoInfo* info, void* ctx)
WOLFSSL_MSG("CMAC not compiled in");
ret = NOT_COMPILED_IN;
#endif
#endif /* WOLFSSL_CAAM_CMAC */
break;
case WC_ALGO_TYPE_HASH:
#ifdef WOLFSSL_CAAM_HASH
#ifdef WOLFSSL_SECO_CAAM
switch(info->hash.type) {
#ifdef WOLFSSL_SHA224
@ -209,18 +212,22 @@ static int wc_CAAM_router(int devId, wc_CryptoInfo* info, void* ctx)
ret = CRYPTOCB_UNAVAILABLE;
}
#endif
#endif /* WOLFSSL_CAAM_HASH */
break;
case WC_ALGO_TYPE_HMAC:
#if defined(WOLFSSL_CAAM_HMAC)
ret = wc_CAAM_Hmac(info->hmac.hmac,
info->hmac.macType,
info->hmac.in, info->hmac.inSz,
info->hmac.digest);
#endif
break;
case WC_ALGO_TYPE_CIPHER:
#ifdef WOLFSSL_CAAM_CIPHER
#ifdef WOLFSSL_SECO_CAAM
if (devId == WOLFSSL_CAAM_DEVID)
if (devId != WOLFSSL_SECO_DEVID)
break; /* only call to SECO if using WOLFSSL_SECO_DEVID */
#endif
switch (info->cipher.type) {
@ -316,6 +323,7 @@ static int wc_CAAM_router(int devId, wc_CryptoInfo* info, void* ctx)
}
#endif /* HAVE_AES_ECB */
}
#endif /* WOLFSSL_CAAM_CIPHER */
break;
case WC_ALGO_TYPE_RNG: