mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-01 04:20:45 +00:00
Normalize whitespace to Mbed TLS standards
Only whitespace changes in this commit.
This commit is contained in:
parent
1c2a7ea4e2
commit
61b91d4476
@ -1203,39 +1203,39 @@ psa_status_t psa_mac_verify( psa_mac_operation_t *operation,
|
|||||||
/* Asymmetric cryptography */
|
/* Asymmetric cryptography */
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
|
||||||
static psa_status_t verify_RSA_hash_input_and_get_md_type(psa_algorithm_t alg, size_t hash_length, mbedtls_md_type_t *md_alg)
|
static psa_status_t verify_RSA_hash_input_and_get_md_type( psa_algorithm_t alg,
|
||||||
|
size_t hash_length,
|
||||||
|
mbedtls_md_type_t *md_alg )
|
||||||
{
|
{
|
||||||
psa_algorithm_t hash_alg = PSA_ALG_RSA_GET_HASH(alg);
|
psa_algorithm_t hash_alg = PSA_ALG_RSA_GET_HASH( alg );
|
||||||
const mbedtls_md_info_t *md_info = mbedtls_md_info_from_psa(hash_alg);
|
const mbedtls_md_info_t *md_info = mbedtls_md_info_from_psa( hash_alg );
|
||||||
*md_alg = hash_alg == 0 ? MBEDTLS_MD_NONE : mbedtls_md_get_type(md_info);
|
*md_alg = hash_alg == 0 ? MBEDTLS_MD_NONE : mbedtls_md_get_type( md_info );
|
||||||
if (*md_alg == MBEDTLS_MD_NONE)
|
if( *md_alg == MBEDTLS_MD_NONE )
|
||||||
{
|
{
|
||||||
#if SIZE_MAX > UINT_MAX
|
#if SIZE_MAX > UINT_MAX
|
||||||
if (hash_length > UINT_MAX)
|
if( hash_length > UINT_MAX )
|
||||||
return(PSA_ERROR_INVALID_ARGUMENT);
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (mbedtls_md_get_size(md_info) != hash_length)
|
if( mbedtls_md_get_size( md_info ) != hash_length )
|
||||||
return(PSA_ERROR_INVALID_ARGUMENT);
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
if (md_info == NULL)
|
if( md_info == NULL )
|
||||||
return(PSA_ERROR_NOT_SUPPORTED);
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
return PSA_SUCCESS;
|
return( PSA_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
psa_status_t psa_asymmetric_sign( psa_key_slot_t key,
|
||||||
|
psa_algorithm_t alg,
|
||||||
psa_status_t psa_asymmetric_sign(psa_key_slot_t key,
|
const uint8_t *hash,
|
||||||
psa_algorithm_t alg,
|
size_t hash_length,
|
||||||
const uint8_t *hash,
|
const uint8_t *salt,
|
||||||
size_t hash_length,
|
size_t salt_length,
|
||||||
const uint8_t *salt,
|
uint8_t *signature,
|
||||||
size_t salt_length,
|
size_t signature_size,
|
||||||
uint8_t *signature,
|
size_t *signature_length )
|
||||||
size_t signature_size,
|
|
||||||
size_t *signature_length)
|
|
||||||
{
|
{
|
||||||
key_slot_t *slot;
|
key_slot_t *slot;
|
||||||
psa_status_t status;
|
psa_status_t status;
|
||||||
@ -1243,7 +1243,6 @@ psa_status_t psa_asymmetric_sign(psa_key_slot_t key,
|
|||||||
(void) salt;
|
(void) salt;
|
||||||
(void) salt_length;
|
(void) salt_length;
|
||||||
|
|
||||||
|
|
||||||
if( key == 0 || key > MBEDTLS_PSA_KEY_SLOT_COUNT )
|
if( key == 0 || key > MBEDTLS_PSA_KEY_SLOT_COUNT )
|
||||||
return( PSA_ERROR_EMPTY_SLOT );
|
return( PSA_ERROR_EMPTY_SLOT );
|
||||||
slot = &global_data.key_slots[key];
|
slot = &global_data.key_slots[key];
|
||||||
@ -1251,7 +1250,7 @@ psa_status_t psa_asymmetric_sign(psa_key_slot_t key,
|
|||||||
return( PSA_ERROR_EMPTY_SLOT );
|
return( PSA_ERROR_EMPTY_SLOT );
|
||||||
if( ! PSA_KEY_TYPE_IS_KEYPAIR( slot->type ) )
|
if( ! PSA_KEY_TYPE_IS_KEYPAIR( slot->type ) )
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
if( !( slot->policy.usage & PSA_KEY_USAGE_SIGN ) )
|
if( ! ( slot->policy.usage & PSA_KEY_USAGE_SIGN ) )
|
||||||
return( PSA_ERROR_NOT_PERMITTED );
|
return( PSA_ERROR_NOT_PERMITTED );
|
||||||
|
|
||||||
#if defined(MBEDTLS_RSA_C)
|
#if defined(MBEDTLS_RSA_C)
|
||||||
@ -1261,9 +1260,9 @@ psa_status_t psa_asymmetric_sign(psa_key_slot_t key,
|
|||||||
int ret;
|
int ret;
|
||||||
mbedtls_md_type_t md_alg;
|
mbedtls_md_type_t md_alg;
|
||||||
status = verify_RSA_hash_input_and_get_md_type( alg, hash_length,
|
status = verify_RSA_hash_input_and_get_md_type( alg, hash_length,
|
||||||
&md_alg );
|
&md_alg );
|
||||||
if ( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
return status;
|
return( status );
|
||||||
|
|
||||||
if( signature_size < rsa->len )
|
if( signature_size < rsa->len )
|
||||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||||
@ -1315,8 +1314,9 @@ psa_status_t psa_asymmetric_sign(psa_key_slot_t key,
|
|||||||
md_info = mbedtls_md_info_from_psa( alg );
|
md_info = mbedtls_md_info_from_psa( alg );
|
||||||
md_alg = mbedtls_md_get_type( md_info );
|
md_alg = mbedtls_md_get_type( md_info );
|
||||||
ret = mbedtls_ecdsa_write_signature( ecdsa, md_alg, hash, hash_length,
|
ret = mbedtls_ecdsa_write_signature( ecdsa, md_alg, hash, hash_length,
|
||||||
signature, signature_length, mbedtls_ctr_drbg_random,
|
signature, signature_length,
|
||||||
&global_data.ctr_drbg );
|
mbedtls_ctr_drbg_random,
|
||||||
|
&global_data.ctr_drbg );
|
||||||
return( mbedtls_to_psa_error( ret ) );
|
return( mbedtls_to_psa_error( ret ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1326,14 +1326,14 @@ psa_status_t psa_asymmetric_sign(psa_key_slot_t key,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t psa_asymmetric_verify(psa_key_slot_t key,
|
psa_status_t psa_asymmetric_verify( psa_key_slot_t key,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
const uint8_t *hash,
|
const uint8_t *hash,
|
||||||
size_t hash_length,
|
size_t hash_length,
|
||||||
const uint8_t *salt,
|
const uint8_t *salt,
|
||||||
size_t salt_length,
|
size_t salt_length,
|
||||||
uint8_t *signature,
|
uint8_t *signature,
|
||||||
size_t signature_size)
|
size_t signature_size )
|
||||||
{
|
{
|
||||||
key_slot_t *slot;
|
key_slot_t *slot;
|
||||||
psa_status_t status;
|
psa_status_t status;
|
||||||
@ -1345,20 +1345,20 @@ psa_status_t psa_asymmetric_verify(psa_key_slot_t key,
|
|||||||
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_EMPTY_SLOT );
|
return( PSA_ERROR_EMPTY_SLOT );
|
||||||
if (!(slot->policy.usage & PSA_KEY_USAGE_VERIFY))
|
if( ! ( slot->policy.usage & PSA_KEY_USAGE_VERIFY ) )
|
||||||
return(PSA_ERROR_NOT_PERMITTED);
|
return( PSA_ERROR_NOT_PERMITTED );
|
||||||
|
|
||||||
#if defined(MBEDTLS_RSA_C)
|
#if defined(MBEDTLS_RSA_C)
|
||||||
if( ( slot->type == PSA_KEY_TYPE_RSA_KEYPAIR ) ||
|
if( ( slot->type == PSA_KEY_TYPE_RSA_KEYPAIR ) ||
|
||||||
( slot->type == PSA_KEY_TYPE_RSA_PUBLIC_KEY ) )
|
( slot->type == PSA_KEY_TYPE_RSA_PUBLIC_KEY ) )
|
||||||
{
|
{
|
||||||
mbedtls_rsa_context *rsa = slot->data.rsa;
|
mbedtls_rsa_context *rsa = slot->data.rsa;
|
||||||
int ret;
|
int ret;
|
||||||
mbedtls_md_type_t md_alg;
|
mbedtls_md_type_t md_alg;
|
||||||
status = verify_RSA_hash_input_and_get_md_type(alg, hash_length,
|
status = verify_RSA_hash_input_and_get_md_type( alg, hash_length,
|
||||||
&md_alg);
|
&md_alg );
|
||||||
if (status != PSA_SUCCESS)
|
if( status != PSA_SUCCESS )
|
||||||
return status;
|
return( status );
|
||||||
|
|
||||||
if( signature_size < rsa->len )
|
if( signature_size < rsa->len )
|
||||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||||
@ -1369,13 +1369,13 @@ psa_status_t psa_asymmetric_verify(psa_key_slot_t key,
|
|||||||
MBEDTLS_MD_NONE );
|
MBEDTLS_MD_NONE );
|
||||||
|
|
||||||
ret = mbedtls_rsa_pkcs1_verify( rsa,
|
ret = mbedtls_rsa_pkcs1_verify( rsa,
|
||||||
mbedtls_ctr_drbg_random,
|
mbedtls_ctr_drbg_random,
|
||||||
&global_data.ctr_drbg,
|
&global_data.ctr_drbg,
|
||||||
MBEDTLS_RSA_PUBLIC,
|
MBEDTLS_RSA_PUBLIC,
|
||||||
md_alg,
|
md_alg,
|
||||||
hash_length,
|
hash_length,
|
||||||
hash,
|
hash,
|
||||||
signature );
|
signature );
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1400,9 +1400,9 @@ psa_status_t psa_asymmetric_verify(psa_key_slot_t key,
|
|||||||
mbedtls_ecp_keypair *ecdsa = slot->data.ecp;
|
mbedtls_ecp_keypair *ecdsa = slot->data.ecp;
|
||||||
int ret;
|
int ret;
|
||||||
(void)alg;
|
(void)alg;
|
||||||
ret = mbedtls_ecdsa_read_signature(ecdsa, hash, hash_length, signature,
|
ret = mbedtls_ecdsa_read_signature( ecdsa, hash, hash_length,
|
||||||
signature_size);
|
signature, signature_size );
|
||||||
return(mbedtls_to_psa_error(ret));
|
return( mbedtls_to_psa_error( ret ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* defined(MBEDTLS_ECP_C) */
|
#endif /* defined(MBEDTLS_ECP_C) */
|
||||||
@ -1411,16 +1411,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;
|
||||||
(void) salt;
|
(void) salt;
|
||||||
@ -1434,28 +1433,27 @@ psa_status_t psa_asymmetric_encrypt(psa_key_slot_t key,
|
|||||||
return( PSA_ERROR_EMPTY_SLOT );
|
return( PSA_ERROR_EMPTY_SLOT );
|
||||||
if( ! PSA_KEY_TYPE_IS_KEYPAIR( slot->type ) )
|
if( ! PSA_KEY_TYPE_IS_KEYPAIR( slot->type ) )
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
if (!(slot->policy.usage & PSA_KEY_USAGE_ENCRYPT))
|
if( ! ( slot->policy.usage & PSA_KEY_USAGE_ENCRYPT ) )
|
||||||
return(PSA_ERROR_NOT_PERMITTED);
|
return( PSA_ERROR_NOT_PERMITTED );
|
||||||
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_RSA_C)
|
#if defined(MBEDTLS_RSA_C)
|
||||||
if( ( slot->type == PSA_KEY_TYPE_RSA_KEYPAIR ) ||
|
if( ( slot->type == PSA_KEY_TYPE_RSA_KEYPAIR ) ||
|
||||||
( slot->type == PSA_KEY_TYPE_RSA_PUBLIC_KEY) )
|
( slot->type == PSA_KEY_TYPE_RSA_PUBLIC_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 )
|
||||||
{
|
{
|
||||||
ret = mbedtls_rsa_pkcs1_encrypt( rsa,
|
ret = mbedtls_rsa_pkcs1_encrypt( rsa,
|
||||||
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 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* MBEDTLS_PKCS1_V15 */
|
#endif /* MBEDTLS_PKCS1_V15 */
|
||||||
@ -1488,16 +1486,15 @@ psa_status_t psa_asymmetric_encrypt(psa_key_slot_t key,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
(void) salt;
|
(void) salt;
|
||||||
@ -1511,8 +1508,8 @@ psa_status_t psa_asymmetric_decrypt(psa_key_slot_t key,
|
|||||||
return( PSA_ERROR_EMPTY_SLOT );
|
return( PSA_ERROR_EMPTY_SLOT );
|
||||||
if( ! PSA_KEY_TYPE_IS_KEYPAIR( slot->type ) )
|
if( ! PSA_KEY_TYPE_IS_KEYPAIR( slot->type ) )
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
if (!(slot->policy.usage & PSA_KEY_USAGE_DECRYPT))
|
if( ! ( slot->policy.usage & PSA_KEY_USAGE_DECRYPT ) )
|
||||||
return(PSA_ERROR_NOT_PERMITTED);
|
return( PSA_ERROR_NOT_PERMITTED );
|
||||||
|
|
||||||
#if defined(MBEDTLS_RSA_C)
|
#if defined(MBEDTLS_RSA_C)
|
||||||
if( slot->type == PSA_KEY_TYPE_RSA_KEYPAIR )
|
if( slot->type == PSA_KEY_TYPE_RSA_KEYPAIR )
|
||||||
@ -1526,14 +1523,14 @@ psa_status_t psa_asymmetric_decrypt(psa_key_slot_t key,
|
|||||||
#if defined(MBEDTLS_PKCS1_V15)
|
#if defined(MBEDTLS_PKCS1_V15)
|
||||||
if( alg == PSA_ALG_RSA_PKCS1V15_CRYPT )
|
if( alg == PSA_ALG_RSA_PKCS1V15_CRYPT )
|
||||||
{
|
{
|
||||||
ret = mbedtls_rsa_pkcs1_decrypt( rsa,
|
ret = mbedtls_rsa_pkcs1_decrypt( rsa,
|
||||||
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
|
||||||
#endif /* MBEDTLS_PKCS1_V15 */
|
#endif /* MBEDTLS_PKCS1_V15 */
|
||||||
|
@ -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 );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user