Importing ECC private key from PEM to PSA and error using mbedTLS helper functions

Hi,

I have an ECC private key (in PEM) that is parsed by mbedtls_pk_parse_key(). Now, I want to import this private key into PSA (using psa_import_key()). 
I have followed the recommendations here https://github.com/Mbed-TLS/mbedtls/blob/development/docs/psa-transition.md, see section - "Importing a PK key by export-import for an ECC private key".I have written a conversion routine as suggested here i.e. as below:

unsigned char buf[PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)];
size_t length = PSA_BITS_TO_BYTES(mbedtls_pk_bitlen(&pk));
mbedtls_ecp_keypair *ec = mbedtls_pk_ec(&pk);
psa_ecc_curve_t curve;
{
    mbedtls_ecp_group grp;
    mbedtls_ecp_group_init(&grp);
    mbedtls_ecp_point Q;
    mbedtls_ecp_point_init(&Q);
    mbedtls_mpi d;
    mbedtls_mpi_init(&d);
    mbedtls_ecp_export(ec, &grp, &d, &Q);
    size_t bits;
    curve = mbedtls_ecc_group_to_psa(grp.id, &bits);
    mbedtls_ecp_group_free(&grp);
    mbedtls_ecp_point_free(&Q);
    mbedtls_mpi_free(&d);
}
mbedtls_ecp_write_key(ec, buf, length);

But when building, i get an error "undefined reference to `mbedtls_ecp_export'".
I tried configuing 
CONFIG_MBEDTLS_ECP_C=y and  CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y and CONFIG_MBEDTLS_ECP_ALL_ENABLED=y. But, i still get this error when building.
I can see that the function is defined in ecp.c in the nrf SDK.

Is there any particular kconfig option in the nrf SDK that is controlling the compiling of this function mbedtls_ecp_export()?
If not, is there an alternative way to import this ECC private key(returned by into PSA (for ECDSA NIST-P256-SECP-R1)?

Thanks,

Mathi.
#PSA #mbedTLS #ECC #PrivateKey#Import#PEM#Crypto#ECDSA#NISTP256#PSATRANSITION

Related