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