psa: cipher: Dispatch based on driver identifier
For cipher multi-part operations, dispatch based on
the driver identifier even in the case of the
Mbed TLS software implementation (viewed as a driver).
Also use the driver identifier to check that an
cipher operation context is active or not.
This aligns the way hash and cipher multi-part
operations are dispatched.
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index 3dfee3b..f4d8a3e 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -3393,7 +3393,7 @@
PSA_KEY_USAGE_DECRYPT );
/* A context must be freshly initialized before it can be set up. */
- if( operation->alg != 0 )
+ if( operation->id != 0 )
return( PSA_ERROR_BAD_STATE );
/* The requested algorithm must be one that can be processed by cipher. */
@@ -3405,11 +3405,12 @@
if( status != PSA_SUCCESS )
goto exit;
- /* Initialize the operation struct members, except for alg. The alg member
+ /* Initialize the operation struct members, except for id. The id member
* is used to indicate to psa_cipher_abort that there are resources to free,
- * so we only set it after resources have been allocated/initialized. */
+ * so we only set it (in the driver wrapper) after resources have been
+ * allocated/initialized. */
+ operation->alg = alg;
operation->iv_set = 0;
- operation->mbedtls_in_use = 0;
operation->iv_size = 0;
operation->block_size = 0;
if( alg == PSA_ALG_ECB_NO_PADDING )
@@ -3435,13 +3436,6 @@
slot->key.bytes,
alg );
- if( status == PSA_SUCCESS )
- {
- /* Once the driver context is initialized, it needs to be freed using
- * psa_cipher_abort. Indicate this through setting alg. */
- operation->alg = alg;
- }
-
exit:
if( status != PSA_SUCCESS )
psa_cipher_abort( operation );
@@ -3472,7 +3466,7 @@
{
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- if( operation->alg == 0 )
+ if( operation->id == 0 )
{
return( PSA_ERROR_BAD_STATE );
}
@@ -3501,7 +3495,7 @@
{
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- if( operation->alg == 0 )
+ if( operation->id == 0 )
{
return( PSA_ERROR_BAD_STATE );
}
@@ -3531,7 +3525,7 @@
{
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- if( operation->alg == 0 )
+ if( operation->id == 0 )
{
return( PSA_ERROR_BAD_STATE );
}
@@ -3559,7 +3553,7 @@
{
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
- if( operation->alg == 0 )
+ if( operation->id == 0 )
{
return( PSA_ERROR_BAD_STATE );
}
@@ -3585,7 +3579,7 @@
psa_status_t psa_cipher_abort( psa_cipher_operation_t *operation )
{
- if( operation->alg == 0 )
+ if( operation->id == 0 )
{
/* The object has (apparently) been initialized but it is not (yet)
* in use. It's ok to call abort on such an object, and there's
@@ -3600,9 +3594,9 @@
psa_driver_wrapper_cipher_abort( operation );
+ operation->id = 0;
operation->alg = 0;
operation->iv_set = 0;
- operation->mbedtls_in_use = 0;
operation->iv_size = 0;
operation->block_size = 0;
operation->iv_required = 0;