mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-22 23:48:58 +00:00
adds address and memory sanitizer
This commit is contained in:
parent
a0e38afc59
commit
af2cee5b17
@ -88,7 +88,9 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||||
set(CLANG 1)
|
# Additional flags only useful when compiling with clang
|
||||||
|
set(C_CXX_FLAGS
|
||||||
|
"-Wconditional-uninitialized -Wno-missing-variable-declarations -Wno-unused-command-line-argument")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (MACOSX)
|
if (MACOSX)
|
||||||
@ -98,8 +100,7 @@ endif()
|
|||||||
|
|
||||||
# Global configuration
|
# Global configuration
|
||||||
|
|
||||||
set(C_CXX_FLAGS
|
set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-ignored-qualifiers \
|
||||||
"-Wno-ignored-qualifiers \
|
|
||||||
-Wall \
|
-Wall \
|
||||||
-Werror \
|
-Werror \
|
||||||
-Wextra \
|
-Wextra \
|
||||||
@ -107,29 +108,26 @@ set(C_CXX_FLAGS
|
|||||||
-Wshadow \
|
-Wshadow \
|
||||||
-Wno-variadic-macros \
|
-Wno-variadic-macros \
|
||||||
-Wundef \
|
-Wundef \
|
||||||
-Wunused-result")
|
-Wunused-result \
|
||||||
|
-Wno-unused-command-line-argument")
|
||||||
if(CLANG)
|
|
||||||
set(C_CXX_FLAGS
|
|
||||||
"-Wconditional-uninitialized \
|
|
||||||
-Wmissing-variable-declarations")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Build with address sanitizer
|
# Build with address sanitizer
|
||||||
if(ADDRSAN)
|
if(ADDRSAN)
|
||||||
set(CLANG 1)
|
|
||||||
set(C_CXX_FLAGS "${C_CXX_FLAGS} -fsanitize=undefined,address,leak -fno-omit-frame-pointer")
|
set(C_CXX_FLAGS "${C_CXX_FLAGS} -fsanitize=undefined,address,leak -fno-omit-frame-pointer")
|
||||||
set(LDFLAGS "${LDFLAGS} -fsanitize=undefined,address,leak")
|
set(LDFLAGS "${LDFLAGS} -fsanitize=undefined,address,leak")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Build with memory sanitizer
|
# Build with memory sanitizer
|
||||||
if(MEMSAN)
|
if(MEMSAN)
|
||||||
|
# PQC_MEMSAN enables usage of some internals from clang
|
||||||
|
if (NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||||
|
message(FATAL_ERROR "Must use clang if compiled with memory sanitizer.")
|
||||||
|
endif()
|
||||||
if(ADDRSAN)
|
if(ADDRSAN)
|
||||||
message(FATAL_ERROR "Can't use MSAN and ASAN")
|
message(FATAL_ERROR "Can't use MSAN and ASAN")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CLANG 1)
|
set(C_CXX_FLAGS "${C_CXX_FLAGS} -DPQC_MEMSAN=1 -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer")
|
||||||
set(C_CXX_FLAGS "${C_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(.cmake/common.mk)
|
include(.cmake/common.mk)
|
||||||
@ -150,13 +148,21 @@ include_directories(
|
|||||||
|
|
||||||
set_property(GLOBAL PROPERTY obj_libs "")
|
set_property(GLOBAL PROPERTY obj_libs "")
|
||||||
|
|
||||||
|
|
||||||
# Set CPU architecture
|
# Set CPU architecture
|
||||||
set(CMAKE_C_FLAGS "${C_CXX_FLAGS} -D${ARCH}")
|
set(C_CXX_FLAGS "${C_CXX_FLAGS} -D${ARCH}")
|
||||||
set(CMAKE_CXX_FLAGS "${C_CXX_FLAGS} -D${ARCH}")
|
|
||||||
|
# Build for haswell if on x86_64
|
||||||
|
if(${ARCH} STREQUAL "ARCH_x86_64")
|
||||||
|
string(APPEND C_CXX_FLAGS " -march=haswell")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(PQC_CMAKE_C_FLAGS "${C_CXX_FLAGS}")
|
||||||
|
set(PQC_CMAKE_CXX_FLAGS "${C_CXX_FLAGS}")
|
||||||
|
set(CMAKE_C_FLAGS ${PQC_CMAKE_C_FLAGS})
|
||||||
|
set(CMAKE_CXX_FLAGS ${PQC_CMAKE_CXX_FLAGS})
|
||||||
|
|
||||||
if(PQC_WEAK_RANDOMBYTES)
|
if(PQC_WEAK_RANDOMBYTES)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPQC_WEAK_RANDOMBYTES")
|
string(APPEND PQC_CMAKE_C_FLAGS " -DPQC_WEAK_RANDOMBYTES")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Define sources of the components
|
# Define sources of the components
|
||||||
@ -223,10 +229,8 @@ add_subdirectory(src/kem/mceliece/mceliece6688128f/clean)
|
|||||||
add_subdirectory(src/kem/mceliece/mceliece6960119f/clean)
|
add_subdirectory(src/kem/mceliece/mceliece6960119f/clean)
|
||||||
add_subdirectory(src/kem/mceliece/mceliece8192128f/clean)
|
add_subdirectory(src/kem/mceliece/mceliece8192128f/clean)
|
||||||
# Hardware optimized targets
|
# Hardware optimized targets
|
||||||
if(${ARCH} STREQUAL "ARCH_x86_64")
|
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS
|
if(${ARCH} STREQUAL "ARCH_x86_64")
|
||||||
"${CMAKE_C_FLAGS} -march=haswell")
|
|
||||||
set(SRC_COMMON_AVX2
|
set(SRC_COMMON_AVX2
|
||||||
src/common/keccak4x/KeccakP-1600-times4-SIMD256.c
|
src/common/keccak4x/KeccakP-1600-times4-SIMD256.c
|
||||||
)
|
)
|
||||||
@ -279,8 +283,6 @@ add_subdirectory(src/kem/hqc/hqc-rmrs-192/avx2)
|
|||||||
add_subdirectory(src/kem/hqc/hqc-rmrs-256/avx2)
|
add_subdirectory(src/kem/hqc/hqc-rmrs-256/avx2)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# The rest of the library
|
# The rest of the library
|
||||||
set(SRC_COMMON_GENERIC
|
set(SRC_COMMON_GENERIC
|
||||||
src/common/aes.c
|
src/common/aes.c
|
||||||
@ -326,10 +328,14 @@ target_link_libraries(
|
|||||||
${OBJ_LIBS}
|
${OBJ_LIBS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SET(UT_SRC test/ut.cpp)
|
||||||
|
if(MEMSAN)
|
||||||
|
SET(UT_SRC ${UT_SRC} test/ct.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
ut
|
ut
|
||||||
|
${UT_SRC}
|
||||||
test/ut.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
@ -340,7 +346,6 @@ target_link_libraries(
|
|||||||
|
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
ut PRIVATE
|
ut PRIVATE
|
||||||
|
|
||||||
${CMAKE_SOURCE_DIR})
|
${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
|
if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
|
||||||
|
@ -71,7 +71,7 @@ const pqc_sig_ctx_t sigs[] = {
|
|||||||
// Contains capabilities on x86 CPU on which implementation is running
|
// Contains capabilities on x86 CPU on which implementation is running
|
||||||
X86Features CPU_CAPS;
|
X86Features CPU_CAPS;
|
||||||
|
|
||||||
const X86Features * const get_cpu_caps(void) {
|
const X86Features * get_cpu_caps(void) {
|
||||||
return &CPU_CAPS;
|
return &CPU_CAPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
# This Makefile can be used with GNU Make or BSD Make
|
|
||||||
|
|
||||||
LIB=libcommon.a
|
|
||||||
HEADERS= fips202.h aes.h sha2.h randombytes.h sp800-185.h nistseedexpander.h cpucycles.h speed_print.h
|
|
||||||
OBJECTS= fips202.o aes.o sha2.o randombytes.o sp800-185.o nistseedexpander.o cpucycles.o speed_print.o
|
|
||||||
|
|
||||||
CFLAGS=-O3 -march=native -mtune=native -flto -mavx2 -maes -mbmi2 -Wall -Wextra -Wpedantic -Wvla -Wredundant-decls -Wmissing-prototypes -std=gnu99 $(EXTRAFLAGS)
|
|
||||||
|
|
||||||
all: $(LIB)
|
|
||||||
|
|
||||||
%.o: %.s $(HEADERS)
|
|
||||||
$(AS) -o $@ $<
|
|
||||||
|
|
||||||
%.o: %.c $(HEADERS)
|
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
$(LIB): $(OBJECTS)
|
|
||||||
$(AR) -r $@ $(OBJECTS)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM) $(OBJECTS)
|
|
||||||
$(RM) $(LIB)
|
|
@ -32,7 +32,6 @@
|
|||||||
(((uint16_t)(x)[0])<<8 | \
|
(((uint16_t)(x)[0])<<8 | \
|
||||||
((uint16_t)(x)[1])<<0) \
|
((uint16_t)(x)[1])<<0) \
|
||||||
|
|
||||||
|
const X86Features * get_cpu_caps(void);
|
||||||
const X86Features * const get_cpu_caps(void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user