Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,10 @@ Three modes of operation:
- evp_shared (default): Use EVP API and allow shared data between threads

```
Usage: evp_hash [-h] [-t] [-o operation] [-u update-times] [-a algorithm] thread-count
Usage: evp_hash [-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 [deprecated, evp_isolated, evp_shared] (default: evp_shared)
-u update-times - times to update digest. 1 for one-shot (default: 1)
-a algorithm - One of: [SHA1, SHA224, SHA256, SHA384, SHA512] (default: SHA1)
Expand Down
15 changes: 15 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@

cmake_minimum_required(VERSION 3.10)
project(perf-tools)
include(CheckSymbolExists)

if(WIN32)
set(CFLAGS_WARNINGS "/Wall" CACHE STRING "Compiler options for warnings")
Expand Down Expand Up @@ -153,6 +154,8 @@ endif()

target_include_directories(perf PUBLIC "${PROJECT_SOURCE_DIR}")
target_link_libraries(perf PUBLIC OpenSSL::SSL OpenSSL::Crypto)
set(CMAKE_REQUIRED_LIBRARIES OpenSSL::Crypto)
set(CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}")

if( OPENSSL_VERSION VERSION_GREATER_EQUAL 3 )
add_executable(evp_fetch evp_fetch.c)
Expand All @@ -163,6 +166,8 @@ if( OPENSSL_VERSION VERSION_GREATER_EQUAL 3 )

endif()

check_symbol_exists(OSSL_LIB_CTX_freeze "openssl/crypto.h" HAVE_OSSL_LIB_CTX_FREEZE)

if( OPENSSL_VERSION VERSION_GREATER_EQUAL 3.6 )
add_executable(ssl_poll_perf ssl_poll_perf.c)
if(WIN32)
Expand Down Expand Up @@ -260,6 +265,9 @@ set(run_evp_hash_update_times
set(run_evp_hash_algorithms
evp_hash "" "" "-a SHA1" "-a SHA224" "-a SHA256" "-a SHA384" "-a SHA512"
CACHE STRING "Digest hash algorithms for evp_hash")
set(run_evp_hash_freeze
evp_hash "" "" "-f"
CACHE STRING "Freeze LIB_CTX for evp_hash")
set(run_evp_cipher_operations
evp_cipher "" "" "-o evp_isolated" "-o evp_shared"
CACHE STRING "Modes of operation for evp_cipher")
Expand Down Expand Up @@ -332,6 +340,10 @@ set(run_opts run_evp_fetch_pqs
run_writeread_buffers
CACHE STRING "List of per-text options")

if(HAVE_OSSL_LIB_CTX_FREEZE)
list(APPEND run_opts run_evp_hash_freeze)
endif()

# Used across multiple tests
set(run_certdir_tests handshake writeread x509storeissuer
CACHE STRING "List of tests that require certdir parameter")
Expand Down Expand Up @@ -378,6 +390,9 @@ if (WIN32)
endforeach()
endif()

# Generate config.h from config.h.in
configure_file(config.h.in ${CMAKE_SOURCE_DIR}/config.h)

#
# gen_run_target(<cmd> <test> [VAR <var>] [NAME <name>])
#
Expand Down
4 changes: 4 additions & 0 deletions source/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* config.h.in */

/* Define to 1 if you have the `OSSL_LIB_CTX_freeze' function. */
#cmakedefine HAVE_OSSL_LIB_CTX_FREEZE
29 changes: 28 additions & 1 deletion source/evp_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#define OPENSSL_SUPPRESS_DEPRECATED

#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#ifndef _WIN32
Expand Down Expand Up @@ -248,9 +249,16 @@ static void do_hash_evp_shared(size_t num)

static void print_help()
{
#ifdef HAVE_OSSL_LIB_CTX_FREEZE
printf("Usage: evp_hash [-h] [-t] [-f] [-o operation] [-u update-times] [-a algorithm] [-V] thread-count\n");
#else
printf("Usage: evp_hash [-h] [-t] [-o operation] [-u update-times] [-a algorithm] [-V] thread-count\n");
#endif
printf("-h - print this help output\n");
printf("-t - terse output\n");
#ifdef HAVE_OSSL_LIB_CTX_FREEZE
printf("-f - freeze default context\n");
#endif
printf("-o operation - mode of operation. One of [deprecated, evp_isolated, evp_shared] (default: evp_shared)\n");
printf("-u update-times - times to update digest. 1 for one-shot (default: 1)\n");
printf("-a algorithm - One of: [SHA1, SHA224, SHA256, SHA384, SHA512] (default: SHA1)\n");
Expand All @@ -265,9 +273,19 @@ int main(int argc, char *argv[])
double av;
int terse = 0, operation = EVP_SHARED, hash_algorithm = SHA1_ALG;
int j, opt, rc = EXIT_FAILURE;
char *getopt_options = "hto:u:a:V";
#ifdef HAVE_OSSL_LIB_CTX_FREEZE
int freeze = 0;
getopt_options = "hto:u:a:Vf";
#endif

while ((opt = getopt(argc, argv, "hto:u:a:V")) != -1) {
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;
Expand Down Expand Up @@ -345,6 +363,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 out;
}
}
#endif

switch (operation) {
case DEPRECATED:
switch (hash_algorithm) {
Expand Down