mbedtls_psa_pake_get_implicit_key: move psa_key_derivation_input_bytes call to upper layer
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index 8dc1a21..4e0f5f5 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -7295,11 +7295,34 @@
psa_pake_operation_t *operation,
psa_key_derivation_operation_t *output)
{
+ psa_status_t status = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+ uint8_t shared_key[MBEDTLS_PSA_PAKE_BUFFER_SIZE];
+ size_t shared_key_len = 0;
+
if (operation->id == 0) {
return PSA_ERROR_BAD_STATE;
}
- return psa_driver_wrapper_pake_get_implicit_key(operation, output);
+ status = psa_driver_wrapper_pake_get_implicit_key(operation,
+ shared_key,
+ &shared_key_len);
+
+ if (status != PSA_SUCCESS) {
+ return status;
+ }
+
+ status = psa_key_derivation_input_bytes(output,
+ PSA_KEY_DERIVATION_INPUT_SECRET,
+ shared_key,
+ shared_key_len);
+
+ if (status != PSA_SUCCESS) {
+ psa_key_derivation_abort(output);
+ }
+
+ mbedtls_platform_zeroize(shared_key, MBEDTLS_PSA_PAKE_BUFFER_SIZE);
+
+ return status;
}
psa_status_t psa_pake_abort(
diff --git a/library/psa_crypto_driver_wrappers.h b/library/psa_crypto_driver_wrappers.h
index a3755d3..78f2f9a 100644
--- a/library/psa_crypto_driver_wrappers.h
+++ b/library/psa_crypto_driver_wrappers.h
@@ -454,7 +454,7 @@
psa_status_t psa_driver_wrapper_pake_get_implicit_key(
psa_pake_operation_t *operation,
- psa_key_derivation_operation_t *output);
+ uint8_t *output, size_t *output_size);
psa_status_t psa_driver_wrapper_pake_abort(
psa_pake_operation_t *operation);
diff --git a/library/psa_crypto_pake.c b/library/psa_crypto_pake.c
index 6c4db6f..1e5dca4 100644
--- a/library/psa_crypto_pake.c
+++ b/library/psa_crypto_pake.c
@@ -835,7 +835,7 @@
psa_status_t mbedtls_psa_pake_get_implicit_key(
mbedtls_psa_pake_operation_t *operation,
- psa_key_derivation_operation_t *output)
+ uint8_t *output, size_t *output_size)
{
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
@@ -863,16 +863,14 @@
return mbedtls_ecjpake_to_psa_error(ret);
}
- status = psa_key_derivation_input_bytes(output,
- PSA_KEY_DERIVATION_INPUT_SECRET,
- operation->buffer,
- operation->buffer_length);
+ memcpy(output, operation->buffer, operation->buffer_length);
+ *output_size = operation->buffer_length;
mbedtls_platform_zeroize(operation->buffer, MBEDTLS_PSA_PAKE_BUFFER_SIZE);
mbedtls_psa_pake_abort(operation);
- return status;
+ return PSA_SUCCESS;
} else
#else
(void) output;
@@ -880,7 +878,6 @@
{ status = PSA_ERROR_NOT_SUPPORTED; }
error:
- psa_key_derivation_abort(output);
mbedtls_psa_pake_abort(operation);
return status;
diff --git a/library/psa_crypto_pake.h b/library/psa_crypto_pake.h
index c7bf270..9256f5a 100644
--- a/library/psa_crypto_pake.h
+++ b/library/psa_crypto_pake.h
@@ -442,7 +442,7 @@
*/
psa_status_t mbedtls_psa_pake_get_implicit_key(
mbedtls_psa_pake_operation_t *operation,
- psa_key_derivation_operation_t *output);
+ uint8_t *output, size_t *output_size);
/** Abort a PAKE operation.
*