Toggle navigation
Documentation
The friendly Operating System for the Internet of Things
sizes.h
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: 2025 TU Dresden
3
* SPDX-FileCopyrightText: 2021 HAW Hamburg
4
* SPDX-License-Identifier: LGPL-2.1-only
5
*/
6
7
#pragma once
8
21
#ifdef __cplusplus
22
extern
"C"
{
23
#endif
24
25
#include "
psa/sizes.h
"
26
#include "
type.h
"
27
35
#if (IS_USED(MODULE_PSA_MAC_HMAC_SHA_256))
36
#define CONFIG_PSA_MAX_KEY_SIZE 64
37
#elif (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_P256R1) || \
38
IS_USED(MODULE_PSA_ASYMMETRIC_ECC_ED25519) || \
39
IS_USED(MODULE_PSA_CIPHER_AES_256_CBC) || \
40
IS_USED(MODULE_PSA_AEAD_AES_256_CCM) || \
41
IS_USED(MODULE_PSA_SECURE_ELEMENT_ATECCX08A_ECC_P256) || \
42
IS_USED(MODULE_PSA_CIPHER_CHACHA20))
43
#define CONFIG_PSA_MAX_KEY_SIZE 32
44
#elif (IS_USED(MODULE_PSA_CIPHER_AES_192_CBC) || \
45
IS_USED(MODULE_PSA_AEAD_AES_192_CCM) || \
46
IS_USED(MODULE_PSA_ASYMMETRIC_ECC_P192R1))
47
#define CONFIG_PSA_MAX_KEY_SIZE 24
48
#elif (IS_USED(MODULE_PSA_CIPHER_AES_128_CBC)) || \
49
(IS_USED(MODULE_PSA_AEAD_AES_128_CCM)) || \
50
(IS_USED(MODULE_PSA_CIPHER_AES_128_ECB))
51
#define CONFIG_PSA_MAX_KEY_SIZE 16
52
#else
53
#define CONFIG_PSA_MAX_KEY_SIZE 0
54
#endif
55
66
#define PSA_KEY_EXPORT_ECC_KEY_MAX_SIZE(key_type, key_bits) \
67
(size_t)\
68
(PSA_KEY_TYPE_ECC_GET_FAMILY(key_type) == PSA_ECC_FAMILY_TWISTED_EDWARDS ? 32 : \
69
(PSA_KEY_TYPE_ECC_GET_FAMILY(key_type) == PSA_ECC_FAMILY_SECP_R1 ? \
70
PSA_BITS_TO_BYTES(key_bits) : \
71
0))
72
109
#define PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits) \
110
(PSA_KEY_TYPE_IS_PUBLIC_KEY(key_type) ? \
111
PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, key_bits) : \
112
(PSA_KEY_TYPE_IS_ECC(key_type) ? \
113
PSA_KEY_EXPORT_ECC_KEY_MAX_SIZE(key_type, key_bits) : \
114
0))
115
122
#define PSA_ECC_KEY_SIZE_IS_VALID(type, bits) \
123
(PSA_KEY_TYPE_ECC_GET_FAMILY(type) == PSA_ECC_FAMILY_TWISTED_EDWARDS ? \
124
(bits == 255) : \
125
(PSA_KEY_TYPE_ECC_GET_FAMILY(type) == PSA_ECC_FAMILY_SECP_R1 ? \
126
(bits == 128 || \
127
bits == 192 || \
128
bits == 224 || \
129
bits == 256 || \
130
bits == 384) : \
131
0))
132
136
#define PSA_MAX_PRIV_KEY_SIZE (PSA_BYTES_TO_BITS(CONFIG_PSA_MAX_KEY_SIZE))
137
147
#if (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_P256R1) || \
148
IS_USED(MODULE_PSA_SECURE_ELEMENT_ATECCX08A_ECC_P256))
149
#define PSA_EXPORT_KEY_PAIR_MAX_SIZE \
150
(PSA_EXPORT_KEY_OUTPUT_SIZE(PSA_ECC_FAMILY_SECT_R1, 256))
151
#elif (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_ED25519))
152
#define PSA_EXPORT_KEY_PAIR_MAX_SIZE \
153
(PSA_EXPORT_KEY_OUTPUT_SIZE(PSA_ECC_FAMILY_TWISTED_EDWARDS, 255))
154
#elif (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_P192R1))
155
#define PSA_EXPORT_KEY_PAIR_MAX_SIZE \
156
(PSA_EXPORT_KEY_OUTPUT_SIZE(PSA_ECC_FAMILY_SECT_R1, 192))
157
#else
158
#define PSA_EXPORT_KEY_PAIR_MAX_SIZE 0
159
#endif
160
173
#define PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_type, key_bits) \
174
(PSA_KEY_TYPE_ECC_GET_FAMILY(key_type) == PSA_ECC_FAMILY_TWISTED_EDWARDS ? 32 : \
175
((size_t)(2 * PSA_BITS_TO_BYTES(key_bits) + 1)))
176
217
#define PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, key_bits) \
218
(PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_type, key_bits) : \
219
0)
220
231
#if (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_P256R1) || \
232
IS_USED(MODULE_PSA_SECURE_ELEMENT_ATECCX08A_ECC_P256))
233
#define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE \
234
(PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_ECC_FAMILY_SECT_R1, 256))
235
#elif (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_P192R1))
236
#define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE \
237
(PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_ECC_FAMILY_SECT_R1, 192))
238
#elif (IS_USED(MODULE_PSA_ASYMMETRIC_ECC_ED25519))
239
#define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE \
240
(PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_ECC_FAMILY_TWISTED_EDWARDS, 255))
241
#else
242
#define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE 0
243
#endif
244
250
#define PSA_MAX_PRIV_KEY_BUFFER_SIZE (PSA_BITS_TO_BYTES(PSA_MAX_PRIV_KEY_SIZE))
251
255
#define PSA_MAX_ASYMMETRIC_KEYPAIR_SIZE (PSA_BITS_TO_BYTES(PSA_MAX_PRIV_KEY_SIZE) + \
256
PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)
257
261
#if IS_USED(MODULE_PSA_ASYMMETRIC)
262
#define PSA_MAX_KEY_DATA_SIZE (PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)
263
#else
264
#define PSA_MAX_KEY_DATA_SIZE (CONFIG_PSA_MAX_KEY_SIZE)
265
#endif
266
270
#define PSA_MAX_UNSTRUCTURED_KEY_SIZE (CONFIG_PSA_MAX_KEY_SIZE)
271
272
#ifdef __cplusplus
273
}
274
#endif
275
type.h
Key type definitions for the PSA Crypto API.
sizes.h
Size definitions for the PSA Crypto API.
Generated on Mon Nov 24 2025 18:43:16 by
1.9.1