mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-25 13:05:41 +00:00
Merge pull request #18 from ARMmbed/psa-wrapper-apis-export-publickey
Export public key implementation (#18)
This commit is contained in:
commit
5100318a92
|
@ -181,8 +181,8 @@ typedef uint32_t psa_key_type_t;
|
|||
(((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_ASYMMETRIC)
|
||||
/** Whether a key type is the public part of a key pair. */
|
||||
#define PSA_KEY_TYPE_IS_PUBLIC_KEY(type) \
|
||||
(((type) & (PSA_KEY_TYPE_CATEGORY_MASK | PSA_KEY_TYPE_PAIR_FLAG) == \
|
||||
PSA_KEY_TYPE_CATEGORY_ASYMMETRIC))
|
||||
(((type) & (PSA_KEY_TYPE_CATEGORY_MASK | PSA_KEY_TYPE_PAIR_FLAG)) == \
|
||||
PSA_KEY_TYPE_CATEGORY_ASYMMETRIC)
|
||||
/** Whether a key type is a key pair containing a private part and a public
|
||||
* part. */
|
||||
#define PSA_KEY_TYPE_IS_KEYPAIR(type) \
|
||||
|
@ -464,7 +464,7 @@ psa_status_t psa_export_key(psa_key_slot_t key,
|
|||
* For standard key types, the output format is as follows:
|
||||
*
|
||||
* - For RSA keys (#PSA_KEY_TYPE_RSA_KEYPAIR or #PSA_KEY_TYPE_RSA_PUBLIC_KEY),
|
||||
* is the DER representation of the public key defined by RFC 5280
|
||||
* the format is the DER representation of the public key defined by RFC 5280
|
||||
* as SubjectPublicKeyInfo.
|
||||
*
|
||||
* \param key Slot whose content is to be exported. This must
|
||||
|
|
|
@ -472,10 +472,11 @@ psa_status_t psa_get_key_information(psa_key_slot_t key,
|
|||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
psa_status_t psa_export_key(psa_key_slot_t key,
|
||||
uint8_t *data,
|
||||
size_t data_size,
|
||||
size_t *data_length)
|
||||
static psa_status_t psa_internal_export_key(psa_key_slot_t key,
|
||||
uint8_t *data,
|
||||
size_t data_size,
|
||||
size_t *data_length,
|
||||
int export_public_key)
|
||||
{
|
||||
key_slot_t *slot;
|
||||
|
||||
|
@ -485,9 +486,13 @@ psa_status_t psa_export_key(psa_key_slot_t key,
|
|||
if( slot->type == PSA_KEY_TYPE_NONE )
|
||||
return( PSA_ERROR_EMPTY_SLOT );
|
||||
|
||||
if( !( slot->policy.usage & PSA_KEY_USAGE_EXPORT ) )
|
||||
return( PSA_ERROR_NOT_PERMITTED );
|
||||
if( export_public_key && ( !( PSA_KEY_TYPE_IS_ASYMMETRIC( slot->type ) ) ) )
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
if( ( !export_public_key ) && ( !( PSA_KEY_TYPE_IS_PUBLIC_KEY( slot->type ) ) ) &&
|
||||
( !( slot->policy.usage & PSA_KEY_USAGE_EXPORT ) ) )
|
||||
return( PSA_ERROR_NOT_PERMITTED );
|
||||
|
||||
if( PSA_KEY_TYPE_IS_RAW_BYTES( slot->type ) )
|
||||
{
|
||||
if( slot->data.raw.bytes > data_size )
|
||||
|
@ -497,46 +502,65 @@ psa_status_t psa_export_key(psa_key_slot_t key,
|
|||
return( PSA_SUCCESS );
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_PK_WRITE_C)
|
||||
if( slot->type == PSA_KEY_TYPE_RSA_PUBLIC_KEY ||
|
||||
slot->type == PSA_KEY_TYPE_RSA_KEYPAIR ||
|
||||
PSA_KEY_TYPE_IS_ECC( slot->type ) )
|
||||
{
|
||||
mbedtls_pk_context pk;
|
||||
int ret;
|
||||
mbedtls_pk_init( &pk );
|
||||
if( slot->type == PSA_KEY_TYPE_RSA_PUBLIC_KEY ||
|
||||
slot->type == PSA_KEY_TYPE_RSA_KEYPAIR )
|
||||
slot->type == PSA_KEY_TYPE_RSA_KEYPAIR ||
|
||||
PSA_KEY_TYPE_IS_ECC( slot->type ) )
|
||||
{
|
||||
pk.pk_info = &mbedtls_rsa_info;
|
||||
pk.pk_ctx = slot->data.rsa;
|
||||
mbedtls_pk_context pk;
|
||||
int ret;
|
||||
mbedtls_pk_init( &pk );
|
||||
if( slot->type == PSA_KEY_TYPE_RSA_PUBLIC_KEY ||
|
||||
slot->type == PSA_KEY_TYPE_RSA_KEYPAIR )
|
||||
{
|
||||
pk.pk_info = &mbedtls_rsa_info;
|
||||
pk.pk_ctx = slot->data.rsa;
|
||||
}
|
||||
else
|
||||
{
|
||||
pk.pk_info = &mbedtls_eckey_info;
|
||||
pk.pk_ctx = slot->data.ecp;
|
||||
}
|
||||
if( export_public_key || PSA_KEY_TYPE_IS_PUBLIC_KEY( slot->type ) )
|
||||
ret = mbedtls_pk_write_pubkey_der( &pk, data, data_size );
|
||||
else
|
||||
ret = mbedtls_pk_write_key_der( &pk, data, data_size );
|
||||
if( ret < 0 )
|
||||
return( mbedtls_to_psa_error( ret ) );
|
||||
*data_length = ret;
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
else
|
||||
{
|
||||
pk.pk_info = &mbedtls_eckey_info;
|
||||
pk.pk_ctx = slot->data.ecp;
|
||||
}
|
||||
if( PSA_KEY_TYPE_IS_KEYPAIR( slot->type ) )
|
||||
ret = mbedtls_pk_write_key_der( &pk, data, data_size );
|
||||
else
|
||||
ret = mbedtls_pk_write_pubkey_der( &pk, data, data_size );
|
||||
if( ret < 0 )
|
||||
return( mbedtls_to_psa_error( ret ) );
|
||||
*data_length = ret;
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
else
|
||||
#endif /* defined(MBEDTLS_PK_WRITE_C) */
|
||||
{
|
||||
/* This shouldn't happen in the reference implementation, but
|
||||
it is valid for a special-purpose implementation to omit
|
||||
support for exporting certain key types. */
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
{
|
||||
/* This shouldn't happen in the reference implementation, but
|
||||
it is valid for a special-purpose implementation to omit
|
||||
support for exporting certain key types. */
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
psa_status_t psa_export_key(psa_key_slot_t key,
|
||||
uint8_t *data,
|
||||
size_t data_size,
|
||||
size_t *data_length)
|
||||
{
|
||||
return psa_internal_export_key( key, data, data_size,
|
||||
data_length, 0 );
|
||||
}
|
||||
|
||||
|
||||
psa_status_t psa_export_public_key(psa_key_slot_t key,
|
||||
uint8_t *data,
|
||||
size_t data_size,
|
||||
size_t *data_length)
|
||||
{
|
||||
return psa_internal_export_key( key, data, data_size,
|
||||
data_length, 1 );
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/* Message digests */
|
||||
/****************************************************************/
|
||||
|
@ -1002,10 +1026,10 @@ psa_status_t psa_mac_start( psa_mac_operation_t *operation,
|
|||
return( status );
|
||||
slot = &global_data.key_slots[key];
|
||||
|
||||
if ( ( slot->policy.usage & PSA_KEY_USAGE_SIGN ) != 0 )
|
||||
if( ( slot->policy.usage & PSA_KEY_USAGE_SIGN ) != 0 )
|
||||
operation->key_usage_sign = 1;
|
||||
|
||||
if ( ( slot->policy.usage & PSA_KEY_USAGE_VERIFY ) != 0 )
|
||||
if( ( slot->policy.usage & PSA_KEY_USAGE_VERIFY ) != 0 )
|
||||
operation->key_usage_verify = 1;
|
||||
|
||||
if( ! PSA_ALG_IS_HMAC( alg ) )
|
||||
|
@ -1457,7 +1481,7 @@ psa_status_t psa_set_key_lifetime(psa_key_slot_t key,
|
|||
if( slot->type != PSA_KEY_TYPE_NONE )
|
||||
return( PSA_ERROR_OCCUPIED_SLOT );
|
||||
|
||||
if ( lifetime != PSA_KEY_LIFETIME_VOLATILE )
|
||||
if( lifetime != PSA_KEY_LIFETIME_VOLATILE )
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
|
||||
slot->lifetime = lifetime;
|
||||
|
|
|
@ -110,6 +110,7 @@ add_test_suite(pk)
|
|||
add_test_suite(pkparse)
|
||||
add_test_suite(pkwrite)
|
||||
add_test_suite(poly1305)
|
||||
add_test_suite(psa_crypto)
|
||||
add_test_suite(shax)
|
||||
add_test_suite(ssl)
|
||||
add_test_suite(timing)
|
||||
|
|
|
@ -2,28 +2,32 @@ PSA init/deinit
|
|||
init_deinit:
|
||||
|
||||
PSA import/export raw: 0 bytes
|
||||
import_export:"":PSA_KEY_TYPE_RAW_DATA:0:0:PSA_SUCCESS:1
|
||||
import_export:"":PSA_KEY_TYPE_RAW_DATA:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_USAGE_EXPORT:0:0:PSA_SUCCESS:1
|
||||
|
||||
PSA import/export raw: 1 bytes
|
||||
import_export:"2a":PSA_KEY_TYPE_RAW_DATA:8:0:PSA_SUCCESS:1
|
||||
import_export:"2a":PSA_KEY_TYPE_RAW_DATA:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_USAGE_EXPORT:8:0:PSA_SUCCESS:1
|
||||
|
||||
PSA import/export raw: 1 bytes, larger buffer
|
||||
import_export:"2a":PSA_KEY_TYPE_RAW_DATA:8:1:PSA_SUCCESS:1
|
||||
import_export:"2a":PSA_KEY_TYPE_RAW_DATA:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_USAGE_EXPORT:8:1:PSA_SUCCESS:1
|
||||
|
||||
PSA import/export raw: 2 bytes, buffer too small
|
||||
import_export:"2a2b":PSA_KEY_TYPE_RAW_DATA:16:-1:PSA_ERROR_BUFFER_TOO_SMALL:1
|
||||
import_export:"2a2b":PSA_KEY_TYPE_RAW_DATA:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_USAGE_EXPORT:16:-1:PSA_ERROR_BUFFER_TOO_SMALL:1
|
||||
|
||||
PSA import/export RSA public key: good, 1024-bit
|
||||
depends_on:MBEDTLS_PK_C:MBEDTLS_PK_PARSE_C:MBEDTLS_RSA_C
|
||||
import_export:"30819f300d06092a864886f70d010101050003818d0030818902818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc30203010001":PSA_KEY_TYPE_RSA_PUBLIC_KEY:1024:0:PSA_SUCCESS:1
|
||||
import_export:"30819f300d06092a864886f70d010101050003818d0030818902818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc30203010001":PSA_KEY_TYPE_RSA_PUBLIC_KEY:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_USAGE_EXPORT:1024:0:PSA_SUCCESS:1
|
||||
|
||||
PSA import/export RSA keypair usage encrypt: bad, plicy usage set to ENCRYPT instead of EXPORT 1024-bit
|
||||
depends_on:MBEDTLS_PK_C:MBEDTLS_PK_PARSE_C:MBEDTLS_RSA_C
|
||||
import_export:"3082025e02010002818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc3020301000102818100874bf0ffc2f2a71d14671ddd0171c954d7fdbf50281e4f6d99ea0e1ebcf82faa58e7b595ffb293d1abe17f110b37c48cc0f36c37e84d876621d327f64bbe08457d3ec4098ba2fa0a319fba411c2841ed7be83196a8cdf9daa5d00694bc335fc4c32217fe0488bce9cb7202e59468b1ead119000477db2ca797fac19eda3f58c1024100e2ab760841bb9d30a81d222de1eb7381d82214407f1b975cbbfe4e1a9467fd98adbd78f607836ca5be1928b9d160d97fd45c12d6b52e2c9871a174c66b488113024100c5ab27602159ae7d6f20c3c2ee851e46dc112e689e28d5fcbbf990a99ef8a90b8bb44fd36467e7fc1789ceb663abda338652c3c73f111774902e840565927091024100b6cdbd354f7df579a63b48b3643e353b84898777b48b15f94e0bfc0567a6ae5911d57ad6409cf7647bf96264e9bd87eb95e263b7110b9a1f9f94acced0fafa4d024071195eec37e8d257decfc672b07ae639f10cbb9b0c739d0c809968d644a94e3fd6ed9287077a14583f379058f76a8aecd43c62dc8c0f41766650d725275ac4a1024100bb32d133edc2e048d463388b7be9cb4be29f4b6250be603e70e3647501c97ddde20a4e71be95fd5e71784e25aca4baf25be5738aae59bbfe1c997781447a2b24":PSA_KEY_TYPE_RSA_KEYPAIR:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_USAGE_ENCRYPT:1024:0:PSA_ERROR_NOT_PERMITTED:1
|
||||
|
||||
PSA import/export RSA keypair: good, 1024-bit
|
||||
depends_on:MBEDTLS_PK_C:MBEDTLS_PK_PARSE_C:MBEDTLS_RSA_C
|
||||
import_export:"3082025e02010002818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc3020301000102818100874bf0ffc2f2a71d14671ddd0171c954d7fdbf50281e4f6d99ea0e1ebcf82faa58e7b595ffb293d1abe17f110b37c48cc0f36c37e84d876621d327f64bbe08457d3ec4098ba2fa0a319fba411c2841ed7be83196a8cdf9daa5d00694bc335fc4c32217fe0488bce9cb7202e59468b1ead119000477db2ca797fac19eda3f58c1024100e2ab760841bb9d30a81d222de1eb7381d82214407f1b975cbbfe4e1a9467fd98adbd78f607836ca5be1928b9d160d97fd45c12d6b52e2c9871a174c66b488113024100c5ab27602159ae7d6f20c3c2ee851e46dc112e689e28d5fcbbf990a99ef8a90b8bb44fd36467e7fc1789ceb663abda338652c3c73f111774902e840565927091024100b6cdbd354f7df579a63b48b3643e353b84898777b48b15f94e0bfc0567a6ae5911d57ad6409cf7647bf96264e9bd87eb95e263b7110b9a1f9f94acced0fafa4d024071195eec37e8d257decfc672b07ae639f10cbb9b0c739d0c809968d644a94e3fd6ed9287077a14583f379058f76a8aecd43c62dc8c0f41766650d725275ac4a1024100bb32d133edc2e048d463388b7be9cb4be29f4b6250be603e70e3647501c97ddde20a4e71be95fd5e71784e25aca4baf25be5738aae59bbfe1c997781447a2b24":PSA_KEY_TYPE_RSA_KEYPAIR:1024:0:PSA_SUCCESS:1
|
||||
import_export:"3082025e02010002818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc3020301000102818100874bf0ffc2f2a71d14671ddd0171c954d7fdbf50281e4f6d99ea0e1ebcf82faa58e7b595ffb293d1abe17f110b37c48cc0f36c37e84d876621d327f64bbe08457d3ec4098ba2fa0a319fba411c2841ed7be83196a8cdf9daa5d00694bc335fc4c32217fe0488bce9cb7202e59468b1ead119000477db2ca797fac19eda3f58c1024100e2ab760841bb9d30a81d222de1eb7381d82214407f1b975cbbfe4e1a9467fd98adbd78f607836ca5be1928b9d160d97fd45c12d6b52e2c9871a174c66b488113024100c5ab27602159ae7d6f20c3c2ee851e46dc112e689e28d5fcbbf990a99ef8a90b8bb44fd36467e7fc1789ceb663abda338652c3c73f111774902e840565927091024100b6cdbd354f7df579a63b48b3643e353b84898777b48b15f94e0bfc0567a6ae5911d57ad6409cf7647bf96264e9bd87eb95e263b7110b9a1f9f94acced0fafa4d024071195eec37e8d257decfc672b07ae639f10cbb9b0c739d0c809968d644a94e3fd6ed9287077a14583f379058f76a8aecd43c62dc8c0f41766650d725275ac4a1024100bb32d133edc2e048d463388b7be9cb4be29f4b6250be603e70e3647501c97ddde20a4e71be95fd5e71784e25aca4baf25be5738aae59bbfe1c997781447a2b24":PSA_KEY_TYPE_RSA_KEYPAIR:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_USAGE_EXPORT:1024:0:PSA_SUCCESS:1
|
||||
|
||||
PSA import/export RSA keypair: trailing garbage ignored
|
||||
depends_on:MBEDTLS_PK_C:MBEDTLS_PK_PARSE_C:MBEDTLS_RSA_C
|
||||
import_export:"3082025e02010002818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc3020301000102818100874bf0ffc2f2a71d14671ddd0171c954d7fdbf50281e4f6d99ea0e1ebcf82faa58e7b595ffb293d1abe17f110b37c48cc0f36c37e84d876621d327f64bbe08457d3ec4098ba2fa0a319fba411c2841ed7be83196a8cdf9daa5d00694bc335fc4c32217fe0488bce9cb7202e59468b1ead119000477db2ca797fac19eda3f58c1024100e2ab760841bb9d30a81d222de1eb7381d82214407f1b975cbbfe4e1a9467fd98adbd78f607836ca5be1928b9d160d97fd45c12d6b52e2c9871a174c66b488113024100c5ab27602159ae7d6f20c3c2ee851e46dc112e689e28d5fcbbf990a99ef8a90b8bb44fd36467e7fc1789ceb663abda338652c3c73f111774902e840565927091024100b6cdbd354f7df579a63b48b3643e353b84898777b48b15f94e0bfc0567a6ae5911d57ad6409cf7647bf96264e9bd87eb95e263b7110b9a1f9f94acced0fafa4d024071195eec37e8d257decfc672b07ae639f10cbb9b0c739d0c809968d644a94e3fd6ed9287077a14583f379058f76a8aecd43c62dc8c0f41766650d725275ac4a1024100bb32d133edc2e048d463388b7be9cb4be29f4b6250be603e70e3647501c97ddde20a4e71be95fd5e71784e25aca4baf25be5738aae59bbfe1c997781447a2b2400":PSA_KEY_TYPE_RSA_KEYPAIR:1024:-1:PSA_SUCCESS:0
|
||||
import_export:"3082025e02010002818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc3020301000102818100874bf0ffc2f2a71d14671ddd0171c954d7fdbf50281e4f6d99ea0e1ebcf82faa58e7b595ffb293d1abe17f110b37c48cc0f36c37e84d876621d327f64bbe08457d3ec4098ba2fa0a319fba411c2841ed7be83196a8cdf9daa5d00694bc335fc4c32217fe0488bce9cb7202e59468b1ead119000477db2ca797fac19eda3f58c1024100e2ab760841bb9d30a81d222de1eb7381d82214407f1b975cbbfe4e1a9467fd98adbd78f607836ca5be1928b9d160d97fd45c12d6b52e2c9871a174c66b488113024100c5ab27602159ae7d6f20c3c2ee851e46dc112e689e28d5fcbbf990a99ef8a90b8bb44fd36467e7fc1789ceb663abda338652c3c73f111774902e840565927091024100b6cdbd354f7df579a63b48b3643e353b84898777b48b15f94e0bfc0567a6ae5911d57ad6409cf7647bf96264e9bd87eb95e263b7110b9a1f9f94acced0fafa4d024071195eec37e8d257decfc672b07ae639f10cbb9b0c739d0c809968d644a94e3fd6ed9287077a14583f379058f76a8aecd43c62dc8c0f41766650d725275ac4a1024100bb32d133edc2e048d463388b7be9cb4be29f4b6250be603e70e3647501c97ddde20a4e71be95fd5e71784e25aca4baf25be5738aae59bbfe1c997781447a2b2400":PSA_KEY_TYPE_RSA_KEYPAIR:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_USAGE_EXPORT:1024:-1:PSA_SUCCESS:0
|
||||
|
||||
PSA import RSA keypair: truncated
|
||||
depends_on:MBEDTLS_PK_C:MBEDTLS_PK_PARSE_C:MBEDTLS_RSA_C
|
||||
|
@ -31,7 +35,19 @@ import:"3082025e02010002818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541e
|
|||
|
||||
PSA import/export RSA keypair: good, 1023-bit
|
||||
depends_on:MBEDTLS_PK_C:MBEDTLS_PK_PARSE_C:MBEDTLS_RSA_C
|
||||
import_export:"3082025a0201000281806c49704e91f3df44fc99e9b3c0fee5025cc04d09529a1dd05754f2da2751d7a9aa5a79f7070132f2c47b31963e37cd74675f9c93ee7c85a143fefe303e94d1ee0e4d30898d17ab3a229e8457ef21fd179039f748305babe7f134f6d58ce5d721a1a5da98f63503d2466c6a515e53494a41180a91e535bd5b55d4dce2c17419870203010001028180491b277413fb35efe82dace68b544a9dd6aa8917d329731955ec66ec3b0178fcf5a29196e1a6c093bf6c8064b36a8f0d9840a78003d11392754a70a77788975515a1442a6c806cafa2f07fe99cac78a86fa868888d654cec4baf205352cf8255acaa47e2455f23b58c0e5ae43fa297bbffe5b970caa80f71e82084fd35425479024100ef27f3fb2df90ac4910ed95fdde4877d09b0dc4e95079f12a7e2041300a8884a39372a1c79691338cd5c3965bcf3a24f2ce9e10de19d4cb87c7546d60ca0aa0d024073e9e1283475e9ab3075da0b005ca7c7b05e76325f8deb648238831c8353041d594307f784cd527cfee9187b997713d71c0ff98f01beac4d1a85583be52e90e302402f0c801e311c2677274671933f96fee4a56c6adaf6ccaa09c4875d5fd3a8542fadf3e14ffabea62e6d90302688b6b17ebc0a42e1353a79e66d6db102d9371e5d02406731ef3c8607fbf266806590a9cfd3a79a435ee355e2d9906fc6b4236c5f3a288ed178844a7d295512f49ed15b3d82325e4f729478af3262aa9bd083f273d49502410090a32c0e8ca3bcd4c66f092cdc369cd1abb4a05b9a6f0e65e5a51da1d96d5aca8c1525b3f11322c0588062fc8592ebf25b7950f918d39018e82b8acccc8f7e7a":PSA_KEY_TYPE_RSA_KEYPAIR:1023:0:PSA_SUCCESS:1
|
||||
import_export:"3082025a0201000281806c49704e91f3df44fc99e9b3c0fee5025cc04d09529a1dd05754f2da2751d7a9aa5a79f7070132f2c47b31963e37cd74675f9c93ee7c85a143fefe303e94d1ee0e4d30898d17ab3a229e8457ef21fd179039f748305babe7f134f6d58ce5d721a1a5da98f63503d2466c6a515e53494a41180a91e535bd5b55d4dce2c17419870203010001028180491b277413fb35efe82dace68b544a9dd6aa8917d329731955ec66ec3b0178fcf5a29196e1a6c093bf6c8064b36a8f0d9840a78003d11392754a70a77788975515a1442a6c806cafa2f07fe99cac78a86fa868888d654cec4baf205352cf8255acaa47e2455f23b58c0e5ae43fa297bbffe5b970caa80f71e82084fd35425479024100ef27f3fb2df90ac4910ed95fdde4877d09b0dc4e95079f12a7e2041300a8884a39372a1c79691338cd5c3965bcf3a24f2ce9e10de19d4cb87c7546d60ca0aa0d024073e9e1283475e9ab3075da0b005ca7c7b05e76325f8deb648238831c8353041d594307f784cd527cfee9187b997713d71c0ff98f01beac4d1a85583be52e90e302402f0c801e311c2677274671933f96fee4a56c6adaf6ccaa09c4875d5fd3a8542fadf3e14ffabea62e6d90302688b6b17ebc0a42e1353a79e66d6db102d9371e5d02406731ef3c8607fbf266806590a9cfd3a79a435ee355e2d9906fc6b4236c5f3a288ed178844a7d295512f49ed15b3d82325e4f729478af3262aa9bd083f273d49502410090a32c0e8ca3bcd4c66f092cdc369cd1abb4a05b9a6f0e65e5a51da1d96d5aca8c1525b3f11322c0588062fc8592ebf25b7950f918d39018e82b8acccc8f7e7a":PSA_KEY_TYPE_RSA_KEYPAIR:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:PSA_KEY_USAGE_EXPORT:1023:0:PSA_SUCCESS:1
|
||||
|
||||
PSA import/export-public RSA public key: good, 1024-bit
|
||||
depends_on:MBEDTLS_PK_C:MBEDTLS_PK_PARSE_C:MBEDTLS_RSA_C
|
||||
import_export_public_key:"30819f300d06092a864886f70d010101050003818d0030818902818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc30203010001":PSA_KEY_TYPE_RSA_PUBLIC_KEY:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:1024:162:PSA_SUCCESS
|
||||
|
||||
PSA import/export-public PSA keypair: good, 1024-bit
|
||||
depends_on:MBEDTLS_PK_C:MBEDTLS_PK_PARSE_C:MBEDTLS_RSA_C
|
||||
import_export_public_key:"3082025e02010002818100af057d396ee84fb75fdbb5c2b13c7fe5a654aa8aa2470b541ee1feb0b12d25c79711531249e1129628042dbbb6c120d1443524ef4c0e6e1d8956eeb2077af12349ddeee54483bc06c2c61948cd02b202e796aebd94d3a7cbf859c2c1819c324cb82b9cd34ede263a2abffe4733f077869e8660f7d6834da53d690ef7985f6bc3020301000102818100874bf0ffc2f2a71d14671ddd0171c954d7fdbf50281e4f6d99ea0e1ebcf82faa58e7b595ffb293d1abe17f110b37c48cc0f36c37e84d876621d327f64bbe08457d3ec4098ba2fa0a319fba411c2841ed7be83196a8cdf9daa5d00694bc335fc4c32217fe0488bce9cb7202e59468b1ead119000477db2ca797fac19eda3f58c1024100e2ab760841bb9d30a81d222de1eb7381d82214407f1b975cbbfe4e1a9467fd98adbd78f607836ca5be1928b9d160d97fd45c12d6b52e2c9871a174c66b488113024100c5ab27602159ae7d6f20c3c2ee851e46dc112e689e28d5fcbbf990a99ef8a90b8bb44fd36467e7fc1789ceb663abda338652c3c73f111774902e840565927091024100b6cdbd354f7df579a63b48b3643e353b84898777b48b15f94e0bfc0567a6ae5911d57ad6409cf7647bf96264e9bd87eb95e263b7110b9a1f9f94acced0fafa4d024071195eec37e8d257decfc672b07ae639f10cbb9b0c739d0c809968d644a94e3fd6ed9287077a14583f379058f76a8aecd43c62dc8c0f41766650d725275ac4a1024100bb32d133edc2e048d463388b7be9cb4be29f4b6250be603e70e3647501c97ddde20a4e71be95fd5e71784e25aca4baf25be5738aae59bbfe1c997781447a2b24":PSA_KEY_TYPE_RSA_KEYPAIR:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:1024:162:PSA_SUCCESS
|
||||
|
||||
PSA import/export-public symmetric key: bad, try to use export public key with symmetric key type 128-bit
|
||||
depends_on:MBEDTLS_PK_C:MBEDTLS_PK_PARSE_C:MBEDTLS_RSA_C
|
||||
import_export_public_key:"2b7e151628aed2a6abf7158809cf4f3c":PSA_KEY_TYPE_AES:PSA_ALG_CBC_BASE | PSA_ALG_BLOCK_CIPHER_PAD_NONE:128:162:PSA_ERROR_INVALID_ARGUMENT
|
||||
|
||||
PSA import/export EC secp256r1: good
|
||||
depends_on:MBEDTLS_PK_C:MBEDTLS_PK_PARSE_C:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
|
|
|
@ -49,7 +49,10 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void import_export( char *hex, int type_arg,
|
||||
void import_export( char *hex,
|
||||
int type_arg,
|
||||
int alg_arg,
|
||||
int usage_arg,
|
||||
int expected_bits,
|
||||
int export_size_delta,
|
||||
int expected_export_status,
|
||||
|
@ -84,8 +87,7 @@ void import_export( char *hex, int type_arg,
|
|||
|
||||
psa_key_policy_init( &policy );
|
||||
|
||||
psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_EXPORT,
|
||||
PSA_ALG_VENDOR_FLAG );
|
||||
psa_key_policy_set_usage( &policy, usage_arg, alg_arg );
|
||||
|
||||
TEST_ASSERT( psa_set_key_policy( slot, &policy ) == PSA_SUCCESS );
|
||||
|
||||
|
@ -141,6 +143,74 @@ exit:
|
|||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void import_export_public_key( char *hex,
|
||||
int type_arg,
|
||||
int alg_arg,
|
||||
int expected_bits,
|
||||
int public_key_expected_length,
|
||||
int expected_export_status )
|
||||
{
|
||||
int slot = 1;
|
||||
psa_key_type_t type = type_arg;
|
||||
psa_status_t status;
|
||||
unsigned char *data = NULL;
|
||||
unsigned char *exported = NULL;
|
||||
size_t data_size;
|
||||
size_t export_size;
|
||||
size_t exported_length;
|
||||
psa_key_type_t got_type;
|
||||
size_t got_bits;
|
||||
psa_key_policy_t policy = {0};
|
||||
|
||||
data = unhexify_alloc( hex, &data_size );
|
||||
TEST_ASSERT( data != NULL );
|
||||
export_size = (ssize_t) data_size ;
|
||||
exported = mbedtls_calloc( 1, export_size );
|
||||
TEST_ASSERT( exported != NULL );
|
||||
|
||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||
|
||||
psa_key_policy_init( &policy );
|
||||
|
||||
psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_EXPORT,
|
||||
alg_arg );
|
||||
|
||||
TEST_ASSERT( psa_set_key_policy( slot, &policy ) == PSA_SUCCESS );
|
||||
|
||||
/* Import the key */
|
||||
TEST_ASSERT( psa_import_key( slot, type,
|
||||
data, data_size ) == PSA_SUCCESS );
|
||||
|
||||
/* Test the key information */
|
||||
TEST_ASSERT( psa_get_key_information( slot,
|
||||
&got_type, &got_bits ) == PSA_SUCCESS );
|
||||
TEST_ASSERT( got_type == type );
|
||||
TEST_ASSERT( got_bits == (size_t) expected_bits );
|
||||
|
||||
/* Export the key */
|
||||
status = psa_export_public_key( slot,
|
||||
exported, export_size,
|
||||
&exported_length );
|
||||
TEST_ASSERT( status == (psa_status_t) expected_export_status );
|
||||
if( status != PSA_SUCCESS )
|
||||
goto destroy;
|
||||
|
||||
TEST_ASSERT( exported_length == (size_t) public_key_expected_length );
|
||||
|
||||
destroy:
|
||||
/* Destroy the key */
|
||||
TEST_ASSERT( psa_destroy_key( slot ) == PSA_SUCCESS );
|
||||
TEST_ASSERT( psa_get_key_information(
|
||||
slot, NULL, NULL ) == PSA_ERROR_EMPTY_SLOT );
|
||||
|
||||
exit:
|
||||
mbedtls_free( data );
|
||||
mbedtls_psa_crypto_free( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void hash_finish( int alg_arg, char *input_hex, char *hash_hex )
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue