Mbed TLS v3.5.0
crypto_builtin_composites.h
Go to the documentation of this file.
1/*
2 * Context structure declaration of the Mbed TLS software-based PSA drivers
3 * called through the PSA Crypto driver dispatch layer.
4 * This file contains the context structures of those algorithms which need to
5 * rely on other algorithms, i.e. are 'composite' algorithms.
6 *
7 * \note This file may not be included directly. Applications must
8 * include psa/crypto.h.
9 *
10 * \note This header and its content are not part of the Mbed TLS API and
11 * applications must not depend on it. Its main purpose is to define the
12 * multi-part state objects of the Mbed TLS software-based PSA drivers. The
13 * definitions of these objects are then used by crypto_struct.h to define the
14 * implementation-defined types of PSA multi-part state objects.
15 */
16/*
17 * Copyright The Mbed TLS Contributors
18 * SPDX-License-Identifier: Apache-2.0
19 *
20 * Licensed under the Apache License, Version 2.0 (the "License"); you may
21 * not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 * http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
28 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
31 */
32
33#ifndef PSA_CRYPTO_BUILTIN_COMPOSITES_H
34#define PSA_CRYPTO_BUILTIN_COMPOSITES_H
36
38
39#include "mbedtls/cmac.h"
40#include "mbedtls/gcm.h"
41#include "mbedtls/ccm.h"
42#include "mbedtls/chachapoly.h"
43
44/*
45 * MAC multi-part operation definitions.
46 */
47#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || \
48 defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
49#define MBEDTLS_PSA_BUILTIN_MAC
50#endif
51
52#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST)
53typedef struct {
57 struct psa_hash_operation_s hash_ctx;
61
62#define MBEDTLS_PSA_HMAC_OPERATION_INIT { 0, PSA_HASH_OPERATION_INIT, { 0 } }
63#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
64
65typedef struct {
67 union {
68 unsigned MBEDTLS_PRIVATE(dummy); /* Make the union non-empty even with no supported algorithms. */
69#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST)
71#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
72#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || defined(PSA_CRYPTO_DRIVER_TEST)
74#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
77
78#define MBEDTLS_PSA_MAC_OPERATION_INIT { 0, { 0 } }
79
80#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM) || \
81 defined(MBEDTLS_PSA_BUILTIN_ALG_CCM) || \
82 defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
83#define MBEDTLS_PSA_BUILTIN_AEAD 1
84#endif
85
86/* Context structure for the Mbed TLS AEAD implementation. */
87typedef struct {
90
91 unsigned int MBEDTLS_PRIVATE(is_encrypt) : 1;
92
93 uint8_t MBEDTLS_PRIVATE(tag_length);
94
95 union {
96 unsigned dummy; /* Enable easier initializing of the union. */
97#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
99#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
100#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
102#endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
103#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
105#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
106
107 } ctx;
108
110
111#define MBEDTLS_PSA_AEAD_OPERATION_INIT { 0, 0, 0, 0, { 0 } }
112
113#include "mbedtls/ecdsa.h"
114
115/* Context structure for the Mbed TLS interruptible sign hash implementation. */
116typedef struct {
117#if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
118 defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \
119 defined(MBEDTLS_ECP_RESTARTABLE)
122
123 uint32_t MBEDTLS_PRIVATE(num_ops);
124
125 size_t MBEDTLS_PRIVATE(coordinate_bytes);
129 size_t MBEDTLS_PRIVATE(hash_length);
130
131#else
132 /* Make the struct non-empty if algs not supported. */
133 unsigned MBEDTLS_PRIVATE(dummy);
134
135#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) ||
136 * defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) &&
137 * defined( MBEDTLS_ECP_RESTARTABLE ) */
139
140#if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
141 defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \
142 defined(MBEDTLS_ECP_RESTARTABLE)
143#define MBEDTLS_PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { { 0 }, { 0 }, 0, 0, 0, 0, 0, 0 }
144#else
145#define MBEDTLS_PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 }
146#endif
147
148/* Context structure for the Mbed TLS interruptible verify hash
149 * implementation.*/
150typedef struct {
151#if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
152 defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \
153 defined(MBEDTLS_ECP_RESTARTABLE)
154
157
158 uint32_t MBEDTLS_PRIVATE(num_ops);
159
161 size_t MBEDTLS_PRIVATE(hash_length);
162
165
166#else
167 /* Make the struct non-empty if algs not supported. */
168 unsigned MBEDTLS_PRIVATE(dummy);
169
170#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) ||
171 * defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) &&
172 * defined( MBEDTLS_ECP_RESTARTABLE ) */
173
175
176#if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
177 defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \
178 defined(MBEDTLS_ECP_RESTARTABLE)
179#define MBEDTLS_VERIFY_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { { 0 }, { 0 }, 0, 0, 0, 0, { 0 }, \
180 { 0 } }
181#else
182#define MBEDTLS_VERIFY_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 }
183#endif
184
185
186/* EC-JPAKE operation definitions */
187
188#include "mbedtls/ecjpake.h"
189
190#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
191#define MBEDTLS_PSA_BUILTIN_PAKE 1
192#endif
193
194/* Note: the format for mbedtls_ecjpake_read/write function has an extra
195 * length byte for each step, plus an extra 3 bytes for ECParameters in the
196 * server's 2nd round. */
197#define MBEDTLS_PSA_JPAKE_BUFFER_SIZE ((3 + 1 + 65 + 1 + 65 + 1 + 32) * 2)
198
199typedef struct {
201
202 uint8_t *MBEDTLS_PRIVATE(password);
203 size_t MBEDTLS_PRIVATE(password_len);
204#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
207 size_t MBEDTLS_PRIVATE(buffer_length);
208 size_t MBEDTLS_PRIVATE(buffer_offset);
209#endif
210 /* Context structure for the Mbed TLS EC-JPAKE implementation. */
211 union {
212 unsigned int MBEDTLS_PRIVATE(dummy);
213#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
215#endif
217
219
220#define MBEDTLS_PSA_PAKE_OPERATION_INIT { { 0 } }
221
222#endif /* PSA_CRYPTO_BUILTIN_COMPOSITES_H */
This file provides an API for the CCM authenticated encryption mode for block ciphers.
This file contains the AEAD-ChaCha20-Poly1305 definitions and functions.
This file contains CMAC definitions and functions.
#define MBEDTLS_PSA_JPAKE_BUFFER_SIZE
Definitions for all PSA crypto drivers.
#define PSA_HMAC_MAX_HASH_BLOCK_SIZE
Definition: crypto_sizes.h:134
#define PSA_VENDOR_ECC_MAX_CURVE_BITS
Definition: crypto_sizes.h:247
#define PSA_BITS_TO_BYTES(bits)
Definition: crypto_sizes.h:52
This file contains ECDSA definitions and functions.
void mbedtls_ecdsa_restart_ctx
Definition: ecdsa.h:123
Elliptic curve J-PAKE.
mbedtls_ecjpake_role
Definition: ecjpake.h:54
This file contains GCM definitions and functions.
uint16_t psa_key_type_t
Encoding of a key type.
Definition: crypto_types.h:83
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
Definition: crypto_types.h:139
mbedtls_md_type_t
Supported message digests.
Definition: md.h:173
Macro wrapper for struct's members.
#define MBEDTLS_PRIVATE(member)
The CCM context-type definition. The CCM context is passed to the APIs called.
Definition: ccm.h:77
The ECP key-pair structure.
Definition: ecp.h:439
The GCM context structure.
Definition: gcm.h:60
MPI structure.
Definition: bignum.h:219