blob: c9256d6b993ee4745b516f343023680f4b83da7c [file] [log] [blame]
Manuel Pégourié-Gonnard045f0942020-07-02 11:34:02 +02001/**
2 * \file ssl_invasive.h
3 *
4 * \brief SSL module: interfaces for invasive testing only.
5 *
6 * The interfaces in this file are intended for testing purposes only.
7 * They SHOULD NOT be made available in library integrations except when
8 * building the library for testing.
9 */
10/*
Dan Handley50118142020-08-20 11:20:12 +010011 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard045f0942020-07-02 11:34:02 +020012 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License"); you may
15 * not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
Manuel Pégourié-Gonnard045f0942020-07-02 11:34:02 +020025 */
26#ifndef MBEDTLS_SSL_INVASIVE_H
27#define MBEDTLS_SSL_INVASIVE_H
28
29#include "common.h"
30#include "mbedtls/md.h"
31
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020032#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC)
Manuel Pégourié-Gonnard045f0942020-07-02 11:34:02 +020033/** \brief Compute the HMAC of variable-length data with constant flow.
34 *
35 * This function computes the HMAC of the concatenation of \p add_data and \p
36 * data, and does with a code flow and memory access pattern that does not
37 * depend on \p data_len_secret, but only on \p min_data_len and \p
38 * max_data_len. In particular, this function always reads exactly \p
39 * max_data_len bytes from \p data.
40 *
41 * \param ctx The HMAC context. It must have keys configured
Manuel Pégourié-Gonnardbaccf802020-07-22 10:37:27 +020042 * with mbedtls_md_hmac_starts() and use one of the
43 * following hashes: SHA-384, SHA-256, SHA-1 or MD-5.
44 * It is reset using mbedtls_md_hmac_reset() after
45 * the computation is complete to prepare for the
46 * next computation.
Manuel Pégourié-Gonnard045f0942020-07-02 11:34:02 +020047 * \param add_data The additional data prepended to \p data. This
48 * must point to a readable buffer of \p add_data_len
49 * bytes.
50 * \param add_data_len The length of \p add_data in bytes.
51 * \param data The data appended to \p add_data. This must point
52 * to a readable buffer of \p max_data_len bytes.
53 * \param data_len_secret The length of the data to process in \p data.
54 * This must be no less than \p min_data_len and no
Manuel Pégourié-Gonnard390fb4f2020-07-24 11:08:40 +020055 * greater than \p max_data_len.
Manuel Pégourié-Gonnard045f0942020-07-02 11:34:02 +020056 * \param min_data_len The minimal length of \p data in bytes.
57 * \param max_data_len The maximal length of \p data in bytes.
58 * \param output The HMAC will be written here. This must point to
Manuel Pégourié-Gonnard390fb4f2020-07-24 11:08:40 +020059 * a writable buffer of sufficient size to hold the
Manuel Pégourié-Gonnard045f0942020-07-02 11:34:02 +020060 * HMAC value.
61 *
62 * \retval 0
63 * Success.
64 * \retval MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED
65 * The hardware accelerator failed.
66 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020067int mbedtls_ssl_cf_hmac(mbedtls_md_context_t *ctx,
68 const unsigned char *add_data,
69 size_t add_data_len,
70 const unsigned char *data,
71 size_t data_len_secret,
72 size_t min_data_len,
73 size_t max_data_len,
74 unsigned char *output);
Manuel Pégourié-Gonnard7fe2c5f2020-08-18 12:02:54 +020075
76/** \brief Copy data from a secret position with constant flow.
77 *
78 * This function copies \p len bytes from \p src_base + \p offset_secret to \p
79 * dst, with a code flow and memory access pattern that does not depend on \p
80 * offset_secret, but only on \p offset_min, \p offset_max and \p len.
81 *
82 * \param dst The destination buffer. This must point to a writable
83 * buffer of at least \p len bytes.
84 * \param src_base The base of the source buffer. This must point to a
85 * readable buffer of at least \p offset_max + \p len
86 * bytes.
87 * \param offset_secret The offset in the source buffer from which to copy.
88 * This must be no less than \p offset_min and no greater
89 * than \p offset_max.
90 * \param offset_min The minimal value of \p offset_secret.
91 * \param offset_max The maximal value of \p offset_secret.
92 * \param len The number of bytes to copy.
93 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020094void mbedtls_ssl_cf_memcpy_offset(unsigned char *dst,
95 const unsigned char *src_base,
96 size_t offset_secret,
97 size_t offset_min,
98 size_t offset_max,
99 size_t len);
Manuel Pégourié-Gonnarded0e8642020-07-21 11:20:30 +0200100#endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */
Manuel Pégourié-Gonnard045f0942020-07-02 11:34:02 +0200101
102#endif /* MBEDTLS_SSL_INVASIVE_H */