diff --git a/wolfcrypt/benchmark/README.md b/wolfcrypt/benchmark/README.md index ecd75d4d5..69940236e 100644 --- a/wolfcrypt/benchmark/README.md +++ b/wolfcrypt/benchmark/README.md @@ -7,6 +7,16 @@ 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 + + ## Usage ```sh diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 8ac69e68f..8e3443ca7 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -27,15 +27,31 @@ #include #endif +/* 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) + + #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 +88,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 +125,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 +169,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 +984,88 @@ 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 unsigned long long begin_cycles; + static THREAD_LS_T unsigned long long total_cycles; + /* the return value */ + static THREAD_LS_T unsigned long long _xthal_get_ccount_ex = 0; + + /* the last value seen, adjusted for an overflow */ + static THREAD_LS_T unsigned long long _xthal_get_ccount_last = 0; + + /* TAG for ESP_LOGx() */ + static char * TAG = "wolfssl_benchmark"; + + #define HAVE_GET_CYCLES + #define INIT_CYCLE_COUNTER + + /* WARNING the hal UINT xthal_get_ccount() quietly rolls over. */ + #define BEGIN_ESP_CYCLES begin_cycles = (xthal_get_ccount_ex()); + + /* since it rolls over, we have something that will tolerate one */ + #define END_ESP_CYCLES \ + ESP_LOGV(TAG,"%llu - %llu", \ + xthal_get_ccount_ex(), \ + begin_cycles \ + ); \ + total_cycles = (xthal_get_ccount_ex() - 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. + */ + unsigned long long xthal_get_ccount_ex() + { + /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */ + + /* the currently observed clock counter value */ + unsigned long long 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 += (unsigned long long)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; + } #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 +1145,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 @@ -1079,6 +1175,7 @@ static const char* bench_result_words2[][5] = { static volatile int g_threadCount; #endif +/* WOLFSSL_ASYNC_CRYPT */ #ifdef WOLFSSL_ASYNC_CRYPT static WOLF_EVENT_QUEUE eventQueue; @@ -1242,10 +1339,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; } @@ -1254,6 +1353,7 @@ static const char* bench_result_words2[][5] = { } } #endif + #ifndef BENCH_CIPHER_ADD #define BENCH_CIPHER_ADD 0 #endif @@ -1281,30 +1381,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 */ @@ -1375,9 +1478,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, @@ -1562,7 +1665,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) @@ -1570,21 +1681,124 @@ 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) ) + *blocks /= (1000UL * 1000UL * 1000UL); + rt = "GiB"; + +#elif ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) \ + || defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB) ) + *blocks /= (1024UL * 1024UL); + rt = "MiB"; + +#elif ( defined (WOLFSSL_BENCHMARK_FIXED_UNITS_K) \ + || defined (WOLFSSL_BENCHMARK_FIXED_UNITS_KB)) + *blocks /= 1024; + rt = "KiB"; + +#elif ( defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B) \ + || defined (WOLFSSL_BENCHMARK_FIXED_UNITS_BB) ) + (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) \ + || defined (WOLFSSL_BENCHMARK_FIXED_UNITS_BB) ) + (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 @@ -1605,34 +1819,15 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, int count, } } + /* 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) { @@ -1642,44 +1837,108 @@ 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 + #ifdef WOLFSSL_ESPIDF + unsigned long bytes_processed; + #else word64 bytes_processed; - if (blockType[0] == 'K') - bytes_processed = (word64)(blocks * (base2 ? 1024. : 1000.)); - else if (blockType[0] == 'M') + #endif + 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; + } + else if (blockType[0] == 'G') { + bytes_processed = + (word64)(blocks * (base2 ? (1024. * 1024. * 1024.) + : (1000. * 1000. * 1000.) + ) + ); + } + else { + bytes_processed = + (word64)blocks; + } #endif - if (blockType[0] == 'K') + if (blockType[0] == 'K') { persec /= base2 ? 1024. : 1000.; - else if (blockType[0] == 'b') + } + else if (blockType[0] == 'M') { persec /= base2 ? (1024. * 1024.) : (1000. * 1000.); + } + else if (blockType[0] == 'G') { + persec /= base2 ? (1024. * 1024. * 1024.) + : (1000. * 1000. * 1000.); + } + else { + /* no scale needed for bytes */ + } + #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, + /* note this codepath brings in all the fields from the non-CSV case. */ + #ifdef WOLFSSL_ESPIDF + #ifndef HAVE_GET_CYCLES + #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF" + #endif + ESP_LOGI(TAG, "sym,%s,%s,%lu,%f,%f,%llu,", desc, BENCH_ASYNC_GET_NAME(useDeviceID), - bytes_processed, total, persec, total_cycles); + bytes_processed, total, persec, total_cycles); + #else + #ifdef HAVE_GET_CYCLES + (void)XSNPRINTF(msg, sizeof(msg), "sym,%s,%s,%lu,%f,%f,%lu,", desc, + BENCH_ASYNC_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); + #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_ASYNC_GET_NAME(useDeviceID), blocks, blockType, - word[0], total, word[1], persec, blockType, total_cycles); + 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" + ",", + 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_ASYNC_GET_NAME(useDeviceID), blocks, blockType, word[0], total, word[1], persec, blockType); #endif + +#ifdef WOLFSSL_ESPIDF + SHOW_ESP_CYCLES(msg, sizeof(msg), countSz); +#else SHOW_INTEL_CYCLES(msg, sizeof(msg), countSz); - } +#endif + } /* not CSV format */ + printf("%s", msg); /* show errors */ @@ -1697,7 +1956,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) || \ @@ -1721,7 +1980,11 @@ 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) @@ -1745,23 +2008,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_ASYNC_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," @@ -1788,7 +2069,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) @@ -1799,13 +2080,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; @@ -1815,7 +2096,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) @@ -1828,7 +2113,8 @@ 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," + printf("%s", + "\"pq_asym\",Algorithm,avg ms,ops/sec,ops,secs,cycles," "cycles/op\n"); #else printf("\nPost Quantum Asymmetric Ciphers:\n\n"); @@ -1845,7 +2131,8 @@ static void bench_stats_pq_asym_finish(const char* algo, int useDeviceID, int co (void)XSNPRINTF(msg, sizeof(msg), "%s %.3f,%.3f,\n", algo, milliEach, opsSec); #endif - } else { + } + else { #ifdef GENERATE_MACHINE_PARSEABLE_REPORT (void)XSNPRINTF(msg, sizeof(msg), "%-18s %s %6d %s %5.3f %s, %s %5.3f ms," @@ -1854,8 +2141,9 @@ 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_ASYNC_GET_NAME(useDeviceID), + (void)XSNPRINTF(msg, sizeof(msg), + "%-18s %s %6d %s %5.3f %s, %s %5.3f ms," + " %.3f %s\n", algo, BENCH_ASYNC_GET_NAME(useDeviceID), count, word[0], total, word[1], word[2], milliEach, opsSec, word[3]); #endif } @@ -1867,7 +2155,8 @@ 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; @@ -1890,9 +2179,10 @@ static WC_INLINE void bench_stats_free(void) bench_stats_tail = NULL; #endif } -/******************************************************************************/ + +/*****************************************************************************/ /* End Stats Functions */ -/******************************************************************************/ +/*****************************************************************************/ static void* benchmarks_do(void* args) @@ -1968,8 +2258,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); @@ -1983,8 +2275,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); @@ -2638,8 +2933,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); } @@ -2649,6 +2945,7 @@ int benchmark_init(void) printf("%swolfCrypt_Init failed %d\n", err_prefix, ret); return EXIT_FAILURE; } + #ifdef WOLFSSL_SECO_CAAM if (devId == WOLFSSL_SECO_DEVID && wc_SECO_OpenHSM(SECO_KEY_STORE_ID, SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE) @@ -2671,9 +2968,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 @@ -2763,7 +3062,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++) { @@ -2798,6 +3098,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) { @@ -2880,7 +3189,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; @@ -2901,7 +3211,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) { @@ -2935,12 +3246,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; } } @@ -2948,8 +3259,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; @@ -2973,12 +3286,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; } } @@ -2987,7 +3300,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 */ @@ -3018,8 +3332,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; @@ -3076,7 +3391,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, @@ -3095,7 +3410,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; } } @@ -3104,7 +3419,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 */ @@ -3130,7 +3446,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, @@ -3149,7 +3465,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; } } @@ -3157,8 +3473,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; @@ -3185,7 +3503,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 @@ -3245,7 +3564,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; @@ -3281,7 +3601,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 @@ -3290,7 +3610,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; } } @@ -3321,7 +3641,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 @@ -3330,7 +3650,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; } } @@ -3369,7 +3689,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; @@ -3412,7 +3733,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; @@ -3520,8 +3842,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; @@ -3533,7 +3855,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; } @@ -3593,13 +3915,15 @@ void bench_aesccm(int dummy) bench_stats_start(&count, &start); do { for (i = 0; i < numBlocks; i++) { - ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size, - bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ, - bench_additional, aesAuthAddSz); + ret |= wc_AesCcmEncrypt(&enc, bench_cipher, + bench_plain, bench_size, + bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ, + bench_additional, aesAuthAddSz); } count += i; } while (bench_stats_check(start)); - bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), 0, count, bench_size, start, ret); + bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), + 0, count, bench_size, start, ret); if (ret != 0) { printf("wc_AesCcmEncrypt failed, ret = %d\n", ret); goto exit; @@ -3608,13 +3932,15 @@ void bench_aesccm(int dummy) bench_stats_start(&count, &start); do { for (i = 0; i < numBlocks; i++) { - ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size, - bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ, - bench_additional, aesAuthAddSz); + ret |= wc_AesCcmDecrypt(&enc, bench_plain, + bench_cipher, bench_size, + bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ, + bench_additional, aesAuthAddSz); } count += i; } while (bench_stats_check(start)); - bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), 0, count, bench_size, start, ret); + bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), 0, + count, bench_size, start, ret); if (ret != 0) { printf("wc_AesCcmEncrypt failed, ret = %d\n", ret); goto exit; @@ -3797,11 +4123,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; } } @@ -3854,11 +4181,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; } } @@ -3931,8 +4258,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)); @@ -3959,11 +4288,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; } } @@ -3977,10 +4307,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; } } @@ -4025,8 +4356,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)); @@ -4053,11 +4386,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; } } @@ -4071,10 +4405,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; } } @@ -4117,8 +4452,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)); @@ -4142,11 +4479,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; } } @@ -4159,10 +4497,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; } } @@ -4186,7 +4525,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: @@ -4204,8 +4544,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)); @@ -4232,11 +4574,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; } } @@ -4249,10 +4592,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; } } @@ -4276,7 +4620,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: @@ -4294,8 +4639,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)); @@ -4319,11 +4666,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; } } @@ -4336,10 +4684,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; } } @@ -4363,7 +4712,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: @@ -4381,8 +4731,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)); @@ -4406,11 +4758,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; } } @@ -4423,10 +4776,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; } } @@ -4450,7 +4804,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: @@ -4470,8 +4825,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)); @@ -4495,11 +4852,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; } } @@ -4512,10 +4870,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; } } @@ -4539,7 +4898,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: @@ -4557,8 +4917,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)); @@ -4582,11 +4944,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; } } @@ -4599,10 +4962,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; } } @@ -4626,7 +4990,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: @@ -4644,8 +5009,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)); @@ -4669,11 +5036,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; } } @@ -4686,10 +5054,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; } } @@ -4713,7 +5082,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: @@ -4731,8 +5101,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)); @@ -4756,11 +5128,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; } } @@ -4773,10 +5146,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; } } @@ -4800,7 +5174,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: @@ -4818,8 +5193,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)); @@ -4843,11 +5220,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; } } @@ -4860,11 +5238,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; } } @@ -4889,7 +5268,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: @@ -4907,8 +5287,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)); @@ -4932,11 +5314,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; } } @@ -4949,11 +5332,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; } } @@ -4978,7 +5362,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: @@ -5253,7 +5638,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; @@ -5276,8 +5662,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 @@ -5310,10 +5698,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; } @@ -5327,10 +5717,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; } @@ -5388,7 +5780,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"); } @@ -5522,7 +5915,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); @@ -5532,7 +5925,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; } } @@ -5541,7 +5935,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++) { @@ -5679,7 +6074,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; @@ -5692,16 +6087,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; @@ -5732,13 +6135,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; } } @@ -5747,8 +6153,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 @@ -5767,12 +6173,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; } @@ -5782,8 +6189,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 { @@ -5796,13 +6203,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; } } @@ -5811,8 +6219,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; @@ -5830,8 +6238,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], @@ -5840,22 +6249,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; } } @@ -5863,9 +6274,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: @@ -5934,8 +6346,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; } @@ -6084,15 +6496,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) { @@ -6172,8 +6592,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); @@ -6182,8 +6602,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) { @@ -6207,13 +6627,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; } } @@ -6223,7 +6645,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; @@ -6231,7 +6654,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); @@ -6247,9 +6671,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; @@ -6260,8 +6684,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++) { @@ -6460,8 +6886,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); @@ -6481,11 +6908,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++) { @@ -6504,26 +6932,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); @@ -6586,7 +7022,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]); @@ -6602,10 +7038,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; @@ -6630,26 +7067,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; @@ -6666,26 +7109,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 */ @@ -6779,8 +7229,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; @@ -6788,8 +7238,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); @@ -7286,6 +7738,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); @@ -7428,15 +7881,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); @@ -7471,8 +7926,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; @@ -7480,6 +7936,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); @@ -7500,6 +7957,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); @@ -7829,7 +8287,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); @@ -7850,7 +8309,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); @@ -7959,8 +8419,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", @@ -8183,7 +8643,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 @@ -8240,7 +8700,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; @@ -8307,9 +8769,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) @@ -8434,9 +8898,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) @@ -8527,9 +8990,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 @@ -8550,19 +9013,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 */ @@ -8570,11 +9048,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); @@ -8588,9 +9067,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; } } @@ -8600,11 +9079,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; } }