mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-07-09 21:47:33 +00:00
Update multipart hash operations to abort on error
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
ff8d52b398
commit
4e0a82e274
|
@ -2169,34 +2169,51 @@ psa_status_t psa_hash_abort( psa_hash_operation_t *operation )
|
||||||
psa_status_t psa_hash_setup( psa_hash_operation_t *operation,
|
psa_status_t psa_hash_setup( psa_hash_operation_t *operation,
|
||||||
psa_algorithm_t alg )
|
psa_algorithm_t alg )
|
||||||
{
|
{
|
||||||
/* A context must be freshly initialized before it can be set up. */
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
if( operation->id != 0 )
|
|
||||||
return( PSA_ERROR_BAD_STATE );
|
|
||||||
|
|
||||||
if( !PSA_ALG_IS_HASH( alg ) )
|
/* A context must be freshly initialized before it can be set up. */
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
if( operation->id != 0 ) {
|
||||||
|
status = PSA_ERROR_BAD_STATE;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !PSA_ALG_IS_HASH( alg ) ) {
|
||||||
|
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
/* Ensure all of the context is zeroized, since PSA_HASH_OPERATION_INIT only
|
/* Ensure all of the context is zeroized, since PSA_HASH_OPERATION_INIT only
|
||||||
* directly zeroes the int-sized dummy member of the context union. */
|
* directly zeroes the int-sized dummy member of the context union. */
|
||||||
memset( &operation->ctx, 0, sizeof( operation->ctx ) );
|
memset( &operation->ctx, 0, sizeof( operation->ctx ) );
|
||||||
|
|
||||||
return( psa_driver_wrapper_hash_setup( operation, alg ) );
|
status = psa_driver_wrapper_hash_setup( operation, alg );
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if( status != PSA_SUCCESS )
|
||||||
|
psa_hash_abort(operation);
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t psa_hash_update( psa_hash_operation_t *operation,
|
psa_status_t psa_hash_update( psa_hash_operation_t *operation,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length )
|
size_t input_length )
|
||||||
{
|
{
|
||||||
if( operation->id == 0 )
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
return( PSA_ERROR_BAD_STATE );
|
|
||||||
|
if( operation->id == 0 ) {
|
||||||
|
status = PSA_ERROR_BAD_STATE;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
/* Don't require hash implementations to behave correctly on a
|
/* Don't require hash implementations to behave correctly on a
|
||||||
* zero-length input, which may have an invalid pointer. */
|
* zero-length input, which may have an invalid pointer. */
|
||||||
if( input_length == 0 )
|
if( input_length == 0 )
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
|
|
||||||
psa_status_t status = psa_driver_wrapper_hash_update( operation,
|
status = psa_driver_wrapper_hash_update( operation, input, input_length );
|
||||||
input, input_length );
|
|
||||||
|
exit:
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
psa_hash_abort( operation );
|
psa_hash_abort( operation );
|
||||||
|
|
||||||
|
@ -2228,13 +2245,23 @@ psa_status_t psa_hash_verify( psa_hash_operation_t *operation,
|
||||||
operation,
|
operation,
|
||||||
actual_hash, sizeof( actual_hash ),
|
actual_hash, sizeof( actual_hash ),
|
||||||
&actual_hash_length );
|
&actual_hash_length );
|
||||||
|
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
return( status );
|
goto exit;
|
||||||
if( actual_hash_length != hash_length )
|
|
||||||
return( PSA_ERROR_INVALID_SIGNATURE );
|
if( actual_hash_length != hash_length ) {
|
||||||
|
status = PSA_ERROR_INVALID_SIGNATURE;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if( mbedtls_psa_safer_memcmp( hash, actual_hash, actual_hash_length ) != 0 )
|
if( mbedtls_psa_safer_memcmp( hash, actual_hash, actual_hash_length ) != 0 )
|
||||||
return( PSA_ERROR_INVALID_SIGNATURE );
|
status = PSA_ERROR_INVALID_SIGNATURE;
|
||||||
return( PSA_SUCCESS );
|
|
||||||
|
exit:
|
||||||
|
if( status != PSA_SUCCESS )
|
||||||
|
psa_hash_abort(operation);
|
||||||
|
|
||||||
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t psa_hash_compute( psa_algorithm_t alg,
|
psa_status_t psa_hash_compute( psa_algorithm_t alg,
|
||||||
|
|
Loading…
Reference in a new issue