Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 41 additions & 25 deletions wolfcrypt/benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -2902,20 +2902,14 @@ static WC_INLINE void bench_stats_start(int* count, double* start)
}

#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
/* we're using floating point to figure the statistics, so we need to
* FPU save+lock even without SIMD. */
#define bench_stats_start(count, start) do { \
SAVE_VECTOR_REGISTERS(WOLFSSL_DEBUG_PRINTF( \
"ERROR: SAVE_VECTOR_REGISTERS failed for benchmark run."); \
return; ); \
bench_stats_start(count, start); \
} while (0)
#elif defined(WOLFSSL_LINUXKM)
/* we're using floating point to figure the statistics, so we need to
* FPU save+lock even without SIMD.
*/
#define bench_stats_start(count, start) do { \
kernel_fpu_begin(); \
bench_stats_start(count, start); \
} while (0)
#endif

static WC_INLINE int bench_stats_check(double start)
Expand Down Expand Up @@ -3381,8 +3375,6 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID,

#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
RESTORE_VECTOR_REGISTERS();
#elif defined(WOLFSSL_LINUXKM)
kernel_fpu_end();
#endif

bench_stats_prepare();
Expand Down Expand Up @@ -3482,8 +3474,6 @@ static void bench_stats_ops_finish(const char* algo, int strength,

#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
RESTORE_VECTOR_REGISTERS();
#elif defined(WOLFSSL_LINUXKM)
kernel_fpu_end();
#endif

bench_stats_prepare();
Expand Down Expand Up @@ -3891,8 +3881,6 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength,

#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
RESTORE_VECTOR_REGISTERS();
#elif defined(WOLFSSL_LINUXKM)
kernel_fpu_end();
#endif

bench_stats_prepare();
Expand Down Expand Up @@ -12504,7 +12492,6 @@ void bench_dh(int useDeviceID)
}
}


/* Key Gen */
bench_stats_start(&count, &start);
PRIVATE_KEY_UNLOCK();
Expand All @@ -12524,6 +12511,8 @@ void bench_dh(int useDeviceID)
if (!bench_async_handle(&ret,
BENCH_ASYNC_GET_DEV(dhKey[i]),
0, &times, &pending)) {
/* on err we must fall through to next finish
* for restore vector register. */
goto exit_dh_gen;
}
}
Expand All @@ -12537,28 +12526,42 @@ void bench_dh(int useDeviceID)
#endif
);

PRIVATE_KEY_LOCK();
exit_dh_gen:
PRIVATE_KEY_LOCK();
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;
}

#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
SAVE_VECTOR_REGISTERS(WOLFSSL_DEBUG_PRINTF("ERROR: SAVE_VECTOR_REGISTERS "
"failed for benchmark run."); goto exit; );
Comment thread
philljj marked this conversation as resolved.
Resolved
#endif

#ifdef MULTI_VALUE_STATISTICS
bench_multi_value_stats(max, min, sum, squareSum, runs);
#endif

RESET_MULTI_VALUE_STATS_VARS();

/* Generate key to use as other public */
PRIVATE_KEY_UNLOCK();
ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
priv2, &privSz2, pub2, &pubSz2);

PRIVATE_KEY_LOCK();
#ifdef WOLFSSL_ASYNC_CRYPT
ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
#endif
#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
RESTORE_VECTOR_REGISTERS();
#endif

if (ret < 0) {
goto exit;
}

/* Key Agree */
bench_stats_start(&count, &start);
Expand All @@ -12575,7 +12578,9 @@ void bench_dh(int useDeviceID)
privSz[i], pub2, pubSz2);
if (!bench_async_handle(&ret,
BENCH_ASYNC_GET_DEV(dhKey[i]), 0, &times, &pending)) {
goto exit;
/* on err we must fall through to next finish
* for restore vector register. */
goto exit_agree;
}
}
} /* for i */
Expand All @@ -12588,14 +12593,14 @@ void bench_dh(int useDeviceID)
#endif
);

exit_agree:
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
exit:

/* cleanup */
if (WC_ARRAY_OK(dhKey)) {
Expand Down Expand Up @@ -15691,8 +15696,10 @@ static void bench_eccEncryptEx(int useDeviceID, int curveId, int ctxMode)
ret = wc_ecc_encrypt(userA, userB, msg,
BENCH_ECCENCRYPT_MSG_SIZE, out, &outSz, cliCtx);
if (ret != 0) {
/* on err we must fall through to next finish
* for restore vector register. */
printf("wc_ecc_encrypt failed! %d\n", ret);
goto exit_ecies;
goto ecc_encrypt_exit;
}
RECORD_MULTI_VALUE_STATS();
}
Expand All @@ -15702,8 +15709,15 @@ static void bench_eccEncryptEx(int useDeviceID, int curveId, int ctxMode)
|| runs < minimum_runs
#endif
);
ecc_encrypt_exit:
bench_stats_asym_finish(name, keySize * 8, encDesc, useDeviceID,
count, start, ret);

if (ret != 0) {
wc_ecc_ctx_free(cliCtx);
wc_ecc_ctx_free(srvCtx);
goto exit;
}
#ifdef MULTI_VALUE_STATISTICS
bench_multi_value_stats(max, min, sum, squareSum, runs);
#endif
Expand All @@ -15721,8 +15735,10 @@ static void bench_eccEncryptEx(int useDeviceID, int curveId, int ctxMode)
ret = wc_ecc_decrypt(userB, decPubKey, out, outSz,
bench_plain, &bench_plainSz, srvCtx);
if (ret != 0) {
/* on err we must fall through to next finish
* for restore vector register. */
printf("wc_ecc_decrypt failed! %d\n", ret);
goto exit_ecies;
goto ecc_decrypt_exit;
}
RECORD_MULTI_VALUE_STATS();
}
Expand All @@ -15732,6 +15748,7 @@ static void bench_eccEncryptEx(int useDeviceID, int curveId, int ctxMode)
|| runs < minimum_runs
#endif
);
ecc_decrypt_exit:
bench_stats_asym_finish(name, keySize * 8, decDesc, useDeviceID,
count, start, ret);
#ifdef MULTI_VALUE_STATISTICS
Expand All @@ -15740,7 +15757,6 @@ static void bench_eccEncryptEx(int useDeviceID, int curveId, int ctxMode)
RESET_MULTI_VALUE_STATS_VARS();
}

exit_ecies:
wc_ecc_ctx_free(cliCtx);
wc_ecc_ctx_free(srvCtx);
}
Expand Down
Loading