Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve static build testing #367

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions test/oqs_test_endecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,13 @@ int main(int argc, char *argv[])
modulename = argv[1];
configfile = argv[2];

load_oqs_provider(libctx, modulename, configfile);
oqsprov = load_oqs_provider(libctx, modulename, configfile);

keyctx = OSSL_LIB_CTX_new();

load_oqs_provider(keyctx, modulename, configfile);

dfltprov = OSSL_PROVIDER_load(keyctx, "default");
keyprov = OSSL_PROVIDER_load(keyctx, modulename);
oqsprov = OSSL_PROVIDER_load(libctx, modulename);

keyprov = load_oqs_provider(keyctx, modulename, configfile);

algs = OSSL_PROVIDER_query_operation(oqsprov, OSSL_OP_SIGNATURE,
&query_nocache);
Expand All @@ -277,10 +275,11 @@ int main(int argc, char *argv[])
}
#endif /* OQS_KEM_ENCODERS */

OSSL_PROVIDER_unload(dfltprov);
OSSL_PROVIDER_unload(keyprov);
if (OPENSSL_VERSION_PREREQ(3, 1))
OSSL_PROVIDER_unload(oqsprov); // avoid crash in 3.0.x
if (OPENSSL_VERSION_PREREQ(3, 1)) { // avoid crash in 3.0.x
OSSL_PROVIDER_unload(dfltprov);
OSSL_PROVIDER_unload(keyprov);
OSSL_PROVIDER_unload(oqsprov);
}
OSSL_LIB_CTX_free(libctx);
OSSL_LIB_CTX_free(keyctx);

Expand Down
5 changes: 4 additions & 1 deletion test/oqs_test_groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ int main(int argc, char *argv[])
{
size_t i;
int errcnt = 0, test = 0;
OSSL_PROVIDER *oqsprov = NULL;

T((libctx = OSSL_LIB_CTX_new()) != NULL);
T(argc == 4);
Expand All @@ -142,14 +143,16 @@ int main(int argc, char *argv[])
T(cert = test_mk_file_path(certsdir, "servercert.pem"));
T(privkey = test_mk_file_path(certsdir, "serverkey.pem"));

load_oqs_provider(libctx, modulename, configfile);
oqsprov = load_oqs_provider(libctx, modulename, configfile);

T(OSSL_PROVIDER_available(libctx, "default"));

T(OSSL_PROVIDER_do_all(libctx, test_provider_groups, &errcnt));

OPENSSL_free(cert);
OPENSSL_free(privkey);
if (OPENSSL_VERSION_PREREQ(3, 1))
OSSL_PROVIDER_unload(oqsprov); // avoid crash in 3.0.x
OSSL_LIB_CTX_free(libctx);
TEST_ASSERT(errcnt == 0)
return !test;
Expand Down
7 changes: 3 additions & 4 deletions test/oqs_test_kems.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ int main(int argc, char *argv[])
modulename = argv[1];
configfile = argv[2];

load_oqs_provider(libctx, modulename, configfile);

oqsprov = OSSL_PROVIDER_load(libctx, modulename);
oqsprov = load_oqs_provider(libctx, modulename, configfile);

kemalgs
= OSSL_PROVIDER_query_operation(oqsprov, OSSL_OP_KEM, &query_nocache);
Expand All @@ -107,8 +105,9 @@ int main(int argc, char *argv[])
}
}

if (OPENSSL_VERSION_PREREQ(3, 1))
OSSL_PROVIDER_unload(oqsprov); // avoid crash in 3.0.x
OSSL_LIB_CTX_free(libctx);

TEST_ASSERT(errcnt == 0)
return !test;
}
6 changes: 3 additions & 3 deletions test/oqs_test_signatures.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ int main(int argc, char *argv[])
modulename = argv[1];
configfile = argv[2];

load_oqs_provider(libctx, modulename, configfile);

oqsprov = OSSL_PROVIDER_load(libctx, modulename);
oqsprov = load_oqs_provider(libctx, modulename, configfile);

sigalgs = OSSL_PROVIDER_query_operation(oqsprov, OSSL_OP_SIGNATURE,
&query_nocache);
Expand All @@ -124,6 +122,8 @@ int main(int argc, char *argv[])
}
}

if (OPENSSL_VERSION_PREREQ(3, 1))
OSSL_PROVIDER_unload(oqsprov); // avoid crash in 3.0.x
OSSL_LIB_CTX_free(libctx);

TEST_ASSERT(errcnt == 0)
Expand Down
6 changes: 5 additions & 1 deletion test/oqs_test_tlssig.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ int main(int argc, char *argv[])
{
size_t i;
int errcnt = 0, test = 0;
OSSL_PROVIDER *oqsprov = NULL;

#ifndef OPENSSL_NO_TRACE
fprintf(stderr,
Expand All @@ -163,9 +164,10 @@ int main(int argc, char *argv[])
configfile = argv[2];
certsdir = argv[3];

load_oqs_provider(libctx, modulename, configfile);
oqsprov = load_oqs_provider(libctx, modulename, configfile);

T(OSSL_PROVIDER_available(libctx, "default"));
T(OSSL_PROVIDER_available(libctx, modulename));

#ifdef OSSL_CAPABILITY_TLS_SIGALG_NAME
// crashes: EVP_SIGNATURE_do_all_provided(libctx, test_oqs_sigs, &errcnt);
Expand All @@ -176,6 +178,8 @@ int main(int argc, char *argv[])
"TLS-SIG handshake test not enabled. Update OpenSSL to more current version.\n");
#endif

if (OPENSSL_VERSION_PREREQ(3, 1))
OSSL_PROVIDER_unload(oqsprov); // avoid crash in 3.0.x
OSSL_LIB_CTX_free(libctx);
TEST_ASSERT(errcnt == 0)
return !test;
Expand Down
10 changes: 6 additions & 4 deletions test/test_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,27 @@ int alg_is_enabled(const char *algname)
#ifndef OQS_PROVIDER_STATIC

/* Loads the oqs-provider from a shared module (.so). */
void load_oqs_provider(OSSL_LIB_CTX *libctx, const char *modulename,
const char *configfile)
OSSL_PROVIDER *load_oqs_provider(OSSL_LIB_CTX *libctx, const char *modulename,
const char *configfile)
{
T(OSSL_LIB_CTX_load_config(libctx, configfile));
T(OSSL_PROVIDER_available(libctx, modulename));
return OSSL_PROVIDER_load(libctx, modulename);
}

#else

extern OSSL_provider_init_fn OQS_PROVIDER_ENTRYPOINT_NAME;

/* Loads the statically linked oqs-provider. */
void load_oqs_provider(OSSL_LIB_CTX *libctx, const char *modulename,
const char *configfile)
OSSL_PROVIDER *load_oqs_provider(OSSL_LIB_CTX *libctx, const char *modulename,
const char *configfile)
{
(void)configfile;
T(OSSL_PROVIDER_add_builtin(libctx, modulename,
OQS_PROVIDER_ENTRYPOINT_NAME));
T(OSSL_PROVIDER_load(libctx, "default"));
return OSSL_PROVIDER_load(libctx, modulename);
}

#endif // ifndef OQS_PROVIDER_STATIC
4 changes: 2 additions & 2 deletions test/test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ void hexdump(const void *ptr, size_t len);
int alg_is_enabled(const char *algname);

/* Loads the oqs-provider. */
void load_oqs_provider(OSSL_LIB_CTX *libctx, const char *modulename,
const char *configfile);
OSSL_PROVIDER *load_oqs_provider(OSSL_LIB_CTX *libctx, const char *modulename,
const char *configfile);
Loading