From bd5cc3a0beb78d58c64f4dbccb9ccdd7ffb42295 Mon Sep 17 00:00:00 2001 From: Joe Subbiani Date: Fri, 9 Jul 2021 12:17:49 +0100 Subject: [PATCH 1/3] Add test in block_cipher_key_type test case The test case uses a bit shift to check that the block size is a power of 2 Fixes #4228 Signed-off-by: Joe Subbiani --- .../test_suite_psa_crypto_metadata.function | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/suites/test_suite_psa_crypto_metadata.function b/tests/suites/test_suite_psa_crypto_metadata.function index d91f90fc6..ef0b26565 100644 --- a/tests/suites/test_suite_psa_crypto_metadata.function +++ b/tests/suites/test_suite_psa_crypto_metadata.function @@ -603,6 +603,28 @@ void block_cipher_key_type( int type_arg, int block_size_arg ) TEST_EQUAL( type & PSA_KEY_TYPE_CATEGORY_MASK, PSA_KEY_TYPE_CATEGORY_SYMMETRIC ); TEST_EQUAL( PSA_BLOCK_CIPHER_BLOCK_LENGTH( type ), block_size ); + + /* PSA_ROUND_UP_TO_MULTIPLE(block_size, length) in crypto_sizes.h + * Requires block sizes to be a power of 2. + * The following creates a bit and shifts along until it finds a + * match or a mismatch. + */ + int check = 0; + + for (size_t index = 1; index > 0; index = index << 1) + { + if (index == block_size) + { + check = 0; + break; + } + if (index > block_size) + { + check = 1; + break; + } + } + TEST_EQUAL( check, 0); } /* END_CASE */ From c9eb8581a4fcbed38bd430c6b86d4b0639a9f0df Mon Sep 17 00:00:00 2001 From: Joe Subbiani Date: Wed, 14 Jul 2021 15:32:29 +0100 Subject: [PATCH 2/3] Simplify the test and description Previously the check was convoluted. This has been simplified and given a more appropriate suggestion as per gilles suggestion Signed-off-by: Joe Subbiani --- .../test_suite_psa_crypto_metadata.function | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto_metadata.function b/tests/suites/test_suite_psa_crypto_metadata.function index ef0b26565..a044ca56f 100644 --- a/tests/suites/test_suite_psa_crypto_metadata.function +++ b/tests/suites/test_suite_psa_crypto_metadata.function @@ -604,27 +604,9 @@ void block_cipher_key_type( int type_arg, int block_size_arg ) PSA_KEY_TYPE_CATEGORY_SYMMETRIC ); TEST_EQUAL( PSA_BLOCK_CIPHER_BLOCK_LENGTH( type ), block_size ); - /* PSA_ROUND_UP_TO_MULTIPLE(block_size, length) in crypto_sizes.h - * Requires block sizes to be a power of 2. - * The following creates a bit and shifts along until it finds a - * match or a mismatch. - */ - int check = 0; - - for (size_t index = 1; index > 0; index = index << 1) - { - if (index == block_size) - { - check = 0; - break; - } - if (index > block_size) - { - check = 1; - break; - } - } - TEST_EQUAL( check, 0); + /* Check that the block size is a power of 2. This is required, at least, + for PSA_ROUND_UP_TO_MULTIPLE(block_size, length) in crypto_sizes.h. */ + TEST_ASSERT( ( ( block_size - 1 ) & block_size ) == 0 ); } /* END_CASE */ From 50536429a7a6a1064bfb467b453af65d0576fc66 Mon Sep 17 00:00:00 2001 From: Joe Subbiani Date: Thu, 15 Jul 2021 09:02:43 +0100 Subject: [PATCH 3/3] Remove trailing whitespace Signed-off-by: Joe Subbiani --- tests/suites/test_suite_psa_crypto_metadata.function | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/suites/test_suite_psa_crypto_metadata.function b/tests/suites/test_suite_psa_crypto_metadata.function index a044ca56f..7bf1e282d 100644 --- a/tests/suites/test_suite_psa_crypto_metadata.function +++ b/tests/suites/test_suite_psa_crypto_metadata.function @@ -604,7 +604,7 @@ void block_cipher_key_type( int type_arg, int block_size_arg ) PSA_KEY_TYPE_CATEGORY_SYMMETRIC ); TEST_EQUAL( PSA_BLOCK_CIPHER_BLOCK_LENGTH( type ), block_size ); - /* Check that the block size is a power of 2. This is required, at least, + /* Check that the block size is a power of 2. This is required, at least, for PSA_ROUND_UP_TO_MULTIPLE(block_size, length) in crypto_sizes.h. */ TEST_ASSERT( ( ( block_size - 1 ) & block_size ) == 0 ); }