Sfoglia il codice sorgente

makes MSan happy

tags/v0.0.1
Henry Case 3 anni fa
parent
commit
ced21a0c79
5 ha cambiato i file con 14 aggiunte e 4 eliminazioni
  1. +1
    -1
      CMakeLists.txt
  2. +4
    -0
      src/common/randombytes.c
  3. +1
    -1
      src/kem/sike/p434/sike.c
  4. +1
    -1
      test/bench/kyber.cc
  5. +7
    -1
      test/ut.cpp

+ 1
- 1
CMakeLists.txt Vedi File

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


+ 4
- 0
src/common/randombytes.c Vedi File

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


+ 1
- 1
src/kem/sike/p434/sike.c Vedi File

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


+ 1
- 1
test/bench/kyber.cc Vedi File

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


+ 7
- 1
test/ut.cpp Vedi File

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


Caricamento…
Annulla
Salva