sizes.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2025 TU Dresden
3  * Copyright (C) 2021 HAW Hamburg
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
10 #pragma once
11 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #include "algorithm.h"
29 
42 #define PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(ciphertext_length) \
43 /* implementation-defined value */
44 
64 #define PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg) \
65  (PSA_ALG_IS_AEAD(alg) ? \
66  (((alg) & 0x003f0000) >> 16) : \
67  ((void) (key_type), (void) (key_bits), 0))
68 
78 #define PSA_AEAD_TAG_MAX_SIZE (16)
79 
89 #define PSA_AES_CCM_TAG_MAX_SIZE (16)
90 
109 #define PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, ciphertext_length) \
110  (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \
111  ((ciphertext_length) > PSA_AEAD_TAG_LENGTH(key_type, 0, alg)) ? \
112  (ciphertext_length) - PSA_AEAD_TAG_LENGTH(key_type, 0, alg) : 0)
113 
126 #define PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(plaintext_length) \
127  ((plaintext_length) + PSA_AEAD_TAG_MAX_SIZE)
128 
147 #define PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, plaintext_length) \
148  (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \
149  (plaintext_length) + PSA_AEAD_TAG_LENGTH(key_type, 0, alg) : 0)
150 
160 #define PSA_AEAD_FINISH_OUTPUT_MAX_SIZE /* implementation-defined value */
161 
180 #define PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg) \
181 /* implementation-defined value */
182 
202 #define PSA_AEAD_NONCE_LENGTH(key_type, alg) \
203  ((PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) == 16 && \
204  ((PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_CCM) || \
205  (PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_CCM))) || \
206  (key_type == PSA_KEY_TYPE_CHACHA20 && \
207  PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_CHACHA20_POLY1305) ? \
208  12 : 0)
209 
219 #define PSA_AEAD_NONCE_MAX_SIZE (13)
220 
232 #define PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(input_length) \
233 /* implementation-defined value */
234 
253 #define PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \
254 /* implementation-defined value */
255 
267 #define PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE /* implementation-defined value */
268 
286 #define PSA_AEAD_VERIFY_OUTPUT_SIZE(key_type, alg) \
287 /* implementation-defined value */
288 
289 #ifdef __cplusplus
290 }
291 #endif
292 
MAC algorithm definitions for the PSA Crypto API.