Skip to content

Commit 4019b58

Browse files
Test the block size for symmetric keys
Also insist on their category. Fix a missing implementation of PSA_BLOCK_CIPHER_BLOCK_SIZE for ChaCha20.
1 parent 2e8e2be commit 4019b58

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

include/psa/crypto_values.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@
604604
(type) == PSA_KEY_TYPE_DES ? 8 : \
605605
(type) == PSA_KEY_TYPE_CAMELLIA ? 16 : \
606606
(type) == PSA_KEY_TYPE_ARC4 ? 1 : \
607+
(type) == PSA_KEY_TYPE_CHACHA20 ? 1 : \
607608
0)
608609

609610
/** Vendor-defined algorithm flag.

tests/scripts/test_psa_constant_names.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ def __init__(self):
102102
# Any function ending in _algorithm also gets added to
103103
# self.algorithms.
104104
'key_type': [self.key_types],
105+
'block_cipher_key_type': [self.key_types],
106+
'stream_cipher_key_type': [self.key_types],
105107
'ecc_key_types': [self.ecc_curves],
106108
'dh_key_types': [self.dh_groups],
107109
'hash_algorithm': [self.hash_algorithms],

tests/suites/test_suite_psa_crypto_metadata.data

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,25 +315,25 @@ key_type:PSA_KEY_TYPE_HMAC:KEY_TYPE_IS_UNSTRUCTURED
315315
Key type: secret for key derivation
316316
key_type:PSA_KEY_TYPE_DERIVE:KEY_TYPE_IS_UNSTRUCTURED
317317

318-
Key type: AES
318+
Block cipher key type: AES
319319
depends_on:MBEDTLS_AES_C
320-
key_type:PSA_KEY_TYPE_AES:KEY_TYPE_IS_UNSTRUCTURED
320+
block_cipher_key_type:PSA_KEY_TYPE_AES:16
321321

322-
Key type: DES
322+
Block cipher key type: DES
323323
depends_on:MBEDTLS_DES_C
324-
key_type:PSA_KEY_TYPE_DES:KEY_TYPE_IS_UNSTRUCTURED
324+
block_cipher_key_type:PSA_KEY_TYPE_DES:8
325325

326-
Key type: Camellia
326+
Block cipher key type: Camellia
327327
depends_on:MBEDTLS_CAMELLIA_C
328-
key_type:PSA_KEY_TYPE_CAMELLIA:KEY_TYPE_IS_UNSTRUCTURED
328+
block_cipher_key_type:PSA_KEY_TYPE_CAMELLIA:16
329329

330-
Key type: ARC4
330+
Stream cipher key type: ARC4
331331
depends_on:MBEDTLS_ARC4_C
332-
key_type:PSA_KEY_TYPE_ARC4:KEY_TYPE_IS_UNSTRUCTURED
332+
stream_cipher_key_type:PSA_KEY_TYPE_ARC4
333333

334-
Key type: ChaCha20
334+
Stream cipher key type: ChaCha20
335335
depends_on:MBEDTLS_CHACHA20_C
336-
key_type:PSA_KEY_TYPE_CHACHA20:KEY_TYPE_IS_UNSTRUCTURED
336+
stream_cipher_key_type:PSA_KEY_TYPE_CHACHA20
337337

338338
Key type: RSA public key
339339
depends_on:MBEDTLS_RSA_C

tests/suites/test_suite_psa_crypto_metadata.function

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,31 @@ void key_type( int type_arg, int classification_flags )
449449
}
450450
/* END_CASE */
451451

452+
/* BEGIN_CASE */
453+
void block_cipher_key_type( int type_arg, int block_size_arg )
454+
{
455+
test_key_type( type_arg, KEY_TYPE_IS_UNSTRUCTURED );
456+
457+
psa_key_type_t type = type_arg;
458+
size_t block_size = block_size_arg;
459+
TEST_EQUAL( type & PSA_KEY_TYPE_CATEGORY_MASK,
460+
PSA_KEY_TYPE_CATEGORY_SYMMETRIC );
461+
TEST_EQUAL( PSA_BLOCK_CIPHER_BLOCK_SIZE( type ), block_size );
462+
}
463+
/* END_CASE */
464+
465+
/* BEGIN_CASE */
466+
void stream_cipher_key_type( int type_arg )
467+
{
468+
test_key_type( type_arg, KEY_TYPE_IS_UNSTRUCTURED );
469+
470+
psa_key_type_t type = type_arg;
471+
TEST_EQUAL( type & PSA_KEY_TYPE_CATEGORY_MASK,
472+
PSA_KEY_TYPE_CATEGORY_SYMMETRIC );
473+
TEST_EQUAL( PSA_BLOCK_CIPHER_BLOCK_SIZE( type ), 1 );
474+
}
475+
/* END_CASE */
476+
452477
/* BEGIN_CASE */
453478
void ecc_key_types( int curve_arg, int curve_bits_arg )
454479
{

0 commit comments

Comments
 (0)