diff --git a/README.md b/README.md index ac7e8b5..62761d1 100644 --- a/README.md +++ b/README.md @@ -320,12 +320,13 @@ Two modes of operation: - evp_isolated: Use EVP API and don't allow shared data between computations ``` -Usage: evp_rand [-h] [-t] [-o operation] [-V] thread-count +Usage: evp_rand [-h] [-t] [-f] [-o operation] [-V] thread-count -h - print this help output -t - terse output +-f - freeze default context -o operation - mode of operation. One of [evp_isolated, evp_shared] (default: evp_shared) -V - print version information and exit -thread-count - number of thread +thread-count - number of threads ``` ```sh diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 2c737ad..b1bc82b 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -298,6 +298,9 @@ set(run_evp_pkey_operations set(run_evp_pkey_algorithms evp_pkey "" "" "-a RSA" "-a X25519" "-a X448" "-a ED25519" "-a ED448" CACHE STRING "Algorithms for evp_pkey") +set(run_evp_rand_freeze + evp_rand "" "" "-f" + CACHE STRING "Freeze LIB_CTX for evp_rand") set(run_evp_setpeer_keys evp_setpeer "-k" dh ec256 ec521 x25519 all CACHE STRING "Key types for evp_setpeer") @@ -359,7 +362,8 @@ set(run_opts run_evp_fetch_pqs if(HAVE_OSSL_LIB_CTX_FREEZE) list(APPEND run_opts run_evp_hash_freeze - run_evp_cipher_freeze) + run_evp_cipher_freeze + run_evp_rand_freeze) endif() # Used across multiple tests diff --git a/source/evp_rand.c b/source/evp_rand.c index 952978c..0252dd6 100644 --- a/source/evp_rand.c +++ b/source/evp_rand.c @@ -14,6 +14,7 @@ #define OPENSSL_SUPPRESS_DEPRECATED +#include "config.h" #include #include #ifndef _WIN32 @@ -121,9 +122,16 @@ static void do_evp_shared(size_t num) static void print_help(FILE *file) { +#ifdef HAVE_OSSL_LIB_CTX_FREEZE + fprintf(file, "Usage: evp_rand [-h] [-t] [-f] [-o operation] [-V] thread-count\n"); +#else fprintf(file, "Usage: evp_rand [-h] [-t] [-o operation] [-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, "-V - print version information and exit\n"); fprintf(file, "thread-count - number of threads\n"); @@ -136,12 +144,24 @@ int main(int argc, char *argv[]) double av; int terse = 0, operation = EVP_SHARED; int j, opt, rc = EXIT_FAILURE; +#ifdef HAVE_OSSL_LIB_CTX_FREEZE + int freeze = 0; + char *getopt_options = "Vhtfo:"; +#else + char *getopt_options = "Vhto:"; +#endif - while ((opt = getopt(argc, argv, "Vhto:")) != -1) { + + while ((opt = getopt(argc, argv, getopt_options)) != -1) { switch (opt) { case 't': terse = 1; break; +#ifdef HAVE_OSSL_LIB_CTX_FREEZE + case 'f': + freeze = 1; + break; +#endif case 'o': if (strcmp(optarg, "evp_isolated") == 0) { operation = EVP_ISOLATED; @@ -184,6 +204,15 @@ int main(int argc, char *argv[]) goto err; } +#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 + max_time = ossl_time_add(ossl_time_now(), ossl_seconds2time(RUN_TIME)); switch (operation) {