From 356b4195320d1b9ce0a70363d1a2d1fb3695ac73 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Tue, 15 Dec 2020 17:14:13 +1000 Subject: [PATCH] SP math all: fixes for different compilers and configs --- wolfcrypt/src/cpuid.c | 5 +++-- wolfcrypt/src/sp_int.c | 8 +++----- wolfssl/wolfcrypt/fe_448.h | 15 +++++++++------ wolfssl/wolfcrypt/sp_int.h | 22 ++++++++++++++-------- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/wolfcrypt/src/cpuid.c b/wolfcrypt/src/cpuid.c index 7bc852e60..006da8cf7 100644 --- a/wolfcrypt/src/cpuid.c +++ b/wolfcrypt/src/cpuid.c @@ -28,8 +28,9 @@ #include -#if defined(WOLFSSL_X86_64_BUILD) || defined(USE_INTEL_SPEEDUP) || \ - defined(WOLFSSL_AESNI) || defined(WOLFSSL_SP_X86_64_ASM) +#if (defined(WOLFSSL_X86_64_BUILD) || defined(USE_INTEL_SPEEDUP) || \ + defined(WOLFSSL_AESNI) || defined(WOLFSSL_SP_X86_64_ASM)) && \ + !defined(WOLFSSL_NO_ASM) /* Each platform needs to query info type 1 from cpuid to see if aesni is * supported. Also, let's setup a macro for proper linkage w/o ABI conflicts */ diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index bd04f6aad..53fe07a11 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -12970,10 +12970,11 @@ int sp_radix_size(sp_int* a, int radix, int* size) int sp_rand_prime(sp_int* r, int len, WC_RNG* rng, void* heap) { static const int USE_BBS = 1; - int err = MP_OKAY, type; + int err = MP_OKAY; + int type = 0; int isPrime = MP_NO; #ifdef WOLFSSL_SP_MATH_ALL - int bits; + int bits = 0; #endif /* WOLFSSL_SP_MATH_ALL */ (void)heap; @@ -12988,9 +12989,6 @@ int sp_rand_prime(sp_int* r, int len, WC_RNG* rng, void* heap) type = USE_BBS; len = -len; } - else { - type = 0; - } #ifndef WOLFSSL_SP_MATH_ALL /* For minimal maths, support only what's in SP and needed for DH. */ diff --git a/wolfssl/wolfcrypt/fe_448.h b/wolfssl/wolfcrypt/fe_448.h index 352311609..bcf8815a2 100644 --- a/wolfssl/wolfcrypt/fe_448.h +++ b/wolfssl/wolfcrypt/fe_448.h @@ -46,12 +46,15 @@ #if defined(CURVED448_128BIT) typedef int64_t fe448; - #ifdef __SIZEOF_INT128__ - typedef __uint128_t uint128_t; - typedef __int128_t int128_t; - #else - typedef unsigned long uint128_t __attribute__ ((mode(TI))); - typedef long int128_t __attribute__ ((mode(TI))); + #ifndef WOLFSSL_UINT128_T_DEFINED + #ifdef __SIZEOF_INT128__ + typedef __uint128_t uint128_t; + typedef __int128_t int128_t; + #else + typedef unsigned long uint128_t __attribute__ ((mode(TI))); + typedef long int128_t __attribute__ ((mode(TI))); + #endif + #define WOLFSSL_UINT128_T_DEFINED #endif #else typedef int32_t fe448; diff --git a/wolfssl/wolfcrypt/sp_int.h b/wolfssl/wolfcrypt/sp_int.h index 1e5b4be83..03aa23f25 100644 --- a/wolfssl/wolfcrypt/sp_int.h +++ b/wolfssl/wolfcrypt/sp_int.h @@ -206,15 +206,21 @@ extern "C" { /* Define the types used. */ #ifdef HAVE___UINT128_T #ifdef __SIZEOF_INT128__ - typedef __uint128_t sp_uint128; - typedef __int128_t sp_int128; - typedef __uint128_t uint128_t; - typedef __int128_t int128_t; + typedef __uint128_t sp_uint128; + typedef __int128_t sp_int128; #else - typedef unsigned long sp_uint128 __attribute__ ((mode(TI))); - typedef long sp_int128 __attribute__ ((mode(TI))); - typedef unsigned long uint128_t __attribute__ ((mode(TI))); - typedef long int128_t __attribute__ ((mode(TI))); + typedef unsigned long sp_uint128 __attribute__ ((mode(TI))); + typedef long sp_int128 __attribute__ ((mode(TI))); + #endif + #ifndef WOLFSSL_UINT128_T_DEFINED + #ifdef __SIZEOF_INT128__ + typedef __uint128_t uint128_t; + typedef __int128_t int128_t; + #else + typedef unsigned long uint128_t __attribute__ ((mode(TI))); + typedef long int128_t __attribute__ ((mode(TI))); + #endif + #define WOLFSSL_UINT128_T_DEFINED #endif #endif