1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-05 19:35:48 +03:00

Optimize psa_pake_ecjpake_setup()

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemek Stekiel
2023-02-14 20:05:43 +01:00
parent 849c35f8b4
commit 4fcc61eec0

View File

@@ -167,19 +167,10 @@ static psa_status_t mbedtls_ecjpake_to_psa_error(int ret)
static psa_status_t psa_pake_ecjpake_setup(mbedtls_psa_pake_operation_t *operation) static psa_status_t psa_pake_ecjpake_setup(mbedtls_psa_pake_operation_t *operation)
{ {
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
mbedtls_ecjpake_role role; mbedtls_ecjpake_role role = (operation->role == PSA_PAKE_ROLE_CLIENT) ?
MBEDTLS_ECJPAKE_CLIENT : MBEDTLS_ECJPAKE_SERVER;
if (operation->role == PSA_PAKE_ROLE_CLIENT) { mbedtls_ecjpake_init(&operation->ctx.pake);
role = MBEDTLS_ECJPAKE_CLIENT;
} else if (operation->role == PSA_PAKE_ROLE_SERVER) {
role = MBEDTLS_ECJPAKE_SERVER;
} else {
return PSA_ERROR_BAD_STATE;
}
if (operation->password_len == 0) {
return PSA_ERROR_BAD_STATE;
}
ret = mbedtls_ecjpake_setup(&operation->ctx.pake, ret = mbedtls_ecjpake_setup(&operation->ctx.pake,
role, role,
@@ -189,9 +180,6 @@ static psa_status_t psa_pake_ecjpake_setup(mbedtls_psa_pake_operation_t *operati
operation->password_len); operation->password_len);
mbedtls_platform_zeroize(operation->password, operation->password_len); mbedtls_platform_zeroize(operation->password, operation->password_len);
mbedtls_free(operation->password);
operation->password = NULL;
operation->password_len = 0;
if (ret != 0) { if (ret != 0) {
return mbedtls_ecjpake_to_psa_error(ret); return mbedtls_ecjpake_to_psa_error(ret);
@@ -238,7 +226,7 @@ psa_status_t mbedtls_psa_pake_setup(mbedtls_psa_pake_operation_t *operation,
return PSA_ERROR_NOT_SUPPORTED; return PSA_ERROR_NOT_SUPPORTED;
} }
mbedtls_ecjpake_init(&operation->ctx.pake);
operation->password = mbedtls_calloc(1, password_len); operation->password = mbedtls_calloc(1, password_len);
if (operation->password == NULL) { if (operation->password == NULL) {