From ba1201483ef2b9910e07175091e01d5009de8f77 Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Wed, 29 Oct 2025 13:15:19 +0100 Subject: [PATCH 1/6] evp_fetch: factor out usage printing Signed-off-by: Eugene Syromiatnikov --- source/evp_fetch.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/source/evp_fetch.c b/source/evp_fetch.c index 70b35b76..0c8a9e7b 100644 --- a/source/evp_fetch.c +++ b/source/evp_fetch.c @@ -284,6 +284,20 @@ void do_fetch(size_t num) } while (time.t < max_time.t); } +static void +usage(const char *progname) +{ +#ifdef OPENSSL_DO_PQ + printf("Usage: %s [-t] [-q] threadcount\n", progname); +#else + printf("Usage: %s [-t] threadcount\n", progname); +#endif + printf("-t - terse output\n"); +#ifdef OPENSSL_DO_PQ + printf("-q - include post-quantum algorithms\n"); +#endif +} + int main(int argc, char *argv[]) { OSSL_TIME duration; @@ -311,15 +325,7 @@ int main(int argc, char *argv[]) break; #endif default: -#ifdef OPENSSL_DO_PQ - printf("Usage: %s [-t] [-q] threadcount\n", basename(argv[0])); -#else - printf("Usage: %s [-t] threadcount\n", basename(argv[0])); -#endif - printf("-t - terse output\n"); -#ifdef OPENSSL_DO_PQ - printf("-q - include post-quantum algorithms\n"); -#endif + usage(basename(argv[0])); return EXIT_FAILURE; } } From 76b6fd89a501dca55790b70ab5a681434778bb14 Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Wed, 29 Oct 2025 13:41:29 +0100 Subject: [PATCH 2/6] evp_fetch: reduce the amount of ifdefery for handling PQ Signed-off-by: Eugene Syromiatnikov --- source/evp_fetch.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/source/evp_fetch.c b/source/evp_fetch.c index 0c8a9e7b..1fed1bf6 100644 --- a/source/evp_fetch.c +++ b/source/evp_fetch.c @@ -29,6 +29,13 @@ #if OPENSSL_VERSION_MAJOR > 3 || \ (OPENSSL_VERSION_MAJOR == 3 && OPENSSL_VERSION_MINOR >= 5) # define OPENSSL_DO_PQ +# define PQ_GETOPT "q" +# define PQ_USAGE_OPT " [-q]" +# define PQ_USAGE_DESC "-q - include post-quantum algorithms\n" +#else +# define PQ_GETOPT "" +# define PQ_USAGE_OPT "" +# define PQ_USAGE_DESC "" #endif #define RUN_TIME 5 @@ -287,15 +294,10 @@ void do_fetch(size_t num) static void usage(const char *progname) { -#ifdef OPENSSL_DO_PQ - printf("Usage: %s [-t] [-q] threadcount\n", progname); -#else - printf("Usage: %s [-t] threadcount\n", progname); -#endif - printf("-t - terse output\n"); -#ifdef OPENSSL_DO_PQ - printf("-q - include post-quantum algorithms\n"); -#endif + printf("Usage: %s [-t]" PQ_USAGE_OPT " threadcount\n" + "-t - terse output\n" + PQ_USAGE_DESC, + progname); } int main(int argc, char *argv[]) @@ -310,11 +312,7 @@ int main(int argc, char *argv[]) char *fetch_type = getenv("EVP_FETCH_TYPE"); int opt; -#ifdef OPENSSL_DO_PQ - while ((opt = getopt(argc, argv, "tq")) != -1) { -#else - while ((opt = getopt(argc, argv, "t")) != -1) { -#endif + while ((opt = getopt(argc, argv, "t" PQ_GETOPT)) != -1) { switch (opt) { case 't': terse = 1; From 0de51ca4792856e7bde40ba20e5e47d269560abc Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Wed, 29 Oct 2025 14:10:42 +0100 Subject: [PATCH 3/6] evp_fetch: define PQ fetch algorithms only when they are available in the library Signed-off-by: Eugene Syromiatnikov --- source/evp_fetch.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/evp_fetch.c b/source/evp_fetch.c index 1fed1bf6..41479477 100644 --- a/source/evp_fetch.c +++ b/source/evp_fetch.c @@ -44,19 +44,19 @@ * Update the constant numbers below if you add or remove * post-quantum algorithms from the fetch list. */ -#ifndef OPENSSL_NO_ML_KEM +#if defined(OPENSSL_DO_PQ) && !defined(OPENSSL_NO_ML_KEM) #define FETCH_ENTRY_ML_KEM_N 3 #else #define FETCH_ENTRY_ML_KEM_N 0 #endif -#ifndef OPENSSL_NO_ML_DSA +#if defined(OPENSSL_DO_PQ) && !defined(OPENSSL_NO_ML_DSA) #define FETCH_ENTRY_ML_DSA_N 3 #else #define FETCH_ENTRY_ML_DSA_N 0 #endif -#ifndef OPENSSL_NO_SLH_DSA +#if defined(OPENSSL_DO_PQ) && !defined(OPENSSL_NO_SLH_DSA) #define FETCH_ENTRY_SLH_DSA_N 6 #else #define FETCH_ENTRY_SLH_DSA_N 0 @@ -144,17 +144,17 @@ static struct fetch_data_entry fetch_entries[] = { #ifndef OPENSSL_NO_POLY1305 {FETCH_MAC, OSSL_MAC_NAME_POLY1305, NULL}, #endif -#ifndef OPENSSL_NO_ML_KEM +#if defined(OPENSSL_DO_PQ) && !defined(OPENSSL_NO_ML_KEM) {FETCH_PQ_KEM, "ML-KEM-512", NULL}, {FETCH_PQ_KEM, "ML-KEM-768", NULL}, {FETCH_PQ_KEM, "ML-KEM-1024", NULL}, #endif -#ifndef OPENSSL_NO_ML_DSA +#if defined(OPENSSL_DO_PQ) && !defined(OPENSSL_NO_ML_DSA) {FETCH_PQ_SIGNATURE, "ML-DSA-44", NULL}, {FETCH_PQ_SIGNATURE, "ML-DSA-65", NULL}, {FETCH_PQ_SIGNATURE, "ML-DSA-87", NULL}, #endif -#ifndef OPENSSL_NO_SLH_DSA +#if defined(OPENSSL_DO_PQ) && !defined(OPENSSL_NO_SLH_DSA) {FETCH_PQ_SIGNATURE, "SLH-DSA-SHA2-128s", NULL}, {FETCH_PQ_SIGNATURE, "SLH-DSA-SHA2-192s", NULL}, {FETCH_PQ_SIGNATURE, "SLH-DSA-SHA2-256s", NULL}, From c37d0a7f02b82ef7820e61057277508fdfbdb067 Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Wed, 29 Oct 2025 14:11:12 +0100 Subject: [PATCH 4/6] evp_fetch: simplify type_map array and constify it Signed-off-by: Eugene Syromiatnikov --- source/evp_fetch.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/source/evp_fetch.c b/source/evp_fetch.c index 41479477..c4ecea9a 100644 --- a/source/evp_fetch.c +++ b/source/evp_fetch.c @@ -90,19 +90,14 @@ typedef enum { FETCH_END } fetch_type_t; -struct fetch_type_map { - char *name; - fetch_type_t id; -}; - -struct fetch_type_map type_map[] = { - { "MD" , FETCH_MD }, - { "CIPHER" , FETCH_CIPHER }, - { "KDF" , FETCH_KDF }, - { "MAC" , FETCH_MAC }, - { "RAND" , FETCH_RAND }, - { "KEM" , FETCH_PQ_KEM }, - { "SIGNATURE" , FETCH_PQ_SIGNATURE }, +static const char *type_map[] = { + [FETCH_MD] = "MD", + [FETCH_CIPHER] = "CIPHER", + [FETCH_KDF] = "KDF", + [FETCH_MAC] = "MAC", + [FETCH_RAND] = "RAND", + [FETCH_PQ_KEM] = "KEM", + [FETCH_PQ_SIGNATURE] = "SIGNATURE", }; fetch_type_t exclusive_fetch_type = FETCH_END; @@ -338,8 +333,8 @@ int main(int argc, char *argv[]) *exclusive_fetch_alg = '\0'; exclusive_fetch_alg++; for (i = 0; i < ARRAY_SIZE(type_map); i++) { - if (!strcmp(fetch_type, type_map[i].name)) { - exclusive_fetch_type = type_map[i].id; + if (type_map[i] != NULL && !strcmp(fetch_type, type_map[i])) { + exclusive_fetch_type = i; break; } } From 1d794abdabbc792b5193aa5efb44da4e0ac793f8 Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Wed, 29 Oct 2025 14:11:29 +0100 Subject: [PATCH 5/6] evp_fetch: constify fetch_entries Signed-off-by: Eugene Syromiatnikov --- source/evp_fetch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/evp_fetch.c b/source/evp_fetch.c index c4ecea9a..9766ee81 100644 --- a/source/evp_fetch.c +++ b/source/evp_fetch.c @@ -113,7 +113,7 @@ struct fetch_data_entry { * The post quantum algorithms must be the last entries in the * list, so we can easily skip them if we don't want them. */ -static struct fetch_data_entry fetch_entries[] = { +static const struct fetch_data_entry fetch_entries[] = { {FETCH_MD, OSSL_DIGEST_NAME_SHA2_224, NULL}, {FETCH_MD, OSSL_DIGEST_NAME_SHA2_256, NULL}, {FETCH_MD, OSSL_DIGEST_NAME_SHA3_224, NULL}, From 4ab8e0eb8da152151fef5f895762c2ba5e02c822 Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Wed, 29 Oct 2025 14:12:04 +0100 Subject: [PATCH 6/6] evp_fetch: add an option to specify the algorithm to fetch in addition to the envvar Signed-off-by: Eugene Syromiatnikov --- source/evp_fetch.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/source/evp_fetch.c b/source/evp_fetch.c index 9766ee81..ab8ed784 100644 --- a/source/evp_fetch.c +++ b/source/evp_fetch.c @@ -289,10 +289,22 @@ void do_fetch(size_t num) static void usage(const char *progname) { - printf("Usage: %s [-t]" PQ_USAGE_OPT " threadcount\n" + printf("Usage: %s [-t] [-f TYPE:ALGORITHM]" PQ_USAGE_OPT " threadcount\n" "-t - terse output\n" - PQ_USAGE_DESC, + "-f - fetch only the specified algorithm\n" + PQ_USAGE_DESC + "\nEnvironment variables:\n" + " EVP_FETCH_TYPE - if no -f option is provided, fetch only\n" + " the specified TYPE:ALGORITHM\n", progname); + + printf("\nAvailable TYPE:ALGORITHM combinations:\n"); + for (size_t i = 0; i < ARRAY_SIZE(fetch_entries); i++) { + const fetch_type_t ft = fetch_entries[i].ftype; + + if (ft >= 0 && ft < ARRAY_SIZE(type_map) && type_map[ft] != NULL) + printf(" %s:%s\n", type_map[ft], fetch_entries[i].alg); + } } int main(int argc, char *argv[]) @@ -307,11 +319,14 @@ int main(int argc, char *argv[]) char *fetch_type = getenv("EVP_FETCH_TYPE"); int opt; - while ((opt = getopt(argc, argv, "t" PQ_GETOPT)) != -1) { + while ((opt = getopt(argc, argv, "tf:" PQ_GETOPT)) != -1) { switch (opt) { case 't': terse = 1; break; + case 'f': + fetch_type = optarg; + break; #ifdef OPENSSL_DO_PQ case 'q': pq = 1;