diff --git a/wolfcrypt/benchmark/README.md b/wolfcrypt/benchmark/README.md index ecd75d4d5..34f12f949 100644 --- a/wolfcrypt/benchmark/README.md +++ b/wolfcrypt/benchmark/README.md @@ -7,6 +7,19 @@ Tool for performing cryptographic algorithm benchmarking. * Symmetric algorithms like AES and ChaCha20 are measured in Killobytes (KB) or Megabytes (MB) per second. * Asymmetric algorithms like RSA and ECC are measured using Operations Per Second (Ops) per second. +## Compile Options + +Compile with the following options for fixed units. Otherwise the units will auto-scale. See `-base10` parameter option, below. + +`-DWOLFSSL_BENCHMARK_FIXED_UNITS_GB` for GB/GiB +`-DWOLFSSL_BENCHMARK_FIXED_UNITS_MB` for MB/MiB +`-DWOLFSSL_BENCHMARK_FIXED_UNITS_KB` for KB/KiB +`-DWOLFSSL_BENCHMARK_FIXED_UNITS_B` for Bytes + +To set the output to always be CSV: + +`-DWOLFSSL_BENCHMARK_FIXED_CSV` + ## Usage ```sh diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 87aa743f5..9f2c3b083 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -27,15 +27,48 @@ #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 +#include /* also picks up user_settings.h */ #include #include #include #include +#ifdef WOLFSSL_ESPIDF + #include /* reminder Espressif RISC-V not yet implemented */ + #include +#endif + #ifdef HAVE_PTHREAD #include #endif @@ -72,11 +105,11 @@ #endif #ifdef GENERATE_MACHINE_PARSEABLE_REPORT -static const char info_prefix[] = "###, "; -static const char err_prefix[] = "!!!, "; + static const char info_prefix[] = "###, "; + static const char err_prefix[] = "!!!, "; #else -static const char info_prefix[] = ""; -static const char err_prefix[] = ""; + static const char info_prefix[] = ""; + static const char err_prefix[] = ""; #endif @@ -109,7 +142,7 @@ static const char err_prefix[] = ""; static int printfk(const char *fmt, ...) { int ret; - char line[150]; + char line[__BENCHMARK_MAXIMUM_LINE_LENGTH]; va_list ap; va_start(ap, fmt); @@ -153,9 +186,9 @@ static const char err_prefix[] = ""; #include #define printf(...) \ - __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__) + __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__) #define fprintf(fp, ...) \ - __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__) + __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__) #else #if defined(XMALLOC_USER) || defined(FREESCALE_MQX) @@ -968,8 +1001,92 @@ static const char* bench_desc_words[][15] = { #define SHOW_INTEL_CYCLES_CSV(b, n, s) \ (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), "%.6f,\n", \ (float)total_cycles / (count*s)) +#elif defined(WOLFSSL_ESPIDF) + static THREAD_LS_T word64 begin_cycles; + static THREAD_LS_T word64 total_cycles; + + /* the return value */ + static THREAD_LS_T word64 _xthal_get_ccount_ex = 0; + + /* the last value seen, adjusted for an overflow */ + static THREAD_LS_T word64 _xthal_get_ccount_last = 0; + + /* TAG for ESP_LOGx() */ + static char * TAG = "wolfssl_benchmark"; + + #define HAVE_GET_CYCLES + #define INIT_CYCLE_COUNTER + static WC_INLINE word64 get_xtensa_cycles(void); + + /* WARNING the hal UINT xthal_get_ccount() quietly rolls over. */ + #define BEGIN_ESP_CYCLES begin_cycles = (get_xtensa_cycles()); + + /* since it rolls over, we have something that will tolerate one */ + #define END_ESP_CYCLES \ + ESP_LOGV(TAG,"%llu - %llu", \ + get_xtensa_cycles(), \ + begin_cycles \ + ); \ + total_cycles = (get_xtensa_cycles() - begin_cycles); + + #define SHOW_ESP_CYCLES(b, n, s) \ + (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), " %s = %6.2f\n", \ + bench_result_words1[lng_index][2], \ + (float)total_cycles / (count*s) \ + ) + + #define SHOW_ESP_CYCLES_CSV(b, n, s) \ + (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), "%.6f,\n", \ + (float)total_cycles / (count*s)) + + /* xthal_get_ccount_ex() is a single-overflow-tolerant extension to + ** the Espressif `unsigned xthal_get_ccount()` which is known to overflow + ** at least once during full benchmark tests. + */ + word64 xthal_get_ccount_ex() + { + /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */ + + /* the currently observed clock counter value */ + word64 thisVal = xthal_get_ccount(); + + /* if the current value is less than the previous value, + ** we likely overflowed at least once. + */ + if (thisVal < _xthal_get_ccount_last) + { + /* Warning: we assume the return type of xthal_get_ccount() + ** will always be unsigned int to add UINT_MAX. + ** + ** NOTE for long duration between calls with multiple overflows: + ** + ** WILL NOT BE DETECTED - the return value will be INCORRECT. + ** + ** At this time no single test overflows. This is currently only a + ** concern for cumulative counts over multiple tests. As long + ** as well call xthal_get_ccount_ex() with no more than one + ** overflow CPU tick count, all will be well. + */ + ESP_LOGV(TAG, "Alert: Detected xthal_get_ccount overflow, " + "adding %ull", UINT_MAX); + thisVal += (word64)UINT_MAX; + } + + /* adjust our actual returned value that takes into account overflow */ + _xthal_get_ccount_ex += (thisVal - _xthal_get_ccount_last); + + /* all of this took some time, so reset the "last seen" value */ + _xthal_get_ccount_last = xthal_get_ccount(); + + return _xthal_get_ccount_ex; + } + +/* implement other architecture cycle counters here */ #else + /* if we don't know the platform, it is unlikely we can count CPU cycles */ + #undef HAVE_GET_CYCLES + #define INIT_CYCLE_COUNTER #define BEGIN_INTEL_CYCLES #define END_INTEL_CYCLES @@ -1049,9 +1166,9 @@ static const char* bench_desc_words[][15] = { defined(HAVE_CURVE448) || defined(HAVE_ED448) || \ defined(WOLFSSL_HAVE_KYBER) static const char* bench_result_words2[][5] = { - { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */ + { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */ #ifndef NO_MULTIBYTE_PRINT - { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */ + { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */ #endif }; #endif @@ -1249,10 +1366,12 @@ static const char* bench_result_words2[][5] = { if (options & AAD_SIZE_DEFAULT) { aesAuthAddSz = AES_AUTH_ADD_SZ; options &= ~AAD_SIZE_DEFAULT; - } else if (options & AAD_SIZE_ZERO) { + } + else if (options & AAD_SIZE_ZERO) { aesAuthAddSz = 0; options &= ~AAD_SIZE_ZERO; - } else if (options & AAD_SIZE_CUSTOM) { + } + else if (options & AAD_SIZE_CUSTOM) { aesAuthAddSz = aes_aad_size; options &= ~AAD_SIZE_CUSTOM; } @@ -1261,6 +1380,7 @@ static const char* bench_result_words2[][5] = { } } #endif + #ifndef BENCH_CIPHER_ADD #define BENCH_CIPHER_ADD 0 #endif @@ -1288,30 +1408,33 @@ static const char* bench_result_words2[][5] = { #define NUM_BLOCKS 5 #define BENCH_SIZE (1024*1024uL) #endif + static int numBlocks = NUM_BLOCKS; static word32 bench_size = BENCH_SIZE; static int base2 = 1; static int digest_stream = 1; + #ifndef NO_RSA -/* Don't measure RSA sign/verify by default */ -static int rsa_sign_verify = 0; + /* Don't measure RSA sign/verify by default */ + static int rsa_sign_verify = 0; #endif + #ifndef NO_DH -/* Use the FFDHE parameters */ -static int use_ffdhe = 0; + /* Use the FFDHE parameters */ + static int use_ffdhe = 0; #endif /* Don't print out in CSV format by default */ static int csv_format = 0; #ifdef WOLFSSL_XILINX_CRYPT_VERSAL -/* Versal PLM maybe prints an error message to the same console. - * In order to not mix those outputs up, sleep a little while - * before erroring out. - */ -#define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0) + /* Versal PLM maybe prints an error message to the same console. + * In order to not mix those outputs up, sleep a little while + * before erroring out. + */ + #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0) #else -#define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0) + #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0) #endif /* globals for cipher tests */ @@ -1382,9 +1505,9 @@ static void benchmark_static_init(int force) -/******************************************************************************/ -/* Begin Stats Functions */ -/******************************************************************************/ +/*****************************************************************************/ +/* Begin Stats Functions */ +/*****************************************************************************/ typedef enum bench_stat_type { BENCH_STAT_ASYM, BENCH_STAT_SYM, @@ -1569,7 +1692,15 @@ static WC_INLINE void bench_stats_start(int* count, double* start) { *count = 0; *start = current_time(1); + +#ifdef WOLFSSL_ESPIDF + ESP_LOGV(TAG, "finish total_cycles = %llu, start=%f", + total_cycles, *start ); + + BEGIN_ESP_CYCLES +#else BEGIN_INTEL_CYCLES +#endif } static WC_INLINE int bench_stats_check(double start) @@ -1577,21 +1708,130 @@ static WC_INLINE int bench_stats_check(double start) return ((current_time(0) - start) < BENCH_MIN_RUNTIME_SEC); } +/* return text for units and scale the value of blocks as needed for base2 */ +static WC_INLINE const char* specified_base2_blockType(double * blocks) +{ + const char* rt; + +#if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) \ + || defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB) ) + #undef WOLFSSL_FIXED_UNITS_PER_SEC + #define WOLFSSL_FIXED_UNITS_PER_SEC "GB/s" + *blocks /= (1000UL * 1000UL * 1000UL); + rt = "GiB"; + +#elif ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) \ + || defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB) ) + #undef WOLFSSL_FIXED_UNITS_PER_SEC + #define WOLFSSL_FIXED_UNITS_PER_SEC "MB/s" + *blocks /= (1024UL * 1024UL); + rt = "MiB"; + +#elif ( defined (WOLFSSL_BENCHMARK_FIXED_UNITS_K) \ + || defined (WOLFSSL_BENCHMARK_FIXED_UNITS_KB)) + #undef WOLFSSL_FIXED_UNITS_PER_SEC + #define WOLFSSL_FIXED_UNITS_PER_SEC "KB/s" + *blocks /= 1024; + rt = "KiB"; + +#elif ( defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B) ) + #undef WOLFSSL_FIXED_UNITS_PER_SEC + #define WOLFSSL_FIXED_UNITS_PER_SEC "bytes/s" + (void)(*blocks); /* no adjustment, just appease compiler for not used */ + rt = "bytes"; + +#else + + /* if no user-specified, auto-scale each metric (results vary) + ** + ** determine if we should show as KB or MB or bytes. No GiB here. + */ + if (*blocks > (1024UL * 1024UL)) { + *blocks /= (1024UL * 1024UL); + rt = "MiB"; + } + else if (*blocks > 1024) { + *blocks /= 1024; + rt = "KiB"; + } + else { + rt = "bytes"; + } + +#endif + + return rt; +} /* specified_base2_blockType() */ + +/* return text for units and scale the value of blocks as needed */ +static WC_INLINE const char* specified_blockType(double * blocks) +{ + const char* rt; + +#if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) \ + || defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB) ) + *blocks /= (1000UL * 1000UL * 1000UL); + rt = "GB"; + +#elif ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) \ + || defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB) ) + *blocks /= (1000UL * 1000UL); + rt = "MB"; + +#elif ( defined (WOLFSSL_BENCHMARK_FIXED_UNITS_K) \ + || defined (WOLFSSL_BENCHMARK_FIXED_UNITS_KB) ) + *blocks /= (1000UL); + rt = "KB"; + +#elif ( defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B) ) + (void)(*blocks); /* no adjustment, just appease compiler */ + rt = "bytes"; + +#else + /* if not user-specified, auto-scale each metric (results vary) + ** + ** determine if we should show as KB or MB or bytes + */ + if (*blocks > (1000UL * 1000UL)) { + *blocks /= (1000UL * 1000UL); + rt = "MB"; + } + else if (*blocks > 1000) { + *blocks /= 1000; /* make KB */ + rt = "KB"; + } + else { + rt = "bytes"; + } /* rt auto-assigned */ +#endif /* WOLFSSL_BENCHMARK UNITS */ + + return rt; +} /* specified_blockType */ /* countSz is number of bytes that 1 count represents. Normally bench_size, * except for AES direct that operates on AES_BLOCK_SIZE blocks */ -static void bench_stats_sym_finish(const char* desc, int useDeviceID, int count, - int countSz, double start, int ret) +static void bench_stats_sym_finish(const char* desc, int useDeviceID, + int count, int countSz, + double start, int ret) { double total, persec = 0, blocks = (double)count; const char* blockType; - char msg[128] = {0}; + char msg[__BENCHMARK_MAXIMUM_LINE_LENGTH] = {0}; const char** word = bench_result_words1[lng_index]; static int sym_header_printed = 0; +#ifdef WOLFSSL_ESPIDF + END_ESP_CYCLES +#else END_INTEL_CYCLES +#endif + total = current_time(0) - start; +#ifdef WOLFSSL_ESPIDF + ESP_LOGV(TAG, "%s total_cycles = %llu", desc, total_cycles); +#endif + #ifdef LINUX_RUSAGE_UTIME check_for_excessive_stime(desc, ""); #endif @@ -1601,45 +1841,41 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, int count, if (csv_format == 1) { /* only print out header once */ if (sym_header_printed == 0) { + #ifdef GENERATE_MACHINE_PARSEABLE_REPORT + /* machine parseable CSV */ + #ifdef HAVE_GET_CYCLES printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,seconds_total," - "MB/s,cycles_total,Cycles per byte,\n"); + WOLFSSL_FIXED_UNITS_PER_SEC ",cycles_total,Cycles per byte,\n"); + #else + printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,seconds_total," + WOLFSSL_FIXED_UNITS_PER_SEC ",cycles_total,\n"); + #endif #else + /* normal CSV */ + #ifdef HAVE_GET_CYCLES printf("\n\nSymmetric Ciphers:\n\n"); - printf("Algorithm,MB/s,Cycles per byte,\n"); + printf("Algorithm," + WOLFSSL_FIXED_UNITS_PER_SEC ",Cycles per byte,\n"); + #else + printf("\n\nSymmetric Ciphers:\n\n"); + printf("Algorithm," + WOLFSSL_FIXED_UNITS_PER_SEC ", \n"); + #endif #endif sym_header_printed = 1; } } + /* determine if we have fixed units, or auto-scale bits or bytes for units. + ** note that the blockType text is assigned AND the blocks param is scaled. + */ if (base2) { - /* determine if we should show as KiB or MiB */ - if (blocks > (1024UL * 1024UL)) { - blocks /= (1024UL * 1024UL); - blockType = "MiB"; - } - else if (blocks > 1024) { - blocks /= 1024; - blockType = "KiB"; - } - else { - blockType = "bytes"; - } - } + blockType = specified_base2_blockType(&blocks); + } /* is base2 bit counter */ else { - /* determine if we should show as KB or MB */ - if (blocks > (1000UL * 1000UL)) { - blocks /= (1000UL * 1000UL); - blockType = "MB"; - } - else if (blocks > 1000) { - blocks /= 1000; /* make KB */ - blockType = "KB"; - } - else { - blockType = "bytes"; - } - } + blockType = specified_blockType(&blocks); + } /* not base2, is byte counter */ /* calculate blocks per second */ if (total > 0) { @@ -1649,44 +1885,87 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, int count, SLEEP_ON_ERROR(ret); /* format and print to terminal */ if (csv_format == 1) { + #ifdef GENERATE_MACHINE_PARSEABLE_REPORT - word64 bytes_processed; - if (blockType[0] == 'K') - bytes_processed = (word64)(blocks * (base2 ? 1024. : 1000.)); - else if (blockType[0] == 'M') - bytes_processed = - (word64)(blocks * (base2 ? (1024. * 1024.) : (1000. * 1000.))); - else - bytes_processed = (word64)blocks; + #ifdef WOLFSSL_ESPIDF + unsigned long bytes_processed = (unsigned long)blocks; + #else + word64 bytes_processed = (word64)blocks; + #endif #endif - if (blockType[0] == 'K') - persec /= base2 ? 1024. : 1000.; - else if (blockType[0] == 'b') - persec /= base2 ? (1024. * 1024.) : (1000. * 1000.); + + #ifdef GENERATE_MACHINE_PARSEABLE_REPORT - /* note this codepath brings in all the fields from the non-CSV case. */ - (void)XSNPRINTF(msg, sizeof(msg), "sym,%s,%s,%lu,%f,%f,%lu,", desc, - BENCH_DEVID_GET_NAME(useDeviceID), - bytes_processed, total, persec, total_cycles); + /* 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,%f,%f,%lu,", desc, + BENCH_DEVID_GET_NAME(useDeviceID), + bytes_processed, total, persec, + (long unsigned int) total_cycles); + #else + #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF" + #endif + + /* implement other architectures here */ + + #else + #ifdef HAVE_GET_CYCLES + (void)XSNPRINTF(msg, sizeof(msg), "sym,%s,%s,%lu,%f,%f,%lu,", desc, + BENCH_DEVID_GET_NAME(useDeviceID), + bytes_processed, total, persec, total_cycles); + #else + (void)XSNPRINTF(msg, sizeof(msg), "sym,%s,%s,%lu,%f,%f,", desc, + BENCH_ASYNC_GET_NAME(useDeviceID), + bytes_processed, total, persec); + #endif + #endif #else (void)XSNPRINTF(msg, sizeof(msg), "%s,%f,", desc, persec); #endif + + #ifdef WOLFSSL_ESPIDF + SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz); + ESP_LOGV(TAG, "finish total_cycles = %llu", total_cycles); + /* implement other cycle counters here */ + #else SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), countSz); - } else { + #endif + } /* if (csv_format == 1) */ + + else { #ifdef GENERATE_MACHINE_PARSEABLE_REPORT + #ifdef HAVE_GET_CYCLES + (void)XSNPRINTF(msg, sizeof(msg), + "%-24s%s %5.0f %s %s %5.3f %s, %8.3f %s/s" + ", %lu cycles,", + desc, BENCH_DEVID_GET_NAME(useDeviceID), blocks, blockType, + word[0], total, word[1], persec, blockType, + (unsigned long) total_cycles); + #else (void)XSNPRINTF(msg, sizeof(msg), "%-24s%s %5.0f %s %s %5.3f %s, %8.3f %s/s" - ", %lu cycles,", - desc, BENCH_DEVID_GET_NAME(useDeviceID), blocks, blockType, - word[0], total, word[1], persec, blockType, total_cycles); + ",", + desc, BENCH_ASYNC_GET_NAME(useDeviceID), blocks, blockType, + word[0], total, word[1], persec, blockType); + #endif /* HAVE_GET_CYCLES */ #else (void)XSNPRINTF(msg, sizeof(msg), "%-24s%s %5.0f %s %s %5.3f %s, %8.3f %s/s", desc, BENCH_DEVID_GET_NAME(useDeviceID), blocks, blockType, word[0], total, word[1], persec, blockType); #endif + +#ifdef WOLFSSL_ESPIDF + SHOW_ESP_CYCLES(msg, sizeof(msg), countSz); + +/* implement other architecture cycle counters here */ + +#else SHOW_INTEL_CYCLES(msg, sizeof(msg), countSz); - } +#endif + } /* not CSV format */ + printf("%s", msg); /* show errors */ @@ -1706,7 +1985,7 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, int count, (void)ret; TEST_SLEEP(); -} +} /* bench_stats_sym_finish */ #ifdef BENCH_ASYM #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \ @@ -1730,12 +2009,29 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, #endif #ifdef GENERATE_MACHINE_PARSEABLE_REPORT - END_INTEL_CYCLES + #ifdef WOLFSSL_ESPIDF + END_ESP_CYCLES + #else + END_INTEL_CYCLES + #endif #endif - if (count > 0) + /* some sanity checks on the final numbers */ + if (count > 0) { each = total / count; /* per second */ - opsSec = count / total; /* ops second */ + } + else { + count = 0; + each = 0; + } + + if (total > 0) { + opsSec = count / total; /* ops second */ + } + else { + opsSec = 0; + } + milliEach = each * 1000; /* milliseconds */ SLEEP_ON_ERROR(ret); @@ -1744,8 +2040,13 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, /* only print out header once */ if (asym_header_printed == 0) { #ifdef GENERATE_MACHINE_PARSEABLE_REPORT + #ifdef HAVE_GET_CYCLES printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/sec," "ops,secs,cycles,cycles/op\n"); + #else + printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/sec," + "ops,secs\n"); + #endif #else printf("\n%sAsymmetric Ciphers:\n\n", info_prefix); printf("%sAlgorithm,key size,operation,avg ms,ops/sec,\n", @@ -1754,23 +2055,41 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, asym_header_printed = 1; } #ifdef GENERATE_MACHINE_PARSEABLE_REPORT + #ifdef HAVE_GET_CYCLES (void)XSNPRINTF(msg, sizeof(msg), "asym,%s,%d,%s%s,%.3f,%.3f,%d,%f,%lu,%.6f\n", algo, strength, desc, desc_extra, milliEach, opsSec, - count, total, total_cycles, + count, total, (unsigned long) total_cycles, (double)total_cycles / (double)count); + #else + (void)XSNPRINTF(msg, sizeof(msg), + "asym,%s,%d,%s%s,%.3f,%.3f,%d,%f\n", + algo, strength, desc, desc_extra, milliEach, opsSec, + count, total); + #endif #else (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,%.3f,%.3f,\n", algo, strength, desc, desc_extra, milliEach, opsSec); #endif - } else { + } /* if (csv_format == 1) */ + + else { #ifdef GENERATE_MACHINE_PARSEABLE_REPORT + #ifdef HAVE_GET_CYCLES (void)XSNPRINTF(msg, sizeof(msg), "%-6s %5d %8s%-2s %s %6d %s %5.3f %s, %s %5.3f ms," " %.3f %s, %lu cycles\n", algo, strength, desc, desc_extra, BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], total, word[1], word[2], milliEach, - opsSec, word[3], total_cycles); + opsSec, word[3], (unsigned long) total_cycles); + #else + (void)XSNPRINTF(msg, sizeof(msg), + "%-6s %5d %8s%-2s %s %6d %s %5.3f %s, %s %5.3f ms," + " %.3f %s\n", algo, strength, desc, + desc_extra, BENCH_ASYNC_GET_NAME(useDeviceID), + count, word[0], total, word[1], word[2], milliEach, + opsSec, word[3]); + #endif /* HAVE_GET_CYCLES */ #else (void)XSNPRINTF(msg, sizeof(msg), "%-6s %5d %8s%-2s %s %6d %s %5.3f %s, %s %5.3f ms," @@ -1799,7 +2118,7 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, (void)ret; TEST_SLEEP(); -} +} /* bench_stats_asym_finish_ex */ static void bench_stats_asym_finish(const char* algo, int strength, const char* desc, int useDeviceID, int count, double start, int ret) @@ -1810,13 +2129,13 @@ static void bench_stats_asym_finish(const char* algo, int strength, #endif #if defined(HAVE_PQC) && (defined(HAVE_LIBOQS) || defined(HAVE_PQM4)) -static void bench_stats_pq_asym_finish(const char* algo, int useDeviceID, int count, - double start, int ret) +static void bench_stats_pq_asym_finish(const char* algo, int useDeviceID, + int count, double start, int ret) { double total, each = 0, opsSec, milliEach; const char **word = bench_result_words2[lng_index]; const char* kOpsSec = "Ops/Sec"; - char msg[128] = {0}; + char msg[__BENCHMARK_MAXIMUM_LINE_LENGTH] = {0}; static int pqasym_header_printed = 0; total = current_time(0) - start; @@ -1826,7 +2145,11 @@ static void bench_stats_pq_asym_finish(const char* algo, int useDeviceID, int co #endif #ifdef GENERATE_MACHINE_PARSEABLE_REPORT - END_INTEL_CYCLES + #ifdef WOLFSSL_ESPIDF + END_ESP_CYCLES + #else + END_INTEL_CYCLES + #endif #endif if (count > 0) @@ -1839,8 +2162,15 @@ static void bench_stats_pq_asym_finish(const char* algo, int useDeviceID, int co /* only print out header once */ if (pqasym_header_printed == 0) { #ifdef GENERATE_MACHINE_PARSEABLE_REPORT - printf("%s", "\"pq_asym\",Algorithm,avg ms,ops/sec,ops,secs,cycles," + #ifdef HAVE_GET_CYCLES + printf("%s", + "\"pq_asym\",Algorithm,avg ms,ops/sec,ops,secs,cycles," "cycles/op\n"); + #else + printf("%s", + "\"pq_asym\",Algorithm,avg ms,ops/sec,ops,secs\n"); + #endif + #else printf("\nPost Quantum Asymmetric Ciphers:\n\n"); printf("Algorithm,avg ms,ops/sec,\n"); @@ -1848,15 +2178,25 @@ static void bench_stats_pq_asym_finish(const char* algo, int useDeviceID, int co pqasym_header_printed = 1; } #ifdef GENERATE_MACHINE_PARSEABLE_REPORT + #ifdef HAVE_GET_CYCLES (void)XSNPRINTF(msg, sizeof(msg), "pq_asym,%s,%.3f,%.3f,%d,%f,%lu,%.6f,\n", algo, milliEach, opsSec, count, total, total_cycles, (double)total_cycles / (double)count); + #else + (void)XSNPRINTF(msg, sizeof(msg), + "pq_asym,%s,%.3f,%.3f,%d,%f,%lu,%.6f,\n", + algo, milliEach, opsSec, count, total); + #endif #else (void)XSNPRINTF(msg, sizeof(msg), "%s %.3f,%.3f,\n", algo, milliEach, opsSec); #endif - } else { + } /* CSV */ + + else { + /* not CSV*/ + #ifdef GENERATE_MACHINE_PARSEABLE_REPORT (void)XSNPRINTF(msg, sizeof(msg), "%-18s %s %6d %s %5.3f %s, %s %5.3f ms," @@ -1865,11 +2205,13 @@ static void bench_stats_pq_asym_finish(const char* algo, int useDeviceID, int co count, word[0], total, word[1], word[2], milliEach, opsSec, word[3], total_cycles); #else - (void)XSNPRINTF(msg, sizeof(msg), "%-18s %s %6d %s %5.3f %s, %s %5.3f ms," - " %.3f %s\n", algo, BENCH_DEVID_GET_NAME(useDeviceID), + (void)XSNPRINTF(msg, sizeof(msg), + "%-18s %s %6d %s %5.3f %s, %s %5.3f ms," + " %.3f %s\n", algo, BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], total, word[1], word[2], milliEach, opsSec, word[3]); -#endif - } +#endif /* GENERATE_MACHINE_PARSEABLE_REPORT */ + } /* not CSV */ + printf("%s", msg); /* show errors */ @@ -1878,14 +2220,15 @@ static void bench_stats_pq_asym_finish(const char* algo, int useDeviceID, int co } /* Add to thread stats */ - bench_stats_add(BENCH_STAT_ASYM, algo, 0, "", useDeviceID, opsSec, kOpsSec, ret); + bench_stats_add(BENCH_STAT_ASYM, algo, 0, "", + useDeviceID, opsSec, kOpsSec, ret); (void)useDeviceID; (void)ret; TEST_SLEEP(); } -#endif +#endif /* HAVE_PQC, etc... */ #endif /* BENCH_ASYM */ static WC_INLINE void bench_stats_free(void) @@ -1901,9 +2244,10 @@ static WC_INLINE void bench_stats_free(void) bench_stats_tail = NULL; #endif } -/******************************************************************************/ + +/*****************************************************************************/ /* End Stats Functions */ -/******************************************************************************/ +/*****************************************************************************/ static void* benchmarks_do(void* args) @@ -1979,8 +2323,10 @@ static void* benchmarks_do(void* args) bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); #else - bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); - bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16, + HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16, + HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); #endif if (bench_plain == NULL || bench_cipher == NULL) { XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); @@ -1994,8 +2340,11 @@ static void* benchmarks_do(void* args) XMEMSET(bench_cipher, 0, (size_t)bench_buf_size); #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC) - bench_key = (byte*)XMALLOC(sizeof(bench_key_buf), HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); - bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf), HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + bench_key = (byte*)XMALLOC(sizeof(bench_key_buf), + HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf), + HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + if (bench_key == NULL || bench_iv == NULL) { XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); @@ -2637,8 +2986,9 @@ int benchmark_init(void) benchmark_static_init(0); #ifdef WOLFSSL_STATIC_MEMORY - ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory, sizeof(gBenchMemory), - WOLFMEM_GENERAL, 1); + ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory, + sizeof(gBenchMemory), WOLFMEM_GENERAL, 1); + if (ret != 0) { printf("%sunable to load static memory %d\n", err_prefix, ret); } @@ -2648,6 +2998,7 @@ int benchmark_init(void) printf("%swolfCrypt_Init failed %d\n", err_prefix, ret); return EXIT_FAILURE; } + #ifdef WOLFSSL_SECO_CAAM if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID, SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE) @@ -2670,9 +3021,11 @@ int benchmark_init(void) printf("%swolfCrypt Benchmark (block bytes %d, min %.1f sec each)\n", info_prefix, (int)bench_size, BENCH_MIN_RUNTIME_SEC); + #ifndef GENERATE_MACHINE_PARSEABLE_REPORT if (csv_format == 1) { - printf("This format allows you to easily copy the output to a csv file."); + printf("This format allows you to easily copy " + "the output to a csv file."); } #endif @@ -2762,7 +3115,8 @@ static int benchmark_test_threaded(void* args) } for (i = 0; i < g_threadCount; i++) { - PTHREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id, NULL, run_bench, args)); + PTHREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id, + NULL, run_bench, args)); } for (i = 0; i < g_threadCount; i++) { @@ -2797,6 +3151,15 @@ int benchmark_test(void *args) #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING) { + /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT + ** + ** Chapter Two, Build Options: + ** + ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf + ** + ** asynchronous cryptography using hardware based adapters such as + ** the Intel QuickAssist or Marvell (Cavium) Nitrox V. + */ int i; if (g_threadCount == 0) { @@ -2879,7 +3242,8 @@ void bench_rng(void) len = remain; if (len > RNG_MAX_BLOCK_LEN) len = RNG_MAX_BLOCK_LEN; - ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos], (word32)len); + ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos], + (word32)len); if (ret < 0) goto exit_rng; @@ -2900,7 +3264,8 @@ exit_rng: #ifndef NO_AES #ifdef HAVE_AES_CBC -static void bench_aescbc_internal(int useDeviceID, const byte* key, word32 keySz, +static void bench_aescbc_internal(int useDeviceID, + const byte* key, word32 keySz, const byte* iv, const char* encLabel, const char* decLabel) { @@ -2934,12 +3299,12 @@ static void bench_aescbc_internal(int useDeviceID, const byte* key, word32 keySz /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { + ×, numBlocks, &pending)) { ret = wc_AesCbcEncrypt(&enc[i], bench_plain, bench_cipher, bench_size); if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_aes_enc; } } @@ -2947,8 +3312,10 @@ static void bench_aescbc_internal(int useDeviceID, const byte* key, word32 keySz } /* for times */ count += times; } while (bench_stats_check(start)); + exit_aes_enc: - bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish(encLabel, useDeviceID, count, + bench_size, start, ret); if (ret < 0) { goto exit; @@ -2972,12 +3339,12 @@ exit_aes_enc: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { + ×, numBlocks, &pending)) { ret = wc_AesCbcDecrypt(&enc[i], bench_cipher, bench_plain, bench_size); if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_aes_dec; } } @@ -2986,7 +3353,8 @@ exit_aes_enc: count += times; } while (bench_stats_check(start)); exit_aes_dec: - bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size, + start, ret); #endif /* HAVE_AES_DECRYPT */ @@ -3017,8 +3385,9 @@ void bench_aescbc(int useDeviceID) #endif /* HAVE_AES_CBC */ #ifdef HAVE_AESGCM -static void bench_aesgcm_internal(int useDeviceID, const byte* key, word32 keySz, - const byte* iv, word32 ivSz, +static void bench_aesgcm_internal(int useDeviceID, + const byte* key, word32 keySz, + const byte* iv, word32 ivSz, const char* encLabel, const char* decLabel) { int ret = 0, i, count = 0, times, pending = 0; @@ -3075,7 +3444,7 @@ static void bench_aesgcm_internal(int useDeviceID, const byte* key, word32 keySz /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { + ×, numBlocks, &pending)) { #ifndef BENCHMARK_AESGCM_STREAM ret = wc_AesGcmEncrypt(&enc[i], bench_cipher, bench_plain, bench_size, @@ -3094,7 +3463,7 @@ static void bench_aesgcm_internal(int useDeviceID, const byte* key, word32 keySz } #endif if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_aes_gcm; } } @@ -3103,7 +3472,8 @@ static void bench_aesgcm_internal(int useDeviceID, const byte* key, word32 keySz count += times; } while (bench_stats_check(start)); exit_aes_gcm: - bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size, + start, ret); #ifdef HAVE_AES_DECRYPT /* init keys */ @@ -3129,7 +3499,7 @@ exit_aes_gcm: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&dec[i]), 0, - ×, numBlocks, &pending)) { + ×, numBlocks, &pending)) { #ifndef BENCHMARK_AESGCM_STREAM ret = wc_AesGcmDecrypt(&dec[i], bench_plain, bench_cipher, bench_size, @@ -3148,7 +3518,7 @@ exit_aes_gcm: } #endif if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&dec[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_aes_gcm_dec; } } @@ -3156,8 +3526,10 @@ exit_aes_gcm: } /* for times */ count += times; } while (bench_stats_check(start)); + exit_aes_gcm_dec: - bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size, + start, ret); #endif /* HAVE_AES_DECRYPT */ (void)decLabel; @@ -3184,7 +3556,8 @@ void bench_aesgcm(int useDeviceID) { #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir) #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \ - && !defined(WOLFSSL_XILINX_CRYPT) || defined(WOLFSSL_XILINX_CRYPT_VERSAL) + && !defined(WOLFSSL_XILINX_CRYPT) \ + || defined(WOLFSSL_XILINX_CRYPT_VERSAL) bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12, AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec)); #endif @@ -3244,7 +3617,8 @@ void bench_gmac(void) #ifdef HAVE_AES_ECB -static void bench_aesecb_internal(int useDeviceID, const byte* key, word32 keySz, +static void bench_aesecb_internal(int useDeviceID, + const byte* key, word32 keySz, const char* encLabel, const char* decLabel) { int ret = 0, i, count = 0, times, pending = 0; @@ -3285,7 +3659,7 @@ static void bench_aesecb_internal(int useDeviceID, const byte* key, word32 keySz /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { + ×, numBlocks, &pending)) { #ifdef HAVE_FIPS wc_AesEncryptDirect(&enc[i], bench_cipher, bench_plain); #else @@ -3294,7 +3668,7 @@ static void bench_aesecb_internal(int useDeviceID, const byte* key, word32 keySz #endif ret = 0; if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_aes_enc; } } @@ -3325,7 +3699,7 @@ exit_aes_enc: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { + ×, numBlocks, &pending)) { #ifdef HAVE_FIPS wc_AesDecryptDirect(&enc[i], bench_plain, bench_cipher); #else @@ -3334,7 +3708,7 @@ exit_aes_enc: #endif ret = 0; if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_aes_dec; } } @@ -3373,7 +3747,8 @@ void bench_aesecb(int useDeviceID) #endif /* HAVE_AES_ECB */ #ifdef WOLFSSL_AES_CFB -static void bench_aescfb_internal(const byte* key, word32 keySz, const byte* iv, +static void bench_aescfb_internal(const byte* key, + word32 keySz, const byte* iv, const char* label) { Aes enc; @@ -3416,7 +3791,8 @@ void bench_aescfb(void) #ifdef WOLFSSL_AES_OFB -static void bench_aesofb_internal(const byte* key, word32 keySz, const byte* iv, +static void bench_aesofb_internal(const byte* key, + word32 keySz, const byte* iv, const char* label) { Aes enc; @@ -3532,8 +3908,8 @@ void bench_aesxts(void) #ifdef WOLFSSL_AES_COUNTER -static void bench_aesctr_internal(const byte* key, word32 keySz, const byte* iv, - const char* label) +static void bench_aesctr_internal(const byte* key, word32 keySz, + const byte* iv, const char* label) { Aes enc; double start; @@ -3545,7 +3921,7 @@ static void bench_aesctr_internal(const byte* key, word32 keySz, const byte* iv, do { for (i = 0; i < numBlocks; i++) { if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher, - bench_size)) != 0) { + bench_size)) != 0) { printf("wc_AesCtrEncrypt failed, ret = %d\n", ret); return; } @@ -3810,11 +4186,12 @@ void bench_des(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { - ret = wc_Des3_CbcEncrypt(&enc[i], bench_cipher, bench_plain, - bench_size); + ×, numBlocks, &pending)) { + ret = wc_Des3_CbcEncrypt(&enc[i], + bench_cipher, + bench_plain, bench_size); if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_3des; } } @@ -3867,11 +4244,11 @@ void bench_arc4(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { + ×, numBlocks, &pending)) { ret = wc_Arc4Process(&enc[i], bench_cipher, bench_plain, - bench_size); + bench_size); if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_arc4; } } @@ -3944,8 +4321,10 @@ void bench_md5(int useDeviceID) wc_Md5 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_MD5_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_MD5_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_MD5_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_MD5_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -3972,11 +4351,12 @@ void bench_md5(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Md5Update(&hash[i], bench_plain, - bench_size); + bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), + 0, ×, &pending)) { goto exit_md5; } } @@ -3990,10 +4370,11 @@ void bench_md5(int useDeviceID) for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Md5Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_md5; } } @@ -4038,8 +4419,10 @@ void bench_sha(int useDeviceID) wc_Sha hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4066,11 +4449,12 @@ void bench_sha(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_ShaUpdate(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha; } } @@ -4084,10 +4468,11 @@ void bench_sha(int useDeviceID) for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_ShaFinal(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha; } } @@ -4131,8 +4516,10 @@ void bench_sha224(int useDeviceID) wc_Sha224 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA224_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA224_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA224_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA224_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4156,11 +4543,12 @@ void bench_sha224(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha224Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha224; } } @@ -4173,10 +4561,11 @@ void bench_sha224(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha224Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha224; } } @@ -4201,7 +4590,8 @@ void bench_sha224(int useDeviceID) } while (bench_stats_check(start)); } exit_sha224: - bench_stats_sym_finish("SHA-224", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA-224", useDeviceID, count, + bench_size, start, ret); exit: @@ -4219,8 +4609,10 @@ void bench_sha256(int useDeviceID) wc_Sha256 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA256_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA256_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA256_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA256_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4247,11 +4639,12 @@ void bench_sha256(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha256Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha256; } } @@ -4264,10 +4657,11 @@ void bench_sha256(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha256Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha256; } } @@ -4292,7 +4686,8 @@ void bench_sha256(int useDeviceID) } while (bench_stats_check(start)); } exit_sha256: - bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size, + start, ret); exit: @@ -4310,8 +4705,10 @@ void bench_sha384(int useDeviceID) wc_Sha384 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA384_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA384_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA384_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA384_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4335,11 +4732,12 @@ void bench_sha384(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha384Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha384; } } @@ -4352,10 +4750,11 @@ void bench_sha384(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha384Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha384; } } @@ -4380,7 +4779,8 @@ void bench_sha384(int useDeviceID) } while (bench_stats_check(start)); } exit_sha384: - bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size, + start, ret); exit: @@ -4398,8 +4798,10 @@ void bench_sha512(int useDeviceID) wc_Sha512 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA512_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA512_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA512_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA512_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4423,11 +4825,12 @@ void bench_sha512(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha512Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha512; } } @@ -4440,10 +4843,11 @@ void bench_sha512(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha512Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha512; } } @@ -4468,7 +4872,8 @@ void bench_sha512(int useDeviceID) } while (bench_stats_check(start)); } exit_sha512: - bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size, + start, ret); exit: @@ -4488,8 +4893,10 @@ void bench_sha3_224(int useDeviceID) wc_Sha3 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_224_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_224_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_224_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_224_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4513,11 +4920,12 @@ void bench_sha3_224(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_224_Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_224; } } @@ -4530,10 +4938,11 @@ void bench_sha3_224(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_224_Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_224; } } @@ -4558,7 +4967,8 @@ void bench_sha3_224(int useDeviceID) } while (bench_stats_check(start)); } exit_sha3_224: - bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size, + start, ret); exit: @@ -4576,8 +4986,10 @@ void bench_sha3_256(int useDeviceID) wc_Sha3 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_256_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_256_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_256_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_256_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4601,11 +5013,12 @@ void bench_sha3_256(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_256_Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_256; } } @@ -4618,10 +5031,11 @@ void bench_sha3_256(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_256_Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_256; } } @@ -4646,7 +5060,8 @@ void bench_sha3_256(int useDeviceID) } while (bench_stats_check(start)); } exit_sha3_256: - bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size, + start, ret); exit: @@ -4664,8 +5079,10 @@ void bench_sha3_384(int useDeviceID) wc_Sha3 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_384_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_384_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_384_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_384_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4689,11 +5106,12 @@ void bench_sha3_384(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_384_Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_384; } } @@ -4706,10 +5124,11 @@ void bench_sha3_384(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_384_Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_384; } } @@ -4734,7 +5153,8 @@ void bench_sha3_384(int useDeviceID) } while (bench_stats_check(start)); } exit_sha3_384: - bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size, + start, ret); exit: @@ -4752,8 +5172,10 @@ void bench_sha3_512(int useDeviceID) wc_Sha3 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_512_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_512_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_512_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_512_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4777,11 +5199,12 @@ void bench_sha3_512(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_512_Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_512; } } @@ -4794,10 +5217,11 @@ void bench_sha3_512(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_512_Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_512; } } @@ -4822,7 +5246,8 @@ void bench_sha3_512(int useDeviceID) } while (bench_stats_check(start)); } exit_sha3_512: - bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size, + start, ret); exit: @@ -4840,8 +5265,10 @@ void bench_shake128(int useDeviceID) wc_Shake hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_128_BLOCK_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_128_BLOCK_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_128_BLOCK_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_128_BLOCK_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4865,11 +5292,12 @@ void bench_shake128(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Shake128_Update(&hash[i], bench_plain, BENCH_SIZE); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_shake128; } } @@ -4882,11 +5310,12 @@ void bench_shake128(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Shake128_Final(&hash[i], digest[i], WC_SHA3_128_BLOCK_SIZE); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_shake128; } } @@ -4912,7 +5341,8 @@ void bench_shake128(int useDeviceID) } while (bench_stats_check(start)); } exit_shake128: - bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size, + start, ret); exit: @@ -4930,8 +5360,10 @@ void bench_shake256(int useDeviceID) wc_Shake hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_256_BLOCK_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_256_BLOCK_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_256_BLOCK_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_256_BLOCK_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4955,11 +5387,12 @@ void bench_shake256(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Shake256_Update(&hash[i], bench_plain, BENCH_SIZE); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_shake256; } } @@ -4972,11 +5405,12 @@ void bench_shake256(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Shake256_Final(&hash[i], digest[i], WC_SHA3_256_BLOCK_SIZE); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_shake256; } } @@ -5002,7 +5436,8 @@ void bench_shake256(int useDeviceID) } while (bench_stats_check(start)); } exit_shake256: - bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size, + start, ret); exit: @@ -5281,7 +5716,8 @@ void bench_scrypt(void) do { for (i = 0; i < scryptCnt; i++) { ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13, - (byte*)"SodiumChloride", 14, 14, 8, 1, sizeof(derived)); + (byte*)"SodiumChloride", 14, 14, 8, 1, + sizeof(derived)); if (ret != 0) { printf("scrypt failed, ret = %d\n", ret); goto exit; @@ -5304,8 +5740,10 @@ static void bench_hmac(int useDeviceID, int type, int digestSz, double start; int ret = 0, i, count = 0, times, pending = 0; #ifdef WOLFSSL_ASYNC_CRYPT - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_MAX_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_MAX_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_MAX_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_MAX_DIGEST_SIZE, HEAP_HINT); #else byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE]; #endif @@ -5338,10 +5776,12 @@ static void bench_hmac(int useDeviceID, int type, int digestSz, /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hmac[i]), 0, + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&hmac[i]), 0, ×, numBlocks, &pending)) { ret = wc_HmacUpdate(&hmac[i], bench_plain, bench_size); - if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&hmac[i]), + if (!bench_async_handle(&ret, + BENCH_ASYNC_GET_DEV(&hmac[i]), 0, ×, &pending)) { goto exit_hmac; } @@ -5355,10 +5795,12 @@ static void bench_hmac(int useDeviceID, int type, int digestSz, bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hmac[i]), 0, + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&hmac[i]), 0, ×, numBlocks, &pending)) { ret = wc_HmacFinal(&hmac[i], digest[i]); - if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&hmac[i]), + if (!bench_async_handle(&ret, + BENCH_ASYNC_GET_DEV(&hmac[i]), 0, ×, &pending)) { goto exit_hmac; } @@ -5416,7 +5858,8 @@ void bench_hmac_sha224(int useDeviceID) 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; - bench_hmac(useDeviceID, WC_SHA224, WC_SHA224_DIGEST_SIZE, key, sizeof(key), + bench_hmac(useDeviceID, WC_SHA224, + WC_SHA224_DIGEST_SIZE, key, sizeof(key), "HMAC-SHA224"); } @@ -5550,7 +5993,7 @@ static void bench_rsaKeyGen_helper(int useDeviceID, int keySz) for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), - 0, ×, genTimes, &pending)) { + 0, ×, genTimes, &pending)) { wc_FreeRsaKey(&genKey[i]); ret = wc_InitRsaKey_ex(&genKey[i], HEAP_HINT, devId); @@ -5560,7 +6003,8 @@ static void bench_rsaKeyGen_helper(int useDeviceID, int keySz) ret = wc_MakeRsaKey(&genKey[i], keySz, rsa_e_val, &gRng); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&genKey[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&genKey[i]), 0, + ×, &pending)) { goto exit; } } @@ -5569,7 +6013,8 @@ static void bench_rsaKeyGen_helper(int useDeviceID, int keySz) count += times; } while (bench_stats_check(start)); exit: - bench_stats_asym_finish("RSA", keySz, desc[2], useDeviceID, count, start, ret); + bench_stats_asym_finish("RSA", keySz, desc[2], useDeviceID, count, + start, ret); /* cleanup */ for (i = 0; i < BENCH_MAX_PENDING; i++) { @@ -5707,7 +6152,7 @@ static unsigned char rsa_3072_sig[] = { #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */ static void bench_rsa_helper(int useDeviceID, RsaKey rsaKey[BENCH_MAX_PENDING], - int rsaKeySz) + int rsaKeySz) { int ret = 0, i, times, count = 0, pending = 0; word32 idx = 0; @@ -5720,16 +6165,24 @@ static void bench_rsa_helper(int useDeviceID, RsaKey rsaKey[BENCH_MAX_PENDING], #ifndef WOLFSSL_RSA_VERIFY_ONLY WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT); #endif - WC_DECLARE_ARRAY_DYNAMIC_DEC(enc, byte, BENCH_MAX_PENDING, rsaKeySz, HEAP_HINT); - #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) - WC_DECLARE_ARRAY_DYNAMIC_DEC(out, byte, BENCH_MAX_PENDING, rsaKeySz, HEAP_HINT); + WC_DECLARE_ARRAY_DYNAMIC_DEC(enc, byte, BENCH_MAX_PENDING, + rsaKeySz, HEAP_HINT); + + #if ( !defined(WOLFSSL_RSA_VERIFY_INLINE) \ + && !defined(WOLFSSL_RSA_PUBLIC_ONLY) ) + WC_DECLARE_ARRAY_DYNAMIC_DEC(out, byte, BENCH_MAX_PENDING, + rsaKeySz, HEAP_HINT); #else byte* out[BENCH_MAX_PENDING]; #endif - WC_DECLARE_ARRAY_DYNAMIC_EXE(enc, byte, BENCH_MAX_PENDING, rsaKeySz, HEAP_HINT); - #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) - WC_DECLARE_ARRAY_DYNAMIC_EXE(out, byte, BENCH_MAX_PENDING, rsaKeySz, HEAP_HINT); + WC_DECLARE_ARRAY_DYNAMIC_EXE(enc, byte, BENCH_MAX_PENDING, + rsaKeySz, HEAP_HINT); + + #if ( !defined(WOLFSSL_RSA_VERIFY_INLINE) \ + && !defined(WOLFSSL_RSA_PUBLIC_ONLY) ) + WC_DECLARE_ARRAY_DYNAMIC_EXE(out, byte, BENCH_MAX_PENDING, + rsaKeySz, HEAP_HINT); if (out[0] == NULL) { ret = MEMORY_E; goto exit; @@ -5760,13 +6213,16 @@ static void bench_rsa_helper(int useDeviceID, RsaKey rsaKey[BENCH_MAX_PENDING], /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), - 1, ×, ntimes, &pending)) { + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&rsaKey[i]), + 1, ×, ntimes, &pending)) { ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i], rsaKeySz/8, &rsaKey[i], GLOBAL_RNG); - if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV( - &rsaKey[i]), 1, ×, &pending)) { + if (!bench_async_handle(&ret, + BENCH_ASYNC_GET_DEV( + &rsaKey[i]), 1, ×, + &pending)) { goto exit_rsa_verify; } } @@ -5775,8 +6231,8 @@ static void bench_rsa_helper(int useDeviceID, RsaKey rsaKey[BENCH_MAX_PENDING], count += times; } while (bench_stats_check(start)); exit_rsa_verify: - bench_stats_asym_finish("RSA", rsaKeySz, desc[0], useDeviceID, count, - start, ret); + bench_stats_asym_finish("RSA", rsaKeySz, desc[0], + useDeviceID, count, start, ret); #endif /* !WOLFSSL_RSA_VERIFY_ONLY */ #ifndef WOLFSSL_RSA_PUBLIC_ONLY @@ -5795,12 +6251,13 @@ exit_rsa_verify: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), - 1, ×, ntimes, &pending)) { + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&rsaKey[i]), + 1, ×, ntimes, &pending)) { ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i], - rsaKeySz/8, &rsaKey[i]); + rsaKeySz/8, &rsaKey[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&rsaKey[i]), + BENCH_ASYNC_GET_DEV(&rsaKey[i]), 1, ×, &pending)) { goto exit_rsa_pub; } @@ -5810,8 +6267,8 @@ exit_rsa_verify: count += times; } while (bench_stats_check(start)); exit_rsa_pub: - bench_stats_asym_finish("RSA", rsaKeySz, desc[1], useDeviceID, count, - start, ret); + bench_stats_asym_finish("RSA", rsaKeySz, desc[1], + useDeviceID, count, start, ret); #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */ } else { @@ -5824,13 +6281,14 @@ exit_rsa_pub: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), - 1, ×, ntimes, &pending)) { + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&rsaKey[i]), + 1, ×, ntimes, &pending)) { ret = wc_RsaSSL_Sign(message, len, enc[i], rsaKeySz/8, &rsaKey[i], &gRng); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&rsaKey[i]), - 1, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&rsaKey[i]), + 1, ×, &pending)) { goto exit_rsa_sign; } } @@ -5839,8 +6297,8 @@ exit_rsa_pub: count += times; } while (bench_stats_check(start)); exit_rsa_sign: - bench_stats_asym_finish("RSA", rsaKeySz, desc[4], useDeviceID, count, start, - ret); + bench_stats_asym_finish("RSA", rsaKeySz, desc[4], useDeviceID, + count, start, ret); if (ret < 0) { goto exit; @@ -5858,8 +6316,9 @@ exit_rsa_sign: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), - 1, ×, ntimes, &pending)) { + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&rsaKey[i]), + 1, ×, ntimes, &pending)) { #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \ !defined(WOLFSSL_RSA_PUBLIC_ONLY) ret = wc_RsaSSL_Verify(enc[i], idx, out[i], @@ -5868,22 +6327,24 @@ exit_rsa_sign: XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig)); idx = sizeof(rsa_2048_sig); out[i] = NULL; - ret = wc_RsaSSL_VerifyInline(enc[i], idx, &out[i], - &rsaKey[i]); - if (ret > 0) + ret = wc_RsaSSL_VerifyInline(enc[i], idx, + &out[i], &rsaKey[i]); + if (ret > 0) { ret = 0; + } + #elif defined(USE_CERT_BUFFERS_3072) XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig)); idx = sizeof(rsa_3072_sig); out[i] = NULL; - ret = wc_RsaSSL_VerifyInline(enc[i], idx, &out[i], - &rsaKey[i]); + ret = wc_RsaSSL_VerifyInline(enc[i], idx, + &out[i], &rsaKey[i]); if (ret > 0) ret = 0; #endif if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&rsaKey[i]), - 1, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&rsaKey[i]), + 1, ×, &pending)) { goto exit_rsa_verifyinline; } } @@ -5891,9 +6352,10 @@ exit_rsa_sign: } /* for times */ count += times; } while (bench_stats_check(start)); + exit_rsa_verifyinline: - bench_stats_asym_finish("RSA", rsaKeySz, desc[5], useDeviceID, count, - start, ret); + bench_stats_asym_finish("RSA", rsaKeySz, desc[5], + useDeviceID, count, start, ret); } exit: @@ -5962,8 +6424,8 @@ void bench_rsa(int useDeviceID) #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY) /* decode the private key */ idx = 0; - if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx, &rsaKey[i], - (word32)bytes)) != 0) { + if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx, + &rsaKey[i], (word32)bytes)) != 0) { printf("wc_RsaPrivateKeyDecode failed! %d\n", ret); goto exit_bench_rsa; } @@ -6112,15 +6574,23 @@ void bench_dh(int useDeviceID) #endif #endif - WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); - WC_DECLARE_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT); - WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); - WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT); - WC_DECLARE_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING, + BENCH_DH_KEY_SIZE, HEAP_HINT); + WC_DECLARE_VAR(pub2, byte, + BENCH_DH_KEY_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING, + BENCH_DH_KEY_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING, + BENCH_DH_PRIV_SIZE, HEAP_HINT); + WC_DECLARE_VAR(priv2, byte, + BENCH_DH_PRIV_SIZE, HEAP_HINT); - WC_INIT_ARRAY(pub, byte, BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); - WC_INIT_ARRAY(agree, byte, BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); - WC_INIT_ARRAY(priv, byte, BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT); + WC_INIT_ARRAY(pub, byte, + BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); + WC_INIT_ARRAY(agree, byte, + BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); + WC_INIT_ARRAY(priv, byte, + BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT); #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC if (pub[0] == NULL || pub2 == NULL || agree[0] == NULL || priv[0] == NULL || priv2 == NULL) { @@ -6200,8 +6670,8 @@ void bench_dh(int useDeviceID) /* setup key */ if (!use_ffdhe) { #ifdef NO_ASN - ret = wc_DhSetKey(&dhKey[i], dh_p, sizeof(dh_p), dh_g, - sizeof(dh_g)); + ret = wc_DhSetKey(&dhKey[i], dh_p, + sizeof(dh_p), dh_g, sizeof(dh_g)); #else idx = 0; ret = wc_DhKeyDecode(tmp, &idx, &dhKey[i], (word32)bytes); @@ -6210,8 +6680,8 @@ void bench_dh(int useDeviceID) #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) #ifdef HAVE_PUBLIC_FFDHE else if (params != NULL) { - ret = wc_DhSetKey(&dhKey[i], params->p, params->p_len, params->g, - params->g_len); + ret = wc_DhSetKey(&dhKey[i], params->p, params->p_len, + params->g, params->g_len); } #else else if (paramName != 0) { @@ -6235,13 +6705,15 @@ void bench_dh(int useDeviceID) for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&dhKey[i]), - 0, ×, genTimes, &pending)) { + 0, ×, genTimes, &pending)) { privSz[i] = BENCH_DH_PRIV_SIZE; pubSz[i] = BENCH_DH_KEY_SIZE; - ret = wc_DhGenerateKeyPair(&dhKey[i], &gRng, priv[i], &privSz[i], - pub[i], &pubSz[i]); + ret = wc_DhGenerateKeyPair(&dhKey[i], &gRng, + priv[i], &privSz[i], + pub[i], &pubSz[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&dhKey[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&dhKey[i]), + 0, ×, &pending)) { goto exit_dh_gen; } } @@ -6251,7 +6723,8 @@ void bench_dh(int useDeviceID) } while (bench_stats_check(start)); PRIVATE_KEY_LOCK(); exit_dh_gen: - bench_stats_asym_finish("DH", dhKeySz, desc[2], useDeviceID, count, start, ret); + bench_stats_asym_finish("DH", dhKeySz, desc[2], + useDeviceID, count, start, ret); if (ret < 0) { goto exit; @@ -6259,7 +6732,8 @@ exit_dh_gen: /* Generate key to use as other public */ PRIVATE_KEY_UNLOCK(); - ret = wc_DhGenerateKeyPair(&dhKey[0], &gRng, priv2, &privSz2, pub2, &pubSz2); + ret = wc_DhGenerateKeyPair(&dhKey[0], &gRng, + priv2, &privSz2, pub2, &pubSz2); PRIVATE_KEY_LOCK(); #ifdef WOLFSSL_ASYNC_CRYPT ret = wc_AsyncWait(ret, &dhKey[0].asyncDev, WC_ASYNC_FLAG_NONE); @@ -6275,9 +6749,9 @@ exit_dh_gen: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&dhKey[i]), - 0, ×, agreeTimes, &pending)) { + 0, ×, agreeTimes, &pending)) { ret = wc_DhAgree(&dhKey[i], agree[i], &agreeSz[i], priv[i], - privSz[i], pub2, pubSz2); + privSz[i], pub2, pubSz2); if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&dhKey[i]), 0, ×, &pending)) { goto exit; @@ -6288,8 +6762,10 @@ exit_dh_gen: count += times; } while (bench_stats_check(start)); PRIVATE_KEY_LOCK(); + exit: - bench_stats_asym_finish("DH", dhKeySz, desc[3], useDeviceID, count, start, ret); + bench_stats_asym_finish("DH", dhKeySz, desc[3], + useDeviceID, count, start, ret); /* cleanup */ for (i = 0; i < BENCH_MAX_PENDING; i++) { @@ -6481,8 +6957,9 @@ void bench_eccMakeKey(int useDeviceID, int curveId) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 0, - ×, agreeTimes, &pending)) { + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&genKey[i]), 0, + ×, agreeTimes, &pending)) { wc_ecc_free(&genKey[i]); ret = wc_ecc_init_ex(&genKey[i], HEAP_HINT, deviceID); @@ -6502,11 +6979,12 @@ void bench_eccMakeKey(int useDeviceID, int curveId) } /* for times */ count += times; } while (bench_stats_check(start)); + exit: (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]", wc_ecc_get_name(curveId)); - bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count, start, - ret); + bench_stats_asym_finish(name, keySize * 8, desc[2], + useDeviceID, count, start, ret); /* cleanup */ for (i = 0; i < BENCH_MAX_PENDING; i++) { @@ -6525,26 +7003,34 @@ void bench_ecc(int useDeviceID, int curveId) #ifdef HAVE_ECC_DHE ecc_key genKey2[BENCH_MAX_PENDING]; #endif + #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN) -#ifdef HAVE_ECC_VERIFY - int verify[BENCH_MAX_PENDING]; -#endif + #ifdef HAVE_ECC_VERIFY + int verify[BENCH_MAX_PENDING]; + #endif #endif + word32 x[BENCH_MAX_PENDING]; double start = 0; const char**desc = bench_desc_words[lng_index]; #ifdef HAVE_ECC_DHE - WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); + WC_DECLARE_ARRAY(shared, byte, + BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); #endif + #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN) - WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT); - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); + WC_DECLARE_ARRAY(sig, byte, + BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, + BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); #endif #ifdef HAVE_ECC_DHE - WC_INIT_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); + WC_INIT_ARRAY(shared, byte, + BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); #endif + #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN) WC_INIT_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); @@ -6602,7 +7088,7 @@ void bench_ecc(int useDeviceID, int curveId) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 1, - ×, agreeTimes, &pending)) { + ×, agreeTimes, &pending)) { x[i] = (word32)keySize; ret = wc_ecc_shared_secret(&genKey[i], &genKey2[i], shared[i], &x[i]); @@ -6618,10 +7104,11 @@ void bench_ecc(int useDeviceID, int curveId) } while (bench_stats_check(start)); PRIVATE_KEY_UNLOCK(); exit_ecdhe: - (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]", wc_ecc_get_name(curveId)); + (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]", + wc_ecc_get_name(curveId)); - bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count, start, - ret); + bench_stats_asym_finish(name, keySize * 8, desc[3], + useDeviceID, count, start, ret); if (ret < 0) { goto exit; @@ -6646,26 +7133,32 @@ exit_ecdhe: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 1, - ×, agreeTimes, &pending)) { - if (genKey[i].state == 0) + ×, agreeTimes, &pending)) { + + if (genKey[i].state == 0) { x[i] = ECC_MAX_SIG_SIZE; + } + ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i], - &x[i], &gRng, &genKey[i]); + &x[i], &gRng, &genKey[i]); + if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 1, ×, &pending)) { goto exit_ecdsa_sign; } - } + } /* bench_async_check */ } /* for i */ } /* for times */ count += times; } while (bench_stats_check(start)); -exit_ecdsa_sign: - (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]", wc_ecc_get_name(curveId)); - bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count, start, - ret); +exit_ecdsa_sign: + (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]", + wc_ecc_get_name(curveId)); + + bench_stats_asym_finish(name, keySize * 8, desc[4], + useDeviceID, count, start, ret); if (ret < 0) { goto exit; @@ -6682,26 +7175,33 @@ exit_ecdsa_sign: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 1, - ×, agreeTimes, &pending)) { - if (genKey[i].state == 0) + ×, agreeTimes, &pending)) { + if (genKey[i].state == 0) { verify[i] = 0; + } + ret = wc_ecc_verify_hash(sig[i], x[i], digest[i], - (word32)keySize, &verify[i], &genKey[i]); + (word32)keySize, &verify[i], + &genKey[i]); + if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&genKey[i]), 1, ×, - &pending)) { + BENCH_ASYNC_GET_DEV(&genKey[i]), + 1, ×, + &pending)) { goto exit_ecdsa_verify; } - } + } /* if bench_async_check */ } /* for i */ } /* for times */ count += times; } while (bench_stats_check(start)); -exit_ecdsa_verify: - (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]", wc_ecc_get_name(curveId)); - bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count, start, - ret); +exit_ecdsa_verify: + (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]", + wc_ecc_get_name(curveId)); + + bench_stats_asym_finish(name, keySize * 8, desc[5], + useDeviceID, count, start, ret); #endif /* HAVE_ECC_VERIFY */ #endif /* !NO_ASN && HAVE_ECC_SIGN */ @@ -6795,8 +7295,8 @@ void bench_eccEncrypt(int curveId) do { for (i = 0; i < ntimes; i++) { /* encrypt msg to B */ - ret = wc_ecc_encrypt(&userA, &userB, msg, sizeof(msg), out, &outSz, - NULL); + ret = wc_ecc_encrypt(&userA, &userB, msg, sizeof(msg), + out, &outSz, NULL); if (ret != 0) { printf("wc_ecc_encrypt failed! %d\n", ret); goto exit_enc; @@ -6804,8 +7304,10 @@ void bench_eccEncrypt(int curveId) } count += i; } while (bench_stats_check(start)); + exit_enc: - (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]", wc_ecc_get_name(curveId)); + (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]", + wc_ecc_get_name(curveId)); bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret); bench_stats_start(&count, &start); @@ -7313,6 +7815,7 @@ void bench_eccsi(void) for (i = 0; i < genTimes; i++) { ret = wc_VerifyEccsiHash(&genKey, WC_HASH_TYPE_SHA256, msg, sizeof(msg), sig, sigSz, &verified); + if (ret != 0 || !verified) { printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret, verified); @@ -7455,15 +7958,17 @@ void bench_sakke(void) bench_stats_start(&count, &start); do { for (i = 0; i < genTimes; i++) { - ret = wc_MakeSakkeEncapsulatedSSV(&genKey, WC_HASH_TYPE_SHA256, ssv, - sizeof(ssv), auth, &authSz); + ret = wc_MakeSakkeEncapsulatedSSV(&genKey, + WC_HASH_TYPE_SHA256, + ssv, sizeof(ssv), auth, &authSz); if (ret != 0) { printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret); break; } - } + } /* for */ count += i; } while (bench_stats_check(start)); + bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1", 0, count, start, 0); @@ -7498,8 +8003,9 @@ void bench_sakke(void) bench_stats_start(&count, &start); do { for (i = 0; i < genTimes; i++) { - ret = wc_MakeSakkeEncapsulatedSSV(&genKey, WC_HASH_TYPE_SHA256, ssv, - sizeof(ssv), auth, &authSz); + ret = wc_MakeSakkeEncapsulatedSSV(&genKey, + WC_HASH_TYPE_SHA256, ssv, + sizeof(ssv), auth, &authSz); if (ret != 0) { printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret); break; @@ -7507,6 +8013,7 @@ void bench_sakke(void) } count += i; } while (bench_stats_check(start)); + bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0, count, start, 0); @@ -7527,6 +8034,7 @@ void bench_sakke(void) if (ret != 0) break; count += i; } while (bench_stats_check(start)); + bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0, count, start, 0); @@ -7856,7 +8364,8 @@ void bench_falconKeySign(byte level) } while (bench_stats_check(start)); if (ret == 0) { - bench_stats_asym_finish("FALCON", level, desc[4], 0, count, start, ret); + bench_stats_asym_finish("FALCON", level, desc[4], 0, + count, start, ret); } bench_stats_start(&count, &start); @@ -7877,7 +8386,8 @@ void bench_falconKeySign(byte level) } while (bench_stats_check(start)); if (ret == 0) { - bench_stats_asym_finish("FALCON", level, desc[5], 0, count, start, ret); + bench_stats_asym_finish("FALCON", level, desc[5], + 0, count, start, ret); } wc_falcon_free(&key); @@ -7986,8 +8496,8 @@ void bench_dilithiumKeySign(byte level, byte sym) for (i = 0; i < agreeTimes; i++) { if (ret == 0) { int verify = 0; - ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg), &verify, - &key); + ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg), + &verify, &key); if (ret != 0 || verify != 1) { printf("wc_dilithium_verify_msg failed %d, verify %d\n", @@ -8210,7 +8720,7 @@ void bench_sphincsKeySign(byte level, byte optim) #include "task.h" #if defined(WOLFSSL_ESPIDF) - /* proto type definition */ + /* prototype definition */ int construct_argv(); extern char* __argv[22]; #endif @@ -8271,7 +8781,9 @@ void bench_sphincsKeySign(byte level, byte optim) #elif defined(WOLFSSL_DEOS) double current_time(int reset) { - const uint32_t systemTickTimeInHz = 1000000 / systemTickInMicroseconds(); + const uint32_t systemTickTimeInHz + = 1000000 / systemTickInMicroseconds(); + const volatile uint32_t *systemTickPtr = systemTickPointer(); (void)reset; @@ -8338,9 +8850,11 @@ void bench_sphincsKeySign(byte level, byte optim) #elif defined(WOLFSSL_XILINX) #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ - #define COUNTS_PER_SECOND XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ + #define COUNTS_PER_SECOND \ + XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ #else - #define COUNTS_PER_SECOND XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ + #define COUNTS_PER_SECOND \ + XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ #endif double current_time(int reset) @@ -8422,17 +8936,27 @@ void bench_sphincsKeySign(byte level, byte optim) #if defined(HAVE_GET_CYCLES) -static WC_INLINE word64 get_intel_cycles(void) -{ - unsigned int lo_c, hi_c; - __asm__ __volatile__ ( - "cpuid\n\t" - "rdtsc" - : "=a"(lo_c), "=d"(hi_c) /* out */ - : "a"(0) /* in */ - : "%ebx", "%ecx"); /* clobber */ - return ((word64)lo_c) | (((word64)hi_c) << 32); -} + #if defined(WOLFSSL_ESPIDF) + static WC_INLINE word64 get_xtensa_cycles(void) + { + return xthal_get_ccount_ex(); + } + + /* implement other architectures here */ + + #else + static WC_INLINE word64 get_intel_cycles(void) + { + unsigned int lo_c, hi_c; + __asm__ __volatile__ ( + "cpuid\n\t" + "rdtsc" + : "=a"(lo_c), "=d"(hi_c) /* out */ + : "a"(0) /* in */ + : "%ebx", "%ecx"); /* clobber */ + return ((word64)lo_c) | (((word64)hi_c) << 32); + } + #endif #endif /* HAVE_GET_CYCLES */ @@ -8465,9 +8989,8 @@ static void print_alg(const char* str, int* line) *line = 13; } *line += optLen; - printf(" %s", str); } -#endif +#endif /* WOLFSSL_BENCHMARK_ALL */ /* Display the usage options of the benchmark program. */ static void Usage(void) @@ -8558,9 +9081,9 @@ static void Usage(void) #endif /* HAVE_PQC */ #endif /* !WOLFSSL_BENCHMARK_ALL */ e++; - printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */ - printf("%s", bench_Usage_msg1[lng_index][e++]); /* option */ - printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks */ + printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */ + printf("%s", bench_Usage_msg1[lng_index][e++]); /* option */ + printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks */ #ifdef WC_ENABLE_BENCH_THREADING printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads */ #endif @@ -8581,19 +9104,34 @@ static int string_matches(const char* arg, const char* str) } #endif /* MAIN_NO_ARGS */ +/* +** ---------------------------------------------------------------------------- +** determine how the benchmarks are called, the function name varies: +** ---------------------------------------------------------------------------- +*/ #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION) -#if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE) -int wolf_benchmark_task(void) -#elif defined(MAIN_NO_ARGS) -int main() -#else -int main(int argc, char** argv) -#endif + #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE) + + /* for some environments, we'll call a function wolf_benchmark_task: */ + int wolf_benchmark_task(void) + + #elif defined(MAIN_NO_ARGS) + + /* otherwise we'll use main() with no arguments as desired: */ + int main() + + #else + + /* else we'll be calling main with default arg parameters */ + int main(int argc, char** argv) + + #endif { -#ifdef WOLFSSL_ESPIDF - int argc = construct_argv(); - char** argv = (char**)__argv; -#endif + #ifdef WOLFSSL_ESPIDF + int argc = construct_argv(); + char** argv = (char**)__argv; + #endif + return wolfcrypt_benchmark_main(argc, argv); } #endif /* NO_MAIN_DRIVER && NO_MAIN_FUNCTION */ @@ -8601,11 +9139,12 @@ int main(int argc, char** argv) int wolfcrypt_benchmark_main(int argc, char** argv) { int ret = 0; + #ifndef MAIN_NO_ARGS int optMatched; -#ifndef WOLFSSL_BENCHMARK_ALL - int i; -#endif + #ifndef WOLFSSL_BENCHMARK_ALL + int i; + #endif #endif benchmark_static_init(1); @@ -8619,9 +9158,9 @@ int wolfcrypt_benchmark_main(int argc, char** argv) #ifndef MAIN_NO_ARGS while (argc > 1) { if (string_matches(argv[1], "-?")) { - if(--argc>1){ + if (--argc > 1) { lng_index = XATOI((++argv)[1]); - if(lng_index<0||lng_index>1) { + if (lng_index<0 || lng_index>1) { lng_index = 0; } } @@ -8631,11 +9170,11 @@ int wolfcrypt_benchmark_main(int argc, char** argv) else if (string_matches(argv[1], "-lng")) { argc--; argv++; - if(argc>1) { + if (argc > 1) { lng_index = XATOI(argv[1]); - if(lng_index<0||lng_index>1){ + if (lng_index<0 || lng_index>1) { printf("invalid number(%d) is specified. [ :0-1]\n", - lng_index); + lng_index); lng_index = 0; } } @@ -8691,6 +9230,7 @@ int wolfcrypt_benchmark_main(int argc, char** argv) csv_format = 1; } #endif + #ifdef WC_ENABLE_BENCH_THREADING else if (string_matches(argv[1], "-threads")) { argc--; @@ -8801,6 +9341,13 @@ int wolfcrypt_benchmark_main(int argc, char** argv) } #endif /* MAIN_NO_ARGS */ +#if defined(WOLFSSL_BENCHMARK_FIXED_CSV) + /* when defined, we'll always output CSV regardless of params. + ** this is typically convenient in embedded environments. + */ + csv_format = 1; +#endif + #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT) if (g_threadCount > 1) { ret = benchmark_test_threaded(NULL);