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 "kernel_defines.h"
29 #include "psa/cipher/algorithm.h"
30 #include "psa/key/type.h"
31 
44 #define PSA_BLOCK_CIPHER_BLOCK_LENGTH(type) \
45  (1u << (((type) >> 8) & 7))
46 
52 #define PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE 64
53 
80 #define PSA_CIPHER_IV_LENGTH(key_type, alg) \
81  ((PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) > 1 && \
82  ((alg) == PSA_ALG_CBC_NO_PADDING)) ? 16 : \
83  (key_type == PSA_KEY_TYPE_CHACHA20) ? 12 : 0)
84 
94 #define PSA_CIPHER_IV_MAX_SIZE 16
95 
114 #define PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_length) \
115  (input_length + PSA_CIPHER_IV_LENGTH(key_type, alg))
116 
128 #define PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input_length) \
129  (PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(PSA_KEY_TYPE_AES, PSA_ALG_CBC_NO_PADDING, input_length) \
130  > PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(PSA_KEY_TYPE_CHACHA20, PSA_ALG_STREAM_CIPHER, input_length) \
131  ? PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(PSA_KEY_TYPE_AES, PSA_ALG_CBC_NO_PADDING, input_length) \
132  : PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(PSA_KEY_TYPE_CHACHA20, PSA_ALG_STREAM_CIPHER, input_length))
133 
152 #define PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_length) \
153  (input_length - PSA_CIPHER_IV_LENGTH(key_type, alg))
154 
166 #define PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(input_length) \
167  (input_length)
168 
188 #define PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \
189  ((key_type == PSA_KEY_TYPE_CHACHA20 \
190  && alg == PSA_ALG_STREAM_CIPHER) ? (input_length + 64) : 0)
191 
204 #define PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(input_length) \
205  (input_length + 64)
206 
224 #define PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg) \
225  ((key_type == PSA_KEY_TYPE_CHACHA20) ? 64 : 0 )
226 
236 #define PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE 64
237 
238 #ifdef __cplusplus
239 }
240 #endif
241 
Cipher algorithm definitions for the PSA Crypto API.
Common macros and compiler attributes/pragmas configuration.
Key type definitions for the PSA Crypto API.