1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2026-01-06 11:41:12 +03:00

Normalize whitespace

Normalize whitespace to Mbed TLS standards. There are only whitespace
changes in this commit.
This commit is contained in:
Gilles Peskine
2018-06-18 15:41:12 +02:00
committed by itayzafrir
parent 6de7a179c8
commit 2d2778650b
4 changed files with 225 additions and 219 deletions

View File

@@ -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_key_type_t type,
const uint8_t *data,
size_t data_length)
psa_status_t psa_import_key( psa_key_slot_t key,
psa_key_type_t type,
const uint8_t *data,
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_key_type_t *type,
size_t *bits)
psa_status_t psa_get_key_information( psa_key_slot_t key,
psa_key_type_t *type,
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,
uint8_t *data,
size_t data_size,
size_t *data_length,
int export_public_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 )
{
key_slot_t *slot;
@@ -492,7 +496,7 @@ static psa_status_t psa_internal_export_key(psa_key_slot_t key,
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 )
@@ -542,23 +546,23 @@ static psa_status_t psa_internal_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)
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 );
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)
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 );
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,
const uint8_t *hash,
size_t hash_length)
psa_status_t psa_hash_verify( psa_hash_operation_t *operation,
const uint8_t *hash,
size_t hash_length )
{
uint8_t actual_hash[MBEDTLS_MD_MAX_SIZE];
size_t actual_hash_length;
@@ -912,7 +916,7 @@ psa_status_t psa_hash_verify(psa_hash_operation_t *operation,
static const mbedtls_cipher_info_t *mbedtls_cipher_info_from_psa(
psa_algorithm_t alg,
psa_key_type_t key_type,
size_t key_bits,
size_t key_bits,
mbedtls_cipher_id_t* cipher_id )
{
mbedtls_cipher_mode_t mode;
@@ -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 );
default:
return ( 0 );
return( 128 );
default:
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 */
@@ -1241,7 +1244,7 @@ psa_status_t psa_mac_update( psa_mac_operation_t *operation,
if( PSA_ALG_IS_HMAC( operation->alg ) )
{
status = psa_hash_update( &operation->ctx.hmac.hash_ctx, input,
input_length );
input_length );
}
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 );
}
@@ -1261,9 +1264,9 @@ psa_status_t psa_mac_update( psa_mac_operation_t *operation,
}
static psa_status_t psa_mac_finish_internal( psa_mac_operation_t *operation,
uint8_t *mac,
size_t mac_size,
size_t *mac_length )
uint8_t *mac,
size_t mac_size,
size_t *mac_length )
{
int ret = 0;
psa_status_t status = PSA_SUCCESS;
@@ -1296,7 +1299,7 @@ static psa_status_t psa_mac_finish_internal( psa_mac_operation_t *operation,
unsigned char *opad = operation->ctx.hmac.opad;
size_t hash_size = 0;
size_t block_size =
psa_get_hash_block_size( ( PSA_ALG_HMAC_HASH( operation->alg ) ) );
psa_get_hash_block_size( ( PSA_ALG_HMAC_HASH( operation->alg ) ) );
if( block_size == 0 )
return( PSA_ERROR_NOT_SUPPORTED );
@@ -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;
}
@@ -1362,9 +1365,9 @@ psa_status_t psa_mac_finish( psa_mac_operation_t *operation,
mac_size, mac_length ) );
}
#define MBEDTLS_PSA_MAC_MAX_SIZE \
( MBEDTLS_MD_MAX_SIZE > MBEDTLS_MAX_BLOCK_LENGTH ? \
MBEDTLS_MD_MAX_SIZE : \
#define MBEDTLS_PSA_MAC_MAX_SIZE \
( MBEDTLS_MD_MAX_SIZE > MBEDTLS_MAX_BLOCK_LENGTH ? \
MBEDTLS_MD_MAX_SIZE : \
MBEDTLS_MAX_BLOCK_LENGTH )
psa_status_t psa_mac_verify( psa_mac_operation_t *operation,
const uint8_t *mac,
@@ -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,
psa_key_usage_t usage,
psa_algorithm_t alg)
void psa_key_policy_set_usage( psa_key_policy_t *policy,
psa_key_usage_t usage,
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;
@@ -2051,8 +2054,8 @@ psa_status_t psa_set_key_policy(psa_key_slot_t key,
return( PSA_ERROR_OCCUPIED_SLOT );
if( ( policy->usage & ~( PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT
| PSA_KEY_USAGE_DECRYPT | PSA_KEY_USAGE_SIGN
| PSA_KEY_USAGE_VERIFY ) ) != 0 )
| PSA_KEY_USAGE_DECRYPT | PSA_KEY_USAGE_SIGN
| PSA_KEY_USAGE_VERIFY ) ) != 0 )
return( PSA_ERROR_INVALID_ARGUMENT );
slot->policy = *policy;
@@ -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;
@@ -2146,7 +2149,7 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key,
size_t tag_length;
mbedtls_cipher_id_t cipher_id;
const mbedtls_cipher_info_t *cipher_info = NULL;
*ciphertext_length = 0;
status = psa_get_key_information( key, &key_type, &key_bits );
@@ -2154,18 +2157,18 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key,
return( status );
slot = &global_data.key_slots[key];
if( slot->type == PSA_KEY_TYPE_NONE )
return( PSA_ERROR_EMPTY_SLOT );
return( PSA_ERROR_EMPTY_SLOT );
cipher_info = mbedtls_cipher_info_from_psa( alg, key_type,
key_bits, &cipher_id );
if( cipher_info == NULL )
return( PSA_ERROR_NOT_SUPPORTED );
return( PSA_ERROR_NOT_SUPPORTED );
if( !( slot->policy.usage & PSA_KEY_USAGE_ENCRYPT ) )
return( PSA_ERROR_NOT_PERMITTED );
if ( ( key_type & PSA_KEY_TYPE_CATEGORY_MASK ) !=
PSA_KEY_TYPE_CATEGORY_SYMMETRIC )
if( ( key_type & PSA_KEY_TYPE_CATEGORY_MASK ) !=
PSA_KEY_TYPE_CATEGORY_SYMMETRIC )
return( PSA_ERROR_INVALID_ARGUMENT );
if( alg == PSA_ALG_GCM )
@@ -2238,13 +2241,13 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key,
{
return( PSA_ERROR_NOT_SUPPORTED );
}
if( ret != 0 )
{
memset( ciphertext, 0, ciphertext_size );
return( mbedtls_to_psa_error( ret ) );
}
*ciphertext_length = plaintext_length + tag_length;
return( PSA_SUCCESS );
}
@@ -2291,7 +2294,7 @@ psa_status_t psa_aead_decrypt( psa_key_slot_t key,
size_t tag_length;
mbedtls_cipher_id_t cipher_id;
const mbedtls_cipher_info_t *cipher_info = NULL;
*plaintext_length = 0;
status = psa_get_key_information( key, &key_type, &key_bits );
@@ -2299,18 +2302,18 @@ psa_status_t psa_aead_decrypt( psa_key_slot_t key,
return( status );
slot = &global_data.key_slots[key];
if( slot->type == PSA_KEY_TYPE_NONE )
return( PSA_ERROR_EMPTY_SLOT );
return( PSA_ERROR_EMPTY_SLOT );
cipher_info = mbedtls_cipher_info_from_psa( alg, key_type,
key_bits, &cipher_id );
if( cipher_info == NULL )
return( PSA_ERROR_NOT_SUPPORTED );
return( PSA_ERROR_NOT_SUPPORTED );
if( !( slot->policy.usage & PSA_KEY_USAGE_DECRYPT ) )
return( PSA_ERROR_NOT_PERMITTED );
if ( ( key_type & PSA_KEY_TYPE_CATEGORY_MASK ) !=
PSA_KEY_TYPE_CATEGORY_SYMMETRIC )
if( ( key_type & PSA_KEY_TYPE_CATEGORY_MASK ) !=
PSA_KEY_TYPE_CATEGORY_SYMMETRIC )
return( PSA_ERROR_INVALID_ARGUMENT );
if( alg == PSA_ALG_GCM )