| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "EVP_PKEY-SM2 7SSL" |
| 58 |
.TH EVP_PKEY-SM2 7SSL 2026-04-07 3.6.2 OpenSSL |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
EVP_PKEY\-SM2, EVP_KEYMGMT\-SM2, SM2 |
| 65 |
\&\- EVP_PKEY keytype support for the Chinese SM2 signature and encryption algorithms |
| 66 |
.SH DESCRIPTION |
| 67 |
.IX Header "DESCRIPTION" |
| 68 |
The \fBSM2\fR algorithm was first defined by the Chinese national standard GM/T |
| 69 |
0003\-2012 and was later standardized by ISO as ISO/IEC 14888. \fBSM2\fR is actually |
| 70 |
an elliptic curve based algorithm. The current implementation in OpenSSL supports |
| 71 |
both signature and encryption schemes via the EVP interface. |
| 72 |
.PP |
| 73 |
When doing the \fBSM2\fR signature algorithm, it requires a distinguishing identifier |
| 74 |
to form the message prefix which is hashed before the real message is hashed. |
| 75 |
.SS "Common SM2 parameters" |
| 76 |
.IX Subsection "Common SM2 parameters" |
| 77 |
SM2 uses the parameters defined in "Common EC parameters" in \fBEVP_PKEY\-EC\fR\|(7). |
| 78 |
The following parameters are different: |
| 79 |
.IP """cofactor"" (\fBOSSL_PKEY_PARAM_EC_COFACTOR\fR) <unsigned integer>" 4 |
| 80 |
.IX Item """cofactor"" (OSSL_PKEY_PARAM_EC_COFACTOR) <unsigned integer>" |
| 81 |
This parameter is ignored for \fBSM2\fR. |
| 82 |
.IP "(\fBOSSL_PKEY_PARAM_DEFAULT_DIGEST\fR) <UTF8 string>" 4 |
| 83 |
.IX Item "(OSSL_PKEY_PARAM_DEFAULT_DIGEST) <UTF8 string>" |
| 84 |
Getter that returns the default digest name. |
| 85 |
(Currently returns "SM3" as of OpenSSL 3.0). |
| 86 |
.SH NOTES |
| 87 |
.IX Header "NOTES" |
| 88 |
\&\fBSM2\fR signatures can be generated by using the 'DigestSign' series of APIs, for |
| 89 |
instance, \fBEVP_DigestSignInit()\fR, \fBEVP_DigestSignUpdate()\fR and \fBEVP_DigestSignFinal()\fR. |
| 90 |
Ditto for the verification process by calling the 'DigestVerify' series of APIs. |
| 91 |
Note that the SM2 algorithm requires the presence of the public key for signatures, |
| 92 |
as such the \fBOSSL_PKEY_PARAM_PUB_KEY\fR option must be set on any key used in signature |
| 93 |
generation. |
| 94 |
.PP |
| 95 |
Before computing an \fBSM2\fR signature, an \fBEVP_PKEY_CTX\fR needs to be created, |
| 96 |
and an \fBSM2\fR ID must be set for it, like this: |
| 97 |
.PP |
| 98 |
.Vb 1 |
| 99 |
\& EVP_PKEY_CTX_set1_id(pctx, id, id_len); |
| 100 |
.Ve |
| 101 |
.PP |
| 102 |
Before calling the \fBEVP_DigestSignInit()\fR or \fBEVP_DigestVerifyInit()\fR functions, |
| 103 |
that \fBEVP_PKEY_CTX\fR should be assigned to the \fBEVP_MD_CTX\fR, like this: |
| 104 |
.PP |
| 105 |
.Vb 1 |
| 106 |
\& EVP_MD_CTX_set_pkey_ctx(mctx, pctx); |
| 107 |
.Ve |
| 108 |
.PP |
| 109 |
There is normally no need to pass a \fBpctx\fR parameter to \fBEVP_DigestSignInit()\fR |
| 110 |
or \fBEVP_DigestVerifyInit()\fR in such a scenario. |
| 111 |
.PP |
| 112 |
SM2 can be tested with the \fBopenssl\-speed\fR\|(1) application since version 3.0. |
| 113 |
Currently, the only valid algorithm name is \fBsm2\fR. |
| 114 |
.PP |
| 115 |
Since version 3.0, SM2 keys can be generated and loaded only when the domain |
| 116 |
parameters specify the SM2 elliptic curve. |
| 117 |
.SH EXAMPLES |
| 118 |
.IX Header "EXAMPLES" |
| 119 |
This example demonstrates the calling sequence for using an \fBEVP_PKEY\fR to verify |
| 120 |
a message with the SM2 signature algorithm and the SM3 hash algorithm: |
| 121 |
.PP |
| 122 |
.Vb 1 |
| 123 |
\& #include <openssl/evp.h> |
| 124 |
\& |
| 125 |
\& /* obtain an EVP_PKEY using whatever methods... */ |
| 126 |
\& mctx = EVP_MD_CTX_new(); |
| 127 |
\& pctx = EVP_PKEY_CTX_new(pkey, NULL); |
| 128 |
\& EVP_PKEY_CTX_set1_id(pctx, id, id_len); |
| 129 |
\& EVP_MD_CTX_set_pkey_ctx(mctx, pctx); |
| 130 |
\& EVP_DigestVerifyInit(mctx, NULL, EVP_sm3(), NULL, pkey); |
| 131 |
\& EVP_DigestVerifyUpdate(mctx, msg, msg_len); |
| 132 |
\& EVP_DigestVerifyFinal(mctx, sig, sig_len) |
| 133 |
.Ve |
| 134 |
.SH "SEE ALSO" |
| 135 |
.IX Header "SEE ALSO" |
| 136 |
\&\fBEVP_PKEY_CTX_new\fR\|(3), |
| 137 |
\&\fBEVP_DigestSignInit\fR\|(3), |
| 138 |
\&\fBEVP_DigestVerifyInit\fR\|(3), |
| 139 |
\&\fBEVP_PKEY_CTX_set1_id\fR\|(3), |
| 140 |
\&\fBEVP_MD_CTX_set_pkey_ctx\fR\|(3) |
| 141 |
.SH COPYRIGHT |
| 142 |
.IX Header "COPYRIGHT" |
| 143 |
Copyright 2018\-2024 The OpenSSL Project Authors. All Rights Reserved. |
| 144 |
.PP |
| 145 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 146 |
this file except in compliance with the License. You can obtain a copy |
| 147 |
in the file LICENSE in the source distribution or at |
| 148 |
<https://www.openssl.org/source/license.html>. |