blob: 419c34e45a61b281e5cb64a6723268b2893fa34f [file] [log] [blame]
Thomas Fossatieb010242016-07-17 08:51:22 +01001/**
2 * \file hkdf.h
3 *
4 * \brief The HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
5 *
6 */
7/*
8 * Copyright (C) 2016-2018, ARM Limited, All Rights Reserved
9 * SPDX-License-Identifier: Apache-2.0
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
12 * not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 *
23 * This file is part of mbed TLS (https://tls.mbed.org)
24 */
25#ifndef MBEDTLS_HKDF_H
26#define MBEDTLS_HKDF_H
27
28#include "md.h"
29
30/**
31 * \name HKDF Error codes
32 * \{
33 */
34#define MBEDTLS_ERR_HKDF_BAD_PARAM -0x5300 /**< Bad parameter */
35/* \} name */
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/**
42 * \brief HMAC-based Extract-and-Expand Key Derivation Function
43 *
44 * \param md a hash function; md.size denotes the length of the hash
45 * function output in bytes
46 * \param salt optional salt value (a non-secret random value);
47 * if not provided, it is set to a string of md.size zeros.
48 * \param salt_len length in bytes of the optional \p salt
49 * \param ikm input keying material
50 * \param ikm_len length in bytes of \p ikm
51 * \param info optional context and application specific information
52 * (can be a zero-length string)
53 * \param info_len length of \p info in bytes
54 * \param okm output keying material (of \p okm_len bytes)
55 * \param okm_len length of output keying material in octets
56 * (<= 255*md.size)
57 *
58 * \return 0 on success or one of the failure codes from mbedtls_hkdf_extract
59 * or mbedtls_hkdf_expand
60 */
61int mbedtls_hkdf( const mbedtls_md_info_t *md, const unsigned char *salt,
62 size_t salt_len, const unsigned char *ikm, size_t ikm_len,
63 const unsigned char *info, size_t info_len,
64 unsigned char *okm, size_t okm_len );
65
66/**
67 * \brief Take the input keying material \p ikm and extract from it a
68 * fixed-length pseudorandom key \p prk
69 *
70 * \param md a hash function; md.size denotes the length of the
71 * hash function output in bytes
72 * \param salt optional salt value (a non-secret random value);
73 * if not provided, it is set to a string of md.size
74 * zeros.
75 * \param salt_len length in bytes of the optional \p salt
76 * \param ikm input keying material
77 * \param ikm_len length in bytes of \p ikm
78 * \param[out] prk a pseudorandom key of md.size bytes
79 *
80 * \return 0 on success, MBEDTLS_ERR_HKDF_BAD_PARAM or one of mbedtls_md_*
81 * error codes on failure
82 */
83int mbedtls_hkdf_extract( const mbedtls_md_info_t *md,
84 const unsigned char *salt, size_t salt_len,
85 const unsigned char *ikm, size_t ikm_len,
86 unsigned char *prk );
87
88/**
89 * \brief Expand the supplied \p prk into several additional pseudorandom keys
90 * (the output of the KDF).
91 *
92 * \param md a hash function; md.size denotes the length of the hash
93 * function output in bytes
94 * \param prk a pseudorandom key of at least md.size bytes; usually,
95 * the output from the extract step
96 * \param prk_len length of \p prk in bytes
97 * \param info optional context and application specific information
98 * (can be a zero-length string)
99 * \param info_len length of \p info in bytes
100 * \param okm output keying material (of \p okm_len bytes)
101 * \param okm_len length of output keying material in octets
102 * (<= 255*md.size)
103 *
104 * \return 0 on success, MBEDTLS_ERR_HKDF_BAD_PARAM or a failure code from the
105 * mbedtls_md_* family
106 */
107int mbedtls_hkdf_expand( const mbedtls_md_info_t *md, const unsigned char *prk,
108 size_t prk_len, const unsigned char *info,
109 size_t info_len, unsigned char *okm, size_t okm_len );
110
111#ifdef __cplusplus
112}
113#endif
114
115#endif /* hkdf.h */