diff --git a/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.c b/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.c index 1ff49a8..49803d6 100644 --- a/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.c +++ b/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.c @@ -37,12 +37,22 @@ * when the output should be in machine-parseable format: * GENERATE_MACHINE_PARSEABLE_REPORT * + * use microseconds as the unit of time: + * BENCH_MICROSECOND + * + * display mean, max, min and sd of operation durations: + * MULTI_VALUE_STATISTICS + * * Enable tracking of the stats into an allocated linked list: * (use -print to display results): * WC_BENCH_TRACK_STATS * * set the default devId for cryptocb to the value instead of INVALID_DEVID * WC_USE_DEVID=0x1234 + * + * Turn on benchmark timing debugging (CPU Cycles, RTOS ticks, etc) + * DEBUG_WOLFSSL_BENCHMARK_TIMING + * */ @@ -127,6 +137,7 @@ #ifdef WOLFSSL_SIPHASH #include #endif + #include #ifndef NO_PWDBASED #include #endif @@ -218,7 +229,47 @@ #endif /* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */ -#define WOLFSSL_FIXED_UNITS_PER_SEC "MB/s" /* may be re-set by fixed units */ +#define WOLFSSL_FIXED_UNIT "MB" /* may be re-set by fixed units */ +#define MILLION_VALUE 1000000.0 + +#ifdef BENCH_MICROSECOND + #define WOLFSSL_FIXED_TIME_UNIT "μs" + #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB +#else + #define WOLFSSL_FIXED_TIME_UNIT "s" +#endif + +#ifdef MULTI_VALUE_STATISTICS + #define STATS_CLAUSE_SEPARATOR "" + #define DECLARE_MULTI_VALUE_STATS_VARS() double max = 0, min = 0, sum = 0,\ + squareSum = 0, prev = 0, delta;\ + int runs = 0; + #define RECORD_MULTI_VALUE_STATS() if (runs == 0) {\ + delta = current_time(0) - start;\ + min = delta;\ + max = delta;\ + }\ + else {\ + delta = current_time(0) - prev;\ + }\ + if (max < delta)\ + max = delta;\ + else if (min > delta)\ + min = delta;\ + sum += delta;\ + squareSum += delta * delta;\ + runs++;\ + prev = current_time(0) + #define RESET_MULTI_VALUE_STATS_VARS() prev = 0;\ + runs = 0;\ + sum = 0;\ + squareSum = 0 +#else + #define STATS_CLAUSE_SEPARATOR "\n" + #define DECLARE_MULTI_VALUE_STATS_VARS() + #define RECORD_MULTI_VALUE_STATS() WC_DO_NOTHING + #define RESET_MULTI_VALUE_STATS_VARS() WC_DO_NOTHING +#endif #ifdef WOLFSSL_NO_FLOAT_FMT #define FLT_FMT "%0ld,%09lu" @@ -250,20 +301,46 @@ #endif /* WOLFSSL_NO_FLOAT_FMT */ #ifdef WOLFSSL_ESPIDF - #if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) + #ifdef configTICK_RATE_HZ + /* Define CPU clock cycles per tick of FreeRTOS clock + * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240 + * configTICK_RATE_HZ is typically 100 or 1000. + **/ + #define CPU_TICK_CYCLES ( \ + (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \ + / configTICK_RATE_HZ \ + ) + #endif + #if defined(CONFIG_IDF_TARGET_ESP32C2) #include "driver/gptimer.h" static gptimer_handle_t esp_gptimer = NULL; static gptimer_config_t esp_timer_config = { .clk_src = GPTIMER_CLK_SRC_DEFAULT, .direction = GPTIMER_COUNT_UP, - .resolution_hz = CONFIG_XTAL_FREQ * 1000000, + .resolution_hz = CONFIG_XTAL_FREQ * 100000, }; + #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \ + defined(CONFIG_IDF_TARGET_ESP32C6) + #include + #include "driver/gptimer.h" + #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG + #define RESOLUTION_SCALE 100 + static gptimer_handle_t esp_gptimer = NULL; + static gptimer_config_t esp_timer_config = { + .clk_src = GPTIMER_CLK_SRC_DEFAULT, + .direction = GPTIMER_COUNT_UP, + .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * (MILLION_VALUE / RESOLUTION_SCALE), /* CONFIG_XTAL_FREQ = 40, CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */ + }; + #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */ + #elif defined(CONFIG_IDF_TARGET_ESP32) || \ defined(CONFIG_IDF_TARGET_ESP32S2) || \ defined(CONFIG_IDF_TARGET_ESP32S3) #include + #elif defined(CONFIG_IDF_TARGET_ESP32H2) + #else - #error "CONFIG_IDF_TARGET not implemented" + /* Other platform */ #endif #include #endif /* WOLFSSL_ESPIDF */ @@ -534,6 +611,9 @@ #define BENCH_PBKDF2 0x00000100 #define BENCH_SIPHASH 0x00000200 +/* KDF algorithms */ +#define BENCH_SRTP_KDF 0x00000001 + /* Asymmetric algorithms. */ #define BENCH_RSA_KEYGEN 0x00000001 #define BENCH_RSA 0x00000002 @@ -619,6 +699,8 @@ static word32 bench_cipher_algs = 0; static word32 bench_digest_algs = 0; /* MAC algorithms to benchmark. */ static word32 bench_mac_algs = 0; +/* KDF algorithms to benchmark. */ +static word32 bench_kdf_algs = 0; /* Asymmetric algorithms to benchmark. */ static word32 bench_asym_algs = 0; /* Post-Quantum Asymmetric algorithms to benchmark. */ @@ -797,9 +879,18 @@ static const bench_alg bench_mac_opt[] = { #ifndef NO_PWDBASED { "-pbkdf2", BENCH_PBKDF2 }, #endif +#endif #ifdef WOLFSSL_SIPHASH { "-siphash", BENCH_SIPHASH }, #endif + { NULL, 0 } +}; + +/* All recognized KDF algorithm choosing command line options. */ +static const bench_alg bench_kdf_opt[] = { + { "-kdf", 0xffffffff }, +#ifdef WC_SRTP_KDF + { "-srtp-kdf", BENCH_SRTP_KDF }, #endif { NULL, 0 } }; @@ -967,7 +1058,7 @@ static int lng_index = 0; #ifndef NO_MAIN_DRIVER #ifndef MAIN_NO_ARGS -static const char* bench_Usage_msg1[][22] = { +static const char* bench_Usage_msg1[][25] = { /* 0 English */ { "-? Help, print this usage\n", " 0: English, 1: Japanese\n", @@ -999,7 +1090,10 @@ static const char* bench_Usage_msg1[][22] = { " option, but must be used after that one.\n" ), "-threads Number of threads to run\n", - "-print Show benchmark stats summary\n" + "-print Show benchmark stats summary\n", + "-hash_input Input data to use for hash benchmarking\n", + "-cipher_input Input data to use for cipher benchmarking\n", + "-min_runs Specify minimum number of operation runs\n" }, #ifndef NO_MULTIBYTE_PRINT /* 1 Japanese */ @@ -1028,7 +1122,11 @@ static const char* bench_Usage_msg1[][22] = { " ブロックサイズをバイト単位で指定します。\n", "-blocks TBD.\n", "-threads 実行するスレッド数\n", - "-print ベンチマーク統計の要約を表示する\n" + "-print ベンチマーク統計の要約を表示する\n", + /* TODO: translate below */ + "-hash_input Input data to use for hash benchmarking\n", + "-cipher_input Input data to use for cipher benchmarking\n", + "-min_runs Specify minimum number of operation runs\n" }, #endif }; @@ -1036,7 +1134,13 @@ static const char* bench_Usage_msg1[][22] = { #endif static const char* bench_result_words1[][4] = { - { "took", "seconds" , "Cycles per byte", NULL }, /* 0 English */ + { "took", +#ifdef BENCH_MICROSECOND + "microseconds" +#else + "seconds" +#endif + , "Cycles per byte", NULL }, /* 0 English */ #ifndef NO_MULTIBYTE_PRINT { "を" , "秒で処理", "1バイトあたりのサイクル数", NULL }, /* 1 Japanese */ #endif @@ -1059,6 +1163,15 @@ static const char* bench_desc_words[][15] = { #endif +#ifdef MULTI_VALUE_STATISTICS +static const char* bench_result_words3[][5] = { + /* 0 English */ + { "max duration", "min duration" , "mean duration", "sd", NULL }, + /* TODO: Add japenese version */ + { "max duration", "min duration" , "mean duration", "sd", NULL } +}; +#endif + #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX) #define HAVE_GET_CYCLES static WC_INLINE word64 get_intel_cycles(void); @@ -1067,15 +1180,15 @@ static const char* bench_desc_words[][15] = { #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles(); #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles; /* s == size in bytes that 1 count represents, normally BENCH_SIZE */ - #define SHOW_INTEL_CYCLES(b, n, s) \ - (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \ - " %s = " FLT_FMT_PREC2 "\n", \ - bench_result_words1[lng_index][2], \ - FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \ + #define SHOW_INTEL_CYCLES(b, n, s) \ + (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \ + " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \ + bench_result_words1[lng_index][2], \ + FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \ (double)total_cycles / ((word64)count*(s)))) - #define SHOW_INTEL_CYCLES_CSV(b, n, s) \ - (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC ",\n", \ - FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \ + #define SHOW_INTEL_CYCLES_CSV(b, n, s) \ + (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \ + STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \ (double)total_cycles / ((word64)count*(s)))) #elif defined(LINUX_CYCLE_COUNT) #include @@ -1100,14 +1213,16 @@ static const char* bench_desc_words[][15] = { } while (0); /* s == size in bytes that 1 count represents, normally BENCH_SIZE */ - #define SHOW_INTEL_CYCLES(b, n, s) \ - (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \ - " %s = " FLT_FMT_PREC2 "\n", \ - bench_result_words1[lng_index][2], \ - FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s))) - #define SHOW_INTEL_CYCLES_CSV(b, n, s) \ - (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \ - FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s))) + #define SHOW_INTEL_CYCLES(b, n, s) \ + (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \ + " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \ + bench_result_words1[lng_index][2], \ + FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \ + (count*s))) + #define SHOW_INTEL_CYCLES_CSV(b, n, s) \ + (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \ + STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \ + / (count*s))) #elif defined(SYNERGY_CYCLE_COUNT) #include "hal_data.h" @@ -1119,76 +1234,166 @@ static const char* bench_desc_words[][15] = { #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles; /* s == size in bytes that 1 count represents, normally BENCH_SIZE */ - #define SHOW_INTEL_CYCLES(b, n, s) \ - (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \ - " %s = " FLT_FMT_PREC2 "\n", \ - bench_result_words1[lng_index][2], \ + #define SHOW_INTEL_CYCLES(b, n, s) \ + (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \ + " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \ + bench_result_words1[lng_index][2], \ FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s))) - #define SHOW_INTEL_CYCLES_CSV(b, n, s) \ - (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \ + #define SHOW_INTEL_CYCLES_CSV(b, n, s) \ + (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \ FLT_FMT_PREC_ARGS(6, (double)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 const char* TAG = "wolfssl_benchmark"; - #define HAVE_GET_CYCLES - #define INIT_CYCLE_COUNTER - static WC_INLINE word64 get_xtensa_cycles(void); + static THREAD_LS_T word64 begin_cycles; + static THREAD_LS_T word64 begin_cycles_ticks; + static THREAD_LS_T word64 end_cycles; + static THREAD_LS_T word64 total_cycles; - /* WARNING the hal UINT xthal_get_ccount() quietly rolls over. */ - #define BEGIN_ESP_CYCLES begin_cycles = (get_xtensa_cycles()); + /* the return value, as a global var */ + static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0; + + /* the last value seen, adjusted for an overflow, as a global var */ + static THREAD_LS_T word64 _esp_cpu_count_last = 0; + + static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */ + + /* esp_get_cpu_benchmark_cycles(void): + * + * Architecture-independant CPU clock counter. + * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */ + static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void); + + /* Some vars for debugging, compare ticks to cycles */ + #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG + static THREAD_LS_T word64 _esp_cpu_timer_last = 0; + static THREAD_LS_T word64 _esp_cpu_timer_diff = 0; + static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0; + static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0; + #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */ + + /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */ + #if ESP_IDF_VERSION_MAJOR >= 5 + /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */ + #define HAVE_GET_CYCLES + #define INIT_CYCLE_COUNTER do { \ + ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \ + esp_cpu_set_cycle_count(0); \ + } while (0); + #else + #define HAVE_GET_CYCLES + #define INIT_CYCLE_COUNTER do { \ + ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \ + } while (0); + #endif + + #define BEGIN_ESP_CYCLES do { \ + ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \ + begin_cycles = esp_get_cpu_benchmark_cycles(); \ + begin_cycles_ticks = xTaskGetTickCount(); \ + } while (0); /* 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 END_ESP_CYCLES \ + end_cycles = esp_get_cpu_benchmark_cycles(); \ + ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \ + end_cycles, \ + begin_cycles \ + ); \ + total_cycles = (end_cycles - begin_cycles); #define SHOW_ESP_CYCLES(b, n, s) \ - (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \ - " %s = " FLT_FMT_PREC2 "\n", \ - bench_result_words1[lng_index][2], \ - FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \ - ) + (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \ + " %s = " FLT_FMT_PREC2 "\n", \ + bench_result_words1[lng_index][2], \ + FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \ + ) #define SHOW_ESP_CYCLES_CSV(b, n, s) \ - (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \ - FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s))) + (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \ + FLT_FMT_PREC_ARGS(6, (double)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. - */ - uint64_t xthal_get_ccount_ex() - { - /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */ - - /* the currently observed clock counter value */ - #if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) - uint64_t thisVal = 0; - ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisVal)); - #else - /* reminder unsupported CONFIG_IDF_TARGET captured above */ - uint64_t thisVal = xthal_get_ccount(); - #endif - /* if the current value is less than the previous value, - ** we likely overflowed at least once. - */ - if (thisVal < _xthal_get_ccount_last) + #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG + /* 64 bit, unisgned, absolute difference + * used in CPU cycle counter debug calcs. */ + static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y) { - /* Warning: we assume the return type of xthal_get_ccount() - ** will always be unsigned int to add UINT_MAX. + uint64_t ret; + ret = (x > y) ? (x - y) : (y - x); + return ret; + } + #endif + + /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to + ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or + ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow + ** at least once during full benchmark tests. + ** + ** To test timing overflow, add a delay longer than max cycles: + ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) ); + */ + uint64_t esp_get_cycle_count_ex() + { + /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */ + /* unsigned int max = 4,294,967,295 */ + uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */ + uint64_t thisIncrement = 0; /* The adjusted increment amount. */ + uint64_t expected_diff = 0; /* FreeRTOS esimated expected CPU diff. */ + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + uint32_t tickCount = 0; /* Currrent rtos tick counter. */ + uint32_t tickDiff = 0; /* Tick difference from last check. */ + uint32_t tickBeginDiff = 0; /* Tick difference from beginning. */ + #endif + + #if defined(CONFIG_IDF_TARGET_ESP32C2) || \ + defined(CONFIG_IDF_TARGET_ESP32C3) || \ + defined(CONFIG_IDF_TARGET_ESP32C6) + + #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG + uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */ + uint64_t diffDiff = 0; /* Difference between CPU & Timer differences: + * (current - last) */ + ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal)); + thisTimerVal = thisTimerVal * RESOLUTION_SCALE; + #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */ + + thisVal = esp_cpu_get_cycle_count(); + + #elif defined(CONFIG_IDF_TARGET_ESP32H2) + thisVal = esp_cpu_get_cycle_count(); + #else + /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa? + * Calling current_time(1) to reset time causes thisVal overflow, + * on Xtensa, but not on RISC-V architecture. See also, below */ + #ifndef __XTENSA__ + thisVal = esp_cpu_get_cycle_count(); + #else + thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */ + #endif + #endif + + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + { + tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */ + tickDiff = tickCount - last_tickCount; /* ticks since bench start */ + expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */ + ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES); + ESP_LOGV(TAG, "tickCount = %lu", tickCount); + ESP_LOGV(TAG, "last_tickCount = %lu", last_tickCount); + ESP_LOGV(TAG, "tickDiff = %lu", tickDiff); + ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff); + } + #endif + + /* If either thisVal is smaller than last (overflow), and/or the + * expected value calculated from FreeRTOS tick difference that would + * have never fit into an unsigned 32 bit integer anyhow... then we + * need to adjust thisVal to save. */ + if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) ) + { + /* Warning: we assume the return type of esp_cpu_get_cycle_count() + ** will always be unsigned int (or uint32_t) to add UINT_MAX. ** ** NOTE for long duration between calls with multiple overflows: ** @@ -1199,22 +1404,113 @@ static const char* bench_desc_words[][15] = { ** 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; + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + ESP_LOGW(TAG, + "Alert: Detected xthal_get_ccount overflow at %llu, " + "adding UINT_MAX.", + thisVal); + #endif + + /* double check expected diff calc */ + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) + * tickDiff / configTICK_RATE_HZ; + ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff); + #endif + if (expected_diff > UINT_MAX) { + /* The number of cycles expected from FreeRTOS ticks is + * greater than the maximum size of an unsigned 32-bit + * integer, meaning multiple overflows occured. */ + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX); + #endif + thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */ + } + else { + thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */ + } + + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + { + tickBeginDiff = tickCount - begin_cycles_ticks; + + ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks); + ESP_LOGI(TAG, "tickDiff = %lu", tickDiff); + ESP_LOGI(TAG, "expected_diff = %llu", expected_diff); + ESP_LOGI(TAG, "tickBeginDiff = %lu", tickBeginDiff); + + ESP_LOGW(TAG, ""); + } + #endif } + else { + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal); + #endif + } /* if thisVal adjustment check */ - /* adjust our actual returned value that takes into account overflow */ - _xthal_get_ccount_ex += (thisVal - _xthal_get_ccount_last); + #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG + if (thisTimerVal < _esp_cpu_timer_last) + { + ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, " + "adding %ull", UINT_MAX); + thisTimerVal += (word64)UINT_MAX; + } + /* Check an alternate counter using a timer */ - /* all of this took some time, so reset the "last seen" value */ - #if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) - ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, - &_xthal_get_ccount_last)); - #else - _xthal_get_ccount_last = xthal_get_ccount(); - #endif - return _xthal_get_ccount_ex; + _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last); + #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */ + + /* Adjust our actual returned value that takes into account overflow, + * increment 64 bit extended total by this 32 bit differential: */ + thisIncrement = (thisVal - _esp_cpu_count_last); + + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement); + #endif + + /* Add our adjustment, taking into account overflows (see above) */ + _esp_get_cycle_count_ex += thisIncrement; + + #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG + _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt); + _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last); + diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff); + #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */ + + /* all of this took some time, so reset the "last seen" value + * for the next measurement. */ + #if defined(CONFIG_IDF_TARGET_ESP32C2) || \ + defined(CONFIG_IDF_TARGET_ESP32C3) || \ + defined(CONFIG_IDF_TARGET_ESP32C6) + { + #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG + ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, + &_esp_cpu_timer_last)); + ESP_LOGI(TAG, "thisVal = %llu", thisVal); + ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal); + ESP_LOGI(TAG, "diffDiff = %llu", diffDiff); + ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff); + #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */ + _esp_cpu_count_last = esp_cpu_get_cycle_count(); + ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last); + } + #elif defined(CONFIG_IDF_TARGET_ESP32H2) + _esp_cpu_count_last = esp_cpu_get_cycle_count(); + #else + /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa + * when resetting CPU cycle counter? FreeRTOS tick collison? + * thisVal = esp_cpu_get_cycle_count(); See also, above + * or thisVal = xthal_get_ccount(); */ + #if ESP_IDF_VERSION_MAJOR < 5 + _esp_cpu_count_last = xthal_get_ccount(); + #else + _esp_cpu_count_last = esp_cpu_get_cycle_count(); + #endif + #endif + + /* Return the 64 bit extended total from 32 bit counter. */ + return _esp_get_cycle_count_ex; } /* implement other architecture cycle counters here */ @@ -1226,8 +1522,13 @@ static const char* bench_desc_words[][15] = { #define INIT_CYCLE_COUNTER #define BEGIN_INTEL_CYCLES #define END_INTEL_CYCLES - #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n' - #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n' + #ifdef MULTI_VALUE_STATISTICS + #define SHOW_INTEL_CYCLES(b, n, s) WC_DO_NOTHING + #define SHOW_INTEL_CYCLES_CSV(b, n, s) WC_DO_NOTHING + #else + #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n' + #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n' + #endif #endif /* determine benchmark buffer to use (if NO_FILESYSTEM) */ @@ -1302,7 +1603,12 @@ static const char* bench_desc_words[][15] = { defined(HAVE_CURVE448) || defined(HAVE_ED448) || \ defined(WOLFSSL_HAVE_KYBER) static const char* bench_result_words2[][5] = { +#ifdef BENCH_MICROSECOND + { "ops took", "μsec" , "avg" , "ops/μsec", NULL }, /* 0 English + for μsec */ +#else { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */ +#endif #ifndef NO_MULTIBYTE_PRINT { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */ #endif @@ -1561,6 +1867,10 @@ static word32 bench_size = BENCH_SIZE; static int base2 = 1; static int digest_stream = 1; +#ifdef MULTI_VALUE_STATISTICS +static int minimum_runs = 0; +#endif + #ifndef NO_RSA /* Don't measure RSA sign/verify by default */ static int rsa_sign_verify = 0; @@ -1587,6 +1897,10 @@ static int csv_format = 0; /* globals for cipher tests */ static THREAD_LS_T byte* bench_plain = NULL; static THREAD_LS_T byte* bench_cipher = NULL; +#ifndef NO_FILESYSTEM +static THREAD_LS_T char* hash_input = NULL; +static THREAD_LS_T char* cipher_input = NULL; +#endif static const XGEN_ALIGN byte bench_key_buf[] = { @@ -1641,11 +1955,15 @@ static void benchmark_static_init(int force) #endif base2 = 1; digest_stream = 1; + #ifdef MULTI_VALUE_STATISTICS + minimum_runs = 0; + #endif bench_all = 1; bench_cipher_algs = 0; bench_digest_algs = 0; bench_mac_algs = 0; + bench_kdf_algs = 0; bench_asym_algs = 0; bench_pq_asym_algs = 0; bench_other_algs = 0; @@ -1754,24 +2072,33 @@ typedef enum bench_stat_type { void bench_stats_print(void) { bench_stats_t* bstat; + int digits; #ifdef WC_ENABLE_BENCH_THREADING /* protect bench_stats_head and bench_stats_tail access */ THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock)); #endif + #ifdef BENCH_MICROSECOND + digits = 5; + #else + digits = 3; + #endif + for (bstat = bench_stats_head; bstat != NULL; ) { if (bstat->type == BENCH_STAT_SYM) { - printf("%-16s%s " FLT_FMT_PREC2 " %s/s\n", bstat->desc, + printf("%-16s%s " FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT + "\n", bstat->desc, BENCH_DEVID_GET_NAME(bstat->useDeviceID), - FLT_FMT_PREC2_ARGS(8, 3, bstat->perfsec), + FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec), base2 ? "MB" : "mB"); } else { - printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/sec\n", + printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/" + WOLFSSL_FIXED_TIME_UNIT "ec\n", bstat->algo, bstat->strength, bstat->desc, BENCH_DEVID_GET_NAME(bstat->useDeviceID), - FLT_FMT_PREC_ARGS(3, bstat->perfsec)); + FLT_FMT_PREC_ARGS(digits, bstat->perfsec)); } bstat = bstat->next; @@ -1798,9 +2125,10 @@ static WC_INLINE void bench_stats_start(int* count, double* start) *start = current_time(1); #ifdef WOLFSSL_ESPIDF - ESP_LOGV(TAG, "finish total_cycles = %llu, start=" FLT_FMT, - total_cycles, FLT_FMT_ARGS(*start) ); - + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu, start=" FLT_FMT, + total_cycles, FLT_FMT_ARGS(*start) ); + #endif BEGIN_ESP_CYCLES #else BEGIN_INTEL_CYCLES @@ -1818,7 +2146,23 @@ static WC_INLINE void bench_stats_start(int* count, double* start) static WC_INLINE int bench_stats_check(double start) { - return ((current_time(0) - start) < BENCH_MIN_RUNTIME_SEC); + int ret = 0; + double this_current_time; + this_current_time = current_time(0); /* get the timestamp, no reset */ +#if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) + #if (WOLFSSL_ESPIDF) + ESP_LOGI(TAG, "bench_stats_check Current time %f, start %f", + this_current_time, start ); + #endif +#endif + + ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC +#ifdef BENCH_MICROSECOND + * 1000000 +#endif + ); + + return ret; } /* return text for units and scale the value of blocks as needed */ @@ -1828,25 +2172,25 @@ static const char* get_blocktype(double* blocks) #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" + #undef WOLFSSL_FIXED_UNIT + #define WOLFSSL_FIXED_UNIT "GB" *blocks /= (1024UL * 1024UL * 1024UL); 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" + #undef WOLFSSL_FIXED_UNIT + #define WOLFSSL_FIXED_UNIT "MB" *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" + #undef WOLFSSL_FIXED_UNIT + #define WOLFSSL_FIXED_UNIT "KB" *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" + #undef WOLFSSL_FIXED_UNIT + #define WOLFSSL_FIXED_UNIT "bytes" (void)(*blocks); /* no adjustment, just appease compiler for not used */ rt = "bytes"; #else @@ -1907,6 +2251,66 @@ static const char* get_blocktype_base10(double* blocks) return rt; } +#ifdef MULTI_VALUE_STATISTICS +static double wc_sqroot(double in) +{ + /* do 32 iterations for the sqroot */ + int iter = 32; + double root = in/3.0; + + if (in < 0.0) + return -1; + + for (int i=0; i < iter; i++) + root = (root + in / root) / 2.0; + + return root; +} + +static void bench_multi_value_stats(double max, double min, double sum, + double squareSum, int runs) +{ + double mean = 0; + double sd = 0; + char msg[WC_BENCH_MAX_LINE_LEN]; + const char** word = bench_result_words3[lng_index]; + + XMEMSET(msg, 0, sizeof(msg)); + + mean = sum / runs; + + /* Calculating standard deviation */ + sd = (squareSum / runs) - (mean * mean); + sd = wc_sqroot(sd); + + if (csv_format == 1) { + (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 "," + FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n", + FLT_FMT_PREC2_ARGS(3, 3, max), + FLT_FMT_PREC2_ARGS(3, 3, min), + FLT_FMT_PREC2_ARGS(3, 3, mean), + FLT_FMT_PREC2_ARGS(3, 3, sd)); + } + else{ + (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " " + WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " " + WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " " + WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " " + WOLFSSL_FIXED_TIME_UNIT "\n", + word[0], FLT_FMT_PREC2_ARGS(3, 3, max), + word[1], FLT_FMT_PREC2_ARGS(3, 3, min), + word[2], FLT_FMT_PREC2_ARGS(3, 3, mean), + word[3], FLT_FMT_PREC2_ARGS(3, 3, sd)); + } + printf("%s", msg); + +#ifndef WOLFSSL_SGX + XFFLUSH(stdout); +#endif + +} +#endif + /* 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, @@ -1929,8 +2333,8 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, total = current_time(0) - start; -#ifdef WOLFSSL_ESPIDF - ESP_LOGV(TAG, "%s total_cycles = %llu", desc, total_cycles); +#if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) + ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles); #endif #ifdef LINUX_RUSAGE_UTIME @@ -1946,11 +2350,15 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, #ifdef GENERATE_MACHINE_PARSEABLE_REPORT /* machine parseable CSV */ #ifdef HAVE_GET_CYCLES - printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,seconds_total," - WOLFSSL_FIXED_UNITS_PER_SEC ",cycles_total,Cycles per byte,\n"); + printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total," + WOLFSSL_FIXED_TIME_UNIT "econds_total," + WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT + ",cycles_total,Cycles per byte,"); #else - printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,seconds_total," - WOLFSSL_FIXED_UNITS_PER_SEC ",cycles_total,\n"); + printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total," + WOLFSSL_FIXED_TIME_UNIT "econds_total," + WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT + ",cycles_total,"); #endif #else /* normal CSV */ @@ -1963,14 +2371,20 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, printf("\n\nSymmetric Ciphers:\n\n"); printf("Algorithm," BENCH_DEVID_COLUMN_HEADER - WOLFSSL_FIXED_UNITS_PER_SEC ",Cycles per byte,\n"); + WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT + ",Cycles per byte,"); #else printf("\n\nSymmetric Ciphers:\n\n"); printf("Algorithm," BENCH_DEVID_COLUMN_HEADER - WOLFSSL_FIXED_UNITS_PER_SEC ", \n"); + WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT ","); #endif #endif + #ifdef MULTI_VALUE_STATISTICS + printf("max duration,min duration,mean duration,sd,\n"); + #else + printf("\n"); + #endif sym_header_printed = 1; } } @@ -2042,9 +2456,15 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, #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 */ + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu", + total_cycles); + #endif + + /* implement other cycle counters here */ + #else + /* the default cycle counter is Intel */ SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz); #endif } /* if (csv_format == 1) */ @@ -2052,31 +2472,31 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, else { #ifdef GENERATE_MACHINE_PARSEABLE_REPORT #ifdef HAVE_GET_CYCLES + (void)XSNPRINTF(msg, sizeof(msg), + "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, " + FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,", + desc, BENCH_DEVID_GET_NAME(useDeviceID), + FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType, + word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], + FLT_FMT_PREC2_ARGS(8, 3, persec), blockType, + (unsigned long) total_cycles); + #else (void)XSNPRINTF(msg, sizeof(msg), "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, " - FLT_FMT_PREC2 " %s/s, %lu cycles,", + FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",", desc, BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType, word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], - FLT_FMT_PREC2_ARGS(8, 3, persec), blockType, - (unsigned long) total_cycles); - #else - (void)XSNPRINTF(msg, sizeof(msg), - "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, " - FLT_FMT_PREC2 " %s/s,", - desc, BENCH_DEVID_GET_NAME(useDeviceID), - FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType, - word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], - FLT_FMT_PREC2_ARGS(8, 3, persec), blockType); - #endif /* HAVE_GET_CYCLES */ + FLT_FMT_PREC2_ARGS(8, 3, persec), blockType); + #endif /* HAVE_GET_CYCLES */ #else (void)XSNPRINTF(msg, sizeof(msg), - "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, " - FLT_FMT_PREC2 " %s/s", - desc, BENCH_DEVID_GET_NAME(useDeviceID), - FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType, - word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], - FLT_FMT_PREC2_ARGS(8, 3, persec), blockType); + "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, " + FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT, + desc, BENCH_DEVID_GET_NAME(useDeviceID), + FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType, + word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], + FLT_FMT_PREC2_ARGS(8, 3, persec), blockType); #endif #ifdef WOLFSSL_ESPIDF @@ -2109,7 +2529,9 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, (void)useDeviceID; (void)ret; +#ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS RESTORE_VECTOR_REGISTERS(); +#endif TEST_SLEEP(); } /* bench_stats_sym_finish */ @@ -2130,6 +2552,11 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, #endif char msg[256]; static int asym_header_printed = 0; +#ifdef BENCH_MICROSECOND + const int digits = 5; +#else + const int digits = 3; +#endif XMEMSET(msg, 0, sizeof(msg)); @@ -2163,53 +2590,144 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, opsSec = 0; } +#ifdef BENCH_MICROSECOND + milliEach = each / 1000; /* milliseconds */ +#else milliEach = each * 1000; /* milliseconds */ +#endif SLEEP_ON_ERROR(ret); + +#ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */ + (void)milliEach; + /* format and print to terminal */ if (csv_format == 1) { /* 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"); + printf("%s", "\"asym\",Algorithm,key size,operation,ops/" + WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT + "ecs,cycles,cycles/op,"); #else - printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/sec," - "ops,secs\n"); + printf("%s", "\"asym\",Algorithm,key size,operation,ops/" + WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT + "ecs,"); #endif #else printf("\n%sAsymmetric Ciphers:\n\n", info_prefix); - printf("%sAlgorithm,key size,operation,avg ms,ops/sec,\n", - info_prefix); + printf("%sAlgorithm,key size,operation,ops/" + WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix); #endif + printf("max duration,min duration,mean duration,sd,\n"); + asym_header_printed = 1; + } +#ifdef GENERATE_MACHINE_PARSEABLE_REPORT + #ifdef HAVE_GET_CYCLES + (void)XSNPRINTF(msg, sizeof(msg), + "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d," + FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR, + algo, strength, desc, desc_extra, + FLT_FMT_PREC_ARGS(digits, opsSec), + count, FLT_FMT_ARGS(total), (unsigned long)total_cycles, + FLT_FMT_PREC_ARGS(6, + (double)total_cycles / (double)count)); + #else + (void)XSNPRINTF(msg, sizeof(msg), + "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d," + FLT_FMT STATS_CLAUSE_SEPARATOR, + algo, strength, desc, desc_extra, + FLT_FMT_PREC_ARGS(digits, opsSec), + count, FLT_FMT_ARGS(total)); + #endif +#else + (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," + FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR, + algo, strength, desc, desc_extra, + FLT_FMT_PREC_ARGS(digits, opsSec)); +#endif + } /* 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 " FLT_FMT_PREC2 " %s, " + FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR, + algo, strength, desc, desc_extra, + BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], + FLT_FMT_PREC2_ARGS(5, 3, total), word[1], + FLT_FMT_PREC_ARGS(digits, opsSec), word[3], + (unsigned long)total_cycles); + #else + (void)XSNPRINTF(msg, sizeof(msg), + "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, " + FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR, + algo, strength, desc, desc_extra, + BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], + FLT_FMT_PREC2_ARGS(5, 3, total), word[1], + FLT_FMT_PREC_ARGS(digits, opsSec), word[3]); + #endif /* HAVE_GET_CYCLES */ +#else + (void)XSNPRINTF(msg, sizeof(msg), + "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, " + FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR, + algo, strength, desc, desc_extra, + BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], + FLT_FMT_PREC2_ARGS(5, 3, total), word[1], + FLT_FMT_PREC_ARGS(digits, opsSec), word[3]); +#endif + } +#else /* MULTI_VALUE_STATISTICS. Print with avg ms */ + /* format and print to terminal */ + if (csv_format == 1) { + /* 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/" + WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT + "ecs,cycles,cycles/op,"); + #else + printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/" + WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT + "ecs,"); + #endif +#else + printf("\n%sAsymmetric Ciphers:\n\n", info_prefix); + printf("%sAlgorithm,key size,operation,avg ms,ops/" + WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix); +#endif + printf("\n"); asym_header_printed = 1; } #ifdef GENERATE_MACHINE_PARSEABLE_REPORT #ifdef HAVE_GET_CYCLES (void)XSNPRINTF(msg, sizeof(msg), "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d," - FLT_FMT ",%lu," FLT_FMT_PREC "\n", + FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR, algo, strength, desc, desc_extra, FLT_FMT_PREC_ARGS(3, milliEach), - FLT_FMT_PREC_ARGS(3, opsSec), + FLT_FMT_PREC_ARGS(digits, opsSec), count, FLT_FMT_ARGS(total), (unsigned long)total_cycles, FLT_FMT_PREC_ARGS(6, (double)total_cycles / (double)count)); #else (void)XSNPRINTF(msg, sizeof(msg), "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d," - FLT_FMT "\n", + FLT_FMT STATS_CLAUSE_SEPARATOR, algo, strength, desc, desc_extra, FLT_FMT_PREC_ARGS(3, milliEach), - FLT_FMT_PREC_ARGS(3, opsSec), + FLT_FMT_PREC_ARGS(digits, opsSec), count, FLT_FMT_ARGS(total)); #endif #else (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC "," - FLT_FMT_PREC ",\n", algo, strength, desc, desc_extra, + FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR, + algo, strength, desc, desc_extra, FLT_FMT_PREC_ARGS(3, milliEach), - FLT_FMT_PREC_ARGS(3, opsSec)); + FLT_FMT_PREC_ARGS(digits, opsSec)); #endif } /* if (csv_format == 1) */ @@ -2218,34 +2736,38 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, #ifdef HAVE_GET_CYCLES (void)XSNPRINTF(msg, sizeof(msg), "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " - FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles\n", + FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles" + STATS_CLAUSE_SEPARATOR, algo, strength, desc, desc_extra, BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2], FLT_FMT_PREC2_ARGS(5, 3, milliEach), - FLT_FMT_PREC_ARGS(3, opsSec), word[3], + FLT_FMT_PREC_ARGS(digits, opsSec), word[3], (unsigned long)total_cycles); #else (void)XSNPRINTF(msg, sizeof(msg), "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " - FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s\n", + FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s" + STATS_CLAUSE_SEPARATOR, algo, strength, desc, desc_extra, BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2], FLT_FMT_PREC2_ARGS(5, 3, milliEach), - FLT_FMT_PREC_ARGS(3, opsSec), word[3]); + FLT_FMT_PREC_ARGS(digits, opsSec), word[3]); #endif /* HAVE_GET_CYCLES */ #else (void)XSNPRINTF(msg, sizeof(msg), "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " - FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s\n", + FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s" + STATS_CLAUSE_SEPARATOR, algo, strength, desc, desc_extra, BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2], FLT_FMT_PREC2_ARGS(5, 3, milliEach), - FLT_FMT_PREC_ARGS(3, opsSec), word[3]); + FLT_FMT_PREC_ARGS(digits, opsSec), word[3]); #endif } +#endif /* MULTI_VALUE_STATISTICS */ printf("%s", msg); /* show errors */ @@ -2267,7 +2789,9 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, (void)useDeviceID; (void)ret; +#ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS RESTORE_VECTOR_REGISTERS(); +#endif TEST_SLEEP(); } /* bench_stats_asym_finish_ex */ @@ -2302,7 +2826,7 @@ static WC_INLINE void bench_stats_free(void) static void* benchmarks_do(void* args) { - int bench_buf_size; + long bench_buf_size; #ifdef WOLFSSL_ASYNC_CRYPT #ifndef WC_NO_ASYNC_THREADING @@ -2386,8 +2910,101 @@ static void* benchmarks_do(void* args) printf("%sBenchmark block buffer alloc failed!\n", err_prefix); goto exit; } - XMEMSET(bench_plain, 0, (size_t)bench_buf_size); - XMEMSET(bench_cipher, 0, (size_t)bench_buf_size); + +#ifndef NO_FILESYSTEM + if (hash_input) { + int rawSz; + XFILE file; + file = XFOPEN(hash_input, "rb"); + if (file == XBADFILE) + goto exit; + + if (XFSEEK(file, 0, XSEEK_END) != 0) { + XFCLOSE(file); + goto exit; + } + + bench_buf_size = XFTELL(file); + if(XFSEEK(file, 0, XSEEK_SET) != 0) { + XFCLOSE(file); + goto exit; + } + + XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + + rawSz = (int)bench_buf_size; + if (bench_buf_size % 16) + bench_buf_size += 16 - (bench_buf_size % 16); + + bench_size = (word32)bench_buf_size; + + bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2, + HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + + if (bench_plain == NULL) { + XFCLOSE(file); + goto exit; + } + + if ((size_t)XFREAD(bench_plain, 1, rawSz, file) + != (size_t)rawSz) { + XFCLOSE(file); + goto exit; + } + + XFCLOSE(file); + } + else { + XMEMSET(bench_plain, 0, (size_t)bench_buf_size); + } + + if (cipher_input) { + int rawSz; + XFILE file; + file = XFOPEN(cipher_input, "rb"); + if (file == XBADFILE) + goto exit; + + if (XFSEEK(file, 0, XSEEK_END) != 0) { + XFCLOSE(file); + goto exit; + } + + bench_buf_size = XFTELL(file); + if(XFSEEK(file, 0, XSEEK_SET) != 0) { + XFCLOSE(file); + goto exit; + } + + XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + + rawSz = (int)bench_buf_size; + if (bench_buf_size % 16) + bench_buf_size += 16 - (bench_buf_size % 16); + + if (bench_size > (word32)bench_buf_size) + bench_size = (word32)bench_buf_size; + + bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2, + HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + + if (bench_cipher == NULL) { + XFCLOSE(file); + goto exit; + } + + if ((size_t)XFREAD(bench_cipher, 1, rawSz, file) + != (size_t)rawSz) { + XFCLOSE(file); + goto exit; + } + + XFCLOSE(file); + } + else { + XMEMSET(bench_cipher, 0, (size_t)bench_buf_size); + } +#endif #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC) bench_key = (byte*)XMALLOC(sizeof(bench_key_buf), @@ -2785,12 +3402,18 @@ static void* benchmarks_do(void* args) bench_pbkdf2(); } #endif - #ifdef WOLFSSL_SIPHASH - if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) { - bench_siphash(); - } - #endif #endif /* NO_HMAC */ +#ifdef WOLFSSL_SIPHASH + if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) { + bench_siphash(); + } +#endif + +#ifdef WC_SRTP_KDF + if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) { + bench_srtpkdf(); + } +#endif #ifdef HAVE_SCRYPT if (bench_all || (bench_other_algs & BENCH_SCRYPT)) @@ -3333,6 +3956,7 @@ void bench_rng(void) double start; long pos, len, remain; WC_RNG myrng; + DECLARE_MULTI_VALUE_STATS_VARS() #ifndef HAVE_FIPS ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId); @@ -3362,11 +3986,19 @@ void bench_rng(void) remain -= len; pos += len; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); exit_rng: bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_FreeRng(&myrng); } @@ -3384,6 +4016,7 @@ static void bench_aescbc_internal(int useDeviceID, int ret = 0, i, count = 0, times, pending = 0; Aes enc[BENCH_MAX_PENDING]; double start; + DECLARE_MULTI_VALUE_STATS_VARS() /* clear for done cleanup */ XMEMSET(enc, 0, sizeof(enc)); @@ -3421,13 +4054,21 @@ static void bench_aescbc_internal(int useDeviceID, } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); exit_aes_enc: bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif if (ret < 0) { goto exit; @@ -3443,6 +4084,8 @@ exit_aes_enc: } } + RESET_MULTI_VALUE_STATS_VARS(); + bench_stats_start(&count, &start); do { for (times = 0; times < numBlocks || pending > 0; ) { @@ -3461,12 +4104,21 @@ exit_aes_enc: } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_aes_dec: bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif #endif /* HAVE_AES_DECRYPT */ @@ -3518,6 +4170,7 @@ static void bench_aesgcm_internal(int useDeviceID, Aes dec[BENCH_MAX_PENDING+1]; #endif double start; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT); WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT); @@ -3574,16 +4227,27 @@ static void bench_aesgcm_internal(int useDeviceID, } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_aes_gcm: bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif #ifdef HAVE_AES_DECRYPT XMEMSET(dec, 0, sizeof(dec)); + RESET_MULTI_VALUE_STATS_VARS(); + /* init keys */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if ((ret = wc_AesInit(&dec[i], HEAP_HINT, @@ -3618,13 +4282,21 @@ exit_aes_gcm: } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); exit_aes_gcm_dec: bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif #endif /* HAVE_AES_DECRYPT */ (void)decLabel; @@ -3658,6 +4330,7 @@ static void bench_aesgcm_stream_internal(int useDeviceID, Aes dec[BENCH_MAX_PENDING]; #endif double start; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT); WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT); @@ -3723,12 +4396,21 @@ static void bench_aesgcm_stream_internal(int useDeviceID, } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_aes_gcm: bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif #ifdef HAVE_AES_DECRYPT /* init keys */ @@ -3746,6 +4428,8 @@ exit_aes_gcm: } } + RESET_MULTI_VALUE_STATS_VARS(); + bench_stats_start(&count, &start); do { for (times = 0; times < numBlocks || pending > 0; ) { @@ -3771,13 +4455,21 @@ exit_aes_gcm: } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); exit_aes_gcm_dec: bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif #endif /* HAVE_AES_DECRYPT */ (void)decLabel; @@ -3858,6 +4550,7 @@ void bench_gmac(int useDeviceID) Gmac gmac; double start; byte tag[AES_AUTH_TAG_SZ]; + DECLARE_MULTI_VALUE_STATS_VARS() /* determine GCM GHASH method */ #ifdef GCM_SMALL @@ -3889,10 +4582,20 @@ void bench_gmac(int useDeviceID) tag, sizeof(tag)); count++; - } while (bench_stats_check(start)); + RECORD_MULTI_VALUE_STATS(); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + wc_AesFree((Aes*)&gmac); bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + } #endif /* HAVE_AESGCM */ @@ -3906,10 +4609,11 @@ static void bench_aesecb_internal(int useDeviceID, int ret = 0, i, count = 0, times, pending = 0; Aes enc[BENCH_MAX_PENDING]; double start; + DECLARE_MULTI_VALUE_STATS_VARS() #ifdef HAVE_FIPS - static const int benchSz = AES_BLOCK_SIZE; + const int benchSz = AES_BLOCK_SIZE; #else - static const int benchSz = BENCH_SIZE; + const int benchSz = (int)bench_size; #endif /* clear for done cleanup */ @@ -3955,12 +4659,21 @@ static void bench_aesecb_internal(int useDeviceID, } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_aes_enc: bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif #ifdef HAVE_AES_DECRYPT /* init keys */ @@ -3972,6 +4685,8 @@ exit_aes_enc: } } + RESET_MULTI_VALUE_STATS_VARS(); + bench_stats_start(&count, &start); do { int outer_loop_limit = (10 * ((int)bench_size / benchSz)) + 1; @@ -3995,12 +4710,21 @@ exit_aes_enc: } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_aes_dec: bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif #endif /* HAVE_AES_DECRYPT */ @@ -4036,6 +4760,13 @@ static void bench_aescfb_internal(const byte* key, Aes enc; double start; int i, ret, count; + DECLARE_MULTI_VALUE_STATS_VARS() + + ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID); + if (ret != 0) { + printf("AesInit failed, ret = %d\n", ret); + return; + } ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION); if (ret != 0) { @@ -4051,10 +4782,19 @@ static void bench_aescfb_internal(const byte* key, printf("wc_AesCfbEncrypt failed, ret = %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish(label, 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } void bench_aescfb(void) @@ -4080,6 +4820,7 @@ static void bench_aesofb_internal(const byte* key, Aes enc; double start; int i, ret, count; + DECLARE_MULTI_VALUE_STATS_VARS() ret = wc_AesInit(&enc, NULL, INVALID_DEVID); if (ret != 0) { @@ -4101,10 +4842,19 @@ static void bench_aesofb_internal(const byte* key, printf("wc_AesCfbEncrypt failed, ret = %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish(label, 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_AesFree(&enc); } @@ -4130,6 +4880,7 @@ void bench_aesxts(void) XtsAes aes; double start; int i, count, ret; + DECLARE_MULTI_VALUE_STATS_VARS() static unsigned char k1[] = { 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35, @@ -4158,10 +4909,19 @@ void bench_aesxts(void) printf("wc_AesXtsEncrypt failed, ret = %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_AesXtsFree(&aes); /* decryption benchmark */ @@ -4172,6 +4932,8 @@ void bench_aesxts(void) return; } + RESET_MULTI_VALUE_STATS_VARS(); + bench_stats_start(&count, &start); do { for (i = 0; i < numBlocks; i++) { @@ -4180,10 +4942,19 @@ void bench_aesxts(void) printf("wc_AesXtsDecrypt failed, ret = %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_AesXtsFree(&aes); } #endif /* WOLFSSL_AES_XTS */ @@ -4197,6 +4968,7 @@ static void bench_aesctr_internal(const byte* key, word32 keySz, Aes enc; double start; int i, count, ret = 0; + DECLARE_MULTI_VALUE_STATS_VARS() if ((ret = wc_AesInit(&enc, HEAP_HINT, useDeviceID ? devId : INVALID_DEVID)) != 0) { @@ -4216,10 +4988,19 @@ static void bench_aesctr_internal(const byte* key, word32 keySz, printf("wc_AesCtrEncrypt failed, ret = %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_AesFree(&enc); } @@ -4245,6 +5026,7 @@ void bench_aesccm(int useDeviceID) Aes enc; double start; int ret, i, count; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT); WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT); @@ -4276,27 +5058,47 @@ void bench_aesccm(int useDeviceID) ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size, bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ, bench_additional, 0); + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif if (ret != 0) { printf("wc_AesCcmEncrypt failed, ret = %d\n", ret); goto exit; } + RESET_MULTI_VALUE_STATS_VARS(); + 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, 0); + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif if (ret != 0) { printf("wc_AesCcmEncrypt failed, ret = %d\n", ret); goto exit; @@ -4321,6 +5123,7 @@ static void bench_aessiv_internal(const byte* key, word32 keySz, const char* byte siv[AES_BLOCK_SIZE]; int count = 0; double start; + DECLARE_MULTI_VALUE_STATS_VARS() bench_stats_start(&count, &start); do { @@ -4332,10 +5135,21 @@ static void bench_aessiv_internal(const byte* key, word32 keySz, const char* printf("wc_AesSivEncrypt failed (%d)\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); bench_stats_start(&count, &start); do { @@ -4347,10 +5161,19 @@ static void bench_aessiv_internal(const byte* key, word32 keySz, const char* printf("wc_AesSivDecrypt failed (%d)\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } void bench_aessiv(void) @@ -4370,6 +5193,7 @@ void bench_poly1305(void) byte mac[16]; double start; int ret = 0, i, count; + DECLARE_MULTI_VALUE_STATS_VARS() if (digest_stream) { ret = wc_Poly1305SetKey(&enc, bench_key, 32); @@ -4386,11 +5210,15 @@ void bench_poly1305(void) printf("Poly1305Update failed: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } wc_Poly1305Final(&enc, mac); count += i; - } while (bench_stats_check(start)); - bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -4407,11 +5235,19 @@ void bench_poly1305(void) break; } wc_Poly1305Final(&enc, mac); + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); - bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } + bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } #endif /* HAVE_POLY1305 */ @@ -4422,6 +5258,7 @@ void bench_camellia(void) Camellia cam; double start; int ret, i, count; + DECLARE_MULTI_VALUE_STATS_VARS() ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv); if (ret != 0) { @@ -4438,10 +5275,19 @@ void bench_camellia(void) printf("CamelliaCbcEncrypt failed: %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } #endif @@ -4453,6 +5299,7 @@ void bench_sm4_cbc(void) int ret; int i; int count; + DECLARE_MULTI_VALUE_STATS_VARS() ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE); if (ret != 0) { @@ -4473,10 +5320,21 @@ void bench_sm4_cbc(void) printf("Sm4CbcEncrypt failed: %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); bench_stats_start(&count, &start); do { @@ -4486,10 +5344,19 @@ void bench_sm4_cbc(void) printf("Sm4CbcDecrypt failed: %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } #endif @@ -4501,6 +5368,7 @@ void bench_sm4_gcm(void) int ret; int i; int count; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT); WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT); @@ -4527,10 +5395,21 @@ void bench_sm4_gcm(void) printf("Sm4GcmEncrypt failed: %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); bench_stats_start(&count, &start); do { @@ -4542,10 +5421,19 @@ void bench_sm4_gcm(void) printf("Sm4GcmDecrypt failed: %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } #endif @@ -4555,6 +5443,7 @@ void bench_sm4_ccm() wc_Sm4 enc; double start; int ret, i, count; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT); WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT); @@ -4580,25 +5469,45 @@ void bench_sm4_ccm() ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size, bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ, bench_additional, 0); + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif if (ret != 0) { printf("wc_Sm4Encrypt failed, ret = %d\n", ret); goto exit; } + RESET_MULTI_VALUE_STATS_VARS(); + bench_stats_start(&count, &start); do { for (i = 0; i < numBlocks; i++) { ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size, bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ, bench_additional, 0); + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif if (ret != 0) { printf("wc_Sm4Decrypt failed, ret = %d\n", ret); goto exit; @@ -4616,6 +5525,7 @@ void bench_des(int useDeviceID) int ret = 0, i, count = 0, times, pending = 0; Des3 enc[BENCH_MAX_PENDING]; double start; + DECLARE_MULTI_VALUE_STATS_VARS() /* clear for done cleanup */ XMEMSET(enc, 0, sizeof(enc)); @@ -4653,11 +5563,20 @@ void bench_des(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_3des: bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -4674,6 +5593,7 @@ void bench_arc4(int useDeviceID) int ret = 0, i, count = 0, times, pending = 0; Arc4 enc[BENCH_MAX_PENDING]; double start; + DECLARE_MULTI_VALUE_STATS_VARS() /* clear for done cleanup */ XMEMSET(enc, 0, sizeof(enc)); @@ -4710,11 +5630,20 @@ void bench_arc4(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_arc4: bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -4731,7 +5660,9 @@ void bench_chacha(void) ChaCha enc; double start; int i, count; + DECLARE_MULTI_VALUE_STATS_VARS() + XMEMSET(&enc, 0, sizeof(enc)); wc_Chacha_SetKey(&enc, bench_key, 16); bench_stats_start(&count, &start); @@ -4739,10 +5670,19 @@ void bench_chacha(void) for (i = 0; i < numBlocks; i++) { wc_Chacha_SetIV(&enc, bench_iv, 0); wc_Chacha_Process(&enc, bench_cipher, bench_plain, bench_size); + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } #endif /* HAVE_CHACHA*/ @@ -4751,6 +5691,7 @@ void bench_chacha20_poly1305_aead(void) { double start; int ret = 0, i, count; + DECLARE_MULTI_VALUE_STATS_VARS() byte authTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE]; XMEMSET(authTag, 0, sizeof(authTag)); @@ -4764,10 +5705,19 @@ void bench_chacha20_poly1305_aead(void) printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } #endif /* HAVE_CHACHA && HAVE_POLY1305 */ @@ -4778,6 +5728,8 @@ void bench_md5(int useDeviceID) wc_Md5 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_MD5_DIGEST_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, @@ -4818,6 +5770,7 @@ void bench_md5(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -4837,7 +5790,11 @@ void bench_md5(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -4850,12 +5807,20 @@ void bench_md5(int useDeviceID) ret = wc_Md5Final(hash, digest[0]); if (ret != 0) goto exit_md5; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_md5: bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -4876,6 +5841,7 @@ void bench_sha(int useDeviceID) wc_Sha hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA_DIGEST_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, @@ -4916,6 +5882,7 @@ void bench_sha(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -4935,7 +5902,11 @@ void bench_sha(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -4949,12 +5920,20 @@ void bench_sha(int useDeviceID) ret = wc_ShaFinal(hash, digest[0]); if (ret != 0) goto exit_sha; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_sha: bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -4973,6 +5952,7 @@ void bench_sha224(int useDeviceID) wc_Sha224 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA224_DIGEST_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, @@ -5010,6 +5990,7 @@ void bench_sha224(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -5028,7 +6009,11 @@ void bench_sha224(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -5044,11 +6029,18 @@ void bench_sha224(int useDeviceID) goto exit_sha224; } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_sha224: bench_stats_sym_finish("SHA-224", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -5060,12 +6052,14 @@ exit: } #endif + #ifndef NO_SHA256 void bench_sha256(int useDeviceID) { wc_Sha256 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA256_DIGEST_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, @@ -5106,6 +6100,7 @@ void bench_sha256(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -5124,7 +6119,11 @@ void bench_sha256(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -5138,16 +6137,22 @@ void bench_sha256(int useDeviceID) ret = wc_Sha256Final(hash, digest[0]); if (ret != 0) goto exit_sha256; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_sha256: bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size, start, ret); - +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: - for (i = 0; i < BENCH_MAX_PENDING; i++) { wc_Sha256Free(&hash[i]); } @@ -5162,6 +6167,7 @@ void bench_sha384(int useDeviceID) wc_Sha384 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA384_DIGEST_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, @@ -5199,6 +6205,7 @@ void bench_sha384(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -5217,7 +6224,11 @@ void bench_sha384(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -5231,13 +6242,21 @@ void bench_sha384(int useDeviceID) ret = wc_Sha384Final(hash, digest[0]); if (ret != 0) goto exit_sha384; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_sha384: bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -5255,6 +6274,7 @@ void bench_sha512(int useDeviceID) wc_Sha512 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA512_DIGEST_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, @@ -5292,6 +6312,7 @@ void bench_sha512(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -5310,7 +6331,11 @@ void bench_sha512(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -5324,13 +6349,21 @@ void bench_sha512(int useDeviceID) ret = wc_Sha512Final(hash, digest[0]); if (ret != 0) goto exit_sha512; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_sha512: bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -5348,7 +6381,8 @@ void bench_sha512_224(int useDeviceID) wc_Sha512_224 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + DECLARE_MULTI_VALUE_STATS_VARS() + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA512_224_DIGEST_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA512_224_DIGEST_SIZE, HEAP_HINT); @@ -5385,6 +6419,7 @@ void bench_sha512_224(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -5403,7 +6438,11 @@ void bench_sha512_224(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -5417,13 +6456,21 @@ void bench_sha512_224(int useDeviceID) ret = wc_Sha512_224Final(hash, digest[0]); if (ret != 0) goto exit_sha512_224; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_sha512_224: bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -5442,6 +6489,7 @@ void bench_sha512_256(int useDeviceID) wc_Sha512_256 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA512_256_DIGEST_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, @@ -5479,6 +6527,7 @@ void bench_sha512_256(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -5497,7 +6546,11 @@ void bench_sha512_256(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -5511,13 +6564,21 @@ void bench_sha512_256(int useDeviceID) ret = wc_Sha512_256Final(hash, digest[0]); if (ret != 0) goto exit_sha512_256; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_sha512_256: bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -5539,6 +6600,7 @@ void bench_sha3_224(int useDeviceID) wc_Sha3 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_224_DIGEST_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, @@ -5576,6 +6638,7 @@ void bench_sha3_224(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -5594,7 +6657,11 @@ void bench_sha3_224(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -5608,13 +6675,21 @@ void bench_sha3_224(int useDeviceID) ret = wc_Sha3_224_Final(hash, digest[0]); if (ret != 0) goto exit_sha3_224; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_sha3_224: bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -5631,6 +6706,7 @@ void bench_sha3_256(int useDeviceID) { wc_Sha3 hash[BENCH_MAX_PENDING]; double start; + DECLARE_MULTI_VALUE_STATS_VARS() int ret = 0, i, count = 0, times, pending = 0; WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_256_DIGEST_SIZE, HEAP_HINT); @@ -5669,6 +6745,7 @@ void bench_sha3_256(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -5687,7 +6764,11 @@ void bench_sha3_256(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -5701,13 +6782,21 @@ void bench_sha3_256(int useDeviceID) ret = wc_Sha3_256_Final(hash, digest[0]); if (ret != 0) goto exit_sha3_256; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_sha3_256: bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -5725,6 +6814,7 @@ void bench_sha3_384(int useDeviceID) wc_Sha3 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_384_DIGEST_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, @@ -5762,6 +6852,7 @@ void bench_sha3_384(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -5780,7 +6871,11 @@ void bench_sha3_384(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -5794,13 +6889,21 @@ void bench_sha3_384(int useDeviceID) ret = wc_Sha3_384_Final(hash, digest[0]); if (ret != 0) goto exit_sha3_384; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_sha3_384: bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -5818,6 +6921,7 @@ void bench_sha3_512(int useDeviceID) wc_Sha3 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_512_DIGEST_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, @@ -5855,6 +6959,7 @@ void bench_sha3_512(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -5873,7 +6978,11 @@ void bench_sha3_512(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -5887,13 +6996,21 @@ void bench_sha3_512(int useDeviceID) ret = wc_Sha3_512_Final(hash, digest[0]); if (ret != 0) goto exit_sha3_512; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_sha3_512: bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -5911,6 +7028,7 @@ void bench_shake128(int useDeviceID) wc_Shake hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_128_BLOCK_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, @@ -5948,6 +7066,7 @@ void bench_shake128(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -5967,7 +7086,11 @@ void bench_shake128(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -5982,13 +7105,21 @@ void bench_shake128(int useDeviceID) WC_SHA3_128_BLOCK_SIZE); if (ret != 0) goto exit_shake128; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_shake128: bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -6006,6 +7137,7 @@ void bench_shake256(int useDeviceID) wc_Shake hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_256_BLOCK_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, @@ -6043,6 +7175,7 @@ void bench_shake256(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -6062,7 +7195,11 @@ void bench_shake256(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -6077,13 +7214,21 @@ void bench_shake256(int useDeviceID) WC_SHA3_256_BLOCK_SIZE); if (ret != 0) goto exit_shake256; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_shake256: bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -6102,6 +7247,7 @@ void bench_sm3(int useDeviceID) wc_Sm3 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE, @@ -6138,6 +7284,7 @@ void bench_sm3(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; @@ -6155,7 +7302,11 @@ void bench_sm3(int useDeviceID) } } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -6169,12 +7320,20 @@ void bench_sm3(int useDeviceID) ret = wc_Sm3Final(hash, digest[0]); if (ret != 0) goto exit_sm3; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } exit_sm3: bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -6194,6 +7353,7 @@ void bench_ripemd(void) byte digest[RIPEMD_DIGEST_SIZE]; double start; int i, count, ret = 0; + DECLARE_MULTI_VALUE_STATS_VARS() if (digest_stream) { ret = wc_InitRipeMd(&hash); @@ -6210,6 +7370,7 @@ void bench_ripemd(void) printf("wc_RipeMdUpdate failed, retval %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } ret = wc_RipeMdFinal(&hash, digest); if (ret != 0) { @@ -6218,7 +7379,11 @@ void bench_ripemd(void) } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -6239,11 +7404,19 @@ void bench_ripemd(void) printf("wc_RipeMdFinal failed, retval %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif return; } @@ -6257,6 +7430,7 @@ void bench_blake2b(void) byte digest[64]; double start; int ret = 0, i, count; + DECLARE_MULTI_VALUE_STATS_VARS() if (digest_stream) { ret = wc_InitBlake2b(&b2b, 64); @@ -6273,6 +7447,7 @@ void bench_blake2b(void) printf("Blake2bUpdate failed, ret = %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } ret = wc_Blake2bFinal(&b2b, digest, 64); if (ret != 0) { @@ -6280,7 +7455,11 @@ void bench_blake2b(void) return; } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -6301,11 +7480,19 @@ void bench_blake2b(void) printf("Blake2bFinal failed, ret = %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } #endif @@ -6316,6 +7503,7 @@ void bench_blake2s(void) byte digest[32]; double start; int ret = 0, i, count; + DECLARE_MULTI_VALUE_STATS_VARS() if (digest_stream) { ret = wc_InitBlake2s(&b2s, 32); @@ -6332,6 +7520,7 @@ void bench_blake2s(void) printf("Blake2sUpdate failed, ret = %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } ret = wc_Blake2sFinal(&b2s, digest, 32); if (ret != 0) { @@ -6339,7 +7528,11 @@ void bench_blake2s(void) return; } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } else { bench_stats_start(&count, &start); @@ -6360,11 +7553,19 @@ void bench_blake2s(void) printf("Blake2sFinal failed, ret = %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); } bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } #endif @@ -6378,6 +7579,7 @@ static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID) word32 digestSz = sizeof(digest); double start; int ret, i, count; + DECLARE_MULTI_VALUE_STATS_VARS() #ifdef WOLFSSL_SECO_CAAM unsigned int keyID; int keyGroup = 1; /* group one was chosen arbitrarily */ @@ -6422,6 +7624,7 @@ static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID) printf("CmacUpdate failed, ret = %d\n", ret); return; } + RECORD_MULTI_VALUE_STATS(); } /* Note: final force zero's the Cmac struct */ ret = wc_CmacFinal(&cmac, digest, &digestSz); @@ -6430,8 +7633,16 @@ static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID) return; } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } void bench_cmac(int useDeviceID) @@ -6453,6 +7664,7 @@ void bench_scrypt(void) byte derived[64]; double start; int ret, i, count; + DECLARE_MULTI_VALUE_STATS_VARS() bench_stats_start(&count, &start); do { @@ -6464,11 +7676,20 @@ void bench_scrypt(void) printf("scrypt failed, ret = %d\n", ret); goto exit; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit: bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } #endif /* HAVE_SCRYPT */ @@ -6481,6 +7702,7 @@ static void bench_hmac(int useDeviceID, int type, int digestSz, Hmac hmac[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; + DECLARE_MULTI_VALUE_STATS_VARS() #ifdef WOLFSSL_ASYNC_CRYPT WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_MAX_DIGEST_SIZE, HEAP_HINT); @@ -6547,11 +7769,20 @@ static void bench_hmac(int useDeviceID, int type, int digestSz, goto exit_hmac; } } + RECORD_MULTI_VALUE_STATS(); } /* for i */ } while (pending > 0); - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_hmac: bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -6676,14 +7907,24 @@ void bench_pbkdf2(void) 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06, 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 }; byte derived[32]; + DECLARE_MULTI_VALUE_STATS_VARS() bench_stats_start(&count, &start); do { ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32), salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256); count++; - } while (bench_stats_check(start)); + RECORD_MULTI_VALUE_STATS(); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } #endif /* !NO_PWDBASED */ @@ -6697,26 +7938,149 @@ void bench_siphash(void) const char* passwd16 = "passwordpassword"; byte out[16]; int i; + DECLARE_MULTI_VALUE_STATS_VARS() bench_stats_start(&count, &start); do { for (i = 0; i < numBlocks; i++) { ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size, out, 8); + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); bench_stats_start(&count, &start); do { for (i = 0; i < numBlocks; i++) { ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size, out, 16); + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif +} +#endif + +#ifdef WC_SRTP_KDF +void bench_srtpkdf(void) +{ + double start; + int count; + int ret = 0; + byte keyE[32]; + byte keyA[20]; + byte keyS[14]; + const byte *key = bench_key_buf; + const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e }; + const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA }; + int kdrIdx = 0; + int i; + DECLARE_MULTI_VALUE_STATS_VARS() + + bench_stats_start(&count, &start); + do { + for (i = 0; i < numBlocks; i++) { + ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt), + kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA), + keyS, sizeof(keyS)); + RECORD_MULTI_VALUE_STATS(); + } + count += i; + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); + + bench_stats_start(&count, &start); + do { + for (i = 0; i < numBlocks; i++) { + ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt), + kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA), + keyS, sizeof(keyS)); + RECORD_MULTI_VALUE_STATS(); + } + count += i; + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); + + bench_stats_start(&count, &start); + do { + for (i = 0; i < numBlocks; i++) { + ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt), + kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA), + keyS, sizeof(keyS)); + RECORD_MULTI_VALUE_STATS(); + } + count += i; + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); + + bench_stats_start(&count, &start); + do { + for (i = 0; i < numBlocks; i++) { + ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt), + kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA), + keyS, sizeof(keyS)); + RECORD_MULTI_VALUE_STATS(); + } + count += i; + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + } #endif @@ -6734,6 +8098,7 @@ static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz) int ret = 0, i, count = 0, times, pending = 0; const long rsa_e_val = WC_RSA_EXPONENT; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() #ifdef WOLFSSL_SMALL_STACK genKey = (RsaKey *)XMALLOC(sizeof(*genKey) * BENCH_MAX_PENDING, @@ -6772,12 +8137,21 @@ static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit: bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif /* cleanup */ for (i = 0; i < BENCH_MAX_PENDING; i++) { @@ -6928,6 +8302,7 @@ static void bench_rsa_helper(int useDeviceID, RsaKey rsaKey[BENCH_MAX_PENDING], #endif double start = 0.0F; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() #ifndef WOLFSSL_RSA_VERIFY_ONLY WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT); #endif @@ -6993,12 +8368,21 @@ static void bench_rsa_helper(int useDeviceID, RsaKey rsaKey[BENCH_MAX_PENDING], } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); + exit_rsa_verify: bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0], useDeviceID, count, start, ret); + #ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); + #endif #endif /* !WOLFSSL_RSA_VERIFY_ONLY */ #ifndef WOLFSSL_RSA_PUBLIC_ONLY @@ -7006,6 +8390,8 @@ exit_rsa_verify: goto exit; } + RESET_MULTI_VALUE_STATS_VARS(); + /* capture resulting encrypt length */ idx = (word32)(rsaKeySz/8); @@ -7029,12 +8415,21 @@ exit_rsa_verify: } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); + exit_rsa_pub: bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1], useDeviceID, count, start, ret); + #ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); + #endif #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */ } else { @@ -7059,16 +8454,27 @@ exit_rsa_pub: } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); + exit_rsa_sign: bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID, count, start, ret); - + #ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); + #endif if (ret < 0) { goto exit; } + + RESET_MULTI_VALUE_STATS_VARS(); + #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */ /* capture resulting encrypt length */ @@ -7115,13 +8521,21 @@ exit_rsa_sign: } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) + #ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs + #endif + ); exit_rsa_verifyinline: bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5], useDeviceID, count, start, ret); + #ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); + #endif } exit: @@ -7377,6 +8791,7 @@ void bench_dh(int useDeviceID) int paramName = 0; #endif #endif + DECLARE_MULTI_VALUE_STATS_VARS() WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); @@ -7513,6 +8928,7 @@ void bench_dh(int useDeviceID) } } + /* Key Gen */ bench_stats_start(&count, &start); PRIVATE_KEY_UNLOCK(); @@ -7536,18 +8952,29 @@ void bench_dh(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + PRIVATE_KEY_LOCK(); exit_dh_gen: bench_stats_asym_finish("DH", dhKeySz, desc[2], useDeviceID, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif if (ret < 0) { goto exit; } + RESET_MULTI_VALUE_STATS_VARS(); + /* Generate key to use as other public */ PRIVATE_KEY_UNLOCK(); ret = wc_DhGenerateKeyPair(&dhKey[0], &gRng, @@ -7576,14 +9003,23 @@ exit_dh_gen: } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + PRIVATE_KEY_LOCK(); exit: bench_stats_asym_finish("DH", dhKeySz, desc[3], useDeviceID, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif /* cleanup */ #ifdef WOLFSSL_SMALL_STACK @@ -7614,6 +9050,7 @@ static void bench_kyber_keygen(int type, const char* name, int keySize, int ret = 0, times, count, pending = 0; double start; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() /* KYBER Make Key */ bench_stats_start(&count, &start); @@ -7633,13 +9070,20 @@ static void bench_kyber_keygen(int type, const char* name, int keySize, #endif if (ret != 0) goto exit; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } - while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); exit: bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } static void bench_kyber_encap(const char* name, int keySize, KyberKey* key) @@ -7650,6 +9094,7 @@ static void bench_kyber_encap(const char* name, int keySize, KyberKey* key) byte ct[KYBER_MAX_CIPHER_TEXT_SIZE]; byte ss[KYBER_SS_SZ]; word32 ctSz; + DECLARE_MULTI_VALUE_STATS_VARS() ret = wc_KyberKey_CipherTextSize(key, &ctSz); if (ret != 0) { @@ -7670,13 +9115,22 @@ static void bench_kyber_encap(const char* name, int keySize, KyberKey* key) #endif if (ret != 0) goto exit_encap; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } - while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); exit_encap: bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); /* KYBER Decapsulate */ bench_stats_start(&count, &start); @@ -7686,13 +9140,20 @@ exit_encap: ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz); if (ret != 0) goto exit_decap; + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } - while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); exit_decap: bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } void bench_kyber(int type) @@ -8043,14 +9504,23 @@ static void bench_lms_sign_verify(enum wc_LmsParm parm) printf("wc_LmsKey_Sign failed: %d\n", ret); goto exit_lms_sign_verify; } + RECORD_MULTI_VALUE_STATS(); } count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); bench_stats_asym_finish(str, (int)sigSz, "sign", 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + RESET_MULTI_VALUE_STATS_VARS(); count = 0; bench_stats_start(&count, &start); @@ -8062,14 +9532,22 @@ static void bench_lms_sign_verify(enum wc_LmsParm parm) printf("wc_LmsKey_Verify failed: %d\n", ret); goto exit_lms_sign_verify; } + RECORD_MULTI_VALUE_STATS(); } count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); exit_lms_sign_verify: bench_stats_asym_finish(str, (int)sigSz, "verify", 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif if (loaded) { @@ -8382,6 +9860,7 @@ void bench_eccMakeKey(int useDeviceID, int curveId) char name[BENCH_ECC_NAME_SZ]; double start; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() #ifdef WOLFSSL_SMALL_STACK genKey = (ecc_key *)XMALLOC(sizeof(*genKey) * BENCH_MAX_PENDING, @@ -8425,15 +9904,23 @@ void bench_eccMakeKey(int useDeviceID, int curveId) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); 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); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif /* cleanup */ for (i = 0; i < BENCH_MAX_PENDING; i++) { @@ -8474,6 +9961,7 @@ void bench_ecc(int useDeviceID, int curveId) word32 x[BENCH_MAX_PENDING]; double start = 0; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() #ifdef HAVE_ECC_DHE WC_DECLARE_ARRAY(shared, byte, @@ -8578,9 +10066,15 @@ void bench_ecc(int useDeviceID, int curveId) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + PRIVATE_KEY_UNLOCK(); exit_ecdhe: (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]", @@ -8588,10 +10082,16 @@ exit_ecdhe: bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); if (ret < 0) { goto exit; } + #endif /* HAVE_ECC_DHE */ #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN) @@ -8628,9 +10128,14 @@ exit_ecdhe: } } /* bench_async_check */ } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); exit_ecdsa_sign: (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]", @@ -8638,6 +10143,11 @@ exit_ecdsa_sign: bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); if (ret < 0) { goto exit; @@ -8671,9 +10181,14 @@ exit_ecdsa_sign: } } /* if bench_async_check */ } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); exit_ecdsa_verify: (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]", @@ -8681,6 +10196,9 @@ exit_ecdsa_verify: bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif #endif /* HAVE_ECC_VERIFY */ #endif /* !NO_ASN && HAVE_ECC_SIGN */ @@ -8743,6 +10261,7 @@ void bench_eccEncrypt(int curveId) int ret, i, count; double start; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() #ifdef WOLFSSL_SMALL_STACK userA = (ecc_key *)XMALLOC(sizeof(*userA), @@ -8812,14 +10331,24 @@ void bench_eccEncrypt(int curveId) printf("wc_ecc_encrypt failed! %d\n", ret); goto exit_enc; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); exit_enc: (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); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); bench_stats_start(&count, &start); do { @@ -8831,11 +10360,20 @@ exit_enc: printf("wc_ecc_decrypt failed! %d\n", ret); goto exit_dec; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_dec: bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif exit: @@ -8870,6 +10408,7 @@ static void bench_sm2_MakeKey(int useDeviceID) char name[BENCH_ECC_NAME_SZ]; double start; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() deviceID = useDeviceID ? devId : INVALID_DEVID; keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1); @@ -8903,14 +10442,23 @@ static void bench_sm2_MakeKey(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit: (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]", wc_ecc_get_name(ECC_SM2P256V1)); - 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); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif /* cleanup */ for (i = 0; i < BENCH_MAX_PENDING; i++) { @@ -8937,6 +10485,7 @@ void bench_sm2(int useDeviceID) word32 x[BENCH_MAX_PENDING]; double start = 0; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() #ifdef HAVE_ECC_DHE WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); @@ -8962,6 +10511,7 @@ void bench_sm2(int useDeviceID) #ifdef HAVE_ECC_DHE XMEMSET(&genKey2, 0, sizeof(genKey2)); #endif + keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1); /* init keys */ @@ -9019,15 +10569,25 @@ void bench_sm2(int useDeviceID) } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* for times */ count += times; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + PRIVATE_KEY_UNLOCK(); exit_ecdhe: - (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]", wc_ecc_get_name(ECC_SM2P256V1)); + (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]", + wc_ecc_get_name(ECC_SM2P256V1)); - 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); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif if (ret < 0) { goto exit; @@ -9043,6 +10603,8 @@ exit_ecdhe: } } + RESET_MULTI_VALUE_STATS_VARS(); + /* ECC Sign */ bench_stats_start(&count, &start); do { @@ -9064,14 +10626,24 @@ exit_ecdhe: } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* 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(ECC_SM2P256V1)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); - 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(ECC_SM2P256V1)); + + bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count, + start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif if (ret < 0) { goto exit; @@ -9100,14 +10672,25 @@ exit_ecdsa_sign: } } } /* for i */ + RECORD_MULTI_VALUE_STATS(); } /* 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(ECC_SM2P256V1)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + +exit_ecdsa_verify: + (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]", + wc_ecc_get_name(ECC_SM2P256V1)); + + bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count, + start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif - bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count, start, - ret); #endif /* HAVE_ECC_VERIFY */ #endif /* !NO_ASN && HAVE_ECC_SIGN */ @@ -9148,6 +10731,7 @@ void bench_curve25519KeyGen(int useDeviceID) double start; int ret = 0, i, count; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() /* Key Gen */ bench_stats_start(&count, &start); @@ -9166,11 +10750,20 @@ void bench_curve25519KeyGen(int useDeviceID) printf("wc_curve25519_make_key failed: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } #ifdef HAVE_CURVE25519_SHARED_SECRET @@ -9182,6 +10775,7 @@ void bench_curve25519KeyAgree(int useDeviceID) byte shared[32]; const char**desc = bench_desc_words[lng_index]; word32 x = 0; + DECLARE_MULTI_VALUE_STATS_VARS() wc_curve25519_init_ex(&genKey, HEAP_HINT, useDeviceID ? devId : INVALID_DEVID); @@ -9210,12 +10804,21 @@ void bench_curve25519KeyAgree(int useDeviceID) printf("curve25519_shared_secret failed: %d\n", ret); goto exit; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit: bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_curve25519_free(&genKey2); wc_curve25519_free(&genKey); @@ -9231,6 +10834,7 @@ void bench_ed25519KeyGen(void) double start; int i, count; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() /* Key Gen */ bench_stats_start(&count, &start); @@ -9239,10 +10843,19 @@ void bench_ed25519KeyGen(void) wc_ed25519_init(&genKey); (void)wc_ed25519_make_key(&gRng, 32, &genKey); wc_ed25519_free(&genKey); + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif #endif /* HAVE_ED25519_MAKE_KEY */ } @@ -9260,6 +10873,7 @@ void bench_ed25519KeySign(void) byte msg[512]; word32 x = 0; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() #endif wc_ed25519_init(&genKey); @@ -9286,11 +10900,22 @@ void bench_ed25519KeySign(void) printf("ed25519_sign_msg failed\n"); goto exit_ed_sign; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_ed_sign: bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); #ifdef HAVE_ED25519_VERIFY bench_stats_start(&count, &start); @@ -9303,11 +10928,20 @@ exit_ed_sign: printf("ed25519_verify_msg failed\n"); goto exit_ed_verify; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_ed_verify: bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif #endif /* HAVE_ED25519_VERIFY */ #endif /* HAVE_ED25519_SIGN */ @@ -9322,6 +10956,7 @@ void bench_curve448KeyGen(void) double start; int ret = 0, i, count; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() /* Key Gen */ bench_stats_start(&count, &start); @@ -9333,10 +10968,19 @@ void bench_curve448KeyGen(void) printf("wc_curve448_make_key failed: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } #ifdef HAVE_CURVE448_SHARED_SECRET @@ -9348,6 +10992,7 @@ void bench_curve448KeyAgree(void) byte shared[56]; const char**desc = bench_desc_words[lng_index]; word32 x = 0; + DECLARE_MULTI_VALUE_STATS_VARS() wc_curve448_init(&genKey); wc_curve448_init(&genKey2); @@ -9374,11 +11019,20 @@ void bench_curve448KeyAgree(void) printf("curve448_shared_secret failed: %d\n", ret); goto exit; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit: bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_curve448_free(&genKey2); wc_curve448_free(&genKey); @@ -9393,6 +11047,7 @@ void bench_ed448KeyGen(void) double start; int i, count; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() /* Key Gen */ bench_stats_start(&count, &start); @@ -9401,10 +11056,19 @@ void bench_ed448KeyGen(void) wc_ed448_init(&genKey); (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey); wc_ed448_free(&genKey); + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } @@ -9419,6 +11083,7 @@ void bench_ed448KeySign(void) byte msg[512]; word32 x = 0; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() #endif wc_ed448_init(&genKey); @@ -9444,11 +11109,22 @@ void bench_ed448KeySign(void) printf("ed448_sign_msg failed\n"); goto exit_ed_sign; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_ed_sign: bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); #ifdef HAVE_ED448_VERIFY bench_stats_start(&count, &start); @@ -9461,11 +11137,20 @@ exit_ed_sign: printf("ed448_verify_msg failed\n"); goto exit_ed_verify; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + exit_ed_verify: bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif #endif /* HAVE_ED448_VERIFY */ #endif /* HAVE_ED448_SIGN */ @@ -9482,6 +11167,7 @@ void bench_eccsiKeyGen(void) int i, count; const char**desc = bench_desc_words[lng_index]; int ret; + DECLARE_MULTI_VALUE_STATS_VARS() /* Key Gen */ bench_stats_start(&count, &start); @@ -9494,10 +11180,19 @@ void bench_eccsiKeyGen(void) break; } wc_FreeEccsiKey(&genKey); + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } void bench_eccsiPairGen(void) @@ -9510,6 +11205,7 @@ void bench_eccsiPairGen(void) ecc_point* pvt; static const byte id[] = { 0x01, 0x23, 0x34, 0x45 }; int ret; + DECLARE_MULTI_VALUE_STATS_VARS() (void)mp_init(&ssk); pvt = wc_ecc_new_point(); @@ -9526,10 +11222,19 @@ void bench_eccsiPairGen(void) printf("wc_MakeEccsiPair failed: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_FreeEccsiKey(&genKey); wc_ecc_del_point(pvt); @@ -9549,6 +11254,7 @@ void bench_eccsiValidate(void) static const byte id[] = { 0x01, 0x23, 0x34, 0x45 }; int valid; int ret; + DECLARE_MULTI_VALUE_STATS_VARS() (void)mp_init(&ssk); pvt = wc_ecc_new_point(); @@ -9568,10 +11274,19 @@ void bench_eccsiValidate(void) valid); break; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_FreeEccsiKey(&genKey); wc_ecc_del_point(pvt); @@ -9594,6 +11309,7 @@ void bench_eccsi(void) word32 sigSz = sizeof(sig); int ret; int verified; + DECLARE_MULTI_VALUE_STATS_VARS() (void)mp_init(&ssk); pvt = wc_ecc_new_point(); @@ -9616,10 +11332,21 @@ void bench_eccsi(void) printf("wc_SignEccsiHash failed: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); /* Derive */ bench_stats_start(&count, &start); @@ -9633,10 +11360,19 @@ void bench_eccsi(void) verified); break; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_FreeEccsiKey(&genKey); wc_ecc_del_point(pvt); @@ -9653,6 +11389,7 @@ void bench_sakkeKeyGen(void) int i, count; const char**desc = bench_desc_words[lng_index]; int ret; + DECLARE_MULTI_VALUE_STATS_VARS() /* Key Gen */ bench_stats_start(&count, &start); @@ -9665,10 +11402,19 @@ void bench_sakkeKeyGen(void) break; } wc_FreeSakkeKey(&genKey); + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif } void bench_sakkeRskGen(void) @@ -9680,6 +11426,7 @@ void bench_sakkeRskGen(void) ecc_point* rsk; static const byte id[] = { 0x01, 0x23, 0x34, 0x45 }; int ret; + DECLARE_MULTI_VALUE_STATS_VARS() rsk = wc_ecc_new_point(); wc_InitSakkeKey_ex(&genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID); @@ -9694,10 +11441,19 @@ void bench_sakkeRskGen(void) printf("wc_MakeSakkeRsk failed: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_FreeSakkeKey(&genKey); wc_ecc_del_point(rsk); @@ -9715,6 +11471,7 @@ void bench_sakkeValidate(void) static const byte id[] = { 0x01, 0x23, 0x34, 0x45 }; int valid; int ret; + DECLARE_MULTI_VALUE_STATS_VARS() rsk = wc_ecc_new_point(); (void)wc_InitSakkeKey_ex(&genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID); @@ -9732,10 +11489,19 @@ void bench_sakkeValidate(void) valid); break; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_FreeSakkeKey(&genKey); wc_ecc_del_point(rsk); @@ -9759,6 +11525,7 @@ void bench_sakke(void) word32 len = 0; byte* iTable = NULL; word32 iTableLen = 0; + DECLARE_MULTI_VALUE_STATS_VARS() XMEMCPY(ssv, ssv_init, sizeof ssv); @@ -9780,12 +11547,22 @@ void bench_sakke(void) printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } /* for */ count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1", 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); /* Derive */ bench_stats_start(&count, &start); @@ -9798,12 +11575,21 @@ void bench_sakke(void) printf("wc_DeriveSakkeSSV failed: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } if (ret != 0) break; count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1", 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif /* Calculate Point I and generate table. */ (void)wc_MakeSakkePointI(&genKey, id, sizeof(id)); @@ -9825,12 +11611,22 @@ void bench_sakke(void) printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); (void)wc_SetSakkeRsk(&genKey, rsk, table, len); @@ -9845,13 +11641,23 @@ void bench_sakke(void) printf("wc_DeriveSakkeSSV failed: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } if (ret != 0) break; count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); len = 0; (void)wc_GenerateSakkeRskTable(&genKey, rsk, NULL, &len); @@ -9872,12 +11678,23 @@ void bench_sakke(void) printf("wc_DeriveSakkeSSV failed: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } if (ret != 0) break; count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3", 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif + + RESET_MULTI_VALUE_STATS_VARS(); wc_ClearSakkePointITable(&genKey); /* Derive with RSK table */ @@ -9891,12 +11708,21 @@ void bench_sakke(void) printf("wc_DeriveSakkeSSV failed: %d\n", ret); break; } + RECORD_MULTI_VALUE_STATS(); } if (ret != 0) break; count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); + bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0, count, start, 0); +#ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); +#endif wc_FreeSakkeKey(&genKey); wc_ecc_del_point(rsk); @@ -9916,6 +11742,7 @@ void bench_falconKeySign(byte level) byte msg[512]; word32 x = 0; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() ret = wc_falcon_init(&key); if (ret != 0) { @@ -9966,15 +11793,25 @@ void bench_falconKeySign(byte level) printf("wc_falcon_sign_msg failed\n"); } } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); if (ret == 0) { bench_stats_asym_finish("FALCON", level, desc[4], 0, count, start, ret); + #ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); + #endif } + RESET_MULTI_VALUE_STATS_VARS(); + bench_stats_start(&count, &start); do { for (i = 0; i < agreeTimes; i++) { @@ -9988,13 +11825,21 @@ void bench_falconKeySign(byte level) ret = -1; } } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); if (ret == 0) { bench_stats_asym_finish("FALCON", level, desc[5], 0, count, start, ret); + #ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); + #endif } wc_falcon_free(&key); @@ -10012,6 +11857,7 @@ void bench_dilithiumKeySign(byte level) byte msg[512]; word32 x = 0; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() ret = wc_dilithium_init(&key); if (ret != 0) { @@ -10068,15 +11914,25 @@ void bench_dilithiumKeySign(byte level) printf("wc_dilithium_sign_msg failed\n"); } } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); if (ret == 0) { bench_stats_asym_finish("DILITHIUM", level, desc[4], 0, count, start, ret); + #ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); + #endif } + RESET_MULTI_VALUE_STATS_VARS(); + bench_stats_start(&count, &start); do { for (i = 0; i < agreeTimes; i++) { @@ -10091,13 +11947,21 @@ void bench_dilithiumKeySign(byte level) ret = -1; } } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); if (ret == 0) { bench_stats_asym_finish("DILITHIUM", level, desc[5], 0, count, start, ret); + #ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); + #endif } wc_dilithium_free(&key); @@ -10115,6 +11979,7 @@ void bench_sphincsKeySign(byte level, byte optim) byte msg[512]; word32 x = 0; const char**desc = bench_desc_words[lng_index]; + DECLARE_MULTI_VALUE_STATS_VARS() ret = wc_sphincs_init(&key); if (ret != 0) { @@ -10195,9 +12060,14 @@ void bench_sphincsKeySign(byte level, byte optim) printf("wc_sphincs_sign_msg failed\n"); } } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); if (ret == 0) { if (optim == FAST_VARIANT) { @@ -10208,8 +12078,13 @@ void bench_sphincsKeySign(byte level, byte optim) bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count, start, ret); } + #ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); + #endif } + RESET_MULTI_VALUE_STATS_VARS(); + bench_stats_start(&count, &start); do { for (i = 0; i < agreeTimes; i++) { @@ -10224,9 +12099,14 @@ void bench_sphincsKeySign(byte level, byte optim) ret = -1; } } + RECORD_MULTI_VALUE_STATS(); } count += i; - } while (bench_stats_check(start)); + } while (bench_stats_check(start) +#ifdef MULTI_VALUE_STATISTICS + || runs < minimum_runs +#endif + ); if (ret == 0) { if (optim == FAST_VARIANT) { @@ -10237,6 +12117,9 @@ void bench_sphincsKeySign(byte level, byte optim) bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count, start, ret); } + #ifdef MULTI_VALUE_STATISTICS + bench_multi_value_stats(max, min, sum, squareSum, runs); + #endif } wc_sphincs_free(&key); @@ -10265,7 +12148,11 @@ void bench_sphincsKeySign(byte level, byte optim) QueryPerformanceCounter(&count); +#ifdef BENCH_MICROSECOND + return ((double)count.QuadPart * 1000000) / freq.QuadPart; +#else return (double)count.QuadPart / freq.QuadPart; +#endif } #elif defined MICROCHIP_PIC32 @@ -10303,21 +12190,110 @@ void bench_sphincsKeySign(byte level, byte optim) /* prototype definition */ int construct_argv(); extern char* __argv[22]; -#endif + + /* current_time(reset) + * + * Benchmark passage of time, in fractional seconds. + * [reset] is non zero to adjust timer or counter to zero + * + * Use care when repeatedly calling calling. See implementation. */ double current_time(int reset) { + double ret; #if ESP_IDF_VERSION_MAJOR >= 4 - TickType_t tickCount; + TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */ #else portTickType tickCount; #endif - (void) reset; + #if defined(__XTENSA__) + (void)reset; + if (reset) { + /* TODO: Determine a mechanism for reset that does not interfere + * with freeRTOS tick. Using this code for Xtensa appears to cause + * RTOS tick timer to stick. See "last_tickCount unchanged". + ESP_LOGW(TAG, "Current_time() reset!"); + portTICK_TYPE_ENTER_CRITICAL(); + { + esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0); + _esp_cpu_count_last = xthal_get_ccount(); + _esp_cpu_count_last = esp_cpu_get_cycle_count(); + } + portTICK_TYPE_EXIT_CRITICAL(); + */ + } + #else + /* Only reset the CPU counter for RISC-V */ + if (reset) { + ESP_LOGV(TAG, "current_time() reset!"); + /* TODO: why does Espressif esp_cpu_get_cycle_count() cause + * unexpected rollovers in return values for Xtensa but not RISC-V? + * See also esp_get_cycle_count_ex() */ + #ifdef __XTENSA__ + _esp_cpu_count_last = xthal_get_ccount(); + #else + esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0); + _esp_cpu_count_last = esp_cpu_get_cycle_count(); + #endif + } + #endif + + /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */ + tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles! + The count of ticks since vTaskStartScheduler was called, + typiclly in app_startup.c */ + + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + ESP_LOGV(TAG, "tickCount = %lu", tickCount); + if (tickCount == last_tickCount) { + ESP_LOGW(TAG, "last_tickCount unchanged? %lu", tickCount); + + } + if (tickCount < last_tickCount) { + ESP_LOGW(TAG, "last_tickCount overflow?"); + } + #endif + + if (reset) { + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + ESP_LOGW(TAG, "Assign last_tickCount = %lu", tickCount); + #endif + last_tickCount = tickCount; + } + else { + #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING + ESP_LOGW(TAG, "No Reset last_tickCount = %lu", tickCount); + #endif + } + + #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ) + ret = (double)tickCount / configTICK_RATE_HZ; + #else + ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined," + "assuming 1000 Hz."); + ret = (double)(tickCount / 1000.0); + #endif /* configTICK_RATE_HZ */ + + return ret; + + } /* current_time */ +#else + /* current_time(reset) + * + * Benchmark passage of time, in fractional seconds. + * [reset] is non zero to adjust timer or counter to zero + * + * Use care when repeatedly calling calling. See implementation. */ + double current_time(int reset) + { + portTickType tickCount; /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */ tickCount = xTaskGetTickCount(); return (double)tickCount / 1000; } +#endif + #elif defined (WOLFSSL_TIRTOS) @@ -10356,7 +12332,7 @@ void bench_sphincsKeySign(byte level, byte optim) { double time_now; double current_s = OS_GetTime() / 1000.0; - double current_us = OS_GetTime_us() / 1000000.0; + double current_us = OS_GetTime_us() / MILLION_VALUE; time_now = (double)( current_s + current_us); (void) reset; @@ -10483,20 +12459,20 @@ void bench_sphincsKeySign(byte level, byte optim) * outside wolfcrypt. */ return (double)rusage.ru_utime.tv_sec + - (double)rusage.ru_utime.tv_usec / 1000000.0; + (double)rusage.ru_utime.tv_usec / MILLION_VALUE; } static void check_for_excessive_stime(const char *desc, const char *desc_extra) { double start_utime = (double)base_rusage.ru_utime.tv_sec + - (double)base_rusage.ru_utime.tv_usec / 1000000.0; + (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE; double start_stime = (double)base_rusage.ru_stime.tv_sec + - (double)base_rusage.ru_stime.tv_usec / 1000000.0; + (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE; double cur_utime = (double)cur_rusage.ru_utime.tv_sec + - (double)cur_rusage.ru_utime.tv_usec / 1000000.0; + (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE; double cur_stime = (double)cur_rusage.ru_stime.tv_sec + - (double)cur_rusage.ru_stime.tv_usec / 1000000.0; + (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE; double stime_utime_ratio = (cur_stime - start_stime) / (cur_utime - start_utime); if (stime_utime_ratio > .1) @@ -10521,13 +12497,17 @@ void bench_sphincsKeySign(byte level, byte optim) double current_time(int reset) { - struct timeval tv; + struct timespec tv; (void)reset; - LIBCALL_CHECK_RET(gettimeofday(&tv, 0)); + LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv)); - return (double)tv.tv_sec + (double)tv.tv_usec / 1000000; + #ifdef BENCH_MICROSECOND + return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000; + #else + return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000; + #endif } #endif /* _WIN32 */ @@ -10535,9 +12515,12 @@ void bench_sphincsKeySign(byte level, byte optim) #if defined(HAVE_GET_CYCLES) #if defined(WOLFSSL_ESPIDF) - static WC_INLINE word64 get_xtensa_cycles(void) + /* Generic CPU cycle counter for either Xtensa or RISC-V */ + static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void) { - return xthal_get_ccount_ex(); + /* Reminder for long duration between calls with + * multiple overflows will not be detected. */ + return esp_get_cycle_count_ex(); } /* implement other architectures here */ @@ -10660,6 +12643,8 @@ static void Usage(void) print_alg(bench_digest_opt[i].str, &line); for (i=0; bench_mac_opt[i].str != NULL; i++) print_alg(bench_mac_opt[i].str, &line); + for (i=0; bench_kdf_opt[i].str != NULL; i++) + print_alg(bench_kdf_opt[i].str, &line); for (i=0; bench_asym_opt[i].str != NULL; i++) print_alg(bench_asym_opt[i].str, &line); for (i=0; bench_other_opt[i].str != NULL; i++) @@ -10688,6 +12673,18 @@ static void Usage(void) e++; #ifdef WC_BENCH_TRACK_STATS printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */ +#endif + e++; +#ifndef NO_FILESYSTEM + printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */ +#endif + e++; +#ifndef NO_FILESYSTEM + printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */ +#endif +#ifdef MULTI_VALUE_STATISTICS + e++; + printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */ #endif } @@ -10726,25 +12723,18 @@ static int string_matches(const char* arg, const char* str) #endif { + /* Code for main() or wolf_benchmark_task() */ #ifdef WOLFSSL_ESPIDF int argc = construct_argv(); char** argv = (char**)__argv; - - #if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) - ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config, &esp_gptimer)); - ESP_LOGI(TAG, "Enable ESP32-C3 timer "); - ESP_ERROR_CHECK(gptimer_enable(esp_gptimer)); - ESP_ERROR_CHECK(gptimer_start(esp_gptimer)); - #endif #elif defined(MAIN_NO_ARGS) int argc = 0; char** argv = NULL; - #endif return wolfcrypt_benchmark_main(argc, argv); } -#endif /* NO_MAIN_DRIVER && NO_MAIN_FUNCTION */ +#endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */ int wolfcrypt_benchmark_main(int argc, char** argv) { @@ -10866,6 +12856,29 @@ int wolfcrypt_benchmark_main(int argc, char** argv) if (argc > 1) numBlocks = XATOI(argv[1]); } +#ifndef NO_FILESYSTEM + else if (string_matches(argv[1], "-hash_input")) { + argc--; + argv++; + if (argc > 1) + hash_input = argv[1]; + } + else if (string_matches(argv[1], "-cipher_input")) { + argc--; + argv++; + if (argc > 1) + cipher_input = argv[1]; + } +#endif +#ifdef MULTI_VALUE_STATISTICS + else if (string_matches(argv[1], "-min_runs")) { + argc--; + argv++; + if (argc > 1) { + minimum_runs = XATOI(argv[1]); + } + } +#endif else if (argv[1][0] == '-') { optMatched = 0; #ifndef WOLFSSL_BENCHMARK_ALL @@ -10894,6 +12907,14 @@ int wolfcrypt_benchmark_main(int argc, char** argv) optMatched = 1; } } + /* Known KDF algorithms */ + for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) { + if (string_matches(argv[1], bench_kdf_opt[i].str)) { + bench_kdf_algs |= bench_kdf_opt[i].val; + bench_all = 0; + optMatched = 1; + } + } /* Known asymmetric algorithms */ for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) { if (string_matches(argv[1], bench_asym_opt[i].str)) { @@ -10978,6 +12999,22 @@ int wolfcrypt_benchmark_main(int argc, char** argv) else #endif { + #if defined(CONFIG_IDF_TARGET_ESP32C2) || \ + defined(CONFIG_IDF_TARGET_ESP32C3) || \ + defined(CONFIG_IDF_TARGET_ESP32C6) + { + #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG + if (esp_gptimer == NULL) { + ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config, + &esp_gptimer) ); + } + ESP_ERROR_CHECK(gptimer_enable(esp_gptimer)); + ESP_ERROR_CHECK(gptimer_start(esp_gptimer)); + ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET); + #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */ + } + #endif + #ifdef HAVE_STACK_SIZE ret = StackSizeCheck(NULL, benchmark_test); #else @@ -10985,6 +13022,17 @@ int wolfcrypt_benchmark_main(int argc, char** argv) #endif } + #if defined(CONFIG_IDF_TARGET_ESP32C2) || \ + defined(CONFIG_IDF_TARGET_ESP32C3) || \ + defined(CONFIG_IDF_TARGET_ESP32C6) + { + #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG + ESP_ERROR_CHECK(gptimer_stop(esp_gptimer)); + ESP_ERROR_CHECK(gptimer_disable(esp_gptimer)); + #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */ + } + #endif + return ret; } #endif /* !NO_MAIN_DRIVER */ diff --git a/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.h b/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.h index 765d15f..cefef7c 100644 --- a/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.h +++ b/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.h @@ -95,6 +95,7 @@ void bench_hmac_sha256(int useDeviceID); void bench_hmac_sha384(int useDeviceID); void bench_hmac_sha512(int useDeviceID); void bench_siphash(void); +void bench_srtpkdf(void); void bench_rsaKeyGen(int useDeviceID); void bench_rsaKeyGen_size(int useDeviceID, word32 keySz); void bench_rsa(int useDeviceID); diff --git a/recipes-examples/wolfcrypt/wolfcrypttest/test.c b/recipes-examples/wolfcrypt/wolfcrypttest/test.c index 4fc747c..0d1bf23 100644 --- a/recipes-examples/wolfcrypt/wolfcrypttest/test.c +++ b/recipes-examples/wolfcrypt/wolfcrypttest/test.c @@ -58,9 +58,10 @@ #ifdef HAVE_STACK_SIZE_VERBOSE #ifdef WOLFSSL_TEST_MAX_RELATIVE_STACK_BYTES - static ssize_t max_relative_stack = WOLFSSL_TEST_MAX_RELATIVE_STACK_BYTES; + static WC_MAYBE_UNUSED ssize_t max_relative_stack = + WOLFSSL_TEST_MAX_RELATIVE_STACK_BYTES; #else - static ssize_t max_relative_stack = -1; + static WC_MAYBE_UNUSED ssize_t max_relative_stack = -1; #endif #endif @@ -133,6 +134,7 @@ const byte const_byte_array[] = "A+Gd\0\0\0"; #include #include #include + #include /* */ #elif defined(WOLFSSL_ZEPHYR) #include @@ -518,6 +520,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void); #endif WOLFSSL_TEST_SUBROUTINE wc_test_ret_t x963kdf_test(void); WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void); +#ifdef WC_SRTP_KDF +WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void); +#endif WOLFSSL_TEST_SUBROUTINE wc_test_ret_t arc4_test(void); #ifdef WC_RC2 WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rc2_test(void); @@ -569,7 +574,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void); WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void); WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void); +#if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC) WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void); +#endif WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void); #ifdef HAVE_ECC WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void); @@ -713,8 +720,25 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void); /* General big buffer size for many tests. */ #define FOURK_BUF 4096 +#if defined(WOLFSSL_ESPIDF_ERROR_PAUSE) + /* When defined, pause at error condition rather than exit with error. */ + #define ERROR_OUT(err, eLabel) \ + do { \ + ret = (err); \ + esp_ShowExtendedSystemInfo(); \ + ESP_LOGE("wolfcrypt_test", "ESP Error! ret = %d ", err); \ + while (1) { \ + vTaskDelay(60000); \ + } \ + /* Just to appease compiler, don't actually go to eLabel */ \ + goto eLabel; \ + } while (0) +#else + #define ERROR_OUT(err, eLabel) do { ret = (err); goto eLabel; } while (0) +#endif -#define ERROR_OUT(err, eLabel) do { ret = (err); goto eLabel; } while (0) +/* Not all unexpected conditions are actually errors .*/ +#define WARNING_OUT(err, eLabel) do { ret = (err); goto eLabel; } while (0) static void render_error_message(const char* msg, wc_test_ret_t es) { @@ -1333,6 +1357,13 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ TEST_PASS("HPKE test passed!\n"); #endif +#if defined(WC_SRTP_KDF) + if ( (ret = srtpkdf_test()) != 0) + TEST_FAIL("SRTP KDF test failed!\n", ret); + else + TEST_PASS("SRTP KDF test passed!\n"); +#endif + #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && \ !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT) && \ !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY) @@ -1893,7 +1924,7 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ #endif { wc_test_ret_t ret; - func_args args; + func_args args = { 0, 0, 0 }; #if defined(WOLFSSL_ESPIDF) || defined(WOLFSSL_SE050) /* set dummy wallclock time. */ struct timeval utctime; @@ -1995,16 +2026,7 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ while (1); #endif -#ifdef WOLFSSL_ESPIDF - /* ESP_LOGI to print takes up a lot less memory than printf */ - ESP_LOGI("wolfcrypt_test", "Exiting main with return code: % d\n", args.return_code); -#endif - -/* everything else will use printf */ -#if !defined(WOLFSSL_ESPIDF) -/* gate this for target platforms wishing to avoid printf reference */ printf("Exiting main with return code: %ld\n", (long int)args.return_code); -#endif return args.return_code; } /* wolfcrypt_test_main or wolf_test_task */ @@ -7939,6 +7961,7 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, #else EVP_CIPHER_CTX ctx[1]; #endif + int ctx_inited = 0; int idx, cipherSz; wc_test_ret_t ret = 0; byte* cipher; @@ -7956,6 +7979,7 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, /* test encrypt */ EVP_CIPHER_CTX_init(ctx); + ctx_inited = 1; if (EVP_CipherInit(ctx, type, key, iv, 1) == 0) { ret = WC_TEST_RET_ENC_NC; goto EVP_TEST_END; @@ -7978,8 +8002,18 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, goto EVP_TEST_END; } + ret = wolfSSL_EVP_CIPHER_CTX_cleanup(ctx); + ctx_inited = 0; + if (ret == WOLFSSL_SUCCESS) + ret = 0; + else { + ret = WC_TEST_RET_ENC_NC; + goto EVP_TEST_END; + } + /* test decrypt */ EVP_CIPHER_CTX_init(ctx); + ctx_inited = 1; if (EVP_CipherInit(ctx, type, key, iv, 0) == 0) { ret = WC_TEST_RET_ENC_NC; goto EVP_TEST_END; @@ -8006,6 +8040,13 @@ EVP_TEST_END: if (cipher) XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); (void)cipherSz; + + if (ctx_inited) { + int cleanup_ret = wolfSSL_EVP_CIPHER_CTX_cleanup(ctx); + if (cleanup_ret != WOLFSSL_SUCCESS) + ret = WC_TEST_RET_ENC_NC; + } + #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wolfSSL_EVP_CIPHER_CTX_free(ctx); #endif @@ -8141,6 +8182,14 @@ EVP_TEST_END: } #endif + ret = wc_AesInit(enc, HEAP_HINT, INVALID_DEVID); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + + ret = wc_AesInit(dec, HEAP_HINT, INVALID_DEVID); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); @@ -9309,7 +9358,8 @@ static wc_test_ret_t aes_key_size_test(void) return ret; } -#if defined(WOLFSSL_AES_XTS) +#if defined(WOLFSSL_AES_XTS) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3)) + /* test vectors from http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html */ #ifdef WOLFSSL_AES_128 static wc_test_ret_t aes_xts_128_test(void) @@ -9386,8 +9436,6 @@ static wc_test_ret_t aes_xts_128_test(void) 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a }; -#if !defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3) - WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, @@ -9413,8 +9461,6 @@ static wc_test_ret_t aes_xts_128_test(void) 0xB5, 0x5A, 0xDD, 0xCB, 0x80, 0xE0, 0xFC, 0xCD }; -#endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */ - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); @@ -9430,13 +9476,16 @@ static wc_test_ret_t aes_xts_128_test(void) #endif XMEMSET(buf, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_ENCRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsInit(aes, HEAP_HINT, devId); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); else aes_inited = 1; + ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); @@ -9446,11 +9495,22 @@ static wc_test_ret_t aes_xts_128_test(void) if (XMEMCMP(c2, buf, sizeof(c2))) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - XMEMSET(buf, 0, sizeof(buf)); - wc_AesXtsFree(aes); +#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_AES_C_DYNAMIC_FALLBACK) + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); +#endif + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(c2, buf, sizeof(c2))) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#endif - ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, - HEAP_HINT, devId); + XMEMSET(buf, 0, sizeof(buf)); + + ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1)); @@ -9462,6 +9522,19 @@ static wc_test_ret_t aes_xts_128_test(void) if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_AES_C_DYNAMIC_FALLBACK) + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); +#endif + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#endif + /* partial block encryption test */ XMEMSET(cipher, 0, sizeof(cipher)); ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1)); @@ -9472,12 +9545,24 @@ static wc_test_ret_t aes_xts_128_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(cp2, cipher, sizeof(cp2))) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); + +#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_AES_C_DYNAMIC_FALLBACK) + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + XMEMSET(cipher, 0, sizeof(cipher)); + ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); +#endif + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(cp2, cipher, sizeof(cp2))) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#endif /* partial block decrypt test */ XMEMSET(buf, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1)); @@ -9489,6 +9574,20 @@ static wc_test_ret_t aes_xts_128_test(void) if (XMEMCMP(pp, buf, sizeof(pp))) ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_AES_C_DYNAMIC_FALLBACK) + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + XMEMSET(buf, 0, sizeof(buf)); + ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); +#endif + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(pp, buf, sizeof(pp))) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#endif + /* NIST decrypt test vector */ XMEMSET(buf, 0, sizeof(buf)); ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1)); @@ -9500,6 +9599,20 @@ static wc_test_ret_t aes_xts_128_test(void) if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_AES_C_DYNAMIC_FALLBACK) + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + XMEMSET(buf, 0, sizeof(buf)); + ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); +#endif + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#endif + /* fail case with decrypting using wrong key */ XMEMSET(buf, 0, sizeof(buf)); ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2)); @@ -9511,12 +9624,9 @@ static wc_test_ret_t aes_xts_128_test(void) if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */ ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); - /* set correct key and retest */ XMEMSET(buf, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_DECRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2)); @@ -9528,18 +9638,11 @@ static wc_test_ret_t aes_xts_128_test(void) if (XMEMCMP(p2, buf, sizeof(p2))) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); - -#if !defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3) - /* Test ciphertext stealing in-place. */ XMEMCPY(buf, p3, sizeof(p3)); - ret = wc_AesXtsSetKey(aes, k3, sizeof(k3), AES_ENCRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - else - aes_inited = 1; ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3)); #if defined(WOLFSSL_ASYNC_CRYPT) @@ -9550,10 +9653,7 @@ static wc_test_ret_t aes_xts_128_test(void) if (XMEMCMP(c3, buf, sizeof(c3))) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); - - ret = wc_AesXtsSetKey(aes, k3, sizeof(k3), AES_DECRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3)); @@ -9565,10 +9665,7 @@ static wc_test_ret_t aes_xts_128_test(void) if (XMEMCMP(p3, buf, sizeof(p3))) ERROR_OUT(WC_TEST_RET_ENC_NC, out); -#endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */ - #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \ - (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3)) && \ !defined(WOLFSSL_AFALG) { #define LARGE_XTS_SZ 1024 @@ -9589,8 +9686,7 @@ static wc_test_ret_t aes_xts_128_test(void) large_input[i] = (byte)i; for (j = 16; j < (int)LARGE_XTS_SZ; j++) { - ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1, @@ -9601,8 +9697,7 @@ static wc_test_ret_t aes_xts_128_test(void) if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1, @@ -9623,7 +9718,6 @@ static wc_test_ret_t aes_xts_128_test(void) #endif } #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM && - * (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) && * !WOLFSSL_AFALG */ @@ -9741,13 +9835,17 @@ static wc_test_ret_t aes_xts_256_test(void) } #endif - XMEMSET(buf, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_ENCRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsInit(aes, HEAP_HINT, devId); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); else aes_inited = 1; + + XMEMSET(buf, 0, sizeof(buf)); + ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); @@ -9756,11 +9854,9 @@ static wc_test_ret_t aes_xts_256_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c2, buf, sizeof(c2))) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); XMEMSET(buf, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1)); @@ -9780,12 +9876,10 @@ static wc_test_ret_t aes_xts_256_test(void) #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - wc_AesXtsFree(aes); /* partial block decrypt test */ XMEMSET(buf, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1)); @@ -9807,11 +9901,9 @@ static wc_test_ret_t aes_xts_256_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); XMEMSET(buf, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_DECRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2)); @@ -10020,13 +10112,17 @@ static wc_test_ret_t aes_xts_sector_test(void) ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif - XMEMSET(buf, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsInit(aes, HEAP_HINT, devId); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); else aes_inited = 1; + + XMEMSET(buf, 0, sizeof(buf)); + ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesXtsEncryptSector(aes, buf, p1, sizeof(p1), s1); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); @@ -10035,12 +10131,10 @@ static wc_test_ret_t aes_xts_sector_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); /* decrypt test */ XMEMSET(buf, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecryptSector(aes, buf, c1, sizeof(c1), s1); @@ -10051,12 +10145,10 @@ static wc_test_ret_t aes_xts_sector_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); /* 256 bit key tests */ XMEMSET(buf, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_ENCRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsEncryptSector(aes, buf, p2, sizeof(p2), s2); @@ -10067,12 +10159,10 @@ static wc_test_ret_t aes_xts_sector_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c2, buf, sizeof(c2))) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); /* decrypt test */ XMEMSET(buf, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_DECRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecryptSector(aes, buf, c2, sizeof(c2), s2); @@ -10083,14 +10173,12 @@ static wc_test_ret_t aes_xts_sector_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p2, buf, sizeof(p2))) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); #if !defined(BENCH_EMBEDDED) && \ (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) /* encrypt consecutive sectors test */ XMEMSET(data, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k3, sizeof(k3), AES_ENCRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsEncryptConsecutiveSectors(aes, data, p3, @@ -10102,12 +10190,10 @@ static wc_test_ret_t aes_xts_sector_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c3, data, sizeof(c3))) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); /* decrypt consecutive sectors test */ XMEMSET(data, 0, sizeof(buf)); - ret = wc_AesXtsSetKey(aes, k3, sizeof(k3), AES_DECRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecryptConsecutiveSectors(aes, data, c3, @@ -10119,7 +10205,6 @@ static wc_test_ret_t aes_xts_sector_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p3, data, sizeof(p3))) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); #endif /* !BENCH_EMBEDDED && (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) */ @@ -10175,20 +10260,22 @@ static wc_test_ret_t aes_xts_args_test(void) ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif - if (wc_AesXtsSetKey(NULL, k1, sizeof(k1), AES_ENCRYPTION, - HEAP_HINT, devId) == 0) - ERROR_OUT(WC_TEST_RET_ENC_NC, out); - if (wc_AesXtsSetKey(aes, NULL, sizeof(k1), AES_ENCRYPTION, - HEAP_HINT, devId) == 0) - ERROR_OUT(WC_TEST_RET_ENC_NC, out); - - /* encryption operations */ - ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsInit(aes, HEAP_HINT, devId); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); else aes_inited = 1; + + if (wc_AesXtsSetKeyNoInit(NULL, k1, sizeof(k1), AES_ENCRYPTION) == 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + if (wc_AesXtsSetKeyNoInit(aes, NULL, sizeof(k1), AES_ENCRYPTION) == 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + + /* encryption operations */ + ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesXtsEncryptSector(NULL, buf, p1, sizeof(p1), s1); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); @@ -10202,11 +10289,9 @@ static wc_test_ret_t aes_xts_args_test(void) #endif if (ret == 0) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesXtsFree(aes); /* decryption operations */ - ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, - HEAP_HINT, devId); + ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecryptSector(NULL, buf, c1, sizeof(c1), s1); @@ -10238,7 +10323,7 @@ static wc_test_ret_t aes_xts_args_test(void) return ret; } #endif /* WOLFSSL_AES_128 */ -#endif /* WOLFSSL_AES_XTS */ +#endif /* WOLFSSL_AES_XTS && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */ #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) static wc_test_ret_t aes_cbc_test(void) @@ -10348,17 +10433,83 @@ static wc_test_ret_t aesecb_test(void) if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0) ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_AES_C_DYNAMIC_FALLBACK) + XMEMSET(cipher, 0, AES_BLOCK_SIZE); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesEcbEncrypt(enc, cipher, niPlain, AES_BLOCK_SIZE); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + + XMEMSET(cipher, 0, AES_BLOCK_SIZE); + ret = wc_AesEcbEncrypt(enc, cipher, niPlain, AES_BLOCK_SIZE); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + + XMEMSET(cipher, 0, AES_BLOCK_SIZE); + ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesEcbEncrypt(enc, cipher, niPlain, AES_BLOCK_SIZE); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#endif + XMEMSET(plain, 0, AES_BLOCK_SIZE); ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE) != 0) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE); if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - } +#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_AES_C_DYNAMIC_FALLBACK) + XMEMSET(plain, 0, AES_BLOCK_SIZE); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + + XMEMSET(plain, 0, AES_BLOCK_SIZE); + ret = wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + + XMEMSET(plain, 0, AES_BLOCK_SIZE); + ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#endif + } out: #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -10989,6 +11140,86 @@ static wc_test_ret_t aesctr_test(Aes* enc, Aes* dec, byte* cipher, byte* plain) #endif } +#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_AES_C_DYNAMIC_FALLBACK) + for (i = 0; i < AES_CTR_TEST_LEN; i++) { + if (testVec[i].key != NULL) { + ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz, + testVec[i].iv, AES_ENCRYPTION); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); + } + /* Ctr only uses encrypt, even on key setup */ + ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz, + testVec[i].iv, AES_ENCRYPTION); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); + } + } + + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); + } + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); + } + + if (XMEMCMP(plain, ctrPlain, testVec[i].len)) { + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); + } +#if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM)) + if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) { + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); + } +#endif + } + + for (i = 0; i < AES_CTR_TEST_LEN; i++) { + if (testVec[i].key != NULL) { + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz, + testVec[i].iv, AES_ENCRYPTION); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); + } + /* Ctr only uses encrypt, even on key setup */ + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz, + testVec[i].iv, AES_ENCRYPTION); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); + } + } + + ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); + } + ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); + } + + if (XMEMCMP(plain, ctrPlain, testVec[i].len)) { + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); + } +#if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM)) + if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) { + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); + } +#endif + } + +#endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_AES_C_DYNAMIC_FALLBACK */ + + out: return ret; } @@ -11070,6 +11301,35 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif +#ifdef HAVE_AES_ECB + { + WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb[AES_BLOCK_SIZE] = { + 0xd0, 0xc9, 0xd9, 0xc9, 0x40, 0xe8, 0x97, 0xb6, + 0xc8, 0x8c, 0x33, 0x3b, 0xb5, 0x8f, 0x85, 0xd1 + }; + XMEMSET(cipher, 0, AES_BLOCK_SIZE * 4); + ret = wc_AesEcbEncrypt(enc, cipher, msg, AES_BLOCK_SIZE); + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + #endif + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(cipher, verify_ecb, AES_BLOCK_SIZE)) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + #ifdef HAVE_AES_DECRYPT + XMEMSET(plain, 0, AES_BLOCK_SIZE * 4); + ret = wc_AesEcbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE); + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); + #endif + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + #endif /* HAVE_AES_DECRYPT */ + } +#endif + XMEMSET(cipher, 0, AES_BLOCK_SIZE * 4); ret = wc_AesCbcEncrypt(enc, cipher, msg, AES_BLOCK_SIZE); #if defined(WOLFSSL_ASYNC_CRYPT) @@ -11213,6 +11473,57 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void) break; } +#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_AES_C_DYNAMIC_FALLBACK) + /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole + * message by AES_BLOCK_SIZE for each size of AES key. */ + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + for (keySz = 16; keySz <= 32; keySz += 8) { + for (msgSz = AES_BLOCK_SIZE; + msgSz <= sizeof(bigMsg); + msgSz += AES_BLOCK_SIZE) { + + XMEMSET(bigCipher, 0, sizeof(bigMsg)); + XMEMSET(bigPlain, 0, sizeof(bigMsg)); + ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION); + if (ret != 0) { + ret = WC_TEST_RET_ENC_EC(ret); + break; + } + ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION); + if (ret != 0) { + ret = WC_TEST_RET_ENC_EC(ret); + break; + } + + ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz); + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + #endif + if (ret != 0) { + ret = WC_TEST_RET_ENC_EC(ret); + break; + } + + ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz); + #if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); + #endif + if (ret != 0) { + ret = WC_TEST_RET_ENC_EC(ret); + break; + } + + if (XMEMCMP(bigPlain, bigMsg, msgSz)) { + ret = WC_TEST_RET_ENC_NC; + break; + } + } + if (ret != 0) + break; + } + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); +#endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_AES_C_DYNAMIC_FALLBACK */ + #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); @@ -11386,7 +11697,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void) goto out; #endif -#if defined(WOLFSSL_AES_XTS) +#if defined(WOLFSSL_AES_XTS) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3)) #ifdef WOLFSSL_AES_128 ret = aes_xts_128_test(); if (ret != 0) @@ -11542,6 +11853,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void) #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(cipher, verify, (int) sizeof(cipher))) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + #ifdef HAVE_AES_DECRYPT XMEMSET(plain, 0, AES_BLOCK_SIZE); ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher)); @@ -11555,9 +11869,6 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void) } #endif - if (XMEMCMP(cipher, verify, (int) sizeof(cipher))) - ERROR_OUT(WC_TEST_RET_ENC_NC, out); - wc_AesFree(enc); #ifdef HAVE_AES_DECRYPT wc_AesFree(dec); @@ -11683,6 +11994,93 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void) wc_AesFree(enc); #ifdef HAVE_AES_DECRYPT wc_AesFree(dec); +#endif + +#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_AES_C_DYNAMIC_FALLBACK) + ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); +#ifdef HAVE_AES_DECRYPT + ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); +#endif + + XMEMSET(cipher, 0, AES_BLOCK_SIZE); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); +#endif + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); +#ifdef HAVE_AES_DECRYPT + XMEMSET(plain, 0, AES_BLOCK_SIZE); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); +#endif + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(plain, msg, (int) sizeof(plain))) { + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + } +#endif +#ifndef HAVE_RENESAS_SYNC + if (XMEMCMP(cipher, verify, (int) sizeof(cipher))) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#endif + + wc_AesFree(enc); +#ifdef HAVE_AES_DECRYPT + wc_AesFree(dec); +#endif + + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); +#ifdef HAVE_AES_DECRYPT + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION); + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); +#endif + + XMEMSET(cipher, 0, AES_BLOCK_SIZE); + ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); +#endif + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); +#ifdef HAVE_AES_DECRYPT + XMEMSET(plain, 0, AES_BLOCK_SIZE); + ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); +#endif + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(plain, msg, (int) sizeof(plain))) { + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + } +#endif +#ifndef HAVE_RENESAS_SYNC + if (XMEMCMP(cipher, verify, (int) sizeof(cipher))) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#endif + + wc_AesFree(enc); +#ifdef HAVE_AES_DECRYPT + wc_AesFree(dec); +#endif + #endif out: @@ -11751,7 +12149,6 @@ static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, /* AES-GCM encrypt and decrypt both use AES encrypt internally */ ret = wc_AesGcmEncrypt(enc, resultC, plain, plainSz, iv, ivSz, resultT, tagSz, aad, aadSz); - #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif @@ -11764,6 +12161,23 @@ static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, if (XMEMCMP(tag, resultT, tagSz)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_AES_C_DYNAMIC_FALLBACK) + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesGcmEncrypt(enc, resultC, plain, plainSz, iv, ivSz, + resultT, tagSz, aad, aadSz); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); +#endif + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (cipher != NULL) { + if (XMEMCMP(cipher, resultC, cipherSz)) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + } + if (XMEMCMP(tag, resultT, tagSz)) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#endif #ifdef HAVE_AES_DECRYPT ret = wc_AesGcmSetKey(dec, key, keySz); @@ -11782,6 +12196,22 @@ static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, ERROR_OUT(WC_TEST_RET_ENC_NC, out); } +#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_AES_C_DYNAMIC_FALLBACK) + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(SYSLIB_FAILED_E); + ret = wc_AesGcmDecrypt(dec, resultP, resultC, cipherSz, + iv, ivSz, resultT, tagSz, aad, aadSz); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); +#endif + WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (plain != NULL) { + if (XMEMCMP(plain, resultP, plainSz)) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + } +#endif + #endif /* HAVE_AES_DECRYPT */ ret = 0; @@ -12210,10 +12640,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void) #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) - ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif /* HAVE_AES_DECRYPT */ #endif /* BENCH_AESGCM_LARGE */ #if defined(ENABLE_NON_12BYTE_IV_TEST) && defined(WOLFSSL_AES_256) @@ -12395,6 +12825,38 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ + /* Large buffer test */ +#ifdef BENCH_AESGCM_LARGE + wc_AesGcmSetKey(enc, k2, k3Sz); + wc_AesGcmSetKey(dec, k2, k3Sz); + /* setup test buffer */ + for (alen=0; alenasyncDev, WC_ASYNC_FLAG_NONE); +#endif + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + +#ifdef HAVE_AES_DECRYPT + ret = wc_AesGcmDecrypt(dec, large_outdec, large_output, + BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT, + sizeof(t1), a, sizeof(a)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); +#endif + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE)) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#endif /* HAVE_AES_DECRYPT */ +#endif /* BENCH_AESGCM_LARGE */ + XMEMSET(resultT, 0, sizeof(resultT)); XMEMSET(resultC, 0, sizeof(resultC)); XMEMSET(resultP, 0, sizeof(resultP)); @@ -12427,6 +12889,38 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void) if (XMEMCMP(p3, resultP, sizeof(p3))) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ + + /* Large buffer test */ +#ifdef BENCH_AESGCM_LARGE + wc_AesGcmSetKey(enc, k3, k3Sz); + wc_AesGcmSetKey(dec, k3, k3Sz); + /* setup test buffer */ + for (alen=0; alenasyncDev, WC_ASYNC_FLAG_NONE); +#endif + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + +#ifdef HAVE_AES_DECRYPT + ret = wc_AesGcmDecrypt(dec, large_outdec, large_output, + BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT, + sizeof(t1), a, sizeof(a)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); +#endif + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE)) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); +#endif /* HAVE_AES_DECRYPT */ +#endif /* BENCH_AESGCM_LARGE */ #endif /* WOLFSSL_AES_128 */ #endif /* ENABLE_NON_12BYTE_IV_TEST */ @@ -13064,6 +13558,10 @@ static wc_test_ret_t aesccm_128_test(void) XMEMSET(p2, 0, sizeof(p2)); XMEMSET(iv2, 0, sizeof(iv2)); + ret = wc_AesInit(enc, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + #ifndef HAVE_SELFTEST /* selftest build does not have wc_AesCcmSetNonce() or * wc_AesCcmEncrypt_ex() */ @@ -15350,7 +15848,7 @@ static void initDefaultName(void) WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage[] = "digitalSignature,nonRepudiation"; #endif - #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) + #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_ASN_TIME) WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage2[] = "digitalSignature,nonRepudiation,keyEncipherment,keyAgreement"; #endif @@ -16418,7 +16916,7 @@ static wc_test_ret_t rsa_decode_test(RsaKey* keyPub) goto done; } ret = wc_RsaPublicKeyDecodeRaw(n, (word32)-1, e, sizeof(e), keyPub); -#if !defined(WOLFSSL_SP_MATH) & !defined(WOLFSSL_SP_MATH_ALL) +#if defined(USE_INTEGER_HEAP_MATH) if (ret != 0) #else if (ret != ASN_GETINT_E) @@ -16432,11 +16930,12 @@ static wc_test_ret_t rsa_decode_test(RsaKey* keyPub) if (ret != 0) return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, (word32)-1, keyPub); -#if !defined(WOLFSSL_SP_MATH) & !defined(WOLFSSL_SP_MATH_ALL) - if (ret != 0) { +#if defined(USE_INTEGER_HEAP_MATH) + if (ret != 0) #else - if (ret != ASN_GETINT_E) { + if (ret != ASN_GETINT_E) #endif + { ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -20089,11 +20588,15 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void) word32 bytes; word32 idx = 0; WC_RNG rng; + int rng_inited = 0; wc_Sha sha; byte hash[WC_SHA_DIGEST_SIZE]; byte signature[40]; + int key_inited = 0; #ifdef WOLFSSL_KEY_GEN byte* der = 0; + int derIn_inited = 0; + int genKey_inited = 0; #endif #define DSA_TEST_TMP_SIZE 1024 #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -20103,6 +20606,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void) DsaKey *derIn = (DsaKey *)XMALLOC(sizeof *derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); DsaKey *genKey = (DsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); #endif + if ((tmp == NULL) || (key == NULL) #ifdef WOLFSSL_KEY_GEN @@ -20151,6 +20655,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void) ret = wc_InitDsaKey(key); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + key_inited = 1; ret = wc_DsaPrivateKeyDecode(tmp, &idx, key, bytes); if (ret != 0) @@ -20163,6 +20668,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void) #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + rng_inited = 1; ret = wc_DsaSign(hash, signature, key, &rng); if (ret != 0) @@ -20175,6 +20681,12 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void) ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_FreeDsaKey(key); + key_inited = 0; + + ret = wc_InitDsaKey_h(key, NULL); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + key_inited = 1; #ifdef WOLFSSL_KEY_GEN { @@ -20183,70 +20695,43 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void) ret = wc_InitDsaKey(genKey); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + genKey_inited = 1; ret = wc_MakeDsaParameters(&rng, 1024, genKey); - if (ret != 0) { - wc_FreeDsaKey(genKey); + if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - } ret = wc_MakeDsaKey(&rng, genKey); - if (ret != 0) { - wc_FreeDsaKey(genKey); + if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - } der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if (der == NULL) { - wc_FreeDsaKey(genKey); + if (der == NULL) ERROR_OUT(WC_TEST_RET_ENC_NC, out); - } derSz = wc_DsaKeyToDer(genKey, der, FOURK_BUF); - if (derSz < 0) { - XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + if (derSz < 0) ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), out); - } ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile, DSA_PRIVATEKEY_TYPE); - if (ret != 0) { - XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - wc_FreeDsaKey(genKey); + if (ret != 0) goto out; - } ret = wc_InitDsaKey(derIn); - if (ret != 0) { - XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - wc_FreeDsaKey(genKey); + if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - } + derIn_inited = 1; idx = 0; ret = wc_DsaPrivateKeyDecode(der, &idx, derIn, derSz); - if (ret != 0) { - XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - wc_FreeDsaKey(derIn); - wc_FreeDsaKey(genKey); + if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } - - } #endif /* WOLFSSL_KEY_GEN */ out: -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) - if (key) { -#endif - ret = wc_InitDsaKey_h(key, NULL); - if (ret != 0) - ret = WC_TEST_RET_ENC_EC(ret); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) - } -#endif - #ifdef WOLFSSL_KEY_GEN if (der) XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); @@ -20255,29 +20740,39 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (tmp) XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if (key) + if (key) { + if (key_inited) + wc_FreeDsaKey(key); XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + } #ifdef WOLFSSL_KEY_GEN if (derIn) { - wc_FreeDsaKey(derIn); + if (derIn_inited) + wc_FreeDsaKey(derIn); XFREE(derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); } if (genKey) { - wc_FreeDsaKey(genKey); + if (genKey_inited) + wc_FreeDsaKey(genKey); XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); } #endif #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */ + if (key_inited) + wc_FreeDsaKey(key); #ifdef WOLFSSL_KEY_GEN - wc_FreeDsaKey(derIn); - wc_FreeDsaKey(genKey); + if (derIn_inited) + wc_FreeDsaKey(derIn); + if (genKey_inited) + wc_FreeDsaKey(genKey); #endif #endif - wc_FreeRng(&rng); + if (rng_inited) + wc_FreeRng(&rng); return ret; } @@ -20548,6 +21043,8 @@ static wc_test_ret_t openssl_aes_test(void) if (total != 32) return 3408; + EVP_CIPHER_CTX_cleanup(en); + total = 0; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_cbc(), @@ -20585,6 +21082,8 @@ static wc_test_ret_t openssl_aes_test(void) if (XMEMCMP(plain, cbcPlain, 18)) return WC_TEST_RET_ENC_NC; + EVP_CIPHER_CTX_cleanup(de); + /* test with encrypting/decrypting more than 16 bytes at once */ total = 0; EVP_CIPHER_CTX_init(en); @@ -20613,6 +21112,8 @@ static wc_test_ret_t openssl_aes_test(void) if (total != 32) return WC_TEST_RET_ENC_NC; + EVP_CIPHER_CTX_cleanup(en); + total = 0; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_cbc(), @@ -20659,6 +21160,8 @@ static wc_test_ret_t openssl_aes_test(void) plain[i] = i; } + EVP_CIPHER_CTX_cleanup(de); + total = 0; EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_128_cbc(), @@ -20679,6 +21182,8 @@ static wc_test_ret_t openssl_aes_test(void) if (total != sizeof(plain)) return WC_TEST_RET_ENC_NC; + EVP_CIPHER_CTX_cleanup(en); + total = 0; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_cbc(), @@ -20714,6 +21219,8 @@ static wc_test_ret_t openssl_aes_test(void) } } + EVP_CIPHER_CTX_cleanup(de); + #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wolfSSL_EVP_CIPHER_CTX_free(en); wolfSSL_EVP_CIPHER_CTX_free(de); @@ -20777,6 +21284,8 @@ static wc_test_ret_t openssl_aes_test(void) if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) != 0) return WC_TEST_RET_ENC_NC; + EVP_CIPHER_CTX_cleanup(en); + /* turn padding back on and do successful encrypt */ total = 0; EVP_CIPHER_CTX_init(en); @@ -20799,6 +21308,8 @@ static wc_test_ret_t openssl_aes_test(void) return WC_TEST_RET_ENC_NC; XMEMCPY(cipher, padded, EVP_TEST_BUF_SZ); + EVP_CIPHER_CTX_cleanup(en); + /* test out of bounds read on buffers w/o padding during decryption */ total = 0; EVP_CIPHER_CTX_init(de); @@ -20819,6 +21330,8 @@ static wc_test_ret_t openssl_aes_test(void) if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0) return WC_TEST_RET_ENC_NC; + EVP_CIPHER_CTX_cleanup(de); + total = 0; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_cbc(), @@ -20838,6 +21351,8 @@ static wc_test_ret_t openssl_aes_test(void) if (XMEMCMP(padded, cbcPlain, EVP_TEST_BUF_SZ)) return WC_TEST_RET_ENC_NC; + EVP_CIPHER_CTX_cleanup(de); + #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wolfSSL_EVP_CIPHER_CTX_free(en); wolfSSL_EVP_CIPHER_CTX_free(de); @@ -20886,6 +21401,8 @@ static wc_test_ret_t openssl_aes_test(void) if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) return WC_TEST_RET_ENC_NC; + EVP_CIPHER_CTX_cleanup(ctx); + EVP_CIPHER_CTX_init(ctx); if (EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 0) == 0) return WC_TEST_RET_ENC_NC; @@ -20896,6 +21413,8 @@ static wc_test_ret_t openssl_aes_test(void) if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) return WC_TEST_RET_ENC_NC; + EVP_CIPHER_CTX_cleanup(ctx); + #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wolfSSL_EVP_CIPHER_CTX_free(ctx); #endif @@ -20903,6 +21422,8 @@ static wc_test_ret_t openssl_aes_test(void) #endif /* WOLFSSL_AES_128 */ #endif /* HAVE_AES_CBC */ +#ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API + #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256) { /* evp_cipher test: EVP_aes_256_ecb*/ #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -21036,6 +21557,8 @@ static wc_test_ret_t openssl_aes_test(void) } #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */ +#endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */ + /* EVP_Cipher with EVP_aes_xxx_ctr() */ #ifdef WOLFSSL_AES_COUNTER { @@ -21183,6 +21706,11 @@ static wc_test_ret_t openssl_aes_test(void) AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; + if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4)) return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4)) @@ -21210,6 +21738,11 @@ static wc_test_ret_t openssl_aes_test(void) AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; + wolfSSL_EVP_CIPHER_CTX_free(p_en); wolfSSL_EVP_CIPHER_CTX_free(p_de); #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */ @@ -21248,6 +21781,11 @@ static wc_test_ret_t openssl_aes_test(void) return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipherBuff, oddCipher, 9)) return WC_TEST_RET_ENC_NC; + + if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; #endif /* WOLFSSL_AES_128 */ #ifdef WOLFSSL_AES_192 @@ -21272,6 +21810,11 @@ static wc_test_ret_t openssl_aes_test(void) return WC_TEST_RET_ENC_NC; if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher))) return WC_TEST_RET_ENC_NC; + + if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; #endif /* WOLFSSL_AES_192 */ #ifdef WOLFSSL_AES_256 @@ -21297,6 +21840,11 @@ static wc_test_ret_t openssl_aes_test(void) if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher))) return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; + #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wolfSSL_EVP_CIPHER_CTX_free(en); wolfSSL_EVP_CIPHER_CTX_free(de); @@ -21306,6 +21854,8 @@ static wc_test_ret_t openssl_aes_test(void) } #endif /* HAVE_AES_COUNTER */ +#ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API + #if defined(WOLFSSL_AES_CFB) && defined(WOLFSSL_AES_128) { #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -21381,6 +21931,9 @@ static wc_test_ret_t openssl_aes_test(void) #endif } #endif /* WOLFSSL_AES_CFB && WOLFSSL_AES_128 */ + +#endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */ + return 0; } @@ -21940,6 +22493,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) } /* end evp_cipher test */ #endif /* HAVE_AES_ECB && WOLFSSL_AES_128 */ +#ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API + #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256) /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */ { @@ -22015,6 +22570,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */ +#endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */ + /* EVP_Cipher with EVP_aes_xxx_ctr() */ #ifdef WOLFSSL_AES_COUNTER { @@ -22165,6 +22722,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4)) return WC_TEST_RET_ENC_NC; + EVP_CIPHER_CTX_cleanup(en); + EVP_CIPHER_CTX_cleanup(de); + #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) p_en = wolfSSL_EVP_CIPHER_CTX_new(); if (p_en == NULL) @@ -22187,6 +22747,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) return WC_TEST_RET_ENC_NC; + EVP_CIPHER_CTX_cleanup(p_en); + EVP_CIPHER_CTX_cleanup(p_de); + wolfSSL_EVP_CIPHER_CTX_free(p_en); wolfSSL_EVP_CIPHER_CTX_free(p_de); #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */ @@ -22225,6 +22788,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipherBuff, oddCipher, 9)) return WC_TEST_RET_ENC_NC; + + EVP_CIPHER_CTX_cleanup(en); + EVP_CIPHER_CTX_cleanup(de); #endif /* WOLFSSL_AES_128 */ #ifdef WOLFSSL_AES_192 @@ -22249,6 +22815,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) return WC_TEST_RET_ENC_NC; if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher))) return WC_TEST_RET_ENC_NC; + + EVP_CIPHER_CTX_cleanup(en); + EVP_CIPHER_CTX_cleanup(de); #endif /* WOLFSSL_AES_192 */ #ifdef WOLFSSL_AES_256 @@ -22273,6 +22842,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void) return WC_TEST_RET_ENC_NC; if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher))) return WC_TEST_RET_ENC_NC; + + EVP_CIPHER_CTX_cleanup(en); + EVP_CIPHER_CTX_cleanup(de); #endif /* WOLFSSL_AES_256 */ #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -24806,6 +25378,444 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void) } #endif /* HAVE_HPKE && HAVE_ECC && HAVE_AESGCM */ +#if defined(WC_SRTP_KDF) +typedef struct Srtp_Kdf_Tv { + const unsigned char* key; + word32 keySz; + const unsigned char* salt; + word32 saltSz; + int kdfIdx; + const unsigned char* index; + const unsigned char* ke; + const unsigned char* ka; + const unsigned char* ks; + const unsigned char* index_c; + const unsigned char* ke_c; + const unsigned char* ka_c; + const unsigned char* ks_c; + word32 keSz; + word32 kaSz; + word32 ksSz; +} Srtp_Kdf_Tv; + +WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void) +{ + wc_test_ret_t ret = 0; + /* 128-bit key, kdrIdx = -1 */ + WOLFSSL_SMALL_STACK_STATIC const byte key_0[] = { + 0xc4, 0x80, 0x9f, 0x6d, 0x36, 0x98, 0x88, 0x72, + 0x8e, 0x26, 0xad, 0xb5, 0x32, 0x12, 0x98, 0x90 + }; + WOLFSSL_SMALL_STACK_STATIC const byte salt_0[] = { + 0x0e, 0x23, 0x00, 0x6c, 0x6c, 0x04, 0x4f, 0x56, + 0x62, 0x40, 0x0e, 0x9d, 0x1b, 0xd6 + }; + WOLFSSL_SMALL_STACK_STATIC const byte index_0[] = { + 0x48, 0x71, 0x65, 0x64, 0x9c, 0xca + }; + WOLFSSL_SMALL_STACK_STATIC const byte ke_0[] = { + 0xdc, 0x38, 0x21, 0x92, 0xab, 0x65, 0x10, 0x8a, + 0x86, 0xb2, 0x59, 0xb6, 0x1b, 0x3a, 0xf4, 0x6f + }; + WOLFSSL_SMALL_STACK_STATIC const byte ka_0[] = { + 0xb8, 0x39, 0x37, 0xfb, 0x32, 0x17, 0x92, 0xee, + 0x87, 0xb7, 0x88, 0x19, 0x3b, 0xe5, 0xa4, 0xe3, + 0xbd, 0x32, 0x6e, 0xe4 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ks_0[] = { + 0xf1, 0xc0, 0x35, 0xc0, 0x0b, 0x5a, 0x54, 0xa6, + 0x16, 0x92, 0xc0, 0x16, 0x27, 0x6c + }; + WOLFSSL_SMALL_STACK_STATIC const byte index_c_0[] = { + 0x56, 0xf3, 0xf1, 0x97 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ke_c_0[] = { + 0xab, 0x5b, 0xe0, 0xb4, 0x56, 0x23, 0x5d, 0xcf, + 0x77, 0xd5, 0x08, 0x69, 0x29, 0xba, 0xfb, 0x38 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ka_c_0[] = { + 0xc5, 0x2f, 0xde, 0x0b, 0x80, 0xb0, 0xf0, 0xba, + 0xd8, 0xd1, 0x56, 0x45, 0xcb, 0x86, 0xe7, 0xc7, + 0xc3, 0xd8, 0x77, 0x0e + }; + WOLFSSL_SMALL_STACK_STATIC const byte ks_c_0[] = { + 0xde, 0xb5, 0xf8, 0x5f, 0x81, 0x33, 0x6a, 0x96, + 0x5e, 0xd3, 0x2b, 0xb7, 0xed, 0xe8 + }; + /* 192-bit key, kdrIdx = 0 */ + WOLFSSL_SMALL_STACK_STATIC const byte key_1[] = { + 0xbb, 0x04, 0x5b, 0x1f, 0x53, 0xc6, 0x93, 0x2c, + 0x2b, 0xa6, 0x88, 0xf5, 0xe3, 0xf2, 0x24, 0x70, + 0xe1, 0x7d, 0x7d, 0xec, 0x8a, 0x93, 0x4d, 0xf2 + }; + WOLFSSL_SMALL_STACK_STATIC const byte salt_1[] = { + 0xe7, 0x22, 0xab, 0x92, 0xfc, 0x7c, 0x89, 0xb6, + 0x53, 0x8a, 0xf9, 0x3c, 0xb9, 0x52 + }; + WOLFSSL_SMALL_STACK_STATIC const byte index_1[] = { + 0xd7, 0x87, 0x8f, 0x33, 0xb1, 0x76 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ke_1[] = { + 0x2c, 0xc8, 0x3e, 0x54, 0xb2, 0x33, 0x89, 0xb3, + 0x71, 0x65, 0x0f, 0x51, 0x61, 0x65, 0xe4, 0x93, + 0x07, 0x4e, 0xb3, 0x47, 0xba, 0x2d, 0x60, 0x60 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ka_1[] = { + 0x2e, 0x80, 0xe4, 0x82, 0x55, 0xa2, 0xbe, 0x6d, + 0xe0, 0x46, 0xcc, 0xc1, 0x75, 0x78, 0x6e, 0x78, + 0xd1, 0xd1, 0x47, 0x08 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ks_1[] = { + 0xe0, 0xc1, 0xe6, 0xaf, 0x1e, 0x8d, 0x8c, 0xfe, + 0xe5, 0x60, 0x70, 0xb5, 0xe6, 0xea + }; + WOLFSSL_SMALL_STACK_STATIC const byte index_c_1[] = { + 0x40, 0xbf, 0xd4, 0xa9 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ke_c_1[] = { + 0x94, 0x0f, 0x55, 0xce, 0x58, 0xd8, 0x16, 0x65, + 0xf0, 0xfa, 0x46, 0x40, 0x0c, 0xda, 0xb1, 0x11, + 0x9e, 0x69, 0xa0, 0x93, 0x4e, 0xd7, 0xf2, 0x84 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ka_c_1[] = { + 0xf5, 0x41, 0x6f, 0xc2, 0x65, 0xc5, 0xb3, 0xef, + 0xbb, 0x22, 0xc8, 0xfc, 0x6b, 0x00, 0x14, 0xb2, + 0xf3, 0x3b, 0x8e, 0x29 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ks_c_1[] = { + 0x35, 0xb7, 0x42, 0x43, 0xf0, 0x01, 0x01, 0xb4, + 0x68, 0xa1, 0x28, 0x80, 0x37, 0xf0 + }; + /* 256-bit key, kdrIdx = 1 */ + WOLFSSL_SMALL_STACK_STATIC const byte key_2[] = { + 0x10, 0x38, 0x0a, 0xcd, 0xd6, 0x47, 0xab, 0xee, + 0xc0, 0xd4, 0x44, 0xf4, 0x7e, 0x51, 0x36, 0x02, + 0x79, 0xa8, 0x94, 0x80, 0x35, 0x40, 0xed, 0x50, + 0xf4, 0x45, 0x30, 0x3d, 0xb5, 0xf0, 0x2b, 0xbb + }; + WOLFSSL_SMALL_STACK_STATIC const byte salt_2[] = { + 0xc7, 0x31, 0xf2, 0xc8, 0x40, 0x43, 0xb8, 0x74, + 0x8a, 0x61, 0x84, 0x7a, 0x25, 0x8a + }; + WOLFSSL_SMALL_STACK_STATIC const byte index_2[] = { + 0x82, 0xf1, 0x84, 0x8c, 0xac, 0x42 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ke_2[] = { + 0xb2, 0x26, 0x60, 0xaf, 0x08, 0x23, 0x14, 0x98, + 0x91, 0xde, 0x5d, 0x87, 0x95, 0x61, 0xca, 0x8f, + 0x0e, 0xce, 0xfb, 0x68, 0x4d, 0xd6, 0x28, 0xcb, + 0x28, 0xe2, 0x27, 0x20, 0x2d, 0xff, 0x64, 0xbb + }; + WOLFSSL_SMALL_STACK_STATIC const byte ka_2[] = { + 0x12, 0x6f, 0x52, 0xe8, 0x07, 0x7f, 0x07, 0x84, + 0xa0, 0x61, 0x96, 0xf8, 0xee, 0x4d, 0x05, 0x57, + 0x65, 0xc7, 0x50, 0xc1 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ks_2[] = { + 0x18, 0x5a, 0x59, 0xe5, 0x91, 0x4d, 0xc9, 0x6c, + 0xfa, 0x5b, 0x36, 0x06, 0x8c, 0x9a + }; + WOLFSSL_SMALL_STACK_STATIC const byte index_c_2[] = { + 0x31, 0x2d, 0x58, 0x15 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ke_c_2[] = { + 0x14, 0xf2, 0xc8, 0x25, 0x02, 0x79, 0x22, 0xa1, + 0x96, 0xb6, 0xf7, 0x07, 0x76, 0xa6, 0xa3, 0xc4, + 0x37, 0xdf, 0xa0, 0xf8, 0x78, 0x93, 0x2c, 0xfa, + 0xea, 0x35, 0xf0, 0xf3, 0x3f, 0x32, 0x6e, 0xfd + }; + WOLFSSL_SMALL_STACK_STATIC const byte ka_c_2[] = { + 0x6e, 0x3d, 0x4a, 0x99, 0xea, 0x2f, 0x9d, 0x13, + 0x4a, 0x1e, 0x71, 0x2e, 0x15, 0xc0, 0xca, 0xb6, + 0x35, 0x78, 0xdf, 0xa4 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ks_c_2[] = { + 0xae, 0xe4, 0xec, 0x18, 0x31, 0x70, 0x5d, 0x3f, + 0xdc, 0x97, 0x89, 0x88, 0xfd, 0xff + }; + /* 128-bit key, kdrIdx = 8 */ + WOLFSSL_SMALL_STACK_STATIC const byte key_3[] = { + 0x36, 0xb4, 0xde, 0xcb, 0x2e, 0x51, 0x23, 0x76, + 0xe0, 0x27, 0x7e, 0x3e, 0xc8, 0xf6, 0x54, 0x04 + }; + WOLFSSL_SMALL_STACK_STATIC const byte salt_3[] = { + 0x73, 0x26, 0xf4, 0x3f, 0xc0, 0xd9, 0xc6, 0xe3, + 0x2f, 0x92, 0x7d, 0x46, 0x12, 0x76 + }; + WOLFSSL_SMALL_STACK_STATIC const byte index_3[] = { + 0x44, 0x73, 0xb2, 0x2d, 0xb2, 0x60 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ke_3[] = { + 0x79, 0x91, 0x3d, 0x7b, 0x20, 0x5d, 0xea, 0xe2, + 0xeb, 0x46, 0x89, 0x68, 0x5a, 0x06, 0x73, 0x74 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ka_3[] = { + 0x2d, 0x2e, 0x97, 0x4e, 0x76, 0x8c, 0x62, 0xa6, + 0x57, 0x80, 0x13, 0x42, 0x0b, 0x51, 0xa7, 0x66, + 0xea, 0x31, 0x24, 0xe6 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ks_3[] = { + 0xcc, 0xd7, 0x31, 0xf6, 0x3b, 0xf3, 0x89, 0x8a, + 0x5b, 0x7b, 0xb5, 0x8b, 0x4c, 0x3f + }; + WOLFSSL_SMALL_STACK_STATIC const byte index_c_3[] = { + 0x4a, 0x7d, 0xaa, 0x85 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ke_c_3[] = { + 0x34, 0x99, 0x71, 0xfe, 0x12, 0x93, 0xae, 0x8c, + 0x4a, 0xe9, 0x84, 0xe4, 0x93, 0x53, 0x63, 0x88 + }; + WOLFSSL_SMALL_STACK_STATIC const byte ka_c_3[] = { + 0xa4, 0x53, 0x5e, 0x0a, 0x9c, 0xf2, 0xce, 0x13, + 0xef, 0x7a, 0x13, 0xee, 0x0a, 0xef, 0xba, 0x17, + 0x05, 0x18, 0xe3, 0xed + }; + WOLFSSL_SMALL_STACK_STATIC const byte ks_c_3[] = { + 0xe1, 0x29, 0x4f, 0x61, 0x30, 0x3c, 0x4d, 0x46, + 0x5f, 0x5c, 0x81, 0x3c, 0x38, 0xb6 + }; + #define SRTP_TV_CNT 4 + Srtp_Kdf_Tv tv[SRTP_TV_CNT] = { + { key_0, (word32)sizeof(key_0), salt_0, (word32)sizeof(salt_0), -1, + index_0, ke_0, ka_0, ks_0, index_c_0, ke_c_0, ka_c_0, ks_c_0, + 16, 20, 14 }, + { key_1, (word32)sizeof(key_1), salt_1, (word32)sizeof(salt_1), 0, + index_1, ke_1, ka_1, ks_1, index_c_1, ke_c_1, ka_c_1, ks_c_1, + 24, 20, 14 }, + { key_2, (word32)sizeof(key_2), salt_2, (word32)sizeof(salt_2), 1, + index_2, ke_2, ka_2, ks_2, index_c_2, ke_c_2, ka_c_2, ks_c_2, + 32, 20, 14 }, + { key_3, (word32)sizeof(key_3), salt_3, (word32)sizeof(salt_3), 8, + index_3, ke_3, ka_3, ks_3, index_c_3, ke_c_3, ka_c_3, ks_c_3, + 16, 20, 14 }, + }; + int i; + int idx; + unsigned char keyE[32]; + unsigned char keyA[20]; + unsigned char keyS[14]; + + for (i = 0; (ret == 0) && (i < SRTP_TV_CNT); i++) { + #ifndef WOLFSSL_AES_128 + if (tv[i].keySz == AES_128_KEY_SIZE) { + continue; + } + #endif + #ifndef WOLFSSL_AES_192 + if (tv[i].keySz == AES_192_KEY_SIZE) { + continue; + } + #endif + #ifndef WOLFSSL_AES_256 + if (tv[i].keySz == AES_256_KEY_SIZE) { + continue; + } + #endif + + ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0) + return WC_TEST_RET_ENC_NC; + if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0) + return WC_TEST_RET_ENC_NC; + if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0) + return WC_TEST_RET_ENC_NC; + + ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt, + tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_ENCRYPTION, + keyE, tv[i].keSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0) + return WC_TEST_RET_ENC_NC; + + ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt, + tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_MSG_AUTH, + keyA, tv[i].kaSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0) + return WC_TEST_RET_ENC_NC; + + ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt, + tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_SALT, keyS, + tv[i].ksSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0) + return WC_TEST_RET_ENC_NC; + + ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0) + return WC_TEST_RET_ENC_NC; + if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0) + return WC_TEST_RET_ENC_NC; + if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0) + return WC_TEST_RET_ENC_NC; + + ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt, + tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, + WC_SRTCP_LABEL_ENCRYPTION, keyE, tv[i].keSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0) + return WC_TEST_RET_ENC_NC; + + ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt, + tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_MSG_AUTH, + keyA, tv[i].kaSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0) + return WC_TEST_RET_ENC_NC; + + ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt, + tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_SALT, + keyS, tv[i].ksSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0) + return WC_TEST_RET_ENC_NC; + } + +#ifdef WOLFSSL_AES_128 + i = 0; +#elif defined(WOLFSSL_AES_192) + i = 1; +#else + i = 2; +#endif + ret = wc_SRTP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SRTCP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + + ret = wc_SRTP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SRTCP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + + ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15, + tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15, + tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + + ret = wc_SRTP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SRTCP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + + ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + + ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz, + 25, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz, + 25, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + + ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz, + -2, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz, + -2, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + + ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index, NULL, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index_c, NULL, tv[i].keSz, keyA, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + + ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, NULL, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, NULL, tv[i].kaSz, + keyS, tv[i].ksSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + + ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz, + NULL, tv[i].ksSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz, + tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz, + NULL, tv[i].ksSz); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + + idx = wc_SRTP_KDF_kdr_to_idx(0); + if (idx != -1) + return WC_TEST_RET_ENC_NC; + for (i = 0; i < 32; i++) { + word32 kdr = 1U << i; + idx = wc_SRTP_KDF_kdr_to_idx(kdr); + if (idx != i) + return WC_TEST_RET_ENC_NC; + } + + return 0; +} +#endif + #ifdef HAVE_ECC /* size to use for ECC key gen tests */ @@ -26370,7 +27380,8 @@ static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerif /* only perform the below tests if the key size matches */ if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize) - ERROR_OUT(ECC_CURVE_OID_E, done); + /* Not an error, just not a key size match */ + WARNING_OUT(ECC_CURVE_OID_E, done); #ifdef HAVE_ECC_DHE #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \ @@ -27286,8 +28297,9 @@ static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng) #else ecc_key key[1]; #endif -#if (defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \ - (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)) +#if !defined(NO_ECC_SECP) && \ + ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \ + (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT))) word32 idx = 0; #endif @@ -27338,8 +28350,9 @@ static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng) (void)rng; #endif /* !WC_NO_RNG */ -#if (defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \ - (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)) +#if !defined(NO_ECC_SECP) && \ + ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \ + (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT))) /* Use test ECC key - ensure real private "d" exists */ #ifdef USE_CERT_BUFFERS_256 ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key, @@ -29005,6 +30018,58 @@ static wc_test_ret_t ecc_test_nonblock(WC_RNG* rng) } #endif /* WC_ECC_NONBLOCK && WOLFSSL_HAVE_SP_ECC && WOLFSSL_PUBLIC_MP */ +#if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \ + (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \ + (HAVE_FIPS_VERSION > 2))) +static int ecc_test_raw_enc_dec(void) +{ + int ret; + unsigned char r[1]; + word32 rSz; + unsigned char s[1]; + word32 sSz; + unsigned char rZero[] = { 0, 0, 0, 0 }; + unsigned char sOne[] = { 0, 0, 1 }; + unsigned char sigRaw[32]; + word32 sigRawSz; + unsigned char expSig[] = { 0x30, 0x06, 0x02, 0x01, 0x00, 0x02, 0x01, 0x01 }; + + sigRawSz = sizeof(sigRaw); + ret = wc_ecc_rs_raw_to_sig(rZero, sizeof(rZero), sOne, sizeof(sOne), + sigRaw, &sigRawSz); + if (ret != 0) { + return WC_TEST_RET_ENC_EC(ret); + } + if (sigRawSz != sizeof(expSig)) { + return WC_TEST_RET_ENC_EC((int)sigRawSz); + } + if (XMEMCMP(sigRaw, expSig, sizeof(expSig)) != 0) { + return WC_TEST_RET_ENC_NC; + } + + rSz = sizeof(r); + sSz = sizeof(s); + ret = wc_ecc_sig_to_rs(sigRaw, sigRawSz, r, &rSz, s, &sSz); + if (ret != 0) { + return WC_TEST_RET_ENC_EC(ret); + } + if (rSz != 1) { + return WC_TEST_RET_ENC_EC((int)rSz); + } + if (sSz != 1) { + return WC_TEST_RET_ENC_EC((int)sSz); + } + if (r[0] != 0) { + return WC_TEST_RET_ENC_EC(r[0]); + } + if (s[0] != 1) { + return WC_TEST_RET_ENC_EC(s[0]); + } + + return ret; +} +#endif + WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void) { wc_test_ret_t ret; @@ -29129,6 +30194,16 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void) } #endif +#if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \ + (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \ + (HAVE_FIPS_VERSION > 2))) + ret = ecc_test_raw_enc_dec(); + if (ret != 0) { + printf("raw sig encode/decode\n"); + goto done; + } +#endif + #if defined(WOLFSSL_CUSTOM_CURVES) ret = ecc_test_custom_curves(&rng); if (ret != 0) { @@ -40148,7 +41223,7 @@ static int myDecryptionFunc(PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz, #ifdef WOLFSSL_AES_256 case AES256CBCb: if ((keySz != 32 ) || (ivSz != AES_BLOCK_SIZE)) - ERROR_OUT(BAD_FUNC_ARG, out); + WARNING_OUT(BAD_FUNC_ARG, out); break; #endif #ifdef WOLFSSL_AES_128 @@ -40846,7 +41921,7 @@ static wc_test_ret_t pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCer #endif #if !defined(NO_AES) && defined(WOLFSSL_AES_256) && defined(HAVE_ECC) && \ - defined(WOLFSSL_SHA512) + defined(WOLFSSL_SHA512) && defined(HAVE_AESGCM) WOLFSSL_SMALL_STACK_STATIC const byte optionalUkm[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07 }; @@ -40949,7 +42024,12 @@ static wc_test_ret_t pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCer NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, "pkcs7authEnvelopedDataAES256GCM_IANDS.der"); #endif - #endif /* NO_AES */ + #else /* NO_AES || !HAVE_AESGCM */ + (void)rsaCert; + (void)rsaCertSz; + (void)rsaPrivKey; + (void)rsaPrivKeySz; + #endif /* NO_AES || !HAVE_AESGCM */ #endif /* key agreement key encryption technique*/ @@ -45142,6 +46222,67 @@ static wc_test_ret_t mp_test_cmp(mp_int* a, mp_int* b) return WC_TEST_RET_ENC_NC; #endif +#if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \ + defined(WOLFSSL_ECC_GEN_REJECT_SAMPLING) + mp_zero(a); + mp_zero(b); + ret = mp_cmp_ct(a, b, 1); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp_ct(a, a, a->used); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_EC(ret); + +#ifdef WOLFSSL_SP_MATH_ALL + ret = mp_cmp_ct(a, NULL, a->used); + if (ret != MP_GT) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp_ct(NULL, a, a->used); + if (ret != MP_LT) + return WC_TEST_RET_ENC_EC(ret); +#endif + + mp_read_radix(a, "1", MP_RADIX_HEX); + ret = mp_cmp_ct(a, b, 1); + if (ret != MP_GT) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp_ct(b, a, 1); + if (ret != MP_LT) + return WC_TEST_RET_ENC_EC(ret); + + mp_read_radix(a, "0123456789abcdef0123456789abcdef", MP_RADIX_HEX); + ret = mp_cmp_ct(a, b, a->used); + if (ret != MP_GT) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp_ct(b, a, a->used); + if (ret != MP_LT) + return WC_TEST_RET_ENC_EC(ret); + + mp_read_radix(b, "1123456789abcdef0123456789abcdef", MP_RADIX_HEX); + ret = mp_cmp_ct(b, a, a->used); + if (ret != MP_GT) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp_ct(a, b, a->used); + if (ret != MP_LT) + return WC_TEST_RET_ENC_EC(ret); + + mp_read_radix(b, "0123456789abcdef0123456789abcdf0", MP_RADIX_HEX); + ret = mp_cmp_ct(b, a, a->used); + if (ret != MP_GT) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp_ct(a, b, a->used); + if (ret != MP_LT) + return WC_TEST_RET_ENC_EC(ret); + + mp_read_radix(b, "0123456789abcdf0", MP_RADIX_HEX); + ret = mp_cmp_ct(a, b, a->used); + if (ret != MP_GT) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp_ct(b, a, a->used); + if (ret != MP_LT) + return WC_TEST_RET_ENC_EC(ret); +#endif + return 0; } @@ -48466,7 +49607,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void) #endif #endif #ifndef NO_PWDBASED - #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) + #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC) if (ret == 0) ret = pbkdf2_test(); #endif diff --git a/recipes-wolfssl/wolfmqtt/wolfmqtt_1.17.0.bb b/recipes-wolfssl/wolfmqtt/wolfmqtt_1.17.0.bb deleted file mode 100644 index 11b4066..0000000 --- a/recipes-wolfssl/wolfmqtt/wolfmqtt_1.17.0.bb +++ /dev/null @@ -1,26 +0,0 @@ -SUMMARY = "wolfMQTT Client Library" -DESCRIPTION = "wolfMQTT is a client library implementation of the MQTT \ - protocol, written in ANSI C and targeted for embedded, RTOS, \ - and resource-constrained environments. It has been built from \ - the ground up to be multi-platform, space conscious, and \ - extensible. It includes support for the MQTT v5.0 protocol." -HOMEPAGE = "https://www.wolfssl.com/products/wolfmqtt" -BUGTRACKER = "https://github.com/wolfssl/wolfmqtt/issues" -SECTION = "libs" -LICENSE = "GPL-2.0-only" -LIC_FILES_CHKSUM = "file://LICENSE;md5=2c1c00f9d3ed9e24fa69b932b7e7aff2" - -DEPENDS += "wolfssl" - -SRC_URI = "git://github.com/wolfssl/wolfMQTT.git;nobranch=1;protocol=https;rev=51b84ead212dde4364352ce9acdf5211b39cbf89" - - -S = "${WORKDIR}/git" - -inherit autotools pkgconfig - -EXTRA_OECONF = "--with-libwolfssl-prefix=${COMPONENTS_DIR}/${PACKAGE_ARCH}/wolfssl/usr" - -do_configure:prepend() { - (cd ${S}; ./autogen.sh; cd -) -} diff --git a/recipes-wolfssl/wolfmqtt/wolfmqtt_1.15.1.bb b/recipes-wolfssl/wolfmqtt/wolfmqtt_1.18.0.bb similarity index 94% rename from recipes-wolfssl/wolfmqtt/wolfmqtt_1.15.1.bb rename to recipes-wolfssl/wolfmqtt/wolfmqtt_1.18.0.bb index 41782cc..abc8447 100644 --- a/recipes-wolfssl/wolfmqtt/wolfmqtt_1.15.1.bb +++ b/recipes-wolfssl/wolfmqtt/wolfmqtt_1.18.0.bb @@ -12,7 +12,7 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=2c1c00f9d3ed9e24fa69b932b7e7aff2" DEPENDS += "wolfssl" -SRC_URI = "git://github.com/wolfssl/wolfMQTT.git;nobranch=1;protocol=https;rev=6a1a7f85b4b42e8818a3b3d91760f55ed34d345f" +SRC_URI = "git://github.com/wolfssl/wolfMQTT.git;nobranch=1;protocol=https;rev=91b01f4be412fff883374168aa4da2bd00d2968c" S = "${WORKDIR}/git" diff --git a/recipes-wolfssl/wolfssl/wolfssl_5.6.4.bb b/recipes-wolfssl/wolfssl/wolfssl_5.6.4.bb deleted file mode 100644 index f31c2ed..0000000 --- a/recipes-wolfssl/wolfssl/wolfssl_5.6.4.bb +++ /dev/null @@ -1,28 +0,0 @@ -SUMMARY = "wolfSSL Lightweight Embedded SSL/TLS Library" -DESCRIPTION = "wolfSSL is a lightweight SSL/TLS library written in C and \ - optimized for embedded and RTOS environments. It can be up \ - to 20 times smaller than OpenSSL while still supporting \ - a full TLS client and server, up to TLS 1.3" -HOMEPAGE = "https://www.wolfssl.com/products/wolfssl" -BUGTRACKER = "https://github.com/wolfssl/wolfssl/issues" -SECTION = "libs" -LICENSE = "GPL-2.0-only" -LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263" -DEPENDS += "util-linux-native" - -PROVIDES += "cyassl" -RPROVIDES_${PN} = "cyassl" -PROVIDES += "wolfssl" -RPROVIDES_${PN} = "wolfssl" - -SRC_URI = "git://github.com/wolfssl/wolfssl.git;nobranch=1;protocol=https;rev=37884f864d6fd9b04f44677cb04da15d0c9d6526" - -S = "${WORKDIR}/git" - -inherit autotools pkgconfig - -do_configure:prepend() { - (cd ${S}; ./autogen.sh; cd -) -} - -BBCLASSEXTEND += "native nativesdk" diff --git a/recipes-wolfssl/wolfssl/wolfssl_5.6.3.bb b/recipes-wolfssl/wolfssl/wolfssl_5.6.6.bb similarity index 94% rename from recipes-wolfssl/wolfssl/wolfssl_5.6.3.bb rename to recipes-wolfssl/wolfssl/wolfssl_5.6.6.bb index a6e3236..5ea5b85 100644 --- a/recipes-wolfssl/wolfssl/wolfssl_5.6.3.bb +++ b/recipes-wolfssl/wolfssl/wolfssl_5.6.6.bb @@ -15,7 +15,7 @@ RPROVIDES_${PN} = "cyassl" PROVIDES += "wolfssl" RPROVIDES_${PN} = "wolfssl" -SRC_URI = "git://github.com/wolfssl/wolfssl.git;nobranch=1;protocol=https;rev=3b3c175af0e993ffaae251871421e206cc41963f" +SRC_URI = "git://github.com/wolfssl/wolfssl.git;nobranch=1;protocol=https;rev=66596ad9e1d7efa8479656872cf09c9c1870a02e" S = "${WORKDIR}/git" diff --git a/recipes-wolfssl/wolftpm/wolftpm_3.0.0.bb b/recipes-wolfssl/wolftpm/wolftpm_3.1.0.bb similarity index 94% rename from recipes-wolfssl/wolftpm/wolftpm_3.0.0.bb rename to recipes-wolfssl/wolftpm/wolftpm_3.1.0.bb index 8488019..12a6d18 100644 --- a/recipes-wolfssl/wolftpm/wolftpm_3.0.0.bb +++ b/recipes-wolfssl/wolftpm/wolftpm_3.1.0.bb @@ -12,7 +12,7 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=b234ee4d69f5fce4486a80fdaf4a4263" DEPENDS += "wolfssl" -SRC_URI = "git://github.com/wolfssl/wolfTPM.git;nobranch=1;protocol=https;rev=5b288d480d7bc5598d47dc78832907ff377b38d8" +SRC_URI = "git://github.com/wolfssl/wolfTPM.git;nobranch=1;protocol=https;rev=e54734a3ab2507fbba378567d16aa3e27c54655b" S = "${WORKDIR}/git" diff --git a/update-version.sh b/update-version.sh index 9b5ef32..3c61113 100755 --- a/update-version.sh +++ b/update-version.sh @@ -39,9 +39,9 @@ update() { REV=`git rev-list -n 1 $TAG` cd .. rm -rf $1 - git mv ./recipes-wolfssl/$1/$1_$CURRENT.bb ./recipes-wolfssl/$1/$1_$NEW.bb &> /dev/null sed -i "s/rev=.*/rev=$REV\"/" ./recipes-wolfssl/$1/$1_$NEW.bb + git add ./recipes-wolfssl/$1/$1_$NEW.bb else printf "version $CURRENT is the latest\n" fi @@ -61,7 +61,9 @@ if [ "$CURRENT" != "$NEW" ]; then unzip wolfssl-$NEW.zip &> /dev/null mv wolfSSL-wolfssl-* wolfssl-$NEW &> /dev/null cp ./wolfssl-$NEW/wolfcrypt/benchmark/benchmark.{c,h} recipes-examples/wolfcrypt/wolfcryptbenchmark/ &> /dev/null + git add recipes-examples/wolfcrypt/wolfcryptbenchmark/* &> /dev/null cp ./wolfssl-$NEW/wolfcrypt/test/test.{c,h} recipes-examples/wolfcrypt/wolfcrypttest/ &> /dev/null + git add recipes-examples/wolfcrypt/wolfcrypttest/* &> /dev/null rm -rf ./wolfssl-$NEW* &> /dev/null printf "done\n" set +e