From 48bae0295c064d819b7a199565943a9b27437b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 8 Feb 2022 11:14:58 +0100 Subject: [PATCH] Avoid hardcoding a size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Pégourié-Gonnard --- programs/cipher/cipher_aead_demo.c | 7 ++++--- programs/psa/aead_demo.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/programs/cipher/cipher_aead_demo.c b/programs/cipher/cipher_aead_demo.c index c9a41ae5a..05d1cb0c4 100644 --- a/programs/cipher/cipher_aead_demo.c +++ b/programs/cipher/cipher_aead_demo.c @@ -80,9 +80,10 @@ const unsigned char add_data2[] = { 0x11, 0x12 }; const unsigned char msg2_part1[] = { 0x13, 0x14 }; const unsigned char msg2_part2[] = { 0x15, 0x16, 0x17 }; -/* This must at least the sum of the length of the 2 parts for each message. - * This is a macro for the sake of compilers with insufficient C99 support. */ -#define MSG_MAX_SIZE 5 +/* Maximum total size of the messages */ +#define MSG1_SIZE ( sizeof( msg1_part1 ) + sizeof( msg1_part2 ) ) +#define MSG2_SIZE ( sizeof( msg2_part1 ) + sizeof( msg2_part2 ) ) +#define MSG_MAX_SIZE ( MSG1_SIZE > MSG2_SIZE ? MSG1_SIZE : MSG2_SIZE ) /* Dummy key material - never do this in production! * 32-byte is enough to all the key size supported by this program. */ diff --git a/programs/psa/aead_demo.c b/programs/psa/aead_demo.c index 322908bed..ac7bf6577 100644 --- a/programs/psa/aead_demo.c +++ b/programs/psa/aead_demo.c @@ -82,9 +82,10 @@ const unsigned char add_data2[] = { 0x11, 0x12 }; const unsigned char msg2_part1[] = { 0x13, 0x14 }; const unsigned char msg2_part2[] = { 0x15, 0x16, 0x17 }; -/* This must at least the sum of the length of the 2 parts for each message. - * This is a macro for the sake of compilers with insufficient C99 support. */ -#define MSG_MAX_SIZE 5 +/* Maximum total size of the messages */ +#define MSG1_SIZE ( sizeof( msg1_part1 ) + sizeof( msg1_part2 ) ) +#define MSG2_SIZE ( sizeof( msg2_part1 ) + sizeof( msg2_part2 ) ) +#define MSG_MAX_SIZE ( MSG1_SIZE > MSG2_SIZE ? MSG1_SIZE : MSG2_SIZE ) /* Dummy key material - never do this in production! * 32-byte is enough to all the key size supported by this program. */