From c301b66aa68f9e1b65e31518c38fe0ad2a65ab3b Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Wed, 11 Feb 2026 10:58:21 +0100 Subject: [PATCH 1/5] evp_cipher: add freeze option $ ./build/evp_cipher -o evp_isolated -a AES-128-CBC 64 Average time per encryption: 22.675682us $ ./build/evp_cipher -o evp_isolated -a AES-128-CBC 64 -f Average time per encryption: 2.371467us Signed-off-by: Nikola Pajkovsky --- README.md | 3 ++- source/evp_cipher.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1df56db..44abefc 100644 --- a/README.md +++ b/README.md @@ -248,9 +248,10 @@ Two modes of operation: - evp_shared (default): Use EVP API and allow shared data between threads ``` -Usage: evp_cipher [-h] [-t] [-o operation] [-u update-times] [-a algorithm] thread-count +Usage: evp_cipher [-h] [-t] [-f] [-o operation] [-u update-times] [-a algorithm] thread-count -h - print this help output -t - terse output +-f - freeze default context (available only with openssl >= 4.x.x) -o operation - mode of operation. One of [evp_isolated, evp_shared] (default: evp_shared) -u update-times - times to update (default: 1) -a algorithm - One of: [AES-128-CBC, AES-256-CBC] (default: AES-128-CBC) diff --git a/source/evp_cipher.c b/source/evp_cipher.c index 52427fb..a128b5d 100644 --- a/source/evp_cipher.c +++ b/source/evp_cipher.c @@ -14,6 +14,7 @@ #define OPENSSL_SUPPRESS_DEPRECATED +#include "config.h" #include #include #ifndef _WIN32 @@ -121,9 +122,16 @@ static void do_cipher_shared(size_t num) static void print_help(FILE *file) { +#ifdef HAVE_OSSL_LIB_CTX_FREEZE + fprintf(file, "Usage: evp_cipher [-h] [-f] [-t] [-o operation] [-u update-times] [-a algorithm] [-V] thread-count\n"); +#else fprintf(file, "Usage: evp_cipher [-h] [-t] [-o operation] [-u update-times] [-a algorithm] [-V] thread-count\n"); +#endif fprintf(file, "-h - print this help output\n"); fprintf(file, "-t - terse output\n"); +#ifdef HAVE_OSSL_LIB_CTX_FREEZE + fprintf(file, "-f - freeze default context\n"); +#endif fprintf(file, "-o operation - mode of operation. One of [evp_isolated, evp_shared] (default: evp_shared)\n"); fprintf(file, "-u update-times - times to update (default: 1)\n"); fprintf(file, "-a algorithm - One of: [AES-128-CBC, AES-256-CBC] (default: AES-128-CBC)\n"); @@ -139,9 +147,19 @@ int main(int argc, char *argv[]) int terse = 0, operation = EVP_SHARED; int j, opt, rc = EXIT_FAILURE; int key_len, iv_len; - - while ((opt = getopt(argc, argv, "Vhto:u:a:")) != -1) { - switch (opt) { + char *getopt_options = "Vhto:u:a:"; +#ifdef HAVE_OSSL_LIB_CTX_FREEZE + int freeze = 0; + getopt_options = "Vhto:u:a:f"; +#endif + + while ((opt = getopt(argc, argv, getopt_options)) != -1) { +#ifdef HAVE_OSSL_LIB_CTX_FREEZE + switch (opt) { + case 'f': + freeze = 1; + break; +#endif case 't': terse = 1; break; @@ -228,6 +246,15 @@ int main(int argc, char *argv[]) max_time = ossl_time_add(ossl_time_now(), ossl_seconds2time(RUN_TIME)); +#ifdef HAVE_OSSL_LIB_CTX_FREEZE + if (freeze) { + if (OSSL_LIB_CTX_freeze(NULL, NULL) == 0) { + fprintf(stderr, "Freezing LIB CTX failed\n"); + goto err; + } + } +#endif + switch (operation) { case EVP_ISOLATED: err = !perflib_run_multi_thread_test(do_cipher_isolated, threadcount, &duration) || err; From 9d700c9c94776d93bda793586a28b57af2be28ed Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Mon, 16 Feb 2026 14:37:11 +0100 Subject: [PATCH 2/5] fixup! evp_cipher: add freeze option --- source/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 25e1500..9b505cb 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -274,6 +274,9 @@ set(run_evp_cipher_operations set(run_evp_cipher_algorithms evp_cipher "" "" "-a AES-128-CBC" "-a AES-256-CBC" CACHE STRING "Encryption algorithms for evp_cipher") +set(run_evp_cipher_freeze + evp_hash "" "" "-f" + CACHE STRING "Freeze LIB_CTX for evp_cipher") set(run_evp_mac_operations evp_mac "" "" "-o deprecated_isolated" "-o deprecated_shared" "-o evp_isolated" "-o evp_shared" CACHE STRING "Modes of operation for evp_mac") @@ -341,7 +344,7 @@ set(run_opts run_evp_fetch_pqs CACHE STRING "List of per-text options") if(HAVE_OSSL_LIB_CTX_FREEZE) - list(APPEND run_opts run_evp_hash_freeze) + list(APPEND run_opts run_evp_hash_freeze run_evp_cipher_freeze) endif() # Used across multiple tests From 7b58d3c30ae0aae0468205d2285722b26b1b4033 Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Mon, 16 Feb 2026 14:42:43 +0100 Subject: [PATCH 3/5] fixup! evp_cipher: add freeze option --- source/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 9b505cb..1055c9a 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -275,7 +275,7 @@ set(run_evp_cipher_algorithms evp_cipher "" "" "-a AES-128-CBC" "-a AES-256-CBC" CACHE STRING "Encryption algorithms for evp_cipher") set(run_evp_cipher_freeze - evp_hash "" "" "-f" + evp_cipher "" "" "-f" CACHE STRING "Freeze LIB_CTX for evp_cipher") set(run_evp_mac_operations evp_mac "" "" "-o deprecated_isolated" "-o deprecated_shared" "-o evp_isolated" "-o evp_shared" @@ -344,7 +344,8 @@ set(run_opts run_evp_fetch_pqs CACHE STRING "List of per-text options") if(HAVE_OSSL_LIB_CTX_FREEZE) - list(APPEND run_opts run_evp_hash_freeze run_evp_cipher_freeze) + list(APPEND run_opts run_evp_hash_freeze + run_evp_cipher_freeze) endif() # Used across multiple tests From 974374b9eabe9f71306bcf1ac9632c7aa8271c67 Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Mon, 16 Feb 2026 21:51:12 +0100 Subject: [PATCH 4/5] fixup! evp_cipher: add freeze option --- source/evp_cipher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/evp_cipher.c b/source/evp_cipher.c index a128b5d..c276b6b 100644 --- a/source/evp_cipher.c +++ b/source/evp_cipher.c @@ -154,8 +154,8 @@ int main(int argc, char *argv[]) #endif while ((opt = getopt(argc, argv, getopt_options)) != -1) { -#ifdef HAVE_OSSL_LIB_CTX_FREEZE switch (opt) { +#ifdef HAVE_OSSL_LIB_CTX_FREEZE case 'f': freeze = 1; break; From 90e540d0fbdc18586bf3ffe0bc32e95f5e7d5db8 Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Tue, 17 Feb 2026 10:42:47 +0100 Subject: [PATCH 5/5] fixup! evp_cipher: add freeze option --- source/evp_cipher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/evp_cipher.c b/source/evp_cipher.c index c276b6b..864de37 100644 --- a/source/evp_cipher.c +++ b/source/evp_cipher.c @@ -251,7 +251,7 @@ int main(int argc, char *argv[]) if (OSSL_LIB_CTX_freeze(NULL, NULL) == 0) { fprintf(stderr, "Freezing LIB CTX failed\n"); goto err; - } + } } #endif