mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-26 08:31:11 +00:00
Add tests that checks key management corner cases
- import a key into a non empty key slot. - export a key from invalid slot number.
This commit is contained in:
parent
0d1caacf55
commit
28a38e6e38
|
@ -31,6 +31,19 @@ PSA import/export AES-256
|
||||||
depends_on:MBEDTLS_AES_C
|
depends_on:MBEDTLS_AES_C
|
||||||
import_export:"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef":PSA_KEY_TYPE_AES:PSA_ALG_CTR:PSA_KEY_USAGE_EXPORT:256:0:PSA_SUCCESS:1
|
import_export:"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef":PSA_KEY_TYPE_AES:PSA_ALG_CTR:PSA_KEY_USAGE_EXPORT:256:0:PSA_SUCCESS:1
|
||||||
|
|
||||||
|
PSA import to non empty key slot
|
||||||
|
depends_on:MBEDTLS_AES_C
|
||||||
|
import_key_nonempty_slot
|
||||||
|
|
||||||
|
PSA export empty key slot
|
||||||
|
export_invalid_slot:1:PSA_ERROR_EMPTY_SLOT
|
||||||
|
|
||||||
|
PSA export out of range key slot - lower bound
|
||||||
|
export_invalid_slot:0:PSA_ERROR_INVALID_ARGUMENT
|
||||||
|
|
||||||
|
PSA export out of range key slot - upper bound
|
||||||
|
export_invalid_slot:(psa_key_slot_t)(-1):PSA_ERROR_INVALID_ARGUMENT
|
||||||
|
|
||||||
PSA import AES: bad key size
|
PSA import AES: bad key size
|
||||||
depends_on:MBEDTLS_AES_C
|
depends_on:MBEDTLS_AES_C
|
||||||
import:"0123456789abcdef":PSA_KEY_TYPE_AES:PSA_ERROR_INVALID_ARGUMENT
|
import:"0123456789abcdef":PSA_KEY_TYPE_AES:PSA_ERROR_INVALID_ARGUMENT
|
||||||
|
|
|
@ -1003,6 +1003,50 @@ exit:
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
|
/* BEGIN_CASE */
|
||||||
|
void import_key_nonempty_slot( )
|
||||||
|
{
|
||||||
|
int slot = 1;
|
||||||
|
psa_key_type_t type = PSA_KEY_TYPE_RAW_DATA;
|
||||||
|
psa_status_t status;
|
||||||
|
const uint8_t data[] = { 0x1, 0x2, 0x3, 0x4, 0x5 };
|
||||||
|
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||||
|
|
||||||
|
/* Import the key */
|
||||||
|
TEST_ASSERT( psa_import_key( slot, type,
|
||||||
|
data, sizeof( data ) ) == PSA_SUCCESS );
|
||||||
|
|
||||||
|
/* Import the key again */
|
||||||
|
status = psa_import_key( slot, type, data, sizeof( data ) );
|
||||||
|
TEST_ASSERT( status == PSA_ERROR_OCCUPIED_SLOT );
|
||||||
|
|
||||||
|
exit:
|
||||||
|
mbedtls_psa_crypto_free( );
|
||||||
|
}
|
||||||
|
/* END_CASE */
|
||||||
|
|
||||||
|
/* BEGIN_CASE */
|
||||||
|
void export_invalid_slot( int slot, int expected_export_status_arg )
|
||||||
|
{
|
||||||
|
psa_status_t status;
|
||||||
|
unsigned char *exported = NULL;
|
||||||
|
size_t export_size = 0;
|
||||||
|
size_t exported_length = INVALID_EXPORT_LENGTH;
|
||||||
|
psa_status_t expected_export_status = expected_export_status_arg;
|
||||||
|
|
||||||
|
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||||
|
|
||||||
|
/* Export the key */
|
||||||
|
status = psa_export_key( slot,
|
||||||
|
exported, export_size,
|
||||||
|
&exported_length );
|
||||||
|
TEST_ASSERT( status == expected_export_status );
|
||||||
|
|
||||||
|
exit:
|
||||||
|
mbedtls_psa_crypto_free( );
|
||||||
|
}
|
||||||
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void import_export_public_key( data_t *data,
|
void import_export_public_key( data_t *data,
|
||||||
int type_arg,
|
int type_arg,
|
||||||
|
|
Loading…
Reference in a new issue