Test the block size for symmetric keys

Also insist on their category.

Fix a missing implementation of PSA_BLOCK_CIPHER_BLOCK_SIZE for
ChaCha20.
This commit is contained in:
Gilles Peskine 2019-12-02 17:26:44 +01:00
parent 92f2da9d67
commit f8210f2bd5
4 changed files with 40 additions and 10 deletions

View File

@ -604,6 +604,7 @@
(type) == PSA_KEY_TYPE_DES ? 8 : \
(type) == PSA_KEY_TYPE_CAMELLIA ? 16 : \
(type) == PSA_KEY_TYPE_ARC4 ? 1 : \
(type) == PSA_KEY_TYPE_CHACHA20 ? 1 : \
0)
/** Vendor-defined algorithm flag.

View File

@ -102,6 +102,8 @@ class Inputs:
# Any function ending in _algorithm also gets added to
# self.algorithms.
'key_type': [self.key_types],
'block_cipher_key_type': [self.key_types],
'stream_cipher_key_type': [self.key_types],
'ecc_key_types': [self.ecc_curves],
'dh_key_types': [self.dh_groups],
'hash_algorithm': [self.hash_algorithms],

View File

@ -315,25 +315,25 @@ key_type:PSA_KEY_TYPE_HMAC:KEY_TYPE_IS_UNSTRUCTURED
Key type: secret for key derivation
key_type:PSA_KEY_TYPE_DERIVE:KEY_TYPE_IS_UNSTRUCTURED
Key type: AES
Block cipher key type: AES
depends_on:MBEDTLS_AES_C
key_type:PSA_KEY_TYPE_AES:KEY_TYPE_IS_UNSTRUCTURED
block_cipher_key_type:PSA_KEY_TYPE_AES:16
Key type: DES
Block cipher key type: DES
depends_on:MBEDTLS_DES_C
key_type:PSA_KEY_TYPE_DES:KEY_TYPE_IS_UNSTRUCTURED
block_cipher_key_type:PSA_KEY_TYPE_DES:8
Key type: Camellia
Block cipher key type: Camellia
depends_on:MBEDTLS_CAMELLIA_C
key_type:PSA_KEY_TYPE_CAMELLIA:KEY_TYPE_IS_UNSTRUCTURED
block_cipher_key_type:PSA_KEY_TYPE_CAMELLIA:16
Key type: ARC4
Stream cipher key type: ARC4
depends_on:MBEDTLS_ARC4_C
key_type:PSA_KEY_TYPE_ARC4:KEY_TYPE_IS_UNSTRUCTURED
stream_cipher_key_type:PSA_KEY_TYPE_ARC4
Key type: ChaCha20
Stream cipher key type: ChaCha20
depends_on:MBEDTLS_CHACHA20_C
key_type:PSA_KEY_TYPE_CHACHA20:KEY_TYPE_IS_UNSTRUCTURED
stream_cipher_key_type:PSA_KEY_TYPE_CHACHA20
Key type: RSA public key
depends_on:MBEDTLS_RSA_C

View File

@ -449,6 +449,33 @@ 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 )
{
psa_key_type_t type = type_arg;
size_t block_size = block_size_arg;
test_key_type( type_arg, KEY_TYPE_IS_UNSTRUCTURED );
TEST_EQUAL( type & PSA_KEY_TYPE_CATEGORY_MASK,
PSA_KEY_TYPE_CATEGORY_SYMMETRIC );
TEST_EQUAL( PSA_BLOCK_CIPHER_BLOCK_SIZE( type ), block_size );
}
/* END_CASE */
/* BEGIN_CASE */
void stream_cipher_key_type( int type_arg )
{
psa_key_type_t type = type_arg;
test_key_type( type_arg, KEY_TYPE_IS_UNSTRUCTURED );
TEST_EQUAL( type & PSA_KEY_TYPE_CATEGORY_MASK,
PSA_KEY_TYPE_CATEGORY_SYMMETRIC );
TEST_EQUAL( PSA_BLOCK_CIPHER_BLOCK_SIZE( type ), 1 );
}
/* END_CASE */
/* BEGIN_CASE */
void ecc_key_types( int curve_arg, int curve_bits_arg )
{