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

Merge pull request #76 from PQClean/namespaced-consts

Namespace the #define constants.
This commit is contained in:
Joost Rijneveld 2019-03-19 21:11:37 +00:00 committed by GitHub
commit 8255f49fc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 15 deletions

View File

@ -1,16 +1,16 @@
#ifndef API_H #ifndef PQCLEAN_KYBER768_CLEAN_API_H
#define API_H #define PQCLEAN_KYBER768_CLEAN_API_H
#include <stdint.h> #include <stdint.h>
#include "params.h" #include "params.h"
#define CRYPTO_SECRETKEYBYTES KYBER_SECRETKEYBYTES #define PQCLEAN_KYBER768_CLEAN_CRYPTO_SECRETKEYBYTES KYBER_SECRETKEYBYTES
#define CRYPTO_PUBLICKEYBYTES KYBER_PUBLICKEYBYTES #define PQCLEAN_KYBER768_CLEAN_CRYPTO_PUBLICKEYBYTES KYBER_PUBLICKEYBYTES
#define CRYPTO_CIPHERTEXTBYTES KYBER_CIPHERTEXTBYTES #define PQCLEAN_KYBER768_CLEAN_CRYPTO_CIPHERTEXTBYTES KYBER_CIPHERTEXTBYTES
#define CRYPTO_BYTES KYBER_SYMBYTES #define PQCLEAN_KYBER768_CLEAN_CRYPTO_BYTES KYBER_SYMBYTES
#define CRYPTO_ALGNAME "Kyber768" #define PQCLEAN_KYBER768_CLEAN_CRYPTO_ALGNAME "Kyber768"
int PQCLEAN_KYBER768_CLEAN_crypto_kem_keypair(uint8_t *pk, uint8_t *sk); int PQCLEAN_KYBER768_CLEAN_crypto_kem_keypair(uint8_t *pk, uint8_t *sk);

View File

@ -1,17 +1,16 @@
#ifndef API_H #ifndef PQCLEAN_DILITHIUMIII_CLEAN_API_H
#include <stdint.h> #define PQCLEAN_DILITHIUMIII_CLEAN_API_H
#define API_H
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#define MODE 2 #define MODE 2
#define CRYPTO_PUBLICKEYBYTES 1472U #define PQCLEAN_DILITHIUMIII_CLEAN_CRYPTO_PUBLICKEYBYTES 1472U
#define CRYPTO_SECRETKEYBYTES 3504U #define PQCLEAN_DILITHIUMIII_CLEAN_CRYPTO_SECRETKEYBYTES 3504U
#define CRYPTO_BYTES 2701U #define PQCLEAN_DILITHIUMIII_CLEAN_CRYPTO_BYTES 2701U
#define CRYPTO_ALGNAME "Dilithium-III" #define PQCLEAN_DILITHIUMIII_CLEAN_CRYPTO_ALGNAME "Dilithium-III"
int PQCLEAN_DILITHIUMIII_CLEAN_crypto_sign_keypair(uint8_t *pk, int PQCLEAN_DILITHIUMIII_CLEAN_crypto_sign_keypair(uint8_t *pk,
uint8_t *sk); uint8_t *sk);

View File

@ -15,7 +15,7 @@ COMMON_HEADERS=$(COMMON_DIR)/fips202.h $(COMMON_DIR)/randombytes.h $(COMMON_DIR)
DEST_DIR=../bin DEST_DIR=../bin
# This -Wall was supported by the European Commission through the ERC Starting Grant 805031 (EPOQUE) # This -Wall was supported by the European Commission through the ERC Starting Grant 805031 (EPOQUE)
CFLAGS=-Wall -Wextra -Wpedantic -Werror -std=c99 -I$(COMMON_DIR) $(EXTRAFLAGS) CFLAGS=-Wall -Wextra -Wpedantic -Werror -Wundef -std=c99 -I$(COMMON_DIR) $(EXTRAFLAGS)
all: $(DEST_DIR)/functest_$(SCHEME)_$(IMPLEMENTATION) $(DEST_DIR)/testvectors_$(SCHEME)_$(IMPLEMENTATION) all: $(DEST_DIR)/functest_$(SCHEME)_$(IMPLEMENTATION) $(DEST_DIR)/testvectors_$(SCHEME)_$(IMPLEMENTATION)

View File

@ -34,6 +34,12 @@ static int check_canary(const uint8_t *d) {
#define EVALUATOR(x, y) PASTER(x, y) #define EVALUATOR(x, y) PASTER(x, y)
#define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun) #define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun)
#define CRYPTO_BYTES NAMESPACE(CRYPTO_BYTES)
#define CRYPTO_PUBLICKEYBYTES NAMESPACE(CRYPTO_PUBLICKEYBYTES)
#define CRYPTO_SECRETKEYBYTES NAMESPACE(CRYPTO_SECRETKEYBYTES)
#define CRYPTO_CIPHERTEXTBYTES NAMESPACE(CRYPTO_CIPHERTEXTBYTES)
#define CRYPTO_ALGNAME NAMESPACE(CRYPTO_ALGNAME)
#define crypto_kem_keypair NAMESPACE(crypto_kem_keypair) #define crypto_kem_keypair NAMESPACE(crypto_kem_keypair)
#define crypto_kem_enc NAMESPACE(crypto_kem_enc) #define crypto_kem_enc NAMESPACE(crypto_kem_enc)
#define crypto_kem_dec NAMESPACE(crypto_kem_dec) #define crypto_kem_dec NAMESPACE(crypto_kem_dec)
@ -44,12 +50,23 @@ static int check_canary(const uint8_t *d) {
return -1; \ return -1; \
} }
// https://stackoverflow.com/a/55243651/248065
#define MY_TRUTHY_VALUE_X 1
#define CAT(x,y) CAT_(x,y)
#define CAT_(x,y) x##y
#define HAS_NAMESPACE(x) CAT(CAT(MY_TRUTHY_VALUE_,CAT(PQCLEAN_NAMESPACE,CAT(_,x))),X)
#if !HAS_NAMESPACE(API_H)
#error "namespace not properly defined for header guard"
#endif
static int test_keys(void) { static int test_keys(void) {
/* /*
* This is most likely going to be aligned by the compiler. * This is most likely going to be aligned by the compiler.
* 16 extra bytes for canary * 16 extra bytes for canary
* 1 extra byte for unalignment * 1 extra byte for unalignment
*/ */
uint8_t key_a_aligned[CRYPTO_BYTES + 16 + 1]; uint8_t key_a_aligned[CRYPTO_BYTES + 16 + 1];
uint8_t key_b_aligned[CRYPTO_BYTES + 16 + 1]; uint8_t key_b_aligned[CRYPTO_BYTES + 16 + 1];
uint8_t pk_aligned[CRYPTO_PUBLICKEYBYTES + 16 + 1]; uint8_t pk_aligned[CRYPTO_PUBLICKEYBYTES + 16 + 1];
@ -190,6 +207,9 @@ static int test_invalid_ciphertext(void) {
} }
int main(void) { int main(void) {
// Check if CRYPTO_ALGNAME is printable
puts(CRYPTO_ALGNAME);
int result = 0; int result = 0;
result += test_keys(); result += test_keys();
result += test_invalid_sk_a(); result += test_invalid_sk_a();

View File

@ -21,6 +21,11 @@ static void printbytes(const uint8_t *x, size_t xlen) {
#define EVALUATOR(x, y) PASTER(x, y) #define EVALUATOR(x, y) PASTER(x, y)
#define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun) #define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun)
#define CRYPTO_BYTES NAMESPACE(CRYPTO_BYTES)
#define CRYPTO_PUBLICKEYBYTES NAMESPACE(CRYPTO_PUBLICKEYBYTES)
#define CRYPTO_SECRETKEYBYTES NAMESPACE(CRYPTO_SECRETKEYBYTES)
#define CRYPTO_CIPHERTEXTBYTES NAMESPACE(CRYPTO_CIPHERTEXTBYTES)
#define crypto_kem_keypair NAMESPACE(crypto_kem_keypair) #define crypto_kem_keypair NAMESPACE(crypto_kem_keypair)
#define crypto_kem_enc NAMESPACE(crypto_kem_enc) #define crypto_kem_enc NAMESPACE(crypto_kem_enc)
#define crypto_kem_dec NAMESPACE(crypto_kem_dec) #define crypto_kem_dec NAMESPACE(crypto_kem_dec)

View File

@ -36,6 +36,11 @@ static int check_canary(const uint8_t *d) {
#define EVALUATOR(x, y) PASTER(x, y) #define EVALUATOR(x, y) PASTER(x, y)
#define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun) #define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun)
#define CRYPTO_PUBLICKEYBYTES NAMESPACE(CRYPTO_PUBLICKEYBYTES)
#define CRYPTO_SECRETKEYBYTES NAMESPACE(CRYPTO_SECRETKEYBYTES)
#define CRYPTO_BYTES NAMESPACE(CRYPTO_BYTES)
#define CRYPTO_ALGNAME NAMESPACE(CRYPTO_ALGNAME)
#define crypto_sign_keypair NAMESPACE(crypto_sign_keypair) #define crypto_sign_keypair NAMESPACE(crypto_sign_keypair)
#define crypto_sign NAMESPACE(crypto_sign) #define crypto_sign NAMESPACE(crypto_sign)
#define crypto_sign_open NAMESPACE(crypto_sign_open) #define crypto_sign_open NAMESPACE(crypto_sign_open)
@ -46,6 +51,17 @@ static int check_canary(const uint8_t *d) {
return -1; \ return -1; \
} }
// https://stackoverflow.com/a/55243651/248065
#define MY_TRUTHY_VALUE_X 1
#define CAT(x,y) CAT_(x,y)
#define CAT_(x,y) x##y
#define HAS_NAMESPACE(x) CAT(CAT(MY_TRUTHY_VALUE_,CAT(PQCLEAN_NAMESPACE,CAT(_,x))),X)
#if !HAS_NAMESPACE(API_H)
#error "namespace not properly defined for header guard"
#endif
static int test_sign(void) { static int test_sign(void) {
/* /*
* This is most likely going to be aligned by the compiler. * This is most likely going to be aligned by the compiler.
@ -155,6 +171,8 @@ static int test_wrong_pk(void) {
} }
int main(void) { int main(void) {
// check if CRYPTO_ALGNAME is printable
puts(CRYPTO_ALGNAME);
int result = 0; int result = 0;
result += test_sign(); result += test_sign();
result += test_wrong_pk(); result += test_wrong_pk();

View File

@ -22,6 +22,10 @@ static void printbytes(const uint8_t *x, size_t xlen) {
#define EVALUATOR(x, y) PASTER(x, y) #define EVALUATOR(x, y) PASTER(x, y)
#define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun) #define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun)
#define CRYPTO_PUBLICKEYBYTES NAMESPACE(CRYPTO_PUBLICKEYBYTES)
#define CRYPTO_SECRETKEYBYTES NAMESPACE(CRYPTO_SECRETKEYBYTES)
#define CRYPTO_BYTES NAMESPACE(CRYPTO_BYTES)
#define crypto_sign_keypair NAMESPACE(crypto_sign_keypair) #define crypto_sign_keypair NAMESPACE(crypto_sign_keypair)
#define crypto_sign NAMESPACE(crypto_sign) #define crypto_sign NAMESPACE(crypto_sign)
#define crypto_sign_open NAMESPACE(crypto_sign_open) #define crypto_sign_open NAMESPACE(crypto_sign_open)