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 "algorithm.h"
26 
39 #define PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(ciphertext_length) \
40 /* implementation-defined value */
41 
61 #define PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg) \
62  (PSA_ALG_IS_AEAD(alg) ? \
63  (((alg) & 0x003f0000) >> 16) : \
64  ((void) (key_type), (void) (key_bits), 0))
65 
75 #define PSA_AEAD_TAG_MAX_SIZE (16)
76 
86 #define PSA_AES_CCM_TAG_MAX_SIZE (16)
87 
106 #define PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, ciphertext_length) \
107  (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \
108  ((ciphertext_length) > PSA_AEAD_TAG_LENGTH(key_type, 0, alg)) ? \
109  (ciphertext_length) - PSA_AEAD_TAG_LENGTH(key_type, 0, alg) : 0)
110 
123 #define PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(plaintext_length) \
124  ((plaintext_length) + PSA_AEAD_TAG_MAX_SIZE)
125 
144 #define PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, plaintext_length) \
145  (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \
146  (plaintext_length) + PSA_AEAD_TAG_LENGTH(key_type, 0, alg) : 0)
147 
157 #define PSA_AEAD_FINISH_OUTPUT_MAX_SIZE /* implementation-defined value */
158 
177 #define PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg) \
178 /* implementation-defined value */
179 
199 #define PSA_AEAD_NONCE_LENGTH(key_type, alg) \
200  ((PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) == 16 && \
201  ((PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_CCM) || \
202  (PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_CCM))) || \
203  (key_type == PSA_KEY_TYPE_CHACHA20 && \
204  PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_CHACHA20_POLY1305) ? \
205  12 : 0)
206 
216 #define PSA_AEAD_NONCE_MAX_SIZE (13)
217 
229 #define PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(input_length) \
230 /* implementation-defined value */
231 
250 #define PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \
251 /* implementation-defined value */
252 
264 #define PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE /* implementation-defined value */
265 
283 #define PSA_AEAD_VERIFY_OUTPUT_SIZE(key_type, alg) \
284 /* implementation-defined value */
285 
286 #ifdef __cplusplus
287 }
288 #endif
289 
MAC algorithm definitions for the PSA Crypto API.