Extend psa_crypto_metadata tests to check for powers of 2
Add a check to ensure the block_size is or is not a power of 2 Add a new parameter to verify the expected pass/fail when a block_size is or is not a power of 2. Add new sets of input data to verify these tests Fixes #4228 Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
This commit is contained in:
parent
0a7ff4a4e2
commit
f37bbe53a0
2 changed files with 37 additions and 5 deletions
|
@ -293,15 +293,27 @@ key_type:PSA_KEY_TYPE_DERIVE:KEY_TYPE_IS_UNSTRUCTURED
|
||||||
|
|
||||||
Block cipher key type: AES
|
Block cipher key type: AES
|
||||||
depends_on:PSA_WANT_KEY_TYPE_AES
|
depends_on:PSA_WANT_KEY_TYPE_AES
|
||||||
block_cipher_key_type:PSA_KEY_TYPE_AES:16
|
block_cipher_key_type:PSA_KEY_TYPE_AES:16:0
|
||||||
|
|
||||||
Block cipher key type: DES
|
Block cipher key type: DES
|
||||||
depends_on:PSA_WANT_KEY_TYPE_DES
|
depends_on:PSA_WANT_KEY_TYPE_DES
|
||||||
block_cipher_key_type:PSA_KEY_TYPE_DES:8
|
block_cipher_key_type:PSA_KEY_TYPE_DES:8:0
|
||||||
|
|
||||||
Block cipher key type: Camellia
|
Block cipher key type: Camellia
|
||||||
depends_on:PSA_WANT_KEY_TYPE_CAMELLIA
|
depends_on:PSA_WANT_KEY_TYPE_CAMELLIA
|
||||||
block_cipher_key_type:PSA_KEY_TYPE_CAMELLIA:16
|
block_cipher_key_type:PSA_KEY_TYPE_CAMELLIA:16:0
|
||||||
|
|
||||||
|
Block cipher key type: AES
|
||||||
|
depends_on:PSA_WANT_KEY_TYPE_AES
|
||||||
|
block_cipher_key_type:PSA_KEY_TYPE_AES:24:1
|
||||||
|
|
||||||
|
Block cipher key type: AES
|
||||||
|
depends_on:PSA_WANT_KEY_TYPE_AES
|
||||||
|
block_cipher_key_type:PSA_KEY_TYPE_AES:12:1
|
||||||
|
|
||||||
|
Block cipher key type: DES
|
||||||
|
depends_on:PSA_WANT_KEY_TYPE_DES
|
||||||
|
block_cipher_key_type:PSA_KEY_TYPE_DES:24:1
|
||||||
|
|
||||||
Stream cipher key type: ChaCha20
|
Stream cipher key type: ChaCha20
|
||||||
depends_on:PSA_WANT_KEY_TYPE_CHACHA20
|
depends_on:PSA_WANT_KEY_TYPE_CHACHA20
|
||||||
|
|
|
@ -619,7 +619,7 @@ void key_type( int type_arg, int classification_flags )
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void block_cipher_key_type( int type_arg, int block_size_arg )
|
void block_cipher_key_type( int type_arg, int block_size_arg, int expecting_power_2 )
|
||||||
{
|
{
|
||||||
psa_key_type_t type = type_arg;
|
psa_key_type_t type = type_arg;
|
||||||
size_t block_size = block_size_arg;
|
size_t block_size = block_size_arg;
|
||||||
|
@ -628,7 +628,27 @@ 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 );
|
|
||||||
|
if (expecting_power_2 == 0)
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
int check = 0;
|
||||||
|
|
||||||
|
while( block_size > 1)
|
||||||
|
{
|
||||||
|
if ( block_size % 2 != 0 )
|
||||||
|
{
|
||||||
|
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 );
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue