201 lines
8.0 KiB
HTML
Executable File
201 lines
8.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_CTX_set_hkdf_md</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="#string_ctrls">STRING CTRLS</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="#conforming_to">CONFORMING TO</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_CTX_set_hkdf_md, EVP_PKEY_CTX_set1_hkdf_salt,
|
|
EVP_PKEY_CTX_set1_hkdf_key, EVP_PKEY_CTX_add1_hkdf_info,
|
|
EVP_PKEY_CTX_hkdf_mode -
|
|
HMAC-based Extract-and-Expand key derivation algorithm</p>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="synopsis">SYNOPSIS</a></h1>
|
|
<pre>
|
|
#include <openssl/kdf.h></pre>
|
|
<pre>
|
|
int EVP_PKEY_CTX_hkdf_mode(EVP_PKEY_CTX *pctx, int mode);</pre>
|
|
<pre>
|
|
int EVP_PKEY_CTX_set_hkdf_md(EVP_PKEY_CTX *pctx, const EVP_MD *md);</pre>
|
|
<pre>
|
|
int EVP_PKEY_CTX_set1_hkdf_salt(EVP_PKEY_CTX *pctx, unsigned char *salt,
|
|
int saltlen);</pre>
|
|
<pre>
|
|
int EVP_PKEY_CTX_set1_hkdf_key(EVP_PKEY_CTX *pctx, unsigned char *key,
|
|
int keylen);</pre>
|
|
<pre>
|
|
int EVP_PKEY_CTX_add1_hkdf_info(EVP_PKEY_CTX *pctx, unsigned char *info,
|
|
int infolen);</pre>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="description">DESCRIPTION</a></h1>
|
|
<p>The EVP_PKEY_HKDF algorithm implements the HKDF key derivation function.
|
|
HKDF follows the "extract-then-expand" paradigm, where the KDF logically
|
|
consists of two modules. The first stage takes the input keying material
|
|
and "extracts" from it a fixed-length pseudorandom key K. The second stage
|
|
"expands" the key K into several additional pseudorandom keys (the output
|
|
of the KDF).</p>
|
|
<p><code>EVP_PKEY_CTX_hkdf_mode()</code> sets the mode for the HKDF operation. There are three
|
|
modes that are currently defined:</p>
|
|
<dl>
|
|
<dt><strong><a name="evp_pkey_hkdef_mode_extract_and_expand" class="item">EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND</a></strong></dt>
|
|
|
|
<dd>
|
|
<p>This is the default mode. Calling <em>EVP_PKEY_derive(3)</em> on an EVP_PKEY_CTX set
|
|
up for HKDF will perform an extract followed by an expand operation in one go.
|
|
The derived key returned will be the result after the expand operation. The
|
|
intermediate fixed-length pseudorandom key K is not returned.</p>
|
|
<p>In this mode the digest, key, salt and info values must be set before a key is
|
|
derived or an error occurs.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_pkey_hkdef_mode_extract_only" class="item">EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY</a></strong></dt>
|
|
|
|
<dd>
|
|
<p>In this mode calling <em>EVP_PKEY_derive(3)</em> will just perform the extract
|
|
operation. The value returned will be the intermediate fixed-length pseudorandom
|
|
key K.</p>
|
|
<p>The digest, key and salt values must be set before a key is derived or an
|
|
error occurs.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_pkey_hkdef_mode_expand_only" class="item">EVP_PKEY_HKDEF_MODE_EXPAND_ONLY</a></strong></dt>
|
|
|
|
<dd>
|
|
<p>In this mode calling <em>EVP_PKEY_derive(3)</em> will just perform the expand
|
|
operation. The input key should be set to the intermediate fixed-length
|
|
pseudorandom key K returned from a previous extract operation.</p>
|
|
<p>The digest, key and info values must be set before a key is derived or an
|
|
error occurs.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><code>EVP_PKEY_CTX_set_hkdf_md()</code> sets the message digest associated with the HKDF.</p>
|
|
<p>EVP_PKEY_CTX_set1_hkdf_salt() sets the salt to <strong>saltlen</strong> bytes of the
|
|
buffer <strong>salt</strong>. Any existing value is replaced.</p>
|
|
<p>EVP_PKEY_CTX_set1_hkdf_key() sets the key to <strong>keylen</strong> bytes of the buffer
|
|
<strong>key</strong>. Any existing value is replaced.</p>
|
|
<p>EVP_PKEY_CTX_add1_hkdf_info() sets the info value to <strong>infolen</strong> bytes of the
|
|
buffer <strong>info</strong>. If a value is already set, it is appended to the existing
|
|
value.</p>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="string_ctrls">STRING CTRLS</a></h1>
|
|
<p>HKDF also supports string based control operations via
|
|
<em>EVP_PKEY_CTX_ctrl_str(3)</em>.
|
|
The <strong>type</strong> parameter "md" uses the supplied <strong>value</strong> as the name of the digest
|
|
algorithm to use.
|
|
The <strong>type</strong> parameter "mode" uses the values "EXTRACT_AND_EXPAND",
|
|
"EXTRACT_ONLY" and "EXPAND_ONLY" to determine the mode to use.
|
|
The <strong>type</strong> parameters "salt", "key" and "info" use the supplied <strong>value</strong>
|
|
parameter as a <strong>seed</strong>, <strong>key</strong> or <strong>info</strong> value.
|
|
The names "hexsalt", "hexkey" and "hexinfo" are similar except they take a hex
|
|
string which is converted to binary.</p>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="notes">NOTES</a></h1>
|
|
<p>All these functions are implemented as macros.</p>
|
|
<p>A context for HKDF can be obtained by calling:</p>
|
|
<pre>
|
|
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);</pre>
|
|
<p>The total length of the info buffer cannot exceed 1024 bytes in length: this
|
|
should be more than enough for any normal use of HKDF.</p>
|
|
<p>The output length of an HKDF expand operation is specified via the length
|
|
parameter to the <em>EVP_PKEY_derive(3)</em> function.
|
|
Since the HKDF output length is variable, passing a <strong>NULL</strong> buffer as a means
|
|
to obtain the requisite length is not meaningful with HKDF in any mode that
|
|
performs an expand operation. Instead, the caller must allocate a buffer of the
|
|
desired length, and pass that buffer to <em>EVP_PKEY_derive(3)</em> along with (a
|
|
pointer initialized to) the desired length. Passing a <strong>NULL</strong> buffer to obtain
|
|
the length is allowed when using EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY.</p>
|
|
<p>Optimised versions of HKDF can be implemented in an ENGINE.</p>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="return_values">RETURN VALUES</a></h1>
|
|
<p>All these functions return 1 for success and 0 or a negative value for failure.
|
|
In particular a return value of -2 indicates the operation is not supported by
|
|
the public key algorithm.</p>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="examples">EXAMPLES</a></h1>
|
|
<p>This example derives 10 bytes using SHA-256 with the secret key "secret",
|
|
salt value "salt" and info value "label":</p>
|
|
<pre>
|
|
EVP_PKEY_CTX *pctx;
|
|
unsigned char out[10];
|
|
size_t outlen = sizeof(out);
|
|
pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);</pre>
|
|
<pre>
|
|
if (EVP_PKEY_derive_init(pctx) <= 0)
|
|
/* Error */
|
|
if (EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()) <= 0)
|
|
/* Error */
|
|
if (EVP_PKEY_CTX_set1_hkdf_salt(pctx, "salt", 4) <= 0)
|
|
/* Error */
|
|
if (EVP_PKEY_CTX_set1_hkdf_key(pctx, "secret", 6) <= 0)
|
|
/* Error */
|
|
if (EVP_PKEY_CTX_add1_hkdf_info(pctx, "label", 5) <= 0)
|
|
/* Error */
|
|
if (EVP_PKEY_derive(pctx, out, &outlen) <= 0)
|
|
/* Error */</pre>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="conforming_to">CONFORMING TO</a></h1>
|
|
<p>RFC 5869</p>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="see_also">SEE ALSO</a></h1>
|
|
<p><em>EVP_PKEY_CTX_new(3)</em>,
|
|
<em>EVP_PKEY_CTX_ctrl_str(3)</em>,
|
|
<em>EVP_PKEY_derive(3)</em></p>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="copyright">COPYRIGHT</a></h1>
|
|
<p>Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.</p>
|
|
<p>Licensed under the Apache License 2.0 (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>
|