wolfssl icon indicating copy to clipboard operation
wolfssl copied to clipboard

20240522-sha256-avx1-IS_INTEL_SHA

Open douzzer opened this issue 1 year ago • 2 comments

wolfcrypt/src/sha256.c: in WC_NO_INTERNAL_FUNCTION_POINTERS code path (linuxkm), fix oversight whereby Transform_Sha256_AVX1_Sha() was used on targets with false IS_INTEL_SHA(intel_flags). the former SHA256_AVX1 method id is now split into SHA256_AVX1_SHA and SHA256_AVX1_NOSHA, with corresponding fixes in Sha256_SetTransform(), inline_XTRANSFORM() and inline_XTRANSFORM_LEN().

tested with wolfssl-multi-test.sh ... linuxkm-all-cryptonly-intelasm-LKCAPI-insmod-mainline-fallback-fuzzing linuxkm-defaults-all-intelasm

douzzer avatar May 22 '24 19:05 douzzer

note, these are the implementations that use the SHA hardware instructions:

$ awk 'BEGIN{printed=0;}/^\.type[      ]+[^,]+,@function/{curfunc=$0;printed=0;next}/^[        ]*sha/{if (! printed){print curfunc; printed=1}}' < wolfcrypt/src/sha256_asm.S 
.type   Transform_Sha256_SSE2_Sha,@function
.type   Transform_Sha256_SSE2_Sha_Len,@function
.type   Transform_Sha256_AVX1_Sha,@function
.type   Transform_Sha256_AVX1_Sha_Len,@function

The WC_NO_INTERNAL_FUNCTION_POINTERS version of Sha256_SetTransform() already had the SSE2 implementation correctly dependent on IS_INTEL_SHA(intel_flags). With this patch, the AVX1+SHA implementation is also correctly dependent.

Note, WC_NO_INTERNAL_FUNCTION_POINTERS is currently only used by the linuxkm build, by way of the WC_C_DYNAMIC_FALLBACK flag.

douzzer avatar May 22 '24 19:05 douzzer

retest this please

douzzer avatar May 22 '24 21:05 douzzer