mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-22 15:39:07 +00:00
WIP
This commit is contained in:
parent
e7b5cfe9f8
commit
150f905b41
@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
project(cryptocore VERSION 0.0.1 LANGUAGES C)
|
project(pqc VERSION 0.0.1 LANGUAGES C)
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
include(ExternalProject)
|
include(ExternalProject)
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ include(.cmake/common.mk)
|
|||||||
|
|
||||||
# Control Debug/Release mode
|
# Control Debug/Release mode
|
||||||
if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
|
if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
|
||||||
string(APPEND PQC_CMAKE_C_CXX_FLAGS " -g3 -O0 -Wno-unused")
|
string(APPEND PQC_CMAKE_C_CXX_FLAGS " -g3 -O0")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Set CPU architecture
|
# Set CPU architecture
|
||||||
@ -184,17 +184,17 @@ if(PQC_WEAK_RANDOMBYTES)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Build CPU features
|
# Build CPU features
|
||||||
set(CMAKE_C_FLAGS "${PQC_CMAKE_C_CXX_FLAGS} ${EXTRA_C_CXX_FLAGS}")
|
set(CMAKE_C_FLAGS "-O0")
|
||||||
set(CMAKE_CXX_FLAGS "$${PQC_CMAKE_C_CXX_FLAGS} {EXTRA_C_CXX_FLAGS}")
|
set(CMAKE_CXX_FLAGS "${PQC_CMAKE_C_CXX_FLAGS}")
|
||||||
set(BUILD_PIC ON CACHE BOOL "")
|
set(BUILD_PIC ON CACHE BOOL "")
|
||||||
add_subdirectory(3rd/cpu_features)
|
add_subdirectory(3rd/cpu_features)
|
||||||
|
|
||||||
# PQC library
|
# PQC library
|
||||||
|
|
||||||
# Set C, CXX, and LD flags
|
# Set C, CXX, and LD flags
|
||||||
|
if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
|
||||||
string(APPEND PQC_CMAKE_C_CXX_FLAGS " -Wpedantic")
|
string(APPEND PQC_CMAKE_C_CXX_FLAGS " -Wpedantic")
|
||||||
set(CMAKE_C_FLAGS "${PQC_CMAKE_C_CXX_FLAGS} ${EXTRA_C_CXX_FLAGS}")
|
endif()
|
||||||
set(CMAKE_CXX_FLAGS "${PQC_CMAKE_C_CXX_FLAGS} ${EXTRA_C_CXX_FLAGS}")
|
|
||||||
string(APPEND LDFLAGS "${EXTRA_LDFLAGS}")
|
string(APPEND LDFLAGS "${EXTRA_LDFLAGS}")
|
||||||
include_directories(
|
include_directories(
|
||||||
public
|
public
|
||||||
@ -378,8 +378,8 @@ set(GOOGLETEST_PATH "${CMAKE_SOURCE_DIR}/3rd/gtest" CACHE PATH "Path to the gtes
|
|||||||
#endif()
|
#endif()
|
||||||
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
|
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
|
||||||
set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "" FORCE)
|
set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "" FORCE)
|
||||||
set(CMAKE_C_FLAGS "${EXTRA_C_CXX_FLAGS}")
|
#set(CMAKE_C_FLAGS "${EXTRA_C_CXX_FLAGS}")
|
||||||
set(CMAKE_CXX_FLAGS "${EXTRA_C_CXX_FLAGS}")
|
#set(CMAKE_CXX_FLAGS "${EXTRA_C_CXX_FLAGS}")
|
||||||
if (MEMSAN)
|
if (MEMSAN)
|
||||||
set(BENCHMARK_USE_LIBCXX ON CACHE BOOL "" FORCE)
|
set(BENCHMARK_USE_LIBCXX ON CACHE BOOL "" FORCE)
|
||||||
# Since build requires C++20 it is safe to assume that std::regex is available.
|
# Since build requires C++20 it is safe to assume that std::regex is available.
|
||||||
|
@ -38,6 +38,23 @@ extern "C" {
|
|||||||
(((uint16_t)(x)[0])<<8 | \
|
(((uint16_t)(x)[0])<<8 | \
|
||||||
((uint16_t)(x)[1])<<0) \
|
((uint16_t)(x)[1])<<0) \
|
||||||
|
|
||||||
|
//#if !defined(NDEBUG)
|
||||||
|
#include <stdio.h>
|
||||||
|
static inline void dump_buffer_hex(FILE *f, int ind, const void* data, size_t size) {
|
||||||
|
if (!f) {
|
||||||
|
f = stdout;
|
||||||
|
}
|
||||||
|
fprintf(f, "%*s", ind, " ");
|
||||||
|
for (size_t i = 0; i < size; ++i) {
|
||||||
|
fprintf(f, "%02X:", ((uint8_t*)data)[i]);
|
||||||
|
if ((i+1) % 32 == 0 || i+1 == size) {
|
||||||
|
fprintf(f, "\n%*s", ind, " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(f,"\n");
|
||||||
|
}
|
||||||
|
//#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
const cpu_features::X86Features*
|
const cpu_features::X86Features*
|
||||||
#else
|
#else
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "rounding.h"
|
#include "rounding.h"
|
||||||
#include "symmetric.h"
|
#include "symmetric.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#define DBENCH_START()
|
#define DBENCH_START()
|
||||||
#define DBENCH_STOP(t)
|
#define DBENCH_STOP(t)
|
||||||
@ -464,6 +465,7 @@ void PQCLEAN_DILITHIUM2_CLEAN_poly_uniform_gamma1(poly *a,
|
|||||||
stream256_init(&state, seed, nonce);
|
stream256_init(&state, seed, nonce);
|
||||||
stream256_squeezeblocks(buf, POLY_UNIFORM_GAMMA1_NBLOCKS, &state);
|
stream256_squeezeblocks(buf, POLY_UNIFORM_GAMMA1_NBLOCKS, &state);
|
||||||
stream256_release(&state);
|
stream256_release(&state);
|
||||||
|
dump_buffer_hex(0,0,buf,4);
|
||||||
PQCLEAN_DILITHIUM2_CLEAN_polyz_unpack(a, buf);
|
PQCLEAN_DILITHIUM2_CLEAN_polyz_unpack(a, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "sign.h"
|
#include "sign.h"
|
||||||
#include "symmetric.h"
|
#include "symmetric.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
/*************************************************
|
/*************************************************
|
||||||
* Name: PQCLEAN_DILITHIUM2_CLEAN_crypto_sign_keypair
|
* Name: PQCLEAN_DILITHIUM2_CLEAN_crypto_sign_keypair
|
||||||
@ -116,6 +117,8 @@ int PQCLEAN_DILITHIUM2_CLEAN_crypto_sign_signature(uint8_t *sig,
|
|||||||
|
|
||||||
rej:
|
rej:
|
||||||
/* Sample intermediate vector y */
|
/* Sample intermediate vector y */
|
||||||
|
dump_buffer_hex(0,0,rhoprime,64);
|
||||||
|
|
||||||
PQCLEAN_DILITHIUM2_CLEAN_polyvecl_uniform_gamma1(&y, rhoprime, nonce++);
|
PQCLEAN_DILITHIUM2_CLEAN_polyvecl_uniform_gamma1(&y, rhoprime, nonce++);
|
||||||
|
|
||||||
/* Matrix-vector multiplication */
|
/* Matrix-vector multiplication */
|
||||||
@ -129,6 +132,7 @@ rej:
|
|||||||
PQCLEAN_DILITHIUM2_CLEAN_polyveck_caddq(&w1);
|
PQCLEAN_DILITHIUM2_CLEAN_polyveck_caddq(&w1);
|
||||||
PQCLEAN_DILITHIUM2_CLEAN_polyveck_decompose(&w1, &w0, &w1);
|
PQCLEAN_DILITHIUM2_CLEAN_polyveck_decompose(&w1, &w0, &w1);
|
||||||
PQCLEAN_DILITHIUM2_CLEAN_polyveck_pack_w1(sig, &w1);
|
PQCLEAN_DILITHIUM2_CLEAN_polyveck_pack_w1(sig, &w1);
|
||||||
|
dump_buffer_hex(0, 4, sig, 10);
|
||||||
|
|
||||||
shake256_inc_init(&state);
|
shake256_inc_init(&state);
|
||||||
shake256_inc_absorb(&state, mu, CRHBYTES);
|
shake256_inc_absorb(&state, mu, CRHBYTES);
|
||||||
|
@ -74,7 +74,6 @@ static void BenchKeyPair(benchmark::State &st) {
|
|||||||
|
|
||||||
static void BenchSign(benchmark::State &st) {
|
static void BenchSign(benchmark::State &st) {
|
||||||
int64_t t, total = 0;
|
int64_t t, total = 0;
|
||||||
struct pqcl_asym_t *key_pair = nullptr;
|
|
||||||
uint32_t id = st.range(0);
|
uint32_t id = st.range(0);
|
||||||
uint8_t msg[2048] = {0};
|
uint8_t msg[2048] = {0};
|
||||||
const pqc_ctx_t *ctx;
|
const pqc_ctx_t *ctx;
|
||||||
@ -96,7 +95,6 @@ static void BenchSign(benchmark::State &st) {
|
|||||||
|
|
||||||
static void BenchVerify(benchmark::State &st) {
|
static void BenchVerify(benchmark::State &st) {
|
||||||
int64_t t, total = 0;
|
int64_t t, total = 0;
|
||||||
struct pqcl_asym_t *key_pair = nullptr;
|
|
||||||
uint32_t id = st.range(0);
|
uint32_t id = st.range(0);
|
||||||
const pqc_ctx_t *ctx;
|
const pqc_ctx_t *ctx;
|
||||||
uint8_t msg[2048] = {0};
|
uint8_t msg[2048] = {0};
|
||||||
|
52
test/ut.cpp
52
test/ut.cpp
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user