From 9dd8baecc0478eaf853f568cc1d99bb1b5393343 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Wed, 15 Nov 2017 16:56:19 +1000 Subject: [PATCH] Fix when RORX implementations are compiled and used --- wolfcrypt/src/sha256.c | 33 ++++++++++++++++----------------- wolfcrypt/src/sha512.c | 31 ++++++++++++++++--------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index 9b237cc0d..321106f07 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -213,10 +213,12 @@ static int InitSha256(wc_Sha256* sha256) #if defined(HAVE_INTEL_AVX2) static int Transform_Sha256_AVX2(wc_Sha256 *sha256); static int Transform_Sha256_AVX2_Len(wc_Sha256* sha256, word32 len); + #ifdef HAVE_INTEL_RORX static int Transform_Sha256_AVX1_RORX(wc_Sha256 *sha256); static int Transform_Sha256_AVX1_RORX_Len(wc_Sha256* sha256, word32 len); static int Transform_Sha256_AVX2_RORX(wc_Sha256 *sha256); static int Transform_Sha256_AVX2_RORX_Len(wc_Sha256* sha256, word32 len); + #endif #endif static int (*Transform_Sha256_p)(wc_Sha256* sha256); /* = _Transform_Sha256 */ @@ -235,7 +237,7 @@ static int InitSha256(wc_Sha256* sha256) intel_flags = cpuid_get_flags(); - #if defined(HAVE_INTEL_AVX2) + #ifdef HAVE_INTEL_AVX2 if (IS_INTEL_AVX2(intel_flags)) { #ifdef HAVE_INTEL_RORX if (IS_INTEL_BMI2(intel_flags)) { @@ -244,26 +246,24 @@ static int InitSha256(wc_Sha256* sha256) } else #endif + if (1) { Transform_Sha256_p = Transform_Sha256_AVX2; Transform_Sha256_Len_p = Transform_Sha256_AVX2_Len; } - } - else - #endif - #if defined(HAVE_INTEL_AVX1) - if (IS_INTEL_AVX1(intel_flags)) { #ifdef HAVE_INTEL_RORX - if (IS_INTEL_BMI2(intel_flags)) { + else { Transform_Sha256_p = Transform_Sha256_AVX1_RORX; Transform_Sha256_Len_p = Transform_Sha256_AVX1_RORX_Len; } - else #endif - { - Transform_Sha256_p = Transform_Sha256_AVX1; - Transform_Sha256_Len_p = Transform_Sha256_AVX1_Len; - } + } + else + #endif + #ifdef HAVE_INTEL_AVX1 + if (IS_INTEL_AVX1(intel_flags)) { + Transform_Sha256_p = Transform_Sha256_AVX1; + Transform_Sha256_Len_p = Transform_Sha256_AVX1_Len; } else #endif @@ -1830,8 +1830,9 @@ SHA256_NOINLINE static int Transform_Sha256_AVX1_Len(wc_Sha256* sha256, return 0; } +#endif /* HAVE_INTEL_AVX1 */ -#if defined(HAVE_INTEL_RORX) +#if defined(HAVE_INTEL_AVX2) && defined(HAVE_INTEL_RORX) SHA256_NOINLINE static int Transform_Sha256_AVX1_RORX(wc_Sha256* sha256) { __asm__ __volatile__ ( @@ -1962,8 +1963,7 @@ SHA256_NOINLINE static int Transform_Sha256_AVX1_RORX_Len(wc_Sha256* sha256, return 0; } -#endif /* HAVE_INTEL_RORX */ -#endif /* HAVE_INTEL_AVX1 */ +#endif /* HAVE_INTEL_AVX2 && HAVE_INTEL_RORX */ #if defined(HAVE_INTEL_AVX2) @@ -2555,9 +2555,8 @@ SHA256_NOINLINE static int Transform_Sha256_AVX2_RORX_Len(wc_Sha256* sha256, return 0; } - #endif /* HAVE_INTEL_RORX */ -#endif /* HAVE_INTEL_AVX2 */ +#endif /* HAVE_INTEL_AVX2 */ #ifdef WOLFSSL_SHA224 diff --git a/wolfcrypt/src/sha512.c b/wolfcrypt/src/sha512.c index 377f50220..20222b524 100644 --- a/wolfcrypt/src/sha512.c +++ b/wolfcrypt/src/sha512.c @@ -130,7 +130,6 @@ #if defined(USE_INTEL_SPEEDUP) #define HAVE_INTEL_AVX1 - #if defined(__GNUC__) && ((__GNUC__ < 4) || \ (__GNUC__ == 4 && __GNUC_MINOR__ <= 8)) #define NO_AVX2_SUPPORT @@ -268,7 +267,7 @@ static int InitSha512(wc_Sha512* sha512) #if defined(HAVE_INTEL_AVX2) static int Transform_Sha512_AVX2(wc_Sha512 *sha512); static int Transform_Sha512_AVX2_Len(wc_Sha512 *sha512, word32 len); - #if defined(HAVE_INTEL_AVX1) && defined(HAVE_INTEL_AVX2) && defined(HAVE_INTEL_RORX) + #if defined(HAVE_INTEL_RORX) static int Transform_Sha512_AVX1_RORX(wc_Sha512 *sha512); static int Transform_Sha512_AVX1_RORX_Len(wc_Sha512 *sha512, word32 len); @@ -295,27 +294,30 @@ static int InitSha512(wc_Sha512* sha512) #if defined(HAVE_INTEL_AVX2) if (IS_INTEL_AVX2(intel_flags)) { + #ifdef HAVE_INTEL_RORX if (IS_INTEL_BMI2(intel_flags)) { Transform_Sha512_p = Transform_Sha512_AVX2_RORX; Transform_Sha512_Len_p = Transform_Sha512_AVX2_RORX_Len; } - else { + else + #endif + if (1) { Transform_Sha512_p = Transform_Sha512_AVX2; Transform_Sha512_Len_p = Transform_Sha512_AVX2_Len; } + #ifdef HAVE_INTEL_RORX + else { + Transform_Sha512_p = Transform_Sha512_AVX1_RORX; + Transform_Sha512_Len_p = Transform_Sha512_AVX1_RORX_Len; + } + #endif } else #endif #if defined(HAVE_INTEL_AVX1) if (IS_INTEL_AVX1(intel_flags)) { - if (!IS_INTEL_BMI2(intel_flags)) { - Transform_Sha512_p = Transform_Sha512_AVX1; - Transform_Sha512_Len_p = Transform_Sha512_AVX1_Len; - } - else { - Transform_Sha512_p = Transform_Sha512_AVX1_RORX; - Transform_Sha512_Len_p = Transform_Sha512_AVX1_RORX_Len; - } + Transform_Sha512_p = Transform_Sha512_AVX1; + Transform_Sha512_Len_p = Transform_Sha512_AVX1_Len; } else #endif @@ -1487,8 +1489,7 @@ static int Transform_Sha512_AVX1_Len(wc_Sha512* sha512, word32 len) } #endif /* HAVE_INTEL_AVX1 */ -#if defined(HAVE_INTEL_AVX2) && defined(HAVE_INTEL_AVX1) && \ - defined(HAVE_INTEL_RORX) +#if defined(HAVE_INTEL_AVX2) && defined(HAVE_INTEL_RORX) static int Transform_Sha512_AVX1_RORX(wc_Sha512* sha512) { __asm__ __volatile__ ( @@ -1645,7 +1646,7 @@ static int Transform_Sha512_AVX1_RORX_Len(wc_Sha512* sha512, word32 len) return 0; } -#endif /* HAVE_INTEL_AVX2 && HAVE_INTEL_AVX1 && HAVE_INTEL_RORX */ +#endif /* HAVE_INTEL_AVX2 && HAVE_INTEL_RORX */ #if defined(HAVE_INTEL_AVX2) static const unsigned long mBYTE_FLIP_MASK_Y[] = @@ -2528,7 +2529,7 @@ static int Transform_Sha512_AVX2_RORX_Len(wc_Sha512* sha512, word32 len) return 0; } -#endif +#endif /* HAVE_INTEL_RORX */ #endif /* HAVE_INTEL_AVX2 */