-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PK: don't use mbedtls_ecp_check_pub_priv() when USE_PSA is enabled #7391
Conversation
Instead of using the legacy mbedtls_ecp_check_pub_priv() function which was based on ECP math, we add a new option named eckey_check_pair_psa() which takes advantage of PSA. Of course, this is available when MBEDTLS_USE_PSA_CRYPTO in enabled. Tests were also fixed accordingly. Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there was a misunderstanding about the scope of the task, and changes should be limited to PK. A few other points, and also the CI is unhappy.
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left only few minor suggestions. Otherwise looks good.
library/pk_wrap.c
Outdated
if (status != PSA_SUCCESS) { | ||
ret = PSA_PK_TO_MBEDTLS_ERR(status); | ||
status = psa_destroy_key(key_id); | ||
return (status != PSA_SUCCESS) ? PSA_PK_TO_MBEDTLS_ERR(status) : ret; | ||
} | ||
|
||
status = psa_destroy_key(key_id); | ||
if (status != PSA_SUCCESS) { | ||
return PSA_PK_TO_MBEDTLS_ERR(status); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call to psa_destroy_key(key_id)
is duplicated. Key is destroyed regardless of status of psa_export_public_key
. Seems that this can be optimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Key is destroyed regardless of status of psa_export_public_key
But if psa_export_public_key()
fails then we need to destroy the key that was imported few lines above before returning from this function. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for the possible optimization I thought something like this:
ret = PSA_PK_TO_MBEDTLS_ERR(psa_export_public_key(key_id,
prv_key_buf,
sizeof(prv_key_buf),
&prv_key_len));
status = psa_destroy_key(key_id);
if (ret != 0 || status != PSA_SUCCESS) {
return (ret != 0) ? ret : PSA_PK_TO_MBEDTLS_ERR(status);
}
Is that what you were looking for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done ;)
library/pk_wrap.c
Outdated
size_t pub_key_len; | ||
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT; | ||
size_t curve_bits; | ||
psa_ecc_family_t curve = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
psa_ecc_family_t curve = | |
const psa_ecc_family_t curve = |
library/pk_wrap.c
Outdated
size_t curve_bits; | ||
psa_ecc_family_t curve = | ||
mbedtls_ecc_group_to_psa(prv_ctx->grp.id, &curve_bits); | ||
size_t curve_bytes = PSA_BITS_TO_BYTES(curve_bits); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size_t curve_bytes = PSA_BITS_TO_BYTES(curve_bits); | |
const size_t curve_bytes = PSA_BITS_TO_BYTES(curve_bits); |
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing my comments! LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Instead of using the legacy mbedtls_ecp_check_pub_priv() function which was based on ECP math, we add a new option named eckey_check_pair_psa() which takes advantage of PSA.
Resolves #7387
Gatekeeper checklist