cleanups: line length, WOLFSSL_SMALL_STACK_STATIC, and SAVE_VECTOR_REGISTERS() failure trap in benchmark.c, proper path to benchmark.c in linuxkm/module_hooks.c, and proper casting in aes.c. also harmonized semantics and prototype of bench_ripemd().

This commit is contained in:
Daniel Pouzzner
2023-05-17 13:00:46 -05:00
parent 37b716192b
commit fffff657de
4 changed files with 138 additions and 80 deletions

View File

@ -119,7 +119,7 @@ static int updateFipsHash(void);
#define NO_MAIN_FUNCTION #define NO_MAIN_FUNCTION
#define current_time benchmark_current_time #define current_time benchmark_current_time
#define WOLFSSL_NO_FLOAT_FMT #define WOLFSSL_NO_FLOAT_FMT
#include "/home/douzzer/com/wolfssl/src/wolfssl/wolfcrypt/benchmark/benchmark.c" #include "wolfcrypt/benchmark/benchmark.c"
#endif /* WOLFSSL_LINUXKM_BENCHMARKS */ #endif /* WOLFSSL_LINUXKM_BENCHMARKS */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)

View File

@ -69,14 +69,21 @@
#define FLT_FMT "%0ld,%09lu" #define FLT_FMT "%0ld,%09lu"
#define FLT_FMT_PREC "%0ld.%0*lu" #define FLT_FMT_PREC "%0ld.%0*lu"
#define FLT_FMT_PREC2 FLT_FMT_PREC #define FLT_FMT_PREC2 FLT_FMT_PREC
#define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : (unsigned long)(((x) - (double)(long)(x)) * 1000000000.0) #define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? \
static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, 10000000.0, 100000000.0, 1000000000.0 }; (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : \
(unsigned long)(((x) - (double)(long)(x)) * 1000000000.0)
static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, \
10000.0, 100000.0, 1000000.0, \
10000000.0, 100000000.0, \
1000000000.0 };
#define FLT_FMT_PREC_ARGS(p, x) \ #define FLT_FMT_PREC_ARGS(p, x) \
(long)(x), \ (long)(x), \
p, \ p, \
(x) >= 0.0 ? \ (x) >= 0.0 ? \
(unsigned long int)((((x) - (double)(long)(x)) * pow_10_array[(p)+1]) + 0.5) : \ (unsigned long int)((((x) - (double)(long)(x)) * \
(unsigned long int)((((-(x)) - (double)((long)-(x))) * pow_10_array[(p)+1]) + 0.5) pow_10_array[(p)+1]) + 0.5) : \
(unsigned long int)((((-(x)) - (double)((long)-(x))) * \
pow_10_array[(p)+1]) + 0.5)
#define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x) #define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x)
#else #else
#define FLT_FMT "%f" #define FLT_FMT "%f"
@ -943,13 +950,16 @@ static const char* bench_desc_words[][15] = {
#define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles(); #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles();
#define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles; #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles;
/* s == size in bytes that 1 count represents, normally BENCH_SIZE */ /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
#define SHOW_INTEL_CYCLES(b, n, s) \ #define SHOW_INTEL_CYCLES(b, n, s) \
(void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), " %s = " FLT_FMT_PREC2 "\n", \ (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
bench_result_words1[lng_index][2], \ " %s = " FLT_FMT_PREC2 "\n", \
FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : (double)total_cycles / ((word64)count*(s)))) bench_result_words1[lng_index][2], \
#define SHOW_INTEL_CYCLES_CSV(b, n, s) \ 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", \ (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC ",\n", \
FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : (double)total_cycles / ((word64)count*(s)))) FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
(double)total_cycles / ((word64)count*(s))))
#elif defined(LINUX_CYCLE_COUNT) #elif defined(LINUX_CYCLE_COUNT)
#include <linux/perf_event.h> #include <linux/perf_event.h>
#include <sys/syscall.h> #include <sys/syscall.h>
@ -960,25 +970,26 @@ static const char* bench_desc_words[][15] = {
static THREAD_LS_T int cycles = -1; static THREAD_LS_T int cycles = -1;
static THREAD_LS_T struct perf_event_attr atr; static THREAD_LS_T struct perf_event_attr atr;
#define INIT_CYCLE_COUNTER do { \ #define INIT_CYCLE_COUNTER do { \
atr.type = PERF_TYPE_HARDWARE; \ atr.type = PERF_TYPE_HARDWARE; \
atr.config = PERF_COUNT_HW_CPU_CYCLES; \ atr.config = PERF_COUNT_HW_CPU_CYCLES; \
cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \ cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
} while (0); } while (0);
#define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles)); #define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
#define END_INTEL_CYCLES do { \ #define END_INTEL_CYCLES do { \
read(cycles, &total_cycles, sizeof(total_cycles)); \ read(cycles, &total_cycles, sizeof(total_cycles)); \
total_cycles = total_cycles - begin_cycles; \ total_cycles = total_cycles - begin_cycles; \
} while (0); } while (0);
/* s == size in bytes that 1 count represents, normally BENCH_SIZE */ /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
#define SHOW_INTEL_CYCLES(b, n, s) \ #define SHOW_INTEL_CYCLES(b, n, s) \
(void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), " %s = " FLT_FMT_PREC2 "\n", \ (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
bench_result_words1[lng_index][2], \ " %s = " FLT_FMT_PREC2 "\n", \
bench_result_words1[lng_index][2], \
FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s))) FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
#define SHOW_INTEL_CYCLES_CSV(b, n, s) \ #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
(void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \ (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s))) FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
#elif defined(SYNERGY_CYCLE_COUNT) #elif defined(SYNERGY_CYCLE_COUNT)
@ -991,12 +1002,13 @@ static const char* bench_desc_words[][15] = {
#define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles; #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
/* s == size in bytes that 1 count represents, normally BENCH_SIZE */ /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
#define SHOW_INTEL_CYCLES(b, n, s) \ #define SHOW_INTEL_CYCLES(b, n, s) \
(void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), " %s = " FLT_FMT_PREC2 "\n", \ (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
bench_result_words1[lng_index][2], \ " %s = " FLT_FMT_PREC2 "\n", \
bench_result_words1[lng_index][2], \
FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s))) FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
#define SHOW_INTEL_CYCLES_CSV(b, n, s) \ #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
(void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \ (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s))) FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
#elif defined(WOLFSSL_ESPIDF) #elif defined(WOLFSSL_ESPIDF)
static THREAD_LS_T word64 begin_cycles; static THREAD_LS_T word64 begin_cycles;
@ -1027,9 +1039,10 @@ static const char* bench_desc_words[][15] = {
total_cycles = (get_xtensa_cycles() - begin_cycles); total_cycles = (get_xtensa_cycles() - begin_cycles);
#define SHOW_ESP_CYCLES(b, n, s) \ #define SHOW_ESP_CYCLES(b, n, s) \
(void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), " %s = " FLT_FMT_PREC2 "\n", \ (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
bench_result_words1[lng_index][2], \ " %s = " FLT_FMT_PREC2 "\n", \
FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \ 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) \ #define SHOW_ESP_CYCLES_CSV(b, n, s) \
@ -1613,13 +1626,15 @@ typedef enum bench_stat_type {
for (bstat = bench_stats_head; bstat != NULL; ) { for (bstat = bench_stats_head; bstat != NULL; ) {
if (bstat->type == BENCH_STAT_SYM) { if (bstat->type == BENCH_STAT_SYM) {
printf("%-16s%s " FLT_FMT_PREC2 " %s/s\n", bstat->desc, printf("%-16s%s " FLT_FMT_PREC2 " %s/s\n", bstat->desc,
BENCH_DEVID_GET_NAME(bstat->useDeviceID), FLT_FMT_PREC2_ARGS(8, 3, bstat->perfsec), BENCH_DEVID_GET_NAME(bstat->useDeviceID),
FLT_FMT_PREC2_ARGS(8, 3, bstat->perfsec),
base2 ? "MB" : "mB"); base2 ? "MB" : "mB");
} }
else { else {
printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/sec\n", printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/sec\n",
bstat->algo, bstat->strength, bstat->desc, bstat->algo, bstat->strength, bstat->desc,
BENCH_DEVID_GET_NAME(bstat->useDeviceID), FLT_FMT_PREC_ARGS(3, bstat->perfsec)); BENCH_DEVID_GET_NAME(bstat->useDeviceID),
FLT_FMT_PREC_ARGS(3, bstat->perfsec));
} }
bstat = bstat->next; bstat = bstat->next;
@ -1673,12 +1688,14 @@ typedef enum bench_stat_type {
for (i=0; i<gStatsCount; i++) { for (i=0; i<gStatsCount; i++) {
bench_stats_t* bstat = &gStats[i]; bench_stats_t* bstat = &gStats[i];
if (bstat->type == BENCH_STAT_SYM) { if (bstat->type == BENCH_STAT_SYM) {
printf("%-16s " FLT_FMT_PREC2 " %s/s\n", bstat->desc, FLT_FMT_PREC2_ARGS(8, 3, bstat->perfsec), printf("%-16s " FLT_FMT_PREC2 " %s/s\n", bstat->desc,
FLT_FMT_PREC2_ARGS(8, 3, bstat->perfsec),
base2 ? "MB" : "mB"); base2 ? "MB" : "mB");
} }
else if (bstat->type == BENCH_STAT_ASYM) { else if (bstat->type == BENCH_STAT_ASYM) {
printf("%-5s %4d %-9s " FLT_FMT_PREC " ops/sec\n", printf("%-5s %4d %-9s " FLT_FMT_PREC " ops/sec\n",
bstat->algo, bstat->strength, bstat->desc, FLT_FMT_PREC_ARGS(3, bstat->perfsec)); bstat->algo, bstat->strength, bstat->desc,
FLT_FMT_PREC_ARGS(3, bstat->perfsec));
} }
} }
} }
@ -1695,8 +1712,6 @@ static WC_INLINE void bench_stats_init(void)
static WC_INLINE void bench_stats_start(int* count, double* start) static WC_INLINE void bench_stats_start(int* count, double* start)
{ {
SAVE_VECTOR_REGISTERS(pr_err("SAVE_VECTOR_REGISTERS failed for benchmark run."););
*count = 0; *count = 0;
*start = current_time(1); *start = current_time(1);
@ -1710,6 +1725,14 @@ static WC_INLINE void bench_stats_start(int* count, double* start)
#endif #endif
} }
#ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
#define bench_stats_start(count, start) do { \
SAVE_VECTOR_REGISTERS(pr_err("SAVE_VECTOR_REGISTERS failed for benchmark run."); \
return; ); \
bench_stats_start(count, start); \
} while (0)
#endif
static WC_INLINE int bench_stats_check(double start) static WC_INLINE int bench_stats_check(double start)
{ {
return ((current_time(0) - start) < BENCH_MIN_RUNTIME_SEC); return ((current_time(0) - start) < BENCH_MIN_RUNTIME_SEC);
@ -1911,13 +1934,17 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID,
#else #else
#ifdef HAVE_GET_CYCLES #ifdef HAVE_GET_CYCLES
(void)XSNPRINTF(msg, sizeof(msg), "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc, (void)XSNPRINTF(msg, sizeof(msg),
"sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
BENCH_DEVID_GET_NAME(useDeviceID), BENCH_DEVID_GET_NAME(useDeviceID),
bytes_processed, FLT_FMT_ARGS(total), FLT_FMT_ARGS(persec), total_cycles); bytes_processed, FLT_FMT_ARGS(total),
FLT_FMT_ARGS(persec), total_cycles);
#else #else
(void)XSNPRINTF(msg, sizeof(msg), "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc, (void)XSNPRINTF(msg, sizeof(msg),
"sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
BENCH_DEVID_GET_NAME(useDeviceID), BENCH_DEVID_GET_NAME(useDeviceID),
bytes_processed, FLT_FMT_ARGS(total), FLT_FMT_ARGS(persec)); bytes_processed, FLT_FMT_ARGS(total),
FLT_FMT_ARGS(persec));
#endif #endif
#endif #endif
#elif defined(BENCH_DEVID) #elif defined(BENCH_DEVID)
@ -1940,23 +1967,30 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID,
#ifdef GENERATE_MACHINE_PARSEABLE_REPORT #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
#ifdef HAVE_GET_CYCLES #ifdef HAVE_GET_CYCLES
(void)XSNPRINTF(msg, sizeof(msg), (void)XSNPRINTF(msg, sizeof(msg),
"%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, " FLT_FMT_PREC2 " %s/s" "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
", %lu cycles,", FLT_FMT_PREC2 " %s/s, %lu cycles,",
desc, BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType, desc, BENCH_DEVID_GET_NAME(useDeviceID),
word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], FLT_FMT_PREC2_ARGS(8, 3, persec), blockType, 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); (unsigned long) total_cycles);
#else #else
(void)XSNPRINTF(msg, sizeof(msg), (void)XSNPRINTF(msg, sizeof(msg),
"%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, " FLT_FMT_PREC2 " %s/s" "%-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, desc, BENCH_DEVID_GET_NAME(useDeviceID),
word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], FLT_FMT_PREC2_ARGS(8, 3, persec), blockType); 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 */ #endif /* HAVE_GET_CYCLES */
#else #else
(void)XSNPRINTF(msg, sizeof(msg), (void)XSNPRINTF(msg, sizeof(msg),
"%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, " FLT_FMT_PREC2 " %s/s", "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
desc, BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType, FLT_FMT_PREC2 " %s/s",
word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], FLT_FMT_PREC2_ARGS(8, 3, persec), blockType); 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 #endif
#ifdef WOLFSSL_ESPIDF #ifdef WOLFSSL_ESPIDF
@ -2064,19 +2098,23 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength,
#ifdef GENERATE_MACHINE_PARSEABLE_REPORT #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
#ifdef HAVE_GET_CYCLES #ifdef HAVE_GET_CYCLES
(void)XSNPRINTF(msg, sizeof(msg), (void)XSNPRINTF(msg, sizeof(msg),
"asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d," FLT_FMT ",%lu," FLT_FMT_PREC "\n", "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d," FLT_FMT
algo, strength, desc, desc_extra, FLT_FMT_PREC_ARGS(3, milliEach), FLT_FMT_PREC_ARGS(3, opsSec), ",%lu," FLT_FMT_PREC "\n",
algo, strength, desc, desc_extra, FLT_FMT_PREC_ARGS(3, milliEach),
FLT_FMT_PREC_ARGS(3, opsSec),
count, FLT_FMT_ARGS(total), (unsigned long) total_cycles, count, FLT_FMT_ARGS(total), (unsigned long) total_cycles,
FLT_FMT_PREC_ARGS(6, (double)total_cycles / (double)count)); FLT_FMT_PREC_ARGS(6, (double)total_cycles / (double)count));
#else #else
(void)XSNPRINTF(msg, sizeof(msg), (void)XSNPRINTF(msg, sizeof(msg),
"asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d," FLT_FMT "\n", "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d," FLT_FMT "\n",
algo, strength, desc, desc_extra, FLT_FMT_PREC_ARGS(3, milliEach), FLT_FMT_PREC_ARGS(3, opsSec), algo, strength, desc, desc_extra, FLT_FMT_PREC_ARGS(3, milliEach),
FLT_FMT_PREC_ARGS(3, opsSec),
count, FLT_FMT_ARGS(total)); count, FLT_FMT_ARGS(total));
#endif #endif
#else #else
(void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",\n", algo, (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",\n", algo,
strength, desc, desc_extra, FLT_FMT_PREC_ARGS(3, milliEach), FLT_FMT_PREC_ARGS(3, opsSec)); strength, desc, desc_extra, FLT_FMT_PREC_ARGS(3, milliEach),
FLT_FMT_PREC_ARGS(3, opsSec));
#endif #endif
} /* if (csv_format == 1) */ } /* if (csv_format == 1) */
@ -2087,14 +2125,16 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength,
"%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " FLT_FMT_PREC2 " ms," "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " FLT_FMT_PREC2 " ms,"
" " FLT_FMT_PREC " %s, %lu cycles\n", algo, strength, desc, " " FLT_FMT_PREC " %s, %lu cycles\n", algo, strength, desc,
desc_extra, BENCH_DEVID_GET_NAME(useDeviceID), 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), count, word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
FLT_FMT_PREC2_ARGS(5, 3, milliEach),
FLT_FMT_PREC_ARGS(3, opsSec), word[3], (unsigned long) total_cycles); FLT_FMT_PREC_ARGS(3, opsSec), word[3], (unsigned long) total_cycles);
#else #else
(void)XSNPRINTF(msg, sizeof(msg), (void)XSNPRINTF(msg, sizeof(msg),
"%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " FLT_FMT_PREC2 " ms," "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " FLT_FMT_PREC2 " ms,"
" " FLT_FMT_PREC " %s\n", algo, strength, desc, " " FLT_FMT_PREC " %s\n", algo, strength, desc,
desc_extra, BENCH_DEVID_GET_NAME(useDeviceID), 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), 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(3, opsSec), word[3]);
#endif /* HAVE_GET_CYCLES */ #endif /* HAVE_GET_CYCLES */
#else #else
@ -2102,7 +2142,8 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength,
"%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " FLT_FMT_PREC2 " ms," "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s " FLT_FMT_PREC2 " ms,"
" " FLT_FMT_PREC " %s\n", algo, strength, desc, desc_extra, " " FLT_FMT_PREC " %s\n", algo, strength, desc, desc_extra,
BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2], FLT_FMT_PREC2_ARGS(5, 3, milliEach), FLT_FMT_PREC_ARGS(3, opsSec), word[3]); FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
FLT_FMT_PREC2_ARGS(5, 3, milliEach), FLT_FMT_PREC_ARGS(3, opsSec), word[3]);
#endif #endif
} }
printf("%s", msg); printf("%s", msg);
@ -5717,7 +5758,7 @@ exit:
#ifdef WOLFSSL_RIPEMD #ifdef WOLFSSL_RIPEMD
int bench_ripemd(void) void bench_ripemd(void)
{ {
RipeMd hash; RipeMd hash;
byte digest[RIPEMD_DIGEST_SIZE]; byte digest[RIPEMD_DIGEST_SIZE];
@ -5727,7 +5768,8 @@ int bench_ripemd(void)
if (digest_stream) { if (digest_stream) {
ret = wc_InitRipeMd(&hash); ret = wc_InitRipeMd(&hash);
if (ret != 0) { if (ret != 0) {
return ret; printf("wc_InitRipeMd failed, retval %d\n", ret);
return;
} }
bench_stats_start(&count, &start); bench_stats_start(&count, &start);
@ -5735,12 +5777,14 @@ int bench_ripemd(void)
for (i = 0; i < numBlocks; i++) { for (i = 0; i < numBlocks; i++) {
ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size); ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
if (ret != 0) { if (ret != 0) {
return ret; printf("wc_RipeMdUpdate failed, retval %d\n", ret);
return;
} }
} }
ret = wc_RipeMdFinal(&hash, digest); ret = wc_RipeMdFinal(&hash, digest);
if (ret != 0) { if (ret != 0) {
return ret; printf("wc_RipeMdFinal failed, retval %d\n", ret);
return;
} }
count += i; count += i;
@ -5752,15 +5796,18 @@ int bench_ripemd(void)
for (i = 0; i < numBlocks; i++) { for (i = 0; i < numBlocks; i++) {
ret = wc_InitRipeMd(&hash); ret = wc_InitRipeMd(&hash);
if (ret != 0) { if (ret != 0) {
return ret; printf("wc_InitRipeMd failed, retval %d\n", ret);
return;
} }
ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size); ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
if (ret != 0) { if (ret != 0) {
return ret; printf("wc_RipeMdUpdate failed, retval %d\n", ret);
return;
} }
ret = wc_RipeMdFinal(&hash, digest); ret = wc_RipeMdFinal(&hash, digest);
if (ret != 0) { if (ret != 0) {
return ret; printf("wc_RipeMdFinal failed, retval %d\n", ret);
return;
} }
} }
count += i; count += i;
@ -5768,7 +5815,7 @@ int bench_ripemd(void)
} }
bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret); bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
return 0; return;
} }
#endif #endif
@ -6091,7 +6138,8 @@ exit:
void bench_hmac_md5(int useDeviceID) void bench_hmac_md5(int useDeviceID)
{ {
static const byte key[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key), bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
@ -6104,7 +6152,8 @@ void bench_hmac_md5(int useDeviceID)
void bench_hmac_sha(int useDeviceID) void bench_hmac_sha(int useDeviceID)
{ {
static const byte key[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b }; 0x0b, 0x0b, 0x0b, 0x0b };
@ -6118,7 +6167,8 @@ void bench_hmac_sha(int useDeviceID)
void bench_hmac_sha224(int useDeviceID) void bench_hmac_sha224(int useDeviceID)
{ {
static const byte key[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b }; 0x0b, 0x0b, 0x0b, 0x0b };
@ -6134,7 +6184,8 @@ void bench_hmac_sha224(int useDeviceID)
void bench_hmac_sha256(int useDeviceID) void bench_hmac_sha256(int useDeviceID)
{ {
static const byte key[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
@ -6149,7 +6200,8 @@ void bench_hmac_sha256(int useDeviceID)
void bench_hmac_sha384(int useDeviceID) void bench_hmac_sha384(int useDeviceID)
{ {
static const byte key[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
@ -6166,7 +6218,8 @@ void bench_hmac_sha384(int useDeviceID)
void bench_hmac_sha512(int useDeviceID) void bench_hmac_sha512(int useDeviceID)
{ {
static const byte key[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
@ -6187,7 +6240,8 @@ void bench_pbkdf2(void)
double start; double start;
int ret = 0, count = 0; int ret = 0, count = 0;
const char* passwd32 = "passwordpasswordpasswordpassword"; const char* passwd32 = "passwordpasswordpasswordpassword";
static const byte salt32[] = { 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06, WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06, 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06, 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 }; 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
@ -6913,7 +6967,8 @@ void bench_dh(int useDeviceID)
BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT); BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
#ifdef WOLFSSL_SMALL_STACK #ifdef WOLFSSL_SMALL_STACK
dhKey = (DhKey *)XMALLOC(sizeof(DhKey) * BENCH_MAX_PENDING, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); dhKey = (DhKey *)XMALLOC(sizeof(DhKey) * BENCH_MAX_PENDING, HEAP_HINT,
DYNAMIC_TYPE_TMP_BUFFER);
if (! dhKey) { if (! dhKey) {
ret = MEMORY_E; ret = MEMORY_E;
goto exit; goto exit;
@ -7630,7 +7685,9 @@ exit:
void bench_eccEncrypt(int curveId) void bench_eccEncrypt(int curveId)
{ {
#define BENCH_ECCENCRYPT_MSG_SIZE 48 #define BENCH_ECCENCRYPT_MSG_SIZE 48
#define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + WC_SHA256_DIGEST_SIZE + (MAX_ECC_BITS+3)/4 + 2) #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
WC_SHA256_DIGEST_SIZE + \
(MAX_ECC_BITS+3)/4 + 2)
word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE; word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
#ifdef WOLFSSL_SMALL_STACK #ifdef WOLFSSL_SMALL_STACK
ecc_key *userA = NULL, *userB = NULL; ecc_key *userA = NULL, *userB = NULL;
@ -9117,7 +9174,8 @@ void bench_sphincsKeySign(byte level, byte optim)
if (stime_utime_ratio > .1) if (stime_utime_ratio > .1)
printf("%swarning, " printf("%swarning, "
"excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n", "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
err_prefix, desc, desc_extra, FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0)); err_prefix, desc, desc_extra,
FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
} }
#elif defined(WOLFSSL_LINUXKM) #elif defined(WOLFSSL_LINUXKM)

View File

@ -81,7 +81,7 @@ void bench_sha3_384(int useDeviceID);
void bench_sha3_512(int useDeviceID); void bench_sha3_512(int useDeviceID);
void bench_shake128(int useDeviceID); void bench_shake128(int useDeviceID);
void bench_shake256(int useDeviceID); void bench_shake256(int useDeviceID);
int bench_ripemd(void); void bench_ripemd(void);
void bench_cmac(int useDeviceID); void bench_cmac(int useDeviceID);
void bench_scrypt(void); void bench_scrypt(void);
void bench_hmac_md5(int useDeviceID); void bench_hmac_md5(int useDeviceID);

View File

@ -3131,7 +3131,7 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
if (haveAESNI) { if (haveAESNI) {
#ifdef WOLFSSL_LINUXKM #ifdef WOLFSSL_LINUXKM
/* runtime alignment check */ /* runtime alignment check */
if ((unsigned long)&aes->key & 0xf) { if ((wc_ptr_t)&aes->key & (wc_ptr_t)0xf) {
return BAD_ALIGN_E; return BAD_ALIGN_E;
} }
#endif #endif