Skip to content

Commit d440f13

Browse files
committed
crypto: Guard code with ENABLE_SSE41 macro
The code in `sha_x86_shani.cpp` uses the `_mm_blend_epi16` function from the SSE4.1 instruction set. However, it is possible that SHA-NI is enabled even when SSE4.1 is disabled. This changes avoid compilation errors in such a condition.
1 parent 6ec1ca7 commit d440f13

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/Makefile.am

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ LIBBITCOIN_CRYPTO = $(LIBBITCOIN_CRYPTO_BASE)
5353
if ENABLE_SSE41
5454
LIBBITCOIN_CRYPTO_SSE41 = crypto/libbitcoin_crypto_sse41.la
5555
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_SSE41)
56+
if ENABLE_X86_SHANI
57+
LIBBITCOIN_CRYPTO_X86_SHANI = crypto/libbitcoin_crypto_x86_shani.la
58+
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_X86_SHANI)
59+
endif
5660
endif
5761
if ENABLE_AVX2
5862
LIBBITCOIN_CRYPTO_AVX2 = crypto/libbitcoin_crypto_avx2.la
5963
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_AVX2)
6064
endif
61-
if ENABLE_X86_SHANI
62-
LIBBITCOIN_CRYPTO_X86_SHANI = crypto/libbitcoin_crypto_x86_shani.la
63-
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_X86_SHANI)
64-
endif
6565
if ENABLE_ARM_SHANI
6666
LIBBITCOIN_CRYPTO_ARM_SHANI = crypto/libbitcoin_crypto_arm_shani.la
6767
LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_ARM_SHANI)
@@ -612,7 +612,7 @@ crypto_libbitcoin_crypto_x86_shani_la_LDFLAGS = $(AM_LDFLAGS) -static
612612
crypto_libbitcoin_crypto_x86_shani_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -static
613613
crypto_libbitcoin_crypto_x86_shani_la_CPPFLAGS = $(AM_CPPFLAGS)
614614
crypto_libbitcoin_crypto_x86_shani_la_CXXFLAGS += $(X86_SHANI_CXXFLAGS)
615-
crypto_libbitcoin_crypto_x86_shani_la_CPPFLAGS += -DENABLE_X86_SHANI
615+
crypto_libbitcoin_crypto_x86_shani_la_CPPFLAGS += -DENABLE_SSE41 -DENABLE_X86_SHANI
616616
crypto_libbitcoin_crypto_x86_shani_la_SOURCES = crypto/sha256_x86_shani.cpp
617617

618618
# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and

src/crypto/sha256.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ std::string SHA256AutoDetect(sha256_implementation::UseImplementation use_implem
623623
}
624624
}
625625

626-
#if defined(ENABLE_X86_SHANI)
626+
#if defined(ENABLE_SSE41) && defined(ENABLE_X86_SHANI)
627627
if (have_x86_shani) {
628628
Transform = sha256_x86_shani::Transform;
629629
TransformD64 = TransformD64Wrapper<sha256_x86_shani::Transform>;

src/crypto/sha256_x86_shani.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Written and placed in public domain by Jeffrey Walton.
77
// Based on code from Intel, and by Sean Gulley for the miTLS project.
88

9-
#ifdef ENABLE_X86_SHANI
9+
#if defined(ENABLE_SSE41) && defined(ENABLE_X86_SHANI)
1010

1111
#include <stdint.h>
1212
#include <immintrin.h>

0 commit comments

Comments
 (0)