# man > EVP_PKEY-SM2(7SSL)

---
type: CommandReference
command: EVP_PKEY-SM2
mode: man
section: 7
source: man-pages
---

## Quick Reference
- `EVP_PKEY_CTX_set1_id(pctx, id, id_len)` — set SM2 distinguishing identifier before signing/verification
- `EVP_MD_CTX_set_pkey_ctx(mctx, pctx)` — attach the SM2 context to the digest context
- `EVP_DigestSignInit(mctx, NULL, EVP_sm3(), NULL, pkey)` — initialize SM2 signing with SM3 hash
- `EVP_DigestVerifyInit(mctx, NULL, EVP_sm3(), NULL, pkey)` — initialize SM2 verification with SM3
- SM2 keys require domain parameters that specify the SM2 elliptic curve (OpenSSL ≥ 3.0)
- Use `openssl-speed sm2` to benchmark SM2 operations

## Name
EVP_PKEY-SM2 - EVP_PKEY keytype support for the Chinese SM2 signature and encryption algorithms

## Synopsis
c
#include <openssl/evp.h>

EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new(pkey, NULL);
EVP_PKEY_CTX_set1_id(pctx, id, id_len);
EVP_MD_CTX_set_pkey_ctx(mctx, pctx);
/* then call DigestSign/DigestVerify functions */
## Options
- **`"cofactor"`** (`OSSL_PKEY_PARAM_EC_COFACTOR`) — ignored for SM2.
- **`"default digest"`** (`OSSL_PKEY_PARAM_DEFAULT_DIGEST`) — returns `"SM3"` as the default digest name.

## Examples
SM2 message verification with SM3 hash:
c
#include <openssl/evp.h>

/* obtain an EVP_PKEY using whatever methods... */
mctx = EVP_MD_CTX_new();
pctx = EVP_PKEY_CTX_new(pkey, NULL);
EVP_PKEY_CTX_set1_id(pctx, id, id_len);
EVP_MD_CTX_set_pkey_ctx(mctx, pctx);
EVP_DigestVerifyInit(mctx, NULL, EVP_sm3(), NULL, pkey);
EVP_DigestVerifyUpdate(mctx, msg, msg_len);
EVP_DigestVerifyFinal(mctx, sig, sig_len);
## See Also
[EVP_PKEY_CTX_new(3)](http://localhost/phpMan.php/man/new/3/markdown), [EVP_DigestSignInit(3)](http://localhost/phpMan.php/man/DigestSignInit/3/markdown), [EVP_DigestVerifyInit(3)](http://localhost/phpMan.php/man/DigestVerifyInit/3/markdown), [EVP_PKEY_CTX_set1_id(3)](http://localhost/phpMan.php/man/id/3/markdown), [EVP_MD_CTX_set_pkey_ctx(3)](http://localhost/phpMan.php/man/ctx/3/markdown)