Remove test cases and update power 2 check

The power 2 check now uses a looping bit shift to try match
with the block sizes and will escape the loop when appropriate

The test cases, as pointed out by Gilles, could be harmful in
the future and testing a test case is not generally necessary

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
This commit is contained in:
Joe Subbiani 2021-07-08 15:32:52 +01:00
parent fc46318792
commit 93213f6649
2 changed files with 16 additions and 25 deletions

View file

@ -293,27 +293,15 @@ key_type:PSA_KEY_TYPE_DERIVE:KEY_TYPE_IS_UNSTRUCTURED
Block cipher key type: AES
depends_on:PSA_WANT_KEY_TYPE_AES
block_cipher_key_type:PSA_KEY_TYPE_AES:16:0
block_cipher_key_type:PSA_KEY_TYPE_AES:16
Block cipher key type: DES
depends_on:PSA_WANT_KEY_TYPE_DES
block_cipher_key_type:PSA_KEY_TYPE_DES:8:0
block_cipher_key_type:PSA_KEY_TYPE_DES:8
Block cipher key type: Camellia
depends_on:PSA_WANT_KEY_TYPE_CAMELLIA
block_cipher_key_type:PSA_KEY_TYPE_CAMELLIA:16:0
Block cipher key type: AES non power 2 block_size (24)
depends_on:PSA_WANT_KEY_TYPE_AES
block_cipher_key_type:PSA_KEY_TYPE_AES:24:1
Block cipher key type: AES non power 2 block_size (12)
depends_on:PSA_WANT_KEY_TYPE_AES
block_cipher_key_type:PSA_KEY_TYPE_AES:12:1
Block cipher key type: DES non power 2 block_size (24)
depends_on:PSA_WANT_KEY_TYPE_DES
block_cipher_key_type:PSA_KEY_TYPE_DES:24:1
block_cipher_key_type:PSA_KEY_TYPE_CAMELLIA:16
Stream cipher key type: ChaCha20
depends_on:PSA_WANT_KEY_TYPE_CHACHA20

View file

@ -619,7 +619,7 @@ void key_type( int type_arg, int classification_flags )
/* END_CASE */
/* BEGIN_CASE */
void block_cipher_key_type( int type_arg, int block_size_arg, int expecting_power_2 )
void block_cipher_key_type( int type_arg, int block_size_arg)
{
psa_key_type_t type = type_arg;
size_t block_size = block_size_arg;
@ -629,26 +629,29 @@ void block_cipher_key_type( int type_arg, int block_size_arg, int expecting_powe
TEST_EQUAL( type & PSA_KEY_TYPE_CATEGORY_MASK,
PSA_KEY_TYPE_CATEGORY_SYMMETRIC );
if (expecting_power_2 == 0)
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 test ensures
* the block sizes are indeed powers of 2.
* 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;
while( block_size > 1)
for (size_t index = 1; index > 0; index = index << 1)
{
if ( block_size % 2 != 0 )
if (index == block_size)
{
check = 0;
break;
}
if (index > block_size)
{
check = 1;
break;
}
block_size = block_size / 2;
}
/* expecting_power_2 should be 0 if true (e.g 16, 32 etc.) or 1 otherwise */
TEST_EQUAL( check, expecting_power_2 );
TEST_EQUAL( check, 0);
}
/* END_CASE */