Loading...
Searching...
No Matches
sizes.h File Reference

Cipher size definitions for the PSA Crypto API. More...

Detailed Description

#include "kernel_defines.h"
#include "psa/cipher/algorithm.h"
#include "psa/key/type.h"
+ Include dependency graph for sizes.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

#define PSA_BLOCK_CIPHER_BLOCK_LENGTH(type)
 The block size of a block cipher.
 
#define PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE   /* implementation-defined value */
 The maximum block size of a block cipher supported by the implementation.
 
#define PSA_CIPHER_IV_LENGTH(key_type, alg)
 The default IV size for a cipher algorithm, in bytes.
 
#define PSA_CIPHER_IV_MAX_SIZE   /* implementation-defined value */
 A sufficient buffer size for storing the IV generated by psa_cipher_generate_iv(), for any of the supported key types and cipher algorithms.
 
#define PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_length)
 The maximum size of the output of psa_cipher_encrypt(), in bytes.
 
#define PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input_length)
 A sufficient output buffer size for psa_cipher_encrypt(), for any of the supported key types and cipher algorithms.
 
#define PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_length)
 The maximum size of the output of psa_cipher_decrypt(), in bytes.
 
#define PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(input_length)
 A sufficient output buffer size for psa_cipher_decrypt(), for any of the supported key types and cipher algorithms.
 
#define PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input_length)
 A sufficient output buffer size for psa_cipher_update().
 
#define PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(input_length)
 A sufficient output buffer size for psa_cipher_update(), for any of the supported key types and cipher algorithms.
 
#define PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg)
 A sufficient output buffer size for psa_cipher_finish().
 
#define PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE   /* implementation-defined value */
 A sufficient output buffer size for psa_cipher_finish(), for any of the supported key types and cipher algorithms.
 

Macro Definition Documentation

◆ PSA_BLOCK_CIPHER_BLOCK_LENGTH

#define PSA_BLOCK_CIPHER_BLOCK_LENGTH ( type)
Value:
(1u << (((type) >> 8) & 7))

The block size of a block cipher.

Note
It is possible to build stream cipher algorithms on top of a block cipher, for example CTR mode (PSA_ALG_CTR). This macro only takes the key type into account, so it cannot be used to determine the size of the data that psa_cipher_update() might buffer for future processing in general.
Parameters
typeA cipher key type (value of type psa_key_type_t).
Returns
The block size for a block cipher, or 1 for a stream cipher.

Definition at line 44 of file sizes.h.

◆ PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE

#define PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE   /* implementation-defined value */

The maximum block size of a block cipher supported by the implementation.

See also PSA_BLOCK_CIPHER_BLOCK_LENGTH().

Definition at line 52 of file sizes.h.

◆ PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE

#define PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE ( input_length)
Value:
(input_length)

A sufficient output buffer size for psa_cipher_decrypt(), for any of the supported key types and cipher algorithms.

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_decrypt() will not fail due to an insufficient buffer size.

See also PSA_CIPHER_DECRYPT_OUTPUT_SIZE().

Parameters
input_lengthSize of the input in bytes.

Definition at line 163 of file sizes.h.

◆ PSA_CIPHER_DECRYPT_OUTPUT_SIZE

#define PSA_CIPHER_DECRYPT_OUTPUT_SIZE ( key_type,
alg,
input_length )
Value:
(input_length - PSA_CIPHER_IV_LENGTH(key_type, alg))
#define PSA_CIPHER_IV_LENGTH(key_type, alg)
The default IV size for a cipher algorithm, in bytes.
Definition sizes.h:80

The maximum size of the output of psa_cipher_decrypt(), in bytes.

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_decrypt() will not fail due to an insufficient buffer size. Depending on the algorithm, the actual size of the output might be smaller.

See also PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algA cipher algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_CIPHER(alg) is true).
input_lengthSize of the input in bytes.
Returns
A sufficient output size for the specified key type and algorithm. 0 if the key type or cipher algorithm is not recognized, or the parameters are incompatible.

Definition at line 149 of file sizes.h.

◆ PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE

#define PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE ( input_length)
Value:
#define PSA_ALG_CBC_NO_PADDING
The Cipher Block Chaining (CBC) mode of a block cipher, with no padding.
Definition algorithm.h:275
#define PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_length)
The maximum size of the output of psa_cipher_encrypt(), in bytes.
Definition sizes.h:114
#define PSA_KEY_TYPE_AES
Key for a cipher, AEAD or MAC algorithm based on the AES block cipher.
Definition type.h:290

A sufficient output buffer size for psa_cipher_encrypt(), for any of the supported key types and cipher algorithms.

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_encrypt() will not fail due to an insufficient buffer size.

See also PSA_CIPHER_ENCRYPT_OUTPUT_SIZE().

Parameters
input_lengthSize of the input in bytes.

Definition at line 128 of file sizes.h.

◆ PSA_CIPHER_ENCRYPT_OUTPUT_SIZE

#define PSA_CIPHER_ENCRYPT_OUTPUT_SIZE ( key_type,
alg,
input_length )
Value:
(input_length + PSA_CIPHER_IV_LENGTH(key_type, alg))

The maximum size of the output of psa_cipher_encrypt(), in bytes.

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_encrypt() will not fail due to an insufficient buffer size. Depending on the algorithm, the actual size of the output might be smaller.

See also PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algA cipher algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_CIPHER(alg) is true).
input_lengthSize of the input in bytes.
Returns
A sufficient output size for the specified key type and algorithm. 0 if the key type or cipher algorithm is not recognized, not supported or the parameters are incompatible.

Definition at line 114 of file sizes.h.

◆ PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE

#define PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE   /* implementation-defined value */

A sufficient output buffer size for psa_cipher_finish(), for any of the supported key types and cipher algorithms.

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_finish() will not fail due to an insufficient buffer size.

See also PSA_CIPHER_FINISH_OUTPUT_SIZE().

Definition at line 232 of file sizes.h.

◆ PSA_CIPHER_FINISH_OUTPUT_SIZE

#define PSA_CIPHER_FINISH_OUTPUT_SIZE ( key_type,
alg )
Value:
/* implementation-defined value */

A sufficient output buffer size for psa_cipher_finish().

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_finish() will not fail due to an insufficient buffer size. The actual size of the output might be smaller in any given call.

See also PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algA cipher algorithm: a value of type psa_algorithm_t such that PSA_ALG_IS_CIPHER(alg) is true.
Returns
A sufficient output size for the specified key type and algorithm. 0 if the key type or cipher algorithm is not recognized, not supported or the parameters are incompatible.

Definition at line 220 of file sizes.h.

◆ PSA_CIPHER_IV_LENGTH

#define PSA_CIPHER_IV_LENGTH ( key_type,
alg )
Value:
((PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) > 1 && \
((alg) == PSA_ALG_CBC_NO_PADDING)) ? 16 : \
(key_type == PSA_KEY_TYPE_CHACHA20) ? 12 : 0)
#define PSA_BLOCK_CIPHER_BLOCK_LENGTH(type)
The block size of a block cipher.
Definition sizes.h:44
#define PSA_KEY_TYPE_CHACHA20
Key for the ChaCha20 stream cipher or the ChaCha20-Poly1305 AEAD algorithm.
Definition type.h:444

The default IV size for a cipher algorithm, in bytes.

The IV that is generated as part of a call to psa_cipher_encrypt() is always the default IV length for the algorithm.

This macro can be used to allocate a buffer of sufficient size to store the IV output from psa_cipher_generate_iv() when using a multi-part cipher operation.

See also PSA_CIPHER_IV_MAX_SIZE.

Warning
This macro may evaluate its arguments multiple times or zero times, so you should not pass arguments that contain side effects.
Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algA cipher algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_CIPHER(alg) is true)
Returns
The default IV size for the specified key type and algorithm. 0, if the algorithm does not use an IV, if key type or cipher algorithm are not recognized or if the parameters are not compatible.

Definition at line 80 of file sizes.h.

◆ PSA_CIPHER_IV_MAX_SIZE

#define PSA_CIPHER_IV_MAX_SIZE   /* implementation-defined value */

A sufficient buffer size for storing the IV generated by psa_cipher_generate_iv(), for any of the supported key types and cipher algorithms.

If the size of the IV buffer is at least this large, it is guaranteed that psa_cipher_generate_iv() will not fail due to an insufficient buffer size.

See also PSA_CIPHER_IV_LENGTH().

Definition at line 94 of file sizes.h.

◆ PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE

#define PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE ( input_length)
Value:
/* implementation-defined value */

A sufficient output buffer size for psa_cipher_update(), for any of the supported key types and cipher algorithms.

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_update() will not fail due to an insufficient buffer size.

See also PSA_CIPHER_UPDATE_OUTPUT_SIZE().

Parameters
input_lengthSize of the input in bytes.

Definition at line 200 of file sizes.h.

◆ PSA_CIPHER_UPDATE_OUTPUT_SIZE

#define PSA_CIPHER_UPDATE_OUTPUT_SIZE ( key_type,
alg,
input_length )
Value:
/* implementation-defined value */

A sufficient output buffer size for psa_cipher_update().

If the size of the output buffer is at least this large, it is guaranteed that psa_cipher_update() will not fail due to an insufficient buffer size. The actual size of the output might be smaller in any given call.

See also PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE.

Parameters
key_typeA symmetric key type that is compatible with algorithm alg.
algA cipher algorithm (PSA_ALG_XXX value such that PSA_ALG_IS_CIPHER(alg) is true).
input_lengthSize of the input in bytes.
Returns
A sufficient output size for the specified key type and algorithm. 0 if the key type or cipher algorithm is not recognized, not supported or the parameters are incompatible.

Definition at line 185 of file sizes.h.