Skip to content

Commit e001ad7

Browse files
nikolapajkovskySashan
authored andcommitted
evp_kdf: add freeze option
$ ./evp_kdf -o evp_isolated 64 -f Average time per computation: 8181.213888us $ ./evp_kdf -o evp_isolated 64 Average time per computation: 8307.157135us Signed-off-by: Nikola Pajkovsky <nikolap@openssl.org>
1 parent a7e290a commit e001ad7

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,10 @@ Four modes of operation:
329329
- deprecated_isolated: Use legacy API and don't allow shared data between computations
330330

331331
```
332-
Usage: evp_kdf [-h] [-t] [-o operation] [-V] thread-count
332+
Usage: evp_kdf [-h] [-t] [-f] [-o operation] [-V] thread-count
333333
-h - print this help output
334334
-t - terse output
335+
-f - freeze default context (available only with openssl >= 4.x.x)
335336
-o operation - mode of operation. One of [evp_isolated, evp_shared, deprecated_isolated, deprecated_shared] (default: evp_shared)
336337
-V - print version information and exit
337338
thread-count - number of threads

source/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ list(APPEND run_opts run_writeread_buffers)
346346
add_executable(evp_hash evp_hash.c)
347347
target_link_libraries(evp_hash PRIVATE perf)
348348
list(APPEND run_tests evp_hash)
349+
if( HAVE_OSSL_LIB_CTX_FREEZE )
350+
set(run_evp_kdf_freeze
351+
evp_kdf "" "" "-f"
352+
CACHE STRING "Freeze LIB_CTX for evp_kdf")
353+
list(APPEND run_opts run_evp_kdf_freeze)
354+
endif()
349355
set(run_evp_hash_operations
350356
evp_hash "" "" "-o deprecated" "-o evp_isolated" "-o evp_shared"
351357
CACHE STRING "Modes of operation for evp_hash")

source/evp_kdf.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#define OPENSSL_SUPPRESS_DEPRECATED
1616

17+
#include "config.h"
1718
#include <stdlib.h>
1819
#include <stdio.h>
1920
#ifndef _WIN32
@@ -169,9 +170,16 @@ static void do_deprecated_shared(size_t num)
169170

170171
static void print_help(FILE *file)
171172
{
173+
#ifdef HAVE_OSSL_LIB_CTX_FREEZE
174+
fprintf(file, "Usage: evp_kdf [-h] [-t] [-f] [-o operation] [-V] thread-count\n");
175+
#else
172176
fprintf(file, "Usage: evp_kdf [-h] [-t] [-o operation] [-V] thread-count\n");
177+
#endif
173178
fprintf(file, "-h - print this help output\n");
174179
fprintf(file, "-t - terse output\n");
180+
#ifdef HAVE_OSSL_LIB_CTX_FREEZE
181+
printf("-f - freeze default context\n");
182+
#endif
175183
fprintf(file, "-o operation - mode of operation. One of [evp_isolated, evp_shared, deprecated_isolated, deprecated_shared] (default: evp_shared)\n");
176184
fprintf(file, "-V - print version information and exit\n");
177185
fprintf(file, "thread-count - number of threads\n");
@@ -184,9 +192,19 @@ int main(int argc, char *argv[])
184192
double av;
185193
int terse = 0, operation = EVP_SHARED;
186194
int j, opt, rc = EXIT_FAILURE;
195+
char *getopt_options = "Vhto:";
196+
#ifdef HAVE_OSSL_LIB_CTX_FREEZE
197+
int freeze = 0;
198+
getopt_options = "Vhto:f";
199+
#endif
187200

188-
while ((opt = getopt(argc, argv, "Vhto:")) != -1) {
201+
while ((opt = getopt(argc, argv, getopt_options)) != -1) {
189202
switch (opt) {
203+
#ifdef HAVE_OSSL_LIB_CTX_FREEZE
204+
case 'f':
205+
freeze = 1;
206+
break;
207+
#endif
190208
case 't':
191209
terse = 1;
192210
break;
@@ -242,6 +260,14 @@ int main(int argc, char *argv[])
242260

243261
max_time = ossl_time_add(ossl_time_now(), ossl_seconds2time(RUN_TIME));
244262

263+
#ifdef HAVE_OSSL_LIB_CTX_FREEZE
264+
if (freeze) {
265+
if (OSSL_LIB_CTX_freeze(NULL, NULL) == 0) {
266+
fprintf(stderr, "Freezing LIB CTX failed\n");
267+
goto err;
268+
}
269+
}
270+
#endif
245271
switch (operation) {
246272
case EVP_SHARED:
247273
run_err = !perflib_run_multi_thread_test(do_evp_shared, threadcount, &duration) || run_err;

0 commit comments

Comments
 (0)