From e5b9b13160c340326fae8c3258ddb5798587800c Mon Sep 17 00:00:00 2001 From: Leon Date: Sun, 16 Jun 2019 17:01:29 +0200 Subject: [PATCH] rename impl to leaktime --- crypto_kem/ledakemlt12/META.yml | 2 +- .../clean/H_Q_matrices_generation.h | 11 ---- crypto_kem/ledakemlt12/clean/api.h | 18 ------ crypto_kem/ledakemlt12/clean/dfr_test.h | 8 --- .../clean/gf2x_arith_mod_xPplusOne.h | 38 ------------ .../H_Q_matrices_generation.c | 8 +-- .../leaktime/H_Q_matrices_generation.h | 11 ++++ .../ledakemlt12/{clean => leaktime}/LICENSE | 0 .../clean => ledakemlt12/leaktime}/Makefile | 2 +- .../leaktime}/Makefile.Microsoft_nmake | 2 +- crypto_kem/ledakemlt12/leaktime/api.h | 18 ++++++ .../{clean => leaktime}/bf_decoding.c | 10 +-- .../{clean => leaktime}/bf_decoding.h | 2 +- .../clean => ledakemlt12/leaktime}/dfr_test.c | 6 +- crypto_kem/ledakemlt12/leaktime/dfr_test.h | 8 +++ .../leaktime}/gf2x_arith.c | 8 +-- .../leaktime}/gf2x_arith.h | 8 +-- .../gf2x_arith_mod_xPplusOne.c | 54 ++++++++-------- .../leaktime/gf2x_arith_mod_xPplusOne.h | 38 ++++++++++++ .../clean => ledakemlt12/leaktime}/kem.c | 32 +++++----- .../leaktime}/niederreiter.c | 62 +++++++++---------- .../{clean => leaktime}/niederreiter.h | 6 +- .../{clean => leaktime}/qc_ldpc_parameters.h | 0 .../ledakemlt12/{clean => leaktime}/rng.c | 4 +- .../ledakemlt12/{clean => leaktime}/rng.h | 4 +- crypto_kem/ledakemlt32/META.yml | 2 +- .../clean/H_Q_matrices_generation.h | 11 ---- crypto_kem/ledakemlt32/clean/api.h | 18 ------ crypto_kem/ledakemlt32/clean/dfr_test.h | 8 --- .../clean/gf2x_arith_mod_xPplusOne.h | 38 ------------ .../leaktime}/H_Q_matrices_generation.c | 8 +-- .../leaktime/H_Q_matrices_generation.h | 11 ++++ .../ledakemlt32/{clean => leaktime}/LICENSE | 0 .../ledakemlt32/{clean => leaktime}/Makefile | 2 +- .../leaktime}/Makefile.Microsoft_nmake | 2 +- crypto_kem/ledakemlt32/leaktime/api.h | 18 ++++++ .../leaktime}/bf_decoding.c | 10 +-- .../{clean => leaktime}/bf_decoding.h | 2 +- .../clean => ledakemlt32/leaktime}/dfr_test.c | 6 +- crypto_kem/ledakemlt32/leaktime/dfr_test.h | 8 +++ .../leaktime}/gf2x_arith.c | 8 +-- .../{clean => leaktime}/gf2x_arith.h | 8 +-- .../gf2x_arith_mod_xPplusOne.c | 54 ++++++++-------- .../leaktime/gf2x_arith_mod_xPplusOne.h | 38 ++++++++++++ .../clean => ledakemlt32/leaktime}/kem.c | 32 +++++----- .../leaktime}/niederreiter.c | 62 +++++++++---------- .../leaktime}/niederreiter.h | 6 +- .../{clean => leaktime}/qc_ldpc_parameters.h | 0 .../ledakemlt32/{clean => leaktime}/rng.c | 4 +- .../clean => ledakemlt32/leaktime}/rng.h | 4 +- crypto_kem/ledakemlt52/META.yml | 2 +- .../clean/H_Q_matrices_generation.h | 11 ---- crypto_kem/ledakemlt52/clean/api.h | 18 ------ crypto_kem/ledakemlt52/clean/dfr_test.h | 8 --- .../clean/gf2x_arith_mod_xPplusOne.h | 37 ----------- .../leaktime}/H_Q_matrices_generation.c | 8 +-- .../leaktime/H_Q_matrices_generation.h | 11 ++++ .../ledakemlt52/{clean => leaktime}/LICENSE | 0 .../clean => ledakemlt52/leaktime}/Makefile | 2 +- .../leaktime}/Makefile.Microsoft_nmake | 2 +- crypto_kem/ledakemlt52/leaktime/api.h | 18 ++++++ .../leaktime}/bf_decoding.c | 10 +-- .../{clean => leaktime}/bf_decoding.h | 2 +- .../{clean => leaktime}/dfr_test.c | 6 +- crypto_kem/ledakemlt52/leaktime/dfr_test.h | 8 +++ .../leaktime}/gf2x_arith.c | 8 +-- .../leaktime}/gf2x_arith.h | 8 +-- .../gf2x_arith_mod_xPplusOne.c | 54 ++++++++-------- .../leaktime/gf2x_arith_mod_xPplusOne.h | 37 +++++++++++ .../clean => ledakemlt52/leaktime}/kem.c | 32 +++++----- .../leaktime}/niederreiter.c | 62 +++++++++---------- .../leaktime}/niederreiter.h | 6 +- .../{clean => leaktime}/qc_ldpc_parameters.h | 0 .../ledakemlt52/{clean => leaktime}/rng.c | 4 +- .../clean => ledakemlt52/leaktime}/rng.h | 4 +- 75 files changed, 539 insertions(+), 539 deletions(-) delete mode 100644 crypto_kem/ledakemlt12/clean/H_Q_matrices_generation.h delete mode 100644 crypto_kem/ledakemlt12/clean/api.h delete mode 100644 crypto_kem/ledakemlt12/clean/dfr_test.h delete mode 100644 crypto_kem/ledakemlt12/clean/gf2x_arith_mod_xPplusOne.h rename crypto_kem/ledakemlt12/{clean => leaktime}/H_Q_matrices_generation.c (72%) create mode 100644 crypto_kem/ledakemlt12/leaktime/H_Q_matrices_generation.h rename crypto_kem/ledakemlt12/{clean => leaktime}/LICENSE (100%) rename crypto_kem/{ledakemlt52/clean => ledakemlt12/leaktime}/Makefile (95%) rename crypto_kem/{ledakemlt32/clean => ledakemlt12/leaktime}/Makefile.Microsoft_nmake (93%) create mode 100644 crypto_kem/ledakemlt12/leaktime/api.h rename crypto_kem/ledakemlt12/{clean => leaktime}/bf_decoding.c (87%) rename crypto_kem/ledakemlt12/{clean => leaktime}/bf_decoding.h (87%) rename crypto_kem/{ledakemlt32/clean => ledakemlt12/leaktime}/dfr_test.c (94%) create mode 100644 crypto_kem/ledakemlt12/leaktime/dfr_test.h rename crypto_kem/{ledakemlt52/clean => ledakemlt12/leaktime}/gf2x_arith.c (82%) rename crypto_kem/{ledakemlt52/clean => ledakemlt12/leaktime}/gf2x_arith.h (82%) rename crypto_kem/ledakemlt12/{clean => leaktime}/gf2x_arith_mod_xPplusOne.c (87%) create mode 100644 crypto_kem/ledakemlt12/leaktime/gf2x_arith_mod_xPplusOne.h rename crypto_kem/{ledakemlt32/clean => ledakemlt12/leaktime}/kem.c (58%) rename crypto_kem/{ledakemlt52/clean => ledakemlt12/leaktime}/niederreiter.c (65%) rename crypto_kem/ledakemlt12/{clean => leaktime}/niederreiter.h (64%) rename crypto_kem/ledakemlt12/{clean => leaktime}/qc_ldpc_parameters.h (100%) rename crypto_kem/ledakemlt12/{clean => leaktime}/rng.c (94%) rename crypto_kem/ledakemlt12/{clean => leaktime}/rng.h (66%) delete mode 100644 crypto_kem/ledakemlt32/clean/H_Q_matrices_generation.h delete mode 100644 crypto_kem/ledakemlt32/clean/api.h delete mode 100644 crypto_kem/ledakemlt32/clean/dfr_test.h delete mode 100644 crypto_kem/ledakemlt32/clean/gf2x_arith_mod_xPplusOne.h rename crypto_kem/{ledakemlt52/clean => ledakemlt32/leaktime}/H_Q_matrices_generation.c (72%) create mode 100644 crypto_kem/ledakemlt32/leaktime/H_Q_matrices_generation.h rename crypto_kem/ledakemlt32/{clean => leaktime}/LICENSE (100%) rename crypto_kem/ledakemlt32/{clean => leaktime}/Makefile (95%) rename crypto_kem/{ledakemlt52/clean => ledakemlt32/leaktime}/Makefile.Microsoft_nmake (93%) create mode 100644 crypto_kem/ledakemlt32/leaktime/api.h rename crypto_kem/{ledakemlt52/clean => ledakemlt32/leaktime}/bf_decoding.c (87%) rename crypto_kem/ledakemlt32/{clean => leaktime}/bf_decoding.h (87%) rename crypto_kem/{ledakemlt12/clean => ledakemlt32/leaktime}/dfr_test.c (94%) create mode 100644 crypto_kem/ledakemlt32/leaktime/dfr_test.h rename crypto_kem/{ledakemlt12/clean => ledakemlt32/leaktime}/gf2x_arith.c (82%) rename crypto_kem/ledakemlt32/{clean => leaktime}/gf2x_arith.h (82%) rename crypto_kem/ledakemlt32/{clean => leaktime}/gf2x_arith_mod_xPplusOne.c (87%) create mode 100644 crypto_kem/ledakemlt32/leaktime/gf2x_arith_mod_xPplusOne.h rename crypto_kem/{ledakemlt52/clean => ledakemlt32/leaktime}/kem.c (58%) rename crypto_kem/{ledakemlt12/clean => ledakemlt32/leaktime}/niederreiter.c (65%) rename crypto_kem/{ledakemlt52/clean => ledakemlt32/leaktime}/niederreiter.h (63%) rename crypto_kem/ledakemlt32/{clean => leaktime}/qc_ldpc_parameters.h (100%) rename crypto_kem/ledakemlt32/{clean => leaktime}/rng.c (94%) rename crypto_kem/{ledakemlt52/clean => ledakemlt32/leaktime}/rng.h (67%) delete mode 100644 crypto_kem/ledakemlt52/clean/H_Q_matrices_generation.h delete mode 100644 crypto_kem/ledakemlt52/clean/api.h delete mode 100644 crypto_kem/ledakemlt52/clean/dfr_test.h delete mode 100644 crypto_kem/ledakemlt52/clean/gf2x_arith_mod_xPplusOne.h rename crypto_kem/{ledakemlt32/clean => ledakemlt52/leaktime}/H_Q_matrices_generation.c (72%) create mode 100644 crypto_kem/ledakemlt52/leaktime/H_Q_matrices_generation.h rename crypto_kem/ledakemlt52/{clean => leaktime}/LICENSE (100%) rename crypto_kem/{ledakemlt12/clean => ledakemlt52/leaktime}/Makefile (95%) rename crypto_kem/{ledakemlt12/clean => ledakemlt52/leaktime}/Makefile.Microsoft_nmake (93%) create mode 100644 crypto_kem/ledakemlt52/leaktime/api.h rename crypto_kem/{ledakemlt32/clean => ledakemlt52/leaktime}/bf_decoding.c (87%) rename crypto_kem/ledakemlt52/{clean => leaktime}/bf_decoding.h (87%) rename crypto_kem/ledakemlt52/{clean => leaktime}/dfr_test.c (94%) create mode 100644 crypto_kem/ledakemlt52/leaktime/dfr_test.h rename crypto_kem/{ledakemlt32/clean => ledakemlt52/leaktime}/gf2x_arith.c (82%) rename crypto_kem/{ledakemlt12/clean => ledakemlt52/leaktime}/gf2x_arith.h (82%) rename crypto_kem/ledakemlt52/{clean => leaktime}/gf2x_arith_mod_xPplusOne.c (87%) create mode 100644 crypto_kem/ledakemlt52/leaktime/gf2x_arith_mod_xPplusOne.h rename crypto_kem/{ledakemlt12/clean => ledakemlt52/leaktime}/kem.c (58%) rename crypto_kem/{ledakemlt32/clean => ledakemlt52/leaktime}/niederreiter.c (65%) rename crypto_kem/{ledakemlt32/clean => ledakemlt52/leaktime}/niederreiter.h (63%) rename crypto_kem/ledakemlt52/{clean => leaktime}/qc_ldpc_parameters.h (100%) rename crypto_kem/ledakemlt52/{clean => leaktime}/rng.c (94%) rename crypto_kem/{ledakemlt32/clean => ledakemlt52/leaktime}/rng.h (67%) diff --git a/crypto_kem/ledakemlt12/META.yml b/crypto_kem/ledakemlt12/META.yml index 9eda0152..1ec944a7 100644 --- a/crypto_kem/ledakemlt12/META.yml +++ b/crypto_kem/ledakemlt12/META.yml @@ -14,5 +14,5 @@ auxiliary-submitters: - Gerardo Pelosi - Paolo Santini implementations: - - name: clean + - name: leaktime version: 2.? diff --git a/crypto_kem/ledakemlt12/clean/H_Q_matrices_generation.h b/crypto_kem/ledakemlt12/clean/H_Q_matrices_generation.h deleted file mode 100644 index 8274dcd9..00000000 --- a/crypto_kem/ledakemlt12/clean/H_Q_matrices_generation.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef H_Q_MATRICES_GENERATION_H -#define H_Q_MATRICES_GENERATION_H - -#include "gf2x_arith.h" -#include "qc_ldpc_parameters.h" -#include "rng.h" - -void PQCLEAN_LEDAKEMLT12_CLEAN_generateHPosOnes_HtrPosOnes(POSITION_T HPosOnes[N0][DV], POSITION_T HtrPosOnes[N0][DV], AES_XOF_struct *niederreiter_keys_expander); -void PQCLEAN_LEDAKEMLT12_CLEAN_generateQsparse(POSITION_T pos_ones[N0][M], AES_XOF_struct *niederreiter_keys_expander); - -#endif diff --git a/crypto_kem/ledakemlt12/clean/api.h b/crypto_kem/ledakemlt12/clean/api.h deleted file mode 100644 index d37a6323..00000000 --- a/crypto_kem/ledakemlt12/clean/api.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef PQCLEAN_LEDAKEMLT12_CLEAN_API_H -#define PQCLEAN_LEDAKEMLT12_CLEAN_API_H - -#include - -#define PQCLEAN_LEDAKEMLT12_CLEAN_CRYPTO_SECRETKEYBYTES 26 -#define PQCLEAN_LEDAKEMLT12_CLEAN_CRYPTO_PUBLICKEYBYTES 6520 -#define PQCLEAN_LEDAKEMLT12_CLEAN_CRYPTO_CIPHERTEXTBYTES 6520 -#define PQCLEAN_LEDAKEMLT12_CLEAN_CRYPTO_BYTES 32 - -#define PQCLEAN_LEDAKEMLT12_CLEAN_CRYPTO_ALGNAME "LEDAKEMLT12" - -int PQCLEAN_LEDAKEMLT12_CLEAN_crypto_kem_keypair(uint8_t *pk, uint8_t *sk); -int PQCLEAN_LEDAKEMLT12_CLEAN_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk); -int PQCLEAN_LEDAKEMLT12_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk); - - -#endif diff --git a/crypto_kem/ledakemlt12/clean/dfr_test.h b/crypto_kem/ledakemlt12/clean/dfr_test.h deleted file mode 100644 index cbbcbd8a..00000000 --- a/crypto_kem/ledakemlt12/clean/dfr_test.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef DFR_TEST_H -#define DFR_TEST_H - -#define DFR_TEST_FAIL (255) - -uint8_t PQCLEAN_LEDAKEMLT12_CLEAN_DFR_test(POSITION_T LSparse[N0][DV * M]); - -#endif diff --git a/crypto_kem/ledakemlt12/clean/gf2x_arith_mod_xPplusOne.h b/crypto_kem/ledakemlt12/clean/gf2x_arith_mod_xPplusOne.h deleted file mode 100644 index 05695f67..00000000 --- a/crypto_kem/ledakemlt12/clean/gf2x_arith_mod_xPplusOne.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef GF2X_ARITH_MOD_XPLUSONE_H -#define GF2X_ARITH_MOD_XPLUSONE_H - -#include "qc_ldpc_parameters.h" - -#include "gf2x_arith.h" -#include "rng.h" - -#define NUM_BITS_GF2X_ELEMENT (P) // 52147 -#define NUM_DIGITS_GF2X_ELEMENT ((P+DIGIT_SIZE_b-1)/DIGIT_SIZE_b) -#define MSb_POSITION_IN_MSB_DIGIT_OF_ELEMENT ((P % DIGIT_SIZE_b) ? (P % DIGIT_SIZE_b)-1 : DIGIT_SIZE_b-1) -#define NUM_BITS_GF2X_MODULUS (P+1) -#define NUM_DIGITS_GF2X_MODULUS ((P+1+DIGIT_SIZE_b-1)/DIGIT_SIZE_b) -#define MSb_POSITION_IN_MSB_DIGIT_OF_MODULUS (P-DIGIT_SIZE_b*(NUM_DIGITS_GF2X_MODULUS-1)) -#define INVALID_POS_VALUE (P) -#define P_BITS (16) // log_2(p) = 15.6703 - -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_copy(DIGIT dest[], const DIGIT in[]); -DIGIT PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_get_coeff(const DIGIT poly[], unsigned int exponent); -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_set_coeff(DIGIT poly[], unsigned int exponent, DIGIT value); -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_toggle_coeff(DIGIT poly[], unsigned int exponent); -int PQCLEAN_LEDAKEMLT12_CLEAN_population_count(DIGIT *poly); -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_add(DIGIT Res[], const DIGIT A[], const DIGIT B[]); -void PQCLEAN_LEDAKEMLT12_CLEAN_quicksort_sparse(POSITION_T Res[]); -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const DIGIT B[]); -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_transpose_in_place(DIGIT A[]); -void PQCLEAN_LEDAKEMLT12_CLEAN_rand_circulant_sparse_block(POSITION_T *pos_ones, int countOnes, AES_XOF_struct *seed_expander_ctx); -void PQCLEAN_LEDAKEMLT12_CLEAN_rand_circulant_blocks_sequence(DIGIT *sequence, AES_XOF_struct *seed_expander_ctx); -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_add_sparse(int sizeR, POSITION_T Res[], int sizeA, const POSITION_T A[], int sizeB, const POSITION_T B[]); -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_transpose_in_place_sparse(int sizeA, POSITION_T A[]); -int PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]); -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[], size_t sizeA, const POSITION_T A[], size_t sizeB, const POSITION_T B[]); -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_dense_to_sparse(DIGIT Res[], const DIGIT dense[], POSITION_T sparse[], unsigned int nPos); -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly); -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_frombytes(DIGIT *poly, const uint8_t *poly_bytes); - - -#endif diff --git a/crypto_kem/ledakemlt12/clean/H_Q_matrices_generation.c b/crypto_kem/ledakemlt12/leaktime/H_Q_matrices_generation.c similarity index 72% rename from crypto_kem/ledakemlt12/clean/H_Q_matrices_generation.c rename to crypto_kem/ledakemlt12/leaktime/H_Q_matrices_generation.c index ad9ce98c..70a9727a 100644 --- a/crypto_kem/ledakemlt12/clean/H_Q_matrices_generation.c +++ b/crypto_kem/ledakemlt12/leaktime/H_Q_matrices_generation.c @@ -1,13 +1,13 @@ #include "H_Q_matrices_generation.h" #include "gf2x_arith_mod_xPplusOne.h" -void PQCLEAN_LEDAKEMLT12_CLEAN_generateHPosOnes_HtrPosOnes( +void PQCLEAN_LEDAKEMLT12_LEAKTIME_generateHPosOnes_HtrPosOnes( POSITION_T HPosOnes[N0][DV], POSITION_T HtrPosOnes[N0][DV], AES_XOF_struct *keys_expander) { for (int i = 0; i < N0; i++) { /* Generate a random block of Htr */ - PQCLEAN_LEDAKEMLT12_CLEAN_rand_circulant_sparse_block(&HtrPosOnes[i][0], DV, keys_expander); + PQCLEAN_LEDAKEMLT12_LEAKTIME_rand_circulant_sparse_block(&HtrPosOnes[i][0], DV, keys_expander); } for (int i = 0; i < N0; i++) { /* Obtain directly the sparse representation of the block of H */ @@ -17,13 +17,13 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_generateHPosOnes_HtrPosOnes( } } -void PQCLEAN_LEDAKEMLT12_CLEAN_generateQsparse( +void PQCLEAN_LEDAKEMLT12_LEAKTIME_generateQsparse( POSITION_T pos_ones[N0][M], AES_XOF_struct *keys_expander) { for (int i = 0; i < N0; i++) { int placed_ones = 0; for (int j = 0; j < N0; j++) { - PQCLEAN_LEDAKEMLT12_CLEAN_rand_circulant_sparse_block(&pos_ones[i][placed_ones], + PQCLEAN_LEDAKEMLT12_LEAKTIME_rand_circulant_sparse_block(&pos_ones[i][placed_ones], qBlockWeights[i][j], keys_expander); placed_ones += qBlockWeights[i][j]; diff --git a/crypto_kem/ledakemlt12/leaktime/H_Q_matrices_generation.h b/crypto_kem/ledakemlt12/leaktime/H_Q_matrices_generation.h new file mode 100644 index 00000000..0bf43055 --- /dev/null +++ b/crypto_kem/ledakemlt12/leaktime/H_Q_matrices_generation.h @@ -0,0 +1,11 @@ +#ifndef H_Q_MATRICES_GENERATION_H +#define H_Q_MATRICES_GENERATION_H + +#include "gf2x_arith.h" +#include "qc_ldpc_parameters.h" +#include "rng.h" + +void PQCLEAN_LEDAKEMLT12_LEAKTIME_generateHPosOnes_HtrPosOnes(POSITION_T HPosOnes[N0][DV], POSITION_T HtrPosOnes[N0][DV], AES_XOF_struct *niederreiter_keys_expander); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_generateQsparse(POSITION_T pos_ones[N0][M], AES_XOF_struct *niederreiter_keys_expander); + +#endif diff --git a/crypto_kem/ledakemlt12/clean/LICENSE b/crypto_kem/ledakemlt12/leaktime/LICENSE similarity index 100% rename from crypto_kem/ledakemlt12/clean/LICENSE rename to crypto_kem/ledakemlt12/leaktime/LICENSE diff --git a/crypto_kem/ledakemlt52/clean/Makefile b/crypto_kem/ledakemlt12/leaktime/Makefile similarity index 95% rename from crypto_kem/ledakemlt52/clean/Makefile rename to crypto_kem/ledakemlt12/leaktime/Makefile index 09000ede..09326171 100644 --- a/crypto_kem/ledakemlt52/clean/Makefile +++ b/crypto_kem/ledakemlt12/leaktime/Makefile @@ -1,6 +1,6 @@ # This Makefile can be used with GNU Make or BSD Make -LIB=libledakemlt52_clean.a +LIB=libledakemlt12_leaktime.a HEADERS=api.h bf_decoding.h dfr_test.h gf2x_arith_mod_xPplusOne.h \ gf2x_arith.h H_Q_matrices_generation.h \ niederreiter.h qc_ldpc_parameters.h rng.h diff --git a/crypto_kem/ledakemlt32/clean/Makefile.Microsoft_nmake b/crypto_kem/ledakemlt12/leaktime/Makefile.Microsoft_nmake similarity index 93% rename from crypto_kem/ledakemlt32/clean/Makefile.Microsoft_nmake rename to crypto_kem/ledakemlt12/leaktime/Makefile.Microsoft_nmake index 8b169221..fbad677a 100644 --- a/crypto_kem/ledakemlt32/clean/Makefile.Microsoft_nmake +++ b/crypto_kem/ledakemlt12/leaktime/Makefile.Microsoft_nmake @@ -1,7 +1,7 @@ # This Makefile can be used with Microsoft Visual Studio's nmake using the command: # nmake /f Makefile.Microsoft_nmake -LIBRARY=libledakemlt32_clean.lib +LIBRARY=libledakemlt12_leaktime.lib OBJECTS=bf_decoding.obj dfr_test.obj gf2x_arith_mod_xPplusOne.obj gf2x_arith.obj H_Q_matrices_generation.obj kem.obj niederreiter.obj rng.obj CFLAGS=/nologo /I ..\..\..\common /W4 /WX diff --git a/crypto_kem/ledakemlt12/leaktime/api.h b/crypto_kem/ledakemlt12/leaktime/api.h new file mode 100644 index 00000000..fd2f6b8b --- /dev/null +++ b/crypto_kem/ledakemlt12/leaktime/api.h @@ -0,0 +1,18 @@ +#ifndef PQCLEAN_LEDAKEMLT12_LEAKTIME_API_H +#define PQCLEAN_LEDAKEMLT12_LEAKTIME_API_H + +#include + +#define PQCLEAN_LEDAKEMLT12_LEAKTIME_CRYPTO_SECRETKEYBYTES 26 +#define PQCLEAN_LEDAKEMLT12_LEAKTIME_CRYPTO_PUBLICKEYBYTES 6520 +#define PQCLEAN_LEDAKEMLT12_LEAKTIME_CRYPTO_CIPHERTEXTBYTES 6520 +#define PQCLEAN_LEDAKEMLT12_LEAKTIME_CRYPTO_BYTES 32 + +#define PQCLEAN_LEDAKEMLT12_LEAKTIME_CRYPTO_ALGNAME "LEDAKEMLT12" + +int PQCLEAN_LEDAKEMLT12_LEAKTIME_crypto_kem_keypair(uint8_t *pk, uint8_t *sk); +int PQCLEAN_LEDAKEMLT12_LEAKTIME_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk); +int PQCLEAN_LEDAKEMLT12_LEAKTIME_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk); + + +#endif diff --git a/crypto_kem/ledakemlt12/clean/bf_decoding.c b/crypto_kem/ledakemlt12/leaktime/bf_decoding.c similarity index 87% rename from crypto_kem/ledakemlt12/clean/bf_decoding.c rename to crypto_kem/ledakemlt12/leaktime/bf_decoding.c index d4dca821..0e1123ac 100644 --- a/crypto_kem/ledakemlt12/clean/bf_decoding.c +++ b/crypto_kem/ledakemlt12/leaktime/bf_decoding.c @@ -4,7 +4,7 @@ #include #include -int PQCLEAN_LEDAKEMLT12_CLEAN_bf_decoding(DIGIT err[], +int PQCLEAN_LEDAKEMLT12_LEAKTIME_bf_decoding(DIGIT err[], const POSITION_T HtrPosOnes[N0][DV], const POSITION_T QtrPosOnes[N0][M], DIGIT privateSyndrome[], @@ -18,13 +18,13 @@ int PQCLEAN_LEDAKEMLT12_CLEAN_bf_decoding(DIGIT err[], unsigned int corrt_syndrome_based; do { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_copy(currSyndrome, privateSyndrome); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_copy(currSyndrome, privateSyndrome); memset(unsatParityChecks, 0x00, N0 * P * sizeof(uint8_t)); for (int i = 0; i < N0; i++) { for (int valueIdx = 0; valueIdx < P; valueIdx++) { for (int HtrOneIdx = 0; HtrOneIdx < DV; HtrOneIdx++) { POSITION_T tmp = (HtrPosOnes[i][HtrOneIdx] + valueIdx) >= P ? (HtrPosOnes[i][HtrOneIdx] + valueIdx) - P : (HtrPosOnes[i][HtrOneIdx] + valueIdx); - if (PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_get_coeff(currSyndrome, tmp)) { + if (PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_get_coeff(currSyndrome, tmp)) { unsatParityChecks[i * P + valueIdx]++; } } @@ -54,13 +54,13 @@ int PQCLEAN_LEDAKEMLT12_CLEAN_bf_decoding(DIGIT err[], } /* Correlation based flipping */ if (correlation >= corrt_syndrome_based) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_toggle_coeff(err + NUM_DIGITS_GF2X_ELEMENT * i, j); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_toggle_coeff(err + NUM_DIGITS_GF2X_ELEMENT * i, j); for (int v = 0; v < M; v++) { POSITION_T syndromePosToFlip; for (int HtrOneIdx = 0; HtrOneIdx < DV; HtrOneIdx++) { syndromePosToFlip = (HtrPosOnes[currQBlkPos[v]][HtrOneIdx] + currQBitPos[v] ); syndromePosToFlip = syndromePosToFlip >= P ? syndromePosToFlip - P : syndromePosToFlip; - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_toggle_coeff(privateSyndrome, syndromePosToFlip); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_toggle_coeff(privateSyndrome, syndromePosToFlip); } } // end for v } // end if diff --git a/crypto_kem/ledakemlt12/clean/bf_decoding.h b/crypto_kem/ledakemlt12/leaktime/bf_decoding.h similarity index 87% rename from crypto_kem/ledakemlt12/clean/bf_decoding.h rename to crypto_kem/ledakemlt12/leaktime/bf_decoding.h index 3da62547..6c62f4b3 100644 --- a/crypto_kem/ledakemlt12/clean/bf_decoding.h +++ b/crypto_kem/ledakemlt12/leaktime/bf_decoding.h @@ -9,7 +9,7 @@ #define B0 (43) #define T_BAR (4) -int PQCLEAN_LEDAKEMLT12_CLEAN_bf_decoding(DIGIT err[], +int PQCLEAN_LEDAKEMLT12_LEAKTIME_bf_decoding(DIGIT err[], const POSITION_T HtrPosOnes[N0][DV], const POSITION_T QtrPosOnes[N0][M], DIGIT privateSyndrome[], diff --git a/crypto_kem/ledakemlt32/clean/dfr_test.c b/crypto_kem/ledakemlt12/leaktime/dfr_test.c similarity index 94% rename from crypto_kem/ledakemlt32/clean/dfr_test.c rename to crypto_kem/ledakemlt12/leaktime/dfr_test.c index f612e2a2..9ea239a9 100644 --- a/crypto_kem/ledakemlt32/clean/dfr_test.c +++ b/crypto_kem/ledakemlt12/leaktime/dfr_test.c @@ -9,7 +9,7 @@ * computes the threshold for the second iteration of the decoder and returns this values * (max DV * M), on failure it returns 255 >> DV * M */ -uint8_t PQCLEAN_LEDAKEMLT32_CLEAN_DFR_test(POSITION_T LSparse[N0][DV * M]) { +uint8_t PQCLEAN_LEDAKEMLT12_LEAKTIME_DFR_test(POSITION_T LSparse[N0][DV * M]) { POSITION_T LSparse_loc[N0][DV * M]; POSITION_T rotated_column[DV * M]; @@ -31,7 +31,7 @@ uint8_t PQCLEAN_LEDAKEMLT32_CLEAN_DFR_test(POSITION_T LSparse[N0][DV * M]) { LSparse_loc[i][j] = (P - LSparse[i][j]); } } - PQCLEAN_LEDAKEMLT32_CLEAN_quicksort_sparse(LSparse_loc[i]); + PQCLEAN_LEDAKEMLT12_LEAKTIME_quicksort_sparse(LSparse_loc[i]); } for (int i = 0; i < N0; i++ ) { @@ -41,7 +41,7 @@ uint8_t PQCLEAN_LEDAKEMLT32_CLEAN_DFR_test(POSITION_T LSparse[N0][DV * M]) { for (int idxToRotate = 0; idxToRotate < (DV * M); idxToRotate++) { rotated_column[idxToRotate] = (LSparse_loc[j][idxToRotate] + k) % P; } - PQCLEAN_LEDAKEMLT32_CLEAN_quicksort_sparse(rotated_column); + PQCLEAN_LEDAKEMLT12_LEAKTIME_quicksort_sparse(rotated_column); /* compute the intersection amount */ firstidx = 0, secondidx = 0; intersectionval = 0; diff --git a/crypto_kem/ledakemlt12/leaktime/dfr_test.h b/crypto_kem/ledakemlt12/leaktime/dfr_test.h new file mode 100644 index 00000000..39673efb --- /dev/null +++ b/crypto_kem/ledakemlt12/leaktime/dfr_test.h @@ -0,0 +1,8 @@ +#ifndef DFR_TEST_H +#define DFR_TEST_H + +#define DFR_TEST_FAIL (255) + +uint8_t PQCLEAN_LEDAKEMLT12_LEAKTIME_DFR_test(POSITION_T LSparse[N0][DV * M]); + +#endif diff --git a/crypto_kem/ledakemlt52/clean/gf2x_arith.c b/crypto_kem/ledakemlt12/leaktime/gf2x_arith.c similarity index 82% rename from crypto_kem/ledakemlt52/clean/gf2x_arith.c rename to crypto_kem/ledakemlt12/leaktime/gf2x_arith.c index 73652552..6791ed1e 100644 --- a/crypto_kem/ledakemlt52/clean/gf2x_arith.c +++ b/crypto_kem/ledakemlt12/leaktime/gf2x_arith.c @@ -3,14 +3,14 @@ #include #include // memset(...) -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr) { for (int i = 0; i < nr; i++) { Res[i] = A[i] ^ B[i]; } } /* PRE: MAX ALLOWED ROTATION AMOUNT : DIGIT_SIZE_b */ -void PQCLEAN_LEDAKEMLT52_CLEAN_right_bit_shift_n(int length, DIGIT in[], unsigned int amount) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_right_bit_shift_n(int length, DIGIT in[], unsigned int amount) { assert(amount < DIGIT_SIZE_b); if ( amount == 0 ) { return; @@ -26,7 +26,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_right_bit_shift_n(int length, DIGIT in[], unsigne } /* PRE: MAX ALLOWED ROTATION AMOUNT : DIGIT_SIZE_b */ -void PQCLEAN_LEDAKEMLT52_CLEAN_left_bit_shift_n(int length, DIGIT in[], unsigned int amount) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_left_bit_shift_n(int length, DIGIT in[], unsigned int amount) { assert(amount < DIGIT_SIZE_b); if ( amount == 0 ) { return; @@ -41,7 +41,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_left_bit_shift_n(int length, DIGIT in[], unsigned in[j] <<= amount; } -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mul_comb(int nr, DIGIT Res[], +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mul_comb(int nr, DIGIT Res[], int na, const DIGIT A[], int nb, const DIGIT B[]) { int i, j, k; diff --git a/crypto_kem/ledakemlt52/clean/gf2x_arith.h b/crypto_kem/ledakemlt12/leaktime/gf2x_arith.h similarity index 82% rename from crypto_kem/ledakemlt52/clean/gf2x_arith.h rename to crypto_kem/ledakemlt12/leaktime/gf2x_arith.h index cdb6b303..3851fb7f 100644 --- a/crypto_kem/ledakemlt52/clean/gf2x_arith.h +++ b/crypto_kem/ledakemlt12/leaktime/gf2x_arith.h @@ -48,11 +48,11 @@ typedef uint64_t DIGIT; #define DIGIT_SIZE_b (DIGIT_SIZE_B << 3) #define POSITION_T uint32_t -#define GF2X_MUL PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mul_comb +#define GF2X_MUL PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mul_comb -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr); -void PQCLEAN_LEDAKEMLT52_CLEAN_right_bit_shift_n(int length, DIGIT in[], unsigned int amount); -void PQCLEAN_LEDAKEMLT52_CLEAN_left_bit_shift_n(int length, DIGIT in[], unsigned int amount); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_right_bit_shift_n(int length, DIGIT in[], unsigned int amount); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_left_bit_shift_n(int length, DIGIT in[], unsigned int amount); void GF2X_MUL(int nr, DIGIT Res[], int na, const DIGIT A[], int nb, const DIGIT B[]); #endif diff --git a/crypto_kem/ledakemlt12/clean/gf2x_arith_mod_xPplusOne.c b/crypto_kem/ledakemlt12/leaktime/gf2x_arith_mod_xPplusOne.c similarity index 87% rename from crypto_kem/ledakemlt12/clean/gf2x_arith_mod_xPplusOne.c rename to crypto_kem/ledakemlt12/leaktime/gf2x_arith_mod_xPplusOne.c index 30dca0f9..aa43cd45 100644 --- a/crypto_kem/ledakemlt12/clean/gf2x_arith_mod_xPplusOne.c +++ b/crypto_kem/ledakemlt12/leaktime/gf2x_arith_mod_xPplusOne.c @@ -4,14 +4,14 @@ #include #include // memcpy(...), memset(...) -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_copy(DIGIT dest[], const DIGIT in[]) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_copy(DIGIT dest[], const DIGIT in[]) { for (int i = NUM_DIGITS_GF2X_ELEMENT - 1; i >= 0; i--) { dest[i] = in[i]; } } /* returns the coefficient of the x^exponent term as the LSB of a digit */ -DIGIT PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_get_coeff(const DIGIT poly[], unsigned int exponent) { +DIGIT PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_get_coeff(const DIGIT poly[], unsigned int exponent) { unsigned int straightIdx = (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_b - 1) - exponent; unsigned int digitIdx = straightIdx / DIGIT_SIZE_b; unsigned int inDigitIdx = straightIdx % DIGIT_SIZE_b; @@ -19,7 +19,7 @@ DIGIT PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_get_coeff(const DIGIT poly[], unsigned int } /* sets the coefficient of the x^exponent term as the LSB of a digit */ -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_set_coeff(DIGIT poly[], unsigned int exponent, DIGIT value) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_set_coeff(DIGIT poly[], unsigned int exponent, DIGIT value) { unsigned int straightIdx = (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_b - 1) - exponent; unsigned int digitIdx = straightIdx / DIGIT_SIZE_b; unsigned int inDigitIdx = straightIdx % DIGIT_SIZE_b; @@ -31,7 +31,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_set_coeff(DIGIT poly[], unsigned int exponen } /* toggles (flips) the coefficient of the x^exponent term as the LSB of a digit */ -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_toggle_coeff(DIGIT poly[], unsigned int exponent) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_toggle_coeff(DIGIT poly[], unsigned int exponent) { unsigned int straightIdx = (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_b - 1) - exponent; unsigned int digitIdx = straightIdx / DIGIT_SIZE_b; unsigned int inDigitIdx = straightIdx % DIGIT_SIZE_b; @@ -51,7 +51,7 @@ static int popcount_uint64t(uint64_t x) { } /* population count for a single polynomial */ -int PQCLEAN_LEDAKEMLT12_CLEAN_population_count(DIGIT *poly) { +int PQCLEAN_LEDAKEMLT12_LEAKTIME_population_count(DIGIT *poly) { int ret = 0; for (int i = NUM_DIGITS_GF2X_ELEMENT - 1; i >= 0; i--) { ret += popcount_uint64t(poly[i]); @@ -59,8 +59,8 @@ int PQCLEAN_LEDAKEMLT12_CLEAN_population_count(DIGIT *poly) { return ret; } -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_add(DIGIT Res[], const DIGIT A[], const DIGIT B[]) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_add(Res, A, B, NUM_DIGITS_GF2X_ELEMENT); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_add(DIGIT Res[], const DIGIT A[], const DIGIT B[]) { + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_add(Res, A, B, NUM_DIGITS_GF2X_ELEMENT); } static int partition(POSITION_T arr[], int lo, int hi) { @@ -82,7 +82,7 @@ static int partition(POSITION_T arr[], int lo, int hi) { return i + 1; } -void PQCLEAN_LEDAKEMLT12_CLEAN_quicksort_sparse(POSITION_T Res[]) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_quicksort_sparse(POSITION_T Res[]) { int stack[DV * M]; int hi, lo, pivot, tos = -1; stack[++tos] = 0; @@ -175,7 +175,7 @@ static void left_DIGIT_shift_n(unsigned int length, DIGIT in[], unsigned int amo /* may shift by an arbitrary amount*/ static void left_bit_shift_wide_n(const int length, DIGIT in[], unsigned int amount) { left_DIGIT_shift_n(length, in, amount / DIGIT_SIZE_b); - PQCLEAN_LEDAKEMLT12_CLEAN_left_bit_shift_n(length, in, amount % DIGIT_SIZE_b); + PQCLEAN_LEDAKEMLT12_LEAKTIME_left_bit_shift_n(length, in, amount % DIGIT_SIZE_b); } /* Hackers delight, reverses a uint64_t */ @@ -193,7 +193,7 @@ static DIGIT reverse_digit(DIGIT x) { return x; } -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_transpose_in_place(DIGIT A[]) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_transpose_in_place(DIGIT A[]) { /* it keeps the lsb in the same position and * inverts the sequence of the remaining bits */ @@ -214,7 +214,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_transpose_in_place(DIGIT A[]) { A[NUM_DIGITS_GF2X_ELEMENT / 2] = reverse_digit(A[NUM_DIGITS_GF2X_ELEMENT / 2]); if (slack_bits_amount) { - PQCLEAN_LEDAKEMLT12_CLEAN_right_bit_shift_n(NUM_DIGITS_GF2X_ELEMENT, A, slack_bits_amount); + PQCLEAN_LEDAKEMLT12_LEAKTIME_right_bit_shift_n(NUM_DIGITS_GF2X_ELEMENT, A, slack_bits_amount); } A[NUM_DIGITS_GF2X_ELEMENT - 1] = (A[NUM_DIGITS_GF2X_ELEMENT - 1] & (~mask)) | a00; } @@ -265,7 +265,7 @@ static void gf2x_swap(const int length, DIGIT f[], DIGIT s[]) { * (Chapter 11 -- Algorithm 11.44 -- pag 223) * */ -int PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) { /* in^{-1} mod x^P-1 */ +int PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) { /* in^{-1} mod x^P-1 */ int i; int delta = 0; @@ -299,8 +299,8 @@ int PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) { delta += 1; } else { if ( (s[0] & mask) != 0) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_add(s, s, f, NUM_DIGITS_GF2X_MODULUS); - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_add(v, v, u); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_add(s, s, f, NUM_DIGITS_GF2X_MODULUS); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_add(v, v, u); } left_bit_shift(NUM_DIGITS_GF2X_MODULUS, s); if ( delta == 0 ) { @@ -322,7 +322,7 @@ int PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) { return (delta == 0); } -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const DIGIT B[]) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const DIGIT B[]) { DIGIT aux[2 * NUM_DIGITS_GF2X_ELEMENT]; GF2X_MUL(2 * NUM_DIGITS_GF2X_ELEMENT, aux, @@ -334,7 +334,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const /*PRE: the representation of the sparse coefficients is sorted in increasing order of the coefficients themselves */ -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_dense_to_sparse( +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_mul_dense_to_sparse( DIGIT Res[], const DIGIT dense[], POSITION_T sparse[], unsigned int nPos) { @@ -352,7 +352,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_dense_to_sparse( for (unsigned int i = 1; i < nPos; i++) { if (sparse[i] != INVALID_POS_VALUE) { left_bit_shift_wide_n(2 * NUM_DIGITS_GF2X_ELEMENT, aux, (sparse[i] - sparse[i - 1]) ); - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_add(resDouble, aux, resDouble, 2 * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_add(resDouble, aux, resDouble, 2 * NUM_DIGITS_GF2X_ELEMENT); } } } @@ -361,7 +361,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_dense_to_sparse( } -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_transpose_in_place_sparse(int sizeA, POSITION_T A[]) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_transpose_in_place_sparse(int sizeA, POSITION_T A[]) { POSITION_T t; int i = 0, j; @@ -383,7 +383,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_transpose_in_place_sparse(int sizeA, POSITIO } -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[], +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[], size_t sizeA, const POSITION_T A[], size_t sizeB, const POSITION_T B[]) { @@ -406,7 +406,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[ Res[lastFilledPos] = INVALID_POS_VALUE; lastFilledPos++; } - PQCLEAN_LEDAKEMLT12_CLEAN_quicksort_sparse(Res); + PQCLEAN_LEDAKEMLT12_LEAKTIME_quicksort_sparse(Res); /* eliminate duplicates */ POSITION_T lastReadPos = Res[0]; int duplicateCount; @@ -433,7 +433,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[ /* the implementation is safe even in case A or B alias with the result */ /* PRE: A and B should be sorted and have INVALID_POS_VALUE at the end */ -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_add_sparse( +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_add_sparse( int sizeR, POSITION_T Res[], int sizeA, const POSITION_T A[], int sizeB, const POSITION_T B[]) { @@ -492,7 +492,7 @@ static uint32_t rand_range(const unsigned int n, const int logn, AES_XOF_struct uint32_t mask = ( (uint32_t)1 << logn) - 1; do { - PQCLEAN_LEDAKEMLT12_CLEAN_seedexpander(seed_expander_ctx, rnd_char_buffer, required_rnd_bytes); + PQCLEAN_LEDAKEMLT12_LEAKTIME_seedexpander(seed_expander_ctx, rnd_char_buffer, required_rnd_bytes); /* obtain an endianness independent representation of the generated random bytes into an unsigned integer */ rnd_value = ((uint32_t)rnd_char_buffer[3] << 24) + @@ -507,7 +507,7 @@ static uint32_t rand_range(const unsigned int n, const int logn, AES_XOF_struct /* Obtains fresh randomness and seed-expands it until all the required positions * for the '1's in the circulant block are obtained */ -void PQCLEAN_LEDAKEMLT12_CLEAN_rand_circulant_sparse_block(POSITION_T *pos_ones, +void PQCLEAN_LEDAKEMLT12_LEAKTIME_rand_circulant_sparse_block(POSITION_T *pos_ones, int countOnes, AES_XOF_struct *seed_expander_ctx) { @@ -532,7 +532,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_rand_circulant_sparse_block(POSITION_T *pos_ones, } /* Returns random weight-t circulant block */ -void PQCLEAN_LEDAKEMLT12_CLEAN_rand_circulant_blocks_sequence( +void PQCLEAN_LEDAKEMLT12_LEAKTIME_rand_circulant_blocks_sequence( DIGIT sequence[N0 * NUM_DIGITS_GF2X_ELEMENT], AES_XOF_struct *seed_expander_ctx) { @@ -558,13 +558,13 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_rand_circulant_blocks_sequence( for (int j = 0; j < counter; j++) { polyIndex = rndPos[j] / P; exponent = rndPos[j] % P; - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_set_coeff( sequence + NUM_DIGITS_GF2X_ELEMENT * polyIndex, exponent, + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_set_coeff( sequence + NUM_DIGITS_GF2X_ELEMENT * polyIndex, exponent, ( (DIGIT) 1)); } } -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly) { size_t i, j; for (i = 0; i < NUM_DIGITS_GF2X_ELEMENT; i++) { for (j = 0; j < DIGIT_SIZE_B; j++) { @@ -573,7 +573,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly) { } } -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_frombytes(DIGIT *poly, const uint8_t *poly_bytes) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_frombytes(DIGIT *poly, const uint8_t *poly_bytes) { size_t i, j; for (i = 0; i < NUM_DIGITS_GF2X_ELEMENT; i++) { poly[i] = (DIGIT) 0; diff --git a/crypto_kem/ledakemlt12/leaktime/gf2x_arith_mod_xPplusOne.h b/crypto_kem/ledakemlt12/leaktime/gf2x_arith_mod_xPplusOne.h new file mode 100644 index 00000000..8fa0d40a --- /dev/null +++ b/crypto_kem/ledakemlt12/leaktime/gf2x_arith_mod_xPplusOne.h @@ -0,0 +1,38 @@ +#ifndef GF2X_ARITH_MOD_XPLUSONE_H +#define GF2X_ARITH_MOD_XPLUSONE_H + +#include "qc_ldpc_parameters.h" + +#include "gf2x_arith.h" +#include "rng.h" + +#define NUM_BITS_GF2X_ELEMENT (P) // 52147 +#define NUM_DIGITS_GF2X_ELEMENT ((P+DIGIT_SIZE_b-1)/DIGIT_SIZE_b) +#define MSb_POSITION_IN_MSB_DIGIT_OF_ELEMENT ((P % DIGIT_SIZE_b) ? (P % DIGIT_SIZE_b)-1 : DIGIT_SIZE_b-1) +#define NUM_BITS_GF2X_MODULUS (P+1) +#define NUM_DIGITS_GF2X_MODULUS ((P+1+DIGIT_SIZE_b-1)/DIGIT_SIZE_b) +#define MSb_POSITION_IN_MSB_DIGIT_OF_MODULUS (P-DIGIT_SIZE_b*(NUM_DIGITS_GF2X_MODULUS-1)) +#define INVALID_POS_VALUE (P) +#define P_BITS (16) // log_2(p) = 15.6703 + +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_copy(DIGIT dest[], const DIGIT in[]); +DIGIT PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_get_coeff(const DIGIT poly[], unsigned int exponent); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_set_coeff(DIGIT poly[], unsigned int exponent, DIGIT value); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_toggle_coeff(DIGIT poly[], unsigned int exponent); +int PQCLEAN_LEDAKEMLT12_LEAKTIME_population_count(DIGIT *poly); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_add(DIGIT Res[], const DIGIT A[], const DIGIT B[]); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_quicksort_sparse(POSITION_T Res[]); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const DIGIT B[]); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_transpose_in_place(DIGIT A[]); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_rand_circulant_sparse_block(POSITION_T *pos_ones, int countOnes, AES_XOF_struct *seed_expander_ctx); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_rand_circulant_blocks_sequence(DIGIT *sequence, AES_XOF_struct *seed_expander_ctx); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_add_sparse(int sizeR, POSITION_T Res[], int sizeA, const POSITION_T A[], int sizeB, const POSITION_T B[]); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_transpose_in_place_sparse(int sizeA, POSITION_T A[]); +int PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[], size_t sizeA, const POSITION_T A[], size_t sizeB, const POSITION_T B[]); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_mul_dense_to_sparse(DIGIT Res[], const DIGIT dense[], POSITION_T sparse[], unsigned int nPos); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_frombytes(DIGIT *poly, const uint8_t *poly_bytes); + + +#endif diff --git a/crypto_kem/ledakemlt32/clean/kem.c b/crypto_kem/ledakemlt12/leaktime/kem.c similarity index 58% rename from crypto_kem/ledakemlt32/clean/kem.c rename to crypto_kem/ledakemlt12/leaktime/kem.c index 647f4326..5a06bf0b 100644 --- a/crypto_kem/ledakemlt32/clean/kem.c +++ b/crypto_kem/ledakemlt12/leaktime/kem.c @@ -8,43 +8,43 @@ static void pack_pk(uint8_t *pk_bytes, publicKeyNiederreiter_t *pk) { size_t i; for (i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_tobytes(pk_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B, - pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_tobytes(pk_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B, + pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT); } } static void unpack_pk(publicKeyNiederreiter_t *pk, const uint8_t *pk_bytes) { size_t i; for (i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_frombytes(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_frombytes(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, pk_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); } } static void pack_ct(uint8_t *sk_bytes, DIGIT *ct) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_tobytes(sk_bytes, ct); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_tobytes(sk_bytes, ct); } static void unpack_ct(DIGIT *ct, const uint8_t *ct_bytes) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_frombytes(ct, ct_bytes); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_frombytes(ct, ct_bytes); } static void pack_error(uint8_t *error_bytes, DIGIT *error_digits) { size_t i; for (i = 0; i < N0; i++) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_tobytes(error_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B, - error_digits + i * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_tobytes(error_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B, + error_digits + i * NUM_DIGITS_GF2X_ELEMENT); } } /* Generates a keypair - pk is the public key and sk is the secret key. */ -int PQCLEAN_LEDAKEMLT32_CLEAN_crypto_kem_keypair(unsigned char *pk, unsigned char *sk) { +int PQCLEAN_LEDAKEMLT12_LEAKTIME_crypto_kem_keypair(unsigned char *pk, unsigned char *sk) { AES_XOF_struct niederreiter_keys_expander; publicKeyNiederreiter_t pk_nie; randombytes(((privateKeyNiederreiter_t *)sk)->prng_seed, TRNG_BYTE_LENGTH); - PQCLEAN_LEDAKEMLT32_CLEAN_seedexpander_from_trng(&niederreiter_keys_expander, ((privateKeyNiederreiter_t *)sk)->prng_seed); - PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_keygen(&pk_nie, (privateKeyNiederreiter_t *) sk, &niederreiter_keys_expander); + PQCLEAN_LEDAKEMLT12_LEAKTIME_seedexpander_from_trng(&niederreiter_keys_expander, ((privateKeyNiederreiter_t *)sk)->prng_seed); + PQCLEAN_LEDAKEMLT12_LEAKTIME_niederreiter_keygen(&pk_nie, (privateKeyNiederreiter_t *) sk, &niederreiter_keys_expander); pack_pk(pk, &pk_nie); @@ -53,7 +53,7 @@ int PQCLEAN_LEDAKEMLT32_CLEAN_crypto_kem_keypair(unsigned char *pk, unsigned cha /* Encrypt - pk is the public key, ct is a key encapsulation message (ciphertext), ss is the shared secret.*/ -int PQCLEAN_LEDAKEMLT32_CLEAN_crypto_kem_enc(unsigned char *ct, unsigned char *ss, const unsigned char *pk) { +int PQCLEAN_LEDAKEMLT12_LEAKTIME_crypto_kem_enc(unsigned char *ct, unsigned char *ss, const unsigned char *pk) { AES_XOF_struct niederreiter_encap_key_expander; unsigned char encapsulated_key_seed[TRNG_BYTE_LENGTH]; DIGIT error_vector[N0 * NUM_DIGITS_GF2X_ELEMENT]; @@ -64,11 +64,11 @@ int PQCLEAN_LEDAKEMLT32_CLEAN_crypto_kem_enc(unsigned char *ct, unsigned char *s randombytes(encapsulated_key_seed, TRNG_BYTE_LENGTH); unpack_pk(&pk_nie, pk); - PQCLEAN_LEDAKEMLT32_CLEAN_seedexpander_from_trng(&niederreiter_encap_key_expander, encapsulated_key_seed); - PQCLEAN_LEDAKEMLT32_CLEAN_rand_circulant_blocks_sequence(error_vector, &niederreiter_encap_key_expander); + PQCLEAN_LEDAKEMLT12_LEAKTIME_seedexpander_from_trng(&niederreiter_encap_key_expander, encapsulated_key_seed); + PQCLEAN_LEDAKEMLT12_LEAKTIME_rand_circulant_blocks_sequence(error_vector, &niederreiter_encap_key_expander); pack_error(error_bytes, error_vector); HASH_FUNCTION(ss, error_bytes, (N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B)); - PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_encrypt(syndrome, &pk_nie, error_vector); + PQCLEAN_LEDAKEMLT12_LEAKTIME_niederreiter_encrypt(syndrome, &pk_nie, error_vector); pack_ct(ct, syndrome); @@ -78,13 +78,13 @@ int PQCLEAN_LEDAKEMLT32_CLEAN_crypto_kem_enc(unsigned char *ct, unsigned char *s /* Decrypt - ct is a key encapsulation message (ciphertext), sk is the private key, ss is the shared secret */ -int PQCLEAN_LEDAKEMLT32_CLEAN_crypto_kem_dec(unsigned char *ss, const unsigned char *ct, const unsigned char *sk) { +int PQCLEAN_LEDAKEMLT12_LEAKTIME_crypto_kem_dec(unsigned char *ss, const unsigned char *ct, const unsigned char *sk) { DIGIT decoded_error_vector[N0 * NUM_DIGITS_GF2X_ELEMENT]; uint8_t decoded_error_bytes[N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B]; DIGIT syndrome[NUM_DIGITS_GF2X_ELEMENT]; unpack_ct(syndrome, ct); - PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_decrypt(decoded_error_vector, (privateKeyNiederreiter_t *)sk, syndrome); + PQCLEAN_LEDAKEMLT12_LEAKTIME_niederreiter_decrypt(decoded_error_vector, (privateKeyNiederreiter_t *)sk, syndrome); pack_error(decoded_error_bytes, decoded_error_vector); HASH_FUNCTION(ss, decoded_error_bytes, (N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B)); diff --git a/crypto_kem/ledakemlt52/clean/niederreiter.c b/crypto_kem/ledakemlt12/leaktime/niederreiter.c similarity index 65% rename from crypto_kem/ledakemlt52/clean/niederreiter.c rename to crypto_kem/ledakemlt12/leaktime/niederreiter.c index 82fabcc5..273f2c41 100644 --- a/crypto_kem/ledakemlt52/clean/niederreiter.c +++ b/crypto_kem/ledakemlt12/leaktime/niederreiter.c @@ -8,7 +8,7 @@ #include -void PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, privateKeyNiederreiter_t *sk, AES_XOF_struct *keys_expander) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_niederreiter_keygen(publicKeyNiederreiter_t *pk, privateKeyNiederreiter_t *sk, AES_XOF_struct *keys_expander) { POSITION_T HPosOnes[N0][DV]; // sequence of N0 circ block matrices (p x p): Hi POSITION_T HtrPosOnes[N0][DV]; // Sparse tranposed circulant H @@ -23,8 +23,8 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, sk->rejections = (int8_t) 0; do { - PQCLEAN_LEDAKEMLT52_CLEAN_generateHPosOnes_HtrPosOnes(HPosOnes, HtrPosOnes, keys_expander); - PQCLEAN_LEDAKEMLT52_CLEAN_generateQsparse(QPosOnes, keys_expander); + PQCLEAN_LEDAKEMLT12_LEAKTIME_generateHPosOnes_HtrPosOnes(HPosOnes, HtrPosOnes, keys_expander); + PQCLEAN_LEDAKEMLT12_LEAKTIME_generateQsparse(QPosOnes, keys_expander); for (int i = 0; i < N0; i++) { for (int j = 0; j < DV * M; j++) { LPosOnes[i][j] = INVALID_POS_VALUE; @@ -34,10 +34,10 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, memset(processedQOnes, 0x00, sizeof(processedQOnes)); for (int colQ = 0; colQ < N0; colQ++) { for (int i = 0; i < N0; i++) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_sparse(DV * M, auxPosOnes, + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_mul_sparse(DV * M, auxPosOnes, DV, HPosOnes[i], qBlockWeights[i][colQ], QPosOnes[i] + processedQOnes[i]); - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_add_sparse(DV * M, LPosOnes[colQ], + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_add_sparse(DV * M, LPosOnes[colQ], DV * M, LPosOnes[colQ], DV * M, auxPosOnes); processedQOnes[i] += qBlockWeights[i][colQ]; @@ -49,7 +49,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, } sk->rejections = sk->rejections + 1; if (is_L_full) { - threshold = PQCLEAN_LEDAKEMLT52_CLEAN_DFR_test(LPosOnes); + threshold = PQCLEAN_LEDAKEMLT12_LEAKTIME_DFR_test(LPosOnes); } } while (!is_L_full || threshold == DFR_TEST_FAIL); sk->rejections = sk->rejections - 1; @@ -58,41 +58,41 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, memset(Ln0dense, 0x00, sizeof(Ln0dense)); for (int j = 0; j < DV * M; j++) { if (LPosOnes[N0 - 1][j] != INVALID_POS_VALUE) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_set_coeff(Ln0dense, LPosOnes[N0 - 1][j], 1); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_set_coeff(Ln0dense, LPosOnes[N0 - 1][j], 1); } } memset(Ln0Inv, 0x00, sizeof(Ln0Inv)); - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_inverse(Ln0Inv, Ln0dense); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_inverse(Ln0Inv, Ln0dense); for (int i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_dense_to_sparse(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_mul_dense_to_sparse(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, Ln0Inv, LPosOnes[i], DV * M); } for (int i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_transpose_in_place(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_transpose_in_place(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT); } } -void PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_encrypt(DIGIT *syndrome, const publicKeyNiederreiter_t *pk, const DIGIT *err) { +void PQCLEAN_LEDAKEMLT12_LEAKTIME_niederreiter_encrypt(DIGIT *syndrome, const publicKeyNiederreiter_t *pk, const DIGIT *err) { int i; DIGIT saux[NUM_DIGITS_GF2X_ELEMENT]; memset(syndrome, 0x00, NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); for (i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul(saux, - pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, - err + i * NUM_DIGITS_GF2X_ELEMENT); - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_add(syndrome, syndrome, saux); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_mul(saux, + pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, + err + i * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_add(syndrome, syndrome, saux); } - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_add(syndrome, syndrome, err + (N0 - 1)*NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_add(syndrome, syndrome, err + (N0 - 1)*NUM_DIGITS_GF2X_ELEMENT); } -int PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyNiederreiter_t *sk, const DIGIT *syndrome) { +int PQCLEAN_LEDAKEMLT12_LEAKTIME_niederreiter_decrypt(DIGIT *err, const privateKeyNiederreiter_t *sk, const DIGIT *syndrome) { AES_XOF_struct niederreiter_decrypt_expander; POSITION_T HPosOnes[N0][DV]; POSITION_T HtrPosOnes[N0][DV]; @@ -110,11 +110,11 @@ int PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyN int currQoneIdx, endQblockIdx; int decryptOk, err_weight; - PQCLEAN_LEDAKEMLT52_CLEAN_seedexpander_from_trng(&niederreiter_decrypt_expander, sk->prng_seed); + PQCLEAN_LEDAKEMLT12_LEAKTIME_seedexpander_from_trng(&niederreiter_decrypt_expander, sk->prng_seed); do { - PQCLEAN_LEDAKEMLT52_CLEAN_generateHPosOnes_HtrPosOnes(HPosOnes, HtrPosOnes, &niederreiter_decrypt_expander); - PQCLEAN_LEDAKEMLT52_CLEAN_generateQsparse(QPosOnes, &niederreiter_decrypt_expander); + PQCLEAN_LEDAKEMLT12_LEAKTIME_generateHPosOnes_HtrPosOnes(HPosOnes, HtrPosOnes, &niederreiter_decrypt_expander); + PQCLEAN_LEDAKEMLT12_LEAKTIME_generateQsparse(QPosOnes, &niederreiter_decrypt_expander); for (int i = 0; i < N0; i++) { for (int j = 0; j < DV * M; j++) { LPosOnes[i][j] = INVALID_POS_VALUE; @@ -124,10 +124,10 @@ int PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyN memset(processedQOnes, 0x00, sizeof(processedQOnes)); for (int colQ = 0; colQ < N0; colQ++) { for (int i = 0; i < N0; i++) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_sparse(DV * M, auxPosOnes, + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_mul_sparse(DV * M, auxPosOnes, DV, HPosOnes[i], qBlockWeights[i][colQ], QPosOnes[i] + processedQOnes[i]); - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_add_sparse(DV * M, LPosOnes[colQ], + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_add_sparse(DV * M, LPosOnes[colQ], DV * M, LPosOnes[colQ], DV * M, auxPosOnes); processedQOnes[i] += qBlockWeights[i][colQ]; @@ -156,31 +156,31 @@ int PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyN } for (int i = 0; i < N0; i++) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_sparse(DV * M, auxSparse, + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_mul_sparse(DV * M, auxSparse, DV, HPosOnes[i], qBlockWeights[i][N0 - 1], &QPosOnes[i][ M - qBlockWeights[i][N0 - 1]]); - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_add_sparse(DV * M, Ln0trSparse, + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_add_sparse(DV * M, Ln0trSparse, DV * M, Ln0trSparse, DV * M, auxSparse); } - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_transpose_in_place_sparse(DV * M, Ln0trSparse); - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_dense_to_sparse(privateSyndrome, syndrome, Ln0trSparse, DV * M); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_transpose_in_place_sparse(DV * M, Ln0trSparse); + PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mod_mul_dense_to_sparse(privateSyndrome, syndrome, Ln0trSparse, DV * M); /* prepare mockup error vector in case a decoding failure occurs */ memset(mockup_error_vector, 0x00, N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); memcpy(mockup_error_vector, syndrome, NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); - PQCLEAN_LEDAKEMLT52_CLEAN_seedexpander(&niederreiter_decrypt_expander, - ((unsigned char *) mockup_error_vector) + (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B), - TRNG_BYTE_LENGTH); + PQCLEAN_LEDAKEMLT12_LEAKTIME_seedexpander(&niederreiter_decrypt_expander, + ((unsigned char *) mockup_error_vector) + (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B), + TRNG_BYTE_LENGTH); memset(err, 0x00, N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); - decryptOk = PQCLEAN_LEDAKEMLT52_CLEAN_bf_decoding(err, (const POSITION_T (*)[DV]) HtrPosOnes, + decryptOk = PQCLEAN_LEDAKEMLT12_LEAKTIME_bf_decoding(err, (const POSITION_T (*)[DV]) HtrPosOnes, (const POSITION_T (*)[M]) QtrPosOnes, privateSyndrome, sk->threshold); err_weight = 0; for (int i = 0 ; i < N0; i++) { - err_weight += PQCLEAN_LEDAKEMLT52_CLEAN_population_count(err + (NUM_DIGITS_GF2X_ELEMENT * i)); + err_weight += PQCLEAN_LEDAKEMLT12_LEAKTIME_population_count(err + (NUM_DIGITS_GF2X_ELEMENT * i)); } decryptOk = decryptOk && (err_weight == NUM_ERRORS_T); diff --git a/crypto_kem/ledakemlt12/clean/niederreiter.h b/crypto_kem/ledakemlt12/leaktime/niederreiter.h similarity index 64% rename from crypto_kem/ledakemlt12/clean/niederreiter.h rename to crypto_kem/ledakemlt12/leaktime/niederreiter.h index 428726cf..17da4c29 100644 --- a/crypto_kem/ledakemlt12/clean/niederreiter.h +++ b/crypto_kem/ledakemlt12/leaktime/niederreiter.h @@ -21,9 +21,9 @@ typedef struct { // with P coefficients. } publicKeyNiederreiter_t; -void PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, privateKeyNiederreiter_t *sk, AES_XOF_struct *keys_expander); -void PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_encrypt(DIGIT syndrome[], const publicKeyNiederreiter_t *pk, const DIGIT *err); -int PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyNiederreiter_t *sk, const DIGIT *syndrome); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_niederreiter_keygen(publicKeyNiederreiter_t *pk, privateKeyNiederreiter_t *sk, AES_XOF_struct *keys_expander); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_niederreiter_encrypt(DIGIT syndrome[], const publicKeyNiederreiter_t *pk, const DIGIT *err); +int PQCLEAN_LEDAKEMLT12_LEAKTIME_niederreiter_decrypt(DIGIT *err, const privateKeyNiederreiter_t *sk, const DIGIT *syndrome); #endif diff --git a/crypto_kem/ledakemlt12/clean/qc_ldpc_parameters.h b/crypto_kem/ledakemlt12/leaktime/qc_ldpc_parameters.h similarity index 100% rename from crypto_kem/ledakemlt12/clean/qc_ldpc_parameters.h rename to crypto_kem/ledakemlt12/leaktime/qc_ldpc_parameters.h diff --git a/crypto_kem/ledakemlt12/clean/rng.c b/crypto_kem/ledakemlt12/leaktime/rng.c similarity index 94% rename from crypto_kem/ledakemlt12/clean/rng.c rename to crypto_kem/ledakemlt12/leaktime/rng.c index 913b9e67..6d7604e6 100644 --- a/crypto_kem/ledakemlt12/clean/rng.c +++ b/crypto_kem/ledakemlt12/leaktime/rng.c @@ -37,7 +37,7 @@ static void seedexpander_init(AES_XOF_struct *ctx, memset(ctx->buffer, 0x00, 16); } -void PQCLEAN_LEDAKEMLT12_CLEAN_seedexpander_from_trng(AES_XOF_struct *ctx, +void PQCLEAN_LEDAKEMLT12_LEAKTIME_seedexpander_from_trng(AES_XOF_struct *ctx, const unsigned char *trng_entropy /* TRNG_BYTE_LENGTH wide buffer */) { @@ -61,7 +61,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_seedexpander_from_trng(AES_XOF_struct *ctx, x - returns the XOF data xlen - number of bytes to return */ -int PQCLEAN_LEDAKEMLT12_CLEAN_seedexpander(AES_XOF_struct *ctx, unsigned char *x, size_t xlen) { +int PQCLEAN_LEDAKEMLT12_LEAKTIME_seedexpander(AES_XOF_struct *ctx, unsigned char *x, size_t xlen) { size_t offset; aes256ctx ctx256; diff --git a/crypto_kem/ledakemlt12/clean/rng.h b/crypto_kem/ledakemlt12/leaktime/rng.h similarity index 66% rename from crypto_kem/ledakemlt12/clean/rng.h rename to crypto_kem/ledakemlt12/leaktime/rng.h index 204e8f7b..09a81a57 100644 --- a/crypto_kem/ledakemlt12/clean/rng.h +++ b/crypto_kem/ledakemlt12/leaktime/rng.h @@ -18,7 +18,7 @@ typedef struct { unsigned char ctr[16]; } AES_XOF_struct; -int PQCLEAN_LEDAKEMLT12_CLEAN_seedexpander(AES_XOF_struct *ctx, unsigned char *x, size_t xlen); -void PQCLEAN_LEDAKEMLT12_CLEAN_seedexpander_from_trng(AES_XOF_struct *ctx, const unsigned char *trng_entropy); +int PQCLEAN_LEDAKEMLT12_LEAKTIME_seedexpander(AES_XOF_struct *ctx, unsigned char *x, size_t xlen); +void PQCLEAN_LEDAKEMLT12_LEAKTIME_seedexpander_from_trng(AES_XOF_struct *ctx, const unsigned char *trng_entropy); #endif diff --git a/crypto_kem/ledakemlt32/META.yml b/crypto_kem/ledakemlt32/META.yml index ed52b88d..c6c040a5 100644 --- a/crypto_kem/ledakemlt32/META.yml +++ b/crypto_kem/ledakemlt32/META.yml @@ -14,5 +14,5 @@ auxiliary-submitters: - Gerardo Pelosi - Paolo Santini implementations: - - name: clean + - name: leaktime version: 2.? diff --git a/crypto_kem/ledakemlt32/clean/H_Q_matrices_generation.h b/crypto_kem/ledakemlt32/clean/H_Q_matrices_generation.h deleted file mode 100644 index 68d4703d..00000000 --- a/crypto_kem/ledakemlt32/clean/H_Q_matrices_generation.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef H_Q_MATRICES_GENERATION_H -#define H_Q_MATRICES_GENERATION_H - -#include "gf2x_arith.h" -#include "qc_ldpc_parameters.h" -#include "rng.h" - -void PQCLEAN_LEDAKEMLT32_CLEAN_generateHPosOnes_HtrPosOnes(POSITION_T HPosOnes[N0][DV], POSITION_T HtrPosOnes[N0][DV], AES_XOF_struct *niederreiter_keys_expander); -void PQCLEAN_LEDAKEMLT32_CLEAN_generateQsparse(POSITION_T pos_ones[N0][M], AES_XOF_struct *niederreiter_keys_expander); - -#endif diff --git a/crypto_kem/ledakemlt32/clean/api.h b/crypto_kem/ledakemlt32/clean/api.h deleted file mode 100644 index 0d54b775..00000000 --- a/crypto_kem/ledakemlt32/clean/api.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef PQCLEAN_LEDAKEMLT32_CLEAN_API_H -#define PQCLEAN_LEDAKEMLT32_CLEAN_API_H - -#include - -#define PQCLEAN_LEDAKEMLT32_CLEAN_CRYPTO_SECRETKEYBYTES 34 -#define PQCLEAN_LEDAKEMLT32_CLEAN_CRYPTO_PUBLICKEYBYTES 12032 -#define PQCLEAN_LEDAKEMLT32_CLEAN_CRYPTO_CIPHERTEXTBYTES 12032 -#define PQCLEAN_LEDAKEMLT32_CLEAN_CRYPTO_BYTES 48 - -#define PQCLEAN_LEDAKEMLT32_CLEAN_CRYPTO_ALGNAME "LEDAKEMLT32" - -int PQCLEAN_LEDAKEMLT32_CLEAN_crypto_kem_keypair(uint8_t *pk, uint8_t *sk); -int PQCLEAN_LEDAKEMLT32_CLEAN_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk); -int PQCLEAN_LEDAKEMLT32_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk); - - -#endif diff --git a/crypto_kem/ledakemlt32/clean/dfr_test.h b/crypto_kem/ledakemlt32/clean/dfr_test.h deleted file mode 100644 index 1dd40cd2..00000000 --- a/crypto_kem/ledakemlt32/clean/dfr_test.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef DFR_TEST_H -#define DFR_TEST_H - -#define DFR_TEST_FAIL (255) - -uint8_t PQCLEAN_LEDAKEMLT32_CLEAN_DFR_test(POSITION_T LSparse[N0][DV * M]); - -#endif diff --git a/crypto_kem/ledakemlt32/clean/gf2x_arith_mod_xPplusOne.h b/crypto_kem/ledakemlt32/clean/gf2x_arith_mod_xPplusOne.h deleted file mode 100644 index 371ae170..00000000 --- a/crypto_kem/ledakemlt32/clean/gf2x_arith_mod_xPplusOne.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef GF2X_ARITH_MOD_XPLUSONE_H -#define GF2X_ARITH_MOD_XPLUSONE_H - -#include "qc_ldpc_parameters.h" - -#include "gf2x_arith.h" -#include "rng.h" - -#define NUM_BITS_GF2X_ELEMENT (P) // 96221 -#define NUM_DIGITS_GF2X_ELEMENT ((P+DIGIT_SIZE_b-1)/DIGIT_SIZE_b) -#define MSb_POSITION_IN_MSB_DIGIT_OF_ELEMENT ((P % DIGIT_SIZE_b) ? (P % DIGIT_SIZE_b)-1 : DIGIT_SIZE_b-1) -#define NUM_BITS_GF2X_MODULUS (P+1) -#define NUM_DIGITS_GF2X_MODULUS ((P+1+DIGIT_SIZE_b-1)/DIGIT_SIZE_b) -#define MSb_POSITION_IN_MSB_DIGIT_OF_MODULUS (P-DIGIT_SIZE_b*(NUM_DIGITS_GF2X_MODULUS-1)) -#define INVALID_POS_VALUE (P) -#define P_BITS (17) // log_2(p) = 16.55406417 - -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_copy(DIGIT dest[], const DIGIT in[]); -DIGIT PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_get_coeff(const DIGIT poly[], unsigned int exponent); -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_set_coeff(DIGIT poly[], unsigned int exponent, DIGIT value); -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_toggle_coeff(DIGIT poly[], unsigned int exponent); -int PQCLEAN_LEDAKEMLT32_CLEAN_population_count(DIGIT *poly); -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_add(DIGIT Res[], const DIGIT A[], const DIGIT B[]); -void PQCLEAN_LEDAKEMLT32_CLEAN_quicksort_sparse(POSITION_T Res[]); -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const DIGIT B[]); -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_transpose_in_place(DIGIT A[]); -void PQCLEAN_LEDAKEMLT32_CLEAN_rand_circulant_sparse_block(POSITION_T *pos_ones, int countOnes, AES_XOF_struct *seed_expander_ctx); -void PQCLEAN_LEDAKEMLT32_CLEAN_rand_circulant_blocks_sequence(DIGIT *sequence, AES_XOF_struct *seed_expander_ctx); -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_add_sparse(int sizeR, POSITION_T Res[], int sizeA, const POSITION_T A[], int sizeB, const POSITION_T B[]); -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_transpose_in_place_sparse(int sizeA, POSITION_T A[]); -int PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]); -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[], size_t sizeA, const POSITION_T A[], size_t sizeB, const POSITION_T B[]); -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_dense_to_sparse(DIGIT Res[], const DIGIT dense[], POSITION_T sparse[], unsigned int nPos); -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly); -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_frombytes(DIGIT *poly, const uint8_t *poly_bytes); - - -#endif diff --git a/crypto_kem/ledakemlt52/clean/H_Q_matrices_generation.c b/crypto_kem/ledakemlt32/leaktime/H_Q_matrices_generation.c similarity index 72% rename from crypto_kem/ledakemlt52/clean/H_Q_matrices_generation.c rename to crypto_kem/ledakemlt32/leaktime/H_Q_matrices_generation.c index ff832abf..37a455b1 100644 --- a/crypto_kem/ledakemlt52/clean/H_Q_matrices_generation.c +++ b/crypto_kem/ledakemlt32/leaktime/H_Q_matrices_generation.c @@ -1,13 +1,13 @@ #include "H_Q_matrices_generation.h" #include "gf2x_arith_mod_xPplusOne.h" -void PQCLEAN_LEDAKEMLT52_CLEAN_generateHPosOnes_HtrPosOnes( +void PQCLEAN_LEDAKEMLT32_LEAKTIME_generateHPosOnes_HtrPosOnes( POSITION_T HPosOnes[N0][DV], POSITION_T HtrPosOnes[N0][DV], AES_XOF_struct *keys_expander) { for (int i = 0; i < N0; i++) { /* Generate a random block of Htr */ - PQCLEAN_LEDAKEMLT52_CLEAN_rand_circulant_sparse_block(&HtrPosOnes[i][0], DV, keys_expander); + PQCLEAN_LEDAKEMLT32_LEAKTIME_rand_circulant_sparse_block(&HtrPosOnes[i][0], DV, keys_expander); } for (int i = 0; i < N0; i++) { /* Obtain directly the sparse representation of the block of H */ @@ -17,13 +17,13 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_generateHPosOnes_HtrPosOnes( } } -void PQCLEAN_LEDAKEMLT52_CLEAN_generateQsparse( +void PQCLEAN_LEDAKEMLT32_LEAKTIME_generateQsparse( POSITION_T pos_ones[N0][M], AES_XOF_struct *keys_expander) { for (int i = 0; i < N0; i++) { int placed_ones = 0; for (int j = 0; j < N0; j++) { - PQCLEAN_LEDAKEMLT52_CLEAN_rand_circulant_sparse_block(&pos_ones[i][placed_ones], + PQCLEAN_LEDAKEMLT32_LEAKTIME_rand_circulant_sparse_block(&pos_ones[i][placed_ones], qBlockWeights[i][j], keys_expander); placed_ones += qBlockWeights[i][j]; diff --git a/crypto_kem/ledakemlt32/leaktime/H_Q_matrices_generation.h b/crypto_kem/ledakemlt32/leaktime/H_Q_matrices_generation.h new file mode 100644 index 00000000..23bd44f0 --- /dev/null +++ b/crypto_kem/ledakemlt32/leaktime/H_Q_matrices_generation.h @@ -0,0 +1,11 @@ +#ifndef H_Q_MATRICES_GENERATION_H +#define H_Q_MATRICES_GENERATION_H + +#include "gf2x_arith.h" +#include "qc_ldpc_parameters.h" +#include "rng.h" + +void PQCLEAN_LEDAKEMLT32_LEAKTIME_generateHPosOnes_HtrPosOnes(POSITION_T HPosOnes[N0][DV], POSITION_T HtrPosOnes[N0][DV], AES_XOF_struct *niederreiter_keys_expander); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_generateQsparse(POSITION_T pos_ones[N0][M], AES_XOF_struct *niederreiter_keys_expander); + +#endif diff --git a/crypto_kem/ledakemlt32/clean/LICENSE b/crypto_kem/ledakemlt32/leaktime/LICENSE similarity index 100% rename from crypto_kem/ledakemlt32/clean/LICENSE rename to crypto_kem/ledakemlt32/leaktime/LICENSE diff --git a/crypto_kem/ledakemlt32/clean/Makefile b/crypto_kem/ledakemlt32/leaktime/Makefile similarity index 95% rename from crypto_kem/ledakemlt32/clean/Makefile rename to crypto_kem/ledakemlt32/leaktime/Makefile index 4d17eb30..d8d4e9cb 100644 --- a/crypto_kem/ledakemlt32/clean/Makefile +++ b/crypto_kem/ledakemlt32/leaktime/Makefile @@ -1,6 +1,6 @@ # This Makefile can be used with GNU Make or BSD Make -LIB=libledakemlt32_clean.a +LIB=libledakemlt32_leaktime.a HEADERS=api.h bf_decoding.h dfr_test.h gf2x_arith_mod_xPplusOne.h \ gf2x_arith.h H_Q_matrices_generation.h \ niederreiter.h qc_ldpc_parameters.h rng.h diff --git a/crypto_kem/ledakemlt52/clean/Makefile.Microsoft_nmake b/crypto_kem/ledakemlt32/leaktime/Makefile.Microsoft_nmake similarity index 93% rename from crypto_kem/ledakemlt52/clean/Makefile.Microsoft_nmake rename to crypto_kem/ledakemlt32/leaktime/Makefile.Microsoft_nmake index 3cbd9d76..f895e6dc 100644 --- a/crypto_kem/ledakemlt52/clean/Makefile.Microsoft_nmake +++ b/crypto_kem/ledakemlt32/leaktime/Makefile.Microsoft_nmake @@ -1,7 +1,7 @@ # This Makefile can be used with Microsoft Visual Studio's nmake using the command: # nmake /f Makefile.Microsoft_nmake -LIBRARY=libledakemlt52_clean.lib +LIBRARY=libledakemlt32_leaktime.lib OBJECTS=bf_decoding.obj dfr_test.obj gf2x_arith_mod_xPplusOne.obj gf2x_arith.obj H_Q_matrices_generation.obj kem.obj niederreiter.obj rng.obj CFLAGS=/nologo /I ..\..\..\common /W4 /WX diff --git a/crypto_kem/ledakemlt32/leaktime/api.h b/crypto_kem/ledakemlt32/leaktime/api.h new file mode 100644 index 00000000..0a048aa3 --- /dev/null +++ b/crypto_kem/ledakemlt32/leaktime/api.h @@ -0,0 +1,18 @@ +#ifndef PQCLEAN_LEDAKEMLT32_LEAKTIME_API_H +#define PQCLEAN_LEDAKEMLT32_LEAKTIME_API_H + +#include + +#define PQCLEAN_LEDAKEMLT32_LEAKTIME_CRYPTO_SECRETKEYBYTES 34 +#define PQCLEAN_LEDAKEMLT32_LEAKTIME_CRYPTO_PUBLICKEYBYTES 12032 +#define PQCLEAN_LEDAKEMLT32_LEAKTIME_CRYPTO_CIPHERTEXTBYTES 12032 +#define PQCLEAN_LEDAKEMLT32_LEAKTIME_CRYPTO_BYTES 48 + +#define PQCLEAN_LEDAKEMLT32_LEAKTIME_CRYPTO_ALGNAME "LEDAKEMLT32" + +int PQCLEAN_LEDAKEMLT32_LEAKTIME_crypto_kem_keypair(uint8_t *pk, uint8_t *sk); +int PQCLEAN_LEDAKEMLT32_LEAKTIME_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk); +int PQCLEAN_LEDAKEMLT32_LEAKTIME_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk); + + +#endif diff --git a/crypto_kem/ledakemlt52/clean/bf_decoding.c b/crypto_kem/ledakemlt32/leaktime/bf_decoding.c similarity index 87% rename from crypto_kem/ledakemlt52/clean/bf_decoding.c rename to crypto_kem/ledakemlt32/leaktime/bf_decoding.c index 5e209aa9..764904f1 100644 --- a/crypto_kem/ledakemlt52/clean/bf_decoding.c +++ b/crypto_kem/ledakemlt32/leaktime/bf_decoding.c @@ -4,7 +4,7 @@ #include #include -int PQCLEAN_LEDAKEMLT52_CLEAN_bf_decoding(DIGIT err[], +int PQCLEAN_LEDAKEMLT32_LEAKTIME_bf_decoding(DIGIT err[], const POSITION_T HtrPosOnes[N0][DV], const POSITION_T QtrPosOnes[N0][M], DIGIT privateSyndrome[], @@ -18,13 +18,13 @@ int PQCLEAN_LEDAKEMLT52_CLEAN_bf_decoding(DIGIT err[], unsigned int corrt_syndrome_based; do { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_copy(currSyndrome, privateSyndrome); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_copy(currSyndrome, privateSyndrome); memset(unsatParityChecks, 0x00, N0 * P * sizeof(uint8_t)); for (int i = 0; i < N0; i++) { for (int valueIdx = 0; valueIdx < P; valueIdx++) { for (int HtrOneIdx = 0; HtrOneIdx < DV; HtrOneIdx++) { POSITION_T tmp = (HtrPosOnes[i][HtrOneIdx] + valueIdx) >= P ? (HtrPosOnes[i][HtrOneIdx] + valueIdx) - P : (HtrPosOnes[i][HtrOneIdx] + valueIdx); - if (PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_get_coeff(currSyndrome, tmp)) { + if (PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_get_coeff(currSyndrome, tmp)) { unsatParityChecks[i * P + valueIdx]++; } } @@ -54,13 +54,13 @@ int PQCLEAN_LEDAKEMLT52_CLEAN_bf_decoding(DIGIT err[], } /* Correlation based flipping */ if (correlation >= corrt_syndrome_based) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_toggle_coeff(err + NUM_DIGITS_GF2X_ELEMENT * i, j); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_toggle_coeff(err + NUM_DIGITS_GF2X_ELEMENT * i, j); for (int v = 0; v < M; v++) { POSITION_T syndromePosToFlip; for (int HtrOneIdx = 0; HtrOneIdx < DV; HtrOneIdx++) { syndromePosToFlip = (HtrPosOnes[currQBlkPos[v]][HtrOneIdx] + currQBitPos[v] ); syndromePosToFlip = syndromePosToFlip >= P ? syndromePosToFlip - P : syndromePosToFlip; - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_toggle_coeff(privateSyndrome, syndromePosToFlip); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_toggle_coeff(privateSyndrome, syndromePosToFlip); } } // end for v } // end if diff --git a/crypto_kem/ledakemlt32/clean/bf_decoding.h b/crypto_kem/ledakemlt32/leaktime/bf_decoding.h similarity index 87% rename from crypto_kem/ledakemlt32/clean/bf_decoding.h rename to crypto_kem/ledakemlt32/leaktime/bf_decoding.h index 31cc369a..a55b0300 100644 --- a/crypto_kem/ledakemlt32/clean/bf_decoding.h +++ b/crypto_kem/ledakemlt32/leaktime/bf_decoding.h @@ -9,7 +9,7 @@ #define B0 (64) #define T_BAR (5) -int PQCLEAN_LEDAKEMLT32_CLEAN_bf_decoding(DIGIT err[], +int PQCLEAN_LEDAKEMLT32_LEAKTIME_bf_decoding(DIGIT err[], const POSITION_T HtrPosOnes[N0][DV], const POSITION_T QtrPosOnes[N0][M], DIGIT privateSyndrome[], diff --git a/crypto_kem/ledakemlt12/clean/dfr_test.c b/crypto_kem/ledakemlt32/leaktime/dfr_test.c similarity index 94% rename from crypto_kem/ledakemlt12/clean/dfr_test.c rename to crypto_kem/ledakemlt32/leaktime/dfr_test.c index 70c4b26d..73a52f6f 100644 --- a/crypto_kem/ledakemlt12/clean/dfr_test.c +++ b/crypto_kem/ledakemlt32/leaktime/dfr_test.c @@ -9,7 +9,7 @@ * computes the threshold for the second iteration of the decoder and returns this values * (max DV * M), on failure it returns 255 >> DV * M */ -uint8_t PQCLEAN_LEDAKEMLT12_CLEAN_DFR_test(POSITION_T LSparse[N0][DV * M]) { +uint8_t PQCLEAN_LEDAKEMLT32_LEAKTIME_DFR_test(POSITION_T LSparse[N0][DV * M]) { POSITION_T LSparse_loc[N0][DV * M]; POSITION_T rotated_column[DV * M]; @@ -31,7 +31,7 @@ uint8_t PQCLEAN_LEDAKEMLT12_CLEAN_DFR_test(POSITION_T LSparse[N0][DV * M]) { LSparse_loc[i][j] = (P - LSparse[i][j]); } } - PQCLEAN_LEDAKEMLT12_CLEAN_quicksort_sparse(LSparse_loc[i]); + PQCLEAN_LEDAKEMLT32_LEAKTIME_quicksort_sparse(LSparse_loc[i]); } for (int i = 0; i < N0; i++ ) { @@ -41,7 +41,7 @@ uint8_t PQCLEAN_LEDAKEMLT12_CLEAN_DFR_test(POSITION_T LSparse[N0][DV * M]) { for (int idxToRotate = 0; idxToRotate < (DV * M); idxToRotate++) { rotated_column[idxToRotate] = (LSparse_loc[j][idxToRotate] + k) % P; } - PQCLEAN_LEDAKEMLT12_CLEAN_quicksort_sparse(rotated_column); + PQCLEAN_LEDAKEMLT32_LEAKTIME_quicksort_sparse(rotated_column); /* compute the intersection amount */ firstidx = 0, secondidx = 0; intersectionval = 0; diff --git a/crypto_kem/ledakemlt32/leaktime/dfr_test.h b/crypto_kem/ledakemlt32/leaktime/dfr_test.h new file mode 100644 index 00000000..d1484ac9 --- /dev/null +++ b/crypto_kem/ledakemlt32/leaktime/dfr_test.h @@ -0,0 +1,8 @@ +#ifndef DFR_TEST_H +#define DFR_TEST_H + +#define DFR_TEST_FAIL (255) + +uint8_t PQCLEAN_LEDAKEMLT32_LEAKTIME_DFR_test(POSITION_T LSparse[N0][DV * M]); + +#endif diff --git a/crypto_kem/ledakemlt12/clean/gf2x_arith.c b/crypto_kem/ledakemlt32/leaktime/gf2x_arith.c similarity index 82% rename from crypto_kem/ledakemlt12/clean/gf2x_arith.c rename to crypto_kem/ledakemlt32/leaktime/gf2x_arith.c index 980c22de..2ce4869f 100644 --- a/crypto_kem/ledakemlt12/clean/gf2x_arith.c +++ b/crypto_kem/ledakemlt32/leaktime/gf2x_arith.c @@ -3,14 +3,14 @@ #include #include // memset(...) -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr) { for (int i = 0; i < nr; i++) { Res[i] = A[i] ^ B[i]; } } /* PRE: MAX ALLOWED ROTATION AMOUNT : DIGIT_SIZE_b */ -void PQCLEAN_LEDAKEMLT12_CLEAN_right_bit_shift_n(int length, DIGIT in[], unsigned int amount) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_right_bit_shift_n(int length, DIGIT in[], unsigned int amount) { assert(amount < DIGIT_SIZE_b); if ( amount == 0 ) { return; @@ -26,7 +26,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_right_bit_shift_n(int length, DIGIT in[], unsigne } /* PRE: MAX ALLOWED ROTATION AMOUNT : DIGIT_SIZE_b */ -void PQCLEAN_LEDAKEMLT12_CLEAN_left_bit_shift_n(int length, DIGIT in[], unsigned int amount) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_left_bit_shift_n(int length, DIGIT in[], unsigned int amount) { assert(amount < DIGIT_SIZE_b); if ( amount == 0 ) { return; @@ -41,7 +41,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_left_bit_shift_n(int length, DIGIT in[], unsigned in[j] <<= amount; } -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mul_comb(int nr, DIGIT Res[], +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mul_comb(int nr, DIGIT Res[], int na, const DIGIT A[], int nb, const DIGIT B[]) { int i, j, k; diff --git a/crypto_kem/ledakemlt32/clean/gf2x_arith.h b/crypto_kem/ledakemlt32/leaktime/gf2x_arith.h similarity index 82% rename from crypto_kem/ledakemlt32/clean/gf2x_arith.h rename to crypto_kem/ledakemlt32/leaktime/gf2x_arith.h index 720d6fde..ff127b2b 100644 --- a/crypto_kem/ledakemlt32/clean/gf2x_arith.h +++ b/crypto_kem/ledakemlt32/leaktime/gf2x_arith.h @@ -48,11 +48,11 @@ typedef uint64_t DIGIT; #define DIGIT_SIZE_b (DIGIT_SIZE_B << 3) #define POSITION_T uint32_t -#define GF2X_MUL PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mul_comb +#define GF2X_MUL PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mul_comb -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr); -void PQCLEAN_LEDAKEMLT32_CLEAN_right_bit_shift_n(int length, DIGIT in[], unsigned int amount); -void PQCLEAN_LEDAKEMLT32_CLEAN_left_bit_shift_n(int length, DIGIT in[], unsigned int amount); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_right_bit_shift_n(int length, DIGIT in[], unsigned int amount); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_left_bit_shift_n(int length, DIGIT in[], unsigned int amount); void GF2X_MUL(int nr, DIGIT Res[], int na, const DIGIT A[], int nb, const DIGIT B[]); #endif diff --git a/crypto_kem/ledakemlt32/clean/gf2x_arith_mod_xPplusOne.c b/crypto_kem/ledakemlt32/leaktime/gf2x_arith_mod_xPplusOne.c similarity index 87% rename from crypto_kem/ledakemlt32/clean/gf2x_arith_mod_xPplusOne.c rename to crypto_kem/ledakemlt32/leaktime/gf2x_arith_mod_xPplusOne.c index 0d69e00e..75109644 100644 --- a/crypto_kem/ledakemlt32/clean/gf2x_arith_mod_xPplusOne.c +++ b/crypto_kem/ledakemlt32/leaktime/gf2x_arith_mod_xPplusOne.c @@ -4,14 +4,14 @@ #include #include // memcpy(...), memset(...) -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_copy(DIGIT dest[], const DIGIT in[]) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_copy(DIGIT dest[], const DIGIT in[]) { for (int i = NUM_DIGITS_GF2X_ELEMENT - 1; i >= 0; i--) { dest[i] = in[i]; } } /* returns the coefficient of the x^exponent term as the LSB of a digit */ -DIGIT PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_get_coeff(const DIGIT poly[], unsigned int exponent) { +DIGIT PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_get_coeff(const DIGIT poly[], unsigned int exponent) { unsigned int straightIdx = (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_b - 1) - exponent; unsigned int digitIdx = straightIdx / DIGIT_SIZE_b; unsigned int inDigitIdx = straightIdx % DIGIT_SIZE_b; @@ -19,7 +19,7 @@ DIGIT PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_get_coeff(const DIGIT poly[], unsigned int } /* sets the coefficient of the x^exponent term as the LSB of a digit */ -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_set_coeff(DIGIT poly[], unsigned int exponent, DIGIT value) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_set_coeff(DIGIT poly[], unsigned int exponent, DIGIT value) { unsigned int straightIdx = (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_b - 1) - exponent; unsigned int digitIdx = straightIdx / DIGIT_SIZE_b; unsigned int inDigitIdx = straightIdx % DIGIT_SIZE_b; @@ -31,7 +31,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_set_coeff(DIGIT poly[], unsigned int exponen } /* toggles (flips) the coefficient of the x^exponent term as the LSB of a digit */ -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_toggle_coeff(DIGIT poly[], unsigned int exponent) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_toggle_coeff(DIGIT poly[], unsigned int exponent) { unsigned int straightIdx = (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_b - 1) - exponent; unsigned int digitIdx = straightIdx / DIGIT_SIZE_b; unsigned int inDigitIdx = straightIdx % DIGIT_SIZE_b; @@ -51,7 +51,7 @@ static int popcount_uint64t(uint64_t x) { } /* population count for a single polynomial */ -int PQCLEAN_LEDAKEMLT32_CLEAN_population_count(DIGIT *poly) { +int PQCLEAN_LEDAKEMLT32_LEAKTIME_population_count(DIGIT *poly) { int ret = 0; for (int i = NUM_DIGITS_GF2X_ELEMENT - 1; i >= 0; i--) { ret += popcount_uint64t(poly[i]); @@ -59,8 +59,8 @@ int PQCLEAN_LEDAKEMLT32_CLEAN_population_count(DIGIT *poly) { return ret; } -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_add(DIGIT Res[], const DIGIT A[], const DIGIT B[]) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_add(Res, A, B, NUM_DIGITS_GF2X_ELEMENT); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_add(DIGIT Res[], const DIGIT A[], const DIGIT B[]) { + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_add(Res, A, B, NUM_DIGITS_GF2X_ELEMENT); } static int partition(POSITION_T arr[], int lo, int hi) { @@ -82,7 +82,7 @@ static int partition(POSITION_T arr[], int lo, int hi) { return i + 1; } -void PQCLEAN_LEDAKEMLT32_CLEAN_quicksort_sparse(POSITION_T Res[]) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_quicksort_sparse(POSITION_T Res[]) { int stack[DV * M]; int hi, lo, pivot, tos = -1; stack[++tos] = 0; @@ -175,7 +175,7 @@ static void left_DIGIT_shift_n(unsigned int length, DIGIT in[], unsigned int amo /* may shift by an arbitrary amount*/ static void left_bit_shift_wide_n(const int length, DIGIT in[], unsigned int amount) { left_DIGIT_shift_n(length, in, amount / DIGIT_SIZE_b); - PQCLEAN_LEDAKEMLT32_CLEAN_left_bit_shift_n(length, in, amount % DIGIT_SIZE_b); + PQCLEAN_LEDAKEMLT32_LEAKTIME_left_bit_shift_n(length, in, amount % DIGIT_SIZE_b); } /* Hackers delight, reverses a uint64_t */ @@ -193,7 +193,7 @@ static DIGIT reverse_digit(DIGIT x) { return x; } -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_transpose_in_place(DIGIT A[]) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_transpose_in_place(DIGIT A[]) { /* it keeps the lsb in the same position and * inverts the sequence of the remaining bits */ @@ -214,7 +214,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_transpose_in_place(DIGIT A[]) { // A[NUM_DIGITS_GF2X_ELEMENT / 2] = reverse_digit(A[NUM_DIGITS_GF2X_ELEMENT / 2]); // no middle digit if (slack_bits_amount) { - PQCLEAN_LEDAKEMLT32_CLEAN_right_bit_shift_n(NUM_DIGITS_GF2X_ELEMENT, A, slack_bits_amount); + PQCLEAN_LEDAKEMLT32_LEAKTIME_right_bit_shift_n(NUM_DIGITS_GF2X_ELEMENT, A, slack_bits_amount); } A[NUM_DIGITS_GF2X_ELEMENT - 1] = (A[NUM_DIGITS_GF2X_ELEMENT - 1] & (~mask)) | a00; } @@ -265,7 +265,7 @@ static void gf2x_swap(const int length, DIGIT f[], DIGIT s[]) { * (Chapter 11 -- Algorithm 11.44 -- pag 223) * */ -int PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) { /* in^{-1} mod x^P-1 */ +int PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) { /* in^{-1} mod x^P-1 */ int i; int delta = 0; @@ -299,8 +299,8 @@ int PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) { delta += 1; } else { if ( (s[0] & mask) != 0) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_add(s, s, f, NUM_DIGITS_GF2X_MODULUS); - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_add(v, v, u); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_add(s, s, f, NUM_DIGITS_GF2X_MODULUS); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_add(v, v, u); } left_bit_shift(NUM_DIGITS_GF2X_MODULUS, s); if ( delta == 0 ) { @@ -322,7 +322,7 @@ int PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) { return (delta == 0); } -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const DIGIT B[]) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const DIGIT B[]) { DIGIT aux[2 * NUM_DIGITS_GF2X_ELEMENT]; GF2X_MUL(2 * NUM_DIGITS_GF2X_ELEMENT, aux, @@ -334,7 +334,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const /*PRE: the representation of the sparse coefficients is sorted in increasing order of the coefficients themselves */ -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_dense_to_sparse( +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_mul_dense_to_sparse( DIGIT Res[], const DIGIT dense[], POSITION_T sparse[], unsigned int nPos) { @@ -352,7 +352,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_dense_to_sparse( for (unsigned int i = 1; i < nPos; i++) { if (sparse[i] != INVALID_POS_VALUE) { left_bit_shift_wide_n(2 * NUM_DIGITS_GF2X_ELEMENT, aux, (sparse[i] - sparse[i - 1]) ); - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_add(resDouble, aux, resDouble, 2 * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_add(resDouble, aux, resDouble, 2 * NUM_DIGITS_GF2X_ELEMENT); } } } @@ -361,7 +361,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_dense_to_sparse( } -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_transpose_in_place_sparse(int sizeA, POSITION_T A[]) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_transpose_in_place_sparse(int sizeA, POSITION_T A[]) { POSITION_T t; int i = 0, j; @@ -383,7 +383,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_transpose_in_place_sparse(int sizeA, POSITIO } -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[], +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[], size_t sizeA, const POSITION_T A[], size_t sizeB, const POSITION_T B[]) { @@ -406,7 +406,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[ Res[lastFilledPos] = INVALID_POS_VALUE; lastFilledPos++; } - PQCLEAN_LEDAKEMLT32_CLEAN_quicksort_sparse(Res); + PQCLEAN_LEDAKEMLT32_LEAKTIME_quicksort_sparse(Res); /* eliminate duplicates */ POSITION_T lastReadPos = Res[0]; int duplicateCount; @@ -433,7 +433,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[ /* the implementation is safe even in case A or B alias with the result */ /* PRE: A and B should be sorted and have INVALID_POS_VALUE at the end */ -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_add_sparse( +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_add_sparse( int sizeR, POSITION_T Res[], int sizeA, const POSITION_T A[], int sizeB, const POSITION_T B[]) { @@ -492,7 +492,7 @@ static uint32_t rand_range(const unsigned int n, const int logn, AES_XOF_struct uint32_t mask = ( (uint32_t)1 << logn) - 1; do { - PQCLEAN_LEDAKEMLT32_CLEAN_seedexpander(seed_expander_ctx, rnd_char_buffer, required_rnd_bytes); + PQCLEAN_LEDAKEMLT32_LEAKTIME_seedexpander(seed_expander_ctx, rnd_char_buffer, required_rnd_bytes); /* obtain an endianness independent representation of the generated random bytes into an unsigned integer */ rnd_value = ((uint32_t)rnd_char_buffer[3] << 24) + @@ -507,7 +507,7 @@ static uint32_t rand_range(const unsigned int n, const int logn, AES_XOF_struct /* Obtains fresh randomness and seed-expands it until all the required positions * for the '1's in the circulant block are obtained */ -void PQCLEAN_LEDAKEMLT32_CLEAN_rand_circulant_sparse_block(POSITION_T *pos_ones, +void PQCLEAN_LEDAKEMLT32_LEAKTIME_rand_circulant_sparse_block(POSITION_T *pos_ones, int countOnes, AES_XOF_struct *seed_expander_ctx) { @@ -532,7 +532,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_rand_circulant_sparse_block(POSITION_T *pos_ones, } /* Returns random weight-t circulant block */ -void PQCLEAN_LEDAKEMLT32_CLEAN_rand_circulant_blocks_sequence( +void PQCLEAN_LEDAKEMLT32_LEAKTIME_rand_circulant_blocks_sequence( DIGIT sequence[N0 * NUM_DIGITS_GF2X_ELEMENT], AES_XOF_struct *seed_expander_ctx) { @@ -558,13 +558,13 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_rand_circulant_blocks_sequence( for (int j = 0; j < counter; j++) { polyIndex = rndPos[j] / P; exponent = rndPos[j] % P; - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_set_coeff( sequence + NUM_DIGITS_GF2X_ELEMENT * polyIndex, exponent, + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_set_coeff( sequence + NUM_DIGITS_GF2X_ELEMENT * polyIndex, exponent, ( (DIGIT) 1)); } } -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly) { size_t i, j; for (i = 0; i < NUM_DIGITS_GF2X_ELEMENT; i++) { for (j = 0; j < DIGIT_SIZE_B; j++) { @@ -573,7 +573,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly) { } } -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_frombytes(DIGIT *poly, const uint8_t *poly_bytes) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_frombytes(DIGIT *poly, const uint8_t *poly_bytes) { size_t i, j; for (i = 0; i < NUM_DIGITS_GF2X_ELEMENT; i++) { poly[i] = (DIGIT) 0; diff --git a/crypto_kem/ledakemlt32/leaktime/gf2x_arith_mod_xPplusOne.h b/crypto_kem/ledakemlt32/leaktime/gf2x_arith_mod_xPplusOne.h new file mode 100644 index 00000000..a43f1225 --- /dev/null +++ b/crypto_kem/ledakemlt32/leaktime/gf2x_arith_mod_xPplusOne.h @@ -0,0 +1,38 @@ +#ifndef GF2X_ARITH_MOD_XPLUSONE_H +#define GF2X_ARITH_MOD_XPLUSONE_H + +#include "qc_ldpc_parameters.h" + +#include "gf2x_arith.h" +#include "rng.h" + +#define NUM_BITS_GF2X_ELEMENT (P) // 96221 +#define NUM_DIGITS_GF2X_ELEMENT ((P+DIGIT_SIZE_b-1)/DIGIT_SIZE_b) +#define MSb_POSITION_IN_MSB_DIGIT_OF_ELEMENT ((P % DIGIT_SIZE_b) ? (P % DIGIT_SIZE_b)-1 : DIGIT_SIZE_b-1) +#define NUM_BITS_GF2X_MODULUS (P+1) +#define NUM_DIGITS_GF2X_MODULUS ((P+1+DIGIT_SIZE_b-1)/DIGIT_SIZE_b) +#define MSb_POSITION_IN_MSB_DIGIT_OF_MODULUS (P-DIGIT_SIZE_b*(NUM_DIGITS_GF2X_MODULUS-1)) +#define INVALID_POS_VALUE (P) +#define P_BITS (17) // log_2(p) = 16.55406417 + +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_copy(DIGIT dest[], const DIGIT in[]); +DIGIT PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_get_coeff(const DIGIT poly[], unsigned int exponent); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_set_coeff(DIGIT poly[], unsigned int exponent, DIGIT value); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_toggle_coeff(DIGIT poly[], unsigned int exponent); +int PQCLEAN_LEDAKEMLT32_LEAKTIME_population_count(DIGIT *poly); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_add(DIGIT Res[], const DIGIT A[], const DIGIT B[]); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_quicksort_sparse(POSITION_T Res[]); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const DIGIT B[]); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_transpose_in_place(DIGIT A[]); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_rand_circulant_sparse_block(POSITION_T *pos_ones, int countOnes, AES_XOF_struct *seed_expander_ctx); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_rand_circulant_blocks_sequence(DIGIT *sequence, AES_XOF_struct *seed_expander_ctx); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_add_sparse(int sizeR, POSITION_T Res[], int sizeA, const POSITION_T A[], int sizeB, const POSITION_T B[]); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_transpose_in_place_sparse(int sizeA, POSITION_T A[]); +int PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[], size_t sizeA, const POSITION_T A[], size_t sizeB, const POSITION_T B[]); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_mul_dense_to_sparse(DIGIT Res[], const DIGIT dense[], POSITION_T sparse[], unsigned int nPos); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_frombytes(DIGIT *poly, const uint8_t *poly_bytes); + + +#endif diff --git a/crypto_kem/ledakemlt52/clean/kem.c b/crypto_kem/ledakemlt32/leaktime/kem.c similarity index 58% rename from crypto_kem/ledakemlt52/clean/kem.c rename to crypto_kem/ledakemlt32/leaktime/kem.c index d571c73e..d7e09732 100644 --- a/crypto_kem/ledakemlt52/clean/kem.c +++ b/crypto_kem/ledakemlt32/leaktime/kem.c @@ -8,43 +8,43 @@ static void pack_pk(uint8_t *pk_bytes, publicKeyNiederreiter_t *pk) { size_t i; for (i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_tobytes(pk_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B, - pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_tobytes(pk_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B, + pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT); } } static void unpack_pk(publicKeyNiederreiter_t *pk, const uint8_t *pk_bytes) { size_t i; for (i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_frombytes(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_frombytes(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, pk_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); } } static void pack_ct(uint8_t *sk_bytes, DIGIT *ct) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_tobytes(sk_bytes, ct); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_tobytes(sk_bytes, ct); } static void unpack_ct(DIGIT *ct, const uint8_t *ct_bytes) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_frombytes(ct, ct_bytes); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_frombytes(ct, ct_bytes); } static void pack_error(uint8_t *error_bytes, DIGIT *error_digits) { size_t i; for (i = 0; i < N0; i++) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_tobytes(error_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B, - error_digits + i * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_tobytes(error_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B, + error_digits + i * NUM_DIGITS_GF2X_ELEMENT); } } /* Generates a keypair - pk is the public key and sk is the secret key. */ -int PQCLEAN_LEDAKEMLT52_CLEAN_crypto_kem_keypair(unsigned char *pk, unsigned char *sk) { +int PQCLEAN_LEDAKEMLT32_LEAKTIME_crypto_kem_keypair(unsigned char *pk, unsigned char *sk) { AES_XOF_struct niederreiter_keys_expander; publicKeyNiederreiter_t pk_nie; randombytes(((privateKeyNiederreiter_t *)sk)->prng_seed, TRNG_BYTE_LENGTH); - PQCLEAN_LEDAKEMLT52_CLEAN_seedexpander_from_trng(&niederreiter_keys_expander, ((privateKeyNiederreiter_t *)sk)->prng_seed); - PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_keygen(&pk_nie, (privateKeyNiederreiter_t *) sk, &niederreiter_keys_expander); + PQCLEAN_LEDAKEMLT32_LEAKTIME_seedexpander_from_trng(&niederreiter_keys_expander, ((privateKeyNiederreiter_t *)sk)->prng_seed); + PQCLEAN_LEDAKEMLT32_LEAKTIME_niederreiter_keygen(&pk_nie, (privateKeyNiederreiter_t *) sk, &niederreiter_keys_expander); pack_pk(pk, &pk_nie); @@ -53,7 +53,7 @@ int PQCLEAN_LEDAKEMLT52_CLEAN_crypto_kem_keypair(unsigned char *pk, unsigned cha /* Encrypt - pk is the public key, ct is a key encapsulation message (ciphertext), ss is the shared secret.*/ -int PQCLEAN_LEDAKEMLT52_CLEAN_crypto_kem_enc(unsigned char *ct, unsigned char *ss, const unsigned char *pk) { +int PQCLEAN_LEDAKEMLT32_LEAKTIME_crypto_kem_enc(unsigned char *ct, unsigned char *ss, const unsigned char *pk) { AES_XOF_struct niederreiter_encap_key_expander; unsigned char encapsulated_key_seed[TRNG_BYTE_LENGTH]; DIGIT error_vector[N0 * NUM_DIGITS_GF2X_ELEMENT]; @@ -64,11 +64,11 @@ int PQCLEAN_LEDAKEMLT52_CLEAN_crypto_kem_enc(unsigned char *ct, unsigned char *s randombytes(encapsulated_key_seed, TRNG_BYTE_LENGTH); unpack_pk(&pk_nie, pk); - PQCLEAN_LEDAKEMLT52_CLEAN_seedexpander_from_trng(&niederreiter_encap_key_expander, encapsulated_key_seed); - PQCLEAN_LEDAKEMLT52_CLEAN_rand_circulant_blocks_sequence(error_vector, &niederreiter_encap_key_expander); + PQCLEAN_LEDAKEMLT32_LEAKTIME_seedexpander_from_trng(&niederreiter_encap_key_expander, encapsulated_key_seed); + PQCLEAN_LEDAKEMLT32_LEAKTIME_rand_circulant_blocks_sequence(error_vector, &niederreiter_encap_key_expander); pack_error(error_bytes, error_vector); HASH_FUNCTION(ss, error_bytes, (N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B)); - PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_encrypt(syndrome, &pk_nie, error_vector); + PQCLEAN_LEDAKEMLT32_LEAKTIME_niederreiter_encrypt(syndrome, &pk_nie, error_vector); pack_ct(ct, syndrome); @@ -78,13 +78,13 @@ int PQCLEAN_LEDAKEMLT52_CLEAN_crypto_kem_enc(unsigned char *ct, unsigned char *s /* Decrypt - ct is a key encapsulation message (ciphertext), sk is the private key, ss is the shared secret */ -int PQCLEAN_LEDAKEMLT52_CLEAN_crypto_kem_dec(unsigned char *ss, const unsigned char *ct, const unsigned char *sk) { +int PQCLEAN_LEDAKEMLT32_LEAKTIME_crypto_kem_dec(unsigned char *ss, const unsigned char *ct, const unsigned char *sk) { DIGIT decoded_error_vector[N0 * NUM_DIGITS_GF2X_ELEMENT]; uint8_t decoded_error_bytes[N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B]; DIGIT syndrome[NUM_DIGITS_GF2X_ELEMENT]; unpack_ct(syndrome, ct); - PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_decrypt(decoded_error_vector, (privateKeyNiederreiter_t *)sk, syndrome); + PQCLEAN_LEDAKEMLT32_LEAKTIME_niederreiter_decrypt(decoded_error_vector, (privateKeyNiederreiter_t *)sk, syndrome); pack_error(decoded_error_bytes, decoded_error_vector); HASH_FUNCTION(ss, decoded_error_bytes, (N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B)); diff --git a/crypto_kem/ledakemlt12/clean/niederreiter.c b/crypto_kem/ledakemlt32/leaktime/niederreiter.c similarity index 65% rename from crypto_kem/ledakemlt12/clean/niederreiter.c rename to crypto_kem/ledakemlt32/leaktime/niederreiter.c index 419a00c5..66bc3f80 100644 --- a/crypto_kem/ledakemlt12/clean/niederreiter.c +++ b/crypto_kem/ledakemlt32/leaktime/niederreiter.c @@ -8,7 +8,7 @@ #include -void PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, privateKeyNiederreiter_t *sk, AES_XOF_struct *keys_expander) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_niederreiter_keygen(publicKeyNiederreiter_t *pk, privateKeyNiederreiter_t *sk, AES_XOF_struct *keys_expander) { POSITION_T HPosOnes[N0][DV]; // sequence of N0 circ block matrices (p x p): Hi POSITION_T HtrPosOnes[N0][DV]; // Sparse tranposed circulant H @@ -23,8 +23,8 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, sk->rejections = (int8_t) 0; do { - PQCLEAN_LEDAKEMLT12_CLEAN_generateHPosOnes_HtrPosOnes(HPosOnes, HtrPosOnes, keys_expander); - PQCLEAN_LEDAKEMLT12_CLEAN_generateQsparse(QPosOnes, keys_expander); + PQCLEAN_LEDAKEMLT32_LEAKTIME_generateHPosOnes_HtrPosOnes(HPosOnes, HtrPosOnes, keys_expander); + PQCLEAN_LEDAKEMLT32_LEAKTIME_generateQsparse(QPosOnes, keys_expander); for (int i = 0; i < N0; i++) { for (int j = 0; j < DV * M; j++) { LPosOnes[i][j] = INVALID_POS_VALUE; @@ -34,10 +34,10 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, memset(processedQOnes, 0x00, sizeof(processedQOnes)); for (int colQ = 0; colQ < N0; colQ++) { for (int i = 0; i < N0; i++) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_sparse(DV * M, auxPosOnes, + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_mul_sparse(DV * M, auxPosOnes, DV, HPosOnes[i], qBlockWeights[i][colQ], QPosOnes[i] + processedQOnes[i]); - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_add_sparse(DV * M, LPosOnes[colQ], + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_add_sparse(DV * M, LPosOnes[colQ], DV * M, LPosOnes[colQ], DV * M, auxPosOnes); processedQOnes[i] += qBlockWeights[i][colQ]; @@ -49,7 +49,7 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, } sk->rejections = sk->rejections + 1; if (is_L_full) { - threshold = PQCLEAN_LEDAKEMLT12_CLEAN_DFR_test(LPosOnes); + threshold = PQCLEAN_LEDAKEMLT32_LEAKTIME_DFR_test(LPosOnes); } } while (!is_L_full || threshold == DFR_TEST_FAIL); sk->rejections = sk->rejections - 1; @@ -58,41 +58,41 @@ void PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, memset(Ln0dense, 0x00, sizeof(Ln0dense)); for (int j = 0; j < DV * M; j++) { if (LPosOnes[N0 - 1][j] != INVALID_POS_VALUE) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_set_coeff(Ln0dense, LPosOnes[N0 - 1][j], 1); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_set_coeff(Ln0dense, LPosOnes[N0 - 1][j], 1); } } memset(Ln0Inv, 0x00, sizeof(Ln0Inv)); - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_inverse(Ln0Inv, Ln0dense); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_inverse(Ln0Inv, Ln0dense); for (int i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_dense_to_sparse(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_mul_dense_to_sparse(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, Ln0Inv, LPosOnes[i], DV * M); } for (int i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_transpose_in_place(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_transpose_in_place(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT); } } -void PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_encrypt(DIGIT *syndrome, const publicKeyNiederreiter_t *pk, const DIGIT *err) { +void PQCLEAN_LEDAKEMLT32_LEAKTIME_niederreiter_encrypt(DIGIT *syndrome, const publicKeyNiederreiter_t *pk, const DIGIT *err) { int i; DIGIT saux[NUM_DIGITS_GF2X_ELEMENT]; memset(syndrome, 0x00, NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); for (i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul(saux, - pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, - err + i * NUM_DIGITS_GF2X_ELEMENT); - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_add(syndrome, syndrome, saux); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_mul(saux, + pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, + err + i * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_add(syndrome, syndrome, saux); } - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_add(syndrome, syndrome, err + (N0 - 1)*NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_add(syndrome, syndrome, err + (N0 - 1)*NUM_DIGITS_GF2X_ELEMENT); } -int PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyNiederreiter_t *sk, const DIGIT *syndrome) { +int PQCLEAN_LEDAKEMLT32_LEAKTIME_niederreiter_decrypt(DIGIT *err, const privateKeyNiederreiter_t *sk, const DIGIT *syndrome) { AES_XOF_struct niederreiter_decrypt_expander; POSITION_T HPosOnes[N0][DV]; POSITION_T HtrPosOnes[N0][DV]; @@ -110,11 +110,11 @@ int PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyN int currQoneIdx, endQblockIdx; int decryptOk, err_weight; - PQCLEAN_LEDAKEMLT12_CLEAN_seedexpander_from_trng(&niederreiter_decrypt_expander, sk->prng_seed); + PQCLEAN_LEDAKEMLT32_LEAKTIME_seedexpander_from_trng(&niederreiter_decrypt_expander, sk->prng_seed); do { - PQCLEAN_LEDAKEMLT12_CLEAN_generateHPosOnes_HtrPosOnes(HPosOnes, HtrPosOnes, &niederreiter_decrypt_expander); - PQCLEAN_LEDAKEMLT12_CLEAN_generateQsparse(QPosOnes, &niederreiter_decrypt_expander); + PQCLEAN_LEDAKEMLT32_LEAKTIME_generateHPosOnes_HtrPosOnes(HPosOnes, HtrPosOnes, &niederreiter_decrypt_expander); + PQCLEAN_LEDAKEMLT32_LEAKTIME_generateQsparse(QPosOnes, &niederreiter_decrypt_expander); for (int i = 0; i < N0; i++) { for (int j = 0; j < DV * M; j++) { LPosOnes[i][j] = INVALID_POS_VALUE; @@ -124,10 +124,10 @@ int PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyN memset(processedQOnes, 0x00, sizeof(processedQOnes)); for (int colQ = 0; colQ < N0; colQ++) { for (int i = 0; i < N0; i++) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_sparse(DV * M, auxPosOnes, + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_mul_sparse(DV * M, auxPosOnes, DV, HPosOnes[i], qBlockWeights[i][colQ], QPosOnes[i] + processedQOnes[i]); - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_add_sparse(DV * M, LPosOnes[colQ], + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_add_sparse(DV * M, LPosOnes[colQ], DV * M, LPosOnes[colQ], DV * M, auxPosOnes); processedQOnes[i] += qBlockWeights[i][colQ]; @@ -156,31 +156,31 @@ int PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyN } for (int i = 0; i < N0; i++) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_sparse(DV * M, auxSparse, + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_mul_sparse(DV * M, auxSparse, DV, HPosOnes[i], qBlockWeights[i][N0 - 1], &QPosOnes[i][ M - qBlockWeights[i][N0 - 1]]); - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_add_sparse(DV * M, Ln0trSparse, + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_add_sparse(DV * M, Ln0trSparse, DV * M, Ln0trSparse, DV * M, auxSparse); } - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_transpose_in_place_sparse(DV * M, Ln0trSparse); - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mod_mul_dense_to_sparse(privateSyndrome, syndrome, Ln0trSparse, DV * M); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_transpose_in_place_sparse(DV * M, Ln0trSparse); + PQCLEAN_LEDAKEMLT32_LEAKTIME_gf2x_mod_mul_dense_to_sparse(privateSyndrome, syndrome, Ln0trSparse, DV * M); /* prepare mockup error vector in case a decoding failure occurs */ memset(mockup_error_vector, 0x00, N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); memcpy(mockup_error_vector, syndrome, NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); - PQCLEAN_LEDAKEMLT12_CLEAN_seedexpander(&niederreiter_decrypt_expander, - ((unsigned char *) mockup_error_vector) + (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B), - TRNG_BYTE_LENGTH); + PQCLEAN_LEDAKEMLT32_LEAKTIME_seedexpander(&niederreiter_decrypt_expander, + ((unsigned char *) mockup_error_vector) + (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B), + TRNG_BYTE_LENGTH); memset(err, 0x00, N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); - decryptOk = PQCLEAN_LEDAKEMLT12_CLEAN_bf_decoding(err, (const POSITION_T (*)[DV]) HtrPosOnes, + decryptOk = PQCLEAN_LEDAKEMLT32_LEAKTIME_bf_decoding(err, (const POSITION_T (*)[DV]) HtrPosOnes, (const POSITION_T (*)[M]) QtrPosOnes, privateSyndrome, sk->threshold); err_weight = 0; for (int i = 0 ; i < N0; i++) { - err_weight += PQCLEAN_LEDAKEMLT12_CLEAN_population_count(err + (NUM_DIGITS_GF2X_ELEMENT * i)); + err_weight += PQCLEAN_LEDAKEMLT32_LEAKTIME_population_count(err + (NUM_DIGITS_GF2X_ELEMENT * i)); } decryptOk = decryptOk && (err_weight == NUM_ERRORS_T); diff --git a/crypto_kem/ledakemlt52/clean/niederreiter.h b/crypto_kem/ledakemlt32/leaktime/niederreiter.h similarity index 63% rename from crypto_kem/ledakemlt52/clean/niederreiter.h rename to crypto_kem/ledakemlt32/leaktime/niederreiter.h index e6c33ecd..41048034 100644 --- a/crypto_kem/ledakemlt52/clean/niederreiter.h +++ b/crypto_kem/ledakemlt32/leaktime/niederreiter.h @@ -21,9 +21,9 @@ typedef struct { // with P coefficients. } publicKeyNiederreiter_t; -void PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, privateKeyNiederreiter_t *sk, AES_XOF_struct *keys_expander); -void PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_encrypt(DIGIT syndrome[], const publicKeyNiederreiter_t *pk, const DIGIT *err); -int PQCLEAN_LEDAKEMLT52_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyNiederreiter_t *sk, const DIGIT *syndrome); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_niederreiter_keygen(publicKeyNiederreiter_t *pk, privateKeyNiederreiter_t *sk, AES_XOF_struct *keys_expander); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_niederreiter_encrypt(DIGIT syndrome[], const publicKeyNiederreiter_t *pk, const DIGIT *err); +int PQCLEAN_LEDAKEMLT32_LEAKTIME_niederreiter_decrypt(DIGIT *err, const privateKeyNiederreiter_t *sk, const DIGIT *syndrome); #endif diff --git a/crypto_kem/ledakemlt32/clean/qc_ldpc_parameters.h b/crypto_kem/ledakemlt32/leaktime/qc_ldpc_parameters.h similarity index 100% rename from crypto_kem/ledakemlt32/clean/qc_ldpc_parameters.h rename to crypto_kem/ledakemlt32/leaktime/qc_ldpc_parameters.h diff --git a/crypto_kem/ledakemlt32/clean/rng.c b/crypto_kem/ledakemlt32/leaktime/rng.c similarity index 94% rename from crypto_kem/ledakemlt32/clean/rng.c rename to crypto_kem/ledakemlt32/leaktime/rng.c index b0757cee..4e18fa57 100644 --- a/crypto_kem/ledakemlt32/clean/rng.c +++ b/crypto_kem/ledakemlt32/leaktime/rng.c @@ -37,7 +37,7 @@ static void seedexpander_init(AES_XOF_struct *ctx, memset(ctx->buffer, 0x00, 16); } -void PQCLEAN_LEDAKEMLT32_CLEAN_seedexpander_from_trng(AES_XOF_struct *ctx, +void PQCLEAN_LEDAKEMLT32_LEAKTIME_seedexpander_from_trng(AES_XOF_struct *ctx, const unsigned char *trng_entropy /* TRNG_BYTE_LENGTH wide buffer */) { @@ -61,7 +61,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_seedexpander_from_trng(AES_XOF_struct *ctx, x - returns the XOF data xlen - number of bytes to return */ -int PQCLEAN_LEDAKEMLT32_CLEAN_seedexpander(AES_XOF_struct *ctx, unsigned char *x, size_t xlen) { +int PQCLEAN_LEDAKEMLT32_LEAKTIME_seedexpander(AES_XOF_struct *ctx, unsigned char *x, size_t xlen) { size_t offset; aes256ctx ctx256; diff --git a/crypto_kem/ledakemlt52/clean/rng.h b/crypto_kem/ledakemlt32/leaktime/rng.h similarity index 67% rename from crypto_kem/ledakemlt52/clean/rng.h rename to crypto_kem/ledakemlt32/leaktime/rng.h index 5bfc8703..dbff0366 100644 --- a/crypto_kem/ledakemlt52/clean/rng.h +++ b/crypto_kem/ledakemlt32/leaktime/rng.h @@ -18,7 +18,7 @@ typedef struct { unsigned char ctr[16]; } AES_XOF_struct; -int PQCLEAN_LEDAKEMLT52_CLEAN_seedexpander(AES_XOF_struct *ctx, unsigned char *x, size_t xlen); -void PQCLEAN_LEDAKEMLT52_CLEAN_seedexpander_from_trng(AES_XOF_struct *ctx, const unsigned char *trng_entropy); +int PQCLEAN_LEDAKEMLT32_LEAKTIME_seedexpander(AES_XOF_struct *ctx, unsigned char *x, size_t xlen); +void PQCLEAN_LEDAKEMLT32_LEAKTIME_seedexpander_from_trng(AES_XOF_struct *ctx, const unsigned char *trng_entropy); #endif diff --git a/crypto_kem/ledakemlt52/META.yml b/crypto_kem/ledakemlt52/META.yml index 0dcac3f0..5aef2b59 100644 --- a/crypto_kem/ledakemlt52/META.yml +++ b/crypto_kem/ledakemlt52/META.yml @@ -14,5 +14,5 @@ auxiliary-submitters: - Gerardo Pelosi - Paolo Santini implementations: - - name: clean + - name: leaktime version: 2.? diff --git a/crypto_kem/ledakemlt52/clean/H_Q_matrices_generation.h b/crypto_kem/ledakemlt52/clean/H_Q_matrices_generation.h deleted file mode 100644 index 18a8cd5c..00000000 --- a/crypto_kem/ledakemlt52/clean/H_Q_matrices_generation.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef H_Q_MATRICES_GENERATION_H -#define H_Q_MATRICES_GENERATION_H - -#include "gf2x_arith.h" -#include "qc_ldpc_parameters.h" -#include "rng.h" - -void PQCLEAN_LEDAKEMLT52_CLEAN_generateHPosOnes_HtrPosOnes(POSITION_T HPosOnes[N0][DV], POSITION_T HtrPosOnes[N0][DV], AES_XOF_struct *niederreiter_keys_expander); -void PQCLEAN_LEDAKEMLT52_CLEAN_generateQsparse(POSITION_T pos_ones[N0][M], AES_XOF_struct *niederreiter_keys_expander); - -#endif diff --git a/crypto_kem/ledakemlt52/clean/api.h b/crypto_kem/ledakemlt52/clean/api.h deleted file mode 100644 index 2ac2f10c..00000000 --- a/crypto_kem/ledakemlt52/clean/api.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef PQCLEAN_LEDAKEMLT52_CLEAN_API_H -#define PQCLEAN_LEDAKEMLT52_CLEAN_API_H - -#include - -#define PQCLEAN_LEDAKEMLT52_CLEAN_CRYPTO_SECRETKEYBYTES 42 -#define PQCLEAN_LEDAKEMLT52_CLEAN_CRYPTO_PUBLICKEYBYTES 19040 -#define PQCLEAN_LEDAKEMLT52_CLEAN_CRYPTO_CIPHERTEXTBYTES 19040 -#define PQCLEAN_LEDAKEMLT52_CLEAN_CRYPTO_BYTES 64 - -#define PQCLEAN_LEDAKEMLT52_CLEAN_CRYPTO_ALGNAME "LEDAKEMLT52" - -int PQCLEAN_LEDAKEMLT52_CLEAN_crypto_kem_keypair(uint8_t *pk, uint8_t *sk); -int PQCLEAN_LEDAKEMLT52_CLEAN_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk); -int PQCLEAN_LEDAKEMLT52_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk); - - -#endif diff --git a/crypto_kem/ledakemlt52/clean/dfr_test.h b/crypto_kem/ledakemlt52/clean/dfr_test.h deleted file mode 100644 index 577dd3fa..00000000 --- a/crypto_kem/ledakemlt52/clean/dfr_test.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef DFR_TEST_H -#define DFR_TEST_H - -#define DFR_TEST_FAIL (255) - -uint8_t PQCLEAN_LEDAKEMLT52_CLEAN_DFR_test(POSITION_T LSparse[N0][DV * M]); - -#endif diff --git a/crypto_kem/ledakemlt52/clean/gf2x_arith_mod_xPplusOne.h b/crypto_kem/ledakemlt52/clean/gf2x_arith_mod_xPplusOne.h deleted file mode 100644 index 959c645a..00000000 --- a/crypto_kem/ledakemlt52/clean/gf2x_arith_mod_xPplusOne.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef GF2X_ARITH_MOD_XPLUSONE_H -#define GF2X_ARITH_MOD_XPLUSONE_H - -#include "qc_ldpc_parameters.h" - -#include "gf2x_arith.h" -#include "rng.h" - -#define NUM_BITS_GF2X_ELEMENT (P) // 152267 -#define NUM_DIGITS_GF2X_ELEMENT ((P+DIGIT_SIZE_b-1)/DIGIT_SIZE_b) // 2380 -#define MSb_POSITION_IN_MSB_DIGIT_OF_ELEMENT ((P % DIGIT_SIZE_b) ? (P % DIGIT_SIZE_b)-1 : DIGIT_SIZE_b-1) -#define NUM_BITS_GF2X_MODULUS (P+1) -#define NUM_DIGITS_GF2X_MODULUS ((P+1+DIGIT_SIZE_b-1)/DIGIT_SIZE_b) // 2380 -#define MSb_POSITION_IN_MSB_DIGIT_OF_MODULUS (P-DIGIT_SIZE_b*(NUM_DIGITS_GF2X_MODULUS-1)) -#define INVALID_POS_VALUE (P) -#define P_BITS (18) // log_2(p) = 17.216243783 - -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_copy(DIGIT dest[], const DIGIT in[]); -DIGIT PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_get_coeff(const DIGIT poly[], unsigned int exponent); -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_set_coeff(DIGIT poly[], unsigned int exponent, DIGIT value); -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_toggle_coeff(DIGIT poly[], unsigned int exponent); -int PQCLEAN_LEDAKEMLT52_CLEAN_population_count(DIGIT *poly); -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_add(DIGIT Res[], const DIGIT A[], const DIGIT B[]); -void PQCLEAN_LEDAKEMLT52_CLEAN_quicksort_sparse(POSITION_T Res[]); -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const DIGIT B[]); -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_transpose_in_place(DIGIT A[]); -void PQCLEAN_LEDAKEMLT52_CLEAN_rand_circulant_sparse_block(POSITION_T *pos_ones, int countOnes, AES_XOF_struct *seed_expander_ctx); -void PQCLEAN_LEDAKEMLT52_CLEAN_rand_circulant_blocks_sequence(DIGIT *sequence, AES_XOF_struct *seed_expander_ctx); -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_add_sparse(int sizeR, POSITION_T Res[], int sizeA, const POSITION_T A[], int sizeB, const POSITION_T B[]); -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_transpose_in_place_sparse(int sizeA, POSITION_T A[]); -int PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]); -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[], size_t sizeA, const POSITION_T A[], size_t sizeB, const POSITION_T B[]); -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_dense_to_sparse(DIGIT Res[], const DIGIT dense[], POSITION_T sparse[], unsigned int nPos); -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly); -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_frombytes(DIGIT *poly, const uint8_t *poly_bytes); - -#endif diff --git a/crypto_kem/ledakemlt32/clean/H_Q_matrices_generation.c b/crypto_kem/ledakemlt52/leaktime/H_Q_matrices_generation.c similarity index 72% rename from crypto_kem/ledakemlt32/clean/H_Q_matrices_generation.c rename to crypto_kem/ledakemlt52/leaktime/H_Q_matrices_generation.c index eca47755..8c1cdf0f 100644 --- a/crypto_kem/ledakemlt32/clean/H_Q_matrices_generation.c +++ b/crypto_kem/ledakemlt52/leaktime/H_Q_matrices_generation.c @@ -1,13 +1,13 @@ #include "H_Q_matrices_generation.h" #include "gf2x_arith_mod_xPplusOne.h" -void PQCLEAN_LEDAKEMLT32_CLEAN_generateHPosOnes_HtrPosOnes( +void PQCLEAN_LEDAKEMLT52_LEAKTIME_generateHPosOnes_HtrPosOnes( POSITION_T HPosOnes[N0][DV], POSITION_T HtrPosOnes[N0][DV], AES_XOF_struct *keys_expander) { for (int i = 0; i < N0; i++) { /* Generate a random block of Htr */ - PQCLEAN_LEDAKEMLT32_CLEAN_rand_circulant_sparse_block(&HtrPosOnes[i][0], DV, keys_expander); + PQCLEAN_LEDAKEMLT52_LEAKTIME_rand_circulant_sparse_block(&HtrPosOnes[i][0], DV, keys_expander); } for (int i = 0; i < N0; i++) { /* Obtain directly the sparse representation of the block of H */ @@ -17,13 +17,13 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_generateHPosOnes_HtrPosOnes( } } -void PQCLEAN_LEDAKEMLT32_CLEAN_generateQsparse( +void PQCLEAN_LEDAKEMLT52_LEAKTIME_generateQsparse( POSITION_T pos_ones[N0][M], AES_XOF_struct *keys_expander) { for (int i = 0; i < N0; i++) { int placed_ones = 0; for (int j = 0; j < N0; j++) { - PQCLEAN_LEDAKEMLT32_CLEAN_rand_circulant_sparse_block(&pos_ones[i][placed_ones], + PQCLEAN_LEDAKEMLT52_LEAKTIME_rand_circulant_sparse_block(&pos_ones[i][placed_ones], qBlockWeights[i][j], keys_expander); placed_ones += qBlockWeights[i][j]; diff --git a/crypto_kem/ledakemlt52/leaktime/H_Q_matrices_generation.h b/crypto_kem/ledakemlt52/leaktime/H_Q_matrices_generation.h new file mode 100644 index 00000000..168fa743 --- /dev/null +++ b/crypto_kem/ledakemlt52/leaktime/H_Q_matrices_generation.h @@ -0,0 +1,11 @@ +#ifndef H_Q_MATRICES_GENERATION_H +#define H_Q_MATRICES_GENERATION_H + +#include "gf2x_arith.h" +#include "qc_ldpc_parameters.h" +#include "rng.h" + +void PQCLEAN_LEDAKEMLT52_LEAKTIME_generateHPosOnes_HtrPosOnes(POSITION_T HPosOnes[N0][DV], POSITION_T HtrPosOnes[N0][DV], AES_XOF_struct *niederreiter_keys_expander); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_generateQsparse(POSITION_T pos_ones[N0][M], AES_XOF_struct *niederreiter_keys_expander); + +#endif diff --git a/crypto_kem/ledakemlt52/clean/LICENSE b/crypto_kem/ledakemlt52/leaktime/LICENSE similarity index 100% rename from crypto_kem/ledakemlt52/clean/LICENSE rename to crypto_kem/ledakemlt52/leaktime/LICENSE diff --git a/crypto_kem/ledakemlt12/clean/Makefile b/crypto_kem/ledakemlt52/leaktime/Makefile similarity index 95% rename from crypto_kem/ledakemlt12/clean/Makefile rename to crypto_kem/ledakemlt52/leaktime/Makefile index 6d6fa541..0c3b52fa 100644 --- a/crypto_kem/ledakemlt12/clean/Makefile +++ b/crypto_kem/ledakemlt52/leaktime/Makefile @@ -1,6 +1,6 @@ # This Makefile can be used with GNU Make or BSD Make -LIB=libledakemlt12_clean.a +LIB=libledakemlt52_leaktime.a HEADERS=api.h bf_decoding.h dfr_test.h gf2x_arith_mod_xPplusOne.h \ gf2x_arith.h H_Q_matrices_generation.h \ niederreiter.h qc_ldpc_parameters.h rng.h diff --git a/crypto_kem/ledakemlt12/clean/Makefile.Microsoft_nmake b/crypto_kem/ledakemlt52/leaktime/Makefile.Microsoft_nmake similarity index 93% rename from crypto_kem/ledakemlt12/clean/Makefile.Microsoft_nmake rename to crypto_kem/ledakemlt52/leaktime/Makefile.Microsoft_nmake index e4bfc760..0bb72b8b 100644 --- a/crypto_kem/ledakemlt12/clean/Makefile.Microsoft_nmake +++ b/crypto_kem/ledakemlt52/leaktime/Makefile.Microsoft_nmake @@ -1,7 +1,7 @@ # This Makefile can be used with Microsoft Visual Studio's nmake using the command: # nmake /f Makefile.Microsoft_nmake -LIBRARY=libledakemlt12_clean.lib +LIBRARY=libledakemlt52_leaktime.lib OBJECTS=bf_decoding.obj dfr_test.obj gf2x_arith_mod_xPplusOne.obj gf2x_arith.obj H_Q_matrices_generation.obj kem.obj niederreiter.obj rng.obj CFLAGS=/nologo /I ..\..\..\common /W4 /WX diff --git a/crypto_kem/ledakemlt52/leaktime/api.h b/crypto_kem/ledakemlt52/leaktime/api.h new file mode 100644 index 00000000..11c84a4d --- /dev/null +++ b/crypto_kem/ledakemlt52/leaktime/api.h @@ -0,0 +1,18 @@ +#ifndef PQCLEAN_LEDAKEMLT52_LEAKTIME_API_H +#define PQCLEAN_LEDAKEMLT52_LEAKTIME_API_H + +#include + +#define PQCLEAN_LEDAKEMLT52_LEAKTIME_CRYPTO_SECRETKEYBYTES 42 +#define PQCLEAN_LEDAKEMLT52_LEAKTIME_CRYPTO_PUBLICKEYBYTES 19040 +#define PQCLEAN_LEDAKEMLT52_LEAKTIME_CRYPTO_CIPHERTEXTBYTES 19040 +#define PQCLEAN_LEDAKEMLT52_LEAKTIME_CRYPTO_BYTES 64 + +#define PQCLEAN_LEDAKEMLT52_LEAKTIME_CRYPTO_ALGNAME "LEDAKEMLT52" + +int PQCLEAN_LEDAKEMLT52_LEAKTIME_crypto_kem_keypair(uint8_t *pk, uint8_t *sk); +int PQCLEAN_LEDAKEMLT52_LEAKTIME_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk); +int PQCLEAN_LEDAKEMLT52_LEAKTIME_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk); + + +#endif diff --git a/crypto_kem/ledakemlt32/clean/bf_decoding.c b/crypto_kem/ledakemlt52/leaktime/bf_decoding.c similarity index 87% rename from crypto_kem/ledakemlt32/clean/bf_decoding.c rename to crypto_kem/ledakemlt52/leaktime/bf_decoding.c index f740dbc2..476bf162 100644 --- a/crypto_kem/ledakemlt32/clean/bf_decoding.c +++ b/crypto_kem/ledakemlt52/leaktime/bf_decoding.c @@ -4,7 +4,7 @@ #include #include -int PQCLEAN_LEDAKEMLT32_CLEAN_bf_decoding(DIGIT err[], +int PQCLEAN_LEDAKEMLT52_LEAKTIME_bf_decoding(DIGIT err[], const POSITION_T HtrPosOnes[N0][DV], const POSITION_T QtrPosOnes[N0][M], DIGIT privateSyndrome[], @@ -18,13 +18,13 @@ int PQCLEAN_LEDAKEMLT32_CLEAN_bf_decoding(DIGIT err[], unsigned int corrt_syndrome_based; do { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_copy(currSyndrome, privateSyndrome); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_copy(currSyndrome, privateSyndrome); memset(unsatParityChecks, 0x00, N0 * P * sizeof(uint8_t)); for (int i = 0; i < N0; i++) { for (int valueIdx = 0; valueIdx < P; valueIdx++) { for (int HtrOneIdx = 0; HtrOneIdx < DV; HtrOneIdx++) { POSITION_T tmp = (HtrPosOnes[i][HtrOneIdx] + valueIdx) >= P ? (HtrPosOnes[i][HtrOneIdx] + valueIdx) - P : (HtrPosOnes[i][HtrOneIdx] + valueIdx); - if (PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_get_coeff(currSyndrome, tmp)) { + if (PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_get_coeff(currSyndrome, tmp)) { unsatParityChecks[i * P + valueIdx]++; } } @@ -54,13 +54,13 @@ int PQCLEAN_LEDAKEMLT32_CLEAN_bf_decoding(DIGIT err[], } /* Correlation based flipping */ if (correlation >= corrt_syndrome_based) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_toggle_coeff(err + NUM_DIGITS_GF2X_ELEMENT * i, j); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_toggle_coeff(err + NUM_DIGITS_GF2X_ELEMENT * i, j); for (int v = 0; v < M; v++) { POSITION_T syndromePosToFlip; for (int HtrOneIdx = 0; HtrOneIdx < DV; HtrOneIdx++) { syndromePosToFlip = (HtrPosOnes[currQBlkPos[v]][HtrOneIdx] + currQBitPos[v] ); syndromePosToFlip = syndromePosToFlip >= P ? syndromePosToFlip - P : syndromePosToFlip; - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_toggle_coeff(privateSyndrome, syndromePosToFlip); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_toggle_coeff(privateSyndrome, syndromePosToFlip); } } // end for v } // end if diff --git a/crypto_kem/ledakemlt52/clean/bf_decoding.h b/crypto_kem/ledakemlt52/leaktime/bf_decoding.h similarity index 87% rename from crypto_kem/ledakemlt52/clean/bf_decoding.h rename to crypto_kem/ledakemlt52/leaktime/bf_decoding.h index e3b8bb90..0b391c48 100644 --- a/crypto_kem/ledakemlt52/clean/bf_decoding.h +++ b/crypto_kem/ledakemlt52/leaktime/bf_decoding.h @@ -9,7 +9,7 @@ #define B0 (88) #define T_BAR (6) -int PQCLEAN_LEDAKEMLT52_CLEAN_bf_decoding(DIGIT err[], +int PQCLEAN_LEDAKEMLT52_LEAKTIME_bf_decoding(DIGIT err[], const POSITION_T HtrPosOnes[N0][DV], const POSITION_T QtrPosOnes[N0][M], DIGIT privateSyndrome[], diff --git a/crypto_kem/ledakemlt52/clean/dfr_test.c b/crypto_kem/ledakemlt52/leaktime/dfr_test.c similarity index 94% rename from crypto_kem/ledakemlt52/clean/dfr_test.c rename to crypto_kem/ledakemlt52/leaktime/dfr_test.c index 9e97cb17..b93f68aa 100644 --- a/crypto_kem/ledakemlt52/clean/dfr_test.c +++ b/crypto_kem/ledakemlt52/leaktime/dfr_test.c @@ -9,7 +9,7 @@ * computes the threshold for the second iteration of the decoder and returns this values * (max DV * M), on failure it returns 255 >> DV * M */ -uint8_t PQCLEAN_LEDAKEMLT52_CLEAN_DFR_test(POSITION_T LSparse[N0][DV * M]) { +uint8_t PQCLEAN_LEDAKEMLT52_LEAKTIME_DFR_test(POSITION_T LSparse[N0][DV * M]) { POSITION_T LSparse_loc[N0][DV * M]; POSITION_T rotated_column[DV * M]; @@ -31,7 +31,7 @@ uint8_t PQCLEAN_LEDAKEMLT52_CLEAN_DFR_test(POSITION_T LSparse[N0][DV * M]) { LSparse_loc[i][j] = (P - LSparse[i][j]); } } - PQCLEAN_LEDAKEMLT52_CLEAN_quicksort_sparse(LSparse_loc[i]); + PQCLEAN_LEDAKEMLT52_LEAKTIME_quicksort_sparse(LSparse_loc[i]); } for (int i = 0; i < N0; i++ ) { @@ -41,7 +41,7 @@ uint8_t PQCLEAN_LEDAKEMLT52_CLEAN_DFR_test(POSITION_T LSparse[N0][DV * M]) { for (int idxToRotate = 0; idxToRotate < (DV * M); idxToRotate++) { rotated_column[idxToRotate] = (LSparse_loc[j][idxToRotate] + k) % P; } - PQCLEAN_LEDAKEMLT52_CLEAN_quicksort_sparse(rotated_column); + PQCLEAN_LEDAKEMLT52_LEAKTIME_quicksort_sparse(rotated_column); /* compute the intersection amount */ firstidx = 0, secondidx = 0; intersectionval = 0; diff --git a/crypto_kem/ledakemlt52/leaktime/dfr_test.h b/crypto_kem/ledakemlt52/leaktime/dfr_test.h new file mode 100644 index 00000000..92c49c75 --- /dev/null +++ b/crypto_kem/ledakemlt52/leaktime/dfr_test.h @@ -0,0 +1,8 @@ +#ifndef DFR_TEST_H +#define DFR_TEST_H + +#define DFR_TEST_FAIL (255) + +uint8_t PQCLEAN_LEDAKEMLT52_LEAKTIME_DFR_test(POSITION_T LSparse[N0][DV * M]); + +#endif diff --git a/crypto_kem/ledakemlt32/clean/gf2x_arith.c b/crypto_kem/ledakemlt52/leaktime/gf2x_arith.c similarity index 82% rename from crypto_kem/ledakemlt32/clean/gf2x_arith.c rename to crypto_kem/ledakemlt52/leaktime/gf2x_arith.c index 713e9cc5..b1b9df44 100644 --- a/crypto_kem/ledakemlt32/clean/gf2x_arith.c +++ b/crypto_kem/ledakemlt52/leaktime/gf2x_arith.c @@ -3,14 +3,14 @@ #include #include // memset(...) -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr) { for (int i = 0; i < nr; i++) { Res[i] = A[i] ^ B[i]; } } /* PRE: MAX ALLOWED ROTATION AMOUNT : DIGIT_SIZE_b */ -void PQCLEAN_LEDAKEMLT32_CLEAN_right_bit_shift_n(int length, DIGIT in[], unsigned int amount) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_right_bit_shift_n(int length, DIGIT in[], unsigned int amount) { assert(amount < DIGIT_SIZE_b); if ( amount == 0 ) { return; @@ -26,7 +26,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_right_bit_shift_n(int length, DIGIT in[], unsigne } /* PRE: MAX ALLOWED ROTATION AMOUNT : DIGIT_SIZE_b */ -void PQCLEAN_LEDAKEMLT32_CLEAN_left_bit_shift_n(int length, DIGIT in[], unsigned int amount) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_left_bit_shift_n(int length, DIGIT in[], unsigned int amount) { assert(amount < DIGIT_SIZE_b); if ( amount == 0 ) { return; @@ -41,7 +41,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_left_bit_shift_n(int length, DIGIT in[], unsigned in[j] <<= amount; } -void PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mul_comb(int nr, DIGIT Res[], +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mul_comb(int nr, DIGIT Res[], int na, const DIGIT A[], int nb, const DIGIT B[]) { int i, j, k; diff --git a/crypto_kem/ledakemlt12/clean/gf2x_arith.h b/crypto_kem/ledakemlt52/leaktime/gf2x_arith.h similarity index 82% rename from crypto_kem/ledakemlt12/clean/gf2x_arith.h rename to crypto_kem/ledakemlt52/leaktime/gf2x_arith.h index 8f890ab1..c4635592 100644 --- a/crypto_kem/ledakemlt12/clean/gf2x_arith.h +++ b/crypto_kem/ledakemlt52/leaktime/gf2x_arith.h @@ -48,11 +48,11 @@ typedef uint64_t DIGIT; #define DIGIT_SIZE_b (DIGIT_SIZE_B << 3) #define POSITION_T uint32_t -#define GF2X_MUL PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_mul_comb +#define GF2X_MUL PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mul_comb -void PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr); -void PQCLEAN_LEDAKEMLT12_CLEAN_right_bit_shift_n(int length, DIGIT in[], unsigned int amount); -void PQCLEAN_LEDAKEMLT12_CLEAN_left_bit_shift_n(int length, DIGIT in[], unsigned int amount); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_right_bit_shift_n(int length, DIGIT in[], unsigned int amount); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_left_bit_shift_n(int length, DIGIT in[], unsigned int amount); void GF2X_MUL(int nr, DIGIT Res[], int na, const DIGIT A[], int nb, const DIGIT B[]); #endif diff --git a/crypto_kem/ledakemlt52/clean/gf2x_arith_mod_xPplusOne.c b/crypto_kem/ledakemlt52/leaktime/gf2x_arith_mod_xPplusOne.c similarity index 87% rename from crypto_kem/ledakemlt52/clean/gf2x_arith_mod_xPplusOne.c rename to crypto_kem/ledakemlt52/leaktime/gf2x_arith_mod_xPplusOne.c index 7aac95c7..ef7d0e57 100644 --- a/crypto_kem/ledakemlt52/clean/gf2x_arith_mod_xPplusOne.c +++ b/crypto_kem/ledakemlt52/leaktime/gf2x_arith_mod_xPplusOne.c @@ -5,14 +5,14 @@ #include // memcpy(...), memset(...) -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_copy(DIGIT dest[], const DIGIT in[]) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_copy(DIGIT dest[], const DIGIT in[]) { for (int i = NUM_DIGITS_GF2X_ELEMENT - 1; i >= 0; i--) { dest[i] = in[i]; } } /* returns the coefficient of the x^exponent term as the LSB of a digit */ -DIGIT PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_get_coeff(const DIGIT poly[], unsigned int exponent) { +DIGIT PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_get_coeff(const DIGIT poly[], unsigned int exponent) { unsigned int straightIdx = (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_b - 1) - exponent; unsigned int digitIdx = straightIdx / DIGIT_SIZE_b; unsigned int inDigitIdx = straightIdx % DIGIT_SIZE_b; @@ -20,7 +20,7 @@ DIGIT PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_get_coeff(const DIGIT poly[], unsigned int } /* sets the coefficient of the x^exponent term as the LSB of a digit */ -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_set_coeff(DIGIT poly[], unsigned int exponent, DIGIT value) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_set_coeff(DIGIT poly[], unsigned int exponent, DIGIT value) { unsigned int straightIdx = (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_b - 1) - exponent; unsigned int digitIdx = straightIdx / DIGIT_SIZE_b; unsigned int inDigitIdx = straightIdx % DIGIT_SIZE_b; @@ -32,7 +32,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_set_coeff(DIGIT poly[], unsigned int exponen } /* toggles (flips) the coefficient of the x^exponent term as the LSB of a digit */ -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_toggle_coeff(DIGIT poly[], unsigned int exponent) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_toggle_coeff(DIGIT poly[], unsigned int exponent) { unsigned int straightIdx = (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_b - 1) - exponent; unsigned int digitIdx = straightIdx / DIGIT_SIZE_b; unsigned int inDigitIdx = straightIdx % DIGIT_SIZE_b; @@ -52,7 +52,7 @@ static int popcount_uint64t(uint64_t x) { } /* population count for a single polynomial */ -int PQCLEAN_LEDAKEMLT52_CLEAN_population_count(DIGIT *poly) { +int PQCLEAN_LEDAKEMLT52_LEAKTIME_population_count(DIGIT *poly) { int ret = 0; for (int i = NUM_DIGITS_GF2X_ELEMENT - 1; i >= 0; i--) { ret += popcount_uint64t(poly[i]); @@ -60,8 +60,8 @@ int PQCLEAN_LEDAKEMLT52_CLEAN_population_count(DIGIT *poly) { return ret; } -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_add(DIGIT Res[], const DIGIT A[], const DIGIT B[]) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_add(Res, A, B, NUM_DIGITS_GF2X_ELEMENT); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_add(DIGIT Res[], const DIGIT A[], const DIGIT B[]) { + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_add(Res, A, B, NUM_DIGITS_GF2X_ELEMENT); } static int partition(POSITION_T arr[], int lo, int hi) { @@ -83,7 +83,7 @@ static int partition(POSITION_T arr[], int lo, int hi) { return i + 1; } -void PQCLEAN_LEDAKEMLT52_CLEAN_quicksort_sparse(POSITION_T Res[]) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_quicksort_sparse(POSITION_T Res[]) { int stack[DV * M]; int hi, lo, pivot, tos = -1; stack[++tos] = 0; @@ -176,7 +176,7 @@ static void left_DIGIT_shift_n(unsigned int length, DIGIT in[], unsigned int amo /* may shift by an arbitrary amount*/ static void left_bit_shift_wide_n(const int length, DIGIT in[], unsigned int amount) { left_DIGIT_shift_n(length, in, amount / DIGIT_SIZE_b); - PQCLEAN_LEDAKEMLT52_CLEAN_left_bit_shift_n(length, in, amount % DIGIT_SIZE_b); + PQCLEAN_LEDAKEMLT52_LEAKTIME_left_bit_shift_n(length, in, amount % DIGIT_SIZE_b); } /* Hackers delight, reverses a uint64_t */ @@ -194,7 +194,7 @@ static DIGIT reverse_digit(DIGIT x) { return x; } -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_transpose_in_place(DIGIT A[]) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_transpose_in_place(DIGIT A[]) { /* it keeps the lsb in the same position and * inverts the sequence of the remaining bits */ @@ -215,7 +215,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_transpose_in_place(DIGIT A[]) { // A[NUM_DIGITS_GF2X_ELEMENT / 2] = reverse_digit(A[NUM_DIGITS_GF2X_ELEMENT / 2]); // no middle digit if (slack_bits_amount) { - PQCLEAN_LEDAKEMLT52_CLEAN_right_bit_shift_n(NUM_DIGITS_GF2X_ELEMENT, A, slack_bits_amount); + PQCLEAN_LEDAKEMLT52_LEAKTIME_right_bit_shift_n(NUM_DIGITS_GF2X_ELEMENT, A, slack_bits_amount); } A[NUM_DIGITS_GF2X_ELEMENT - 1] = (A[NUM_DIGITS_GF2X_ELEMENT - 1] & (~mask)) | a00; } @@ -266,7 +266,7 @@ static void gf2x_swap(const int length, DIGIT f[], DIGIT s[]) { * (Chapter 11 -- Algorithm 11.44 -- pag 223) * */ -int PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) { /* in^{-1} mod x^P-1 */ +int PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) { /* in^{-1} mod x^P-1 */ int i; int delta = 0; @@ -300,8 +300,8 @@ int PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) { delta += 1; } else { if ( (s[0] & mask) != 0) { - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_add(s, s, f, NUM_DIGITS_GF2X_MODULUS); - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_add(v, v, u); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_add(s, s, f, NUM_DIGITS_GF2X_MODULUS); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_add(v, v, u); } left_bit_shift(NUM_DIGITS_GF2X_MODULUS, s); if ( delta == 0 ) { @@ -323,7 +323,7 @@ int PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) { return (delta == 0); } -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const DIGIT B[]) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const DIGIT B[]) { DIGIT aux[2 * NUM_DIGITS_GF2X_ELEMENT]; GF2X_MUL(2 * NUM_DIGITS_GF2X_ELEMENT, aux, @@ -335,7 +335,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const /*PRE: the representation of the sparse coefficients is sorted in increasing order of the coefficients themselves */ -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_dense_to_sparse( +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_mul_dense_to_sparse( DIGIT Res[], const DIGIT dense[], POSITION_T sparse[], unsigned int nPos) { @@ -353,7 +353,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_dense_to_sparse( for (unsigned int i = 1; i < nPos; i++) { if (sparse[i] != INVALID_POS_VALUE) { left_bit_shift_wide_n(2 * NUM_DIGITS_GF2X_ELEMENT, aux, (sparse[i] - sparse[i - 1]) ); - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_add(resDouble, aux, resDouble, 2 * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_add(resDouble, aux, resDouble, 2 * NUM_DIGITS_GF2X_ELEMENT); } } } @@ -362,7 +362,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_dense_to_sparse( } -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_transpose_in_place_sparse(int sizeA, POSITION_T A[]) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_transpose_in_place_sparse(int sizeA, POSITION_T A[]) { POSITION_T t; int i = 0, j; @@ -384,7 +384,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_transpose_in_place_sparse(int sizeA, POSITIO } -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[], +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[], size_t sizeA, const POSITION_T A[], size_t sizeB, const POSITION_T B[]) { @@ -407,7 +407,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[ Res[lastFilledPos] = INVALID_POS_VALUE; lastFilledPos++; } - PQCLEAN_LEDAKEMLT52_CLEAN_quicksort_sparse(Res); + PQCLEAN_LEDAKEMLT52_LEAKTIME_quicksort_sparse(Res); /* eliminate duplicates */ POSITION_T lastReadPos = Res[0]; int duplicateCount; @@ -434,7 +434,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[ /* the implementation is safe even in case A or B alias with the result */ /* PRE: A and B should be sorted and have INVALID_POS_VALUE at the end */ -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_mod_add_sparse( +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_add_sparse( int sizeR, POSITION_T Res[], int sizeA, const POSITION_T A[], int sizeB, const POSITION_T B[]) { @@ -493,7 +493,7 @@ static uint32_t rand_range(const unsigned int n, const int logn, AES_XOF_struct uint32_t mask = ( (uint32_t)1 << logn) - 1; do { - PQCLEAN_LEDAKEMLT52_CLEAN_seedexpander(seed_expander_ctx, rnd_char_buffer, required_rnd_bytes); + PQCLEAN_LEDAKEMLT52_LEAKTIME_seedexpander(seed_expander_ctx, rnd_char_buffer, required_rnd_bytes); /* obtain an endianness independent representation of the generated random bytes into an unsigned integer */ rnd_value = ((uint32_t)rnd_char_buffer[3] << 24) + @@ -508,7 +508,7 @@ static uint32_t rand_range(const unsigned int n, const int logn, AES_XOF_struct /* Obtains fresh randomness and seed-expands it until all the required positions * for the '1's in the circulant block are obtained */ -void PQCLEAN_LEDAKEMLT52_CLEAN_rand_circulant_sparse_block(POSITION_T *pos_ones, +void PQCLEAN_LEDAKEMLT52_LEAKTIME_rand_circulant_sparse_block(POSITION_T *pos_ones, int countOnes, AES_XOF_struct *seed_expander_ctx) { @@ -533,7 +533,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_rand_circulant_sparse_block(POSITION_T *pos_ones, } /* Returns random weight-t circulant block */ -void PQCLEAN_LEDAKEMLT52_CLEAN_rand_circulant_blocks_sequence( +void PQCLEAN_LEDAKEMLT52_LEAKTIME_rand_circulant_blocks_sequence( DIGIT sequence[N0 * NUM_DIGITS_GF2X_ELEMENT], AES_XOF_struct *seed_expander_ctx) { @@ -559,13 +559,13 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_rand_circulant_blocks_sequence( for (int j = 0; j < counter; j++) { polyIndex = rndPos[j] / P; exponent = rndPos[j] % P; - PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_set_coeff( sequence + NUM_DIGITS_GF2X_ELEMENT * polyIndex, exponent, + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_set_coeff( sequence + NUM_DIGITS_GF2X_ELEMENT * polyIndex, exponent, ( (DIGIT) 1)); } } -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly) { size_t i, j; for (i = 0; i < NUM_DIGITS_GF2X_ELEMENT; i++) { for (j = 0; j < DIGIT_SIZE_B; j++) { @@ -574,7 +574,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly) { } } -void PQCLEAN_LEDAKEMLT52_CLEAN_gf2x_frombytes(DIGIT *poly, const uint8_t *poly_bytes) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_frombytes(DIGIT *poly, const uint8_t *poly_bytes) { size_t i, j; for (i = 0; i < NUM_DIGITS_GF2X_ELEMENT; i++) { poly[i] = (DIGIT) 0; diff --git a/crypto_kem/ledakemlt52/leaktime/gf2x_arith_mod_xPplusOne.h b/crypto_kem/ledakemlt52/leaktime/gf2x_arith_mod_xPplusOne.h new file mode 100644 index 00000000..2286c55f --- /dev/null +++ b/crypto_kem/ledakemlt52/leaktime/gf2x_arith_mod_xPplusOne.h @@ -0,0 +1,37 @@ +#ifndef GF2X_ARITH_MOD_XPLUSONE_H +#define GF2X_ARITH_MOD_XPLUSONE_H + +#include "qc_ldpc_parameters.h" + +#include "gf2x_arith.h" +#include "rng.h" + +#define NUM_BITS_GF2X_ELEMENT (P) // 152267 +#define NUM_DIGITS_GF2X_ELEMENT ((P+DIGIT_SIZE_b-1)/DIGIT_SIZE_b) // 2380 +#define MSb_POSITION_IN_MSB_DIGIT_OF_ELEMENT ((P % DIGIT_SIZE_b) ? (P % DIGIT_SIZE_b)-1 : DIGIT_SIZE_b-1) +#define NUM_BITS_GF2X_MODULUS (P+1) +#define NUM_DIGITS_GF2X_MODULUS ((P+1+DIGIT_SIZE_b-1)/DIGIT_SIZE_b) // 2380 +#define MSb_POSITION_IN_MSB_DIGIT_OF_MODULUS (P-DIGIT_SIZE_b*(NUM_DIGITS_GF2X_MODULUS-1)) +#define INVALID_POS_VALUE (P) +#define P_BITS (18) // log_2(p) = 17.216243783 + +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_copy(DIGIT dest[], const DIGIT in[]); +DIGIT PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_get_coeff(const DIGIT poly[], unsigned int exponent); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_set_coeff(DIGIT poly[], unsigned int exponent, DIGIT value); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_toggle_coeff(DIGIT poly[], unsigned int exponent); +int PQCLEAN_LEDAKEMLT52_LEAKTIME_population_count(DIGIT *poly); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_add(DIGIT Res[], const DIGIT A[], const DIGIT B[]); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_quicksort_sparse(POSITION_T Res[]); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_mul(DIGIT Res[], const DIGIT A[], const DIGIT B[]); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_transpose_in_place(DIGIT A[]); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_rand_circulant_sparse_block(POSITION_T *pos_ones, int countOnes, AES_XOF_struct *seed_expander_ctx); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_rand_circulant_blocks_sequence(DIGIT *sequence, AES_XOF_struct *seed_expander_ctx); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_add_sparse(int sizeR, POSITION_T Res[], int sizeA, const POSITION_T A[], int sizeB, const POSITION_T B[]); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_transpose_in_place_sparse(int sizeA, POSITION_T A[]); +int PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_inverse(DIGIT out[], const DIGIT in[]); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_mul_sparse(size_t sizeR, POSITION_T Res[], size_t sizeA, const POSITION_T A[], size_t sizeB, const POSITION_T B[]); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_mul_dense_to_sparse(DIGIT Res[], const DIGIT dense[], POSITION_T sparse[], unsigned int nPos); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_tobytes(uint8_t *bytes, const DIGIT *poly); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_frombytes(DIGIT *poly, const uint8_t *poly_bytes); + +#endif diff --git a/crypto_kem/ledakemlt12/clean/kem.c b/crypto_kem/ledakemlt52/leaktime/kem.c similarity index 58% rename from crypto_kem/ledakemlt12/clean/kem.c rename to crypto_kem/ledakemlt52/leaktime/kem.c index 89f47145..316d14d0 100644 --- a/crypto_kem/ledakemlt12/clean/kem.c +++ b/crypto_kem/ledakemlt52/leaktime/kem.c @@ -8,43 +8,43 @@ static void pack_pk(uint8_t *pk_bytes, publicKeyNiederreiter_t *pk) { size_t i; for (i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_tobytes(pk_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B, - pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_tobytes(pk_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B, + pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT); } } static void unpack_pk(publicKeyNiederreiter_t *pk, const uint8_t *pk_bytes) { size_t i; for (i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_frombytes(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_frombytes(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, pk_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); } } static void pack_ct(uint8_t *sk_bytes, DIGIT *ct) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_tobytes(sk_bytes, ct); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_tobytes(sk_bytes, ct); } static void unpack_ct(DIGIT *ct, const uint8_t *ct_bytes) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_frombytes(ct, ct_bytes); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_frombytes(ct, ct_bytes); } static void pack_error(uint8_t *error_bytes, DIGIT *error_digits) { size_t i; for (i = 0; i < N0; i++) { - PQCLEAN_LEDAKEMLT12_CLEAN_gf2x_tobytes(error_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B, - error_digits + i * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_tobytes(error_bytes + i * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B, + error_digits + i * NUM_DIGITS_GF2X_ELEMENT); } } /* Generates a keypair - pk is the public key and sk is the secret key. */ -int PQCLEAN_LEDAKEMLT12_CLEAN_crypto_kem_keypair(unsigned char *pk, unsigned char *sk) { +int PQCLEAN_LEDAKEMLT52_LEAKTIME_crypto_kem_keypair(unsigned char *pk, unsigned char *sk) { AES_XOF_struct niederreiter_keys_expander; publicKeyNiederreiter_t pk_nie; randombytes(((privateKeyNiederreiter_t *)sk)->prng_seed, TRNG_BYTE_LENGTH); - PQCLEAN_LEDAKEMLT12_CLEAN_seedexpander_from_trng(&niederreiter_keys_expander, ((privateKeyNiederreiter_t *)sk)->prng_seed); - PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_keygen(&pk_nie, (privateKeyNiederreiter_t *) sk, &niederreiter_keys_expander); + PQCLEAN_LEDAKEMLT52_LEAKTIME_seedexpander_from_trng(&niederreiter_keys_expander, ((privateKeyNiederreiter_t *)sk)->prng_seed); + PQCLEAN_LEDAKEMLT52_LEAKTIME_niederreiter_keygen(&pk_nie, (privateKeyNiederreiter_t *) sk, &niederreiter_keys_expander); pack_pk(pk, &pk_nie); @@ -53,7 +53,7 @@ int PQCLEAN_LEDAKEMLT12_CLEAN_crypto_kem_keypair(unsigned char *pk, unsigned cha /* Encrypt - pk is the public key, ct is a key encapsulation message (ciphertext), ss is the shared secret.*/ -int PQCLEAN_LEDAKEMLT12_CLEAN_crypto_kem_enc(unsigned char *ct, unsigned char *ss, const unsigned char *pk) { +int PQCLEAN_LEDAKEMLT52_LEAKTIME_crypto_kem_enc(unsigned char *ct, unsigned char *ss, const unsigned char *pk) { AES_XOF_struct niederreiter_encap_key_expander; unsigned char encapsulated_key_seed[TRNG_BYTE_LENGTH]; DIGIT error_vector[N0 * NUM_DIGITS_GF2X_ELEMENT]; @@ -64,11 +64,11 @@ int PQCLEAN_LEDAKEMLT12_CLEAN_crypto_kem_enc(unsigned char *ct, unsigned char *s randombytes(encapsulated_key_seed, TRNG_BYTE_LENGTH); unpack_pk(&pk_nie, pk); - PQCLEAN_LEDAKEMLT12_CLEAN_seedexpander_from_trng(&niederreiter_encap_key_expander, encapsulated_key_seed); - PQCLEAN_LEDAKEMLT12_CLEAN_rand_circulant_blocks_sequence(error_vector, &niederreiter_encap_key_expander); + PQCLEAN_LEDAKEMLT52_LEAKTIME_seedexpander_from_trng(&niederreiter_encap_key_expander, encapsulated_key_seed); + PQCLEAN_LEDAKEMLT52_LEAKTIME_rand_circulant_blocks_sequence(error_vector, &niederreiter_encap_key_expander); pack_error(error_bytes, error_vector); HASH_FUNCTION(ss, error_bytes, (N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B)); - PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_encrypt(syndrome, &pk_nie, error_vector); + PQCLEAN_LEDAKEMLT52_LEAKTIME_niederreiter_encrypt(syndrome, &pk_nie, error_vector); pack_ct(ct, syndrome); @@ -78,13 +78,13 @@ int PQCLEAN_LEDAKEMLT12_CLEAN_crypto_kem_enc(unsigned char *ct, unsigned char *s /* Decrypt - ct is a key encapsulation message (ciphertext), sk is the private key, ss is the shared secret */ -int PQCLEAN_LEDAKEMLT12_CLEAN_crypto_kem_dec(unsigned char *ss, const unsigned char *ct, const unsigned char *sk) { +int PQCLEAN_LEDAKEMLT52_LEAKTIME_crypto_kem_dec(unsigned char *ss, const unsigned char *ct, const unsigned char *sk) { DIGIT decoded_error_vector[N0 * NUM_DIGITS_GF2X_ELEMENT]; uint8_t decoded_error_bytes[N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B]; DIGIT syndrome[NUM_DIGITS_GF2X_ELEMENT]; unpack_ct(syndrome, ct); - PQCLEAN_LEDAKEMLT12_CLEAN_niederreiter_decrypt(decoded_error_vector, (privateKeyNiederreiter_t *)sk, syndrome); + PQCLEAN_LEDAKEMLT52_LEAKTIME_niederreiter_decrypt(decoded_error_vector, (privateKeyNiederreiter_t *)sk, syndrome); pack_error(decoded_error_bytes, decoded_error_vector); HASH_FUNCTION(ss, decoded_error_bytes, (N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B)); diff --git a/crypto_kem/ledakemlt32/clean/niederreiter.c b/crypto_kem/ledakemlt52/leaktime/niederreiter.c similarity index 65% rename from crypto_kem/ledakemlt32/clean/niederreiter.c rename to crypto_kem/ledakemlt52/leaktime/niederreiter.c index 1d67281c..d8a70262 100644 --- a/crypto_kem/ledakemlt32/clean/niederreiter.c +++ b/crypto_kem/ledakemlt52/leaktime/niederreiter.c @@ -8,7 +8,7 @@ #include -void PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, privateKeyNiederreiter_t *sk, AES_XOF_struct *keys_expander) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_niederreiter_keygen(publicKeyNiederreiter_t *pk, privateKeyNiederreiter_t *sk, AES_XOF_struct *keys_expander) { POSITION_T HPosOnes[N0][DV]; // sequence of N0 circ block matrices (p x p): Hi POSITION_T HtrPosOnes[N0][DV]; // Sparse tranposed circulant H @@ -23,8 +23,8 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, sk->rejections = (int8_t) 0; do { - PQCLEAN_LEDAKEMLT32_CLEAN_generateHPosOnes_HtrPosOnes(HPosOnes, HtrPosOnes, keys_expander); - PQCLEAN_LEDAKEMLT32_CLEAN_generateQsparse(QPosOnes, keys_expander); + PQCLEAN_LEDAKEMLT52_LEAKTIME_generateHPosOnes_HtrPosOnes(HPosOnes, HtrPosOnes, keys_expander); + PQCLEAN_LEDAKEMLT52_LEAKTIME_generateQsparse(QPosOnes, keys_expander); for (int i = 0; i < N0; i++) { for (int j = 0; j < DV * M; j++) { LPosOnes[i][j] = INVALID_POS_VALUE; @@ -34,10 +34,10 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, memset(processedQOnes, 0x00, sizeof(processedQOnes)); for (int colQ = 0; colQ < N0; colQ++) { for (int i = 0; i < N0; i++) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_sparse(DV * M, auxPosOnes, + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_mul_sparse(DV * M, auxPosOnes, DV, HPosOnes[i], qBlockWeights[i][colQ], QPosOnes[i] + processedQOnes[i]); - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_add_sparse(DV * M, LPosOnes[colQ], + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_add_sparse(DV * M, LPosOnes[colQ], DV * M, LPosOnes[colQ], DV * M, auxPosOnes); processedQOnes[i] += qBlockWeights[i][colQ]; @@ -49,7 +49,7 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, } sk->rejections = sk->rejections + 1; if (is_L_full) { - threshold = PQCLEAN_LEDAKEMLT32_CLEAN_DFR_test(LPosOnes); + threshold = PQCLEAN_LEDAKEMLT52_LEAKTIME_DFR_test(LPosOnes); } } while (!is_L_full || threshold == DFR_TEST_FAIL); sk->rejections = sk->rejections - 1; @@ -58,41 +58,41 @@ void PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, memset(Ln0dense, 0x00, sizeof(Ln0dense)); for (int j = 0; j < DV * M; j++) { if (LPosOnes[N0 - 1][j] != INVALID_POS_VALUE) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_set_coeff(Ln0dense, LPosOnes[N0 - 1][j], 1); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_set_coeff(Ln0dense, LPosOnes[N0 - 1][j], 1); } } memset(Ln0Inv, 0x00, sizeof(Ln0Inv)); - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_inverse(Ln0Inv, Ln0dense); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_inverse(Ln0Inv, Ln0dense); for (int i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_dense_to_sparse(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_mul_dense_to_sparse(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, Ln0Inv, LPosOnes[i], DV * M); } for (int i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_transpose_in_place(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_transpose_in_place(pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT); } } -void PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_encrypt(DIGIT *syndrome, const publicKeyNiederreiter_t *pk, const DIGIT *err) { +void PQCLEAN_LEDAKEMLT52_LEAKTIME_niederreiter_encrypt(DIGIT *syndrome, const publicKeyNiederreiter_t *pk, const DIGIT *err) { int i; DIGIT saux[NUM_DIGITS_GF2X_ELEMENT]; memset(syndrome, 0x00, NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); for (i = 0; i < N0 - 1; i++) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul(saux, - pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, - err + i * NUM_DIGITS_GF2X_ELEMENT); - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_add(syndrome, syndrome, saux); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_mul(saux, + pk->Mtr + i * NUM_DIGITS_GF2X_ELEMENT, + err + i * NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_add(syndrome, syndrome, saux); } - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_add(syndrome, syndrome, err + (N0 - 1)*NUM_DIGITS_GF2X_ELEMENT); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_add(syndrome, syndrome, err + (N0 - 1)*NUM_DIGITS_GF2X_ELEMENT); } -int PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyNiederreiter_t *sk, const DIGIT *syndrome) { +int PQCLEAN_LEDAKEMLT52_LEAKTIME_niederreiter_decrypt(DIGIT *err, const privateKeyNiederreiter_t *sk, const DIGIT *syndrome) { AES_XOF_struct niederreiter_decrypt_expander; POSITION_T HPosOnes[N0][DV]; POSITION_T HtrPosOnes[N0][DV]; @@ -110,11 +110,11 @@ int PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyN int currQoneIdx, endQblockIdx; int decryptOk, err_weight; - PQCLEAN_LEDAKEMLT32_CLEAN_seedexpander_from_trng(&niederreiter_decrypt_expander, sk->prng_seed); + PQCLEAN_LEDAKEMLT52_LEAKTIME_seedexpander_from_trng(&niederreiter_decrypt_expander, sk->prng_seed); do { - PQCLEAN_LEDAKEMLT32_CLEAN_generateHPosOnes_HtrPosOnes(HPosOnes, HtrPosOnes, &niederreiter_decrypt_expander); - PQCLEAN_LEDAKEMLT32_CLEAN_generateQsparse(QPosOnes, &niederreiter_decrypt_expander); + PQCLEAN_LEDAKEMLT52_LEAKTIME_generateHPosOnes_HtrPosOnes(HPosOnes, HtrPosOnes, &niederreiter_decrypt_expander); + PQCLEAN_LEDAKEMLT52_LEAKTIME_generateQsparse(QPosOnes, &niederreiter_decrypt_expander); for (int i = 0; i < N0; i++) { for (int j = 0; j < DV * M; j++) { LPosOnes[i][j] = INVALID_POS_VALUE; @@ -124,10 +124,10 @@ int PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyN memset(processedQOnes, 0x00, sizeof(processedQOnes)); for (int colQ = 0; colQ < N0; colQ++) { for (int i = 0; i < N0; i++) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_sparse(DV * M, auxPosOnes, + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_mul_sparse(DV * M, auxPosOnes, DV, HPosOnes[i], qBlockWeights[i][colQ], QPosOnes[i] + processedQOnes[i]); - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_add_sparse(DV * M, LPosOnes[colQ], + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_add_sparse(DV * M, LPosOnes[colQ], DV * M, LPosOnes[colQ], DV * M, auxPosOnes); processedQOnes[i] += qBlockWeights[i][colQ]; @@ -156,31 +156,31 @@ int PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyN } for (int i = 0; i < N0; i++) { - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_sparse(DV * M, auxSparse, + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_mul_sparse(DV * M, auxSparse, DV, HPosOnes[i], qBlockWeights[i][N0 - 1], &QPosOnes[i][ M - qBlockWeights[i][N0 - 1]]); - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_add_sparse(DV * M, Ln0trSparse, + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_add_sparse(DV * M, Ln0trSparse, DV * M, Ln0trSparse, DV * M, auxSparse); } - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_transpose_in_place_sparse(DV * M, Ln0trSparse); - PQCLEAN_LEDAKEMLT32_CLEAN_gf2x_mod_mul_dense_to_sparse(privateSyndrome, syndrome, Ln0trSparse, DV * M); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_transpose_in_place_sparse(DV * M, Ln0trSparse); + PQCLEAN_LEDAKEMLT52_LEAKTIME_gf2x_mod_mul_dense_to_sparse(privateSyndrome, syndrome, Ln0trSparse, DV * M); /* prepare mockup error vector in case a decoding failure occurs */ memset(mockup_error_vector, 0x00, N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); memcpy(mockup_error_vector, syndrome, NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); - PQCLEAN_LEDAKEMLT32_CLEAN_seedexpander(&niederreiter_decrypt_expander, - ((unsigned char *) mockup_error_vector) + (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B), - TRNG_BYTE_LENGTH); + PQCLEAN_LEDAKEMLT52_LEAKTIME_seedexpander(&niederreiter_decrypt_expander, + ((unsigned char *) mockup_error_vector) + (NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B), + TRNG_BYTE_LENGTH); memset(err, 0x00, N0 * NUM_DIGITS_GF2X_ELEMENT * DIGIT_SIZE_B); - decryptOk = PQCLEAN_LEDAKEMLT32_CLEAN_bf_decoding(err, (const POSITION_T (*)[DV]) HtrPosOnes, + decryptOk = PQCLEAN_LEDAKEMLT52_LEAKTIME_bf_decoding(err, (const POSITION_T (*)[DV]) HtrPosOnes, (const POSITION_T (*)[M]) QtrPosOnes, privateSyndrome, sk->threshold); err_weight = 0; for (int i = 0 ; i < N0; i++) { - err_weight += PQCLEAN_LEDAKEMLT32_CLEAN_population_count(err + (NUM_DIGITS_GF2X_ELEMENT * i)); + err_weight += PQCLEAN_LEDAKEMLT52_LEAKTIME_population_count(err + (NUM_DIGITS_GF2X_ELEMENT * i)); } decryptOk = decryptOk && (err_weight == NUM_ERRORS_T); diff --git a/crypto_kem/ledakemlt32/clean/niederreiter.h b/crypto_kem/ledakemlt52/leaktime/niederreiter.h similarity index 63% rename from crypto_kem/ledakemlt32/clean/niederreiter.h rename to crypto_kem/ledakemlt52/leaktime/niederreiter.h index c2e09ffa..68a9a547 100644 --- a/crypto_kem/ledakemlt32/clean/niederreiter.h +++ b/crypto_kem/ledakemlt52/leaktime/niederreiter.h @@ -21,9 +21,9 @@ typedef struct { // with P coefficients. } publicKeyNiederreiter_t; -void PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_keygen(publicKeyNiederreiter_t *pk, privateKeyNiederreiter_t *sk, AES_XOF_struct *keys_expander); -void PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_encrypt(DIGIT syndrome[], const publicKeyNiederreiter_t *pk, const DIGIT *err); -int PQCLEAN_LEDAKEMLT32_CLEAN_niederreiter_decrypt(DIGIT *err, const privateKeyNiederreiter_t *sk, const DIGIT *syndrome); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_niederreiter_keygen(publicKeyNiederreiter_t *pk, privateKeyNiederreiter_t *sk, AES_XOF_struct *keys_expander); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_niederreiter_encrypt(DIGIT syndrome[], const publicKeyNiederreiter_t *pk, const DIGIT *err); +int PQCLEAN_LEDAKEMLT52_LEAKTIME_niederreiter_decrypt(DIGIT *err, const privateKeyNiederreiter_t *sk, const DIGIT *syndrome); #endif diff --git a/crypto_kem/ledakemlt52/clean/qc_ldpc_parameters.h b/crypto_kem/ledakemlt52/leaktime/qc_ldpc_parameters.h similarity index 100% rename from crypto_kem/ledakemlt52/clean/qc_ldpc_parameters.h rename to crypto_kem/ledakemlt52/leaktime/qc_ldpc_parameters.h diff --git a/crypto_kem/ledakemlt52/clean/rng.c b/crypto_kem/ledakemlt52/leaktime/rng.c similarity index 94% rename from crypto_kem/ledakemlt52/clean/rng.c rename to crypto_kem/ledakemlt52/leaktime/rng.c index ef1a207f..b9f6c255 100644 --- a/crypto_kem/ledakemlt52/clean/rng.c +++ b/crypto_kem/ledakemlt52/leaktime/rng.c @@ -37,7 +37,7 @@ static void seedexpander_init(AES_XOF_struct *ctx, memset(ctx->buffer, 0x00, 16); } -void PQCLEAN_LEDAKEMLT52_CLEAN_seedexpander_from_trng(AES_XOF_struct *ctx, +void PQCLEAN_LEDAKEMLT52_LEAKTIME_seedexpander_from_trng(AES_XOF_struct *ctx, const unsigned char *trng_entropy /* TRNG_BYTE_LENGTH wide buffer */) { @@ -61,7 +61,7 @@ void PQCLEAN_LEDAKEMLT52_CLEAN_seedexpander_from_trng(AES_XOF_struct *ctx, x - returns the XOF data xlen - number of bytes to return */ -int PQCLEAN_LEDAKEMLT52_CLEAN_seedexpander(AES_XOF_struct *ctx, unsigned char *x, size_t xlen) { +int PQCLEAN_LEDAKEMLT52_LEAKTIME_seedexpander(AES_XOF_struct *ctx, unsigned char *x, size_t xlen) { size_t offset; aes256ctx ctx256; diff --git a/crypto_kem/ledakemlt32/clean/rng.h b/crypto_kem/ledakemlt52/leaktime/rng.h similarity index 67% rename from crypto_kem/ledakemlt32/clean/rng.h rename to crypto_kem/ledakemlt52/leaktime/rng.h index 8d7ee8c4..19470c36 100644 --- a/crypto_kem/ledakemlt32/clean/rng.h +++ b/crypto_kem/ledakemlt52/leaktime/rng.h @@ -18,7 +18,7 @@ typedef struct { unsigned char ctr[16]; } AES_XOF_struct; -int PQCLEAN_LEDAKEMLT32_CLEAN_seedexpander(AES_XOF_struct *ctx, unsigned char *x, size_t xlen); -void PQCLEAN_LEDAKEMLT32_CLEAN_seedexpander_from_trng(AES_XOF_struct *ctx, const unsigned char *trng_entropy); +int PQCLEAN_LEDAKEMLT52_LEAKTIME_seedexpander(AES_XOF_struct *ctx, unsigned char *x, size_t xlen); +void PQCLEAN_LEDAKEMLT52_LEAKTIME_seedexpander_from_trng(AES_XOF_struct *ctx, const unsigned char *trng_entropy); #endif