mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-02-02 07:41:03 +00:00
Remove trailing whitespace
Only horizontal whitespace changes in this commit.
This commit is contained in:
parent
6afe789d4c
commit
5b051bc608
|
@ -1442,15 +1442,15 @@ psa_status_t psa_asymmetric_verify(psa_key_slot_t key,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
psa_status_t psa_asymmetric_encrypt(psa_key_slot_t key,
|
psa_status_t psa_asymmetric_encrypt(psa_key_slot_t key,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
const uint8_t *salt,
|
const uint8_t *salt,
|
||||||
size_t salt_length,
|
size_t salt_length,
|
||||||
uint8_t *output,
|
uint8_t *output,
|
||||||
size_t output_size,
|
size_t output_size,
|
||||||
size_t *output_length)
|
size_t *output_length)
|
||||||
{
|
{
|
||||||
key_slot_t *slot;
|
key_slot_t *slot;
|
||||||
|
@ -1471,7 +1471,7 @@ psa_status_t psa_asymmetric_encrypt(psa_key_slot_t key,
|
||||||
{
|
{
|
||||||
mbedtls_rsa_context *rsa = slot->data.rsa;
|
mbedtls_rsa_context *rsa = slot->data.rsa;
|
||||||
int ret;
|
int ret;
|
||||||
if( output_size < rsa->len )
|
if( output_size < rsa->len )
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
#if defined(MBEDTLS_PKCS1_V15)
|
#if defined(MBEDTLS_PKCS1_V15)
|
||||||
if( alg == PSA_ALG_RSA_PKCS1V15_CRYPT )
|
if( alg == PSA_ALG_RSA_PKCS1V15_CRYPT )
|
||||||
|
@ -1480,7 +1480,7 @@ psa_status_t psa_asymmetric_encrypt(psa_key_slot_t key,
|
||||||
mbedtls_ctr_drbg_random,
|
mbedtls_ctr_drbg_random,
|
||||||
&global_data.ctr_drbg,
|
&global_data.ctr_drbg,
|
||||||
MBEDTLS_RSA_PUBLIC,
|
MBEDTLS_RSA_PUBLIC,
|
||||||
input_length,
|
input_length,
|
||||||
input,
|
input,
|
||||||
output );
|
output );
|
||||||
}
|
}
|
||||||
|
@ -1513,17 +1513,17 @@ psa_status_t psa_asymmetric_encrypt(psa_key_slot_t key,
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
psa_status_t psa_asymmetric_decrypt(psa_key_slot_t key,
|
psa_status_t psa_asymmetric_decrypt(psa_key_slot_t key,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
const uint8_t *salt,
|
const uint8_t *salt,
|
||||||
size_t salt_length,
|
size_t salt_length,
|
||||||
uint8_t *output,
|
uint8_t *output,
|
||||||
size_t output_size,
|
size_t output_size,
|
||||||
size_t *output_length)
|
size_t *output_length)
|
||||||
{
|
{
|
||||||
key_slot_t *slot;
|
key_slot_t *slot;
|
||||||
|
@ -1544,7 +1544,7 @@ psa_status_t psa_asymmetric_decrypt(psa_key_slot_t key,
|
||||||
mbedtls_rsa_context *rsa = slot->data.rsa;
|
mbedtls_rsa_context *rsa = slot->data.rsa;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if( output_size < rsa->len )
|
if( output_size < rsa->len )
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
#if defined(MBEDTLS_PKCS1_V15)
|
#if defined(MBEDTLS_PKCS1_V15)
|
||||||
|
@ -1555,9 +1555,9 @@ psa_status_t psa_asymmetric_decrypt(psa_key_slot_t key,
|
||||||
mbedtls_ctr_drbg_random,
|
mbedtls_ctr_drbg_random,
|
||||||
&global_data.ctr_drbg,
|
&global_data.ctr_drbg,
|
||||||
MBEDTLS_RSA_PRIVATE,
|
MBEDTLS_RSA_PRIVATE,
|
||||||
output_length,
|
output_length,
|
||||||
input,
|
input,
|
||||||
output,
|
output,
|
||||||
output_size );
|
output_size );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1589,8 +1589,8 @@ psa_status_t psa_asymmetric_decrypt(psa_key_slot_t key,
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
/* Key Policy */
|
/* Key Policy */
|
||||||
|
@ -1626,13 +1626,13 @@ psa_status_t psa_set_key_policy(psa_key_slot_t key,
|
||||||
|
|
||||||
if( key == 0 || key > MBEDTLS_PSA_KEY_SLOT_COUNT || policy == NULL )
|
if( key == 0 || key > MBEDTLS_PSA_KEY_SLOT_COUNT || policy == NULL )
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
slot = &global_data.key_slots[key];
|
slot = &global_data.key_slots[key];
|
||||||
if( slot->type != PSA_KEY_TYPE_NONE )
|
if( slot->type != PSA_KEY_TYPE_NONE )
|
||||||
return( PSA_ERROR_OCCUPIED_SLOT );
|
return( PSA_ERROR_OCCUPIED_SLOT );
|
||||||
|
|
||||||
if( ( policy->usage & ~( PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT
|
if( ( policy->usage & ~( PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT
|
||||||
| PSA_KEY_USAGE_DECRYPT | PSA_KEY_USAGE_SIGN
|
| PSA_KEY_USAGE_DECRYPT | PSA_KEY_USAGE_SIGN
|
||||||
| PSA_KEY_USAGE_VERIFY ) ) != 0 )
|
| PSA_KEY_USAGE_VERIFY ) ) != 0 )
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
|
@ -1650,7 +1650,7 @@ psa_status_t psa_get_key_policy(psa_key_slot_t key,
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
slot = &global_data.key_slots[key];
|
slot = &global_data.key_slots[key];
|
||||||
|
|
||||||
*policy = slot->policy;
|
*policy = slot->policy;
|
||||||
|
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
|
@ -1671,7 +1671,7 @@ psa_status_t psa_get_key_lifetime(psa_key_slot_t key,
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
slot = &global_data.key_slots[key];
|
slot = &global_data.key_slots[key];
|
||||||
|
|
||||||
*lifetime = slot->lifetime;
|
*lifetime = slot->lifetime;
|
||||||
|
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
|
@ -1685,8 +1685,8 @@ psa_status_t psa_set_key_lifetime(psa_key_slot_t key,
|
||||||
if( key == 0 || key > MBEDTLS_PSA_KEY_SLOT_COUNT )
|
if( key == 0 || key > MBEDTLS_PSA_KEY_SLOT_COUNT )
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
if( lifetime != PSA_KEY_LIFETIME_VOLATILE &&
|
if( lifetime != PSA_KEY_LIFETIME_VOLATILE &&
|
||||||
lifetime != PSA_KEY_LIFETIME_PERSISTENT &&
|
lifetime != PSA_KEY_LIFETIME_PERSISTENT &&
|
||||||
lifetime != PSA_KEY_LIFETIME_WRITE_ONCE)
|
lifetime != PSA_KEY_LIFETIME_WRITE_ONCE)
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
|
@ -1696,7 +1696,7 @@ psa_status_t psa_set_key_lifetime(psa_key_slot_t key,
|
||||||
|
|
||||||
if ( lifetime != PSA_KEY_LIFETIME_VOLATILE )
|
if ( lifetime != PSA_KEY_LIFETIME_VOLATILE )
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
|
|
||||||
slot->lifetime = lifetime;
|
slot->lifetime = lifetime;
|
||||||
|
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
|
|
44
tests/suites/test_suite_psa_crypto.function
Executable file → Normal file
44
tests/suites/test_suite_psa_crypto.function
Executable file → Normal file
|
@ -84,7 +84,7 @@ void import_export( char *hex, int type_arg,
|
||||||
|
|
||||||
psa_key_policy_init( &policy );
|
psa_key_policy_init( &policy );
|
||||||
|
|
||||||
psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_EXPORT,
|
psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_EXPORT,
|
||||||
PSA_ALG_VENDOR_FLAG );
|
PSA_ALG_VENDOR_FLAG );
|
||||||
|
|
||||||
TEST_ASSERT( psa_set_key_policy( slot, &policy ) == PSA_SUCCESS );
|
TEST_ASSERT( psa_set_key_policy( slot, &policy ) == PSA_SUCCESS );
|
||||||
|
@ -400,10 +400,9 @@ void key_policy( int usage_arg, int alg_arg )
|
||||||
unsigned char key[32] = {0};
|
unsigned char key[32] = {0};
|
||||||
psa_key_policy_t policy_set = {0};
|
psa_key_policy_t policy_set = {0};
|
||||||
psa_key_policy_t policy_get = {0};
|
psa_key_policy_t policy_get = {0};
|
||||||
|
|
||||||
|
|
||||||
memset( key, 0x2a, sizeof( key ) );
|
memset( key, 0x2a, sizeof( key ) );
|
||||||
|
|
||||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||||
|
|
||||||
psa_key_policy_init(& policy_set );
|
psa_key_policy_init(& policy_set );
|
||||||
|
@ -425,9 +424,6 @@ void key_policy( int usage_arg, int alg_arg )
|
||||||
TEST_ASSERT( policy_get.usage == policy_set.usage );
|
TEST_ASSERT( policy_get.usage == policy_set.usage );
|
||||||
TEST_ASSERT( policy_get.alg == policy_set.alg );
|
TEST_ASSERT( policy_get.alg == policy_set.alg );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
psa_destroy_key( key_slot );
|
psa_destroy_key( key_slot );
|
||||||
mbedtls_psa_crypto_free( );
|
mbedtls_psa_crypto_free( );
|
||||||
|
@ -443,7 +439,7 @@ void key_policy_fail( int usage_arg, int alg_arg, int expected_status, char *key
|
||||||
size_t signature_length = 0;
|
size_t signature_length = 0;
|
||||||
psa_key_policy_t policy = {0};
|
psa_key_policy_t policy = {0};
|
||||||
int actual_status = PSA_SUCCESS;
|
int actual_status = PSA_SUCCESS;
|
||||||
|
|
||||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||||
|
|
||||||
psa_key_policy_init( &policy );
|
psa_key_policy_init( &policy );
|
||||||
|
@ -458,11 +454,11 @@ void key_policy_fail( int usage_arg, int alg_arg, int expected_status, char *key
|
||||||
TEST_ASSERT( keypair != NULL );
|
TEST_ASSERT( keypair != NULL );
|
||||||
TEST_ASSERT( psa_import_key( key_slot, PSA_KEY_TYPE_RSA_KEYPAIR,
|
TEST_ASSERT( psa_import_key( key_slot, PSA_KEY_TYPE_RSA_KEYPAIR,
|
||||||
keypair, key_size ) == PSA_SUCCESS );
|
keypair, key_size ) == PSA_SUCCESS );
|
||||||
actual_status = psa_asymmetric_sign( key_slot,
|
actual_status = psa_asymmetric_sign( key_slot,
|
||||||
( psa_algorithm_t )alg_arg, NULL, 0, NULL, 0,
|
( psa_algorithm_t )alg_arg, NULL, 0, NULL, 0,
|
||||||
NULL, 0, &signature_length );
|
NULL, 0, &signature_length );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( usage_arg & PSA_KEY_USAGE_SIGN )
|
if( usage_arg & PSA_KEY_USAGE_SIGN )
|
||||||
{
|
{
|
||||||
keypair = unhexify_alloc( key_hex, &key_size );
|
keypair = unhexify_alloc( key_hex, &key_size );
|
||||||
|
@ -489,21 +485,29 @@ void key_lifetime( int lifetime_arg )
|
||||||
unsigned char key[32] = {0};
|
unsigned char key[32] = {0};
|
||||||
psa_key_lifetime_t lifetime_set = (psa_key_lifetime_t) lifetime_arg;
|
psa_key_lifetime_t lifetime_set = (psa_key_lifetime_t) lifetime_arg;
|
||||||
psa_key_lifetime_t lifetime_get;
|
psa_key_lifetime_t lifetime_get;
|
||||||
|
|
||||||
memset( key, 0x2a, sizeof( key ) );
|
memset( key, 0x2a, sizeof( key ) );
|
||||||
|
|
||||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||||
TEST_ASSERT( psa_set_key_lifetime( key_slot,
|
|
||||||
|
TEST_ASSERT( psa_set_key_lifetime( key_slot,
|
||||||
lifetime_set ) == PSA_SUCCESS );
|
lifetime_set ) == PSA_SUCCESS );
|
||||||
|
|
||||||
TEST_ASSERT( psa_import_key( key_slot, key_type,
|
TEST_ASSERT( psa_import_key( key_slot, key_type,
|
||||||
key, sizeof( key ) ) == PSA_SUCCESS );
|
key, sizeof( key ) ) == PSA_SUCCESS );
|
||||||
TEST_ASSERT( psa_get_key_lifetime( key_slot,
|
|
||||||
|
TEST_ASSERT( psa_get_key_lifetime( key_slot,
|
||||||
&lifetime_get ) == PSA_SUCCESS );
|
&lifetime_get ) == PSA_SUCCESS );
|
||||||
TEST_ASSERT( lifetime_get == lifetime_set );
|
|
||||||
|
TEST_ASSERT( lifetime_get == lifetime_set );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
psa_destroy_key( key_slot );
|
psa_destroy_key( key_slot );
|
||||||
mbedtls_psa_crypto_free( );
|
mbedtls_psa_crypto_free( );
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void key_lifetime_set_fail( int key_slot_arg, int lifetime_arg, int expected_status_arg )
|
void key_lifetime_set_fail( int key_slot_arg, int lifetime_arg, int expected_status_arg )
|
||||||
{
|
{
|
||||||
|
@ -518,7 +522,7 @@ void key_lifetime_set_fail( int key_slot_arg, int lifetime_arg, int expected_sta
|
||||||
|
|
||||||
if( actual_status == PSA_SUCCESS )
|
if( actual_status == PSA_SUCCESS )
|
||||||
actual_status = psa_set_key_lifetime( key_slot_arg, lifetime_set );
|
actual_status = psa_set_key_lifetime( key_slot_arg, lifetime_set );
|
||||||
|
|
||||||
TEST_ASSERT( expected_status == actual_status );
|
TEST_ASSERT( expected_status == actual_status );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
@ -654,7 +658,7 @@ void asymmetric_encrypt( int key_type_arg, char *key_hex,
|
||||||
TEST_ASSERT( psa_import_key( slot, key_type,
|
TEST_ASSERT( psa_import_key( slot, key_type,
|
||||||
key_data, key_size ) == PSA_SUCCESS );
|
key_data, key_size ) == PSA_SUCCESS );
|
||||||
|
|
||||||
//checked using encrypt/decrpyt because of non-optional random
|
//checked using encrypt/decrpyt because of non-optional random
|
||||||
// part of encryption process preventing using fixed vectors
|
// part of encryption process preventing using fixed vectors
|
||||||
TEST_ASSERT( psa_asymmetric_encrypt(slot, alg,
|
TEST_ASSERT( psa_asymmetric_encrypt(slot, alg,
|
||||||
input_data,
|
input_data,
|
||||||
|
@ -670,7 +674,7 @@ void asymmetric_encrypt( int key_type_arg, char *key_hex,
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
output2,
|
output2,
|
||||||
output2_size,
|
output2_size,
|
||||||
&output2_length) == PSA_SUCCESS );
|
&output2_length) == PSA_SUCCESS );
|
||||||
TEST_ASSERT( memcmp( input_data, output2, input_size ) == 0 );
|
TEST_ASSERT( memcmp( input_data, output2, input_size ) == 0 );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
@ -711,7 +715,7 @@ void asymmetric_encrypt_fail( int key_type_arg, char *key_hex,
|
||||||
TEST_ASSERT( input_data != NULL );
|
TEST_ASSERT( input_data != NULL );
|
||||||
output = mbedtls_calloc( 1, output_size );
|
output = mbedtls_calloc( 1, output_size );
|
||||||
TEST_ASSERT( output != NULL );
|
TEST_ASSERT( output != NULL );
|
||||||
|
|
||||||
|
|
||||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||||
|
|
||||||
|
@ -763,7 +767,7 @@ void asymmetric_decrypt( int key_type_arg, char *key_hex,
|
||||||
TEST_ASSERT( expected_data != NULL );
|
TEST_ASSERT( expected_data != NULL );
|
||||||
output = mbedtls_calloc( 1, output_size );
|
output = mbedtls_calloc( 1, output_size );
|
||||||
TEST_ASSERT( output != NULL );
|
TEST_ASSERT( output != NULL );
|
||||||
|
|
||||||
|
|
||||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||||
|
|
||||||
|
@ -818,7 +822,7 @@ void asymmetric_decrypt_fail( int key_type_arg, char *key_hex,
|
||||||
TEST_ASSERT( input_data != NULL );
|
TEST_ASSERT( input_data != NULL );
|
||||||
output = mbedtls_calloc( 1, output_size );
|
output = mbedtls_calloc( 1, output_size );
|
||||||
TEST_ASSERT( output != NULL );
|
TEST_ASSERT( output != NULL );
|
||||||
|
|
||||||
|
|
||||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||||
|
|
||||||
|
@ -841,4 +845,4 @@ exit:
|
||||||
mbedtls_free( output);
|
mbedtls_free( output);
|
||||||
mbedtls_psa_crypto_free( );
|
mbedtls_psa_crypto_free( );
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
Loading…
Reference in a new issue