Fix OpenBSD 6.0 compile with GCC 4.9 (Issue 395)

This check-in also enables the 64-bit RDRAND routines for X32. The changes were with held until they could be tested. The testing occurred with Issue 395
pull/398/head
Jeffrey Walton 2017-03-22 17:26:25 -04:00
parent 2ea91ba1b9
commit d865cf9e62
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
4 changed files with 59 additions and 30 deletions

View File

@ -88,14 +88,18 @@ if(IS_BIG_ENDIAN)
add_definitions(-DIS_BIG_ENDIAN) add_definitions(-DIS_BIG_ENDIAN)
endif() endif()
# No DISABLE_NATIVE_ARCH with DISABLE_ASM for now
# See http://github.com/weidai11/cryptopp/issues/395
if(DISABLE_ASM) if(DISABLE_ASM)
add_definitions(-DCRYPTOPP_DISABLE_ASM) add_definitions(-DCRYPTOPP_DISABLE_ASM)
endif() endif()
if(DISABLE_SSSE3) if(DISABLE_SSSE3)
add_definitions(-DCRYPTOPP_DISABLE_SSSE3) add_definitions(-DCRYPTOPP_DISABLE_SSSE3)
set(DISABLE_NATIVE_ARCH 1)
endif() endif()
if(DISABLE_AESNI) if(DISABLE_AESNI)
add_definitions(-DCRYPTOPP_DISABLE_AESNI) add_definitions(-DCRYPTOPP_DISABLE_AESNI)
set(DISABLE_NATIVE_ARCH 1)
endif() endif()
if(NOT CRYPTOPP_DATA_DIR STREQUAL "") if(NOT CRYPTOPP_DATA_DIR STREQUAL "")
add_definitions(-DCRYPTOPP_DATA_DIR="${CRYPTOPP_DATA_DIR}") add_definitions(-DCRYPTOPP_DATA_DIR="${CRYPTOPP_DATA_DIR}")

View File

@ -157,6 +157,23 @@ ifeq ($(IS_X86)$(IS_X32)$(IS_CYGWIN)$(IS_MINGW)$(SUN_COMPILER),00000)
endif endif
endif endif
# .intel_syntax wasn't supported until GNU assembler 2.10
# No DISABLE_NATIVE_ARCH with CRYPTOPP_DISABLE_ASM for now
# See http://github.com/weidai11/cryptopp/issues/395
ifeq ($(HAVE_GAS)$(GAS210_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
else
ifeq ($(HAVE_GAS)$(GAS217_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3
DISABLE_NATIVE_ARCH := 1
else
ifeq ($(HAVE_GAS)$(GAS219_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI
DISABLE_NATIVE_ARCH := 1
endif
endif
endif
# BEGIN NATIVE_ARCH # BEGIN NATIVE_ARCH
# Guard use of -march=native (or -m{32|64} on some platforms) # Guard use of -march=native (or -m{32|64} on some platforms)
# Don't add anything if -march=XXX or -mtune=XXX is specified # Don't add anything if -march=XXX or -mtune=XXX is specified
@ -220,19 +237,6 @@ CXXFLAGS += -DCRYPTOPP_CLANG_INTEGRATED_ASSEMBLER=1
endif endif
endif endif
# .intel_syntax wasn't supported until GNU assembler 2.10
ifeq ($(HAVE_GAS)$(GAS210_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
else
ifeq ($(HAVE_GAS)$(GAS217_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3
else
ifeq ($(HAVE_GAS)$(GAS219_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI
endif
endif
endif
# GCC on Solaris needs -m64. Otherwise, i386 is default # GCC on Solaris needs -m64. Otherwise, i386 is default
# http://github.com/weidai11/cryptopp/issues/230 # http://github.com/weidai11/cryptopp/issues/230
ifeq ($(IS_SUN)$(GCC_COMPILER)$(IS_X64),111) ifeq ($(IS_SUN)$(GCC_COMPILER)$(IS_X64),111)
@ -762,9 +766,8 @@ endif # Dependencies
ifeq ($(USE_NASM),1) ifeq ($(USE_NASM),1)
rdrand.o: rdrand.h rdrand.cpp rdrand.S rdrand.o: rdrand.h rdrand.cpp rdrand.S
$(CXX) $(strip $(CXXFLAGS)) -DNASM_RDRAND_ASM_AVAILABLE=1 -DNASM_RDSEED_ASM_AVAILABLE=1 -c rdrand.cpp $(CXX) $(strip $(CXXFLAGS)) -DNASM_RDRAND_ASM_AVAILABLE=1 -DNASM_RDSEED_ASM_AVAILABLE=1 -c rdrand.cpp
rdrand-x86.o: ; rdrand-%.o:
rdrand-x32.o: ; ./rdrand-nasm.sh
rdrand-x64.o: ;
endif endif
# Only use CRYPTOPP_DATA_DIR if its not set in CXXFLAGS # Only use CRYPTOPP_DATA_DIR if its not set in CXXFLAGS

View File

@ -1,42 +1,64 @@
#!/usr/bin/env bash #!/usr/bin/env sh
IS_LINUX=$(uname -s | grep -i -c linux) IS_LINUX=$(uname -s | grep -i -c linux)
IS_SOLARIS=$(uname -s | grep -i -c sunos) IS_SOLARIS=$(uname -s | grep -i -c sunos)
IS_DARWIN=$(uname -s | grep -i -c darwin) IS_DARWIN=$(uname -s | grep -i -c darwin)
IS_CYGWIN=$(uname -s | grep -i -c cygwin) IS_CYGWIN=$(uname -s | grep -i -c cygwin)
IS_OPENBSD=$(uname -s | grep -i -c openbsd)
IS_DRAGONFLY=$(uname -s | grep -i -c dragonfly)
IS_FREEBSD=$(uname -s | grep -i -c freebsd)
IS_NETBSD=$(uname -s | grep -i -c netbsd)
rm -f rdrand-x86.o rdrand-x32.o rdrand-x64.o &>/dev/null rm -f rdrand-x86.o rdrand-x32.o rdrand-x64.o &>/dev/null
SUCCESS=0
NASM=$(which nasm 2>&1) NASM=$(which nasm 2>&1)
if [[ ! -f "$NASM" ]]; then if [ ! -f "$NASM" ]; then
echo "Unable to locate Nasm" echo "Unable to locate Nasm"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1
fi fi
if [[ "$IS_LINUX" -eq "1" ]]; then if [ "$IS_LINUX" -eq "1" ]; then
echo "Building rdrand and rdseed modules for Linux" echo "Building rdrand and rdseed modules for Linux"
nasm -f elf32 rdrand.S -DX86 -g -o rdrand-x86.o nasm -f elf32 rdrand.S -DX86 -g -o rdrand-x86.o
nasm -f elfx32 rdrand.S -DX32 -g -o rdrand-x32.o nasm -f elfx32 rdrand.S -DX32 -g -o rdrand-x32.o
nasm -f elf64 rdrand.S -DX64 -g -o rdrand-x64.o nasm -f elf64 rdrand.S -DX64 -g -o rdrand-x64.o
SUCCESS=1
fi fi
if [[ "$IS_SOLARIS" -eq "1" ]]; then if [ "$IS_OPENBSD" -eq "1" ] || [ "$IS_NETBSD" -eq "1" ] || [ "$IS_FREEBSD" -eq "1" ] || [ "$IS_DRAGONFLY" -eq "1" ]; then
echo "Building rdrand and rdseed modules for BSD"
nasm -f elf32 rdrand.S -DX86 -g -o rdrand-x86.o
nasm -f elfx32 rdrand.S -DX32 -g -o rdrand-x32.o
nasm -f elf64 rdrand.S -DX64 -g -o rdrand-x64.o
SUCCESS=1
fi
if [ "$IS_SOLARIS" -eq "1" ]; then
echo "Building rdrand and rdseed modules for Solaris" echo "Building rdrand and rdseed modules for Solaris"
nasm -f elf32 rdrand.S -DX86 -o rdrand-x86.o nasm -f elf32 rdrand.S -DX86 -o rdrand-x86.o
nasm -f elfx32 rdrand.S -DX32 -o rdrand-x32.o nasm -f elfx32 rdrand.S -DX32 -o rdrand-x32.o
nasm -f elf64 rdrand.S -DX64 -o rdrand-x64.o nasm -f elf64 rdrand.S -DX64 -o rdrand-x64.o
SUCCESS=1
fi fi
if [[ "$IS_DARWIN" -eq "1" ]]; then if [ "$IS_DARWIN" -eq "1" ]; then
echo "Building rdrand and rdseed modules for Darwin" echo "Building rdrand and rdseed modules for Darwin"
nasm -f macho32 rdrand.S -DDARWIN -DX86 -g -o rdrand-x86.o nasm -f macho32 rdrand.S -DDARWIN -DX86 -g -o rdrand-x86.o
nasm -f macho64 rdrand.S -DDARWIN -DX64 -g -o rdrand-x64.o nasm -f macho64 rdrand.S -DDARWIN -DX64 -g -o rdrand-x64.o
SUCCESS=1
fi fi
if [[ "$IS_CYGWIN" -eq "1" ]]; then if [ "$IS_CYGWIN" -eq "1" ]; then
echo "Building rdrand and rdseed modules for Cygwin" echo "Building rdrand and rdseed modules for Cygwin"
nasm -f win32 rdrand.S -DCYGWIN -DX86 -g -o rdrand-x86.o nasm -f win32 rdrand.S -DCYGWIN -DX86 -g -o rdrand-x86.o
nasm -f win64 rdrand.S -DCYGWIN -DX64 -g -o rdrand-x64.o nasm -f win64 rdrand.S -DCYGWIN -DX64 -g -o rdrand-x64.o
SUCCESS=1
fi
if [ "$SUCCESS" -eq "0" ]; then
echo "Failed to build rdrand and rdseed modules"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1
fi fi
[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 [ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0

View File

@ -160,7 +160,7 @@ inline void RDRAND32(void* output)
#endif #endif
} }
#if CRYPTOPP_BOOL_X64 #if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
// Fills 8 bytes // Fills 8 bytes
inline void RDRAND64(void* output) inline void RDRAND64(void* output)
{ {
@ -198,7 +198,7 @@ inline void RDRAND64(void* output)
throw NotImplemented("RDRAND: failed to find an implementation"); throw NotImplemented("RDRAND: failed to find an implementation");
#endif #endif
} }
#endif // CRYPTOPP_BOOL_X64 and RDRAND64 #endif // CRYPTOPP_BOOL_X64, CRYPTOPP_BOOL_X32 and RDRAND64
void RDRAND::GenerateBlock(byte *output, size_t size) void RDRAND::GenerateBlock(byte *output, size_t size)
{ {
@ -213,7 +213,7 @@ void RDRAND::GenerateBlock(byte *output, size_t size)
MASM_RDRAND_GenerateBlock(output, size); MASM_RDRAND_GenerateBlock(output, size);
#elif CRYPTOPP_BOOL_X64 #elif CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
size_t i = 0; size_t i = 0;
for (i = 0; i < size/8; i++) for (i = 0; i < size/8; i++)
RDRAND64(reinterpret_cast<word64*>(output)+i); RDRAND64(reinterpret_cast<word64*>(output)+i);
@ -227,7 +227,7 @@ void RDRAND::GenerateBlock(byte *output, size_t size)
RDRAND64(&val); RDRAND64(&val);
std::memcpy(output, &val, size); std::memcpy(output, &val, size);
} }
#elif (CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86) #elif CRYPTOPP_BOOL_X86
size_t i = 0; size_t i = 0;
for (i = 0; i < size/4; i++) for (i = 0; i < size/4; i++)
RDRAND32(reinterpret_cast<word32*>(output)+i); RDRAND32(reinterpret_cast<word32*>(output)+i);
@ -304,7 +304,7 @@ inline void RDSEED32(void* output)
#endif #endif
} }
#if CRYPTOPP_BOOL_X64 #if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
// Fills 8 bytes // Fills 8 bytes
inline void RDSEED64(void* output) inline void RDSEED64(void* output)
{ {
@ -357,7 +357,7 @@ void RDSEED::GenerateBlock(byte *output, size_t size)
MASM_RDSEED_GenerateBlock(output, size); MASM_RDSEED_GenerateBlock(output, size);
#elif CRYPTOPP_BOOL_X64 #elif CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
size_t i = 0; size_t i = 0;
for (i = 0; i < size/8; i++) for (i = 0; i < size/8; i++)
RDSEED64(reinterpret_cast<word64*>(output)+i); RDSEED64(reinterpret_cast<word64*>(output)+i);
@ -371,7 +371,7 @@ void RDSEED::GenerateBlock(byte *output, size_t size)
RDSEED64(&val); RDSEED64(&val);
std::memcpy(output, &val, size); std::memcpy(output, &val, size);
} }
#elif (CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86) #elif CRYPTOPP_BOOL_X86
size_t i = 0; size_t i = 0;
for (i = 0; i < size/4; i++) for (i = 0; i < size/4; i++)
RDSEED32(reinterpret_cast<word32*>(output)+i); RDSEED32(reinterpret_cast<word32*>(output)+i);
@ -385,7 +385,7 @@ void RDSEED::GenerateBlock(byte *output, size_t size)
RDSEED32(&val); RDSEED32(&val);
std::memcpy(output, &val, size); std::memcpy(output, &val, size);
} }
#endif #endif // CRYPTOPP_BOOL_X64, CRYPTOPP_BOOL_X32 and RDSEED64
} }
void RDSEED::DiscardBytes(size_t n) void RDSEED::DiscardBytes(size_t n)