Skip to content

Commit

Permalink
Add readers-writer locking to multipart operation id checks
Browse files Browse the repository at this point in the history
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
  • Loading branch information
Andrzej Kurek authored and Andrzej Kurek committed Nov 29, 2021
1 parent b7948b6 commit 50cc174
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions library/psa_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -4309,6 +4309,10 @@ psa_status_t psa_aead_update_ad( psa_aead_operation_t *operation,
operation->ad_remaining -= input_length;
}

#if defined(MBEDTLS_THREADING_C)
if( mbedtls_rwlock_lock_reader( &mbedtls_psa_slots_lock ) != 0 )
return( PSA_ERROR_BAD_STATE );
#endif

status = psa_get_and_lock_key_slot( operation->key_id, &slot );
if( status != PSA_SUCCESS )
Expand All @@ -4332,6 +4336,10 @@ psa_status_t psa_aead_update_ad( psa_aead_operation_t *operation,
operation->ad_started = 1;
else
psa_aead_abort( operation );
#if defined(MBEDTLS_THREADING_C)
if( mbedtls_rwlock_unlock_reader( &mbedtls_psa_slots_lock ) != 0 )
return( PSA_ERROR_BAD_STATE );
#endif

return( status );
}
Expand Down Expand Up @@ -4382,6 +4390,11 @@ psa_status_t psa_aead_update( psa_aead_operation_t *operation,
operation->body_remaining -= input_length;
}

#if defined(MBEDTLS_THREADING_C)
if( mbedtls_rwlock_lock_reader( &mbedtls_psa_slots_lock ) != 0 )
return( PSA_ERROR_BAD_STATE );
#endif

status = psa_get_and_lock_key_slot( operation->key_id, &slot );
if( status != PSA_SUCCESS )
goto exit;
Expand All @@ -4406,6 +4419,11 @@ psa_status_t psa_aead_update( psa_aead_operation_t *operation,
else
psa_aead_abort( operation );

#if defined(MBEDTLS_THREADING_C)
if( mbedtls_rwlock_unlock_reader( &mbedtls_psa_slots_lock ) != 0 )
return( PSA_ERROR_BAD_STATE );
#endif

return( status );
}

Expand Down Expand Up @@ -4436,6 +4454,11 @@ psa_status_t psa_aead_finish( psa_aead_operation_t *operation,
*ciphertext_length = 0;
*tag_length = tag_size;

#if defined(MBEDTLS_THREADING_C)
if( mbedtls_rwlock_lock_reader( &mbedtls_psa_slots_lock ) != 0 )
return( PSA_ERROR_BAD_STATE );
#endif

status = psa_aead_final_checks( operation );
if( status != PSA_SUCCESS )
goto exit;
Expand Down Expand Up @@ -4481,6 +4504,11 @@ psa_status_t psa_aead_finish( psa_aead_operation_t *operation,

psa_aead_abort( operation );

#if defined(MBEDTLS_THREADING_C)
if( mbedtls_rwlock_unlock_reader( &mbedtls_psa_slots_lock ) != 0 )
return( PSA_ERROR_BAD_STATE );
#endif

return( status );
}

Expand All @@ -4498,6 +4526,11 @@ psa_status_t psa_aead_verify( psa_aead_operation_t *operation,

*plaintext_length = 0;

#if defined(MBEDTLS_THREADING_C)
if( mbedtls_rwlock_lock_reader( &mbedtls_psa_slots_lock ) != 0 )
return( PSA_ERROR_BAD_STATE );
#endif

status = psa_aead_final_checks( operation );
if( status != PSA_SUCCESS )
goto exit;
Expand Down Expand Up @@ -4530,6 +4563,11 @@ psa_status_t psa_aead_verify( psa_aead_operation_t *operation,
exit:
psa_aead_abort( operation );

#if defined(MBEDTLS_THREADING_C)
if( mbedtls_rwlock_unlock_reader( &mbedtls_psa_slots_lock ) != 0 )
return( PSA_ERROR_BAD_STATE );
#endif

return( status );
}

Expand Down

0 comments on commit 50cc174

Please sign in to comment.