diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index eb571949a..40fef2f13 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -22,48 +22,179 @@ /* wolfCrypt benchmark */ +/* Some common, optional build settings: + * these can also be set in wolfssl/options.h or user_settings.h + * ------------------------------------------------------------- + * make the binary always use CSV format: + * WOLFSSL_BENCHMARK_FIXED_CSV + * + * choose to use the same units, regardless of scale. pick 1: + * WOLFSSL_BENCHMARK_FIXED_UNITS_GB + * WOLFSSL_BENCHMARK_FIXED_UNITS_MB + * WOLFSSL_BENCHMARK_FIXED_UNITS_KB + * WOLFSSL_BENCHMARK_FIXED_UNITS_B + * + * when the output should be in machine-parseable format: + * GENERATE_MACHINE_PARSEABLE_REPORT + * + * Enable tracking of the stats into an allocated linked list: + * (use -print to display results): + * WC_BENCH_TRACK_STATS + */ + #ifdef HAVE_CONFIG_H #include #endif -/* Some common, optional user settings */ -/* these can also be set in wolfssl/options.h or user_settings.h */ -/* ------------------------------------------------------------- */ -/* make the binary always use CSV format: */ -/* #define WOLFSSL_BENCHMARK_FIXED_CSV */ -/* */ -/* choose to use the same units, regardless of scale. pick 1: */ -/* #define WOLFSSL_BENCHMARK_FIXED_UNITS_GB */ -/* #define WOLFSSL_BENCHMARK_FIXED_UNITS_MB */ -/* #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB */ -/* #define WOLFSSL_BENCHMARK_FIXED_UNITS_B */ -/* */ -/* when the output should be in machine-parseable format: */ -/* #define GENERATE_MACHINE_PARSEABLE_REPORT */ -/* */ - -/* define the max length for each string of metric reported */ -#define __BENCHMARK_MAXIMUM_LINE_LENGTH 150 - -/* some internal helpers to get values of settings */ -/* this first one gets the text name of the #define parameter */ -#define __BENCHMARK_VALUE_TO_STRING(x) #x - -/* this next one gets the text value of the assigned value of #define param */ -#define __BENCHMARK_VALUE(x) __BENCHMARK_VALUE_TO_STRING(x) - -#define WOLFSSL_FIXED_UNITS_PER_SEC "MB/s" /* may be re-set by fixed units */ - #ifndef WOLFSSL_USER_SETTINGS #include #endif #include /* also picks up user_settings.h */ + +/* Macro to disable benchmark */ +#ifndef NO_CRYPT_BENCHMARK + #include -#include #include -#include #include +#include +#include +#include +#include +#include + +#ifdef HAVE_CHACHA + #include +#endif +#ifdef HAVE_POLY1305 + #include +#endif +#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) + #include +#endif +#ifndef NO_AES + #include +#endif +#ifdef HAVE_CAMELLIA + #include +#endif +#ifndef NO_MD5 + #include +#endif +#ifndef NO_SHA + #include +#endif +#ifndef NO_SHA256 + #include +#endif +#if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384) + #include +#endif +#ifdef WOLFSSL_SHA3 + #include +#endif +#ifndef NO_RSA + #include +#endif +#ifdef WOLFSSL_RIPEMD + #include +#endif +#ifdef WOLFSSL_CMAC + #include +#endif +#ifndef NO_DH + #include +#endif +#ifndef NO_DES3 + #include +#endif +#ifndef NO_RC4 + #include +#endif +#ifndef NO_HMAC + #include +#endif +#ifdef WOLFSSL_SIPHASH + #include +#endif +#ifndef NO_PWDBASED + #include +#endif +#ifdef HAVE_ECC + #include +#endif +#ifdef HAVE_CURVE25519 + #include +#endif +#ifdef HAVE_ED25519 + #include +#endif +#ifdef HAVE_CURVE448 + #include +#endif +#ifdef HAVE_ED448 + #include +#endif +#ifdef WOLFSSL_HAVE_KYBER + #include +#ifdef WOLFSSL_WC_KYBER + #include +#endif +#if defined(HAVE_LIBOQS) || defined(HAVE_PQM4) + #include +#endif +#endif +#ifdef WOLFCRYPT_HAVE_ECCSI + #include +#endif +#ifdef WOLFCRYPT_HAVE_SAKKE + #include +#endif + +#if defined(HAVE_PQC) + #if defined(HAVE_FALCON) + #include + #endif + #if defined(HAVE_DILITHIUM) + #include + #endif + #if defined(HAVE_SPHINCS) + #include + #endif +#endif + +#ifdef WOLF_CRYPTO_CB + #include + #ifdef HAVE_INTEL_QA_SYNC + #include + #endif + #ifdef HAVE_CAVIUM_OCTEON_SYNC + #include + #endif + #ifdef HAVE_RENESAS_SYNC + #include + #endif +#endif + +#ifdef WOLFSSL_ASYNC_CRYPT + #include +#endif + +#ifdef USE_FLAT_BENCHMARK_H + #include "benchmark.h" +#else + #include "wolfcrypt/benchmark/benchmark.h" +#endif + + +/* define the max length for each string of metric reported */ +#ifndef WC_BENCH_MAX_LINE_LEN +#define WC_BENCH_MAX_LINE_LEN 150 +#endif + +/* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */ +#define WOLFSSL_FIXED_UNITS_PER_SEC "MB/s" /* may be re-set by fixed units */ #ifdef WOLFSSL_NO_FLOAT_FMT #define FLT_FMT "%0ld,%09lu" @@ -92,7 +223,7 @@ #define FLT_FMT_ARGS(x) x #define FLT_FMT_PREC_ARGS(p, x) p, x #define FLT_FMT_PREC2_ARGS(w, p, x) w, p, x -#endif +#endif /* WOLFSSL_NO_FLOAT_FMT */ #ifdef WOLFSSL_ESPIDF #if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) @@ -111,11 +242,12 @@ #error "CONFIG_IDF_TARGET not implemented" #endif #include -#endif +#endif /* WOLFSSL_ESPIDF */ #ifdef HAVE_PTHREAD #include #endif + #if defined(HAVE_PTHREAD) || \ (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \ !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \ @@ -127,28 +259,21 @@ #endif #if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH) -/* fflush in Zephyr doesn't work on stdout and stderr. Use - * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */ -#undef XFFLUSH -#define XFFLUSH(...) do {} while (0) + /* fflush in Zephyr doesn't work on stdout and stderr. Use + * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */ + #undef XFFLUSH + #define XFFLUSH(...) do {} while (0) #endif -/* Macro to disable benchmark */ -#ifndef NO_CRYPT_BENCHMARK - -#include - /* only for stack size check */ -#if defined(WOLFSSL_ASYNC_CRYPT) - #ifndef WC_NO_ASYNC_THREADING - #define WC_ENABLE_BENCH_THREADING - #endif -#endif +#include -#ifdef USE_FLAT_BENCHMARK_H - #include "benchmark.h" -#else - #include "wolfcrypt/benchmark/benchmark.h" +#if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING) + #define WC_ENABLE_BENCH_THREADING +#endif +/* enable tracking of stats for threaded benchmark */ +#if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS) + #define WC_BENCH_TRACK_STATS #endif #ifdef GENERATE_MACHINE_PARSEABLE_REPORT @@ -189,7 +314,7 @@ static int printfk(const char *fmt, ...) { int ret; - char line[__BENCHMARK_MAXIMUM_LINE_LENGTH]; + char line[WC_BENCH_MAX_LINE_LEN]; va_list ap; va_start(ap, fmt); @@ -258,98 +383,6 @@ #endif #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifndef NO_HMAC - #include -#endif -#ifdef WOLFSSL_SIPHASH - #include -#endif -#ifndef NO_PWDBASED - #include -#endif -#ifdef HAVE_ECC - #include -#endif -#ifdef HAVE_CURVE25519 - #include -#endif -#ifdef HAVE_ED25519 - #include -#endif -#ifdef HAVE_CURVE448 - #include -#endif -#ifdef HAVE_ED448 - #include -#endif -#ifdef WOLFSSL_HAVE_KYBER - #include -#ifdef WOLFSSL_WC_KYBER - #include -#endif -#if defined(HAVE_LIBOQS) || defined(HAVE_PQM4) - #include -#endif -#endif -#ifdef WOLFCRYPT_HAVE_ECCSI - #include -#endif -#ifdef WOLFCRYPT_HAVE_SAKKE - #include -#endif - -#if defined(HAVE_PQC) - #if defined(HAVE_FALCON) - #include - #endif - #if defined(HAVE_DILITHIUM) - #include - #endif - #if defined(HAVE_SPHINCS) - #include - #endif -#endif - -#include -#include -#include -#include - -#ifdef WOLF_CRYPTO_CB - #include - #ifdef HAVE_INTEL_QA_SYNC - #include - #endif - #ifdef HAVE_CAVIUM_OCTEON_SYNC - #include - #endif - #ifdef HAVE_RENESAS_SYNC - #include - #endif -#endif - -#ifdef WOLFSSL_ASYNC_CRYPT - #include -#endif - #ifdef HAVE_FIPS #include @@ -861,7 +894,8 @@ static int lng_index = 0; #ifndef MAIN_NO_ARGS static const char* bench_Usage_msg1[][21] = { /* 0 English */ - { "-? Help, print this usage\n 0: English, 1: Japanese\n", + { "-? Help, print this usage\n" + " 0: English, 1: Japanese\n", "-csv Print terminal output in csv format\n", "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n", "-no_aad No additional authentication data passed.\n", @@ -881,9 +915,11 @@ static const char* bench_Usage_msg1[][21] = { "-p521 Measure ECC using P-521 curve.\n", "-ecc-all Bench all enabled ECC curves.\n", "- Algorithm to benchmark. Available algorithms include:\n", - "-lng Display benchmark result by specified language.\n 0: English, 1: Japanese\n", + "-lng Display benchmark result by specified language.\n" + " 0: English, 1: Japanese\n", " Size of block in bytes\n", - ("-blocks Number of blocks. Can be used together with the 'Size of block'\n" + ("-blocks Number of blocks. Can be used together with the " + "'Size of block'\n" " option, but must be used after that one.\n" ), "-threads Number of threads to run\n", @@ -891,7 +927,8 @@ static const char* bench_Usage_msg1[][21] = { }, #ifndef NO_MULTIBYTE_PRINT /* 1 Japanese */ - { "-? ヘルプ, 使い方を表示します。\n 0: 英語、 1: 日本語\n", + { "-? ヘルプ, 使い方を表示します。\n" + " 0: 英語、 1: 日本語\n", "-csv csv 形式で端末に出力します。\n", "-base10 バイトを10のべき乗で表示します。(例 1 kB = 1000 Bytes)\n", "-no_aad 追加の認証データを使用しません.\n", @@ -906,8 +943,10 @@ static const char* bench_Usage_msg1[][21] = { "-p384 Measure ECC using P-384 curve.\n", "-p521 Measure ECC using P-521 curve.\n", "-ecc-all Bench all enabled ECC curves.\n", - "- アルゴリズムのベンチマークを実施します。\n 利用可能なアルゴリズムは下記を含みます:\n", - "-lng 指定された言語でベンチマーク結果を表示します。\n 0: 英語、 1: 日本語\n", + "- アルゴリズムのベンチマークを実施します。\n" + " 利用可能なアルゴリズムは下記を含みます:\n", + "-lng 指定された言語でベンチマーク結果を表示します。\n" + " 0: 英語、 1: 日本語\n", " ブロックサイズをバイト単位で指定します。\n", "-blocks TBD.\n", "-threads 実行するスレッド数\n", @@ -1242,7 +1281,8 @@ static const char* bench_result_words2[][5] = { /* if algo doesn't require calling again then use this flow */ if (state == WOLF_EVENT_STATE_DONE) { if (callAgain) { - /* needs called again, so allow it and handle completion in bench_async_handle */ + /* needs called again, so allow it and handle completion in + * bench_async_handle */ allowNext = 1; } else { @@ -1369,7 +1409,9 @@ static const char* bench_result_words2[][5] = { #define AES_AAD_OPTIONS_DEFAULT 0x3U #endif #endif - #define AES_AAD_STRING(s) (aesAuthAddSz == 0 ? (s "-no_AAD") : (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom"))) + #define AES_AAD_STRING(s) \ + (aesAuthAddSz == 0 ? (s "-no_AAD") : \ + (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom"))) enum en_aad_options { AAD_SIZE_DEFAULT = 0x1U, AAD_SIZE_ZERO = 0x2U, @@ -1533,11 +1575,11 @@ typedef enum bench_stat_type { BENCH_STAT_IGNORE, } bench_stat_type_t; -#ifdef WC_ENABLE_BENCH_THREADING +#ifdef WC_BENCH_TRACK_STATS static int gPrintStats = 0; - - static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER; - + #ifdef WC_ENABLE_BENCH_THREADING + static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER; + #endif #ifndef BENCH_MAX_NAME_SZ #define BENCH_MAX_NAME_SZ 24 #endif @@ -1563,8 +1605,10 @@ typedef enum bench_stat_type { { bench_stats_t* bstat = NULL; + #ifdef WC_ENABLE_BENCH_THREADING /* protect bench_stats_head and bench_stats_tail access */ PTHREAD_CHECK_RET(pthread_mutex_lock(&bench_lock)); + #endif if (algo != NULL) { /* locate existing in list */ @@ -1611,8 +1655,9 @@ typedef enum bench_stat_type { if (bstat->lastRet > ret) bstat->lastRet = ret; /* track last error */ } + #ifdef WC_ENABLE_BENCH_THREADING PTHREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock)); - + #endif return bstat; } @@ -1620,8 +1665,10 @@ typedef enum bench_stat_type { { bench_stats_t* bstat; + #ifdef WC_ENABLE_BENCH_THREADING /* protect bench_stats_head and bench_stats_tail access */ PTHREAD_CHECK_RET(pthread_mutex_lock(&bench_lock)); + #endif for (bstat = bench_stats_head; bstat != NULL; ) { if (bstat->type == BENCH_STAT_SYM) { @@ -1640,70 +1687,15 @@ typedef enum bench_stat_type { bstat = bstat->next; } + #ifdef WC_ENABLE_BENCH_THREADING PTHREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock)); + #endif } - -#else /* !WC_ENABLE_BENCH_THREADING */ - - typedef struct bench_stats { - const char* algo; - const char* desc; - double perfsec; - const char* perftype; - int strength; - bench_stat_type_t type; - int ret; - } bench_stats_t; - /* 16 threads and 8 different operations. */ - #define MAX_BENCH_STATS (16 * 8) - static bench_stats_t gStats[MAX_BENCH_STATS]; - static int gStatsCount; - - static bench_stats_t* bench_stats_add(bench_stat_type_t type, - const char* algo, int strength, const char* desc, int useDeviceID, - double perfsec, const char* perftype, int ret) - { - bench_stats_t* bstat = NULL; - if (gStatsCount >= MAX_BENCH_STATS) - return bstat; - - bstat = &gStats[gStatsCount++]; - bstat->algo = algo; - bstat->desc = desc; - bstat->perfsec = perfsec; - bstat->perftype = perftype; - bstat->strength = strength; - bstat->type = type; - bstat->ret = ret; - - (void)useDeviceID; - - return bstat; - } - - void bench_stats_print(void) - { - int i; - - for (i=0; itype == BENCH_STAT_SYM) { - printf("%-16s " FLT_FMT_PREC2 " %s/s\n", bstat->desc, - FLT_FMT_PREC2_ARGS(8, 3, bstat->perfsec), - base2 ? "MB" : "mB"); - } - else if (bstat->type == BENCH_STAT_ASYM) { - printf("%-5s %4d %-9s " FLT_FMT_PREC " ops/sec\n", - bstat->algo, bstat->strength, bstat->desc, - FLT_FMT_PREC_ARGS(3, bstat->perfsec)); - } - } - } -#endif /* WC_ENABLE_BENCH_THREADING */ +#endif /* WC_BENCH_TRACK_STATS */ static WC_INLINE void bench_stats_init(void) { -#if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING) +#ifdef WC_BENCH_TRACK_STATS bench_stats_head = NULL; bench_stats_tail = NULL; #endif @@ -1726,10 +1718,11 @@ static WC_INLINE void bench_stats_start(int* count, double* start) } #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS - #define bench_stats_start(count, start) do { \ - SAVE_VECTOR_REGISTERS(pr_err("SAVE_VECTOR_REGISTERS failed for benchmark run."); \ - return; ); \ - bench_stats_start(count, start); \ + #define bench_stats_start(count, start) do { \ + SAVE_VECTOR_REGISTERS(pr_err( \ + "SAVE_VECTOR_REGISTERS failed for benchmark run."); \ + return; ); \ + bench_stats_start(count, start); \ } while (0) #endif @@ -1832,7 +1825,7 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, { double total, persec = 0, blocks = (double)count; const char* blockType; - char msg[__BENCHMARK_MAXIMUM_LINE_LENGTH]; + char msg[WC_BENCH_MAX_LINE_LEN]; const char** word = bench_result_words1[lng_index]; static int sym_header_printed = 0; @@ -1922,9 +1915,11 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, /* note this codepath brings in all the fields from the non-CSV case. */ #ifdef WOLFSSL_ESPIDF #ifdef HAVE_GET_CYCLES - (void)XSNPRINTF(msg, sizeof(msg), "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc, + (void)XSNPRINTF(msg, sizeof(msg), + "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc, BENCH_DEVID_GET_NAME(useDeviceID), - bytes_processed, FLT_FMT_ARGS(total), FLT_FMT_ARGS(persec), + bytes_processed, FLT_FMT_ARGS(total), + FLT_FMT_ARGS(persec), (long unsigned int) total_cycles); #else #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF" @@ -1949,9 +1944,10 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, #endif #elif defined(BENCH_DEVID) (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc, - BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec)); + BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec)); #else - (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc, FLT_FMT_ARGS(persec)); + (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc, + FLT_FMT_ARGS(persec)); #endif #ifdef WOLFSSL_ESPIDF @@ -2014,9 +2010,11 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, XFFLUSH(stdout); #endif +#ifdef WC_BENCH_TRACK_STATS /* Add to thread stats */ bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec, blockType, ret); +#endif (void)useDeviceID; (void)ret; @@ -2037,7 +2035,9 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, { double total, each = 0, opsSec, milliEach; const char **word = bench_result_words2[lng_index]; +#ifdef WC_BENCH_TRACK_STATS const char* kOpsSec = "Ops/Sec"; +#endif char msg[256]; static int asym_header_printed = 0; @@ -2098,22 +2098,27 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, #ifdef GENERATE_MACHINE_PARSEABLE_REPORT #ifdef HAVE_GET_CYCLES (void)XSNPRINTF(msg, sizeof(msg), - "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d," FLT_FMT - ",%lu," FLT_FMT_PREC "\n", - algo, strength, desc, desc_extra, FLT_FMT_PREC_ARGS(3, milliEach), + "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d," + FLT_FMT ",%lu," FLT_FMT_PREC "\n", + algo, strength, desc, desc_extra, + FLT_FMT_PREC_ARGS(3, milliEach), FLT_FMT_PREC_ARGS(3, opsSec), - count, FLT_FMT_ARGS(total), (unsigned long) total_cycles, - FLT_FMT_PREC_ARGS(6, (double)total_cycles / (double)count)); + count, FLT_FMT_ARGS(total), (unsigned long)total_cycles, + FLT_FMT_PREC_ARGS(6, + (double)total_cycles / (double)count)); #else (void)XSNPRINTF(msg, sizeof(msg), - "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d," FLT_FMT "\n", - algo, strength, desc, desc_extra, FLT_FMT_PREC_ARGS(3, milliEach), + "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d," + FLT_FMT "\n", + algo, strength, desc, desc_extra, + FLT_FMT_PREC_ARGS(3, milliEach), FLT_FMT_PREC_ARGS(3, opsSec), count, FLT_FMT_ARGS(total)); #endif #else - (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",\n", algo, - strength, desc, desc_extra, FLT_FMT_PREC_ARGS(3, milliEach), + (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC "," + FLT_FMT_PREC ",\n", algo, strength, desc, desc_extra, + FLT_FMT_PREC_ARGS(3, milliEach), FLT_FMT_PREC_ARGS(3, opsSec)); #endif } /* if (csv_format == 1) */ @@ -2122,28 +2127,33 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, #ifdef GENERATE_MACHINE_PARSEABLE_REPORT #ifdef HAVE_GET_CYCLES (void)XSNPRINTF(msg, sizeof(msg), - "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " FLT_FMT_PREC2 " ms," - " " FLT_FMT_PREC " %s, %lu cycles\n", algo, strength, desc, - desc_extra, BENCH_DEVID_GET_NAME(useDeviceID), - count, word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2], + "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " + FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles\n", + algo, strength, desc, desc_extra, + BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], + FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2], FLT_FMT_PREC2_ARGS(5, 3, milliEach), - FLT_FMT_PREC_ARGS(3, opsSec), word[3], (unsigned long) total_cycles); + FLT_FMT_PREC_ARGS(3, opsSec), word[3], + (unsigned long)total_cycles); #else (void)XSNPRINTF(msg, sizeof(msg), - "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " FLT_FMT_PREC2 " ms," - " " FLT_FMT_PREC " %s\n", algo, strength, desc, - desc_extra, BENCH_DEVID_GET_NAME(useDeviceID), - count, word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2], + "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " + FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s\n", + algo, strength, desc, desc_extra, + BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], + FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2], FLT_FMT_PREC2_ARGS(5, 3, milliEach), FLT_FMT_PREC_ARGS(3, opsSec), word[3]); #endif /* HAVE_GET_CYCLES */ #else (void)XSNPRINTF(msg, sizeof(msg), - "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " FLT_FMT_PREC2 " ms," - " " FLT_FMT_PREC " %s\n", algo, strength, desc, desc_extra, + "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " + FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s\n", + algo, strength, desc, desc_extra, BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2], - FLT_FMT_PREC2_ARGS(5, 3, milliEach), FLT_FMT_PREC_ARGS(3, opsSec), word[3]); + FLT_FMT_PREC2_ARGS(5, 3, milliEach), + FLT_FMT_PREC_ARGS(3, opsSec), word[3]); #endif } printf("%s", msg); @@ -2158,9 +2168,11 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, XFFLUSH(stdout); #endif +#ifdef WC_BENCH_TRACK_STATS /* Add to thread stats */ bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec, kOpsSec, ret); +#endif (void)useDeviceID; (void)ret; @@ -2181,7 +2193,7 @@ static void bench_stats_asym_finish(const char* algo, int strength, static WC_INLINE void bench_stats_free(void) { -#if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING) +#ifdef WC_BENCH_TRACK_STATS bench_stats_t* bstat; for (bstat = bench_stats_head; bstat != NULL; ) { bench_stats_t* next = bstat->next; @@ -3004,7 +3016,7 @@ int benchmark_free(void) { int ret; -#ifdef WC_ENABLE_BENCH_THREADING +#ifdef WC_BENCH_TRACK_STATS if (gPrintStats || devId != INVALID_DEVID) { bench_stats_print(); } @@ -7301,7 +7313,8 @@ void bench_kyber(int type) #ifdef HAVE_ECC -/* +8 for 'ECDSA [%s]' and null terminator */ +/* Maximum ECC name plus null terminator: + * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */ #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8) /* run all benchmarks on a curve */ @@ -7693,13 +7706,12 @@ void bench_eccEncrypt(int curveId) ecc_key *userA = NULL, *userB = NULL; byte *msg = NULL; byte *out = NULL; - char *name = NULL; #else ecc_key userA[1], userB[1]; byte msg[BENCH_ECCENCRYPT_MSG_SIZE]; byte out[BENCH_ECCENCRYPT_OUT_SIZE]; - char name[BENCH_ECC_NAME_SZ]; #endif + char name[BENCH_ECC_NAME_SZ]; int keySize; word32 bench_plainSz = bench_size; int ret, i, count; @@ -7715,9 +7727,7 @@ void bench_eccEncrypt(int curveId) HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); out = (byte *)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - name = (char *)XMALLOC(BENCH_ECC_NAME_SZ, - HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if ((! userA) || (! userB) || (! msg) || (! out) || (! name)) { + if ((! userA) || (! userB) || (! msg) || (! out)) { printf("bench_eccEncrypt malloc failed\n"); goto exit; } @@ -7817,8 +7827,6 @@ exit: XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (out) XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if (name) - XFREE(name, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); #else wc_ecc_free(userB); wc_ecc_free(userA); @@ -9361,7 +9369,9 @@ static void Usage(void) printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads */ #endif e++; +#ifdef WC_BENCH_TRACK_STATS printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */ +#endif } /* Match the command line argument with the string. @@ -9527,6 +9537,8 @@ int wolfcrypt_benchmark_main(int argc, char** argv) } } } +#endif +#ifdef WC_BENCH_TRACK_STATS else if (string_matches(argv[1], "-print")) { gPrintStats = 1; }