Dear support,
I currently develop a Trusted Application on Trusty which implements RSA encryption and RSA decrypt. While RSA encryption works well, RSA decryption is not performed properly (please see details below).
My development platform is Jetson Xavier AGX, under JetPack 4.1. And I use openssl library for RSA encryption/decryption.
A key pair is stored in that TA:
static char publicKey4096[] =
"-----BEGIN PUBLIC KEY-----\n"
"MIICIjAN...
"-----END PUBLIC KEY-----";
static char privateKey4096[] =
"-----BEGIN RSA PRIVATE KEY-----\n"
""MIIJKAIBAAKCA...
"-----END RSA PRIVATE KEY-----\n";
For RSA encryption/decryption, I use openssl library as follows:
Encryption code snippet
// Generate RSA struct
RSA *rsa = createRSA(publicKey4096, 1);
// Encrypt
int size_enc = RSA_public_encrypt(sizeof(data), data, result, rsa, padding);
Decryption code snippet
// Generate RSA struct
RSA *rsa = createRSA(privateKey4096, 0);
// Decrypt
int size_dec = RSA_private_decrypt(payload_len, data, result, rsa, padding);
Prior to encryption/decryption, random number is initialised as follows:
// Init randomseed
RAND_seed(rnd_seed, sizeof rnd_seed);
RSA Encryption
As said, RSA Encryption works well. As shown below, input data is sent to the TA, encrypted on TA, and sent back to CA.
Call to RSA_public_encrypt returns the error code 0000000, which stands for success.
The returned buffer is stored in a encryptedfile
I check the encrypted outcome with Openssl, using the same public key, as follows:
RSA Encryption on TA is validated.
RSA Decryption
RSA Decryption on TA returns an erroneous data. As shown below, encrypted data is sent to the TA, decrypted on TA, and sent back to CA.
Call to RSA_private_decrypt returns the error code 0000000, which stands for success.
But while looking at the returned decrypted outcome, RSA decryption is not done properly. The previously encrypted data is not decrypted.
Would you have any advice/suggestion to have RSA decryption working?
If needed, I can provide the TA source, and RSA keys, in PM.
Thank you in advance for your help.
Best,
Lgiori.