Skip to content

Commit

Permalink
fixup coding style
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Baentsch <[email protected]>
  • Loading branch information
baentsch committed Feb 19, 2025
1 parent c8dd604 commit 67b300f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion oqsprov/oqs_prov.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#define OQS_HYBRID_PKEY_PARAM_PQ_PUB_KEY "hybrid_pq_" OSSL_PKEY_PARAM_PUB_KEY
#define OQS_HYBRID_PKEY_PARAM_PQ_PRIV_KEY "hybrid_pq_" OSSL_PKEY_PARAM_PRIV_KEY

STACK_OF(OPENSSL_STRING) *oqsprov_get_rt_disabled_algs();
STACK_OF(OPENSSL_STRING) * oqsprov_get_rt_disabled_algs();

/* Extras for OQS extension */

Expand Down
61 changes: 34 additions & 27 deletions oqsprov/oqsprov.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
printf(a, b, c)
#endif // NDEBUG

static STACK_OF(OPENSSL_STRING) *rt_disabled_algs;
STACK_OF(OPENSSL_STRING) *oqsprov_get_rt_disabled_algs() {
static STACK_OF(OPENSSL_STRING) * rt_disabled_algs;
STACK_OF(OPENSSL_STRING) * oqsprov_get_rt_disabled_algs() {
return rt_disabled_algs;
}

Expand Down Expand Up @@ -946,25 +946,28 @@ static int oqsprovider_get_params(void *provctx, OSSL_PARAM params[]) {
int cnt_rt_disabled(const OSSL_ALGORITHM orig[], int len) {
int dcnt = 0;

for (int i = 0; i < len-1; i++)
if (sk_OPENSSL_STRING_find(rt_disabled_algs, (char *)orig[i].algorithm_names) >= 0)
dcnt++;
for (int i = 0; i < len - 1; i++)
if (sk_OPENSSL_STRING_find(rt_disabled_algs,
(char *)orig[i].algorithm_names) >= 0)
dcnt++;
return dcnt;
}

#define FILTERED_ALGS(algs) \
d_algs = cnt_rt_disabled(algs, OSSL_NELEM(algs)); \
if (algs##_rt == NULL) { \
algs##_rt = OPENSSL_malloc(sizeof(OSSL_ALGORITHM) * OSSL_NELEM(algs)-d_algs); \
n_cnt = 0; \
for(int i=0; i<OSSL_NELEM(algs); i++) { \
if (sk_OPENSSL_STRING_find(rt_disabled_algs, (char *)algs[i].algorithm_names) < 0) { \
*(algs##_rt+n_cnt) = algs[i]; \
n_cnt++; \
} \
} \
} \
return algs##_rt
#define FILTERED_ALGS(algs) \
d_algs = cnt_rt_disabled(algs, OSSL_NELEM(algs)); \
if (algs##_rt == NULL) { \
algs##_rt = OPENSSL_malloc(sizeof(OSSL_ALGORITHM) * OSSL_NELEM(algs) - \
d_algs); \
n_cnt = 0; \
for (int i = 0; i < OSSL_NELEM(algs); i++) { \
if (sk_OPENSSL_STRING_find(rt_disabled_algs, \
(char *)algs[i].algorithm_names) < 0) { \
*(algs##_rt + n_cnt) = algs[i]; \
n_cnt++; \
} \
} \
} \
return algs##_rt

static const OSSL_ALGORITHM *oqsprovider_query(void *provctx, int operation_id,
int *no_cache) {
Expand Down Expand Up @@ -1012,8 +1015,7 @@ static const OSSL_DISPATCH oqsprovider_dispatch_table[] = {
#define OQS_PROVIDER_ENTRYPOINT_NAME OSSL_provider_init
#endif // ifdef OQS_PROVIDER_STATIC

static int sk_strcmp(const char * const *a, const char * const *b)
{
static int sk_strcmp(const char *const *a, const char *const *b) {
return strcmp(*a, *b);
}

Expand Down Expand Up @@ -1131,22 +1133,25 @@ int OQS_PROVIDER_ENTRYPOINT_NAME(const OSSL_CORE_HANDLE *handle,
ERR_raise(ERR_LIB_USER, OQSPROV_R_OBJ_CREATE_ERR);
goto end_init;
}
end_for:
end_for:
if (!id_ok) {
sk_OPENSSL_STRING_push(rt_disabled_algs, (char *)(oqs_oid_alg_list[i + 1]));
sk_OPENSSL_STRING_push(rt_disabled_algs,
(char *)(oqs_oid_alg_list[i + 1]));
}
}
}

// ML-KEM implementation in OpenSSL 3.5 is _much_ more developed than this code
// ML-KEM implementation in OpenSSL 3.5 is _much_ more developed than this
// code
if (strcmp("3.5.0", ossl_versionp) <= 0) {
sk_OPENSSL_STRING_push(rt_disabled_algs, "mlkem512");
sk_OPENSSL_STRING_push(rt_disabled_algs, "mlkem768");
sk_OPENSSL_STRING_push(rt_disabled_algs, "X25519MLKEM768");
sk_OPENSSL_STRING_push(rt_disabled_algs, "SecP256r1MLKEM768");
sk_OPENSSL_STRING_push(rt_disabled_algs, "SecP384r1MLKEM1024");
sk_OPENSSL_STRING_push(rt_disabled_algs, "mlkem1024");
// need to disable these as per https://github.com/open-quantum-safe/oqs-provider/discussions/610#discussioncomment-12246359
// need to disable these as per
// https://github.com/open-quantum-safe/oqs-provider/discussions/610#discussioncomment-12246359
sk_OPENSSL_STRING_push(rt_disabled_algs, "mldsa44_pss2048");
sk_OPENSSL_STRING_push(rt_disabled_algs, "mldsa44_rsa2048");
sk_OPENSSL_STRING_push(rt_disabled_algs, "mldsa44_ed25519");
Expand All @@ -1164,9 +1169,11 @@ int OQS_PROVIDER_ENTRYPOINT_NAME(const OSSL_CORE_HANDLE *handle,

/*
// output disabled algs:
printf("disabled algs: %p (cnt: %d)\n", rt_disabled_algs, sk_OPENSSL_STRING_num(rt_disabled_algs));
for (int i = 0; i < sk_OPENSSL_STRING_num(rt_disabled_algs); ++i) {
printf("Disabled alg #%d: %s in OpenSSL version %s\n", i, sk_OPENSSL_STRING_value(rt_disabled_algs, i), ossl_versionp);
printf("disabled algs: %p (cnt: %d)\n", rt_disabled_algs,
sk_OPENSSL_STRING_num(rt_disabled_algs)); for (int i = 0; i <
sk_OPENSSL_STRING_num(rt_disabled_algs); ++i) { printf("Disabled alg #%d: %s
in OpenSSL version %s\n", i, sk_OPENSSL_STRING_value(rt_disabled_algs, i),
ossl_versionp);
}
*/

Expand Down
8 changes: 6 additions & 2 deletions oqsprov/oqsprov_capabilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,9 @@ static int oqs_group_capability(OSSL_CALLBACK *cb, void *arg) {

for (i = 0; i < OSSL_NELEM(oqs_param_group_list); i++) {
// do not register algorithms disabled at runtime
if (sk_OPENSSL_STRING_find(oqsprov_get_rt_disabled_algs(), (char *)oqs_param_group_list[i][2].data) < 0) {
if (sk_OPENSSL_STRING_find(oqsprov_get_rt_disabled_algs(),
(char *)oqs_param_group_list[i][2].data) <
0) {
if (!cb(oqs_param_group_list[i], arg))
return 0;
}
Expand Down Expand Up @@ -697,7 +699,9 @@ static int oqs_sigalg_capability(OSSL_CALLBACK *cb, void *arg) {
assert(OSSL_NELEM(oqs_param_sigalg_list) <= OSSL_NELEM(oqs_sigalg_list));
for (i = 0; i < OSSL_NELEM(oqs_param_sigalg_list); i++) {
// do not register algorithms disabled at runtime
if (sk_OPENSSL_STRING_find(oqsprov_get_rt_disabled_algs(), (char *)oqs_param_sigalg_list[i][1].data) < 0) {
if (sk_OPENSSL_STRING_find(oqsprov_get_rt_disabled_algs(),
(char *)oqs_param_sigalg_list[i][1].data) <
0) {
if (!cb(oqs_param_sigalg_list[i], arg))
return 0;
}
Expand Down

0 comments on commit 67b300f

Please sign in to comment.