Merge pull request #3870 from JacobBarthelmeh/Benchmark

fix for using devId with benchmarking ECC
This commit is contained in:
David Garske
2021-03-15 10:09:23 -07:00
committed by GitHub

View File

@ -5359,12 +5359,20 @@ void bench_ecc_curve(int curveId)
void bench_eccMakeKey(int doAsync, int curveId) void bench_eccMakeKey(int doAsync, int curveId)
{ {
int ret = 0, i, times, count, pending = 0; int ret = 0, i, times, count, pending = 0;
int deviceID;
int keySize; int keySize;
ecc_key genKey[BENCH_MAX_PENDING]; ecc_key genKey[BENCH_MAX_PENDING];
char name[BENCH_ECC_NAME_SZ]; char name[BENCH_ECC_NAME_SZ];
double start; double start;
const char**desc = bench_desc_words[lng_index]; const char**desc = bench_desc_words[lng_index];
#ifdef WOLFSSL_ASYNC_CRYPT
deviceID = doAsync ? devId : INVALID_DEVID;
#else
deviceID = devId;
#endif
keySize = wc_ecc_get_curve_size_from_id(curveId); keySize = wc_ecc_get_curve_size_from_id(curveId);
/* clear for done cleanup */ /* clear for done cleanup */
@ -5382,8 +5390,7 @@ void bench_eccMakeKey(int doAsync, int curveId)
&times, genTimes, &pending)) { &times, genTimes, &pending)) {
wc_ecc_free(&genKey[i]); wc_ecc_free(&genKey[i]);
ret = wc_ecc_init_ex(&genKey[i], HEAP_HINT, doAsync ? ret = wc_ecc_init_ex(&genKey[i], HEAP_HINT, deviceID);
devId : INVALID_DEVID);
if (ret < 0) { if (ret < 0) {
goto exit; goto exit;
} }
@ -5416,6 +5423,7 @@ exit:
void bench_ecc(int doAsync, int curveId) void bench_ecc(int doAsync, int curveId)
{ {
int ret = 0, i, times, count, pending = 0; int ret = 0, i, times, count, pending = 0;
int deviceID;
int keySize; int keySize;
char name[BENCH_ECC_NAME_SZ]; char name[BENCH_ECC_NAME_SZ];
ecc_key genKey[BENCH_MAX_PENDING]; ecc_key genKey[BENCH_MAX_PENDING];
@ -5439,6 +5447,12 @@ void bench_ecc(int doAsync, int curveId)
DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
#endif #endif
#ifdef WOLFSSL_ASYNC_CRYPT
deviceID = doAsync ? devId : INVALID_DEVID;
#else
deviceID = devId;
#endif
/* clear for done cleanup */ /* clear for done cleanup */
XMEMSET(&genKey, 0, sizeof(genKey)); XMEMSET(&genKey, 0, sizeof(genKey));
#ifdef HAVE_ECC_DHE #ifdef HAVE_ECC_DHE
@ -5449,8 +5463,7 @@ void bench_ecc(int doAsync, int curveId)
/* init keys */ /* init keys */
for (i = 0; i < BENCH_MAX_PENDING; i++) { for (i = 0; i < BENCH_MAX_PENDING; i++) {
/* setup an context for each key */ /* setup an context for each key */
if ((ret = wc_ecc_init_ex(&genKey[i], HEAP_HINT, if ((ret = wc_ecc_init_ex(&genKey[i], HEAP_HINT, deviceID)) < 0) {
doAsync ? devId : INVALID_DEVID)) < 0) {
goto exit; goto exit;
} }
ret = wc_ecc_make_key_ex(&gRng, keySize, &genKey[i], curveId); ret = wc_ecc_make_key_ex(&gRng, keySize, &genKey[i], curveId);
@ -5462,7 +5475,7 @@ void bench_ecc(int doAsync, int curveId)
} }
#ifdef HAVE_ECC_DHE #ifdef HAVE_ECC_DHE
if ((ret = wc_ecc_init_ex(&genKey2[i], HEAP_HINT, INVALID_DEVID)) < 0) { if ((ret = wc_ecc_init_ex(&genKey2[i], HEAP_HINT, deviceID)) < 0) {
goto exit; goto exit;
} }
if ((ret = wc_ecc_make_key_ex(&gRng, keySize, &genKey2[i], if ((ret = wc_ecc_make_key_ex(&gRng, keySize, &genKey2[i],