Blame doc/man3/EVP_PKEY_CTX_set_hkdf_md.pod

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