blob: 1ea33f9b169513ca8e91a28d2c65f7e6677fa57e [file] [log] [blame]
Hanno Becker108fc842021-01-12 06:39:43 +00001/*
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 * This file is part of mbed TLS (https://tls.mbed.org)
18 */
19
20/**
21 * \file common.h
22 *
23 * \brief Common functions and macros used by MPS
24 */
25
26#ifndef MBEDTLS_MPS_COMMON_H
27#define MBEDTLS_MPS_COMMON_H
28
Hanno Beckerd2f9f532021-01-12 07:11:11 +000029#include <stdio.h>
30
Hanno Becker6ed183c2021-01-12 06:42:16 +000031/**
32 * \name SECTION: MPS Configuration
33 *
34 * \{
35 */
36
37/*! This flag enables/disables assertions on the internal state of MPS.
38 *
39 * Assertions are sanity checks that should never trigger when MPS
40 * is used within the bounds of its API and preconditions.
41 *
42 * Enabling this increases security by limiting the scope of
43 * potential bugs, but comes at the cost of increased code size.
44 *
45 * Note: So far, there is no guiding principle as to what
46 * expected conditions merit an assertion, and which don't.
47 *
48 * Comment this to disable assertions.
49 */
50#define MBEDTLS_MPS_ENABLE_ASSERTIONS
51
Hanno Becker1ae9f752021-01-12 06:43:17 +000052/*! This flag controls whether tracing for MPS should be enabled. */
Hanno Beckerc809ff62021-01-12 06:54:04 +000053//#define MBEDTLS_MPS_TRACE
Hanno Becker1ae9f752021-01-12 06:43:17 +000054
Hanno Becker6ed183c2021-01-12 06:42:16 +000055/* \} name SECTION: MPS Configuration */
Hanno Becker108fc842021-01-12 06:39:43 +000056
Hanno Beckerd2f9f532021-01-12 07:11:11 +000057/**
58 * \name SECTION: Common types
59 *
60 * Various common types used throughout MPS.
61 * \{
62 */
63
64/** \brief The type of buffer sizes and offsets used in MPS structures.
65 *
66 * This is an unsigned integer type that should be large enough to
67 * hold the length of any buffer resp. message processed by MPS.
68 *
69 * The reason to pick a value as small as possible here is
70 * to reduce the size of MPS structures.
71 *
72 * \warning Care has to be taken when using a narrower type
73 * than ::mbedtls_mps_size_t here because of
74 * potential truncation during conversion.
75 *
76 * \warning Handshake messages in TLS may be up to 2^24 ~ 16Mb in size.
77 * If mbedtls_mps_[opt_]stored_size_t is smaller than that, the
78 * maximum handshake message is restricted accordingly.
79 *
80 * For now, we use the default type of size_t throughout, and the use of
81 * smaller types or different types for ::mbedtls_mps_size_t and
82 * ::mbedtls_mps_stored_size_t is not yet supported.
83 *
84 */
85typedef size_t mbedtls_mps_stored_size_t;
86#define MBEDTLS_MPS_SIZE_MAX ( (mbedtls_mps_size_t) -1 )
87
88/** \brief The type of buffer sizes and offsets used in the MPS API
89 * and implementation.
90 *
91 * This must be at least as wide as ::mbedtls_stored_size_t but
92 * may be chosen to be strictly larger if more suitable for the
93 * target architecture.
94 *
95 * For example, in a test build for ARM Thumb, using uint_fast16_t
96 * instead of uint16_t reduced the code size from 1060 Byte to 962 Byte,
97 * so almost 10%.
98 */
99typedef size_t mbedtls_mps_size_t;
100
101#if (mbedtls_mps_size_t) -1 > (mbedtls_mps_stored_size_t) -1
102#error "Misconfiguration of mbedtls_mps_size_t and mbedtls_mps_stored_size_t."
103#endif
104
105/* \} SECTION: Common types */
106
107
Hanno Becker108fc842021-01-12 06:39:43 +0000108#endif /* MBEDTLS_MPS_COMMON_H */