Skip to content

Commit 36c798f

Browse files
evp_fetch: add freeze option
$ ./evp_fetch -f CIPHER:AES-128-GCM 64 -F Average time per fetch call: 1.244238us $ ./evp_fetch -f CIPHER:AES-128-GCM 64 Average time per fetch call: 23.303556us ./evp_fetch -f MD:SHA2-256 64 -F Average time per fetch call: 1.197693us $ ./evp_fetch -f MD:SHA2-256 64 Average time per fetch call: 24.295191us Signed-off-by: Nikola Pajkovsky <nikolap@openssl.org> Reviewed-by: Norbert Pocs <norbertp@openssl.org> MergeDate: Wed Mar 4 14:52:41 2026 (Merged from #80)
1 parent 28c5dde commit 36c798f

3 files changed

Lines changed: 67 additions & 3 deletions

File tree

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,37 @@ thread-count - number of threads
239239
evp_hash -u 10 -a SHA512 -o evp_isolated 15
240240
```
241241

242+
## evp_fetch
243+
244+
Tool that measures the cost of [EVP_*_fetch()](https://docs.openssl.org/master/man3/EVP_MD_fetch/) calls.
245+
Runs for 5 seconds and prints the average execution time per fetch.
246+
247+
By default it cycles over a built-in list of TYPE:ALGORITHM combinations. You can
248+
limit the run to one combination using `-f TYPE:ALGORITHM` or by setting the
249+
`EVP_FETCH_TYPE` environment variable.
250+
251+
```
252+
Usage: evp_fetch [-t] [-f TYPE:ALGORITHM] [-V] [-q] [-F] threadcount
253+
-t - terse output
254+
-f - fetch only the specified algorithm
255+
-q - include post-quantum algorithms (available with OpenSSL >= 3.5 and PQ enabled)
256+
-F - freeze context (available only with openssl >= 4.x.x)
257+
-V - print version information and exit
258+
threadcount - number of threads
259+
```
260+
261+
Environment variables:
262+
263+
```
264+
EVP_FETCH_TYPE - if no -f option is provided, fetch only the specified TYPE:ALGORITHM
265+
```
266+
```sh
267+
./evp_fetch 4
268+
./evp_fetch -f CIPHER:AES-256-GCM 4
269+
EVP_FETCH_TYPE=MD:SHA3-256 ./evp_fetch 4
270+
./evp_fetch -q 4
271+
```
272+
242273
## evp_cipher
243274

244275
Tool that encrypts random data using the specified algorithm.

source/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ set(run_add_version_dep ON
262262
set(run_evp_fetch_pqs
263263
evp_fetch "" "" "-q"
264264
CACHE STRING "Post-quantum option for evp_fetch")
265+
set(run_evp_fetch_freeze
266+
evp_fetch "" "" "-F"
267+
CACHE STRING "Freeze LIB_CTX for evp_fetch")
265268
set(run_evp_hash_operations
266269
evp_hash "" "" "-o deprecated" "-o evp_isolated" "-o evp_shared"
267270
CACHE STRING "Modes of operation for evp_hash")
@@ -363,7 +366,8 @@ set(run_opts run_evp_fetch_pqs
363366
if(HAVE_OSSL_LIB_CTX_FREEZE)
364367
list(APPEND run_opts run_evp_hash_freeze
365368
run_evp_cipher_freeze
366-
run_evp_rand_freeze)
369+
run_evp_rand_freeze
370+
run_evp_fetch_freeze)
367371
endif()
368372

369373
# Used across multiple tests

source/evp_fetch.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* https://www.openssl.org/source/license.html
88
*/
99

10+
#include "config.h"
1011
#include <stdlib.h>
1112
#include <stdio.h>
1213
#include <string.h>
@@ -38,6 +39,16 @@
3839
# define PQ_USAGE_DESC ""
3940
#endif
4041

42+
#ifdef HAVE_OSSL_LIB_CTX_FREEZE
43+
#define FREEZE_GETOPT "F"
44+
#define FREEZE_USAGE_OPT " [-F]"
45+
#define FREEZE_USAGE_DESC "-F - freeze context\n"
46+
#else
47+
#define FREEZE_GETOPT ""
48+
#define FREEZE_USAGE_OPT ""
49+
#define FREEZE_USAGE_DESC ""
50+
#endif
51+
4152
#define RUN_TIME 5
4253

4354
/*
@@ -290,11 +301,12 @@ void do_fetch(size_t num)
290301
static void
291302
usage(const char *progname)
292303
{
293-
printf("Usage: %s [-t] [-f TYPE:ALGORITHM]" PQ_USAGE_OPT " [-V]"
304+
printf("Usage: %s [-t] [-f TYPE:ALGORITHM]" PQ_USAGE_OPT " [-V]" FREEZE_USAGE_OPT
294305
" threadcount\n"
295306
"-t - terse output\n"
296307
"-f - fetch only the specified algorithm\n"
297308
PQ_USAGE_DESC
309+
FREEZE_USAGE_DESC
298310
"-V - print version information and exit\n"
299311
"\nEnvironment variables:\n"
300312
" EVP_FETCH_TYPE - if no -f option is provided, fetch only\n"
@@ -321,9 +333,17 @@ int main(int argc, char *argv[])
321333
int rc = EXIT_FAILURE;
322334
char *fetch_type = getenv("EVP_FETCH_TYPE");
323335
int opt;
336+
#ifdef HAVE_OSSL_LIB_CTX_FREEZE
337+
int freeze = 0;
338+
#endif
324339

325-
while ((opt = getopt(argc, argv, "tf:" PQ_GETOPT "V")) != -1) {
340+
while ((opt = getopt(argc, argv, "tf:" PQ_GETOPT "V" FREEZE_GETOPT)) != -1) {
326341
switch (opt) {
342+
#ifdef HAVE_OSSL_LIB_CTX_FREEZE
343+
case 'F':
344+
freeze = 1;
345+
break;
346+
#endif
327347
case 't':
328348
terse = 1;
329349
break;
@@ -381,6 +401,15 @@ int main(int argc, char *argv[])
381401
if (ctx == NULL)
382402
return EXIT_FAILURE;
383403

404+
#ifdef HAVE_OSSL_LIB_CTX_FREEZE
405+
if (freeze) {
406+
if (OSSL_LIB_CTX_freeze(ctx, NULL) == 0) {
407+
fprintf(stderr, "Freezing LIB CTX failed\n");
408+
goto out;
409+
}
410+
}
411+
#endif
412+
384413
counts = OPENSSL_malloc(sizeof(size_t) * threadcount);
385414
if (counts == NULL) {
386415
printf("Failed to create counts array\n");

0 commit comments

Comments
 (0)