1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-22 23:48:58 +00:00

remove preprocessor conditionals

This commit is contained in:
Matthias J. Kannwischer 2019-06-03 21:51:05 +02:00 committed by Douglas Stebila
parent cb0e8367c6
commit b87bca514e
16 changed files with 114 additions and 168 deletions

View File

@ -1,9 +1,9 @@
#ifndef _BLAS_H_
#define _BLAS_H_
/// @file blas.h
/// @brief Defining the implementations for linear algebra functions depending on the machine architecture.
///
#ifndef _BLAS_H_
#define _BLAS_H_
#include "blas_comm.h"
#include "blas_u32.h"

View File

@ -1,8 +1,8 @@
#ifndef _BLAS_COMM_H_
#define _BLAS_COMM_H_
/// @file blas_comm.h
/// @brief Common functions for linear algebra.
///
#ifndef _BLAS_COMM_H_
#define _BLAS_COMM_H_
#include <stdint.h>

View File

@ -1,9 +1,9 @@
#ifndef _BLAS_U32_H_
#define _BLAS_U32_H_
/// @file blas_u32.h
/// @brief Inlined functions for implementing basic linear algebra functions for uint32 arch.
///
#ifndef _BLAS_U32_H_
#define _BLAS_U32_H_
#include "gf16.h"

View File

@ -1,9 +1,9 @@
#ifndef _GF16_H_
#define _GF16_H_
/// @file gf16.h
/// @brief Library for arithmetics in GF(16) and GF(256)
///
#ifndef _GF16_H_
#define _GF16_H_
#include <stdint.h>

View File

@ -1,14 +1,12 @@
#ifndef _HASH_LEN_CONFIG_H_
#define _HASH_LEN_CONFIG_H_
/// @file hash_len_config.h
/// @brief defining the lenght of outputs of the internel hash functions.
///
#ifndef _HASH_LEN_CONFIG_H_
#define _HASH_LEN_CONFIG_H_
// TODO: remove this file
/// defining the lenght of outputs of the internel hash functions.
#ifndef _HASH_LEN
#define _HASH_LEN (32)
#endif
//#define _HASH_LEN (32)
#endif

View File

@ -1,15 +1,10 @@
#ifndef _P_MATRIX_OP_H_
#define _P_MATRIX_OP_H_
/// @file parallel_matrix_op.h
/// @brief Librarys for operations of batched matrixes.
///
///
#ifndef _P_MATRIX_OP_H_
#define _P_MATRIX_OP_H_
////////////////////////////////////////////////////////////////////////
/// Librarys for batched matrix operations.
/// A batched matrix is a matrix which each element of the matrix

View File

@ -1,18 +1,15 @@
#ifndef _RAINBOW_H_
#define _RAINBOW_H_
/// @file rainbow.h
/// @brief APIs for rainbow.
///
#ifndef _RAINBOW_H_
#define _RAINBOW_H_
#include "rainbow_config.h"
#include "rainbow_keypair.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
///
@ -54,11 +51,4 @@ int PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_sign_cyclic( uint8_t *signature, cons
///
int PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_verify_cyclic( const uint8_t *digest, const uint8_t *signature, const cpk_t *pk );
#ifdef __cplusplus
}
#endif
#endif // _RAINBOW_H_

View File

@ -1,10 +1,10 @@
#ifndef _RAINBOW_BLAS_H_
#define _RAINBOW_BLAS_H_
/// @file rainbow_blas.h
/// @brief Defining the functions used in rainbow.c acconding to the definitions in rainbow_config.h
///
/// Defining the functions used in rainbow.c acconding to the definitions in rainbow_config.h
#ifndef _RAINBOW_BLAS_H_
#define _RAINBOW_BLAS_H_
#include "blas.h"
@ -12,8 +12,6 @@
#include "rainbow_config.h"
#ifdef _USE_GF16
#define gfv_get_ele PQCLEAN_RAINBOWIACLASSIC_CLEAN_gf16v_get_ele
#define gfv_mul_scalar PQCLEAN_RAINBOWIACLASSIC_CLEAN_gf16v_mul_scalar
#define gfv_madd PQCLEAN_RAINBOWIACLASSIC_CLEAN_gf16v_madd
@ -31,27 +29,5 @@
#define batch_quad_trimat_eval PQCLEAN_RAINBOWIACLASSIC_CLEAN_batch_quad_trimat_eval_gf16
#define batch_quad_recmat_eval PQCLEAN_RAINBOWIACLASSIC_CLEAN_batch_quad_recmat_eval_gf16
#else
#define gfv_get_ele gf256v_get_ele
#define gfv_mul_scalar gf256v_mul_scalar
#define gfv_madd gf256v_madd
#define gfmat_prod gf256mat_prod
#define gfmat_inv gf256mat_inv
#define batch_trimat_madd batch_trimat_madd_gf256
#define batch_trimatTr_madd batch_trimatTr_madd_gf256
#define batch_2trimat_madd batch_2trimat_madd_gf256
#define batch_matTr_madd batch_matTr_madd_gf256
#define batch_bmatTr_madd batch_bmatTr_madd_gf256
#define batch_mat_madd batch_mat_madd_gf256
#define batch_quad_trimat_eval batch_quad_trimat_eval_gf256
#define batch_quad_recmat_eval batch_quad_recmat_eval_gf256
#endif
#endif // _RAINBOW_BLAS_H_

View File

@ -1,3 +1,5 @@
#ifndef _H_RAINBOW_CONFIG_H_
#define _H_RAINBOW_CONFIG_H_
/// @file rainbow_config.h
/// @brief Defining the parameters of the Rainbow and the corresponding constants.
///
@ -6,45 +8,43 @@
///
///
#ifndef _H_RAINBOW_CONFIG_H_
#define _H_RAINBOW_CONFIG_H_
// TODO: refactor this
/// the defined parameter
#if (!defined(_RAINBOW16_32_32_32))&&(!defined(_RAINBOW256_68_36_36))&&(!defined(_RAINBOW256_92_48_48))
//#if (!defined(_RAINBOW16_32_32_32))&&(!defined(_RAINBOW256_68_36_36))&&(!defined(_RAINBOW256_92_48_48))
#define _RAINBOW16_32_32_32
//#define _RAINBOW256_68_36_36
//#define _RAINBOW256_92_48_48
#endif
//#endif
#if defined _RAINBOW16_32_32_32
//#if defined _RAINBOW16_32_32_32
#define _USE_GF16
#define _GFSIZE 16
#define _V1 32
#define _O1 32
#define _O2 32
#define _HASH_LEN 32
#elif defined _RAINBOW256_68_36_36
#define _GFSIZE 256
#define _V1 68
#define _O1 36
#define _O2 36
#define _HASH_LEN 48
#elif defined _RAINBOW256_92_48_48
#define _GFSIZE 256
#define _V1 92
#define _O1 48
#define _O2 48
#define _HASH_LEN 64
#else
error here.
#endif
//
//#elif defined _RAINBOW256_68_36_36
//#define _GFSIZE 256
//#define _V1 68
//#define _O1 36
//#define _O2 36
//#define _HASH_LEN 48
//
//#elif defined _RAINBOW256_92_48_48
//#define _GFSIZE 256
//#define _V1 92
//#define _O1 48
//#define _O2 48
//#define _HASH_LEN 64
//
//#else
//error here.
//#endif
#define _V2 ((_V1)+(_O1))
@ -64,7 +64,7 @@ error here.
/// size of variables, in # bytes.
#ifdef _USE_GF16
//#ifdef _USE_GF16
// GF16
#define _V1_BYTE (_V1/2)
#define _V2_BYTE (_V2/2)
@ -73,16 +73,16 @@ error here.
#define _PUB_N_BYTE (_PUB_N/2)
#define _PUB_M_BYTE (_PUB_M/2)
#else
// GF256
#define _V1_BYTE (_V1)
#define _V2_BYTE (_V2)
#define _O1_BYTE (_O1)
#define _O2_BYTE (_O2)
#define _PUB_N_BYTE (_PUB_N)
#define _PUB_M_BYTE (_PUB_M)
#endif
//#else
//// GF256
//#define _V1_BYTE (_V1)
//#define _V2_BYTE (_V2)
//#define _O1_BYTE (_O1)
//#define _O2_BYTE (_O2)
//#define _PUB_N_BYTE (_PUB_N)
//#define _PUB_M_BYTE (_PUB_M)
//
//#endif
/// length of seed for public key, in # bytes

View File

@ -1,10 +1,10 @@
#ifndef _RAINBOW_KEYPAIR_H_
#define _RAINBOW_KEYPAIR_H_
/// @file rainbow_keypair.h
/// @brief Formats of key pairs and functions for generating key pairs.
/// Formats of key pairs and functions for generating key pairs.
///
#ifndef _RAINBOW_KEYPAIR_H_
#define _RAINBOW_KEYPAIR_H_
#include "rainbow_config.h"

View File

@ -119,18 +119,8 @@ void calculate_Q_from_F_ref( ext_cpk_t *Qs, const sk_t *Fs, const sk_t *Ts ) {
// l2_Q5 : _O2_BYTE * _V1 * _O1
// l2_Q9 : _O2_BYTE * _V1 * _O2
#define SIZE_TEMPQ (_O1_BYTE * _O1 * _O1)
#if (_O1_BYTE*_O2*_O2)> SIZE_TEMPQ
#define SIZE_TEMPQ (_O1_BYTE*_O2*_O2)
#endif
#if (_O2_BYTE*_O1*_O1) > SIZE_TEMPQ
#define SIZE_TEMPQ (_O2_BYTE*_O1*_O1)
#endif
#if (_O2_BYTE*_O2*_O2) > SIZE_TEMPQ
#define SIZE_TEMPQ (_O2_BYTE*_O2*_O2)
#endif
unsigned char tempQ[SIZE_TEMPQ + 32];
unsigned char tempQ[_O1_BYTE * _O1 * _O1 + 32];
memset( tempQ, 0, _O1_BYTE * _O1 * _O1 ); // l1_Q5
batch_matTr_madd( tempQ, Ts->t1, _V1, _V1_BYTE, _O1, Qs->l1_Q2, _O1, _O1_BYTE ); // t1_tr*(F1*T1 + F2)

View File

@ -1,3 +1,5 @@
#ifndef _RAINBOW_KEYPAIR_COMP_H_
#define _RAINBOW_KEYPAIR_COMP_H_
/// @file rainbow_keypair_computation.h
/// @brief Functions for calculating pk/sk while generating keys.
///
@ -5,8 +7,6 @@
/// Functions for calculating pk/sk for key generation.
///
#ifndef _RAINBOW_KEYPAIR_COMP_H_
#define _RAINBOW_KEYPAIR_COMP_H_
#include "rainbow_keypair.h"

View File

@ -20,25 +20,25 @@ PQCLEAN_RAINBOWIACLASSIC_CLEAN_crypto_sign_keypair(unsigned char *pk, unsigned c
unsigned char sk_seed[LEN_SKSEED] = {0};
randombytes( sk_seed, LEN_SKSEED );
#if defined _RAINBOW_CLASSIC
// #if defined _RAINBOW_CLASSIC
PQCLEAN_RAINBOWIACLASSIC_CLEAN_generate_keypair( (pk_t *) pk, (sk_t *) sk, sk_seed );
#elif defined _RAINBOW_CYCLIC
// #elif defined _RAINBOW_CYCLIC
unsigned char pk_seed[LEN_PKSEED] = {0};
randombytes( pk_seed, LEN_PKSEED );
generate_keypair_cyclic( (cpk_t *) pk, (sk_t *) sk, pk_seed, sk_seed );
// unsigned char pk_seed[LEN_PKSEED] = {0};
// randombytes( pk_seed, LEN_PKSEED );
// generate_keypair_cyclic( (cpk_t *) pk, (sk_t *) sk, pk_seed, sk_seed );
#elif defined _RAINBOW_CYCLIC_COMPRESSED
// #elif defined _RAINBOW_CYCLIC_COMPRESSED
unsigned char pk_seed[LEN_PKSEED] = {0};
randombytes( pk_seed, LEN_PKSEED );
generate_compact_keypair_cyclic( (cpk_t *) pk, (csk_t *) sk, pk_seed, sk_seed );
// unsigned char pk_seed[LEN_PKSEED] = {0};
// randombytes( pk_seed, LEN_PKSEED );
// generate_compact_keypair_cyclic( (cpk_t *) pk, (csk_t *) sk, pk_seed, sk_seed );
#else
error here
#endif
// #else
// error here
// #endif
return 0;
}
@ -55,21 +55,21 @@ PQCLEAN_RAINBOWIACLASSIC_CLEAN_crypto_sign(unsigned char *sm, size_t *smlen, con
memcpy( sm, m, mlen );
smlen[0] = mlen + _SIGNATURE_BYTE;
#if defined _RAINBOW_CLASSIC
// #if defined _RAINBOW_CLASSIC
return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_sign( sm + mlen, (const sk_t *)sk, digest );
#elif defined _RAINBOW_CYCLIC
// #elif defined _RAINBOW_CYCLIC
return rainbow_sign( sm + mlen, (const sk_t *)sk, digest );
// return rainbow_sign( sm + mlen, (const sk_t *)sk, digest );
#elif defined _RAINBOW_CYCLIC_COMPRESSED
// #elif defined _RAINBOW_CYCLIC_COMPRESSED
return rainbow_sign_cyclic( sm + mlen, (const csk_t *)sk, digest );
// return rainbow_sign_cyclic( sm + mlen, (const csk_t *)sk, digest );
#else
error here
#endif
// #else
// error here
// #endif
}
@ -91,21 +91,21 @@ PQCLEAN_RAINBOWIACLASSIC_CLEAN_crypto_sign_open(unsigned char *m, size_t *mlen,
unsigned char digest[_HASH_LEN];
PQCLEAN_RAINBOWIACLASSIC_CLEAN_hash_msg( digest, _HASH_LEN, m, *mlen );
#if defined _RAINBOW_CLASSIC
// #if defined _RAINBOW_CLASSIC
return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_verify( digest, sm + mlen[0], (const pk_t *)pk );
#elif defined _RAINBOW_CYCLIC
// #elif defined _RAINBOW_CYCLIC
return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_verify_cyclic( digest, sm + mlen[0], (const cpk_t *)pk );
// return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_verify_cyclic( digest, sm + mlen[0], (const cpk_t *)pk );
#elif defined _RAINBOW_CYCLIC_COMPRESSED
// #elif defined _RAINBOW_CYCLIC_COMPRESSED
return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_verify_cyclic( digest, sm + mlen[0], (const cpk_t *)pk );
// return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_verify_cyclic( digest, sm + mlen[0], (const cpk_t *)pk );
#else
error here
#endif
// #else
// error here
// #endif
}
@ -117,15 +117,15 @@ int PQCLEAN_RAINBOWIACLASSIC_CLEAN_crypto_sign_signature(
PQCLEAN_RAINBOWIACLASSIC_CLEAN_hash_msg( digest, _HASH_LEN, m, mlen );
*siglen = _SIGNATURE_BYTE;
#if defined _RAINBOW_CLASSIC
// #if defined _RAINBOW_CLASSIC
return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_sign( sig, (const sk_t *)sk, digest );
#elif defined _RAINBOW_CYCLIC
return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_sign( sig, (const sk_t *)sk, digest );
#elif defined _RAINBOW_CYCLIC_COMPRESSED
return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_sign_cyclic( sig, (const csk_t *)sk, digest );
#else
error here
#endif
// #elif defined _RAINBOW_CYCLIC
// return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_sign( sig, (const sk_t *)sk, digest );
// #elif defined _RAINBOW_CYCLIC_COMPRESSED
// return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_sign_cyclic( sig, (const csk_t *)sk, digest );
// #else
// error here
// #endif
}
@ -137,14 +137,14 @@ int PQCLEAN_RAINBOWIACLASSIC_CLEAN_crypto_sign_verify(
}
unsigned char digest[_HASH_LEN];
PQCLEAN_RAINBOWIACLASSIC_CLEAN_hash_msg( digest, _HASH_LEN, m, mlen );
#if defined _RAINBOW_CLASSIC
// #if defined _RAINBOW_CLASSIC
return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_verify( digest, sig, (const pk_t *)pk );
#elif defined _RAINBOW_CYCLIC
return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_verify_cyclic( digest, sig, (const cpk_t *)pk );
#elif defined _RAINBOW_CYCLIC_COMPRESSED
return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_verify_cyclic( digest, sig, (const cpk_t *)pk );
#else
error here
#endif
// #elif defined _RAINBOW_CYCLIC
// return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_verify_cyclic( digest, sig, (const cpk_t *)pk );
// #elif defined _RAINBOW_CYCLIC_COMPRESSED
// return PQCLEAN_RAINBOWIACLASSIC_CLEAN_rainbow_verify_cyclic( digest, sig, (const cpk_t *)pk );
// #else
// error here
// #endif
}

View File

@ -4,24 +4,21 @@
///
#include "hash_len_config.h"
#include "rainbow_config.h"
#include "sha2.h"
#include "utils_hash.h"
#ifndef _HASH_LEN
#define _HASH_LEN (32)
#endif
static inline
int _hash( unsigned char *digest, const unsigned char *m, unsigned long long mlen ) {
#if 32 == _HASH_LEN
// #if 32 == _HASH_LEN
sha256(digest, m, mlen);
#elif 48 == _HASH_LEN
sha384(digest, m, mlen);
#elif 64 == _HASH_LEN
sha512(digest, m, mlen);
#else
#error "unsupported _HASH_LEN"
#endif
// #elif 48 == _HASH_LEN
// sha384(digest, m, mlen);
// #elif 64 == _HASH_LEN
// sha512(digest, m, mlen);
// #else
//#error "unsupported _HASH_LEN"
// #endif
return 0;
}

View File

@ -1,9 +1,9 @@
#ifndef _UTILS_HASH_H_
#define _UTILS_HASH_H_
/// @file utils_hash.h
/// @brief the interface for adapting hash functions.
///
///
#ifndef _UTILS_HASH_H_
#define _UTILS_HASH_H_
// for the definition of _HASH_LEN.
#include "hash_len_config.h"

View File

@ -1,10 +1,10 @@
#ifndef _UTILS_PRNG_H_
#define _UTILS_PRNG_H_
/// @file utils_prng.h
/// @brief the interface for adapting PRNG functions.
///
///
#ifndef _UTILS_PRNG_H_
#define _UTILS_PRNG_H_
#include "randombytes.h"