Saving ECC keys to persistent memory with psa_crypto (or alternative method)

Hi to all!

I am trying to use the nrf5340 as a MCU for a IoT project. I need to create a ECC key using secp256r1 and save it in the nrf5340 for later use.

I am using the psa_crypto and giving it the attribute PSA_KEY_LIFETIME_PERSISTENT for it to be usable after a reboot. However trying to access the key with psa_export_public_key using the ID after a reboot, it fails saying PSA_ERROR_INVALID_HANDLE while it doesn't fail if I do it without rebooting. I am not calling psa_destroy_key so it should still be there.

My questions are:

Is this the way of safely storing an ECC key for later use in the nrf5340?

Why is it failing to export the public key after reboot? psa_export_public_key states that the EXPORT attribute is not necessary for public keys.

Thanks in advance!!

Related