1SM2(7)                              OpenSSL                             SM2(7)
2
3
4

NAME

6       SM2 - Chinese SM2 signature and encryption algorithm support
7

DESCRIPTION

9       The SM2 algorithm was first defined by the Chinese national standard
10       GM/T 0003-2012 and was later standardized by ISO as ISO/IEC 14888. SM2
11       is actually an elliptic curve based algorithm. The current
12       implementation in OpenSSL supports both signature and encryption
13       schemes via the EVP interface.
14
15       When doing the SM2 signature algorithm, it requires a distinguishing
16       identifier to form the message prefix which is hashed before the real
17       message is hashed.
18

NOTES

20       SM2 signatures can be generated by using the 'DigestSign' series of
21       APIs, for instance, EVP_DigestSignInit(), EVP_DigestSignUpdate() and
22       EVP_DigestSignFinal().  Ditto for the verification process by calling
23       the 'DigestVerify' series of APIs.
24
25       There are several special steps that need to be done before computing
26       an SM2 signature.
27
28       The EVP_PKEY structure will default to using ECDSA for signatures when
29       it is created. It should be set to EVP_PKEY_SM2 by calling:
30
31        EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
32
33       Then an ID should be set by calling:
34
35        EVP_PKEY_CTX_set1_id(pctx, id, id_len);
36
37       When calling the EVP_DigestSignInit() or EVP_DigestVerifyInit()
38       functions, a pre-allocated EVP_PKEY_CTX should be assigned to the
39       EVP_MD_CTX. This is done by calling:
40
41        EVP_MD_CTX_set_pkey_ctx(mctx, pctx);
42
43       And normally there is no need to pass a pctx parameter to
44       EVP_DigestSignInit() or EVP_DigestVerifyInit() in such a scenario.
45

EXAMPLES

47       This example demonstrates the calling sequence for using an EVP_PKEY to
48       verify a message with the SM2 signature algorithm and the SM3 hash
49       algorithm:
50
51        #include <openssl/evp.h>
52
53        /* obtain an EVP_PKEY using whatever methods... */
54        EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
55        mctx = EVP_MD_CTX_new();
56        pctx = EVP_PKEY_CTX_new(pkey, NULL);
57        EVP_PKEY_CTX_set1_id(pctx, id, id_len);
58        EVP_MD_CTX_set_pkey_ctx(mctx, pctx);;
59        EVP_DigestVerifyInit(mctx, NULL, EVP_sm3(), NULL, pkey);
60        EVP_DigestVerifyUpdate(mctx, msg, msg_len);
61        EVP_DigestVerifyFinal(mctx, sig, sig_len)
62

SEE ALSO

64       EVP_PKEY_CTX_new(3), EVP_PKEY_set_alias_type(3), EVP_DigestSignInit(3),
65       EVP_DigestVerifyInit(3), EVP_PKEY_CTX_set1_id(3),
66       EVP_MD_CTX_set_pkey_ctx(3)
67
69       Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
70
71       Licensed under the OpenSSL license (the "License").  You may not use
72       this file except in compliance with the License.  You can obtain a copy
73       in the file LICENSE in the source distribution or at
74       <https://www.openssl.org/source/license.html>.
75
76
77
781.1.1d                            2019-10-03                            SM2(7)
Impressum