openssl-prebuild/linux_amd64/ssl/share/doc/openssl/html/man7/SM2.html

104 lines
3.9 KiB
HTML
Raw Normal View History

2020-03-02 11:50:34 -05:00
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SM2</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>
<body style="background-color: white">
<!-- INDEX BEGIN -->
<div name="index">
<p><a name="__index__"></a></p>
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#notes">NOTES</a></li>
<li><a href="#examples">EXAMPLES</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
<li><a href="#copyright">COPYRIGHT</a></li>
</ul>
<hr name="index" />
</div>
<!-- INDEX END -->
<p>
</p>
<hr />
<h1><a name="name">NAME</a></h1>
<p>SM2 - Chinese SM2 signature and encryption algorithm support</p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>The <strong>SM2</strong> algorithm was first defined by the Chinese national standard GM/T
0003-2012 and was later standardized by ISO as ISO/IEC 14888. <strong>SM2</strong> is actually
an elliptic curve based algorithm. The current implementation in OpenSSL supports
both signature and encryption schemes via the EVP interface.</p>
<p>When doing the <strong>SM2</strong> signature algorithm, it requires a distinguishing identifier
to form the message prefix which is hashed before the real message is hashed.</p>
<p>
</p>
<hr />
<h1><a name="notes">NOTES</a></h1>
<p><strong>SM2</strong> signatures can be generated by using the 'DigestSign' series of APIs, for
instance, <code>EVP_DigestSignInit()</code>, <code>EVP_DigestSignUpdate()</code> and <code>EVP_DigestSignFinal()</code>.
Ditto for the verification process by calling the 'DigestVerify' series of APIs.</p>
<p>Before computing an <strong>SM2</strong> signature, an <strong>EVP_PKEY_CTX</strong> needs to be created,
and an <strong>SM2</strong> ID must be set for it, like this:</p>
<pre>
EVP_PKEY_CTX_set1_id(pctx, id, id_len);</pre>
<p>Before calling the <code>EVP_DigestSignInit()</code> or <code>EVP_DigestVerifyInit()</code> functions,
that <strong>EVP_PKEY_CTX</strong> should be assigned to the <strong>EVP_MD_CTX</strong>, like this:</p>
<pre>
EVP_MD_CTX_set_pkey_ctx(mctx, pctx);</pre>
<p>There is normally no need to pass a <strong>pctx</strong> parameter to <code>EVP_DigestSignInit()</code>
or <code>EVP_DigestVerifyInit()</code> in such a scenario.</p>
<p>SM2 can be tested with the <em>openssl-speed(1)</em> application since version 3.0.0.
Currently, the only valid algorithm name is <strong>sm2</strong>.</p>
<p>
</p>
<hr />
<h1><a name="examples">EXAMPLES</a></h1>
<p>This example demonstrates the calling sequence for using an <strong>EVP_PKEY</strong> to verify
a message with the SM2 signature algorithm and the SM3 hash algorithm:</p>
<pre>
#include &lt;openssl/evp.h&gt;</pre>
<pre>
/* 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)</pre>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><em>EVP_PKEY_CTX_new(3)</em>,
<em>EVP_DigestSignInit(3)</em>,
<em>EVP_DigestVerifyInit(3)</em>,
<em>EVP_PKEY_CTX_set1_id(3)</em>,
<em>EVP_MD_CTX_set_pkey_ctx(3)</em></p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.</p>
<p>Licensed under the Apache License 2.0 (the &quot;License&quot;). You may not use
this file except in compliance with the License. You can obtain a copy
in the file LICENSE in the source distribution or at
<a href="https://www.openssl.org/source/license.html">https://www.openssl.org/source/license.html</a>.</p>
</body>
</html>