mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Merge pull request #231 from dgreen-arm/api-to-development
Merge psa api branch into development
This commit is contained in:
@ -19,6 +19,9 @@ persistence_attributes:0x1234:3:-1:0x1234:3
|
||||
PSA key attributes: lifetime then id
|
||||
persistence_attributes:0x1234:3:0x1235:0x1235:3
|
||||
|
||||
PSA key attributes: slot number
|
||||
slot_number_attribute:
|
||||
|
||||
PSA import/export raw: 0 bytes
|
||||
import_export:"":PSA_KEY_TYPE_RAW_DATA:PSA_KEY_USAGE_EXPORT:0:0:0:PSA_SUCCESS:1
|
||||
|
||||
@ -353,6 +356,14 @@ PSA key policy: MAC, wrong algorithm
|
||||
depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY:PSA_ALG_HMAC(PSA_ALG_SHA_256):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_HMAC(PSA_ALG_SHA_224)
|
||||
|
||||
PSA key policy: MAC, alg=0 in policy
|
||||
depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY:0:PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_HMAC(PSA_ALG_SHA_256)
|
||||
|
||||
PSA key policy: MAC, ANY_HASH in policy is not meaningful
|
||||
depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY:PSA_ALG_HMAC(PSA_ALG_ANY_HASH):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_HMAC(PSA_ALG_SHA_256)
|
||||
|
||||
PSA key policy: MAC, sign but not verify
|
||||
depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C
|
||||
mac_key_policy:PSA_KEY_USAGE_SIGN:PSA_ALG_HMAC(PSA_ALG_SHA_256):PSA_KEY_TYPE_HMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_HMAC(PSA_ALG_SHA_256)
|
||||
@ -385,6 +396,10 @@ PSA key policy: cipher, neither encrypt nor decrypt
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_key_policy:0:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_CTR
|
||||
|
||||
PSA key policy: cipher, alg=0 in policy
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
|
||||
cipher_key_policy:PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:0:PSA_KEY_TYPE_AES:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":PSA_ALG_CTR
|
||||
|
||||
PSA key policy: AEAD, encrypt | decrypt
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CCM_C
|
||||
aead_key_policy:PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:PSA_ALG_CCM:PSA_KEY_TYPE_AES:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":13:16:PSA_ALG_CCM
|
||||
@ -393,6 +408,10 @@ PSA key policy: AEAD, wrong algorithm
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CCM_C:MBEDTLS_GCM_C
|
||||
aead_key_policy:PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:PSA_ALG_CCM:PSA_KEY_TYPE_AES:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":16:16:PSA_ALG_GCM
|
||||
|
||||
PSA key policy: AEAD, alg=0 in policy
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CCM_C
|
||||
aead_key_policy:PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:0:PSA_KEY_TYPE_AES:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":16:16:PSA_ALG_CCM
|
||||
|
||||
PSA key policy: AEAD, encrypt but not decrypt
|
||||
depends_on:MBEDTLS_AES_C:MBEDTLS_CCM_C
|
||||
aead_key_policy:PSA_KEY_USAGE_ENCRYPT:PSA_ALG_CCM:PSA_KEY_TYPE_AES:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":13:16:PSA_ALG_CCM
|
||||
@ -417,6 +436,10 @@ PSA key policy: asymmetric encryption, wrong algorithm (OAEP with different hash
|
||||
depends_on:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V21:MBEDTLS_SHA256_C
|
||||
asymmetric_encryption_key_policy:PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:PSA_ALG_RSA_OAEP(PSA_ALG_SHA_224):PSA_KEY_TYPE_RSA_KEY_PAIR:"3082013b020100024100ee2b131d6b1818a94ca8e91c42387eb15a7c271f57b89e7336b144d4535b16c83097ecdefbbb92d1b5313b5a37214d0e8f25922dca778b424b25295fc8a1a7070203010001024100978ac8eadb0dc6035347d6aba8671215ff21283385396f7897c04baf5e2a835f3b53ef80a82ed36ae687a925380b55a0c73eb85656e989dcf0ed7fb4887024e1022100fdad8e1c6853563f8b921d2d112462ae7d6b176082d2ba43e87e1a37fc1a8b33022100f0592cf4c55ba44307b18981bcdbda376c51e590ffa5345ba866f6962dca94dd02201995f1a967d44ff4a4cd1de837bc65bf97a2bf7eda730a9a62cea53254591105022027f96cf4b8ee68ff8d04062ec1ce7f18c0b74e4b3379b29f9bfea3fc8e592731022100cefa6d220496b43feb83194255d8fb930afcf46f36606e3aa0eb7a93ad88c10c":PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256)
|
||||
|
||||
PSA key policy: asymmetric encryption, alg=0 in policy
|
||||
depends_on:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15
|
||||
asymmetric_encryption_key_policy:PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:0:PSA_KEY_TYPE_RSA_KEY_PAIR:"3082013b020100024100ee2b131d6b1818a94ca8e91c42387eb15a7c271f57b89e7336b144d4535b16c83097ecdefbbb92d1b5313b5a37214d0e8f25922dca778b424b25295fc8a1a7070203010001024100978ac8eadb0dc6035347d6aba8671215ff21283385396f7897c04baf5e2a835f3b53ef80a82ed36ae687a925380b55a0c73eb85656e989dcf0ed7fb4887024e1022100fdad8e1c6853563f8b921d2d112462ae7d6b176082d2ba43e87e1a37fc1a8b33022100f0592cf4c55ba44307b18981bcdbda376c51e590ffa5345ba866f6962dca94dd02201995f1a967d44ff4a4cd1de837bc65bf97a2bf7eda730a9a62cea53254591105022027f96cf4b8ee68ff8d04062ec1ce7f18c0b74e4b3379b29f9bfea3fc8e592731022100cefa6d220496b43feb83194255d8fb930afcf46f36606e3aa0eb7a93ad88c10c":PSA_ALG_RSA_PKCS1V15_CRYPT
|
||||
|
||||
PSA key policy: asymmetric encryption, ANY_HASH in policy is not meaningful
|
||||
depends_on:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V21:MBEDTLS_SHA256_C
|
||||
asymmetric_encryption_key_policy:PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:PSA_ALG_RSA_OAEP(PSA_ALG_ANY_HASH):PSA_KEY_TYPE_RSA_KEY_PAIR:"3082013b020100024100ee2b131d6b1818a94ca8e91c42387eb15a7c271f57b89e7336b144d4535b16c83097ecdefbbb92d1b5313b5a37214d0e8f25922dca778b424b25295fc8a1a7070203010001024100978ac8eadb0dc6035347d6aba8671215ff21283385396f7897c04baf5e2a835f3b53ef80a82ed36ae687a925380b55a0c73eb85656e989dcf0ed7fb4887024e1022100fdad8e1c6853563f8b921d2d112462ae7d6b176082d2ba43e87e1a37fc1a8b33022100f0592cf4c55ba44307b18981bcdbda376c51e590ffa5345ba866f6962dca94dd02201995f1a967d44ff4a4cd1de837bc65bf97a2bf7eda730a9a62cea53254591105022027f96cf4b8ee68ff8d04062ec1ce7f18c0b74e4b3379b29f9bfea3fc8e592731022100cefa6d220496b43feb83194255d8fb930afcf46f36606e3aa0eb7a93ad88c10c":PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256)
|
||||
@ -461,6 +484,10 @@ PSA key policy: asymmetric signature, wrong hash algorithm
|
||||
depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C
|
||||
asymmetric_signature_key_policy:PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY:PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256):PSA_KEY_TYPE_RSA_KEY_PAIR:"3082013b020100024100ee2b131d6b1818a94ca8e91c42387eb15a7c271f57b89e7336b144d4535b16c83097ecdefbbb92d1b5313b5a37214d0e8f25922dca778b424b25295fc8a1a7070203010001024100978ac8eadb0dc6035347d6aba8671215ff21283385396f7897c04baf5e2a835f3b53ef80a82ed36ae687a925380b55a0c73eb85656e989dcf0ed7fb4887024e1022100fdad8e1c6853563f8b921d2d112462ae7d6b176082d2ba43e87e1a37fc1a8b33022100f0592cf4c55ba44307b18981bcdbda376c51e590ffa5345ba866f6962dca94dd02201995f1a967d44ff4a4cd1de837bc65bf97a2bf7eda730a9a62cea53254591105022027f96cf4b8ee68ff8d04062ec1ce7f18c0b74e4b3379b29f9bfea3fc8e592731022100cefa6d220496b43feb83194255d8fb930afcf46f36606e3aa0eb7a93ad88c10c":PSA_ALG_RSA_PKCS1V15_SIGN_RAW:0
|
||||
|
||||
PSA key policy: asymmetric signature, alg=0 in policy
|
||||
depends_on:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15
|
||||
asymmetric_signature_key_policy:PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY:0:PSA_KEY_TYPE_RSA_KEY_PAIR:"3082013b020100024100ee2b131d6b1818a94ca8e91c42387eb15a7c271f57b89e7336b144d4535b16c83097ecdefbbb92d1b5313b5a37214d0e8f25922dca778b424b25295fc8a1a7070203010001024100978ac8eadb0dc6035347d6aba8671215ff21283385396f7897c04baf5e2a835f3b53ef80a82ed36ae687a925380b55a0c73eb85656e989dcf0ed7fb4887024e1022100fdad8e1c6853563f8b921d2d112462ae7d6b176082d2ba43e87e1a37fc1a8b33022100f0592cf4c55ba44307b18981bcdbda376c51e590ffa5345ba866f6962dca94dd02201995f1a967d44ff4a4cd1de837bc65bf97a2bf7eda730a9a62cea53254591105022027f96cf4b8ee68ff8d04062ec1ce7f18c0b74e4b3379b29f9bfea3fc8e592731022100cefa6d220496b43feb83194255d8fb930afcf46f36606e3aa0eb7a93ad88c10c":PSA_ALG_RSA_PKCS1V15_SIGN_RAW:0
|
||||
|
||||
PSA key policy: asymmetric signature, sign but not verify
|
||||
depends_on:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15
|
||||
asymmetric_signature_key_policy:PSA_KEY_USAGE_SIGN:PSA_ALG_RSA_PKCS1V15_SIGN_RAW:PSA_KEY_TYPE_RSA_KEY_PAIR:"3082013b020100024100ee2b131d6b1818a94ca8e91c42387eb15a7c271f57b89e7336b144d4535b16c83097ecdefbbb92d1b5313b5a37214d0e8f25922dca778b424b25295fc8a1a7070203010001024100978ac8eadb0dc6035347d6aba8671215ff21283385396f7897c04baf5e2a835f3b53ef80a82ed36ae687a925380b55a0c73eb85656e989dcf0ed7fb4887024e1022100fdad8e1c6853563f8b921d2d112462ae7d6b176082d2ba43e87e1a37fc1a8b33022100f0592cf4c55ba44307b18981bcdbda376c51e590ffa5345ba866f6962dca94dd02201995f1a967d44ff4a4cd1de837bc65bf97a2bf7eda730a9a62cea53254591105022027f96cf4b8ee68ff8d04062ec1ce7f18c0b74e4b3379b29f9bfea3fc8e592731022100cefa6d220496b43feb83194255d8fb930afcf46f36606e3aa0eb7a93ad88c10c":PSA_ALG_RSA_PKCS1V15_SIGN_RAW:1
|
||||
|
@ -1113,6 +1113,23 @@ exit:
|
||||
return( ok );
|
||||
}
|
||||
|
||||
/* Assert that a key isn't reported as having a slot number. */
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
||||
#define ASSERT_NO_SLOT_NUMBER( attributes ) \
|
||||
do \
|
||||
{ \
|
||||
psa_key_slot_number_t ASSERT_NO_SLOT_NUMBER_slot_number; \
|
||||
TEST_EQUAL( psa_get_key_slot_number( \
|
||||
attributes, \
|
||||
&ASSERT_NO_SLOT_NUMBER_slot_number ), \
|
||||
PSA_ERROR_INVALID_ARGUMENT ); \
|
||||
} \
|
||||
while( 0 )
|
||||
#else /* MBEDTLS_PSA_CRYPTO_SE_C */
|
||||
#define ASSERT_NO_SLOT_NUMBER( attributes ) \
|
||||
( (void) 0 )
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
|
||||
|
||||
/* An overapproximation of the amount of storage needed for a key of the
|
||||
* given type and with the given content. The API doesn't make it easy
|
||||
* to find a good value for the size. The current implementation doesn't
|
||||
@ -1214,6 +1231,46 @@ void persistence_attributes( int id1_arg, int lifetime_arg, int id2_arg,
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_SE_C */
|
||||
void slot_number_attribute( )
|
||||
{
|
||||
psa_key_slot_number_t slot_number = 0xdeadbeef;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
/* Initially, there is no slot number. */
|
||||
TEST_EQUAL( psa_get_key_slot_number( &attributes, &slot_number ),
|
||||
PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
/* Test setting a slot number. */
|
||||
psa_set_key_slot_number( &attributes, 0 );
|
||||
PSA_ASSERT( psa_get_key_slot_number( &attributes, &slot_number ) );
|
||||
TEST_EQUAL( slot_number, 0 );
|
||||
|
||||
/* Test changing the slot number. */
|
||||
psa_set_key_slot_number( &attributes, 42 );
|
||||
PSA_ASSERT( psa_get_key_slot_number( &attributes, &slot_number ) );
|
||||
TEST_EQUAL( slot_number, 42 );
|
||||
|
||||
/* Test clearing the slot number. */
|
||||
psa_clear_key_slot_number( &attributes );
|
||||
TEST_EQUAL( psa_get_key_slot_number( &attributes, &slot_number ),
|
||||
PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
/* Clearing again should have no effect. */
|
||||
psa_clear_key_slot_number( &attributes );
|
||||
TEST_EQUAL( psa_get_key_slot_number( &attributes, &slot_number ),
|
||||
PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
/* Test that reset clears the slot number. */
|
||||
psa_set_key_slot_number( &attributes, 42 );
|
||||
PSA_ASSERT( psa_get_key_slot_number( &attributes, &slot_number ) );
|
||||
TEST_EQUAL( slot_number, 42 );
|
||||
psa_reset_key_attributes( &attributes );
|
||||
TEST_EQUAL( psa_get_key_slot_number( &attributes, &slot_number ),
|
||||
PSA_ERROR_INVALID_ARGUMENT );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void import_with_policy( int type_arg,
|
||||
int usage_arg, int alg_arg,
|
||||
@ -1246,6 +1303,7 @@ void import_with_policy( int type_arg,
|
||||
TEST_EQUAL( psa_get_key_type( &got_attributes ), type );
|
||||
TEST_EQUAL( psa_get_key_usage_flags( &got_attributes ), usage );
|
||||
TEST_EQUAL( psa_get_key_algorithm( &got_attributes ), alg );
|
||||
ASSERT_NO_SLOT_NUMBER( &got_attributes );
|
||||
|
||||
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||
test_operations_on_invalid_handle( handle );
|
||||
@ -1284,6 +1342,7 @@ void import_with_data( data_t *data, int type_arg,
|
||||
TEST_EQUAL( psa_get_key_type( &got_attributes ), type );
|
||||
if( attr_bits != 0 )
|
||||
TEST_EQUAL( attr_bits, psa_get_key_bits( &got_attributes ) );
|
||||
ASSERT_NO_SLOT_NUMBER( &got_attributes );
|
||||
|
||||
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||
test_operations_on_invalid_handle( handle );
|
||||
@ -1328,6 +1387,7 @@ void import_large_key( int type_arg, int byte_size_arg,
|
||||
TEST_EQUAL( psa_get_key_type( &attributes ), type );
|
||||
TEST_EQUAL( psa_get_key_bits( &attributes ),
|
||||
PSA_BYTES_TO_BITS( byte_size ) );
|
||||
ASSERT_NO_SLOT_NUMBER( &attributes );
|
||||
memset( buffer, 0, byte_size + 1 );
|
||||
PSA_ASSERT( psa_export_key( handle, buffer, byte_size, &n ) );
|
||||
for( n = 0; n < byte_size; n++ )
|
||||
@ -1420,6 +1480,7 @@ void import_export( data_t *data,
|
||||
PSA_ASSERT( psa_get_key_attributes( handle, &got_attributes ) );
|
||||
TEST_EQUAL( psa_get_key_type( &got_attributes ), type );
|
||||
TEST_EQUAL( psa_get_key_bits( &got_attributes ), (size_t) expected_bits );
|
||||
ASSERT_NO_SLOT_NUMBER( &got_attributes );
|
||||
|
||||
/* Export the key */
|
||||
status = psa_export_key( handle,
|
||||
|
@ -39,59 +39,125 @@ key_creation_import_export:0:1
|
||||
SE key import-export, check after restart (slot 3)
|
||||
key_creation_import_export:3:1
|
||||
|
||||
Key creation smoke test: AES-CTR
|
||||
key_creation_smoke:PSA_KEY_TYPE_AES:PSA_ALG_CTR:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
Key creation in a specific slot (0)
|
||||
key_creation_in_chosen_slot:0:0:PSA_SUCCESS
|
||||
|
||||
Key creation smoke test: AES-CBC
|
||||
key_creation_smoke:PSA_KEY_TYPE_AES:PSA_ALG_CBC_NO_PADDING:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
Key creation in a specific slot (max)
|
||||
key_creation_in_chosen_slot:ARRAY_LENGTH( ram_slots ) - 1:0:PSA_SUCCESS
|
||||
|
||||
Key creation smoke test: AES-CMAC
|
||||
key_creation_smoke:PSA_KEY_TYPE_AES:PSA_ALG_CMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
Key creation in a specific slot (0, restart)
|
||||
key_creation_in_chosen_slot:0:1:PSA_SUCCESS
|
||||
|
||||
Key creation smoke test: AES-CCM
|
||||
key_creation_smoke:PSA_KEY_TYPE_AES:PSA_ALG_CCM:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
Key creation in a specific slot (max, restart)
|
||||
key_creation_in_chosen_slot:ARRAY_LENGTH( ram_slots ) - 1:1:PSA_SUCCESS
|
||||
|
||||
Key creation smoke test: AES-GCM
|
||||
key_creation_smoke:PSA_KEY_TYPE_AES:PSA_ALG_GCM:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
Key creation in a specific slot (too large)
|
||||
key_creation_in_chosen_slot:ARRAY_LENGTH( ram_slots ):0:PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
Key creation smoke test: CAMELLIA-CTR
|
||||
key_creation_smoke:PSA_KEY_TYPE_CAMELLIA:PSA_ALG_CTR:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
Key import smoke test: AES-CTR
|
||||
import_key_smoke:PSA_KEY_TYPE_AES:PSA_ALG_CTR:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
|
||||
Key creation smoke test: CAMELLIA-CBC
|
||||
key_creation_smoke:PSA_KEY_TYPE_CAMELLIA:PSA_ALG_CBC_NO_PADDING:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
Key import smoke test: AES-CBC
|
||||
import_key_smoke:PSA_KEY_TYPE_AES:PSA_ALG_CBC_NO_PADDING:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
|
||||
Key creation smoke test: CAMELLIA-CMAC
|
||||
key_creation_smoke:PSA_KEY_TYPE_CAMELLIA:PSA_ALG_CMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
Key import smoke test: AES-CMAC
|
||||
import_key_smoke:PSA_KEY_TYPE_AES:PSA_ALG_CMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
|
||||
Key creation smoke test: CAMELLIA-CCM
|
||||
key_creation_smoke:PSA_KEY_TYPE_CAMELLIA:PSA_ALG_GCM:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
Key import smoke test: AES-CCM
|
||||
import_key_smoke:PSA_KEY_TYPE_AES:PSA_ALG_CCM:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
|
||||
Key creation smoke test: CAMELLIA-CCM
|
||||
key_creation_smoke:PSA_KEY_TYPE_CAMELLIA:PSA_ALG_GCM:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
Key import smoke test: AES-GCM
|
||||
import_key_smoke:PSA_KEY_TYPE_AES:PSA_ALG_GCM:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
|
||||
Key creation smoke test: HMAC-SHA-256
|
||||
key_creation_smoke:PSA_KEY_TYPE_HMAC:PSA_ALG_HMAC( PSA_ALG_SHA_256 ):"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
Key import smoke test: CAMELLIA-CTR
|
||||
import_key_smoke:PSA_KEY_TYPE_CAMELLIA:PSA_ALG_CTR:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
|
||||
Key creation smoke test: HKDF-SHA-256
|
||||
key_creation_smoke:PSA_KEY_TYPE_DERIVE:PSA_ALG_HKDF( PSA_ALG_SHA_256 ):"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
Key import smoke test: CAMELLIA-CBC
|
||||
import_key_smoke:PSA_KEY_TYPE_CAMELLIA:PSA_ALG_CBC_NO_PADDING:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
|
||||
Key creation smoke test: RSA PKCS#1v1.5 signature
|
||||
key_creation_smoke:PSA_KEY_TYPE_RSA_KEY_PAIR:PSA_ALG_RSA_PKCS1V15_SIGN_RAW:"30818902818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc30203010001"
|
||||
Key import smoke test: CAMELLIA-CMAC
|
||||
import_key_smoke:PSA_KEY_TYPE_CAMELLIA:PSA_ALG_CMAC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
|
||||
Key creation smoke test: RSA PKCS#1v1.5 encryption
|
||||
key_creation_smoke:PSA_KEY_TYPE_RSA_KEY_PAIR:PSA_ALG_RSA_PKCS1V15_CRYPT:"30818902818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc30203010001"
|
||||
Key import smoke test: CAMELLIA-CCM
|
||||
import_key_smoke:PSA_KEY_TYPE_CAMELLIA:PSA_ALG_GCM:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
|
||||
Key creation smoke test: RSA OAEP encryption
|
||||
key_creation_smoke:PSA_KEY_TYPE_RSA_KEY_PAIR:PSA_ALG_RSA_OAEP( PSA_ALG_SHA_256 ):"30818902818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc30203010001"
|
||||
Key import smoke test: CAMELLIA-CCM
|
||||
import_key_smoke:PSA_KEY_TYPE_CAMELLIA:PSA_ALG_GCM:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
|
||||
Key creation smoke test: ECDSA secp256r1
|
||||
key_creation_smoke:PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 ):PSA_ALG_ECDSA_ANY:"49c9a8c18c4b885638c431cf1df1c994131609b580d4fd43a0cab17db2f13eee"
|
||||
Key import smoke test: HMAC-SHA-256
|
||||
import_key_smoke:PSA_KEY_TYPE_HMAC:PSA_ALG_HMAC( PSA_ALG_SHA_256 ):"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
|
||||
Key creation smoke test: ECDH secp256r1
|
||||
key_creation_smoke:PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 ):PSA_ALG_ECDH:"49c9a8c18c4b885638c431cf1df1c994131609b580d4fd43a0cab17db2f13eee"
|
||||
Key import smoke test: HKDF-SHA-256
|
||||
import_key_smoke:PSA_KEY_TYPE_DERIVE:PSA_ALG_HKDF( PSA_ALG_SHA_256 ):"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
|
||||
Key creation smoke test: ECDH secp256r1 with HKDF
|
||||
key_creation_smoke:PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 ):PSA_ALG_KEY_AGREEMENT( PSA_ALG_ECDH, PSA_ALG_HKDF( PSA_ALG_SHA_256 ) ):"49c9a8c18c4b885638c431cf1df1c994131609b580d4fd43a0cab17db2f13eee"
|
||||
Key import smoke test: RSA PKCS#1v1.5 signature
|
||||
import_key_smoke:PSA_KEY_TYPE_RSA_KEY_PAIR:PSA_ALG_RSA_PKCS1V15_SIGN_RAW:"30818902818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc30203010001"
|
||||
|
||||
Key import smoke test: RSA PKCS#1v1.5 encryption
|
||||
import_key_smoke:PSA_KEY_TYPE_RSA_KEY_PAIR:PSA_ALG_RSA_PKCS1V15_CRYPT:"30818902818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc30203010001"
|
||||
|
||||
Key import smoke test: RSA OAEP encryption
|
||||
import_key_smoke:PSA_KEY_TYPE_RSA_KEY_PAIR:PSA_ALG_RSA_OAEP( PSA_ALG_SHA_256 ):"30818902818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc30203010001"
|
||||
|
||||
Key import smoke test: ECDSA secp256r1
|
||||
import_key_smoke:PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 ):PSA_ALG_ECDSA_ANY:"49c9a8c18c4b885638c431cf1df1c994131609b580d4fd43a0cab17db2f13eee"
|
||||
|
||||
Key import smoke test: ECDH secp256r1
|
||||
import_key_smoke:PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 ):PSA_ALG_ECDH:"49c9a8c18c4b885638c431cf1df1c994131609b580d4fd43a0cab17db2f13eee"
|
||||
|
||||
Key import smoke test: ECDH secp256r1 with HKDF
|
||||
import_key_smoke:PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 ):PSA_ALG_KEY_AGREEMENT( PSA_ALG_ECDH, PSA_ALG_HKDF( PSA_ALG_SHA_256 ) ):"49c9a8c18c4b885638c431cf1df1c994131609b580d4fd43a0cab17db2f13eee"
|
||||
|
||||
Generate key: not supported
|
||||
generate_key_not_supported:PSA_KEY_TYPE_AES:128
|
||||
|
||||
Key generation smoke test: AES-128-CTR
|
||||
generate_key_smoke:PSA_KEY_TYPE_AES:128:PSA_ALG_CTR
|
||||
|
||||
Key generation smoke test: AES-256-CTR
|
||||
generate_key_smoke:PSA_KEY_TYPE_AES:128:PSA_ALG_CTR
|
||||
|
||||
Key generation smoke test: HMAC-SHA-256
|
||||
generate_key_smoke:PSA_KEY_TYPE_HMAC:256:PSA_ALG_HMAC( PSA_ALG_SHA_256 )
|
||||
|
||||
Key registration: smoke test
|
||||
register_key_smoke_test:MIN_DRIVER_LIFETIME:-1:PSA_SUCCESS
|
||||
|
||||
Key registration: invalid lifetime (volatile)
|
||||
register_key_smoke_test:PSA_KEY_LIFETIME_VOLATILE:-1:PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
Key registration: invalid lifetime (internal storage)
|
||||
register_key_smoke_test:PSA_KEY_LIFETIME_PERSISTENT:-1:PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
Key registration: invalid lifetime (no registered driver)
|
||||
register_key_smoke_test:MIN_DRIVER_LIFETIME + 1:-1:PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
Key registration: with driver validation (accepted)
|
||||
register_key_smoke_test:MIN_DRIVER_LIFETIME:1:PSA_SUCCESS
|
||||
|
||||
Key registration: with driver validation (rejected)
|
||||
register_key_smoke_test:MIN_DRIVER_LIFETIME:0:PSA_ERROR_NOT_PERMITTED
|
||||
|
||||
Import-sign-verify: sign in driver, ECDSA
|
||||
depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
sign_verify:SIGN_IN_DRIVER_AND_PARALLEL_CREATION:PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 ):PSA_ALG_ECDSA_ANY:0:"49c9a8c18c4b885638c431cf1df1c994131609b580d4fd43a0cab17db2f13eee":"54686973206973206e6f74206120686173682e"
|
||||
|
||||
Import-sign-verify: sign in driver then export_public, ECDSA
|
||||
depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
sign_verify:SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC:PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 ):PSA_ALG_ECDSA_ANY:0:"49c9a8c18c4b885638c431cf1df1c994131609b580d4fd43a0cab17db2f13eee":"54686973206973206e6f74206120686173682e"
|
||||
|
||||
Import-sign-verify: sign in software, ECDSA
|
||||
depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
sign_verify:SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION:PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 ):PSA_ALG_ECDSA_ANY:0:"49c9a8c18c4b885638c431cf1df1c994131609b580d4fd43a0cab17db2f13eee":"54686973206973206e6f74206120686173682e"
|
||||
|
||||
Generate-sign-verify: sign in driver, ECDSA
|
||||
depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
sign_verify:SIGN_IN_DRIVER_AND_PARALLEL_CREATION:PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 ):PSA_ALG_ECDSA_ANY:256:"49c9a8c18c4b885638c431cf1df1c994131609b580d4fd43a0cab17db2f13eee":"54686973206973206e6f74206120686173682e"
|
||||
|
||||
Generate-sign-verify: sign in driver then export_public, ECDSA
|
||||
depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
sign_verify:SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC:PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 ):PSA_ALG_ECDSA_ANY:256:"49c9a8c18c4b885638c431cf1df1c994131609b580d4fd43a0cab17db2f13eee":"54686973206973206e6f74206120686173682e"
|
||||
|
||||
Generate-sign-verify: sign in software, ECDSA
|
||||
depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
sign_verify:SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION:PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 ):PSA_ALG_ECDSA_ANY:256:"49c9a8c18c4b885638c431cf1df1c994131609b580d4fd43a0cab17db2f13eee":"54686973206973206e6f74206120686173682e"
|
||||
|
@ -18,11 +18,13 @@
|
||||
* This is probably a bug in the library. */
|
||||
#define PSA_ERROR_DETECTED_BY_DRIVER ((psa_status_t)( -500 ))
|
||||
|
||||
/** Like #TEST_ASSERT for use in a driver method.
|
||||
/** Like #TEST_ASSERT for use in a driver method, with no cleanup.
|
||||
*
|
||||
* If an error happens, this macro returns from the calling function.
|
||||
*
|
||||
* Use this macro to assert on guarantees provided by the core.
|
||||
*/
|
||||
#define DRIVER_ASSERT( TEST ) \
|
||||
#define DRIVER_ASSERT_RETURN( TEST ) \
|
||||
do { \
|
||||
if( ! (TEST) ) \
|
||||
{ \
|
||||
@ -31,20 +33,86 @@
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
/** Like #TEST_ASSERT for use in a driver method, with cleanup.
|
||||
*
|
||||
* In case of error, this macro sets `status` and jumps to the
|
||||
* label `exit`.
|
||||
*
|
||||
* Use this macro to assert on guarantees provided by the core.
|
||||
*/
|
||||
#define DRIVER_ASSERT( TEST ) \
|
||||
do { \
|
||||
if( ! (TEST) ) \
|
||||
{ \
|
||||
test_fail( #TEST, __LINE__, __FILE__ ); \
|
||||
status = PSA_ERROR_DETECTED_BY_DRIVER; \
|
||||
goto exit; \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
/** Like #PSA_ASSERT for a PSA API call that calls a driver underneath.
|
||||
*
|
||||
* Run the code \p expr. If this returns \p expected_status,
|
||||
* do nothing. If this returns #PSA_ERROR_DETECTED_BY_DRIVER,
|
||||
* jump directly to the `exit` label. If this returns any other
|
||||
* status, call test_fail() then jump to `exit`.
|
||||
*
|
||||
* The special case for #PSA_ERROR_DETECTED_BY_DRIVER is because in this
|
||||
* case, the test driver code is expected to have called test_fail()
|
||||
* already, so we make sure not to overwrite the failure information.
|
||||
*/
|
||||
#define PSA_ASSERT_VIA_DRIVER( expr, expected_status ) \
|
||||
do { \
|
||||
psa_status_t PSA_ASSERT_VIA_DRIVER_status = ( expr ); \
|
||||
if( PSA_ASSERT_VIA_DRIVER_status == PSA_ERROR_DETECTED_BY_DRIVER ) \
|
||||
goto exit; \
|
||||
if( PSA_ASSERT_VIA_DRIVER_status != ( expected_status ) ) \
|
||||
{ \
|
||||
test_fail( #expr, __LINE__, __FILE__ ); \
|
||||
goto exit; \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
/* Miscellaneous driver methods */
|
||||
/****************************************************************/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
psa_key_slot_number_t slot_number;
|
||||
psa_key_creation_method_t method;
|
||||
psa_status_t status;
|
||||
} validate_slot_number_directions_t;
|
||||
static validate_slot_number_directions_t validate_slot_number_directions;
|
||||
|
||||
/* Validate a choice of slot number as directed. */
|
||||
static psa_status_t validate_slot_number_as_directed(
|
||||
psa_drv_se_context_t *context,
|
||||
const psa_key_attributes_t *attributes,
|
||||
psa_key_creation_method_t method,
|
||||
psa_key_slot_number_t slot_number )
|
||||
{
|
||||
(void) context;
|
||||
(void) attributes;
|
||||
DRIVER_ASSERT_RETURN( slot_number ==
|
||||
validate_slot_number_directions.slot_number );
|
||||
DRIVER_ASSERT_RETURN( method ==
|
||||
validate_slot_number_directions.method );
|
||||
return( validate_slot_number_directions.status );
|
||||
}
|
||||
|
||||
/* Allocate slot numbers with a monotonic counter. */
|
||||
static psa_status_t counter_allocate( psa_drv_se_context_t *context,
|
||||
void *persistent_data,
|
||||
const psa_key_attributes_t *attributes,
|
||||
psa_key_creation_method_t method,
|
||||
psa_key_slot_number_t *slot_number )
|
||||
{
|
||||
psa_key_slot_number_t *p_counter = persistent_data;
|
||||
(void) attributes;
|
||||
(void) method;
|
||||
if( context->persistent_data_size != sizeof( psa_key_slot_number_t ) )
|
||||
return( PSA_ERROR_DETECTED_BY_DRIVER );
|
||||
++*p_counter;
|
||||
@ -57,27 +125,54 @@ static psa_status_t counter_allocate( psa_drv_se_context_t *context,
|
||||
/* Null import: do nothing, but pretend it worked. */
|
||||
static psa_status_t null_import( psa_drv_se_context_t *context,
|
||||
psa_key_slot_number_t slot_number,
|
||||
psa_key_lifetime_t lifetime,
|
||||
psa_key_type_t type,
|
||||
psa_algorithm_t algorithm,
|
||||
psa_key_usage_t usage,
|
||||
const uint8_t *p_data,
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *data,
|
||||
size_t data_length,
|
||||
size_t *bits )
|
||||
{
|
||||
(void) context;
|
||||
(void) slot_number;
|
||||
(void) lifetime;
|
||||
(void) type;
|
||||
(void) algorithm;
|
||||
(void) usage;
|
||||
(void) p_data;
|
||||
(void) attributes;
|
||||
(void) data;
|
||||
/* We're supposed to return a key size. Return one that's correct for
|
||||
* plain data keys. */
|
||||
*bits = PSA_BYTES_TO_BITS( data_length );
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
/* Null generate: do nothing, but pretend it worked. */
|
||||
static psa_status_t null_generate( psa_drv_se_context_t *context,
|
||||
psa_key_slot_number_t slot_number,
|
||||
const psa_key_attributes_t *attributes,
|
||||
uint8_t *pubkey,
|
||||
size_t pubkey_size,
|
||||
size_t *pubkey_length )
|
||||
{
|
||||
(void) context;
|
||||
(void) slot_number;
|
||||
(void) attributes;
|
||||
|
||||
DRIVER_ASSERT_RETURN( *pubkey_length == 0 );
|
||||
if( ! PSA_KEY_TYPE_IS_KEY_PAIR( psa_get_key_type( attributes ) ) )
|
||||
{
|
||||
DRIVER_ASSERT_RETURN( pubkey == NULL );
|
||||
DRIVER_ASSERT_RETURN( pubkey_size == 0 );
|
||||
}
|
||||
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
/* Null destroy: do nothing, but pretend it worked. */
|
||||
static psa_status_t null_destroy( psa_drv_se_context_t *context,
|
||||
void *persistent_data,
|
||||
psa_key_slot_number_t slot_number )
|
||||
{
|
||||
(void) context;
|
||||
(void) persistent_data;
|
||||
(void) slot_number;
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
@ -106,44 +201,135 @@ static void ram_slots_reset( void )
|
||||
ram_min_slot = 0;
|
||||
}
|
||||
|
||||
/* Common parts of key creation.
|
||||
*
|
||||
* In case of error, zero out ram_slots[slot_number]. But don't
|
||||
* do that if the error is PSA_ERROR_DETECTED_BY_DRIVER: in this case
|
||||
* you don't need to clean up (ram_slot_reset() will take care of it
|
||||
* in the test case function's cleanup code) and it might be wrong
|
||||
* (if slot_number is invalid).
|
||||
*/
|
||||
static psa_status_t ram_create_common( psa_drv_se_context_t *context,
|
||||
psa_key_slot_number_t slot_number,
|
||||
const psa_key_attributes_t *attributes,
|
||||
size_t required_storage )
|
||||
{
|
||||
(void) context;
|
||||
DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) );
|
||||
|
||||
ram_slots[slot_number].lifetime = psa_get_key_lifetime( attributes );
|
||||
ram_slots[slot_number].type = psa_get_key_type( attributes );
|
||||
ram_slots[slot_number].bits = psa_get_key_bits( attributes );
|
||||
|
||||
if( required_storage > sizeof( ram_slots[slot_number].content ) )
|
||||
{
|
||||
memset( &ram_slots[slot_number], 0, sizeof( ram_slots[slot_number] ) );
|
||||
return( PSA_ERROR_INSUFFICIENT_STORAGE );
|
||||
}
|
||||
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
/* This function does everything except actually generating key material.
|
||||
* After calling it, you must copy the desired key material to
|
||||
* ram_slots[slot_number].content. */
|
||||
static psa_status_t ram_fake_generate( psa_drv_se_context_t *context,
|
||||
psa_key_slot_number_t slot_number,
|
||||
const psa_key_attributes_t *attributes,
|
||||
uint8_t *pubkey,
|
||||
size_t pubkey_size,
|
||||
size_t *pubkey_length )
|
||||
{
|
||||
psa_status_t status;
|
||||
size_t required_storage =
|
||||
PSA_KEY_EXPORT_MAX_SIZE( psa_get_key_type( attributes ),
|
||||
psa_get_key_bits( attributes ) );
|
||||
|
||||
DRIVER_ASSERT_RETURN( *pubkey_length == 0 );
|
||||
if( ! PSA_KEY_TYPE_IS_KEY_PAIR( psa_get_key_type( attributes ) ) )
|
||||
{
|
||||
DRIVER_ASSERT_RETURN( pubkey == NULL );
|
||||
DRIVER_ASSERT_RETURN( pubkey_size == 0 );
|
||||
}
|
||||
|
||||
status = ram_create_common( context, slot_number, attributes,
|
||||
required_storage );
|
||||
return( status );
|
||||
}
|
||||
|
||||
static psa_status_t ram_import( psa_drv_se_context_t *context,
|
||||
psa_key_slot_number_t slot_number,
|
||||
psa_key_lifetime_t lifetime,
|
||||
psa_key_type_t type,
|
||||
psa_algorithm_t algorithm,
|
||||
psa_key_usage_t usage,
|
||||
const uint8_t *p_data,
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *data,
|
||||
size_t data_length,
|
||||
size_t *bits )
|
||||
{
|
||||
(void) context;
|
||||
DRIVER_ASSERT( slot_number < ARRAY_LENGTH( ram_slots ) );
|
||||
if( data_length > sizeof( ram_slots[slot_number].content ) )
|
||||
return( PSA_ERROR_INSUFFICIENT_STORAGE );
|
||||
ram_slots[slot_number].lifetime = lifetime;
|
||||
ram_slots[slot_number].type = type;
|
||||
ram_slots[slot_number].bits = PSA_BYTES_TO_BITS( data_length );
|
||||
*bits = PSA_BYTES_TO_BITS( data_length );
|
||||
(void) algorithm;
|
||||
(void) usage;
|
||||
memcpy( ram_slots[slot_number].content, p_data, data_length );
|
||||
psa_key_type_t type = psa_get_key_type( attributes );
|
||||
psa_status_t status = ram_create_common( context, slot_number, attributes,
|
||||
data_length );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
|
||||
/* The RAM driver only works for certain key types: raw keys,
|
||||
* and ECC key pairs. This is true in particular of the bit-size
|
||||
* calculation here. */
|
||||
if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) )
|
||||
*bits = PSA_BYTES_TO_BITS( data_length );
|
||||
else if ( PSA_KEY_TYPE_IS_ECC_KEY_PAIR( type ) )
|
||||
*bits = PSA_ECC_CURVE_BITS( PSA_KEY_TYPE_GET_CURVE( type ) );
|
||||
else
|
||||
{
|
||||
memset( &ram_slots[slot_number], 0, sizeof( ram_slots[slot_number] ) );
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
}
|
||||
|
||||
ram_slots[slot_number].bits = *bits;
|
||||
memcpy( ram_slots[slot_number].content, data, data_length );
|
||||
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
static psa_status_t ram_export( psa_drv_se_context_t *context,
|
||||
psa_key_slot_number_t slot_number,
|
||||
uint8_t *p_data,
|
||||
uint8_t *data,
|
||||
size_t data_size,
|
||||
size_t *p_data_length )
|
||||
size_t *data_length )
|
||||
{
|
||||
size_t actual_size;
|
||||
(void) context;
|
||||
DRIVER_ASSERT( slot_number < ARRAY_LENGTH( ram_slots ) );
|
||||
DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) );
|
||||
actual_size = PSA_BITS_TO_BYTES( ram_slots[slot_number].bits );
|
||||
if( actual_size > data_size )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
*p_data_length = actual_size;
|
||||
memcpy( p_data, ram_slots[slot_number].content, actual_size );
|
||||
*data_length = actual_size;
|
||||
memcpy( data, ram_slots[slot_number].content, actual_size );
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
static psa_status_t ram_export_public( psa_drv_se_context_t *context,
|
||||
psa_key_slot_number_t slot_number,
|
||||
uint8_t *data,
|
||||
size_t data_size,
|
||||
size_t *data_length )
|
||||
{
|
||||
psa_status_t status;
|
||||
psa_key_handle_t handle;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
(void) context;
|
||||
DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) );
|
||||
DRIVER_ASSERT_RETURN(
|
||||
PSA_KEY_TYPE_IS_KEY_PAIR( ram_slots[slot_number].type ) );
|
||||
|
||||
psa_set_key_type( &attributes, ram_slots[slot_number].type );
|
||||
status = psa_import_key( &attributes,
|
||||
ram_slots[slot_number].content,
|
||||
PSA_BITS_TO_BYTES( ram_slots[slot_number].bits ),
|
||||
&handle );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
status = psa_export_public_key( handle, data, data_size, data_length );
|
||||
psa_destroy_key( handle );
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
@ -152,8 +338,8 @@ static psa_status_t ram_destroy( psa_drv_se_context_t *context,
|
||||
psa_key_slot_number_t slot_number )
|
||||
{
|
||||
ram_slot_usage_t *slot_usage = persistent_data;
|
||||
DRIVER_ASSERT( context->persistent_data_size == sizeof( ram_slot_usage_t ) );
|
||||
DRIVER_ASSERT( slot_number < ARRAY_LENGTH( ram_slots ) );
|
||||
DRIVER_ASSERT_RETURN( context->persistent_data_size == sizeof( ram_slot_usage_t ) );
|
||||
DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) );
|
||||
memset( &ram_slots[slot_number], 0, sizeof( ram_slots[slot_number] ) );
|
||||
*slot_usage &= ~(ram_slot_usage_t)( 1 << slot_number );
|
||||
return( PSA_SUCCESS );
|
||||
@ -162,11 +348,13 @@ static psa_status_t ram_destroy( psa_drv_se_context_t *context,
|
||||
static psa_status_t ram_allocate( psa_drv_se_context_t *context,
|
||||
void *persistent_data,
|
||||
const psa_key_attributes_t *attributes,
|
||||
psa_key_creation_method_t method,
|
||||
psa_key_slot_number_t *slot_number )
|
||||
{
|
||||
ram_slot_usage_t *slot_usage = persistent_data;
|
||||
(void) attributes;
|
||||
DRIVER_ASSERT( context->persistent_data_size == sizeof( ram_slot_usage_t ) );
|
||||
(void) method;
|
||||
DRIVER_ASSERT_RETURN( context->persistent_data_size == sizeof( ram_slot_usage_t ) );
|
||||
for( *slot_number = ram_min_slot;
|
||||
*slot_number < ARRAY_LENGTH( ram_slots );
|
||||
++( *slot_number ) )
|
||||
@ -177,12 +365,103 @@ static psa_status_t ram_allocate( psa_drv_se_context_t *context,
|
||||
return( PSA_ERROR_INSUFFICIENT_STORAGE );
|
||||
}
|
||||
|
||||
static psa_status_t ram_validate_slot_number(
|
||||
psa_drv_se_context_t *context,
|
||||
const psa_key_attributes_t *attributes,
|
||||
psa_key_creation_method_t method,
|
||||
psa_key_slot_number_t slot_number )
|
||||
{
|
||||
(void) context;
|
||||
(void) attributes;
|
||||
(void) method;
|
||||
if( slot_number >= ARRAY_LENGTH( ram_slots ) )
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
static psa_status_t ram_sign( psa_drv_se_context_t *context,
|
||||
psa_key_slot_number_t slot_number,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *hash,
|
||||
size_t hash_length,
|
||||
uint8_t *signature,
|
||||
size_t signature_size,
|
||||
size_t *signature_length )
|
||||
{
|
||||
ram_slot_t *slot;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
|
||||
|
||||
(void) context;
|
||||
DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) );
|
||||
slot = &ram_slots[slot_number];
|
||||
|
||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN );
|
||||
psa_set_key_algorithm( &attributes, alg );
|
||||
psa_set_key_type( &attributes, slot->type );
|
||||
DRIVER_ASSERT( psa_import_key( &attributes,
|
||||
slot->content,
|
||||
PSA_BITS_TO_BYTES( slot->bits ),
|
||||
&handle ) == PSA_SUCCESS );
|
||||
status = psa_asymmetric_sign( handle, alg,
|
||||
hash, hash_length,
|
||||
signature, signature_size,
|
||||
signature_length );
|
||||
|
||||
exit:
|
||||
psa_destroy_key( handle );
|
||||
return( status );
|
||||
}
|
||||
|
||||
static psa_status_t ram_verify( psa_drv_se_context_t *context,
|
||||
psa_key_slot_number_t slot_number,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *hash,
|
||||
size_t hash_length,
|
||||
const uint8_t *signature,
|
||||
size_t signature_length )
|
||||
{
|
||||
ram_slot_t *slot;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
|
||||
|
||||
(void) context;
|
||||
DRIVER_ASSERT_RETURN( slot_number < ARRAY_LENGTH( ram_slots ) );
|
||||
slot = &ram_slots[slot_number];
|
||||
|
||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY );
|
||||
psa_set_key_algorithm( &attributes, alg );
|
||||
psa_set_key_type( &attributes, slot->type );
|
||||
DRIVER_ASSERT( psa_import_key( &attributes,
|
||||
slot->content,
|
||||
PSA_BITS_TO_BYTES( slot->bits ),
|
||||
&handle ) ==
|
||||
PSA_SUCCESS );
|
||||
status = psa_asymmetric_verify( handle, alg,
|
||||
hash, hash_length,
|
||||
signature, signature_length );
|
||||
|
||||
exit:
|
||||
psa_destroy_key( handle );
|
||||
return( status );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
/* Other test helper functions */
|
||||
/****************************************************************/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION,
|
||||
SIGN_IN_DRIVER_AND_PARALLEL_CREATION,
|
||||
SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC,
|
||||
} sign_verify_method_t;
|
||||
|
||||
/* Check that the attributes of a key reported by psa_get_key_attributes()
|
||||
* are consistent with the attributes used when creating the key. */
|
||||
static int check_key_attributes(
|
||||
@ -212,6 +491,31 @@ static int check_key_attributes(
|
||||
psa_get_key_bits( reference_attributes ) );
|
||||
}
|
||||
|
||||
{
|
||||
psa_key_slot_number_t actual_slot_number = 0xdeadbeef;
|
||||
psa_key_slot_number_t desired_slot_number = 0xb90cc011;
|
||||
psa_key_lifetime_t lifetime =
|
||||
psa_get_key_lifetime( &actual_attributes );
|
||||
psa_status_t status = psa_get_key_slot_number( &actual_attributes,
|
||||
&actual_slot_number );
|
||||
if( lifetime < MIN_DRIVER_LIFETIME )
|
||||
{
|
||||
/* The key is not in a secure element. */
|
||||
TEST_EQUAL( status, PSA_ERROR_INVALID_ARGUMENT );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The key is in a secure element. If it had been created
|
||||
* in a specific slot, check that it is reported there. */
|
||||
PSA_ASSERT( status );
|
||||
status = psa_get_key_slot_number( reference_attributes,
|
||||
&desired_slot_number );
|
||||
if( status == PSA_SUCCESS )
|
||||
{
|
||||
TEST_EQUAL( desired_slot_number, actual_slot_number );
|
||||
}
|
||||
}
|
||||
}
|
||||
ok = 1;
|
||||
|
||||
exit:
|
||||
@ -485,11 +789,14 @@ void key_creation_import_export( int min_slot, int restart )
|
||||
/* Test that the key was created in the expected slot. */
|
||||
TEST_ASSERT( ram_slots[min_slot].type == PSA_KEY_TYPE_RAW_DATA );
|
||||
|
||||
/* Test the key attributes and the key data. */
|
||||
/* Test the key attributes, including the reported slot number. */
|
||||
psa_set_key_bits( &attributes,
|
||||
PSA_BYTES_TO_BITS( sizeof( key_material ) ) );
|
||||
psa_set_key_slot_number( &attributes, min_slot );
|
||||
if( ! check_key_attributes( handle, &attributes ) )
|
||||
goto exit;
|
||||
|
||||
/* Test the key data. */
|
||||
PSA_ASSERT( psa_export_key( handle,
|
||||
exported, sizeof( exported ),
|
||||
&exported_length ) );
|
||||
@ -497,6 +804,9 @@ void key_creation_import_export( int min_slot, int restart )
|
||||
exported, exported_length );
|
||||
|
||||
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||
handle = 0;
|
||||
TEST_EQUAL( psa_open_key( id, &handle ),
|
||||
PSA_ERROR_DOES_NOT_EXIST );
|
||||
|
||||
/* Test that the key has been erased from the designated slot. */
|
||||
TEST_ASSERT( ram_slots[min_slot].type == 0 );
|
||||
@ -509,8 +819,79 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void key_creation_smoke( int type_arg, int alg_arg,
|
||||
data_t *key_material )
|
||||
void key_creation_in_chosen_slot( int slot_arg,
|
||||
int restart,
|
||||
int expected_status_arg )
|
||||
{
|
||||
psa_key_slot_number_t wanted_slot = slot_arg;
|
||||
psa_status_t expected_status = expected_status_arg;
|
||||
psa_status_t status;
|
||||
psa_drv_se_t driver;
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = 2;
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
|
||||
|
||||
memset( &driver, 0, sizeof( driver ) );
|
||||
memset( &key_management, 0, sizeof( key_management ) );
|
||||
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
|
||||
driver.key_management = &key_management;
|
||||
driver.persistent_data_size = sizeof( ram_slot_usage_t );
|
||||
key_management.p_validate_slot_number = ram_validate_slot_number;
|
||||
key_management.p_import = ram_import;
|
||||
key_management.p_destroy = ram_destroy;
|
||||
key_management.p_export = ram_export;
|
||||
|
||||
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
|
||||
/* Create a key. */
|
||||
psa_set_key_id( &attributes, id );
|
||||
psa_set_key_lifetime( &attributes, lifetime );
|
||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
|
||||
psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
|
||||
psa_set_key_slot_number( &attributes, wanted_slot );
|
||||
status = psa_import_key( &attributes,
|
||||
key_material, sizeof( key_material ),
|
||||
&handle );
|
||||
TEST_EQUAL( status, expected_status );
|
||||
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
|
||||
/* Maybe restart, to check that the information is saved correctly. */
|
||||
if( restart )
|
||||
{
|
||||
mbedtls_psa_crypto_free( );
|
||||
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
PSA_ASSERT( psa_open_key( id, &handle ) );
|
||||
}
|
||||
|
||||
/* Test that the key was created in the expected slot. */
|
||||
TEST_EQUAL( ram_slots[wanted_slot].type, PSA_KEY_TYPE_RAW_DATA );
|
||||
|
||||
/* Test that the key is reported with the correct attributes,
|
||||
* including the expected slot. */
|
||||
PSA_ASSERT( psa_get_key_attributes( handle, &attributes ) );
|
||||
|
||||
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||
handle = 0;
|
||||
TEST_EQUAL( psa_open_key( id, &handle ),
|
||||
PSA_ERROR_DOES_NOT_EXIST );
|
||||
|
||||
exit:
|
||||
PSA_DONE( );
|
||||
ram_slots_reset( );
|
||||
psa_purge_storage( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void import_key_smoke( int type_arg, int alg_arg,
|
||||
data_t *key_material )
|
||||
{
|
||||
psa_key_type_t type = type_arg;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
@ -528,6 +909,7 @@ void key_creation_smoke( int type_arg, int alg_arg,
|
||||
driver.persistent_data_size = sizeof( psa_key_slot_number_t );
|
||||
key_management.p_allocate = counter_allocate;
|
||||
key_management.p_import = null_import;
|
||||
key_management.p_destroy = null_destroy;
|
||||
|
||||
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
@ -559,10 +941,12 @@ void key_creation_smoke( int type_arg, int alg_arg,
|
||||
|
||||
/* We're done. */
|
||||
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||
handle = 0;
|
||||
TEST_EQUAL( psa_open_key( id, &handle ),
|
||||
PSA_ERROR_DOES_NOT_EXIST );
|
||||
|
||||
exit:
|
||||
PSA_DONE( );
|
||||
ram_slots_reset( );
|
||||
psa_purge_storage( );
|
||||
}
|
||||
/* END_CASE */
|
||||
@ -585,6 +969,7 @@ void generate_key_not_supported( int type_arg, int bits_arg )
|
||||
driver.key_management = &key_management;
|
||||
driver.persistent_data_size = sizeof( psa_key_slot_number_t );
|
||||
key_management.p_allocate = counter_allocate;
|
||||
/* No p_generate method */
|
||||
|
||||
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
@ -597,8 +982,310 @@ void generate_key_not_supported( int type_arg, int bits_arg )
|
||||
PSA_ERROR_NOT_SUPPORTED );
|
||||
|
||||
exit:
|
||||
PSA_DONE( );
|
||||
psa_purge_storage( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void generate_key_smoke( int type_arg, int bits_arg, int alg_arg )
|
||||
{
|
||||
psa_key_type_t type = type_arg;
|
||||
psa_key_bits_t bits = bits_arg;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
psa_drv_se_t driver;
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = 2;
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
memset( &driver, 0, sizeof( driver ) );
|
||||
memset( &key_management, 0, sizeof( key_management ) );
|
||||
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
|
||||
driver.key_management = &key_management;
|
||||
driver.persistent_data_size = sizeof( psa_key_slot_number_t );
|
||||
key_management.p_allocate = counter_allocate;
|
||||
key_management.p_generate = null_generate;
|
||||
key_management.p_destroy = null_destroy;
|
||||
|
||||
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
|
||||
/* Create a key. */
|
||||
psa_set_key_id( &attributes, id );
|
||||
psa_set_key_lifetime( &attributes, lifetime );
|
||||
psa_set_key_usage_flags( &attributes,
|
||||
PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY |
|
||||
PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT |
|
||||
PSA_KEY_USAGE_EXPORT );
|
||||
psa_set_key_algorithm( &attributes, alg );
|
||||
psa_set_key_type( &attributes, type );
|
||||
psa_set_key_bits( &attributes, bits );
|
||||
PSA_ASSERT( psa_generate_key( &attributes, &handle ) );
|
||||
|
||||
/* Do stuff with the key. */
|
||||
if( ! smoke_test_key( handle ) )
|
||||
goto exit;
|
||||
|
||||
/* Restart and try again. */
|
||||
mbedtls_psa_crypto_free( );
|
||||
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
PSA_ASSERT( psa_open_key( id, &handle ) );
|
||||
if( ! smoke_test_key( handle ) )
|
||||
goto exit;
|
||||
|
||||
/* We're done. */
|
||||
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||
handle = 0;
|
||||
TEST_EQUAL( psa_open_key( id, &handle ),
|
||||
PSA_ERROR_DOES_NOT_EXIST );
|
||||
|
||||
exit:
|
||||
PSA_DONE( );
|
||||
psa_purge_storage( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void sign_verify( int flow,
|
||||
int type_arg, int alg_arg,
|
||||
int bits_arg, data_t *key_material,
|
||||
data_t *input )
|
||||
{
|
||||
psa_key_type_t type = type_arg;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
size_t bits = bits_arg;
|
||||
/* Pass bits=0 to import, bits>0 to fake-generate */
|
||||
int generating = ( bits != 0 );
|
||||
|
||||
psa_drv_se_t driver;
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_drv_se_asymmetric_t asymmetric;
|
||||
|
||||
psa_key_lifetime_t lifetime = 2;
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_handle_t drv_handle = 0; /* key managed by the driver */
|
||||
psa_key_handle_t sw_handle = 0; /* transparent key */
|
||||
psa_key_attributes_t sw_attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_attributes_t drv_attributes;
|
||||
uint8_t signature[PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE];
|
||||
size_t signature_length;
|
||||
|
||||
memset( &driver, 0, sizeof( driver ) );
|
||||
memset( &key_management, 0, sizeof( key_management ) );
|
||||
memset( &asymmetric, 0, sizeof( asymmetric ) );
|
||||
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
|
||||
driver.key_management = &key_management;
|
||||
driver.asymmetric = &asymmetric;
|
||||
driver.persistent_data_size = sizeof( ram_slot_usage_t );
|
||||
key_management.p_allocate = ram_allocate;
|
||||
key_management.p_destroy = ram_destroy;
|
||||
if( generating )
|
||||
key_management.p_generate = ram_fake_generate;
|
||||
else
|
||||
key_management.p_import = ram_import;
|
||||
switch( flow )
|
||||
{
|
||||
case SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION:
|
||||
break;
|
||||
case SIGN_IN_DRIVER_AND_PARALLEL_CREATION:
|
||||
asymmetric.p_sign = ram_sign;
|
||||
break;
|
||||
case SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC:
|
||||
asymmetric.p_sign = ram_sign;
|
||||
key_management.p_export_public = ram_export_public;
|
||||
break;
|
||||
default:
|
||||
TEST_ASSERT( ! "unsupported flow (should be SIGN_IN_xxx)" );
|
||||
break;
|
||||
}
|
||||
asymmetric.p_verify = ram_verify;
|
||||
|
||||
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
|
||||
/* Prepare to create two keys with the same key material: a transparent
|
||||
* key, and one that goes through the driver. */
|
||||
psa_set_key_usage_flags( &sw_attributes,
|
||||
PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY );
|
||||
psa_set_key_algorithm( &sw_attributes, alg );
|
||||
psa_set_key_type( &sw_attributes, type );
|
||||
drv_attributes = sw_attributes;
|
||||
psa_set_key_id( &drv_attributes, id );
|
||||
psa_set_key_lifetime( &drv_attributes, lifetime );
|
||||
|
||||
/* Create the key in the driver. */
|
||||
if( generating )
|
||||
{
|
||||
psa_set_key_bits( &drv_attributes, bits );
|
||||
PSA_ASSERT( psa_generate_key( &drv_attributes, &drv_handle ) );
|
||||
/* Since we called a generate method that does not actually
|
||||
* generate material, store the desired result of generation in
|
||||
* the mock secure element storage. */
|
||||
PSA_ASSERT( psa_get_key_attributes( drv_handle, &drv_attributes ) );
|
||||
TEST_ASSERT( key_material->len == PSA_BITS_TO_BYTES( bits ) );
|
||||
memcpy( ram_slots[ram_min_slot].content, key_material->x,
|
||||
key_material->len );
|
||||
}
|
||||
else
|
||||
{
|
||||
PSA_ASSERT( psa_import_key( &drv_attributes,
|
||||
key_material->x, key_material->len,
|
||||
&drv_handle ) );
|
||||
}
|
||||
|
||||
/* Either import the same key in software, or export the driver's
|
||||
* public key and import that. */
|
||||
switch( flow )
|
||||
{
|
||||
case SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION:
|
||||
case SIGN_IN_DRIVER_AND_PARALLEL_CREATION:
|
||||
PSA_ASSERT( psa_import_key( &sw_attributes,
|
||||
key_material->x, key_material->len,
|
||||
&sw_handle ) );
|
||||
break;
|
||||
case SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC:
|
||||
{
|
||||
uint8_t public_key[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE( PSA_VENDOR_ECC_MAX_CURVE_BITS )];
|
||||
size_t public_key_length;
|
||||
PSA_ASSERT( psa_export_public_key( drv_handle,
|
||||
public_key, sizeof( public_key ),
|
||||
&public_key_length ) );
|
||||
psa_set_key_type( &sw_attributes,
|
||||
PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR( type ) );
|
||||
PSA_ASSERT( psa_import_key( &sw_attributes,
|
||||
public_key, public_key_length,
|
||||
&sw_handle ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Sign with the chosen key. */
|
||||
switch( flow )
|
||||
{
|
||||
case SIGN_IN_DRIVER_AND_PARALLEL_CREATION:
|
||||
case SIGN_IN_DRIVER_THEN_EXPORT_PUBLIC:
|
||||
PSA_ASSERT_VIA_DRIVER(
|
||||
psa_asymmetric_sign( drv_handle,
|
||||
alg,
|
||||
input->x, input->len,
|
||||
signature, sizeof( signature ),
|
||||
&signature_length ),
|
||||
PSA_SUCCESS );
|
||||
break;
|
||||
case SIGN_IN_SOFTWARE_AND_PARALLEL_CREATION:
|
||||
PSA_ASSERT( psa_asymmetric_sign( sw_handle,
|
||||
alg,
|
||||
input->x, input->len,
|
||||
signature, sizeof( signature ),
|
||||
&signature_length ) );
|
||||
break;
|
||||
}
|
||||
|
||||
/* Verify with both keys. */
|
||||
PSA_ASSERT( psa_asymmetric_verify( sw_handle, alg,
|
||||
input->x, input->len,
|
||||
signature, signature_length ) );
|
||||
PSA_ASSERT_VIA_DRIVER(
|
||||
psa_asymmetric_verify( drv_handle, alg,
|
||||
input->x, input->len,
|
||||
signature, signature_length ),
|
||||
PSA_SUCCESS );
|
||||
|
||||
/* Change the signature and verify again. */
|
||||
signature[0] ^= 1;
|
||||
TEST_EQUAL( psa_asymmetric_verify( sw_handle, alg,
|
||||
input->x, input->len,
|
||||
signature, signature_length ),
|
||||
PSA_ERROR_INVALID_SIGNATURE );
|
||||
PSA_ASSERT_VIA_DRIVER(
|
||||
psa_asymmetric_verify( drv_handle, alg,
|
||||
input->x, input->len,
|
||||
signature, signature_length ),
|
||||
PSA_ERROR_INVALID_SIGNATURE );
|
||||
|
||||
exit:
|
||||
psa_destroy_key( drv_handle );
|
||||
psa_destroy_key( sw_handle );
|
||||
PSA_DONE( );
|
||||
ram_slots_reset( );
|
||||
psa_purge_storage( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void register_key_smoke_test( int lifetime_arg,
|
||||
int validate,
|
||||
int expected_status_arg )
|
||||
{
|
||||
psa_key_lifetime_t lifetime = lifetime_arg;
|
||||
psa_status_t expected_status = expected_status_arg;
|
||||
psa_drv_se_t driver;
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_id_t id = 1;
|
||||
size_t bit_size = 48;
|
||||
psa_key_slot_number_t wanted_slot = 0x123456789;
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_status_t status;
|
||||
|
||||
memset( &driver, 0, sizeof( driver ) );
|
||||
driver.hal_version = PSA_DRV_SE_HAL_VERSION;
|
||||
memset( &key_management, 0, sizeof( key_management ) );
|
||||
driver.key_management = &key_management;
|
||||
key_management.p_destroy = null_destroy;
|
||||
if( validate >= 0 )
|
||||
{
|
||||
key_management.p_validate_slot_number = validate_slot_number_as_directed;
|
||||
validate_slot_number_directions.slot_number = wanted_slot;
|
||||
validate_slot_number_directions.method = PSA_KEY_CREATION_REGISTER;
|
||||
validate_slot_number_directions.status =
|
||||
( validate > 0 ? PSA_SUCCESS : PSA_ERROR_NOT_PERMITTED );
|
||||
}
|
||||
|
||||
PSA_ASSERT( psa_register_se_driver( MIN_DRIVER_LIFETIME, &driver ) );
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
|
||||
psa_set_key_id( &attributes, id );
|
||||
psa_set_key_lifetime( &attributes, lifetime );
|
||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
|
||||
psa_set_key_type( &attributes, PSA_KEY_TYPE_RAW_DATA );
|
||||
psa_set_key_bits( &attributes, bit_size );
|
||||
psa_set_key_slot_number( &attributes, wanted_slot );
|
||||
|
||||
status = mbedtls_psa_register_se_key( &attributes );
|
||||
TEST_EQUAL( status, expected_status );
|
||||
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
|
||||
/* Test that the key exists and has the expected attributes. */
|
||||
PSA_ASSERT( psa_open_key( id, &handle ) );
|
||||
if( ! check_key_attributes( handle, &attributes ) )
|
||||
goto exit;
|
||||
PSA_ASSERT( psa_close_key( handle ) );
|
||||
|
||||
/* Restart and try again. */
|
||||
PSA_DONE( );
|
||||
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
|
||||
PSA_ASSERT( psa_crypto_init( ) );
|
||||
PSA_ASSERT( psa_open_key( id, &handle ) );
|
||||
if( ! check_key_attributes( handle, &attributes ) )
|
||||
goto exit;
|
||||
/* This time, destroy the key. */
|
||||
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||
handle = 0;
|
||||
TEST_EQUAL( psa_open_key( id, &handle ),
|
||||
PSA_ERROR_DOES_NOT_EXIST );
|
||||
|
||||
exit:
|
||||
psa_reset_key_attributes( &attributes );
|
||||
psa_destroy_key( handle );
|
||||
PSA_DONE( );
|
||||
psa_purge_storage( );
|
||||
memset( &validate_slot_number_directions, 0,
|
||||
sizeof( validate_slot_number_directions ) );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
Reference in New Issue
Block a user