Hello,
I need to implement the code that calculates the ECDSA signature, using the mbedtls library.
Development environment:
- nRF53DK
- nRF Connect SDK 2.3.0
Currently, the process is implemented as follows:
- The private key is generated using openssl, and stored to flash memory in DER format.
- The signature is calculated by loading the mentioned key in mbedtls_pk_context using mbedtls_pk_parse_key, and passing such context to the mbedtls_ecdsa_write_signature function.
As a next step, it is necessary to implement key generation within the firmware and use it for signature so that the code itself does not need access to the key content.
I was able to generate the key using psa_generate_key.
The plan is to load the generated key to the corresponding mbedtls_pk_context using mbedtls_pk_setup_opaque as a next step.
This should be the only change from the current state (after configuring the mbedtls_pk_context, mbedtls_ecdsa_write_signature is called as before).
However, the problem is that, despite researching similar forum posts, and corresponding mbedtls configuration requests, I am still not able to use the mbedtls_pk_setup_opaque function because it looks like MBEDTLS_USE_PSA_CRYPTO is not defined.
The following security modules are included in the prj file (here there are certainly those that are not needed for the mentioned ECDSA signing, but remained in the project for the needs of tests of various mbedtls functionalities):
CONFIG_NRF_SECURITY=y CONFIG_MBEDTLS_LIBRARY_NRF_SECURITY=y CONFIG_MBEDTLS_USE_PSA_CRYPTO=y CONFIG_MBEDTLS_PSA_CRYPTO_C=y CONFIG_MBEDTLS_PSA_CRYPTO_STORAGE_C=y CONFIG_MBEDTLS_PK_C=y CONFIG_MBEDTLS_RSA_C=y CONFIG_MBEDTLS_PKCS1_V15=y CONFIG_MBEDTLS_SHA256_C=y CONFIG_MBEDTLS_ECP_C=y CONFIG_MBEDTLS_ECDSA_C=y CONFIG_MBEDTLS_ECDH_C=y CONFIG_MBEDTLS_CTR_DRBG_C=y CONFIG_MBEDTLS_ENTROPY_C=y CONFIG_MBEDTLS_PK_PARSE_C=y CONFIG_MBEDTLS_TLS_LIBRARY=y CONFIG_MBEDTLS_X509_LIBRARY=y CONFIG_MBEDTLS_PK_WRITE_C=y CONFIG_MBEDTLS_X509_CREATE_C=y CONFIG_MBEDTLS_X509_CSR_WRITE_C=y CONFIG_MBEDTLS_LEGACY_CRYPTO_C=y CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=n
Do you have any idea what could be the cause of this behavior?
Is this a regular approach for implementing not exposing secret key material to the users of mbedtls API?
Thanks.