xref: /dflybsd-src/crypto/libressl/include/openssl/hkdf.h (revision 72c3367655e64985522b7a48ddfab613e869dc68)
1*72c33676SMaxim Ag /* $OpenBSD: hkdf.h,v 1.2 2018/04/03 13:33:53 tb Exp $ */
2*72c33676SMaxim Ag /* Copyright (c) 2014, Google Inc.
3*72c33676SMaxim Ag  *
4*72c33676SMaxim Ag  * Permission to use, copy, modify, and/or distribute this software for any
5*72c33676SMaxim Ag  * purpose with or without fee is hereby granted, provided that the above
6*72c33676SMaxim Ag  * copyright notice and this permission notice appear in all copies.
7*72c33676SMaxim Ag  *
8*72c33676SMaxim Ag  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*72c33676SMaxim Ag  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*72c33676SMaxim Ag  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11*72c33676SMaxim Ag  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*72c33676SMaxim Ag  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13*72c33676SMaxim Ag  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14*72c33676SMaxim Ag  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
15*72c33676SMaxim Ag 
16*72c33676SMaxim Ag #ifndef OPENSSL_HEADER_HKDF_H
17*72c33676SMaxim Ag #define OPENSSL_HEADER_HKDF_H
18*72c33676SMaxim Ag 
19*72c33676SMaxim Ag #include <openssl/evp.h>
20*72c33676SMaxim Ag 
21*72c33676SMaxim Ag #if defined(__cplusplus)
22*72c33676SMaxim Ag extern "C" {
23*72c33676SMaxim Ag #endif
24*72c33676SMaxim Ag 
25*72c33676SMaxim Ag /*
26*72c33676SMaxim Ag  * HKDF computes HKDF (as specified by RFC 5869) of initial keying
27*72c33676SMaxim Ag  * material |secret| with |salt| and |info| using |digest|, and
28*72c33676SMaxim Ag  * outputs |out_len| bytes to |out_key|. It returns one on success and
29*72c33676SMaxim Ag  * zero on error.
30*72c33676SMaxim Ag  *
31*72c33676SMaxim Ag  * HKDF is an Extract-and-Expand algorithm. It does not do any key
32*72c33676SMaxim Ag  * stretching, and as such, is not suited to be used alone to generate
33*72c33676SMaxim Ag  * a key from a password.
34*72c33676SMaxim Ag  */
35*72c33676SMaxim Ag 
36*72c33676SMaxim Ag int HKDF(uint8_t *out_key, size_t out_len, const struct env_md_st *digest,
37*72c33676SMaxim Ag     const uint8_t *secret, size_t secret_len, const uint8_t *salt,
38*72c33676SMaxim Ag     size_t salt_len, const uint8_t *info, size_t info_len);
39*72c33676SMaxim Ag 
40*72c33676SMaxim Ag /*
41*72c33676SMaxim Ag  * HKDF_extract computes a HKDF PRK (as specified by RFC 5869) from
42*72c33676SMaxim Ag  * initial keying material |secret| and salt |salt| using |digest|,
43*72c33676SMaxim Ag  * and outputs |out_len| bytes to |out_key|. The maximum output size
44*72c33676SMaxim Ag  * is |EVP_MAX_MD_SIZE|.  It returns one on success and zero on error.
45*72c33676SMaxim Ag  */
46*72c33676SMaxim Ag int HKDF_extract(uint8_t *out_key, size_t *out_len,
47*72c33676SMaxim Ag     const struct env_md_st *digest, const uint8_t *secret,
48*72c33676SMaxim Ag     size_t secret_len, const uint8_t *salt, size_t salt_len);
49*72c33676SMaxim Ag 
50*72c33676SMaxim Ag /*
51*72c33676SMaxim Ag  * HKDF_expand computes a HKDF OKM (as specified by RFC 5869) of
52*72c33676SMaxim Ag  * length |out_len| from the PRK |prk| and info |info| using |digest|,
53*72c33676SMaxim Ag  * and outputs the result to |out_key|. It returns one on success and
54*72c33676SMaxim Ag  * zero on error.
55*72c33676SMaxim Ag  */
56*72c33676SMaxim Ag int HKDF_expand(uint8_t *out_key, size_t out_len,
57*72c33676SMaxim Ag     const EVP_MD *digest, const uint8_t *prk, size_t prk_len,
58*72c33676SMaxim Ag     const uint8_t *info,  size_t info_len);
59*72c33676SMaxim Ag 
60*72c33676SMaxim Ag 
61*72c33676SMaxim Ag #if defined(__cplusplus)
62*72c33676SMaxim Ag }  /* extern C */
63*72c33676SMaxim Ag #endif
64*72c33676SMaxim Ag 
65*72c33676SMaxim Ag #endif  /* OPENSSL_HEADER_HKDF_H */
66