From 11348dc644db1257ebc2c82133da3051f04abaec Mon Sep 17 00:00:00 2001 From: Tianjia Zhang Date: Sat, 11 Sep 2021 23:22:26 +0800 Subject: [PATCH 1/2] evp: Supports getting pkey type from keymgmt If the public key type is EVP_PKEY_KEYMGMT, errors may occur in some cases. It is necessary to obtain the exact type of the public key from keymgmt. Signed-off-by: Tianjia Zhang --- crypto/evp/p_lib.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index 0fab07c5da..76e863f78e 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -983,12 +983,19 @@ int EVP_PKEY_type(int type) int EVP_PKEY_get_id(const EVP_PKEY *pkey) { + if (pkey->type == EVP_PKEY_KEYMGMT) { + const char *name = EVP_KEYMGMT_get0_name(pkey->keymgmt); + int type = evp_pkey_name2type(name); + if (type != NID_undef) + return type; + } + return pkey->type; } int EVP_PKEY_get_base_id(const EVP_PKEY *pkey) { - return EVP_PKEY_type(pkey->type); + return EVP_PKEY_type(EVP_PKEY_get_id(pkey)); } /* From b1d75d2df899aef0daca78b00702ca286c0e81da Mon Sep 17 00:00:00 2001 From: Tianjia Zhang Date: Fri, 11 Aug 2023 11:22:32 +0800 Subject: [PATCH 2/2] pkcs7: support sm2 public algorithm Signed-off-by: Tianjia Zhang --- crypto/pkcs7/pk7_lib.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crypto/pkcs7/pk7_lib.c b/crypto/pkcs7/pk7_lib.c index aa600d1794..9f57cf358e 100644 --- a/crypto/pkcs7/pk7_lib.c +++ b/crypto/pkcs7/pk7_lib.c @@ -367,7 +367,9 @@ int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, V_ASN1_NULL, NULL)) return 0; - if (EVP_PKEY_is_a(pkey, "EC") || EVP_PKEY_is_a(pkey, "DSA")) + if (EVP_PKEY_is_a(pkey, "EC") + || EVP_PKEY_is_a(pkey, "DSA") + || EVP_PKEY_is_a(pkey, "SM2")) return pkcs7_ecdsa_or_dsa_sign_verify_setup(p7i, 0); if (EVP_PKEY_is_a(pkey, "RSA")) return pkcs7_rsa_sign_verify_setup(p7i, 0);