mirror of https://github.com/wolfSSL/wolfssl.git
Added option to benchmark RSA sign/verify instead of enc/dec
parent
0b8c069119
commit
f2079ca792
|
@ -689,6 +689,10 @@ static THREAD_LS_T int devId = INVALID_DEVID;
|
||||||
#endif
|
#endif
|
||||||
static int base2 = 1;
|
static int base2 = 1;
|
||||||
static int digest_stream = 1;
|
static int digest_stream = 1;
|
||||||
|
#ifndef NO_RSA
|
||||||
|
/* Don't measure RSA sign/verify by default */
|
||||||
|
static int rsa_sign_verify = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* for compatibility */
|
/* for compatibility */
|
||||||
#define BENCH_SIZE bench_size
|
#define BENCH_SIZE bench_size
|
||||||
|
@ -3681,7 +3685,7 @@ void bench_rsa(int doAsync)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef BENCHMARK_RSA_SIGN_VERIFY
|
if (!rsa_sign_verify) {
|
||||||
/* begin public RSA */
|
/* begin public RSA */
|
||||||
bench_stats_start(&count, &start);
|
bench_stats_start(&count, &start);
|
||||||
do {
|
do {
|
||||||
|
@ -3690,10 +3694,13 @@ void bench_rsa(int doAsync)
|
||||||
|
|
||||||
/* while free pending slots in queue, submit ops */
|
/* while free pending slots in queue, submit ops */
|
||||||
for (i = 0; i < BENCH_MAX_PENDING; i++) {
|
for (i = 0; i < BENCH_MAX_PENDING; i++) {
|
||||||
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), 1, ×, ntimes, &pending)) {
|
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]),
|
||||||
|
1, ×, ntimes, &pending)) {
|
||||||
ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
|
ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
|
||||||
RSA_BUF_SIZE, &rsaKey[i], &rng);
|
RSA_BUF_SIZE, &rsaKey[i],
|
||||||
if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), 1, ×, &pending)) {
|
&rng);
|
||||||
|
if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(
|
||||||
|
&rsaKey[i]), 1, ×, &pending)) {
|
||||||
goto exit_rsa_pub;
|
goto exit_rsa_pub;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3702,7 +3709,8 @@ void bench_rsa(int doAsync)
|
||||||
count += times;
|
count += times;
|
||||||
} while (bench_stats_sym_check(start));
|
} while (bench_stats_sym_check(start));
|
||||||
exit_rsa_pub:
|
exit_rsa_pub:
|
||||||
bench_stats_asym_finish("RSA", rsaKeySz, "public", doAsync, count, start, ret);
|
bench_stats_asym_finish("RSA", rsaKeySz, "public", doAsync, count,
|
||||||
|
start, ret);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -3719,10 +3727,13 @@ exit_rsa_pub:
|
||||||
|
|
||||||
/* while free pending slots in queue, submit ops */
|
/* while free pending slots in queue, submit ops */
|
||||||
for (i = 0; i < BENCH_MAX_PENDING; i++) {
|
for (i = 0; i < BENCH_MAX_PENDING; i++) {
|
||||||
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), 1, ×, ntimes, &pending)) {
|
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]),
|
||||||
|
1, ×, ntimes, &pending)) {
|
||||||
ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
|
ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
|
||||||
RSA_BUF_SIZE, &rsaKey[i]);
|
RSA_BUF_SIZE, &rsaKey[i]);
|
||||||
if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), 1, ×, &pending)) {
|
if (!bench_async_handle(&ret,
|
||||||
|
BENCH_ASYNC_GET_DEV(&rsaKey[i]),
|
||||||
|
1, ×, &pending)) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3731,9 +3742,11 @@ exit_rsa_pub:
|
||||||
count += times;
|
count += times;
|
||||||
} while (bench_stats_sym_check(start));
|
} while (bench_stats_sym_check(start));
|
||||||
exit:
|
exit:
|
||||||
bench_stats_asym_finish("RSA", rsaKeySz, "private", doAsync, count, start, ret);
|
bench_stats_asym_finish("RSA", rsaKeySz, "private", doAsync, count,
|
||||||
#else
|
start, ret);
|
||||||
/* begin public RSA */
|
}
|
||||||
|
else {
|
||||||
|
/* begin RSA sign */
|
||||||
bench_stats_start(&count, &start);
|
bench_stats_start(&count, &start);
|
||||||
do {
|
do {
|
||||||
for (times = 0; times < ntimes || pending > 0; ) {
|
for (times = 0; times < ntimes || pending > 0; ) {
|
||||||
|
@ -3741,19 +3754,23 @@ exit:
|
||||||
|
|
||||||
/* while free pending slots in queue, submit ops */
|
/* while free pending slots in queue, submit ops */
|
||||||
for (i = 0; i < BENCH_MAX_PENDING; i++) {
|
for (i = 0; i < BENCH_MAX_PENDING; i++) {
|
||||||
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), 1, ×, ntimes, &pending)) {
|
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]),
|
||||||
|
1, ×, ntimes, &pending)) {
|
||||||
ret = wc_RsaSSL_Sign(message, len, enc[i],
|
ret = wc_RsaSSL_Sign(message, len, enc[i],
|
||||||
RSA_BUF_SIZE, &rsaKey[i], &rng);
|
RSA_BUF_SIZE, &rsaKey[i], &rng);
|
||||||
if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), 1, ×, &pending)) {
|
if (!bench_async_handle(&ret,
|
||||||
goto exit_rsa_pub;
|
BENCH_ASYNC_GET_DEV(&rsaKey[i]),
|
||||||
|
1, ×, &pending)) {
|
||||||
|
goto exit_rsa_sign;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* for i */
|
} /* for i */
|
||||||
} /* for times */
|
} /* for times */
|
||||||
count += times;
|
count += times;
|
||||||
} while (bench_stats_sym_check(start));
|
} while (bench_stats_sym_check(start));
|
||||||
exit_rsa_pub:
|
exit_rsa_sign:
|
||||||
bench_stats_asym_finish("RSA", rsaKeySz, "private", doAsync, count, start, ret);
|
bench_stats_asym_finish("RSA", rsaKeySz, "sign", doAsync, count, start,
|
||||||
|
ret);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -3762,7 +3779,7 @@ exit_rsa_pub:
|
||||||
/* capture resulting encrypt length */
|
/* capture resulting encrypt length */
|
||||||
idx = rsaKeySz/8;
|
idx = rsaKeySz/8;
|
||||||
|
|
||||||
/* begin private async RSA */
|
/* begin RSA verify */
|
||||||
bench_stats_start(&count, &start);
|
bench_stats_start(&count, &start);
|
||||||
do {
|
do {
|
||||||
for (times = 0; times < ntimes || pending > 0; ) {
|
for (times = 0; times < ntimes || pending > 0; ) {
|
||||||
|
@ -3770,20 +3787,24 @@ exit_rsa_pub:
|
||||||
|
|
||||||
/* while free pending slots in queue, submit ops */
|
/* while free pending slots in queue, submit ops */
|
||||||
for (i = 0; i < BENCH_MAX_PENDING; i++) {
|
for (i = 0; i < BENCH_MAX_PENDING; i++) {
|
||||||
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), 1, ×, ntimes, &pending)) {
|
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]),
|
||||||
|
1, ×, ntimes, &pending)) {
|
||||||
ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
|
ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
|
||||||
RSA_BUF_SIZE, &rsaKey[i]);
|
RSA_BUF_SIZE, &rsaKey[i]);
|
||||||
if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), 1, ×, &pending)) {
|
if (!bench_async_handle(&ret,
|
||||||
goto exit;
|
BENCH_ASYNC_GET_DEV(&rsaKey[i]),
|
||||||
|
1, ×, &pending)) {
|
||||||
|
goto exit_rsa_verify;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* for i */
|
} /* for i */
|
||||||
} /* for times */
|
} /* for times */
|
||||||
count += times;
|
count += times;
|
||||||
} while (bench_stats_sym_check(start));
|
} while (bench_stats_sym_check(start));
|
||||||
exit:
|
exit_rsa_verify:
|
||||||
bench_stats_asym_finish("RSA", rsaKeySz, "public", doAsync, count, start, ret);
|
bench_stats_asym_finish("RSA", rsaKeySz, "verify", doAsync, count,
|
||||||
#endif
|
start, ret);
|
||||||
|
}
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
for (i = 0; i < BENCH_MAX_PENDING; i++) {
|
for (i = 0; i < BENCH_MAX_PENDING; i++) {
|
||||||
|
@ -3934,7 +3955,7 @@ exit_dh_gen:
|
||||||
count += times;
|
count += times;
|
||||||
} while (bench_stats_sym_check(start));
|
} while (bench_stats_sym_check(start));
|
||||||
exit:
|
exit:
|
||||||
bench_stats_asym_finish("DH", dhKeySz, "key agree", doAsync, count, start, ret);
|
bench_stats_asym_finish("DH", dhKeySz, "agree", doAsync, count, start, ret);
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
for (i = 0; i < BENCH_MAX_PENDING; i++) {
|
for (i = 0; i < BENCH_MAX_PENDING; i++) {
|
||||||
|
@ -4520,7 +4541,7 @@ void bench_curve25519KeyAgree(void)
|
||||||
count += i;
|
count += i;
|
||||||
} while (bench_stats_sym_check(start));
|
} while (bench_stats_sym_check(start));
|
||||||
exit:
|
exit:
|
||||||
bench_stats_asym_finish("CURVE", 25519, "key agree", 0, count, start, ret);
|
bench_stats_asym_finish("CURVE", 25519, "agree", 0, count, start, ret);
|
||||||
|
|
||||||
wc_curve25519_free(&genKey2);
|
wc_curve25519_free(&genKey2);
|
||||||
wc_curve25519_free(&genKey);
|
wc_curve25519_free(&genKey);
|
||||||
|
@ -4797,6 +4818,9 @@ static void Usage(void)
|
||||||
printf("-no_aad No additional authentication data passed.\n");
|
printf("-no_aad No additional authentication data passed.\n");
|
||||||
#endif
|
#endif
|
||||||
printf("-dgst_full Full digest operation performed.\n");
|
printf("-dgst_full Full digest operation performed.\n");
|
||||||
|
#ifndef NO_RSA
|
||||||
|
printf("-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n");
|
||||||
|
#endif
|
||||||
#ifndef WOLFSSL_BENCHMARK_ALL
|
#ifndef WOLFSSL_BENCHMARK_ALL
|
||||||
printf("-<alg> Algorithm to benchmark. Available algorithms "
|
printf("-<alg> Algorithm to benchmark. Available algorithms "
|
||||||
"include:\n");
|
"include:\n");
|
||||||
|
@ -4858,6 +4882,10 @@ int main(int argc, char** argv)
|
||||||
#endif
|
#endif
|
||||||
else if (string_matches(argv[1], "-dgst_full"))
|
else if (string_matches(argv[1], "-dgst_full"))
|
||||||
digest_stream = 0;
|
digest_stream = 0;
|
||||||
|
#ifndef NO_RSA
|
||||||
|
else if (string_matches(argv[1], "-rsa_sign"))
|
||||||
|
rsa_sign_verify = 1;
|
||||||
|
#endif
|
||||||
else if (argv[1][0] == '-') {
|
else if (argv[1][0] == '-') {
|
||||||
optMatched = 0;
|
optMatched = 0;
|
||||||
#ifndef WOLFSSL_BENCHMARK_ALL
|
#ifndef WOLFSSL_BENCHMARK_ALL
|
||||||
|
|
Loading…
Reference in New Issue