Optimize out psa_pake_computation_stage_t

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemek Stekiel 2023-01-26 08:46:37 +01:00
parent 27cd488088
commit dde6a910bb
3 changed files with 23 additions and 33 deletions

View File

@ -1292,9 +1292,6 @@ typedef struct psa_pake_operation_s psa_pake_operation_t;
/** The type of input values for PAKE operations. */
typedef struct psa_crypto_driver_pake_inputs_s psa_crypto_driver_pake_inputs_t;
/** The type of computation stage for PAKE operations. */
typedef struct psa_pake_computation_stage_s psa_pake_computation_stage_t;
/** The type of computation stage for J-PAKE operations. */
typedef struct psa_jpake_computation_stage_s psa_jpake_computation_stage_t;
@ -1897,7 +1894,7 @@ psa_status_t psa_pake_abort(psa_pake_operation_t *operation);
* psa_pake_operation_t.
*/
#define PSA_PAKE_OPERATION_INIT { 0, PSA_ALG_NONE, PSA_PAKE_OPERATION_STAGE_COLLECT_INPUTS, \
{ { { 0 } } }, { { 0 } } }
{ { 0 } }, { { 0 } } }
struct psa_pake_cipher_suite_s {
psa_algorithm_t algorithm;
@ -2028,12 +2025,6 @@ struct psa_jpake_computation_stage_s {
unsigned int MBEDTLS_PRIVATE(output_step);
};
struct psa_pake_computation_stage_s {
union {
psa_jpake_computation_stage_t MBEDTLS_PRIVATE(jpake);
} MBEDTLS_PRIVATE(data);
};
struct psa_pake_operation_s {
/** Unique ID indicating which driver got assigned to do the
* operation. Since driver contexts are driver-specific, swapping
@ -2049,7 +2040,9 @@ struct psa_pake_operation_s {
are copied to the corresponding operation context. */
uint8_t MBEDTLS_PRIVATE(stage);
/* Holds computation stage of the PAKE algorithms. */
psa_pake_computation_stage_t MBEDTLS_PRIVATE(computation_stage);
union {
psa_jpake_computation_stage_t MBEDTLS_PRIVATE(jpake);
} MBEDTLS_PRIVATE(computation_stage);
union {
psa_crypto_driver_pake_inputs_t MBEDTLS_PRIVATE(inputs);
psa_driver_pake_context_t MBEDTLS_PRIVATE(ctx);

View File

@ -7260,7 +7260,7 @@ psa_status_t psa_pake_setup(
if (operation->alg == PSA_ALG_JPAKE) {
psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.data.jpake;
&operation->computation_stage.jpake;
computation_stage->state = PSA_PAKE_STATE_SETUP;
computation_stage->sequence = PSA_PAKE_SEQ_INVALID;
@ -7391,12 +7391,12 @@ psa_status_t psa_pake_set_role(
/* Auxiliary function to convert core computation stage(step, sequence, state) to single driver step. */
static psa_pake_driver_step_t convert_jpake_computation_stage_to_driver_step(
psa_pake_computation_stage_t *stage)
psa_jpake_computation_stage_t *stage)
{
switch (stage->data.jpake.state) {
switch (stage->state) {
case PSA_PAKE_OUTPUT_X1_X2:
case PSA_PAKE_INPUT_X1_X2:
switch (stage->data.jpake.sequence) {
switch (stage->sequence) {
case PSA_PAKE_X1_STEP_KEY_SHARE:
return PSA_JPAKE_X1_STEP_KEY_SHARE;
break;
@ -7420,7 +7420,7 @@ static psa_pake_driver_step_t convert_jpake_computation_stage_to_driver_step(
}
break;
case PSA_PAKE_OUTPUT_X2S:
switch (stage->data.jpake.sequence) {
switch (stage->sequence) {
case PSA_PAKE_X1_STEP_KEY_SHARE:
return PSA_JPAKE_X2S_STEP_KEY_SHARE;
break;
@ -7434,7 +7434,7 @@ static psa_pake_driver_step_t convert_jpake_computation_stage_to_driver_step(
}
break;
case PSA_PAKE_INPUT_X4S:
switch (stage->data.jpake.sequence) {
switch (stage->sequence) {
case PSA_PAKE_X1_STEP_KEY_SHARE:
return PSA_JPAKE_X4S_STEP_KEY_SHARE;
break;
@ -7457,7 +7457,7 @@ static psa_status_t psa_pake_complete_inputs(
psa_pake_operation_t *operation)
{
psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.data.jpake;
&operation->computation_stage.jpake;
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
uint8_t *password = operation->data.inputs.password;
size_t password_len = operation->data.inputs.password_len;
@ -7501,7 +7501,7 @@ static psa_status_t psa_jpake_output_prologue(
psa_pake_step_t step)
{
psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.data.jpake;
&operation->computation_stage.jpake;
if (computation_stage->state == PSA_PAKE_STATE_INVALID) {
return PSA_ERROR_BAD_STATE;
@ -7572,7 +7572,7 @@ static psa_status_t psa_jpake_output_epilogue(
psa_pake_operation_t *operation)
{
psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.data.jpake;
&operation->computation_stage.jpake;
if ((computation_stage->state == PSA_PAKE_OUTPUT_X1_X2 &&
computation_stage->sequence == PSA_PAKE_X2_STEP_ZK_PROOF) ||
@ -7628,10 +7628,8 @@ psa_status_t psa_pake_output(
}
status = psa_driver_wrapper_pake_output(operation,
convert_jpake_computation_stage_to_driver_step(&
operation
->
computation_stage),
convert_jpake_computation_stage_to_driver_step(
&operation->computation_stage.jpake),
output,
output_size,
output_length);
@ -7660,7 +7658,7 @@ static psa_status_t psa_jpake_input_prologue(
size_t input_length)
{
psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.data.jpake;
&operation->computation_stage.jpake;
if (computation_stage->state == PSA_PAKE_STATE_INVALID) {
return PSA_ERROR_BAD_STATE;
@ -7737,7 +7735,7 @@ static psa_status_t psa_jpake_input_epilogue(
psa_pake_operation_t *operation)
{
psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.data.jpake;
&operation->computation_stage.jpake;
if ((computation_stage->state == PSA_PAKE_INPUT_X1_X2 &&
computation_stage->sequence == PSA_PAKE_X2_STEP_ZK_PROOF) ||
@ -7792,9 +7790,8 @@ psa_status_t psa_pake_input(
}
status = psa_driver_wrapper_pake_input(operation,
convert_jpake_computation_stage_to_driver_step(&operation
->
computation_stage),
convert_jpake_computation_stage_to_driver_step(
&operation->computation_stage.jpake),
input,
input_length);
@ -7824,7 +7821,7 @@ psa_status_t psa_pake_get_implicit_key(
uint8_t shared_key[MBEDTLS_PSA_PAKE_BUFFER_SIZE];
size_t shared_key_len = 0;
psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.data.jpake;
&operation->computation_stage.jpake;
if (operation->id == 0) {
return PSA_ERROR_BAD_STATE;
@ -7883,7 +7880,7 @@ psa_status_t psa_pake_abort(
if (operation->alg == PSA_ALG_JPAKE) {
psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.data.jpake;
&operation->computation_stage.jpake;
computation_stage->input_step = PSA_PAKE_STEP_INVALID;
computation_stage->output_step = PSA_PAKE_STEP_INVALID;

View File

@ -3119,8 +3119,8 @@ void pake_operations(data_t *pw_data, int forced_status_setup_arg, int forced_st
PSA_SUCCESS);
/* Simulate that we are ready to get implicit key. */
operation.computation_stage.data.jpake.input_step = PSA_PAKE_STEP_DERIVE;
operation.computation_stage.data.jpake.output_step = PSA_PAKE_STEP_DERIVE;
operation.computation_stage.jpake.input_step = PSA_PAKE_STEP_DERIVE;
operation.computation_stage.jpake.output_step = PSA_PAKE_STEP_DERIVE;
/* --- psa_pake_get_implicit_key --- */
mbedtls_test_driver_pake_hooks.forced_status = forced_status;