mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-25 05:55:13 +00:00
Normalize whitespace
Normalize whitespace to Mbed TLS standards. There are only whitespace changes in this commit.
This commit is contained in:
parent
6de7a179c8
commit
2d2778650b
|
@ -84,7 +84,8 @@ struct psa_hash_operation_s
|
|||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
/** The hash context. */
|
||||
struct psa_hash_operation_s hash_ctx;
|
||||
/** The HMAC part of the context. */
|
||||
|
|
|
@ -94,12 +94,15 @@ static inline int safer_memcmp( const uint8_t *a, const uint8_t *b, size_t n )
|
|||
* The value is a compile-time constant for now, for simplicity. */
|
||||
#define MBEDTLS_PSA_KEY_SLOT_COUNT 32
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
psa_key_type_t type;
|
||||
psa_key_policy_t policy;
|
||||
psa_key_lifetime_t lifetime;
|
||||
union {
|
||||
struct raw_data {
|
||||
union
|
||||
{
|
||||
struct raw_data
|
||||
{
|
||||
uint8_t *data;
|
||||
size_t bytes;
|
||||
} raw;
|
||||
|
@ -112,7 +115,8 @@ typedef struct {
|
|||
} data;
|
||||
} key_slot_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int initialized;
|
||||
mbedtls_entropy_context entropy;
|
||||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
|
@ -305,10 +309,10 @@ static psa_status_t mbedtls_to_psa_error( int ret )
|
|||
/* Key management */
|
||||
/****************************************************************/
|
||||
|
||||
psa_status_t psa_import_key(psa_key_slot_t key,
|
||||
psa_status_t psa_import_key( psa_key_slot_t key,
|
||||
psa_key_type_t type,
|
||||
const uint8_t *data,
|
||||
size_t data_length)
|
||||
size_t data_length )
|
||||
{
|
||||
key_slot_t *slot;
|
||||
|
||||
|
@ -380,7 +384,7 @@ psa_status_t psa_import_key(psa_key_slot_t key,
|
|||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
psa_status_t psa_destroy_key(psa_key_slot_t key)
|
||||
psa_status_t psa_destroy_key( psa_key_slot_t key )
|
||||
{
|
||||
key_slot_t *slot;
|
||||
|
||||
|
@ -424,9 +428,9 @@ psa_status_t psa_destroy_key(psa_key_slot_t key)
|
|||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
psa_status_t psa_get_key_information(psa_key_slot_t key,
|
||||
psa_status_t psa_get_key_information( psa_key_slot_t key,
|
||||
psa_key_type_t *type,
|
||||
size_t *bits)
|
||||
size_t *bits )
|
||||
{
|
||||
key_slot_t *slot;
|
||||
|
||||
|
@ -472,11 +476,11 @@ psa_status_t psa_get_key_information(psa_key_slot_t key,
|
|||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
static psa_status_t psa_internal_export_key(psa_key_slot_t key,
|
||||
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)
|
||||
int export_public_key )
|
||||
{
|
||||
key_slot_t *slot;
|
||||
|
||||
|
@ -542,20 +546,20 @@ static psa_status_t psa_internal_export_key(psa_key_slot_t key,
|
|||
}
|
||||
}
|
||||
|
||||
psa_status_t psa_export_key(psa_key_slot_t key,
|
||||
psa_status_t psa_export_key( psa_key_slot_t key,
|
||||
uint8_t *data,
|
||||
size_t data_size,
|
||||
size_t *data_length)
|
||||
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,
|
||||
psa_status_t psa_export_public_key( psa_key_slot_t key,
|
||||
uint8_t *data,
|
||||
size_t data_size,
|
||||
size_t *data_length)
|
||||
size_t *data_length )
|
||||
{
|
||||
return psa_internal_export_key( key, data, data_size,
|
||||
data_length, 1 );
|
||||
|
@ -884,9 +888,9 @@ psa_status_t psa_hash_finish( psa_hash_operation_t *operation,
|
|||
}
|
||||
}
|
||||
|
||||
psa_status_t psa_hash_verify(psa_hash_operation_t *operation,
|
||||
psa_status_t psa_hash_verify( psa_hash_operation_t *operation,
|
||||
const uint8_t *hash,
|
||||
size_t hash_length)
|
||||
size_t hash_length )
|
||||
{
|
||||
uint8_t actual_hash[MBEDTLS_MD_MAX_SIZE];
|
||||
size_t actual_hash_length;
|
||||
|
@ -987,7 +991,7 @@ static const mbedtls_cipher_info_t *mbedtls_cipher_info_from_psa(
|
|||
|
||||
static size_t psa_get_hash_block_size( psa_algorithm_t alg )
|
||||
{
|
||||
switch(alg)
|
||||
switch( alg )
|
||||
{
|
||||
case PSA_ALG_MD2:
|
||||
return( 16 );
|
||||
|
@ -1006,9 +1010,9 @@ static size_t psa_get_hash_block_size( psa_algorithm_t alg )
|
|||
case PSA_ALG_SHA_384:
|
||||
return( 128 );
|
||||
case PSA_ALG_SHA_512:
|
||||
return ( 128 );
|
||||
return( 128 );
|
||||
default:
|
||||
return ( 0 );
|
||||
return( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1032,8 +1036,7 @@ psa_status_t psa_mac_abort( psa_mac_operation_t *operation )
|
|||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
|
||||
psa_hash_abort( &operation->ctx.hmac.hash_ctx );
|
||||
mbedtls_zeroize( operation->ctx.hmac.opad,
|
||||
block_size);
|
||||
mbedtls_zeroize( operation->ctx.hmac.opad, block_size );
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_MD_C */
|
||||
|
@ -1250,10 +1253,10 @@ psa_status_t psa_mac_update( psa_mac_operation_t *operation,
|
|||
}
|
||||
break;
|
||||
}
|
||||
if ( ( ret != 0 ) || ( status != PSA_SUCCESS ) )
|
||||
if( ( ret != 0 ) || ( status != PSA_SUCCESS ) )
|
||||
{
|
||||
psa_mac_abort( operation );
|
||||
if ( ret != 0 )
|
||||
if( ret != 0 )
|
||||
status = mbedtls_to_psa_error( ret );
|
||||
}
|
||||
|
||||
|
@ -1318,7 +1321,7 @@ static psa_status_t psa_mac_finish_internal( psa_mac_operation_t *operation,
|
|||
goto hmac_cleanup;
|
||||
|
||||
status = psa_hash_update( &operation->ctx.hmac.hash_ctx, tmp,
|
||||
hash_size);
|
||||
hash_size );
|
||||
if( status != PSA_SUCCESS )
|
||||
goto hmac_cleanup;
|
||||
|
||||
|
@ -1336,7 +1339,7 @@ static psa_status_t psa_mac_finish_internal( psa_mac_operation_t *operation,
|
|||
}
|
||||
cleanup:
|
||||
|
||||
if( ( ret == 0 ) && (status == PSA_SUCCESS) )
|
||||
if( ( ret == 0 ) && ( status == PSA_SUCCESS ) )
|
||||
{
|
||||
return( psa_mac_abort( operation ) );
|
||||
}
|
||||
|
@ -1344,7 +1347,7 @@ cleanup:
|
|||
{
|
||||
psa_mac_abort( operation );
|
||||
if( ret != 0 )
|
||||
status = mbedtls_to_psa_error(ret);
|
||||
status = mbedtls_to_psa_error( ret );
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -1598,7 +1601,7 @@ psa_status_t psa_asymmetric_verify( psa_key_slot_t key,
|
|||
{
|
||||
mbedtls_ecp_keypair *ecdsa = slot->data.ecp;
|
||||
int ret;
|
||||
(void)alg;
|
||||
(void) alg;
|
||||
ret = mbedtls_ecdsa_read_signature( ecdsa, hash, hash_length,
|
||||
signature, signature_size );
|
||||
return( mbedtls_to_psa_error( ret ) );
|
||||
|
@ -2015,31 +2018,31 @@ psa_status_t psa_cipher_abort( psa_cipher_operation_t *operation )
|
|||
/* Key Policy */
|
||||
/****************************************************************/
|
||||
|
||||
void psa_key_policy_init(psa_key_policy_t *policy)
|
||||
void psa_key_policy_init( psa_key_policy_t *policy )
|
||||
{
|
||||
memset( policy, 0, sizeof( psa_key_policy_t ) );
|
||||
}
|
||||
|
||||
void psa_key_policy_set_usage(psa_key_policy_t *policy,
|
||||
void psa_key_policy_set_usage( psa_key_policy_t *policy,
|
||||
psa_key_usage_t usage,
|
||||
psa_algorithm_t alg)
|
||||
psa_algorithm_t alg )
|
||||
{
|
||||
policy->usage = usage;
|
||||
policy->alg = alg;
|
||||
}
|
||||
|
||||
psa_key_usage_t psa_key_policy_get_usage(psa_key_policy_t *policy)
|
||||
psa_key_usage_t psa_key_policy_get_usage( psa_key_policy_t *policy )
|
||||
{
|
||||
return( policy->usage );
|
||||
}
|
||||
|
||||
psa_algorithm_t psa_key_policy_get_algorithm(psa_key_policy_t *policy)
|
||||
psa_algorithm_t psa_key_policy_get_algorithm( psa_key_policy_t *policy )
|
||||
{
|
||||
return( policy->alg );
|
||||
}
|
||||
|
||||
psa_status_t psa_set_key_policy(psa_key_slot_t key,
|
||||
const psa_key_policy_t *policy)
|
||||
psa_status_t psa_set_key_policy( psa_key_slot_t key,
|
||||
const psa_key_policy_t *policy )
|
||||
{
|
||||
key_slot_t *slot;
|
||||
|
||||
|
@ -2060,8 +2063,8 @@ psa_status_t psa_set_key_policy(psa_key_slot_t key,
|
|||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
psa_status_t psa_get_key_policy(psa_key_slot_t key,
|
||||
psa_key_policy_t *policy)
|
||||
psa_status_t psa_get_key_policy( psa_key_slot_t key,
|
||||
psa_key_policy_t *policy )
|
||||
{
|
||||
key_slot_t *slot;
|
||||
|
||||
|
@ -2081,8 +2084,8 @@ psa_status_t psa_get_key_policy(psa_key_slot_t key,
|
|||
/* Key Lifetime */
|
||||
/****************************************************************/
|
||||
|
||||
psa_status_t psa_get_key_lifetime(psa_key_slot_t key,
|
||||
psa_key_lifetime_t *lifetime)
|
||||
psa_status_t psa_get_key_lifetime( psa_key_slot_t key,
|
||||
psa_key_lifetime_t *lifetime )
|
||||
{
|
||||
key_slot_t *slot;
|
||||
|
||||
|
@ -2096,8 +2099,8 @@ psa_status_t psa_get_key_lifetime(psa_key_slot_t key,
|
|||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
psa_status_t psa_set_key_lifetime(psa_key_slot_t key,
|
||||
const psa_key_lifetime_t lifetime)
|
||||
psa_status_t psa_set_key_lifetime( psa_key_slot_t key,
|
||||
const psa_key_lifetime_t lifetime )
|
||||
{
|
||||
key_slot_t *slot;
|
||||
|
||||
|
@ -2164,7 +2167,7 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key,
|
|||
if( !( slot->policy.usage & PSA_KEY_USAGE_ENCRYPT ) )
|
||||
return( PSA_ERROR_NOT_PERMITTED );
|
||||
|
||||
if ( ( key_type & PSA_KEY_TYPE_CATEGORY_MASK ) !=
|
||||
if( ( key_type & PSA_KEY_TYPE_CATEGORY_MASK ) !=
|
||||
PSA_KEY_TYPE_CATEGORY_SYMMETRIC )
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
|
@ -2309,7 +2312,7 @@ psa_status_t psa_aead_decrypt( psa_key_slot_t key,
|
|||
if( !( slot->policy.usage & PSA_KEY_USAGE_DECRYPT ) )
|
||||
return( PSA_ERROR_NOT_PERMITTED );
|
||||
|
||||
if ( ( key_type & PSA_KEY_TYPE_CATEGORY_MASK ) !=
|
||||
if( ( key_type & PSA_KEY_TYPE_CATEGORY_MASK ) !=
|
||||
PSA_KEY_TYPE_CATEGORY_SYMMETRIC )
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
#include "mbedtls/md.h"
|
||||
|
||||
#if(UINT32_MAX > SIZE_MAX)
|
||||
#define PSA_CRYPTO_TEST_SIZE_T_RANGE(x) ((x) <= SIZE_MAX)
|
||||
#define PSA_CRYPTO_TEST_SIZE_T_RANGE( x ) ( ( x ) <= SIZE_MAX )
|
||||
#else
|
||||
#define PSA_CRYPTO_TEST_SIZE_T_RANGE(x) 1
|
||||
#define PSA_CRYPTO_TEST_SIZE_T_RANGE( x ) 1
|
||||
#endif
|
||||
/* END_HEADER */
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void init_deinit()
|
||||
void init_deinit( )
|
||||
{
|
||||
psa_status_t status;
|
||||
int i;
|
||||
|
@ -966,7 +966,7 @@ void aead_decrypt( int key_type_arg, data_t * key_data,
|
|||
expected_result );
|
||||
|
||||
|
||||
if ( expected_result == PSA_SUCCESS )
|
||||
if( expected_result == PSA_SUCCESS )
|
||||
{
|
||||
TEST_ASSERT( memcmp( output_data, expected_data->x,
|
||||
output_length ) == 0 );
|
||||
|
@ -986,7 +986,7 @@ void signature_size( int type_arg, int bits, int alg_arg, int expected_size_arg
|
|||
{
|
||||
psa_key_type_t type = type_arg;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
size_t actual_size = PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(type, bits, alg);
|
||||
size_t actual_size = PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( type, bits, alg );
|
||||
TEST_ASSERT( actual_size == (size_t) expected_size_arg );
|
||||
exit:
|
||||
;
|
||||
|
@ -1039,8 +1039,8 @@ void sign_deterministic( int key_type_arg, data_t *key_data,
|
|||
signature, signature_size,
|
||||
&signature_length ) == PSA_SUCCESS );
|
||||
TEST_ASSERT( signature_length == (size_t) output_data->len );
|
||||
TEST_ASSERT( memcmp( signature, output_data->x, (size_t) output_data->len )
|
||||
== 0 );
|
||||
TEST_ASSERT( memcmp( signature, output_data->x,
|
||||
(size_t) output_data->len ) == 0 );
|
||||
|
||||
exit:
|
||||
psa_destroy_key( slot );
|
||||
|
@ -1112,14 +1112,14 @@ void key_policy( int usage_arg, int alg_arg )
|
|||
|
||||
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
|
||||
|
||||
psa_key_policy_init(& policy_set );
|
||||
psa_key_policy_init(& policy_get );
|
||||
psa_key_policy_init( &policy_set );
|
||||
psa_key_policy_init( &policy_get );
|
||||
|
||||
psa_key_policy_set_usage( &policy_set, usage_arg, alg_arg );
|
||||
|
||||
TEST_ASSERT( psa_key_policy_get_usage( &policy_set ) == ( psa_key_usage_t )usage_arg );
|
||||
TEST_ASSERT( psa_key_policy_get_usage( &policy_set ) == (psa_key_usage_t) usage_arg );
|
||||
|
||||
TEST_ASSERT( psa_key_policy_get_algorithm( &policy_set) == ( psa_algorithm_t )alg_arg );
|
||||
TEST_ASSERT( psa_key_policy_get_algorithm( &policy_set ) == (psa_algorithm_t) alg_arg );
|
||||
|
||||
TEST_ASSERT( psa_set_key_policy( key_slot, &policy_set ) == PSA_SUCCESS );
|
||||
|
||||
|
@ -1162,7 +1162,9 @@ void key_policy_fail( int usage_arg, int alg_arg, int expected_status,
|
|||
keypair->x, (size_t) keypair->len ) ==
|
||||
PSA_SUCCESS );
|
||||
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 );
|
||||
}
|
||||
|
||||
|
@ -1368,21 +1370,21 @@ void asymmetric_encrypt_decrypt( int key_type_arg, data_t *key_data,
|
|||
/* We test encryption by checking that encrypt-then-decrypt gives back
|
||||
* the original plaintext because of the non-optional random
|
||||
* part of encryption process which prevents using fixed vectors. */
|
||||
TEST_ASSERT( psa_asymmetric_encrypt(slot, alg,
|
||||
TEST_ASSERT( psa_asymmetric_encrypt( slot, alg,
|
||||
input_data->x,
|
||||
(size_t) input_data->len,
|
||||
NULL, 0,
|
||||
output,
|
||||
output_size,
|
||||
&output_length) == PSA_SUCCESS );
|
||||
&output_length ) == PSA_SUCCESS );
|
||||
|
||||
TEST_ASSERT( psa_asymmetric_decrypt(slot, alg,
|
||||
TEST_ASSERT( psa_asymmetric_decrypt( slot, alg,
|
||||
output,
|
||||
output_length,
|
||||
NULL, 0,
|
||||
output2,
|
||||
output2_size,
|
||||
&output2_length) == PSA_SUCCESS );
|
||||
&output2_length ) == PSA_SUCCESS );
|
||||
TEST_ASSERT( memcmp( input_data->x, output2, (size_t) input_data->len )
|
||||
== 0 );
|
||||
|
||||
|
@ -1432,13 +1434,13 @@ void asymmetric_encrypt_fail( int key_type_arg, data_t *key_data,
|
|||
key_data->x, (size_t) key_data->len ) ==
|
||||
PSA_SUCCESS );
|
||||
|
||||
actual_status = psa_asymmetric_encrypt(slot, alg,
|
||||
actual_status = psa_asymmetric_encrypt( slot, alg,
|
||||
input_data->x,
|
||||
(size_t) input_data->len,
|
||||
NULL, 0,
|
||||
output,
|
||||
output_size,
|
||||
&output_length);
|
||||
&output_length );
|
||||
TEST_ASSERT( actual_status == expected_status );
|
||||
|
||||
exit:
|
||||
|
@ -1489,9 +1491,9 @@ void asymmetric_decrypt( int key_type_arg, data_t *key_data,
|
|||
NULL, 0,
|
||||
output,
|
||||
output_size,
|
||||
&output_length) == PSA_SUCCESS );
|
||||
TEST_ASSERT( ((size_t)expected_size) == output_length );
|
||||
TEST_ASSERT( memcmp( expected_data->x, output, (output_length) ) == 0 );
|
||||
&output_length ) == PSA_SUCCESS );
|
||||
TEST_ASSERT( ( (size_t) expected_size ) == output_length );
|
||||
TEST_ASSERT( memcmp( expected_data->x, output, ( output_length ) ) == 0 );
|
||||
|
||||
exit:
|
||||
psa_destroy_key( slot );
|
||||
|
@ -1538,18 +1540,18 @@ void asymmetric_decrypt_fail( int key_type_arg, data_t *key_data,
|
|||
key_data->x, (size_t) key_data->len ) ==
|
||||
PSA_SUCCESS );
|
||||
|
||||
actual_status = psa_asymmetric_decrypt(slot, alg,
|
||||
actual_status = psa_asymmetric_decrypt( slot, alg,
|
||||
input_data->x,
|
||||
(size_t) input_data->len,
|
||||
NULL, 0,
|
||||
output,
|
||||
output_size,
|
||||
&output_length);
|
||||
&output_length );
|
||||
TEST_ASSERT( actual_status == expected_status );
|
||||
|
||||
exit:
|
||||
psa_destroy_key( slot );
|
||||
mbedtls_free( output);
|
||||
mbedtls_free( output );
|
||||
mbedtls_psa_crypto_free( );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
|
Loading…
Reference in a new issue