Current Path : /compat/linux/proc/self/root/usr/opt/openssl11/share/doc/openssl/html/man7/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //compat/linux/proc/self/root/usr/opt/openssl11/share/doc/openssl/html/man7/SM2.html |
<?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@hsxx.drive.ne.jp" /> </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>There are several special steps that need to be done before computing an <strong>SM2</strong> signature.</p> <p>The <strong>EVP_PKEY</strong> structure will default to using ECDSA for signatures when it is created. It should be set to <strong>EVP_PKEY_SM2</strong> by calling:</p> <pre> EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);</pre> <p>Then an ID should be set by calling:</p> <pre> EVP_PKEY_CTX_set1_id(pctx, id, id_len);</pre> <p>When calling the <code>EVP_DigestSignInit()</code> or <code>EVP_DigestVerifyInit()</code> functions, a preallocated <strong>EVP_PKEY_CTX</strong> should be assigned to the <strong>EVP_MD_CTX</strong>. This is done by calling:</p> <pre> EVP_MD_CTX_set_pkey_ctx(mctx, pctx);</pre> <p>And normally there is 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> </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 <openssl/evp.h></pre> <pre> /* obtain an EVP_PKEY using whatever methods... */ EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2); 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_PKEY_set_alias_type(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-2020 The OpenSSL Project Authors. All Rights Reserved.</p> <p>Licensed under the OpenSSL license (the "License"). 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>