mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-05-01 12:06:24 +00:00
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 <joe.subbiani@arm.com>
This commit is contained in:
parent
ba940cc695
commit
bd5cc3a0be
|
@ -603,6 +603,28 @@ void block_cipher_key_type( int type_arg, int block_size_arg )
|
||||||
TEST_EQUAL( type & PSA_KEY_TYPE_CATEGORY_MASK,
|
TEST_EQUAL( type & PSA_KEY_TYPE_CATEGORY_MASK,
|
||||||
PSA_KEY_TYPE_CATEGORY_SYMMETRIC );
|
PSA_KEY_TYPE_CATEGORY_SYMMETRIC );
|
||||||
TEST_EQUAL( PSA_BLOCK_CIPHER_BLOCK_LENGTH( type ), block_size );
|
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 */
|
/* END_CASE */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue