Skip to content

Commit

Permalink
export symbols for acvp tests (dynamic linking), test improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Basil Hess <[email protected]>
  • Loading branch information
bhess committed Nov 5, 2024
1 parent 0989e9d commit 1f89068
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 19 deletions.
31 changes: 31 additions & 0 deletions scripts/copy_from_upstream/patches/pqcrystals-ml_dsa.patch
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,37 @@ index 7d3f882..abb033c 100644
for(i = 0; i < CTILDEBYTES; ++i)
if(c[i] != c2[i])
return -1;
diff --git a/ref/sign.h b/ref/sign.h
index 2741e8f..0b5f74a 100644
--- a/ref/sign.h
+++ b/ref/sign.h
@@ -1,6 +1,8 @@
#ifndef SIGN_H
#define SIGN_H

+#include <oqs/oqs.h>
+
#include <stddef.h>
#include <stdint.h>
#include "params.h"
@@ -11,7 +13,7 @@
int crypto_sign_keypair(uint8_t *pk, uint8_t *sk);

#define crypto_sign_signature_internal DILITHIUM_NAMESPACE(signature_internal)
-int crypto_sign_signature_internal(uint8_t *sig,
+OQS_API int crypto_sign_signature_internal(uint8_t *sig,
size_t *siglen,
const uint8_t *m,
size_t mlen,
@@ -33,7 +35,7 @@ int crypto_sign(uint8_t *sm, size_t *smlen,
const uint8_t *sk);

#define crypto_sign_verify_internal DILITHIUM_NAMESPACE(verify_internal)
-int crypto_sign_verify_internal(const uint8_t *sig,
+OQS_API int crypto_sign_verify_internal(const uint8_t *sig,
size_t siglen,
const uint8_t *m,
size_t mlen,
diff --git a/ref/symmetric-shake.c b/ref/symmetric-shake.c
index 11ec09c..963f649 100644
--- a/ref/symmetric-shake.c
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SIGN_H
#define SIGN_H

#include <oqs/oqs.h>

#include <stddef.h>
#include <stdint.h>
#include "params.h"
Expand All @@ -11,7 +13,7 @@
int crypto_sign_keypair(uint8_t *pk, uint8_t *sk);

#define crypto_sign_signature_internal DILITHIUM_NAMESPACE(signature_internal)
int crypto_sign_signature_internal(uint8_t *sig,
OQS_API int crypto_sign_signature_internal(uint8_t *sig,
size_t *siglen,
const uint8_t *m,
size_t mlen,
Expand All @@ -33,7 +35,7 @@ int crypto_sign(uint8_t *sm, size_t *smlen,
const uint8_t *sk);

#define crypto_sign_verify_internal DILITHIUM_NAMESPACE(verify_internal)
int crypto_sign_verify_internal(const uint8_t *sig,
OQS_API int crypto_sign_verify_internal(const uint8_t *sig,
size_t siglen,
const uint8_t *m,
size_t mlen,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SIGN_H
#define SIGN_H

#include <oqs/oqs.h>

#include <stddef.h>
#include <stdint.h>
#include "params.h"
Expand All @@ -11,7 +13,7 @@
int crypto_sign_keypair(uint8_t *pk, uint8_t *sk);

#define crypto_sign_signature_internal DILITHIUM_NAMESPACE(signature_internal)
int crypto_sign_signature_internal(uint8_t *sig,
OQS_API int crypto_sign_signature_internal(uint8_t *sig,
size_t *siglen,
const uint8_t *m,
size_t mlen,
Expand All @@ -33,7 +35,7 @@ int crypto_sign(uint8_t *sm, size_t *smlen,
const uint8_t *sk);

#define crypto_sign_verify_internal DILITHIUM_NAMESPACE(verify_internal)
int crypto_sign_verify_internal(const uint8_t *sig,
OQS_API int crypto_sign_verify_internal(const uint8_t *sig,
size_t siglen,
const uint8_t *m,
size_t mlen,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SIGN_H
#define SIGN_H

#include <oqs/oqs.h>

#include <stddef.h>
#include <stdint.h>
#include "params.h"
Expand All @@ -11,7 +13,7 @@
int crypto_sign_keypair(uint8_t *pk, uint8_t *sk);

#define crypto_sign_signature_internal DILITHIUM_NAMESPACE(signature_internal)
int crypto_sign_signature_internal(uint8_t *sig,
OQS_API int crypto_sign_signature_internal(uint8_t *sig,
size_t *siglen,
const uint8_t *m,
size_t mlen,
Expand All @@ -33,7 +35,7 @@ int crypto_sign(uint8_t *sm, size_t *smlen,
const uint8_t *sk);

#define crypto_sign_verify_internal DILITHIUM_NAMESPACE(verify_internal)
int crypto_sign_verify_internal(const uint8_t *sig,
OQS_API int crypto_sign_verify_internal(const uint8_t *sig,
size_t siglen,
const uint8_t *m,
size_t mlen,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SIGN_H
#define SIGN_H

#include <oqs/oqs.h>

#include <stddef.h>
#include <stdint.h>
#include "params.h"
Expand All @@ -11,7 +13,7 @@
int crypto_sign_keypair(uint8_t *pk, uint8_t *sk);

#define crypto_sign_signature_internal DILITHIUM_NAMESPACE(signature_internal)
int crypto_sign_signature_internal(uint8_t *sig,
OQS_API int crypto_sign_signature_internal(uint8_t *sig,
size_t *siglen,
const uint8_t *m,
size_t mlen,
Expand All @@ -33,7 +35,7 @@ int crypto_sign(uint8_t *sm, size_t *smlen,
const uint8_t *sk);

#define crypto_sign_verify_internal DILITHIUM_NAMESPACE(verify_internal)
int crypto_sign_verify_internal(const uint8_t *sig,
OQS_API int crypto_sign_verify_internal(const uint8_t *sig,
size_t siglen,
const uint8_t *m,
size_t mlen,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SIGN_H
#define SIGN_H

#include <oqs/oqs.h>

#include <stddef.h>
#include <stdint.h>
#include "params.h"
Expand All @@ -11,7 +13,7 @@
int crypto_sign_keypair(uint8_t *pk, uint8_t *sk);

#define crypto_sign_signature_internal DILITHIUM_NAMESPACE(signature_internal)
int crypto_sign_signature_internal(uint8_t *sig,
OQS_API int crypto_sign_signature_internal(uint8_t *sig,
size_t *siglen,
const uint8_t *m,
size_t mlen,
Expand All @@ -33,7 +35,7 @@ int crypto_sign(uint8_t *sm, size_t *smlen,
const uint8_t *sk);

#define crypto_sign_verify_internal DILITHIUM_NAMESPACE(verify_internal)
int crypto_sign_verify_internal(const uint8_t *sig,
OQS_API int crypto_sign_verify_internal(const uint8_t *sig,
size_t siglen,
const uint8_t *m,
size_t mlen,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SIGN_H
#define SIGN_H

#include <oqs/oqs.h>

#include <stddef.h>
#include <stdint.h>
#include "params.h"
Expand All @@ -11,7 +13,7 @@
int crypto_sign_keypair(uint8_t *pk, uint8_t *sk);

#define crypto_sign_signature_internal DILITHIUM_NAMESPACE(signature_internal)
int crypto_sign_signature_internal(uint8_t *sig,
OQS_API int crypto_sign_signature_internal(uint8_t *sig,
size_t *siglen,
const uint8_t *m,
size_t mlen,
Expand All @@ -33,7 +35,7 @@ int crypto_sign(uint8_t *sm, size_t *smlen,
const uint8_t *sk);

#define crypto_sign_verify_internal DILITHIUM_NAMESPACE(verify_internal)
int crypto_sign_verify_internal(const uint8_t *sig,
OQS_API int crypto_sign_verify_internal(const uint8_t *sig,
size_t siglen,
const uint8_t *m,
size_t mlen,
Expand Down
7 changes: 5 additions & 2 deletions tests/test_acvp_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def test_acvp_vec_sig_keygen(sig_name):
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not needed on Windows")
@pytest.mark.parametrize('sig_name', helpers.available_sigs_by_name())
def test_acvp_vec_sig_gen_deterministic(sig_name):


if not(helpers.is_sig_enabled_by_name(sig_name)): pytest.skip('Not enabled')
if not(sig_name in fips_sig): pytest.skip("Not supported")

with open(os.path.join('tests', ml_dsa_sig), 'r') as fp:
Expand All @@ -155,7 +156,8 @@ def test_acvp_vec_sig_gen_deterministic(sig_name):
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not needed on Windows")
@pytest.mark.parametrize('sig_name', helpers.available_sigs_by_name())
def test_acvp_vec_sig_gen_randomized(sig_name):


if not(helpers.is_sig_enabled_by_name(sig_name)): pytest.skip('Not enabled')
if not(sig_name in fips_sig): pytest.skip("Not supported")

with open(os.path.join('tests', ml_dsa_sig), 'r') as fp:
Expand All @@ -182,6 +184,7 @@ def test_acvp_vec_sig_gen_randomized(sig_name):
@pytest.mark.parametrize('sig_name', helpers.available_sigs_by_name())
def test_acvp_vec_sig_ver(sig_name):

if not(helpers.is_sig_enabled_by_name(sig_name)): pytest.skip('Not enabled')
if not(sig_name in fips_sig): pytest.skip("Not supported")

with open(os.path.join('tests', ml_dsa_ver), 'r') as fp:
Expand Down
26 changes: 21 additions & 5 deletions tests/vectors_sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ static OQS_STATUS sig_kg_vector(const char *method_name,
return ret;
}

#if defined(OQS_ENABLE_SIG_ml_dsa_44) || defined(OQS_ENABLE_SIG_ml_dsa_65) || defined(OQS_ENABLE_SIG_ml_dsa_87)
static int sig_ver_vector(const char *method_name,
const uint8_t *sigVer_pk_bytes,
const uint8_t *sigVer_msg_bytes,
Expand Down Expand Up @@ -262,7 +263,7 @@ static int sig_ver_vector(const char *method_name,
fprintf(stderr, "[vectors_sig] %s ERROR: mlca_sig_verify_internal failed!\n", method_name);
goto err;
} else {
ret = 0;
ret = EXIT_SUCCESS;
}


Expand Down Expand Up @@ -355,6 +356,7 @@ static int sig_gen_vector(const char *method_name,
free(signature);
return ret;
}
#endif

int main(int argc, char **argv) {
OQS_STATUS rc = OQS_SUCCESS;
Expand Down Expand Up @@ -402,8 +404,8 @@ int main(int argc, char **argv) {
OQS_SIG *sig = OQS_SIG_new(alg_name);
if (sig == NULL) {
printf("[vectors_sig] %s was not enabled at compile-time.\n", alg_name);
rc = OQS_ERROR;
goto err;
rc = EXIT_FAILURE;
goto cleanup;
}

if (!strcmp(test_name, "keyGen")) {
Expand Down Expand Up @@ -487,7 +489,12 @@ int main(int argc, char **argv) {
hexStringToByteArray(sigGen_msg, sigGen_msg_bytes);
hexStringToByteArray(sigGen_sig, sigGen_sig_bytes);

#if defined(OQS_ENABLE_SIG_ml_dsa_44) || defined(OQS_ENABLE_SIG_ml_dsa_65) || defined(OQS_ENABLE_SIG_ml_dsa_87)
rc = sig_gen_vector(alg_name, prng_output_stream_bytes, sigGen_sk_bytes, sigGen_msg_bytes, msgLen, sigGen_sig_bytes, randomized);
#else
rc = EXIT_SUCCESS;
goto cleanup;
#endif

} else if (!strcmp(test_name, "sigVer")) {
sigVer_pk = argv[3];
Expand All @@ -500,7 +507,6 @@ int main(int argc, char **argv) {
strlen(sigVer_sig) != 2 * sig->length_signature ||
strlen(sigVer_pk) != 2 * sig->length_public_key ||
(sigVerPassed != 0 && sigVerPassed != 1)) {
rc = EXIT_FAILURE;
goto err;
}

Expand All @@ -514,14 +520,24 @@ int main(int argc, char **argv) {
hexStringToByteArray(sigVer_msg, sigVer_msg_bytes);
hexStringToByteArray(sigVer_sig, sigVer_sig_bytes);

#if defined(OQS_ENABLE_SIG_ml_dsa_44) || defined(OQS_ENABLE_SIG_ml_dsa_65) || defined(OQS_ENABLE_SIG_ml_dsa_87)
rc = sig_ver_vector(alg_name, sigVer_pk_bytes, sigVer_msg_bytes, msgLen, sigVer_sig_bytes, sigVerPassed);
#else
rc = EXIT_SUCCESS;
goto cleanup;
#endif

} else {
rc = EXIT_FAILURE;
printf("[vectors_sig] %s only keyGen/sigGen/sigVer supported!\n", alg_name);
goto err;
}
goto cleanup;

err:
rc = OQS_ERROR;
goto cleanup;

cleanup:
free(prng_output_stream_bytes);
free(kg_pk_bytes);
free(kg_sk_bytes);
Expand Down

0 comments on commit 1f89068

Please sign in to comment.