| Gabor Mezei | a3eecd2 | 2022-02-09 16:57:26 +0100 | [diff] [blame] | 1 | /* | 
|  | 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 Mezei | 5d9a1fe | 2022-03-24 17:49:14 +0100 | [diff] [blame] | 23 | #if defined(MBEDTLS_SSL_PROTO_TLS1_3) | 
|  | 24 |  | 
| Gabor Mezei | a3eecd2 | 2022-02-09 16:57:26 +0100 | [diff] [blame] | 25 | #include "psa/crypto.h" | 
| Gabor Mezei | a3eecd2 | 2022-02-09 16:57:26 +0100 | [diff] [blame] | 26 |  | 
|  | 27 | #if defined(MBEDTLS_TEST_HOOKS) | 
|  | 28 |  | 
| Gabor Mezei | b1f5397 | 2022-02-07 18:18:16 +0100 | [diff] [blame] | 29 | /** | 
|  | 30 | *  \brief  Take the input keying material \p ikm and extract from it a | 
|  | 31 | *          fixed-length pseudorandom key \p prk. | 
|  | 32 | * | 
| Gabor Mezei | ed6d658 | 2022-03-26 17:28:06 +0100 | [diff] [blame] | 33 | *  \param       hash_alg  Hash algorithm to use. | 
| Gabor Mezei | b1f5397 | 2022-02-07 18:18:16 +0100 | [diff] [blame] | 34 | *  \param       salt      An optional salt value (a non-secret random value); | 
|  | 35 | *                         if the salt is not provided, a string of all zeros | 
|  | 36 | *                         of the length of the hash provided by \p alg is used | 
|  | 37 | *                         as the salt. | 
|  | 38 | *  \param       salt_len  The length in bytes of the optional \p salt. | 
|  | 39 | *  \param       ikm       The input keying material. | 
|  | 40 | *  \param       ikm_len   The length in bytes of \p ikm. | 
|  | 41 | *  \param[out]  prk       A pseudorandom key of \p prk_len bytes. | 
|  | 42 | *  \param       prk_size  Size of the \p prk buffer in bytes. | 
|  | 43 | *  \param[out]  prk_len   On success, the length in bytes of the | 
|  | 44 | *                         pseudorandom key in \p prk. | 
|  | 45 | * | 
|  | 46 | *  \return 0 on success. | 
| Gabor Mezei | c5efb8e | 2022-02-08 13:15:45 +0100 | [diff] [blame] | 47 | *  \return #PSA_ERROR_INVALID_ARGUMENT when the parameters are invalid. | 
| Gabor Mezei | b1f5397 | 2022-02-07 18:18:16 +0100 | [diff] [blame] | 48 | *  \return An PSA_ERROR_* error for errors returned from the underlying | 
|  | 49 | *          PSA layer. | 
|  | 50 | */ | 
| Gabor Mezei | ed6d658 | 2022-03-26 17:28:06 +0100 | [diff] [blame] | 51 | psa_status_t mbedtls_psa_hkdf_extract( psa_algorithm_t hash_alg, | 
| Gabor Mezei | 62bf024 | 2022-02-07 18:12:07 +0100 | [diff] [blame] | 52 | const unsigned char *salt, size_t salt_len, | 
|  | 53 | const unsigned char *ikm, size_t ikm_len, | 
|  | 54 | unsigned char *prk, size_t prk_size, | 
|  | 55 | size_t *prk_len ); | 
| Gabor Mezei | 9f4bb31 | 2022-01-31 16:33:47 +0100 | [diff] [blame] | 56 |  | 
| Gabor Mezei | a3eecd2 | 2022-02-09 16:57:26 +0100 | [diff] [blame] | 57 | /** | 
|  | 58 | *  \brief  Expand the supplied \p prk into several additional pseudorandom | 
|  | 59 | *          keys, which is the output of the HKDF. | 
|  | 60 | * | 
| Gabor Mezei | ed6d658 | 2022-03-26 17:28:06 +0100 | [diff] [blame] | 61 | *  \param  hash_alg  Hash algorithm to use. | 
| Gabor Mezei | a3eecd2 | 2022-02-09 16:57:26 +0100 | [diff] [blame] | 62 | *  \param  prk       A pseudorandom key of \p prk_len bytes. \p prk is | 
|  | 63 | *                    usually the output from the HKDF extract step. | 
|  | 64 | *  \param  prk_len   The length in bytes of \p prk. | 
|  | 65 | *  \param  info      An optional context and application specific information | 
|  | 66 | *                    string. This can be a zero-length string. | 
|  | 67 | *  \param  info_len  The length of \p info in bytes. | 
|  | 68 | *  \param  okm       The output keying material of \p okm_len bytes. | 
|  | 69 | *  \param  okm_len   The length of the output keying material in bytes. This | 
|  | 70 | *                    must be less than or equal to | 
|  | 71 | *                    255 * #PSA_HASH_LENGTH( \p alg ) bytes. | 
|  | 72 | * | 
|  | 73 | *  \return 0 on success. | 
|  | 74 | *  \return #PSA_ERROR_INVALID_ARGUMENT when the parameters are invalid. | 
|  | 75 | *  \return An PSA_ERROR_* error for errors returned from the underlying | 
|  | 76 | *          PSA layer. | 
|  | 77 | */ | 
| Gabor Mezei | ed6d658 | 2022-03-26 17:28:06 +0100 | [diff] [blame] | 78 | psa_status_t mbedtls_psa_hkdf_expand( psa_algorithm_t hash_alg, | 
| Gabor Mezei | a3eecd2 | 2022-02-09 16:57:26 +0100 | [diff] [blame] | 79 | const unsigned char *prk, size_t prk_len, | 
|  | 80 | const unsigned char *info, size_t info_len, | 
|  | 81 | unsigned char *okm, size_t okm_len ); | 
|  | 82 |  | 
| Gabor Mezei | a3eecd2 | 2022-02-09 16:57:26 +0100 | [diff] [blame] | 83 | #endif /* MBEDTLS_TEST_HOOKS */ | 
|  | 84 |  | 
| Gabor Mezei | 5d9a1fe | 2022-03-24 17:49:14 +0100 | [diff] [blame] | 85 | #endif /* MBEDTLS_SSL_PROTO_TLS1_3 */ | 
|  | 86 |  | 
| Gabor Mezei | a3eecd2 | 2022-02-09 16:57:26 +0100 | [diff] [blame] | 87 | #endif /* MBEDTLS_SSL_TLS13_INVASIVE_H */ |