From ac98a4de061c6f9b9ab9df1c3da5999b7fce0b53 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 3450c7b33..6db2bb512 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -1009,12 +1009,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 7a1edb4fbc5541c383b138741422e7d6892208ba 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 abfab9291..9c420f025 100644 --- a/crypto/pkcs7/pk7_lib.c +++ b/crypto/pkcs7/pk7_lib.c @@ -365,7 +365,9 @@ int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, X509_ALGOR_set0(p7i->digest_alg, OBJ_nid2obj(EVP_MD_get_type(dgst)), V_ASN1_NULL, NULL); - 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);