mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-26 03:25:30 +00:00
psa: Call cipher operations software implementations as a driver
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
parent
6056fe8a81
commit
dd24c9bbd9
|
@ -3488,20 +3488,10 @@ psa_status_t psa_cipher_generate_iv( psa_cipher_operation_t *operation,
|
||||||
return( PSA_ERROR_BAD_STATE );
|
return( PSA_ERROR_BAD_STATE );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( operation->mbedtls_in_use == 0 )
|
status = psa_driver_wrapper_cipher_generate_iv( operation,
|
||||||
{
|
iv,
|
||||||
status = psa_driver_wrapper_cipher_generate_iv( operation,
|
iv_size,
|
||||||
iv,
|
iv_length );
|
||||||
iv_size,
|
|
||||||
iv_length );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
status = mbedtls_psa_cipher_generate_iv( operation,
|
|
||||||
iv,
|
|
||||||
iv_size,
|
|
||||||
iv_length );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
operation->iv_set = 1;
|
operation->iv_set = 1;
|
||||||
|
@ -3527,16 +3517,9 @@ psa_status_t psa_cipher_set_iv( psa_cipher_operation_t *operation,
|
||||||
return( PSA_ERROR_BAD_STATE );
|
return( PSA_ERROR_BAD_STATE );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( operation->mbedtls_in_use == 0 )
|
status = psa_driver_wrapper_cipher_set_iv( operation,
|
||||||
{
|
iv,
|
||||||
status = psa_driver_wrapper_cipher_set_iv( operation,
|
iv_length );
|
||||||
iv,
|
|
||||||
iv_length );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
status = mbedtls_psa_cipher_set_iv( operation, iv, iv_length );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
operation->iv_set = 1;
|
operation->iv_set = 1;
|
||||||
|
@ -3563,25 +3546,12 @@ psa_status_t psa_cipher_update( psa_cipher_operation_t *operation,
|
||||||
return( PSA_ERROR_BAD_STATE );
|
return( PSA_ERROR_BAD_STATE );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( operation->mbedtls_in_use == 0 )
|
status = psa_driver_wrapper_cipher_update( operation,
|
||||||
{
|
input,
|
||||||
status = psa_driver_wrapper_cipher_update( operation,
|
input_length,
|
||||||
input,
|
output,
|
||||||
input_length,
|
output_size,
|
||||||
output,
|
output_length );
|
||||||
output_size,
|
|
||||||
output_length );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
status = mbedtls_psa_cipher_update( operation,
|
|
||||||
input,
|
|
||||||
input_length,
|
|
||||||
output,
|
|
||||||
output_size,
|
|
||||||
output_length );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
psa_cipher_abort( operation );
|
psa_cipher_abort( operation );
|
||||||
|
|
||||||
|
@ -3604,21 +3574,10 @@ psa_status_t psa_cipher_finish( psa_cipher_operation_t *operation,
|
||||||
return( PSA_ERROR_BAD_STATE );
|
return( PSA_ERROR_BAD_STATE );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( operation->mbedtls_in_use == 0 )
|
status = psa_driver_wrapper_cipher_finish( operation,
|
||||||
{
|
output,
|
||||||
status = psa_driver_wrapper_cipher_finish( operation,
|
output_size,
|
||||||
output,
|
output_length );
|
||||||
output_size,
|
|
||||||
output_length );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
status = mbedtls_psa_cipher_finish( operation,
|
|
||||||
output,
|
|
||||||
output_size,
|
|
||||||
output_length );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
return( psa_cipher_abort( operation ) );
|
return( psa_cipher_abort( operation ) );
|
||||||
else
|
else
|
||||||
|
@ -3645,10 +3604,7 @@ psa_status_t psa_cipher_abort( psa_cipher_operation_t *operation )
|
||||||
if( ! PSA_ALG_IS_CIPHER( operation->alg ) )
|
if( ! PSA_ALG_IS_CIPHER( operation->alg ) )
|
||||||
return( PSA_ERROR_BAD_STATE );
|
return( PSA_ERROR_BAD_STATE );
|
||||||
|
|
||||||
if( operation->mbedtls_in_use == 0 )
|
psa_driver_wrapper_cipher_abort( operation );
|
||||||
psa_driver_wrapper_cipher_abort( operation );
|
|
||||||
else
|
|
||||||
mbedtls_psa_cipher_abort( operation );
|
|
||||||
|
|
||||||
operation->alg = 0;
|
operation->alg = 0;
|
||||||
operation->key_set = 0;
|
operation->key_set = 0;
|
||||||
|
|
|
@ -895,7 +895,13 @@ psa_status_t psa_driver_wrapper_cipher_generate_iv(
|
||||||
size_t iv_size,
|
size_t iv_size,
|
||||||
size_t *iv_length )
|
size_t *iv_length )
|
||||||
{
|
{
|
||||||
#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
if( operation->mbedtls_in_use )
|
||||||
|
return( mbedtls_psa_cipher_generate_iv( operation,
|
||||||
|
iv,
|
||||||
|
iv_size,
|
||||||
|
iv_length ) );
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
switch( operation->ctx.driver.id )
|
switch( operation->ctx.driver.id )
|
||||||
{
|
{
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
@ -906,6 +912,7 @@ psa_status_t psa_driver_wrapper_cipher_generate_iv(
|
||||||
iv_size,
|
iv_size,
|
||||||
iv_length ) );
|
iv_length ) );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
|
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
|
||||||
return( test_opaque_cipher_generate_iv(
|
return( test_opaque_cipher_generate_iv(
|
||||||
|
@ -914,18 +921,10 @@ psa_status_t psa_driver_wrapper_cipher_generate_iv(
|
||||||
iv_size,
|
iv_size,
|
||||||
iv_length ) );
|
iv_length ) );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
default:
|
|
||||||
/* Key is attached to a driver not known to us */
|
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
|
||||||
}
|
}
|
||||||
#else /* PSA_CRYPTO_DRIVER_PRESENT */
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
(void) operation;
|
|
||||||
(void) iv;
|
|
||||||
(void) iv_size;
|
|
||||||
(void) iv_length;
|
|
||||||
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_PRESENT */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t psa_driver_wrapper_cipher_set_iv(
|
psa_status_t psa_driver_wrapper_cipher_set_iv(
|
||||||
|
@ -933,7 +932,12 @@ psa_status_t psa_driver_wrapper_cipher_set_iv(
|
||||||
const uint8_t *iv,
|
const uint8_t *iv,
|
||||||
size_t iv_length )
|
size_t iv_length )
|
||||||
{
|
{
|
||||||
#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
if( operation->mbedtls_in_use )
|
||||||
|
return( mbedtls_psa_cipher_set_iv( operation,
|
||||||
|
iv,
|
||||||
|
iv_length ) );
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
switch( operation->ctx.driver.id )
|
switch( operation->ctx.driver.id )
|
||||||
{
|
{
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
@ -948,17 +952,10 @@ psa_status_t psa_driver_wrapper_cipher_set_iv(
|
||||||
iv,
|
iv,
|
||||||
iv_length ) );
|
iv_length ) );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
default:
|
|
||||||
/* Key is attached to a driver not known to us */
|
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
|
||||||
}
|
}
|
||||||
#else /* PSA_CRYPTO_DRIVER_PRESENT */
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
(void) operation;
|
|
||||||
(void) iv;
|
|
||||||
(void) iv_length;
|
|
||||||
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_PRESENT */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t psa_driver_wrapper_cipher_update(
|
psa_status_t psa_driver_wrapper_cipher_update(
|
||||||
|
@ -969,7 +966,15 @@ psa_status_t psa_driver_wrapper_cipher_update(
|
||||||
size_t output_size,
|
size_t output_size,
|
||||||
size_t *output_length )
|
size_t *output_length )
|
||||||
{
|
{
|
||||||
#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
if( operation->mbedtls_in_use )
|
||||||
|
return( mbedtls_psa_cipher_update( operation,
|
||||||
|
input,
|
||||||
|
input_length,
|
||||||
|
output,
|
||||||
|
output_size,
|
||||||
|
output_length ) );
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
switch( operation->ctx.driver.id )
|
switch( operation->ctx.driver.id )
|
||||||
{
|
{
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
@ -990,20 +995,10 @@ psa_status_t psa_driver_wrapper_cipher_update(
|
||||||
output_size,
|
output_size,
|
||||||
output_length ) );
|
output_length ) );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
default:
|
|
||||||
/* Key is attached to a driver not known to us */
|
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
|
||||||
}
|
}
|
||||||
#else /* PSA_CRYPTO_DRIVER_PRESENT */
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
(void) operation;
|
|
||||||
(void) input;
|
|
||||||
(void) input_length;
|
|
||||||
(void) output;
|
|
||||||
(void) output_length;
|
|
||||||
(void) output_size;
|
|
||||||
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_PRESENT */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t psa_driver_wrapper_cipher_finish(
|
psa_status_t psa_driver_wrapper_cipher_finish(
|
||||||
|
@ -1012,7 +1007,13 @@ psa_status_t psa_driver_wrapper_cipher_finish(
|
||||||
size_t output_size,
|
size_t output_size,
|
||||||
size_t *output_length )
|
size_t *output_length )
|
||||||
{
|
{
|
||||||
#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
if( operation->mbedtls_in_use )
|
||||||
|
return( mbedtls_psa_cipher_finish( operation,
|
||||||
|
output,
|
||||||
|
output_size,
|
||||||
|
output_length ) );
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
switch( operation->ctx.driver.id )
|
switch( operation->ctx.driver.id )
|
||||||
{
|
{
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
@ -1029,25 +1030,20 @@ psa_status_t psa_driver_wrapper_cipher_finish(
|
||||||
output_size,
|
output_size,
|
||||||
output_length ) );
|
output_length ) );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
default:
|
|
||||||
/* Key is attached to a driver not known to us */
|
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
|
||||||
}
|
}
|
||||||
#else /* PSA_CRYPTO_DRIVER_PRESENT */
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
(void) operation;
|
|
||||||
(void) output;
|
|
||||||
(void) output_size;
|
|
||||||
(void) output_length;
|
|
||||||
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_PRESENT */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t psa_driver_wrapper_cipher_abort(
|
psa_status_t psa_driver_wrapper_cipher_abort(
|
||||||
psa_cipher_operation_t *operation )
|
psa_cipher_operation_t *operation )
|
||||||
{
|
{
|
||||||
#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
if( operation->mbedtls_in_use )
|
||||||
psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
|
return( mbedtls_psa_cipher_abort( operation ) );
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
psa_operation_driver_context_t *driver_context = &operation->ctx.driver;
|
psa_operation_driver_context_t *driver_context = &operation->ctx.driver;
|
||||||
|
|
||||||
/* The object has (apparently) been initialized but it is not in use. It's
|
/* The object has (apparently) been initialized but it is not in use. It's
|
||||||
|
@ -1081,15 +1077,10 @@ psa_status_t psa_driver_wrapper_cipher_abort(
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
default:
|
|
||||||
/* Operation is attached to a driver not known to us */
|
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
|
||||||
}
|
}
|
||||||
#else /* PSA_CRYPTO_DRIVER_PRESENT */
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
(void)operation;
|
|
||||||
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_PRESENT */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue