blob: c04eff741deabec29a8638e59abe55b74c53b872 [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 Mezei1e64f7a2022-03-21 16:57:44 +010023#if defined(MBEDTLS_USE_PSA_CRYPTO)
Gabor Mezeia3eecd22022-02-09 16:57:26 +010024#include "psa/crypto.h"
25#endif
26
27#if defined(MBEDTLS_TEST_HOOKS)
28
Gabor Mezei1e64f7a2022-03-21 16:57:44 +010029#if defined(MBEDTLS_USE_PSA_CRYPTO)
Gabor Mezeia3eecd22022-02-09 16:57:26 +010030
Gabor Mezeib1f53972022-02-07 18:18:16 +010031/**
32 * \brief Take the input keying material \p ikm and extract from it a
33 * fixed-length pseudorandom key \p prk.
34 *
Gabor Mezei320d21c2022-02-09 17:25:43 +010035 * \param alg The HMAC algorithm to use
36 * (\c #PSA_ALG_HMAC( PSA_ALG_XXX ) value such that
37 * PSA_ALG_XXX is a hash algorithm and
38 * #PSA_ALG_IS_HMAC(\p alg) is true).
Gabor Mezeib1f53972022-02-07 18:18:16 +010039 * \param salt An optional salt value (a non-secret random value);
40 * if the salt is not provided, a string of all zeros
41 * of the length of the hash provided by \p alg is used
42 * as the salt.
43 * \param salt_len The length in bytes of the optional \p salt.
44 * \param ikm The input keying material.
45 * \param ikm_len The length in bytes of \p ikm.
46 * \param[out] prk A pseudorandom key of \p prk_len bytes.
47 * \param prk_size Size of the \p prk buffer in bytes.
48 * \param[out] prk_len On success, the length in bytes of the
49 * pseudorandom key in \p prk.
50 *
51 * \return 0 on success.
Gabor Mezeic5efb8e2022-02-08 13:15:45 +010052 * \return #PSA_ERROR_INVALID_ARGUMENT when the parameters are invalid.
Gabor Mezeib1f53972022-02-07 18:18:16 +010053 * \return An PSA_ERROR_* error for errors returned from the underlying
54 * PSA layer.
55 */
Gabor Mezei62bf0242022-02-07 18:12:07 +010056psa_status_t mbedtls_psa_hkdf_extract( psa_algorithm_t alg,
57 const unsigned char *salt, size_t salt_len,
58 const unsigned char *ikm, size_t ikm_len,
59 unsigned char *prk, size_t prk_size,
60 size_t *prk_len );
Gabor Mezei9f4bb312022-01-31 16:33:47 +010061
Gabor Mezeia3eecd22022-02-09 16:57:26 +010062/**
63 * \brief Expand the supplied \p prk into several additional pseudorandom
64 * keys, which is the output of the HKDF.
65 *
66 * \param alg The HMAC algorithm to use (\c #PSA_ALG_HMAC( PSA_ALG_XXX )
67 * value such that PSA_ALG_XXX is a hash algorithm and
68 * #PSA_ALG_IS_HMAC(\p alg) is true).
69 * \param prk A pseudorandom key of \p prk_len bytes. \p prk is
70 * usually the output from the HKDF extract step.
71 * \param prk_len The length in bytes of \p prk.
72 * \param info An optional context and application specific information
73 * string. This can be a zero-length string.
74 * \param info_len The length of \p info in bytes.
75 * \param okm The output keying material of \p okm_len bytes.
76 * \param okm_len The length of the output keying material in bytes. This
77 * must be less than or equal to
78 * 255 * #PSA_HASH_LENGTH( \p alg ) bytes.
79 *
80 * \return 0 on success.
81 * \return #PSA_ERROR_INVALID_ARGUMENT when the parameters are invalid.
82 * \return An PSA_ERROR_* error for errors returned from the underlying
83 * PSA layer.
84 */
85psa_status_t mbedtls_psa_hkdf_expand( psa_algorithm_t alg,
86 const unsigned char *prk, size_t prk_len,
87 const unsigned char *info, size_t info_len,
88 unsigned char *okm, size_t okm_len );
89
Gabor Mezei1e64f7a2022-03-21 16:57:44 +010090#endif /* MBEDTLS_USE_PSA_CRYPTO */
Gabor Mezeia3eecd22022-02-09 16:57:26 +010091
92#endif /* MBEDTLS_TEST_HOOKS */
93
94#endif /* MBEDTLS_SSL_TLS13_INVASIVE_H */