Suggested enhancement
mbedtls_psa_ecp_generate_key() calls mbedtls_ecp_gen_key() to generate an ECC key. This ends up calling mbedtls_ecp_gen_keypair_base(), which first generates the private key (which mainly consists of random number generation), but also computes the corresponding public key with mbedtls_ecp_mul() (which is computationally much more expensive).
|
int mbedtls_ecp_gen_keypair_base(mbedtls_ecp_group *grp, |
|
const mbedtls_ecp_point *G, |
|
mbedtls_mpi *d, mbedtls_ecp_point *Q, |
|
int (*f_rng)(void *, unsigned char *, size_t), |
|
void *p_rng) |
|
{ |
|
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
|
MBEDTLS_MPI_CHK(mbedtls_ecp_gen_privkey(grp, d, f_rng, p_rng)); |
|
MBEDTLS_MPI_CHK(mbedtls_ecp_mul(grp, Q, d, G, f_rng, p_rng)); |
|
|
|
cleanup: |
|
return ret; |
|
} |
In PSA, only the private key is used in the API. Thus, computing the public key could be skipped, especially considering the cost of this step.
Suggested enhancement
mbedtls_psa_ecp_generate_key()callsmbedtls_ecp_gen_key()to generate an ECC key. This ends up callingmbedtls_ecp_gen_keypair_base(), which first generates the private key (which mainly consists of random number generation), but also computes the corresponding public key withmbedtls_ecp_mul()(which is computationally much more expensive).mbedtls/tf-psa-crypto/drivers/builtin/src/ecp.c
Lines 3018 to 3030 in f8d13d8
In PSA, only the private key is used in the API. Thus, computing the public key could be skipped, especially considering the cost of this step.