makes MSan happy

This commit is contained in:
Henry Case 2021-06-21 09:20:48 +01:00
rodzic 9b7b7277ce
commit ced21a0c79
5 zmienionych plików z 14 dodań i 4 usunięć

Wyświetl plik

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

Wyświetl plik

@ -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<n; i++) buf[i]=0;
#endif
#if defined(__EMSCRIPTEN__)
return randombytes_js_randombytes_nodejs(buf, n);
#elif defined(__linux__)

Wyświetl plik

@ -103,7 +103,7 @@ static inline void sike_init_basis(const crypto_word_t *gen, f2elm_t XP, f2elm_t
// Conversion of GF(p^2) element from Montgomery to standard representation.
static inline void sike_fp2_encode(const f2elm_t x, uint8_t *enc) {
f2elm_t t;
f2elm_t t={0};
sike_from_fp2mont(x, t);
// convert to bytes in little endian form

Wyświetl plik

@ -22,7 +22,7 @@ auto cpucycle = [](benchmark::State &st, int64_t cycles) {
static void BenchKyberMatK2(benchmark::State &st) {
int64_t t, total = 0;
polyvec a[KYBER_K];
uint8_t seed[32];
uint8_t seed[32] = {0};
for (auto _ : st) {
t = benchmark::cycleclock::Now();
PQCLEAN_KYBER512_AVX2_gen_matrix(a, seed, 0);

Wyświetl plik

@ -2,6 +2,7 @@
#include <vector>
#include <gtest/gtest.h>
#include <pqc/pqc.h>
#include <random>
TEST(Kyber,KEMOneOff) {
@ -27,10 +28,15 @@ TEST(Kyber,KEMOneOff) {
TEST(Kyber,SIGNOneOff) {
std::random_device rd;
std::uniform_int_distribution<uint8_t> dist(0, 0xFF);
uint8_t msg[1234] = {0};
for (int i=0; i<PQC_ALG_SIG_MAX; i++) {
const pqc_ctx_t *p = pqc_sig_alg_by_id(i);
// generate some random msg
for (auto &x : msg) {x = dist(rd);}
uint8_t msg[1234];
std::vector<uint8_t> sig(pqc_signature_bsz(p));
std::vector<uint8_t> sk(pqc_private_key_bsz(p));
std::vector<uint8_t> pk(pqc_public_key_bsz(p));