PSA_CIPHER_IV_LENGTH macro
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.
Syntax
#define PSA_CIPHER_IV_LENGTH(key_type, alg) \
(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) > 1 && \
((alg) == PSA_ALG_CTR || \
(alg) == PSA_ALG_CFB || \
(alg) == PSA_ALG_OFB || \
(alg) == PSA_ALG_XTS || \
(alg) == PSA_ALG_CBC_NO_PADDING || \
(alg) == PSA_ALG_CBC_PKCS7) ? PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \
(key_type) == PSA_KEY_TYPE_CHACHA20 && \
(alg) == PSA_ALG_STREAM_CIPHER ? 12 : \
0)
Arguments
key_type
A symmetric key type that is compatible with algorithm \p alg.
alg
A cipher algorithm (\c PSA_ALG_XXX value such that #PSA_ALG_IS_CIPHER(\p alg) is true).
Return value
The default IV size for the specified key type and algorithm. If the algorithm does not use an IV, return 0. If the key type or cipher algorithm is not recognized, or the parameters are incompatible, return 0.