Просмотр исходного кода

adds address and memory sanitizer

tags/v0.0.1
Henry Case 3 лет назад
Родитель
Сommit
af2cee5b17
5 измененных файлов: 34 добавлений и 52 удалений
  1. +30
    -25
      CMakeLists.txt
  2. +1
    -1
      src/capi/pqapi.c
  3. +1
    -1
      src/capi/schemes.h
  4. +0
    -22
      src/common/Makefile
  5. +2
    -3
      src/common/utils.h

+ 30
- 25
CMakeLists.txt Просмотреть файл

@@ -88,7 +88,9 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
endif()

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()

if (MACOSX)
@@ -98,8 +100,7 @@ endif()

# Global configuration

set(C_CXX_FLAGS
"-Wno-ignored-qualifiers \
set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-ignored-qualifiers \
-Wall \
-Werror \
-Wextra \
@@ -107,29 +108,26 @@ set(C_CXX_FLAGS
-Wshadow \
-Wno-variadic-macros \
-Wundef \
-Wunused-result")

if(CLANG)
set(C_CXX_FLAGS
"-Wconditional-uninitialized \
-Wmissing-variable-declarations")
endif()
-Wunused-result \
-Wno-unused-command-line-argument")

# Build with address sanitizer
if(ADDRSAN)
set(CLANG 1)
set(C_CXX_FLAGS "${C_CXX_FLAGS} -fsanitize=undefined,address,leak -fno-omit-frame-pointer")
set(LDFLAGS "${LDFLAGS} -fsanitize=undefined,address,leak")
endif()

# Build with memory sanitizer
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)
message(FATAL_ERROR "Can't use MSAN and ASAN")
endif()

set(CLANG 1)
set(C_CXX_FLAGS "${C_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
set(C_CXX_FLAGS "${C_CXX_FLAGS} -DPQC_MEMSAN=1 -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer")
endif()

include(.cmake/common.mk)
@@ -150,13 +148,21 @@ include_directories(

set_property(GLOBAL PROPERTY obj_libs "")


# Set CPU architecture
set(CMAKE_C_FLAGS "${C_CXX_FLAGS} -D${ARCH}")
set(CMAKE_CXX_FLAGS "${C_CXX_FLAGS} -D${ARCH}")
set(C_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)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPQC_WEAK_RANDOMBYTES")
string(APPEND PQC_CMAKE_C_FLAGS " -DPQC_WEAK_RANDOMBYTES")
endif()

# 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/mceliece8192128f/clean)
# Hardware optimized targets
if(${ARCH} STREQUAL "ARCH_x86_64")

set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -march=haswell")
if(${ARCH} STREQUAL "ARCH_x86_64")
set(SRC_COMMON_AVX2
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)
endif()



# The rest of the library
set(SRC_COMMON_GENERIC
src/common/aes.c
@@ -326,10 +328,14 @@ target_link_libraries(
${OBJ_LIBS}
)

SET(UT_SRC test/ut.cpp)
if(MEMSAN)
SET(UT_SRC ${UT_SRC} test/ct.cpp)
endif()

add_executable(
ut

test/ut.cpp
${UT_SRC}
)

target_link_libraries(
@@ -340,7 +346,6 @@ target_link_libraries(

target_include_directories(
ut PRIVATE

${CMAKE_SOURCE_DIR})

if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")


+ 1
- 1
src/capi/pqapi.c Просмотреть файл

@@ -71,7 +71,7 @@ const pqc_sig_ctx_t sigs[] = {
// Contains capabilities on x86 CPU on which implementation is running
X86Features CPU_CAPS;

const X86Features * const get_cpu_caps(void) {
const X86Features * get_cpu_caps(void) {
return &CPU_CAPS;
}



+ 1
- 1
src/capi/schemes.h Просмотреть файл

@@ -117,4 +117,4 @@
#include "kem/hqc/hqc-rmrs-256/avx2/api.h"
#include "kem/sike/includes/sike/sike.h"

#endif
#endif

+ 0
- 22
src/common/Makefile Просмотреть файл

@@ -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)

+ 2
- 3
src/common/utils.h Просмотреть файл

@@ -32,7 +32,6 @@
(((uint16_t)(x)[0])<<8 | \
((uint16_t)(x)[1])<<0) \

const X86Features * get_cpu_caps(void);

const X86Features * const get_cpu_caps(void);

#endif
#endif

Загрузка…
Отмена
Сохранить