Rework PSA_AEAD_NONCE_LENGTH to reduce expansion

Due to repeated calls to PSA_AEAD_NONCE_LENGTH, which in turn calls
PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG several times, some macros updated
in this PR expanded to over 6000 characters, more than the 4095 that ISO
C99 compilers are guaranteed to support.

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
This commit is contained in:
Bence Szépkúti 2021-04-07 10:59:35 +02:00
parent 8072db2fcb
commit 598e92991a

View file

@ -375,11 +375,14 @@
*/ */
#define PSA_AEAD_NONCE_LENGTH(key_type, alg) \ #define PSA_AEAD_NONCE_LENGTH(key_type, alg) \
(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) == 16 ? \ (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) == 16 ? \
PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_CCM ? 13 : \ PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, 0) == \
PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_GCM ? 12 : \ PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, 0) ? 13 : \
PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, 0) == \
PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM, 0) ? 12 : \
0 : \ 0 : \
(key_type) == PSA_KEY_TYPE_CHACHA20 && \ (key_type) == PSA_KEY_TYPE_CHACHA20 && \
PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_CHACHA20_POLY1305 ? 12 : \ PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, 0) == \
PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CHACHA20_POLY1305, 0) ? 12 : \
0) 0)
/** The maximum default nonce size among all supported pairs of key types and /** The maximum default nonce size among all supported pairs of key types and