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/CMakeLists.txt b/source/CMakeLists.txt index 25e1500..1055c9a 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_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" CACHE STRING "Modes of operation for evp_mac") @@ -341,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) + list(APPEND run_opts run_evp_hash_freeze + run_evp_cipher_freeze) endif() # Used across multiple tests diff --git a/source/evp_cipher.c b/source/evp_cipher.c index 52427fb..864de37 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) { + switch (opt) { +#ifdef HAVE_OSSL_LIB_CTX_FREEZE + 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;