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

Adding version-conditional context string support #583

Merged
merged 9 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ Also not fully supported in 3.0.2 is performance testing as per the openssl

These versions have full support for all TLS1.3 operations using PQ algorithms
when deploying `oqsprovider`, particularly with regard to the use of signature
algorithms.
algorithms. This also includes support for the "OSSL_SIGNATURE_PARAM_CONTEXT_STRING"
parameter that had not been supported before and for which limited support in
single PQ algorithms is available since `liboqs` version 0.12.

## 3.4 and greater

Expand Down
35 changes: 35 additions & 0 deletions oqsprov/oqs_sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ ASN1_NDEF_SEQUENCE(CompositeSignature) =
size_t mdsize;
// for collecting data if no MD is active:
unsigned char *mddata;
void *context_string;
size_t context_string_length;
int operation;
} PROV_OQSSIG_CTX;

Expand Down Expand Up @@ -517,9 +519,19 @@ static int oqs_sig_sign(void *vpoqs_sigctx, unsigned char *sig, size_t *siglen,
oqs_sig_len = oqsxkey->oqsx_provider_ctx.oqsx_qs_ctx.sig
->length_signature;
buf = OPENSSL_malloc(oqs_sig_len);
#if !defined OQS_VERSION_MINOR || \
(OQS_VERSION_MAJOR == 0 && OQS_VERSION_MINOR < 12)
if (OQS_SIG_sign(oqs_key, buf, &oqs_sig_len,
(const unsigned char *)final_tbs, final_tbslen,
oqsxkey->comp_privkey[i]) != OQS_SUCCESS) {
#else
if (OQS_SIG_sign_with_ctx_str(
oqs_key, buf, &oqs_sig_len,
(const unsigned char *)final_tbs, final_tbslen,
poqs_sigctx->context_string,
poqs_sigctx->context_string_length,
oqsxkey->comp_privkey[i]) != OQS_SUCCESS) {
#endif
ERR_raise(ERR_LIB_USER, OQSPROV_R_SIGNING_FAILED);
CompositeSignature_free(compsig);
OPENSSL_free(final_tbs);
Expand Down Expand Up @@ -666,7 +678,15 @@ static int oqs_sig_sign(void *vpoqs_sigctx, unsigned char *sig, size_t *siglen,

CompositeSignature_free(compsig);
OPENSSL_free(final_tbs);
#if !defined OQS_VERSION_MINOR || \
(OQS_VERSION_MAJOR == 0 && OQS_VERSION_MINOR < 12)
} else if (OQS_SIG_sign(oqs_key, sig + index, &oqs_sig_len, tbs, tbslen,
#else
} else if (OQS_SIG_sign_with_ctx_str(
oqs_key, sig + index, &oqs_sig_len, tbs, tbslen,
poqs_sigctx->context_string,
poqs_sigctx->context_string_length,
#endif
oqsxkey->comp_privkey[oqsxkey->numkeys - 1]) !=
OQS_SUCCESS) {
ERR_raise(ERR_LIB_USER, OQSPROV_R_SIGNING_FAILED);
Expand Down Expand Up @@ -1176,6 +1196,7 @@ static void oqs_sig_freectx(void *vpoqs_sigctx) {
OPENSSL_free(ctx->aid);
ctx->aid = NULL;
ctx->aid_len = 0;
OPENSSL_free(ctx->context_string);
SWilson4 marked this conversation as resolved.
Show resolved Hide resolved
OPENSSL_free(ctx);
}

Expand Down Expand Up @@ -1299,6 +1320,17 @@ static int oqs_sig_set_ctx_params(void *vpoqs_sigctx,
if (!oqs_sig_setup_md(poqs_sigctx, mdname, mdprops))
return 0;
}
#if (OPENSSL_VERSION_PREREQ(3, 2))
p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_CONTEXT_STRING);
if (p != NULL) {
if (!OSSL_PARAM_get_octet_string(
p, &poqs_sigctx->context_string, 0,
&(poqs_sigctx->context_string_length))) {
SWilson4 marked this conversation as resolved.
Show resolved Hide resolved
poqs_sigctx->context_string_length = 0;
return 0;
}
}
#endif

// not passing in parameters we can act on is no error
return 1;
Expand All @@ -1307,6 +1339,9 @@ static int oqs_sig_set_ctx_params(void *vpoqs_sigctx,
static const OSSL_PARAM known_settable_ctx_params[] = {
OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PROPERTIES, NULL, 0),
#if (OPENSSL_VERSION_PREREQ(3, 2))
OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_CONTEXT_STRING, NULL, 0),
#endif
OSSL_PARAM_END};

static const OSSL_PARAM *
Expand Down