From ced21a0c79277a409c94d84e5701d909f5ce160b Mon Sep 17 00:00:00 2001 From: Kris Kwiatkowski Date: Mon, 21 Jun 2021 09:20:48 +0100 Subject: [PATCH] makes MSan happy --- CMakeLists.txt | 2 +- src/common/randombytes.c | 4 ++++ src/kem/sike/p434/sike.c | 2 +- test/bench/kyber.cc | 2 +- test/ut.cpp | 8 +++++++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46ef593d..e5d9b6b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ if(MEMSAN) set(CMAKE_ARGS_MEMCHECK_LIB "-stdlib=libc++ -L${LLVM_PRJ_LIB} -lc++abi -Wl,-rpath,${LLVM_PRJ_LIB}") set(CMAKE_ARGS_MEMCHECK_INC "-isystem -I${LLVM_PRJ_INC} -I${LLVM_PRJ_INC}/c++/v1") set(CMAKE_ARGS_MEMCHECK_FLAGS "-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -Wno-unused-command-line-argument") - set(EXTRA_CXX_FLAGS "${CMAKE_ARGS_MEMCHECK_FLAGS} ${CMAKE_ARGS_MEMCHECK_LIB} ${CMAKE_ARGS_MEMCHECK_INC}") + set(EXTRA_CXX_FLAGS "${CMAKE_ARGS_MEMCHECK_FLAGS} ${CMAKE_ARGS_MEMCHECK_LIB} ${CMAKE_ARGS_MEMCHECK_INC} -DPQC_MEMSAN_BUILD") endif() # Dependencies diff --git a/src/common/randombytes.c b/src/common/randombytes.c index f2896ea6..b0096333 100644 --- a/src/common/randombytes.c +++ b/src/common/randombytes.c @@ -301,6 +301,10 @@ static int randombytes_js_randombytes_nodejs(void *buf, size_t n) { #endif /* defined(__EMSCRIPTEN__) */ int randombytes(uint8_t *buf, size_t n) { +#ifdef PQC_MEMSAN_BUILD + size_t i; + for (i=0; i #include #include +#include TEST(Kyber,KEMOneOff) { @@ -27,10 +28,15 @@ TEST(Kyber,KEMOneOff) { TEST(Kyber,SIGNOneOff) { + std::random_device rd; + std::uniform_int_distribution dist(0, 0xFF); + uint8_t msg[1234] = {0}; + for (int i=0; i sig(pqc_signature_bsz(p)); std::vector sk(pqc_private_key_bsz(p)); std::vector pk(pqc_public_key_bsz(p));