Skip to content

Commit

Permalink
Conditional fetch of mlkem768 KEX
Browse files Browse the repository at this point in the history
  • Loading branch information
beldmit committed Jan 17, 2025
1 parent 12b46ca commit 1abc7f0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions kex-names.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ static const struct kexalg kexalgs[] = {
{ NULL, 0, -1, -1},
};

static int is_mlkem768_available()
{
static int is_fetched = -1;

if (is_fetched == -1) {
EVP_KEM *mlkem768 = EVP_KEM_fetch(NULL, "mlkem768", NULL);
is_fetched = mlkem768 != NULL ? 1 : 0;
EVP_KEM_free(mlkem768);
}

return is_fetched;
}

char *
kex_alg_list(char sep)
{
Expand All @@ -98,6 +111,9 @@ kex_alg_list(char sep)
const struct kexalg *k;

for (k = kexalgs; k->name != NULL; k++) {
if (strcmp(k->name, KEX_MLKEM768X25519_SHA256) == 0
&& !is_mlkem768_available())
continue;
if (ret != NULL)
ret[rlen++] = sep;
nlen = strlen(k->name);
Expand All @@ -117,6 +133,10 @@ kex_alg_by_name(const char *name)
{
const struct kexalg *k;

if (strcmp(name, KEX_MLKEM768X25519_SHA256) == 0
&& !is_mlkem768_available())
return NULL;

for (k = kexalgs; k->name != NULL; k++) {
if (strcmp(k->name, name) == 0)
return k;
Expand Down

0 comments on commit 1abc7f0

Please sign in to comment.