Adapt conditional compilation flags for jpake alg

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemek Stekiel 2023-02-20 13:32:22 +01:00
parent a54dc69fe0
commit 80a8849903
3 changed files with 175 additions and 117 deletions

View file

@ -7256,6 +7256,7 @@ psa_status_t psa_pake_setup(
operation->alg = cipher_suite->algorithm; operation->alg = cipher_suite->algorithm;
operation->data.inputs.cipher_suite = *cipher_suite; operation->data.inputs.cipher_suite = *cipher_suite;
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
if (operation->alg == PSA_ALG_JPAKE) { if (operation->alg == PSA_ALG_JPAKE) {
psa_jpake_computation_stage_t *computation_stage = psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.jpake; &operation->computation_stage.jpake;
@ -7264,6 +7265,12 @@ psa_status_t psa_pake_setup(
computation_stage->sequence = PSA_PAKE_SEQ_INVALID; computation_stage->sequence = PSA_PAKE_SEQ_INVALID;
computation_stage->input_step = PSA_PAKE_STEP_X1_X2; computation_stage->input_step = PSA_PAKE_STEP_X1_X2;
computation_stage->output_step = PSA_PAKE_STEP_X1_X2; computation_stage->output_step = PSA_PAKE_STEP_X1_X2;
} else
#else
#endif
{
status = PSA_ERROR_NOT_SUPPORTED;
goto exit;
} }
operation->stage = PSA_PAKE_OPERATION_STAGE_COLLECT_INPUTS; operation->stage = PSA_PAKE_OPERATION_STAGE_COLLECT_INPUTS;
@ -7407,6 +7414,7 @@ exit:
} }
/* Auxiliary function to convert core computation stage(step, sequence, state) to single driver step. */ /* Auxiliary function to convert core computation stage(step, sequence, state) to single driver step. */
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
static psa_crypto_driver_pake_step_t convert_jpake_computation_stage_to_driver_step( static psa_crypto_driver_pake_step_t convert_jpake_computation_stage_to_driver_step(
psa_jpake_computation_stage_t *stage) psa_jpake_computation_stage_t *stage)
{ {
@ -7469,6 +7477,7 @@ static psa_crypto_driver_pake_step_t convert_jpake_computation_stage_to_driver_s
} }
return PSA_JPAKE_STEP_INVALID; return PSA_JPAKE_STEP_INVALID;
} }
#endif
static psa_status_t psa_pake_complete_inputs( static psa_status_t psa_pake_complete_inputs(
psa_pake_operation_t *operation) psa_pake_operation_t *operation)
@ -7501,6 +7510,7 @@ static psa_status_t psa_pake_complete_inputs(
mbedtls_free(inputs.password); mbedtls_free(inputs.password);
if (status == PSA_SUCCESS) { if (status == PSA_SUCCESS) {
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
if (operation->alg == PSA_ALG_JPAKE) { if (operation->alg == PSA_ALG_JPAKE) {
psa_jpake_computation_stage_t *computation_stage = psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.jpake; &operation->computation_stage.jpake;
@ -7508,15 +7518,27 @@ static psa_status_t psa_pake_complete_inputs(
computation_stage->sequence = PSA_PAKE_SEQ_INVALID; computation_stage->sequence = PSA_PAKE_SEQ_INVALID;
computation_stage->input_step = PSA_PAKE_STEP_X1_X2; computation_stage->input_step = PSA_PAKE_STEP_X1_X2;
computation_stage->output_step = PSA_PAKE_STEP_X1_X2; computation_stage->output_step = PSA_PAKE_STEP_X1_X2;
} else
#endif
{
status = PSA_ERROR_NOT_SUPPORTED;
} }
} }
return status; return status;
} }
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
static psa_status_t psa_jpake_output_prologue( static psa_status_t psa_jpake_output_prologue(
psa_pake_operation_t *operation, psa_pake_operation_t *operation,
psa_pake_step_t step) psa_pake_step_t step)
{ {
if (step != PSA_PAKE_STEP_KEY_SHARE &&
step != PSA_PAKE_STEP_ZK_PUBLIC &&
step != PSA_PAKE_STEP_ZK_PROOF) {
return PSA_ERROR_INVALID_ARGUMENT;
}
if (operation->alg == PSA_ALG_JPAKE) {
psa_jpake_computation_stage_t *computation_stage = psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.jpake; &operation->computation_stage.jpake;
@ -7524,12 +7546,6 @@ static psa_status_t psa_jpake_output_prologue(
return PSA_ERROR_BAD_STATE; return PSA_ERROR_BAD_STATE;
} }
if (step != PSA_PAKE_STEP_KEY_SHARE &&
step != PSA_PAKE_STEP_ZK_PUBLIC &&
step != PSA_PAKE_STEP_ZK_PROOF) {
return PSA_ERROR_INVALID_ARGUMENT;
}
if (computation_stage->state != PSA_PAKE_STATE_READY && if (computation_stage->state != PSA_PAKE_STATE_READY &&
computation_stage->state != PSA_PAKE_OUTPUT_X1_X2 && computation_stage->state != PSA_PAKE_OUTPUT_X1_X2 &&
computation_stage->state != PSA_PAKE_OUTPUT_X2S) { computation_stage->state != PSA_PAKE_OUTPUT_X2S) {
@ -7581,13 +7597,17 @@ static psa_status_t psa_jpake_output_prologue(
default: default:
return PSA_ERROR_BAD_STATE; return PSA_ERROR_BAD_STATE;
} }
}
return PSA_SUCCESS; return PSA_SUCCESS;
} }
#endif
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
static psa_status_t psa_jpake_output_epilogue( static psa_status_t psa_jpake_output_epilogue(
psa_pake_operation_t *operation) psa_pake_operation_t *operation)
{ {
if (operation->alg == PSA_ALG_JPAKE) {
psa_jpake_computation_stage_t *computation_stage = psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.jpake; &operation->computation_stage.jpake;
@ -7601,9 +7621,11 @@ static psa_status_t psa_jpake_output_epilogue(
} else { } else {
computation_stage->sequence++; computation_stage->sequence++;
} }
}
return PSA_SUCCESS; return PSA_SUCCESS;
} }
#endif
psa_status_t psa_pake_output( psa_status_t psa_pake_output(
psa_pake_operation_t *operation, psa_pake_operation_t *operation,
@ -7634,35 +7656,45 @@ psa_status_t psa_pake_output(
} }
switch (operation->alg) { switch (operation->alg) {
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
case PSA_ALG_JPAKE: case PSA_ALG_JPAKE:
status = psa_jpake_output_prologue(operation, step); status = psa_jpake_output_prologue(operation, step);
if (status != PSA_SUCCESS) { if (status != PSA_SUCCESS) {
goto exit; goto exit;
} }
break; break;
#endif
default: default:
(void) step;
status = PSA_ERROR_NOT_SUPPORTED; status = PSA_ERROR_NOT_SUPPORTED;
goto exit; goto exit;
} }
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
status = psa_driver_wrapper_pake_output(operation, status = psa_driver_wrapper_pake_output(operation,
convert_jpake_computation_stage_to_driver_step( convert_jpake_computation_stage_to_driver_step(
&operation->computation_stage.jpake), &operation->computation_stage.jpake),
output, output,
output_size, output_size,
output_length); output_length);
#else
(void) output;
status = PSA_ERROR_NOT_SUPPORTED;
#endif
if (status != PSA_SUCCESS) { if (status != PSA_SUCCESS) {
goto exit; goto exit;
} }
switch (operation->alg) { switch (operation->alg) {
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
case PSA_ALG_JPAKE: case PSA_ALG_JPAKE:
status = psa_jpake_output_epilogue(operation); status = psa_jpake_output_epilogue(operation);
if (status != PSA_SUCCESS) { if (status != PSA_SUCCESS) {
goto exit; goto exit;
} }
break; break;
#endif
default: default:
status = PSA_ERROR_NOT_SUPPORTED; status = PSA_ERROR_NOT_SUPPORTED;
goto exit; goto exit;
@ -7674,11 +7706,19 @@ exit:
return status == PSA_SUCCESS ? abort_status : status; return status == PSA_SUCCESS ? abort_status : status;
} }
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
static psa_status_t psa_jpake_input_prologue( static psa_status_t psa_jpake_input_prologue(
psa_pake_operation_t *operation, psa_pake_operation_t *operation,
psa_pake_step_t step, psa_pake_step_t step,
size_t input_length) size_t input_length)
{ {
if (step != PSA_PAKE_STEP_KEY_SHARE &&
step != PSA_PAKE_STEP_ZK_PUBLIC &&
step != PSA_PAKE_STEP_ZK_PROOF) {
return PSA_ERROR_INVALID_ARGUMENT;
}
if (operation->alg == PSA_ALG_JPAKE) {
psa_jpake_computation_stage_t *computation_stage = psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.jpake; &operation->computation_stage.jpake;
@ -7686,12 +7726,6 @@ static psa_status_t psa_jpake_input_prologue(
return PSA_ERROR_BAD_STATE; return PSA_ERROR_BAD_STATE;
} }
if (step != PSA_PAKE_STEP_KEY_SHARE &&
step != PSA_PAKE_STEP_ZK_PUBLIC &&
step != PSA_PAKE_STEP_ZK_PROOF) {
return PSA_ERROR_INVALID_ARGUMENT;
}
const psa_pake_primitive_t prim = PSA_PAKE_PRIMITIVE( const psa_pake_primitive_t prim = PSA_PAKE_PRIMITIVE(
PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, 256); PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, 256);
if (input_length > (size_t) PSA_PAKE_INPUT_SIZE(PSA_ALG_JPAKE, prim, step)) { if (input_length > (size_t) PSA_PAKE_INPUT_SIZE(PSA_ALG_JPAKE, prim, step)) {
@ -7749,13 +7783,17 @@ static psa_status_t psa_jpake_input_prologue(
default: default:
return PSA_ERROR_BAD_STATE; return PSA_ERROR_BAD_STATE;
} }
}
return PSA_SUCCESS; return PSA_SUCCESS;
} }
#endif
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
static psa_status_t psa_jpake_input_epilogue( static psa_status_t psa_jpake_input_epilogue(
psa_pake_operation_t *operation) psa_pake_operation_t *operation)
{ {
if (operation->alg == PSA_ALG_JPAKE) {
psa_jpake_computation_stage_t *computation_stage = psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.jpake; &operation->computation_stage.jpake;
@ -7769,9 +7807,11 @@ static psa_status_t psa_jpake_input_epilogue(
} else { } else {
computation_stage->sequence++; computation_stage->sequence++;
} }
}
return PSA_SUCCESS; return PSA_SUCCESS;
} }
#endif
psa_status_t psa_pake_input( psa_status_t psa_pake_input(
psa_pake_operation_t *operation, psa_pake_operation_t *operation,
@ -7800,33 +7840,43 @@ psa_status_t psa_pake_input(
} }
switch (operation->alg) { switch (operation->alg) {
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
case PSA_ALG_JPAKE: case PSA_ALG_JPAKE:
status = psa_jpake_input_prologue(operation, step, input_length); status = psa_jpake_input_prologue(operation, step, input_length);
if (status != PSA_SUCCESS) { if (status != PSA_SUCCESS) {
goto exit; goto exit;
} }
break; break;
#endif
default: default:
(void) step;
return PSA_ERROR_NOT_SUPPORTED; return PSA_ERROR_NOT_SUPPORTED;
} }
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
status = psa_driver_wrapper_pake_input(operation, status = psa_driver_wrapper_pake_input(operation,
convert_jpake_computation_stage_to_driver_step( convert_jpake_computation_stage_to_driver_step(
&operation->computation_stage.jpake), &operation->computation_stage.jpake),
input, input,
input_length); input_length);
#else
(void) input;
status = PSA_ERROR_NOT_SUPPORTED;
#endif
if (status != PSA_SUCCESS) { if (status != PSA_SUCCESS) {
goto exit; goto exit;
} }
switch (operation->alg) { switch (operation->alg) {
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
case PSA_ALG_JPAKE: case PSA_ALG_JPAKE:
status = psa_jpake_input_epilogue(operation); status = psa_jpake_input_epilogue(operation);
if (status != PSA_SUCCESS) { if (status != PSA_SUCCESS) {
goto exit; goto exit;
} }
break; break;
#endif
default: default:
status = PSA_ERROR_NOT_SUPPORTED; status = PSA_ERROR_NOT_SUPPORTED;
goto exit; goto exit;
@ -7852,6 +7902,7 @@ psa_status_t psa_pake_get_implicit_key(
goto exit; goto exit;
} }
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
if (operation->alg == PSA_ALG_JPAKE) { if (operation->alg == PSA_ALG_JPAKE) {
psa_jpake_computation_stage_t *computation_stage = psa_jpake_computation_stage_t *computation_stage =
&operation->computation_stage.jpake; &operation->computation_stage.jpake;
@ -7860,6 +7911,13 @@ psa_status_t psa_pake_get_implicit_key(
status = PSA_ERROR_BAD_STATE; status = PSA_ERROR_BAD_STATE;
goto exit; goto exit;
} }
} else
#else
#endif
{
status = PSA_ERROR_NOT_SUPPORTED;
goto exit;
} }
status = psa_driver_wrapper_pake_get_implicit_key(operation, status = psa_driver_wrapper_pake_get_implicit_key(operation,

View file

@ -2976,7 +2976,7 @@ exit:
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_PSA_BUILTIN_ALG_JPAKE */
void pake_operations(data_t *pw_data, int forced_status_setup_arg, int forced_status_arg, void pake_operations(data_t *pw_data, int forced_status_setup_arg, int forced_status_arg,
data_t *forced_output, int expected_status_setup_arg, data_t *forced_output, int expected_status_setup_arg,
int expected_status_input_arg, int expected_status_output_arg, int expected_status_input_arg, int expected_status_output_arg,

View file

@ -909,7 +909,7 @@ void ecjpake_size_macros()
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_PSA_BUILTIN_ALG_JPAKE */
void pake_input_getters(data_t *password, int role_arg, int password_buffer_size, void pake_input_getters(data_t *password, int role_arg, int password_buffer_size,
int alg_arg, int primitive_arg, int hash_arg, int alg_arg, int primitive_arg, int hash_arg,
int expected_status_pass, int expected_status_pass_len, int expected_status_pass, int expected_status_pass_len,