diff --git a/Makefile b/Makefile index 3381a8ca..a51e476f 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ endif bin/functest_$(subst /,_,$(SCHEME)): test/$(dir $(SCHEME))functest.c $(wildcard $(SCHEME)/clean/*.c) $(wildcard $(SCHEME)/clean/*.h) | require_scheme mkdir -p bin $(CC) $(CFLAGS) \ + -DPQCLEAN_NAMESPACE=$(shell echo PQCLEAN_$(subst -,,$(notdir $(SCHEME))) | tr a-z A-Z) \ -iquote "./common/" \ -iquote "$(SCHEME)/clean/" \ -o bin/functest_$(subst /,_,$(SCHEME)) \ @@ -49,6 +50,7 @@ sanitizer: bin/sanitizer_$(subst /,_,$(SCHEME)) bin/testvectors_$(subst /,_,$(SCHEME)): test/$(dir $(SCHEME))testvectors.c $(wildcard $(SCHEME)/clean/*.c) $(wildcard $(SCHEME)/clean/*.h) | require_scheme mkdir -p bin $(CC) $(CFLAGS) \ + -DPQCLEAN_NAMESPACE=$(shell echo PQCLEAN_$(subst -,,$(notdir $(SCHEME))) | tr a-z A-Z) \ -iquote "./common/" \ -iquote "$(SCHEME)/clean/" \ -o bin/testvectors_$(subst /,_,$(SCHEME)) \ @@ -62,6 +64,7 @@ testvectors: bin/testvectors_$(subst /,_,$(SCHEME)) bin/shared_$(subst /,_,$(SCHEME))_clean.so: $(wildcard $(SCHEME)/clean/*.c) | require_scheme mkdir -p bin gcc $(CFLAGS) \ + -DPQCLEAN_NAMESPACE=$(shell echo PQCLEAN_$(subst -,,$(notdir $(SCHEME))) | tr a-z A-Z) \ -shared \ -fPIC \ -iquote "./common/" \ diff --git a/test/check_symbol_namespace.py b/test/check_symbol_namespace.py index cec4143f..a28eb874 100644 --- a/test/check_symbol_namespace.py +++ b/test/check_symbol_namespace.py @@ -13,7 +13,7 @@ if len(sys.argv) != 2: SCHEME = sys.argv[1] SCHEMEFULL = SCHEME.replace('/', '_') # e.g. crypto_kem_kyber768 SCHEMESHORT = SCHEME.split('/')[1].upper() -namespace = f"PQCLEAN_{SCHEMESHORT}_" +namespace = f"PQCLEAN_{SCHEMESHORT}_".replace('-', '') # TODO can we do this using object files instead, to preserve file origin? sharedlib = f"bin/shared_{SCHEMEFULL}_clean.so" diff --git a/test/crypto_kem/functest.c b/test/crypto_kem/functest.c index 9e83ee20..f4f970c5 100644 --- a/test/crypto_kem/functest.c +++ b/test/crypto_kem/functest.c @@ -20,6 +20,15 @@ static int check_canary(const unsigned char *d) { return 0; } +// https://stackoverflow.com/a/1489985/1711232 +#define PASTER(x, y) x##_##y +#define EVALUATOR(x, y) PASTER(x, y) +#define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun) + +#define crypto_kem_keypair NAMESPACE(crypto_kem_keypair) +#define crypto_kem_enc NAMESPACE(crypto_kem_enc) +#define crypto_kem_dec NAMESPACE(crypto_kem_dec) + static int test_keys(void) { unsigned char key_a[CRYPTO_BYTES + 16], key_b[CRYPTO_BYTES + 16]; unsigned char pk[CRYPTO_PUBLICKEYBYTES + 16]; diff --git a/test/crypto_kem/testvectors.c b/test/crypto_kem/testvectors.c index 16b6973f..bad4a88b 100644 --- a/test/crypto_kem/testvectors.c +++ b/test/crypto_kem/testvectors.c @@ -13,6 +13,15 @@ static void printbytes(const unsigned char *x, unsigned long long xlen) { printf("\n"); } +// https://stackoverflow.com/a/1489985/1711232 +#define PASTER(x, y) x##_##y +#define EVALUATOR(x, y) PASTER(x, y) +#define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun) + +#define crypto_kem_keypair NAMESPACE(crypto_kem_keypair) +#define crypto_kem_enc NAMESPACE(crypto_kem_enc) +#define crypto_kem_dec NAMESPACE(crypto_kem_dec) + int main(void) { unsigned char key_a[CRYPTO_BYTES], key_b[CRYPTO_BYTES]; unsigned char pk[CRYPTO_PUBLICKEYBYTES]; diff --git a/test/crypto_sign/functest.c b/test/crypto_sign/functest.c index 7a5a0f57..60158e64 100644 --- a/test/crypto_sign/functest.c +++ b/test/crypto_sign/functest.c @@ -20,6 +20,16 @@ static int check_canary(const unsigned char *d) { return 0; } + +// https://stackoverflow.com/a/1489985/1711232 +#define PASTER(x, y) x##_##y +#define EVALUATOR(x, y) PASTER(x, y) +#define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun) + +#define crypto_sign_keypair NAMESPACE(crypto_sign_keypair) +#define crypto_sign NAMESPACE(crypto_sign) +#define crypto_sign_open NAMESPACE(crypto_sign_open) + static int test_sign(void) { unsigned char pk[CRYPTO_PUBLICKEYBYTES + 16]; unsigned char sk[CRYPTO_SECRETKEYBYTES + 16]; diff --git a/test/crypto_sign/testvectors.c b/test/crypto_sign/testvectors.c index 156352a8..39240442 100644 --- a/test/crypto_sign/testvectors.c +++ b/test/crypto_sign/testvectors.c @@ -14,6 +14,15 @@ static void printbytes(const unsigned char *x, unsigned long long xlen) { printf("\n"); } +// https://stackoverflow.com/a/1489985/1711232 +#define PASTER(x, y) x##_##y +#define EVALUATOR(x, y) PASTER(x, y) +#define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun) + +#define crypto_sign_keypair NAMESPACE(crypto_sign_keypair) +#define crypto_sign NAMESPACE(crypto_sign) +#define crypto_sign_open NAMESPACE(crypto_sign_open) + int main(void) { unsigned char sk[CRYPTO_SECRETKEYBYTES]; unsigned char pk[CRYPTO_PUBLICKEYBYTES];