Hello~
I am developing nrf52840 with zephyr ncs tool chain v2.7.0 and SDK v2.6.1.
Our project needs RSA to exchange secure data.
I use example "samples/crypto/rsa", modified it, tring to encrypt message. be failed.
I add this function to the example :
int rsa_encrypt_msg(const uint8_t * planttext,size_t plantlen, uint8_t * encrypttext,size_t * encryptlen)
{
psa_status_t status = psa_asymmetric_encrypt(pub_key_handle, PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256), \
planttext, plantlen, NULL, 0, encrypttext, 1024, encryptlen);
if (status != PSA_SUCCESS)
{
printk("encrypt_msg failed! (Error: %d )\n", status);
switch(status)
{
case PSA_ERROR_INVALID_HANDLE: LOG_INF("PSA_ERROR_INVALID_HANDLE"); break;
case PSA_ERROR_NOT_PERMITTED: LOG_INF("PSA_ERROR_NOT_PERMITTED"); break;
case PSA_ERROR_BUFFER_TOO_SMALL: LOG_INF("PSA_ERROR_BUFFER_TOO_SMALL"); break;
case PSA_ERROR_NOT_SUPPORTED: LOG_INF("PSA_ERROR_NOT_SUPPORTED"); break;
case PSA_ERROR_INVALID_ARGUMENT: LOG_INF("PSA_ERROR_INVALID_ARGUMENT"); break;
case PSA_ERROR_INSUFFICIENT_MEMORY: LOG_INF("PSA_ERROR_INSUFFICIENT_MEMORY"); break;
case PSA_ERROR_COMMUNICATION_FAILURE: LOG_INF("PSA_ERROR_COMMUNICATION_FAILURE"); break;
case PSA_ERROR_HARDWARE_FAILURE: LOG_INF("PSA_ERROR_HARDWARE_FAILURE"); break;
case PSA_ERROR_CORRUPTION_DETECTED: LOG_INF("PSA_ERROR_CORRUPTION_DETECTED"); break;
case PSA_ERROR_STORAGE_FAILURE: LOG_INF("PSA_ERROR_STORAGE_FAILURE"); break;
case PSA_ERROR_INSUFFICIENT_ENTROPY: LOG_INF("PSA_ERROR_INSUFFICIENT_ENTROPY"); break;
case PSA_ERROR_BAD_STATE: LOG_INF("PSA_ERROR_BAD_STATE"); break;
}
return APP_ERROR;
}
printk("Encrypttext");
return status;
}
and then call this function in main(), just after
uint8_t buffer_in[10] = {1,2,3,4,5,6,7,8,9,0}; uint8_t bufferOut[1024] = {0}; int outputlen = 0; rsa_encrypt_msg(buffer_in,sizeof(buffer_in), bufferOut,&outputlen);
But I always get error:
encrypt_msg failed! (Error: -134 )
[00:00:00.314,178] <inf> rsa: PSA_ERROR_NOT_SUPPORTED
Would you please show me the correct way to use psa_asymmetric_encrypt / psa_asymmetric_decrypt ?