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