From 17659ed48cd8833273ed0b75e7c42bfa3354ad8a Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Tue, 28 Jun 2022 18:15:28 -0500 Subject: [PATCH 1/4] configure.ac: when --enable-fips=disabled, don't touch DEF_SP_MATH/DEF_FAST_MATH; don't enable sp-math-all asm gates when !ENABLED_ASM; add --with-arm-target to allow selecting thumb or cortex in conjunction with a full --host tuple (e.g. --host=armv6zk-softfloat-linux-gnueabi --with-arm-target=thumb). --- configure.ac | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 3ae465c94..4a1189e30 100644 --- a/configure.ac +++ b/configure.ac @@ -291,8 +291,6 @@ AS_CASE([$ENABLED_FIPS], [disabled],[ FIPS_VERSION="disabled" ENABLED_FIPS="no" - DEF_SP_MATH="no" - DEF_FAST_MATH="yes" ], [v1|yes|cert2425],[ FIPS_VERSION="v1" @@ -6480,7 +6478,12 @@ do esac done -if test "$ENABLED_SP_MATH_ALL" = "yes"; then +AC_ARG_WITH([arm-target], + [AS_HELP_STRING([--with-arm-target=x],[x can be "thumb" or "cortex"])], + [ARM_TARGET="$withval"], + [ARM_TARGET='']) + +if test "$ENABLED_SP_MATH_ALL" = "yes" && test "$ENABLED_ASM" != "no"; then ENABLED_FASTMATH="no" ENABLED_SLOWMATH="no" @@ -6498,10 +6501,10 @@ if test "$ENABLED_SP_MATH_ALL" = "yes"; then AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_ARM64 -DWOLFSSL_AARCH64_BUILD" ;; *arm*) - if test $host_alias = "thumb"; then + if test "$host_alias" = "thumb" || test "$ARM_TARGET" = "thumb"; then AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_ARM_THUMB" else - if test $host_alias = "cortex"; then + if test "$host_alias" = "cortex" || test "$ARM_TARGET" = "cortex"; then AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_ARM_CORTEX_M" else AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_ARM32" @@ -6554,12 +6557,12 @@ if test "$ENABLED_SP_ASM" = "yes" && test "$ENABLED_SP" = "yes"; then ENABLED_SP_ARM64_ASM=yes ;; *arm*) - if test $host_alias = "thumb"; then + if test "$host_alias" = "thumb" || test "$ARM_TARGET" = "thumb"; then AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_ARM_THUMB_ASM" AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SP_ARM_THUMB_ASM" ENABLED_SP_ARM_THUMB_ASM=yes else - if test $host_alias = "cortex"; then + if test "$host_alias" = "cortex" || test "$ARM_TARGET" = "cortex"; then AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_ARM_CORTEX_M_ASM" AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SP_ARM_CORTEX_M_ASM" ENABLED_SP_ARM_CORTEX_ASM=yes @@ -7128,10 +7131,10 @@ AM_CFLAGS=$NEW_AM_CFLAGS]) case $host_cpu in *arm*) - if test $host_alias = "thumb"; then + if test "$host_alias" = "thumb" || test "$ARM_TARGET" = "thumb"; then AM_CFLAGS="$AM_CFLAGS -mthumb -march=armv6" else - if test $host_alias = "cortex"; then + if test "$host_alias" = "cortex" || test "$ARM_TARGET" = "cortex"; then AM_CFLAGS="$AM_CFLAGS -mcpu=cortex-r5" fi fi From ce61653a9ac24270d45e8e46d545ff7a58475528 Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Tue, 28 Jun 2022 18:18:42 -0500 Subject: [PATCH 2/4] wolfcrypt/src/asn.c: fixes for ARM portability (GetASN_Items()), unintended fallthrough (OidFromId()), and uninitialized variable (DecodeSubjInfoAcc()). --- wolfcrypt/src/asn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 907e34727..4c08820fc 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -1329,7 +1329,7 @@ int GetASN_Items(const ASNItem* asn, ASNGetData *data, int count, int complete, word32 endIdx[GET_ASN_MAX_DEPTH] = { length, length, length, length, length, length, length }; /* Set choices to -1 to indicate they haven't been seen or found. */ - char choiceMet[GET_ASN_MAX_CHOICES] = { -1, -1 }; + signed char choiceMet[GET_ASN_MAX_CHOICES] = { -1, -1 }; /* Not matching a choice right now. */ int choice = 0; /* Current depth of ASN.1 item. */ @@ -4728,6 +4728,7 @@ const byte* OidFromId(word32 id, word32 type, word32* oidSz) case AIA_CA_REPO_OID: oid = extAuthInfoCaRespOid; *oidSz = sizeof(extAuthInfoCaRespOid); + break; #endif /* WOLFSSL_SUBJ_INFO_ACC */ default: break; @@ -17300,7 +17301,7 @@ static int DecodeSubjInfoAcc(const byte* input, int sz, DecodedCert* cert) */ while (idx < (word32)sz) { - word32 oid; + word32 oid = 0; byte b; /* Unwrap an AccessDescription */ From 90aaeb283e9f80171f1e99f3a2565f78ac91c4b1 Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Tue, 28 Jun 2022 18:19:58 -0500 Subject: [PATCH 3/4] wolfcrypt/src/siphash.c: add missing !WOLFSSL_NO_ASM clause in gate around inline asm. --- wolfcrypt/src/siphash.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/siphash.c b/wolfcrypt/src/siphash.c index d14c9c967..021a3115b 100644 --- a/wolfcrypt/src/siphash.c +++ b/wolfcrypt/src/siphash.c @@ -352,7 +352,7 @@ int wc_SipHashFinal(SipHash* sipHash, unsigned char* out, unsigned char outSz) return ret; } -#if defined(__GNUC__) && defined(__x86_64__) && \ +#if !defined(WOLFSSL_NO_ASM) && defined(__GNUC__) && defined(__x86_64__) && \ (WOLFSSL_SIPHASH_CROUNDS == 1 || WOLFSSL_SIPHASH_CROUNDS == 2) && \ (WOLFSSL_SIPHASH_DROUNDS == 2 || WOLFSSL_SIPHASH_DROUNDS == 4) @@ -566,7 +566,7 @@ int wc_SipHash(const unsigned char* key, const unsigned char* in, word32 inSz, return 0; } -#elif defined(__GNUC__) && defined(__aarch64__) && \ +#elif !defined(WOLFSSL_NO_ASM) && defined(__GNUC__) && defined(__aarch64__) && \ (WOLFSSL_SIPHASH_CROUNDS == 1 || WOLFSSL_SIPHASH_CROUNDS == 2) && \ (WOLFSSL_SIPHASH_DROUNDS == 2 || WOLFSSL_SIPHASH_DROUNDS == 4) From 5adf7e4eb77ada5e549dbf3a3f38cd77e19a2d15 Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Tue, 28 Jun 2022 19:14:58 -0500 Subject: [PATCH 4/4] wolfcrypt/src/asn.c wc_BuildEccKeyDer(): fix for clang-analyzer-deadcode.DeadStores. --- wolfcrypt/src/asn.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 4c08820fc..e75a65ce7 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -29351,17 +29351,19 @@ static int wc_BuildEccKeyDer(ecc_key* key, byte* output, word32 *inLen, SetASNItem_NoOutNode(dataASN, eccKeyASN, ECCKEYASN_IDX_PARAMS, eccKeyASN_Length); } - if (pubIn) { - /* Leave space for public key. */ - SetASN_Buffer(&dataASN[ECCKEYASN_IDX_PUBKEY_VAL], NULL, pubSz); + if (ret == 0) { + if (pubIn) { + /* Leave space for public key. */ + SetASN_Buffer(&dataASN[ECCKEYASN_IDX_PUBKEY_VAL], NULL, pubSz); + } + else { + /* Don't write out public key. */ + SetASNItem_NoOutNode(dataASN, eccKeyASN, ECCKEYASN_IDX_PUBKEY, + eccKeyASN_Length); + } + /* Calculate size of the private key encoding. */ + ret = SizeASN_Items(eccKeyASN, dataASN, eccKeyASN_Length, &sz); } - else { - /* Don't write out public key. */ - SetASNItem_NoOutNode(dataASN, eccKeyASN, ECCKEYASN_IDX_PUBKEY, - eccKeyASN_Length); - } - /* Calculate size of the private key encoding. */ - ret = SizeASN_Items(eccKeyASN, dataASN, eccKeyASN_Length, &sz); } /* Return the size if no buffer. */ if ((ret == 0) && (output == NULL)) {