mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-27 17:35:47 +00:00
069346cdab
To start with, test that key creation fails as intended when the key type is not supported. This commit only covers psa_import_key and psa_generate_key. A follow-up will cover psa_key_derivation_output_key. My primary intent in creating this new test suite is to automatically generate test cases by enumerating the key types and algorithms that the library supports. But this commit only adds a few manually written test cases, to get the ball rolling. Move the relevant test cases of test_suite_psa_crypto.data that only depend on generic knowledge about the API. Keep test cases that depend more closely on the implementation, such as tests of non-supported key sizes, in test_suite_psa_crypto.data. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
53 lines
1.3 KiB
Plaintext
53 lines
1.3 KiB
Plaintext
/* BEGIN_HEADER */
|
|
|
|
#include "psa/crypto.h"
|
|
#include "test/psa_crypto_helpers.h"
|
|
|
|
#define INVALID_KEY_ID 0xfedcba98
|
|
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
* depends_on:MBEDTLS_PSA_CRYPTO_C
|
|
* END_DEPENDENCIES
|
|
*/
|
|
|
|
/* BEGIN_CASE */
|
|
void import_not_supported( int key_type, data_t *key_material )
|
|
{
|
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
|
psa_key_id_t key_id = INVALID_KEY_ID;
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
psa_set_key_type( &attributes, key_type );
|
|
TEST_EQUAL( psa_import_key( &attributes,
|
|
key_material->x, key_material->len,
|
|
&key_id ),
|
|
PSA_ERROR_NOT_SUPPORTED );
|
|
TEST_EQUAL( key_id, 0 );
|
|
|
|
exit:
|
|
psa_destroy_key( key_id );
|
|
PSA_DONE( );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE */
|
|
void generate_not_supported( int key_type, int bits )
|
|
{
|
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
|
psa_key_id_t key_id = INVALID_KEY_ID;
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
|
psa_set_key_type( &attributes, key_type );
|
|
psa_set_key_bits( &attributes, bits );
|
|
TEST_EQUAL( psa_generate_key( &attributes, &key_id ),
|
|
PSA_ERROR_NOT_SUPPORTED );
|
|
TEST_EQUAL( key_id, 0 );
|
|
|
|
exit:
|
|
psa_destroy_key( key_id );
|
|
PSA_DONE( );
|
|
}
|
|
/* END_CASE */
|