From 2abb2eae7d6bc0028f53115ddc0e061cd6f01541 Mon Sep 17 00:00:00 2001 From: David Garske Date: Mon, 1 Nov 2021 16:18:59 -0700 Subject: [PATCH] Changed NXP SE050 to not use symmetric offloading by default. If desired use `WOLFSSL_SE050_HASH` and `WOLFSSL_SE050_CRYPT`. --- configure.ac | 3 +++ wolfcrypt/src/aes.c | 10 +++++----- wolfcrypt/src/port/nxp/README.md | 3 +++ wolfcrypt/src/sha.c | 4 ++-- wolfcrypt/src/sha256.c | 6 +++--- wolfcrypt/src/sha512.c | 20 ++++++++++---------- wolfssl/wolfcrypt/sha.h | 4 ++-- wolfssl/wolfcrypt/sha256.h | 4 ++-- 8 files changed, 30 insertions(+), 24 deletions(-) diff --git a/configure.ac b/configure.ac index 72d96f51d..482282c0b 100644 --- a/configure.ac +++ b/configure.ac @@ -1451,6 +1451,9 @@ AC_ARG_WITH([se050], # Requires AES direct AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_AES_DIRECT" + # Does not support SHA2-512 224/256 + AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_NOSHA512_224 -DWOLFSSL_NOSHA512_256" + AC_MSG_RESULT([yes]) else AC_MSG_RESULT([yes]) diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index eb41c25d0..50cd7d4e6 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -68,7 +68,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits #ifdef WOLFSSL_IMXRT_DCP #include #endif -#ifdef WOLFSSL_SE050 +#if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_CRYPT) #include #endif @@ -867,7 +867,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits #elif defined(WOLFSSL_DEVCRYPTO_AES) /* implemented in wolfcrypt/src/port/devcrypto/devcrypto_aes.c */ -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_CRYPT) static int AES_ECB_encrypt(Aes* aes, const byte* inBlock, byte* outBlock, int sz) { @@ -2598,7 +2598,7 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock) return wc_AesSetKey(aes, userKey, keylen, iv, dir); } -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_CRYPT) int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv, int dir) { @@ -3876,7 +3876,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv) #elif defined(WOLFSSL_DEVCRYPTO_CBC) /* implemented in wolfcrypt/src/port/devcrypt/devcrypto_aes.c */ -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_CRYPT) int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) { return se050_aes_crypt(aes, in, out, sz, AES_ENCRYPTION, @@ -10363,7 +10363,7 @@ void wc_AesFree(Aes* aes) } #endif -#if defined(WOLFSSL_SE050) +#if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_CRYPT) se050_aes_free(aes); #endif diff --git a/wolfcrypt/src/port/nxp/README.md b/wolfcrypt/src/port/nxp/README.md index ba47856ce..ad2ebe9de 100644 --- a/wolfcrypt/src/port/nxp/README.md +++ b/wolfcrypt/src/port/nxp/README.md @@ -44,6 +44,9 @@ make Where `PATH` is the directory location of `simw-top`. Example: `./configure --enable-debug --disable-shared --with-se050=/home/pi/simw-top CFLAGS="-DWOLFSSL_SE050_INIT"` +To enable AES Cipher support use `WOLFSSL_SE050_CRYPT` +To enable SHA-1 and SHA-2 support use `WOLFSSL_SE050_HASH` + ## Building Examples Confirm that you are able to run the examples from the directory: diff --git a/wolfcrypt/src/sha.c b/wolfcrypt/src/sha.c index c5b46d5e5..cf94def92 100644 --- a/wolfcrypt/src/sha.c +++ b/wolfcrypt/src/sha.c @@ -336,7 +336,7 @@ #elif defined(WOLFSSL_SILABS_SE_ACCEL) /* implemented in wolfcrypt/src/port/silabs/silabs_hash.c */ -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #include int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId) @@ -846,7 +846,7 @@ void wc_ShaFree(wc_Sha* sha) #ifdef WOLFSSL_PIC32MZ_HASH wc_ShaPic32Free(sha); #endif -#ifdef WOLFSSL_SE050 +#if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) se050_hash_free(&sha->se050Ctx); #endif #if (defined(WOLFSSL_RENESAS_TSIP_CRYPT) && \ diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index 117c834d0..0aa3ff75c 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -184,7 +184,7 @@ where 0 <= L < 2^64. (!defined(WOLFSSL_ESP32WROOM32_CRYPT) || defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH)) && \ (!defined(WOLFSSL_RENESAS_TSIP_CRYPT) || defined(NO_WOLFSSL_RENESAS_TSIP_HASH)) && \ !defined(WOLFSSL_PSOC6_CRYPTO) && !defined(WOLFSSL_IMXRT_DCP) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \ - !defined(WOLFSSL_KCAPI_HASH) && !defined(WOLFSSL_SE050) + !defined(WOLFSSL_KCAPI_HASH) && !defined(WOLFSSL_SE050_HASH) static int InitSha256(wc_Sha256* sha256) @@ -585,7 +585,7 @@ static int InitSha256(wc_Sha256* sha256) !defined(WOLFSSL_QNX_CAAM) /* functions defined in wolfcrypt/src/port/caam/caam_sha256.c */ -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #include int wc_InitSha256_ex(wc_Sha256* sha256, void* heap, int devId) @@ -1411,7 +1411,7 @@ static int InitSha256(wc_Sha256* sha256) return ret; } -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #include int wc_InitSha224_ex(wc_Sha224* sha224, void* heap, int devId) diff --git a/wolfcrypt/src/sha512.c b/wolfcrypt/src/sha512.c index 6d59192a7..77b472241 100644 --- a/wolfcrypt/src/sha512.c +++ b/wolfcrypt/src/sha512.c @@ -49,7 +49,7 @@ #include #endif -#ifdef WOLFSSL_SE050 +#if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #include #endif @@ -203,7 +203,7 @@ #elif defined(WOLFSSL_KCAPI_HASH) /* functions defined in wolfcrypt/src/port/kcapi/kcapi_hash.c */ -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) int wc_InitSha512(wc_Sha512* sha512) { if (sha512 == NULL) @@ -952,7 +952,7 @@ int wc_Sha512Update(wc_Sha512* sha512, const byte* data, word32 len) #if defined(WOLFSSL_KCAPI_HASH) /* functions defined in wolfcrypt/src/port/kcapi/kcapi_hash.c */ -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #else @@ -1063,7 +1063,7 @@ static WC_INLINE int Sha512Final(wc_Sha512* sha512) #if defined(WOLFSSL_KCAPI_HASH) /* functions defined in wolfcrypt/src/port/kcapi/kcapi_hash.c */ -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #else @@ -1135,7 +1135,7 @@ int wc_Sha512Final(wc_Sha512* sha512, byte* hash) #endif /* WOLFSSL_KCAPI_HASH */ -#ifndef WOLFSSL_SE050 +#if !defined(WOLFSSL_SE050) || !defined(WOLFSSL_SE050_HASH) int wc_InitSha512(wc_Sha512* sha512) { return wc_InitSha512_ex(sha512, NULL, INVALID_DEVID); @@ -1217,7 +1217,7 @@ int wc_Sha512Transform(wc_Sha512* sha, const unsigned char* data) } #endif /* OPENSSL_EXTRA */ #endif /* WOLFSSL_SHA512 */ -#endif /* !WOLFSSL_SE050 */ +#endif /* !WOLFSSL_SE050 || !WOLFSSL_SE050_HASH */ /* -------------------------------------------------------------------------- */ @@ -1228,7 +1228,7 @@ int wc_Sha512Transform(wc_Sha512* sha, const unsigned char* data) #if defined(WOLFSSL_IMX6_CAAM) && !defined(NO_IMX6_CAAM_HASH) && \ !defined(WOLFSSL_QNX_CAAM) /* functions defined in wolfcrypt/src/port/caam/caam_sha.c */ -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) int wc_InitSha384_ex(wc_Sha384* sha384, void* heap, int devId) { if (sha384 == NULL) { @@ -1566,7 +1566,7 @@ int wc_Sha512_224Update(wc_Sha512* sha, const byte* data, word32 len) #if defined(WOLFSSL_KCAPI_HASH) /* functions defined in wolfcrypt/src/port/kcapi/kcapi_hash.c */ -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #else int wc_Sha512_224FinalRaw(wc_Sha512* sha, byte* hash) @@ -1585,7 +1585,7 @@ void wc_Sha512_224Free(wc_Sha512* sha) } #if defined(WOLFSSL_KCAPI_HASH) /* functions defined in wolfcrypt/src/port/kcapi/kcapi_hash.c */ -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #else @@ -1630,7 +1630,7 @@ int wc_Sha512_256Update(wc_Sha512* sha, const byte* data, word32 len) } #if defined(WOLFSSL_KCAPI_HASH) /* functions defined in wolfcrypt/src/port/kcapi/kcapi_hash.c */ -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #else int wc_Sha512_256FinalRaw(wc_Sha512* sha, byte* hash) diff --git a/wolfssl/wolfcrypt/sha.h b/wolfssl/wolfcrypt/sha.h index 6944b1897..8338264d2 100644 --- a/wolfssl/wolfcrypt/sha.h +++ b/wolfssl/wolfcrypt/sha.h @@ -110,7 +110,7 @@ enum { #include "wolfssl/wolfcrypt/port/Renesas/renesas-tsip-crypt.h" #else -#if defined(WOLFSSL_SE050) +#if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #include "wolfssl/wolfcrypt/port/nxp/se050_port.h" #endif @@ -118,7 +118,7 @@ enum { struct wc_Sha { #ifdef FREESCALE_LTC_SHA ltc_hash_ctx_t ctx; -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) SE050_HASH_Context se050Ctx; #elif defined(STM32_HASH) STM32_HASH_Context stmCtx; diff --git a/wolfssl/wolfcrypt/sha256.h b/wolfssl/wolfcrypt/sha256.h index 7759823f3..13ddea2da 100644 --- a/wolfssl/wolfcrypt/sha256.h +++ b/wolfssl/wolfcrypt/sha256.h @@ -144,7 +144,7 @@ enum { #include "wolfssl/wolfcrypt/port/Renesas/renesas-tsip-crypt.h" #else -#if defined(WOLFSSL_SE050) +#if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) #include "wolfssl/wolfcrypt/port/nxp/se050_port.h" #endif @@ -152,7 +152,7 @@ enum { struct wc_Sha256 { #ifdef FREESCALE_LTC_SHA ltc_hash_ctx_t ctx; -#elif defined(WOLFSSL_SE050) +#elif defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_HASH) SE050_HASH_Context se050Ctx; #elif defined(STM32_HASH_SHA2) STM32_HASH_Context stmCtx;