openssl-prebuild/linux_amd64/ssl/share/doc/openssl/html/man3/EVP_PKEY_set1_RSA.html

188 lines
9.0 KiB
HTML
Executable File

<?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>EVP_PKEY_set1_RSA</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="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#notes">NOTES</a></li>
<li><a href="#return_values">RETURN VALUES</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>EVP_PKEY_set1_RSA, EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH, EVP_PKEY_set1_EC_KEY,
EVP_PKEY_get1_RSA, EVP_PKEY_get1_DSA, EVP_PKEY_get1_DH, EVP_PKEY_get1_EC_KEY,
EVP_PKEY_get0_RSA, EVP_PKEY_get0_DSA, EVP_PKEY_get0_DH, EVP_PKEY_get0_EC_KEY,
EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH,
EVP_PKEY_assign_EC_KEY, EVP_PKEY_assign_POLY1305, EVP_PKEY_assign_SIPHASH,
EVP_PKEY_get0_hmac, EVP_PKEY_get0_poly1305, EVP_PKEY_get0_siphash,
EVP_PKEY_type, EVP_PKEY_id, EVP_PKEY_base_id, EVP_PKEY_set_alias_type,
EVP_PKEY_set1_engine, EVP_PKEY_get0_engine - EVP_PKEY assignment functions</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
#include &lt;openssl/evp.h&gt;</pre>
<pre>
int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key);
int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key);
int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key);
int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);</pre>
<pre>
RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);</pre>
<pre>
const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len);
const unsigned char *EVP_PKEY_get0_poly1305(const EVP_PKEY *pkey, size_t *len);
const unsigned char *EVP_PKEY_get0_siphash(const EVP_PKEY *pkey, size_t *len);
RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey);
DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey);
DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey);
EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey);</pre>
<pre>
int EVP_PKEY_assign_RSA(EVP_PKEY *pkey, RSA *key);
int EVP_PKEY_assign_DSA(EVP_PKEY *pkey, DSA *key);
int EVP_PKEY_assign_DH(EVP_PKEY *pkey, DH *key);
int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);
int EVP_PKEY_assign_POLY1305(EVP_PKEY *pkey, ASN1_OCTET_STRING *key);
int EVP_PKEY_assign_SIPHASH(EVP_PKEY *pkey, ASN1_OCTET_STRING *key);</pre>
<pre>
int EVP_PKEY_id(const EVP_PKEY *pkey);
int EVP_PKEY_base_id(const EVP_PKEY *pkey);
int EVP_PKEY_type(int type);
int EVP_PKEY_set_alias_type(EVP_PKEY *pkey, int type);</pre>
<pre>
ENGINE *EVP_PKEY_get0_engine(const EVP_PKEY *pkey);
int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *engine);</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
EVP_PKEY_set1_EC_KEY() set the key referenced by <strong>pkey</strong> to <strong>key</strong>.</p>
<p>EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
EVP_PKEY_get1_EC_KEY() return the referenced key in <strong>pkey</strong> or
<strong>NULL</strong> if the key is not of the correct type.</p>
<p>EVP_PKEY_get0_hmac(), EVP_PKEY_get0_poly1305(), EVP_PKEY_get0_siphash(),
EVP_PKEY_get0_RSA(), EVP_PKEY_get0_DSA(), EVP_PKEY_get0_DH()
and EVP_PKEY_get0_EC_KEY() also return the referenced key in <strong>pkey</strong> or <strong>NULL</strong>
if the key is not of the correct type but the reference count of the
returned key is <strong>not</strong> incremented and so must not be freed up after use.</p>
<p><code>EVP_PKEY_assign_RSA()</code>, <code>EVP_PKEY_assign_DSA()</code>, <code>EVP_PKEY_assign_DH()</code>,
<code>EVP_PKEY_assign_EC_KEY()</code>, EVP_PKEY_assign_POLY1305() and
<code>EVP_PKEY_assign_SIPHASH()</code> also set the referenced key to <strong>key</strong>
however these use the supplied <strong>key</strong> internally and so <strong>key</strong>
will be freed when the parent <strong>pkey</strong> is freed.</p>
<p><code>EVP_PKEY_base_id()</code> returns the type of <strong>pkey</strong>. For example
an RSA key will return <strong>EVP_PKEY_RSA</strong>.</p>
<p><code>EVP_PKEY_id()</code> returns the actual OID associated with <strong>pkey</strong>. Historically keys
using the same algorithm could use different OIDs. For example an RSA key could
use the OIDs corresponding to the NIDs <strong>NID_rsaEncryption</strong> (equivalent to
<strong>EVP_PKEY_RSA</strong>) or <strong>NID_rsa</strong> (equivalent to <strong>EVP_PKEY_RSA2</strong>). The use of
alternative non-standard OIDs is now rare so <strong>EVP_PKEY_RSA2</strong> et al are not
often seen in practice.</p>
<p><code>EVP_PKEY_type()</code> returns the underlying type of the NID <strong>type</strong>. For example
EVP_PKEY_type(EVP_PKEY_RSA2) will return <strong>EVP_PKEY_RSA</strong>.</p>
<p>EVP_PKEY_get0_engine() returns a reference to the ENGINE handling <strong>pkey</strong>.</p>
<p>EVP_PKEY_set1_engine() sets the ENGINE handling <strong>pkey</strong> to <strong>engine</strong>. It
must be called after the key algorithm and components are set up.
If <strong>engine</strong> does not include an <strong>EVP_PKEY_METHOD</strong> for <strong>pkey</strong> an
error occurs.</p>
<p><code>EVP_PKEY_set_alias_type()</code> allows modifying a EVP_PKEY to use a
different set of algorithms than the default.</p>
<p>
</p>
<hr />
<h1><a name="notes">NOTES</a></h1>
<p>In accordance with the OpenSSL naming convention the key obtained
from or assigned to the <strong>pkey</strong> using the <strong>1</strong> functions must be
freed as well as <strong>pkey</strong>.</p>
<p><code>EVP_PKEY_assign_RSA()</code>, <code>EVP_PKEY_assign_DSA()</code>, <code>EVP_PKEY_assign_DH()</code>,
<code>EVP_PKEY_assign_EC_KEY()</code>, EVP_PKEY_assign_POLY1305()
and <code>EVP_PKEY_assign_SIPHASH()</code> are implemented as macros.</p>
<p><code>EVP_PKEY_assign_EC_KEY()</code> looks at the curve name id to determine if
the passed <strong>EC_KEY</strong> is an <em>SM2(7)</em> key, and will set the <strong>EVP_PKEY</strong>
type to <strong>EVP_PKEY_SM2</strong> in that case, instead of <strong>EVP_PKEY_EC</strong>.</p>
<p>It's possible to switch back and forth between the types <strong>EVP_PKEY_EC</strong>
and <strong>EVP_PKEY_SM2</strong> with a call to <code>EVP_PKEY_set_alias_type()</code> on keys
assigned with this macro if it's desirable to do a normal EC
computations with the SM2 curve instead of the special SM2
computations, and vice versa.</p>
<p>Most applications wishing to know a key type will simply call
<code>EVP_PKEY_base_id()</code> and will not care about the actual type:
which will be identical in almost all cases.</p>
<p>Previous versions of this document suggested using EVP_PKEY_type(pkey-&gt;type)
to determine the type of a key. Since <strong>EVP_PKEY</strong> is now opaque this
is no longer possible: the equivalent is EVP_PKEY_base_id(pkey).</p>
<p>EVP_PKEY_set1_engine() is typically used by an ENGINE returning an HSM
key as part of its routine to load a private key.</p>
<p>
</p>
<hr />
<h1><a name="return_values">RETURN VALUES</a></h1>
<p>EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
EVP_PKEY_set1_EC_KEY() return 1 for success or 0 for failure.</p>
<p>EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
EVP_PKEY_get1_EC_KEY() return the referenced key or <strong>NULL</strong> if
an error occurred.</p>
<p><code>EVP_PKEY_assign_RSA()</code>, <code>EVP_PKEY_assign_DSA()</code>, <code>EVP_PKEY_assign_DH()</code>,
<code>EVP_PKEY_assign_EC_KEY()</code>, EVP_PKEY_assign_POLY1305()
and <code>EVP_PKEY_assign_SIPHASH()</code> return 1 for success and 0 for failure.</p>
<p><code>EVP_PKEY_base_id()</code>, <code>EVP_PKEY_id()</code> and <code>EVP_PKEY_type()</code> return a key
type or <strong>NID_undef</strong> (equivalently <strong>EVP_PKEY_NONE</strong>) on error.</p>
<p>EVP_PKEY_set1_engine() returns 1 for success and 0 for failure.</p>
<p><code>EVP_PKEY_set_alias_type()</code> returns 1 for success and 0 for error.</p>
<p>
</p>
<hr />
<h1><a name="examples">EXAMPLES</a></h1>
<p>After loading an ECC key, it is possible to convert it to using SM2
algorithms with EVP_PKEY_set_alias_type:</p>
<pre>
EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);</pre>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><em>EVP_PKEY_new(3)</em>, <em>SM2(7)</em></p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright 2002-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>