From fd1d13c8bd37d2fa03e8c3ca7469717e0ae379fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 28 Jan 2022 12:52:35 +0100 Subject: [PATCH] Avoid requiring too much C99 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MSVC 2013, still supported and used in our CI, did not support that. aead_psa.c(78): error C2099: initializer is not a constant aead_psa.c(168): error C2057: expected constant expression aead_psa.c(168): error C2466: cannot allocate an array of constant size 0 aead_psa.c(168): error C2133: 'out' : unknown size aead_psa.c(169): warning C4034: sizeof returns 0 Signed-off-by: Manuel Pégourié-Gonnard --- programs/psa/aead_non_psa.c | 6 ++---- programs/psa/aead_psa.c | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/programs/psa/aead_non_psa.c b/programs/psa/aead_non_psa.c index 260ea6b92a..4b48b3a989 100644 --- a/programs/psa/aead_non_psa.c +++ b/programs/psa/aead_non_psa.c @@ -64,15 +64,13 @@ const unsigned char iv1[12] = { 0x00 }; const unsigned char add_data1[] = { 0x01, 0x02 }; const unsigned char msg1_part1[] = { 0x03, 0x04 }; const unsigned char msg1_part2[] = { 0x05, 0x06, 0x07 }; -const size_t msg1_size = sizeof( msg1_part1 ) + sizeof( msg1_part2 ); const unsigned char iv2[12] = { 0x10 }; const unsigned char add_data2[] = { 0x11, 0x12 }; const unsigned char msg2_part1[] = { 0x13, 0x14 }; const unsigned char msg2_part2[] = { 0x15, 0x16, 0x17 }; -const size_t msg2_size = sizeof( msg2_part1 ) + sizeof( msg2_part2 ); -const size_t msg_max_size = msg1_size > msg2_size ? msg1_size : msg2_size; +#define MSG_MAX_SIZE 5 const unsigned char key_bytes[32] = { 0x2a }; @@ -149,7 +147,7 @@ static int aead_encrypt( mbedtls_cipher_context_t *ctx, size_t tag_len, { int ret; size_t olen; - unsigned char out[msg_max_size + 16]; + unsigned char out[MSG_MAX_SIZE + 16]; unsigned char *p = out; CHK( mbedtls_cipher_set_iv( ctx, iv, iv_len ) ); diff --git a/programs/psa/aead_psa.c b/programs/psa/aead_psa.c index ebc7cd9d48..5ed32a5f6a 100644 --- a/programs/psa/aead_psa.c +++ b/programs/psa/aead_psa.c @@ -67,15 +67,13 @@ const unsigned char iv1[12] = { 0x00 }; const unsigned char add_data1[] = { 0x01, 0x02 }; const unsigned char msg1_part1[] = { 0x03, 0x04 }; const unsigned char msg1_part2[] = { 0x05, 0x06, 0x07 }; -const size_t msg1_size = sizeof( msg1_part1 ) + sizeof( msg1_part2 ); const unsigned char iv2[12] = { 0x10 }; const unsigned char add_data2[] = { 0x11, 0x12 }; const unsigned char msg2_part1[] = { 0x13, 0x14 }; const unsigned char msg2_part2[] = { 0x15, 0x16, 0x17 }; -const size_t msg2_size = sizeof( msg2_part1 ) + sizeof( msg2_part2 ); -const size_t msg_max_size = msg1_size > msg2_size ? msg1_size : msg2_size; +#define MSG_MAX_SIZE 5 const unsigned char key_bytes[32] = { 0x2a }; @@ -165,7 +163,7 @@ static int aead_encrypt( psa_key_id_t key, psa_algorithm_t alg, { psa_status_t status; size_t olen, olen_tag; - unsigned char out[PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(msg_max_size)]; + unsigned char out[PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(MSG_MAX_SIZE)]; unsigned char *p = out, *end = out + sizeof( out ); unsigned char tag[PSA_AEAD_TAG_MAX_SIZE];