Introduce PSA_PAKE_OPERATION_STAGE_SETUP to optimize out alg checks

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index bfbd497..2d1c065 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -7237,11 +7237,7 @@
     psa_pake_operation_t *operation,
     const psa_pake_cipher_suite_t *cipher_suite)
 {
-    if (operation->stage != PSA_PAKE_OPERATION_STAGE_COLLECT_INPUTS) {
-        return PSA_ERROR_BAD_STATE;
-    }
-
-    if (operation->alg != PSA_ALG_NONE) {
+    if (operation->stage != PSA_PAKE_OPERATION_STAGE_SETUP) {
         return PSA_ERROR_BAD_STATE;
     }
 
@@ -7266,6 +7262,8 @@
         computation_stage->output_step = PSA_PAKE_STEP_X1_X2;
     }
 
+    operation->stage = PSA_PAKE_OPERATION_STAGE_COLLECT_INPUTS;
+
     return PSA_SUCCESS;
 }
 
@@ -7281,10 +7279,6 @@
         return PSA_ERROR_BAD_STATE;
     }
 
-    if (operation->alg == PSA_ALG_NONE) {
-        return PSA_ERROR_BAD_STATE;
-    }
-
     status = psa_get_and_lock_key_slot_with_policy(password, &slot,
                                                    PSA_KEY_USAGE_DERIVE,
                                                    PSA_ALG_JPAKE);
@@ -7329,10 +7323,6 @@
         return PSA_ERROR_BAD_STATE;
     }
 
-    if (operation->alg == PSA_ALG_NONE) {
-        return PSA_ERROR_BAD_STATE;
-    }
-
     if (user_id_len == 0) {
         return PSA_ERROR_INVALID_ARGUMENT;
     }
@@ -7351,10 +7341,6 @@
         return PSA_ERROR_BAD_STATE;
     }
 
-    if (operation->alg == PSA_ALG_NONE) {
-        return PSA_ERROR_BAD_STATE;
-    }
-
     if (peer_id_len == 0) {
         return PSA_ERROR_INVALID_ARGUMENT;
     }
@@ -7370,10 +7356,6 @@
         return PSA_ERROR_BAD_STATE;
     }
 
-    if (operation->alg == PSA_ALG_NONE) {
-        return PSA_ERROR_BAD_STATE;
-    }
-
     if (role != PSA_PAKE_ROLE_NONE &&
         role != PSA_PAKE_ROLE_FIRST &&
         role != PSA_PAKE_ROLE_SECOND &&
@@ -7887,7 +7869,7 @@
     }
 
     operation->alg = PSA_ALG_NONE;
-    operation->stage = PSA_PAKE_OPERATION_STAGE_COLLECT_INPUTS;
+    operation->stage = PSA_PAKE_OPERATION_STAGE_SETUP;
     operation->id = 0;
 
     return PSA_SUCCESS;