aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorChenglong Zhang <auvkone@gmail.com>2021-02-10 17:52:29 +0800
committerTomas Mraz <tomas@openssl.org>2021-02-19 13:55:51 +0100
commitc2279499fd17673b631785887c339cf35f088c41 (patch)
treeb44e6ba0cf949b5e04366f3b5d9ac4aae629d031 /apps
parent1d724b5e82ba36fb50fd24db3cd664da570daf84 (diff)
downloadopenssl-c2279499fd17673b631785887c339cf35f088c41.tar.gz
Fix speed sm2 bug
Should create PKEY CTX with EVP_PKEY_SM2; each job should have its own sm2_pkey; loopargs[i].sigsize should be set after EVP_DigestSign(). Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14144)
Diffstat (limited to 'apps')
-rw-r--r--apps/speed.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/apps/speed.c b/apps/speed.c
index c41fca483f..e867448015 100644
--- a/apps/speed.c
+++ b/apps/speed.c
@@ -1283,12 +1283,14 @@ static int SM2_sign_loop(void *args)
unsigned char *buf = tempargs->buf;
EVP_MD_CTX **sm2ctx = tempargs->sm2_ctx;
unsigned char *sm2sig = tempargs->buf2;
- size_t sm2sigsize = tempargs->sigsize;
- const size_t max_size = tempargs->sigsize;
+ size_t sm2sigsize;
int ret, count;
EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
+ const size_t max_size = EVP_PKEY_size(sm2_pkey[testnum]);
for (count = 0; COND(sm2_c[testnum][0]); count++) {
+ sm2sigsize = max_size;
+
if (!EVP_DigestSignInit(sm2ctx[testnum], NULL, EVP_sm3(),
NULL, sm2_pkey[testnum])) {
BIO_printf(bio_err, "SM2 init sign failure\n");
@@ -1306,7 +1308,6 @@ static int SM2_sign_loop(void *args)
}
/* update the latest returned size and always use the fixed buffer size */
tempargs->sigsize = sm2sigsize;
- sm2sigsize = max_size;
}
return count;
@@ -3567,8 +3568,9 @@ int speed_main(int argc, char **argv)
|| loopargs[i].sm2_vfy_ctx[testnum] == NULL)
break;
- /* SM2 keys are generated as normal EC keys with a special curve */
- st = !((pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) == NULL
+ sm2_pkey = NULL;
+
+ st = !((pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_SM2, NULL)) == NULL
|| EVP_PKEY_keygen_init(pctx) <= 0
|| EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
sm2_curves[testnum].nid) <= 0
@@ -3615,11 +3617,9 @@ int speed_main(int argc, char **argv)
op_count = 1;
} else {
for (i = 0; i < loopargs_len; i++) {
- size_t sm2_sigsize = loopargs[i].sigsize;
-
/* Perform SM2 signature test */
st = EVP_DigestSign(loopargs[i].sm2_ctx[testnum],
- loopargs[i].buf2, &sm2_sigsize,
+ loopargs[i].buf2, &loopargs[i].sigsize,
loopargs[i].buf, 20);
if (st == 0)
break;