1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2026-06-15 00:56:07 -05:00

Crypto: fix no-SSE2 x86 fallback paths

Guard BLAKE2s x86 SIMD dispatch on compiled SSE2 intrinsic support so NOSSE2 builds do not reference missing compressor symbols.

Make Argon2 AVX2/SSE2 stubs fall back to the next available implementation instead of returning ARGON2_INCORRECT_PARAMETER when runtime CPU flags outpace build capabilities.
This commit is contained in:
Mounir IDRASSI
2026-06-05 15:20:34 +09:00
parent 0feecd019a
commit df3bb7c5e6
3 changed files with 16 additions and 8 deletions
+5 -3
View File
@@ -205,10 +205,12 @@ int fill_segment_avx2(const argon2_instance_t *instance,
return ARGON2_OK; return ARGON2_OK;
} }
#else #else
extern int fill_segment_sse2(const argon2_instance_t* instance,
argon2_position_t position);
int fill_segment_avx2(const argon2_instance_t* instance, int fill_segment_avx2(const argon2_instance_t* instance,
argon2_position_t position) { argon2_position_t position) {
(void)instance; /* AVX2-capable CPUs may reach this symbol when the AVX2 TU was built as a stub. */
(void)position; return fill_segment_sse2(instance, position);
return ARGON2_INCORRECT_PARAMETER; /* AVX2 not available */
} }
#endif #endif
+5 -3
View File
@@ -206,10 +206,12 @@ int fill_segment_sse2(const argon2_instance_t *instance,
return ARGON2_OK; return ARGON2_OK;
} }
#else #else
extern int fill_segment_ref(const argon2_instance_t* instance,
argon2_position_t position);
int fill_segment_sse2(const argon2_instance_t* instance, int fill_segment_sse2(const argon2_instance_t* instance,
argon2_position_t position) { argon2_position_t position) {
(void)instance; /* NOSSE2 builds can still run on SSE2-capable CPUs and reach this symbol. */
(void)position; return fill_segment_ref(instance, position);
return ARGON2_INCORRECT_PARAMETER; // SSE2 not available
} }
#endif #endif
+6 -2
View File
@@ -21,6 +21,10 @@
#include "Crypto/cpu.h" #include "Crypto/cpu.h"
#include "Crypto/misc.h" #include "Crypto/misc.h"
#define BLAKE2S_USE_X86_INTRINSICS \
((CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32) \
&& CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE)
// load32 is always called in SSE case which implies little endian // load32 is always called in SSE case which implies little endian
#define load32(x) *((uint32*) (x)) #define load32(x) *((uint32*) (x))
@@ -105,7 +109,7 @@ void blake2s_init_param( blake2s_state *S, const blake2s_param *P )
typedef void (*blake2s_compressFn)( blake2s_state *S, const uint8 block[BLAKE2S_BLOCKBYTES] ); typedef void (*blake2s_compressFn)( blake2s_state *S, const uint8 block[BLAKE2S_BLOCKBYTES] );
blake2s_compressFn blake2s_compress_func = NULL; blake2s_compressFn blake2s_compress_func = NULL;
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 #if BLAKE2S_USE_X86_INTRINSICS
extern int blake2s_has_sse2(); extern int blake2s_has_sse2();
extern int blake2s_has_ssse3(); extern int blake2s_has_ssse3();
extern int blake2s_has_sse41(); extern int blake2s_has_sse41();
@@ -180,7 +184,7 @@ void blake2s_init( blake2s_state *S )
if (!blake2s_compress_func) if (!blake2s_compress_func)
{ {
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 #if BLAKE2S_USE_X86_INTRINSICS
if (HasSSE2() && blake2s_has_sse2()) if (HasSSE2() && blake2s_has_sse2())
{ {
if (HasSSE41() && blake2s_has_sse41()) if (HasSSE41() && blake2s_has_sse41())