Add a SM2(7) man page
[openssl.git] / doc / man7 / SM2.pod
1 =pod
2
3 =head1 NAME
4
5 SM2 - Chinese SM2 signature and encryption algorithm support
6
7 =head1 DESCRIPTION
8
9 B<SM2> algorithm is first defined by the Chinese national standard GM/T 0003-2012
10 and is standardized by ISO as ISO/IEC 14888. B<SM2> is actually an elliptic curve
11 based algorithm. Currnet implementation in OpenSSL supports both signature and
12 encryption schemes via EVP interface.
13
14 When doing the B<SM2> signature algorithm, it requires a distinguishing identifier
15 to form the message prefix which is hashed before the real message is hashed.
16
17 =head1 NOTES
18
19 B<SM2> signature can be generated by using the 'DigestSign' series APIs, for instance,
20 EVP_DigestSignInit(), EVP_DigestSignUpdate() and EVP_DigestSignFinal(). Ditto
21 for the verification process by calling the 'DigestVerify' series APIs.
22
23 There are several special steps need to be done before computing an B<SM2> signature.
24
25 The B<EVP_PKEY> structure should be set to B<EVP_PKEY_SM2> by calling:
26
27  EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
28
29 Then an ID should be set by calling:
30
31  EVP_PKEY_CTX_set1_id(pctx, id, id_len);
32
33 When calling the EVP_DeigestSignInit() or EVP_DigestVerifyInit() function, a
34 pre-allocated B<EVP_PKEY_CTX> should be assigned to the B<EVP_MD_CTX>. This is
35 done by calling:
36
37  EVP_MD_CTX_set_pkey_ctx(mctx, pctx);
38
39 And normally there is no need to pass a B<pctx> parameter to EVP_DeigestSignInit()
40 or EVP_DigestVerifyInit() in such scenario.
41
42 =head1 EXAMPLE
43
44 This example demonstrates the calling sequence on how to use an B<EVP_PKEY> to
45 sign a message with SM2 signature algorithm and SM3 hash algorithm:
46
47  #include <openssl/evp.h>
48
49  /* obtain an EVP_PKEY from whatever methods... */
50  EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
51  mctx = EVP_MD_CTX_new();
52  pctx = EVP_PKEY_CTX_new(pkey, NULL);
53  EVP_PKEY_CTX_set1_id(pctx, id, id_len);
54  EVP_MD_CTX_set_pkey_ctx(mctx, pctx);;
55  EVP_DigestVerifyInit(mctx, NULL, EVP_sm3(), NULL, pkey);
56  EVP_DigestVerifyUpdate(mctx, msg, msg_len);
57  EVP_DigestVerifyFinal(mctx, sig, sig_len)
58
59 =head1 SEE ALSO
60
61 L<EVP_PKEY_CTX_new(3)>,
62 L<EVP_PKEY_set_alias_type(3)>,
63 L<EVP_DigestSignInit(3)>,
64 L<EVP_DigestVerifyInit(3)>,
65 L<EVP_PKEY_CTX_set1_id(3)>,
66 L<EVP_MD_CTX_set_pkey_ctx(3)>
67
68 =head1 COPYRIGHT
69
70 Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
71
72 Licensed under the OpenSSL license (the "License").  You may not use
73 this file except in compliance with the License.  You can obtain a copy
74 in the file LICENSE in the source distribution or at
75 L<https://www.openssl.org/source/license.html>.
76
77 =cut