blob: 8a3a50170f24c633712f86be13f1e060438c115e [file] [log] [blame]
Gabor Mezeia3eecd22022-02-09 16:57:26 +01001/*
2 * Copyright The Mbed TLS Contributors
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef MBEDTLS_SSL_TLS13_INVASIVE_H
19#define MBEDTLS_SSL_TLS13_INVASIVE_H
20
21#include "common.h"
22
Gabor Mezei5d9a1fe2022-03-24 17:49:14 +010023#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
24
Gabor Mezeia3eecd22022-02-09 16:57:26 +010025#include "psa/crypto.h"
Gabor Mezeia3eecd22022-02-09 16:57:26 +010026
27#if defined(MBEDTLS_TEST_HOOKS)
28
Gabor Mezeib1f53972022-02-07 18:18:16 +010029/**
30 * \brief Take the input keying material \p ikm and extract from it a
31 * fixed-length pseudorandom key \p prk.
32 *
Gabor Mezei320d21c2022-02-09 17:25:43 +010033 * \param alg The HMAC algorithm to use
34 * (\c #PSA_ALG_HMAC( PSA_ALG_XXX ) value such that
35 * PSA_ALG_XXX is a hash algorithm and
36 * #PSA_ALG_IS_HMAC(\p alg) is true).
Gabor Mezeib1f53972022-02-07 18:18:16 +010037 * \param salt An optional salt value (a non-secret random value);
38 * if the salt is not provided, a string of all zeros
39 * of the length of the hash provided by \p alg is used
40 * as the salt.
41 * \param salt_len The length in bytes of the optional \p salt.
42 * \param ikm The input keying material.
43 * \param ikm_len The length in bytes of \p ikm.
44 * \param[out] prk A pseudorandom key of \p prk_len bytes.
45 * \param prk_size Size of the \p prk buffer in bytes.
46 * \param[out] prk_len On success, the length in bytes of the
47 * pseudorandom key in \p prk.
48 *
49 * \return 0 on success.
Gabor Mezeic5efb8e2022-02-08 13:15:45 +010050 * \return #PSA_ERROR_INVALID_ARGUMENT when the parameters are invalid.
Gabor Mezeib1f53972022-02-07 18:18:16 +010051 * \return An PSA_ERROR_* error for errors returned from the underlying
52 * PSA layer.
53 */
Gabor Mezei62bf0242022-02-07 18:12:07 +010054psa_status_t mbedtls_psa_hkdf_extract( psa_algorithm_t alg,
55 const unsigned char *salt, size_t salt_len,
56 const unsigned char *ikm, size_t ikm_len,
57 unsigned char *prk, size_t prk_size,
58 size_t *prk_len );
Gabor Mezei9f4bb312022-01-31 16:33:47 +010059
Gabor Mezeia3eecd22022-02-09 16:57:26 +010060/**
61 * \brief Expand the supplied \p prk into several additional pseudorandom
62 * keys, which is the output of the HKDF.
63 *
64 * \param alg The HMAC algorithm to use (\c #PSA_ALG_HMAC( PSA_ALG_XXX )
65 * value such that PSA_ALG_XXX is a hash algorithm and
66 * #PSA_ALG_IS_HMAC(\p alg) is true).
67 * \param prk A pseudorandom key of \p prk_len bytes. \p prk is
68 * usually the output from the HKDF extract step.
69 * \param prk_len The length in bytes of \p prk.
70 * \param info An optional context and application specific information
71 * string. This can be a zero-length string.
72 * \param info_len The length of \p info in bytes.
73 * \param okm The output keying material of \p okm_len bytes.
74 * \param okm_len The length of the output keying material in bytes. This
75 * must be less than or equal to
76 * 255 * #PSA_HASH_LENGTH( \p alg ) bytes.
77 *
78 * \return 0 on success.
79 * \return #PSA_ERROR_INVALID_ARGUMENT when the parameters are invalid.
80 * \return An PSA_ERROR_* error for errors returned from the underlying
81 * PSA layer.
82 */
83psa_status_t mbedtls_psa_hkdf_expand( psa_algorithm_t alg,
84 const unsigned char *prk, size_t prk_len,
85 const unsigned char *info, size_t info_len,
86 unsigned char *okm, size_t okm_len );
87
Gabor Mezeia3eecd22022-02-09 16:57:26 +010088#endif /* MBEDTLS_TEST_HOOKS */
89
Gabor Mezei5d9a1fe2022-03-24 17:49:14 +010090#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
91
Gabor Mezeia3eecd22022-02-09 16:57:26 +010092#endif /* MBEDTLS_SSL_TLS13_INVASIVE_H */