mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-19 09:40:29 +00:00
Migrate p256-m_driver_entrypoints.[hc] to new code style
Signed-off-by: Aditya Deshpande <aditya.deshpande@arm.com>
This commit is contained in:
parent
ebd624e691
commit
ac363d8d20
58
3rdparty/p256-m/p256-m_driver_entrypoints.c
vendored
58
3rdparty/p256-m/p256-m_driver_entrypoints.c
vendored
@ -28,18 +28,17 @@
|
||||
|
||||
psa_status_t p256_to_psa_error(int ret)
|
||||
{
|
||||
switch( ret )
|
||||
{
|
||||
switch (ret) {
|
||||
case P256_SUCCESS:
|
||||
return( PSA_SUCCESS );
|
||||
return PSA_SUCCESS;
|
||||
case P256_INVALID_PUBKEY:
|
||||
case P256_INVALID_PRIVKEY:
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
case P256_INVALID_SIGNATURE:
|
||||
return( PSA_ERROR_INVALID_SIGNATURE );
|
||||
return PSA_ERROR_INVALID_SIGNATURE;
|
||||
case P256_RANDOM_FAILED:
|
||||
default:
|
||||
return( PSA_ERROR_GENERIC_ERROR );
|
||||
return PSA_ERROR_GENERIC_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,8 +57,9 @@ psa_status_t p256_transparent_generate_key(
|
||||
/*
|
||||
* p256-m generates a 32 byte private key, and expects to write to a buffer
|
||||
* that is of that size. */
|
||||
if( key_buffer_size != 32 )
|
||||
return( status );
|
||||
if (key_buffer_size != 32) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* p256-m's keypair generation function outputs both public and private
|
||||
@ -68,13 +68,15 @@ psa_status_t p256_transparent_generate_key(
|
||||
* function as an argument. */
|
||||
uint8_t *public_key_buffer = NULL;
|
||||
public_key_buffer = mbedtls_calloc(1, 64);
|
||||
if( public_key_buffer == NULL)
|
||||
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||
if (public_key_buffer == NULL) {
|
||||
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
|
||||
status = p256_to_psa_error(
|
||||
p256_gen_keypair(key_buffer, public_key_buffer));
|
||||
if( status == PSA_SUCCESS )
|
||||
if (status == PSA_SUCCESS) {
|
||||
*key_buffer_length = 32;
|
||||
}
|
||||
|
||||
/*
|
||||
* The storage format for a SECP256R1 keypair is just the private key, so
|
||||
@ -107,13 +109,15 @@ psa_status_t p256_transparent_key_agreement(
|
||||
* and that the shared secret buffer is big enough. */
|
||||
psa_status_t status = PSA_ERROR_NOT_SUPPORTED;
|
||||
if (key_buffer_size != 32 || shared_secret_size < 32 ||
|
||||
peer_key_length != 65 )
|
||||
return ( status );
|
||||
peer_key_length != 65) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = p256_to_psa_error(
|
||||
p256_ecdh_shared_secret(shared_secret, key_buffer, peer_key+1));
|
||||
if( status == PSA_SUCCESS )
|
||||
if (status == PSA_SUCCESS) {
|
||||
*shared_secret_length = 32;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
@ -136,13 +140,15 @@ psa_status_t p256_transparent_sign_hash(
|
||||
(void) alg;
|
||||
|
||||
psa_status_t status = PSA_ERROR_NOT_SUPPORTED;
|
||||
if( key_buffer_size != 32 || signature_size != 64)
|
||||
return( status );
|
||||
if (key_buffer_size != 32 || signature_size != 64) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = p256_to_psa_error(
|
||||
p256_ecdsa_sign(signature, key_buffer, hash, hash_length));
|
||||
if( status == PSA_SUCCESS )
|
||||
if (status == PSA_SUCCESS) {
|
||||
*signature_length = 64;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
@ -158,8 +164,9 @@ static psa_status_t p256_verify_hash_with_public_key(
|
||||
size_t signature_length)
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_NOT_SUPPORTED;
|
||||
if( key_buffer_size != 65 || signature_length != 64 || *key_buffer != 0x04 )
|
||||
if (key_buffer_size != 65 || signature_length != 64 || *key_buffer != 0x04) {
|
||||
return status;
|
||||
}
|
||||
|
||||
const uint8_t *public_key_buffer = key_buffer + 1;
|
||||
status = p256_to_psa_error(
|
||||
@ -186,12 +193,14 @@ psa_status_t p256_transparent_verify_hash(
|
||||
uint8_t *public_key_buffer = NULL;
|
||||
size_t public_key_buffer_size = 65;
|
||||
public_key_buffer = mbedtls_calloc(1, public_key_buffer_size);
|
||||
if( public_key_buffer == NULL)
|
||||
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||
if (public_key_buffer == NULL) {
|
||||
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
size_t *public_key_length = NULL;
|
||||
public_key_length = mbedtls_calloc(1, sizeof(size_t));
|
||||
if( public_key_length == NULL)
|
||||
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||
if (public_key_length == NULL) {
|
||||
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
*public_key_length = 65;
|
||||
|
||||
/* The contents of key_buffer may either be the 32 byte private key
|
||||
@ -204,8 +213,9 @@ psa_status_t p256_transparent_verify_hash(
|
||||
public_key_buffer,
|
||||
public_key_buffer_size,
|
||||
public_key_length);
|
||||
if( status != PSA_SUCCESS )
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
status = p256_verify_hash_with_public_key(
|
||||
public_key_buffer,
|
||||
@ -218,7 +228,7 @@ psa_status_t p256_transparent_verify_hash(
|
||||
exit:
|
||||
free(public_key_buffer);
|
||||
free(public_key_length);
|
||||
return ( status );
|
||||
return status;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_P256M_EXAMPLE_DRIVER_ENABLED */
|
||||
|
Loading…
x
Reference in New Issue
Block a user