/*1* Copyright (c) 2016 Thomas Pornin <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining4* a copy of this software and associated documentation files (the5* "Software"), to deal in the Software without restriction, including6* without limitation the rights to use, copy, modify, merge, publish,7* distribute, sublicense, and/or sell copies of the Software, and to8* permit persons to whom the Software is furnished to do so, subject to9* the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*/2324#ifndef BR_BEARSSL_PRF_H__25#define BR_BEARSSL_PRF_H__2627#include <stddef.h>28#include <stdint.h>2930#ifdef __cplusplus31extern "C" {32#endif3334/** \file bearssl_prf.h35*36* # The TLS PRF37*38* The "PRF" is the pseudorandom function used internally during the39* SSL/TLS handshake, notably to expand negotiated shared secrets into40* the symmetric encryption keys that will be used to process the41* application data.42*43* TLS 1.0 and 1.1 define a PRF that is based on both MD5 and SHA-1. This44* is implemented by the `br_tls10_prf()` function.45*46* TLS 1.2 redefines the PRF, using an explicit hash function. The47* `br_tls12_sha256_prf()` and `br_tls12_sha384_prf()` functions apply that48* PRF with, respectively, SHA-256 and SHA-384. Most standard cipher suites49* rely on the SHA-256 based PRF, but some use SHA-384.50*51* The PRF always uses as input three parameters: a "secret" (some52* bytes), a "label" (ASCII string), and a "seed" (again some bytes). An53* arbitrary output length can be produced. The "seed" is provided as an54* arbitrary number of binary chunks, that gets internally concatenated.55*/5657/**58* \brief Type for a seed chunk.59*60* Each chunk may have an arbitrary length, and may be empty (no byte at61* all). If the chunk length is zero, then the pointer to the chunk data62* may be `NULL`.63*/64typedef struct {65/**66* \brief Pointer to the chunk data.67*/68const void *data;6970/**71* \brief Chunk length (in bytes).72*/73size_t len;74} br_tls_prf_seed_chunk;7576/**77* \brief PRF implementation for TLS 1.0 and 1.1.78*79* This PRF is the one specified by TLS 1.0 and 1.1. It internally uses80* MD5 and SHA-1.81*82* \param dst destination buffer.83* \param len output length (in bytes).84* \param secret secret value (key) for this computation.85* \param secret_len length of "secret" (in bytes).86* \param label PRF label (zero-terminated ASCII string).87* \param seed_num number of seed chunks.88* \param seed seed chnks for this computation (usually non-secret).89*/90void br_tls10_prf(void *dst, size_t len,91const void *secret, size_t secret_len, const char *label,92size_t seed_num, const br_tls_prf_seed_chunk *seed);9394/**95* \brief PRF implementation for TLS 1.2, with SHA-256.96*97* This PRF is the one specified by TLS 1.2, when the underlying hash98* function is SHA-256.99*100* \param dst destination buffer.101* \param len output length (in bytes).102* \param secret secret value (key) for this computation.103* \param secret_len length of "secret" (in bytes).104* \param label PRF label (zero-terminated ASCII string).105* \param seed_num number of seed chunks.106* \param seed seed chnks for this computation (usually non-secret).107*/108void br_tls12_sha256_prf(void *dst, size_t len,109const void *secret, size_t secret_len, const char *label,110size_t seed_num, const br_tls_prf_seed_chunk *seed);111112/**113* \brief PRF implementation for TLS 1.2, with SHA-384.114*115* This PRF is the one specified by TLS 1.2, when the underlying hash116* function is SHA-384.117*118* \param dst destination buffer.119* \param len output length (in bytes).120* \param secret secret value (key) for this computation.121* \param secret_len length of "secret" (in bytes).122* \param label PRF label (zero-terminated ASCII string).123* \param seed_num number of seed chunks.124* \param seed seed chnks for this computation (usually non-secret).125*/126void br_tls12_sha384_prf(void *dst, size_t len,127const void *secret, size_t secret_len, const char *label,128size_t seed_num, const br_tls_prf_seed_chunk *seed);129130/**131* brief A convenient type name for a PRF implementation.132*133* \param dst destination buffer.134* \param len output length (in bytes).135* \param secret secret value (key) for this computation.136* \param secret_len length of "secret" (in bytes).137* \param label PRF label (zero-terminated ASCII string).138* \param seed_num number of seed chunks.139* \param seed seed chnks for this computation (usually non-secret).140*/141typedef void (*br_tls_prf_impl)(void *dst, size_t len,142const void *secret, size_t secret_len, const char *label,143size_t seed_num, const br_tls_prf_seed_chunk *seed);144145#ifdef __cplusplus146}147#endif148149#endif150151152