Making the RSA keypair persist.

Hi,

I am using the RSA sample code and I need to make the key persist. When I try to change the lifetime attribute to PSA_KEY_LIFETIME_PERSISTENT, the key generation fails.

I am using nRF52840 dev kit.

int generate_rsa_keypair(void)
{
psa_status_t status;
size_t olen;

LOG_INF("Generating random RSA keypair...");

/* Configure the key attributes */
psa_key_attributes_t key_attributes = PSA_KEY_ATTRIBUTES_INIT;

/* Configure the key attributes */
psa_set_key_usage_flags(&key_attributes, PSA_KEY_USAGE_SIGN_HASH);
psa_set_key_lifetime(&key_attributes, PSA_KEY_LIFETIME_VOLATILE);
psa_set_key_algorithm(&key_attributes, PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256));
psa_set_key_type(&key_attributes, PSA_KEY_TYPE_RSA_KEY_PAIR);
psa_set_key_bits(&key_attributes, KEY_SIZE);

/* Generate a random keypair. The keypair is not exposed to the application,
* we can use it to signing/verification the key handle.
*/
status = psa_generate_key(&key_attributes, &keypair_handle);
if (status != PSA_SUCCESS) {
LOG_INF("psa_generate_key failed! (Error: %d)", status);
return APP_ERROR;
}

rsa: psa_generate_key failed! (Error: -134)


Any idea what else needs to be done so the key pair could persist during reboots?

Thanks!
Related