summaryrefslogtreecommitdiffstats
path: root/crypto/ec
diff options
context:
space:
mode:
authorPaul Yang <yang.yang@baishancloud.com>2019-02-25 17:34:03 +0800
committerPaul Yang <yang.yang@baishancloud.com>2019-02-27 10:05:17 +0800
commite766f4a0531bffdab8ad2038279b755928d7a40a (patch)
treeb4496b988a15d355f71aa4e0cb280a9b575efce5 /crypto/ec
parenta7cef52f9b961dcb1e5d0c3b75185a12a88ad2db (diff)
Fix the default digest algorthm of SM2
Currently SM2 shares the ameth with EC, so the current default digest algorithm returned is SHA256. This fixes the default digest algorithm of SM2 to SM3, which is the only valid digest algorithm for SM2 signature. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/8186)
Diffstat (limited to 'crypto/ec')
-rw-r--r--crypto/ec/ec_ameth.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/crypto/ec/ec_ameth.c b/crypto/ec/ec_ameth.c
index 54d55ad472..2beeb82707 100644
--- a/crypto/ec/ec_ameth.c
+++ b/crypto/ec/ec_ameth.c
@@ -504,7 +504,12 @@ static int ec_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
#endif
case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
- *(int *)arg2 = NID_sha256;
+ if (EVP_PKEY_id(pkey) == EVP_PKEY_SM2) {
+ /* For SM2, the only valid digest-alg is SM3 */
+ *(int *)arg2 = NID_sm3;
+ } else {
+ *(int *)arg2 = NID_sha256;
+ }
return 1;
case ASN1_PKEY_CTRL_SET1_TLS_ENCPT: