Skip to content

Conversation

@Akshay-Belsare
Copy link

  • Extend acipher example to support for RSA algorithms:
    • TEE_ALG_RSAES_PKCS1_V1_5
    • TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1/224/256/384/512
  • Users can select algorithm and key size at runtime via: optee_example_acipher <key_size> <string> <algo>
  • Supported key sizes: 2048, 3072, 4096 bits
  • Defaults to TA_ALG_PKCS1_V1_5 if no algorithm is specified
  • Enhances the acipher example for flexible testing of multiple RSA modes

- Extend acipher example to support for RSA algorithms:
  - TEE_ALG_RSAES_PKCS1_V1_5
  - TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1/224/256/384/512
- Users can select algorithm and key size at runtime via:
  `optee_example_acipher <key_size> <string> <algo>`
- Supported key sizes: 2048, 3072, 4096 bits
- Defaults to TA_ALG_PKCS1_V1_5 if no algorithm is specified
- Enhances the acipher example for flexible testing of multiple RSA
modes

Signed-off-by: Amey Avinash Raghatate <ameyavinash.raghatate@amd.com>
Signed-off-by: Amey Avinash Raghatate <ameyavinash.raghatate@amd.com>
Akshay-Belsare pushed a commit to Xilinx/optee_examples that referenced this pull request Sep 29, 2025
- Extend acipher example to support for RSA algorithms:
  - TEE_ALG_RSAES_PKCS1_V1_5
  - TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1/224/256/384/512
- Users can select algorithm and key size at runtime via:
  `optee_example_acipher <key_size> <string> <algo>`
- Supported key sizes: 2048, 3072, 4096 bits
- Defaults to TA_ALG_PKCS1_V1_5 if no algorithm is specified
- Enhances the acipher example for flexible testing of multiple RSA
modes

Signed-off-by: Amey Avinash Raghatate <ameyavinash.raghatate@amd.com>
State: waiting
Link: linaro-swg#133
@github-actions
Copy link

This pull request has been marked as a stale pull request because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment, otherwise this pull request will automatically be closed in 5 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label Oct 13, 2025
@Akshay-Belsare
Copy link
Author

@jforissier @etienne-lms Could you please take a moment to review this change?

@github-actions github-actions bot removed the Stale label Oct 14, 2025
TEEC_VALUE_INPUT, TEEC_VALUE_INPUT);
op.params[0].tmpref.buffer = outbuf;
op.params[0].tmpref.size = outbuf_len;
op.params[2].value.a = DECRYPT; /* decrypt */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a command called TA_ACIPHER_CMD_ENCRYPT to do decryption is inconsistent. Please introduce TA_ACIPHER_CMD_DECRYPT instead.


res = TEEC_InvokeCommand(&sess, TA_ACIPHER_CMD_ENCRYPT, &op, &eo);
if (eo != TEEC_ORIGIN_TRUSTED_APP || res != TEEC_ERROR_SHORT_BUFFER)
teec_err(res, eo, "TEEC_InvokeCommand(TA_ACIPHER_CMD_DYCRYPT)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DECRYPT

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the command is still TA_ACIPHER_CMD_ENCRYPT.
Maybe update the message here and below (line 191):

		teec_err(res, eo, "Command TA_ACIPHER_CMD_ENCRYPT failed for decryption");

and at line 159 above:

 	res = TEEC_InvokeCommand(&sess, TA_ACIPHER_CMD_ENCRYPT, &op, &eo);
 	if (res)
-		teec_err(res, eo, "TEEC_InvokeCommand(TA_ACIPHER_CMD_ENCRYPT)");
+		teec_err(res, eo, "Command TA_ACIPHER_CMD_ENCRYPT failed for encryption");

Alternatively, introduce a dedicated command for decryption: TA_ACIPHER_CMD_DECRYPT.


res = TEEC_InvokeCommand(&sess, TA_ACIPHER_CMD_ENCRYPT, &op, &eo);
if (res)
teec_err(res, eo, "TEEC_InvokeCommand(TA_ACIPHER_CMD_DYCRYPT)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DECRYPT

/*
* in params[1].memref input
* out params[2].memref output
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add the algo: in params[3].value algorithm (TA_ALG_*)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually:

/*
 * in	params[0].memref  Input data to cipher
 * out	params[1].memref  Ciphered output data
 * in   params[2].value.a  Mode: 0 for decryption, any other value for encryption
 * in   params[3].value.a  Algorithm (TA_ALG_*)
 */

printf("TA_ALG_OAEP_MGF1_SHA224\n");
printf("TA_ALG_OAEP_MGF1_SHA256\n");
printf("TA_ALG_OAEP_MGF1_SHA384\n");
printf("TA_ALG_OAEP_MGF1_SHA512\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some indentation would make this more readable.
For consistency: fprintf(stderr, ...) for each trace message?

	fprintf(stderr, "Usage: %s <key_size> <string to encrypt> [<algo name>]\n\n",
		pname);
	fprintf(stderr, "<key_size>:  key size in bits. Supported values are:\n");
	fprintf(stderr, "             2048, 3072, 4096\n");
	fprintf(stderr, "<algo_name>: algorithm name. Supported values are:\n");
	fprintf(stderr, "             TA_ALG_PKCS1_V1_5 (default)\n");
	fprintf(stderr, "             TA_ALG_OAEP_MGF1_SHA1\n");
	fprintf(stderr, "             TA_ALG_OAEP_MGF1_SHA224\n");
	fprintf(stderr, "             TA_ALG_OAEP_MGF1_SHA256\n");
	fprintf(stderr, "             TA_ALG_OAEP_MGF1_SHA384\n");
	fprintf(stderr, "             TA_ALG_OAEP_MGF1_SHA512\n");

Comment on lines 50 to 52
if ((argc > 4) || (argc < 3)) {
warnx("Unexpected number of arguments %d (expected 2)",
argc - 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ((argc > 4) || (argc < 3)) {
warnx("Unexpected number of arguments %d (expected 2)",
argc - 1);
if ((argc > 4) || (argc < 3)) {
warnx("Unexpected number of arguments %d", argc - 1);

} else if (strcmp(algo, "TA_ALG_PKCS1_V1_5") == 0) {
*algo_num = TA_ALG_PKCS1_V1_5;
} else {
printf("%s algo is invalid\n", algo);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency:

Suggested change
printf("%s algo is invalid\n", algo);
fprintf(stderr, "%s algo is invalid\n", algo);


res = TEEC_InvokeCommand(&sess, TA_ACIPHER_CMD_ENCRYPT, &op, &eo);
if (eo != TEEC_ORIGIN_TRUSTED_APP || res != TEEC_ERROR_SHORT_BUFFER)
teec_err(res, eo, "TEEC_InvokeCommand(TA_ACIPHER_CMD_DYCRYPT)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the command is still TA_ACIPHER_CMD_ENCRYPT.
Maybe update the message here and below (line 191):

		teec_err(res, eo, "Command TA_ACIPHER_CMD_ENCRYPT failed for decryption");

and at line 159 above:

 	res = TEEC_InvokeCommand(&sess, TA_ACIPHER_CMD_ENCRYPT, &op, &eo);
 	if (res)
-		teec_err(res, eo, "TEEC_InvokeCommand(TA_ACIPHER_CMD_ENCRYPT)");
+		teec_err(res, eo, "Command TA_ACIPHER_CMD_ENCRYPT failed for encryption");

Alternatively, introduce a dedicated command for decryption: TA_ACIPHER_CMD_DECRYPT.

*algo = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA512;
return TEE_SUCCESS;
default:
EMSG("Invalid algo %u", param);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EMSG("Invalid algo %u", param);
EMSG("Invalid algo %"PRIu32, param);

key_info.keySize);
if (res) {
EMSG("TEE_AllocateOperation(TEE_MODE_ENCRYPT, %#" PRIx32 ", %" PRId32 "): %#" PRIx32, alg, key_info.keySize, res);
EMSG("TEE_AllocateOperation(TEE_MODE_ENCRYPT, %#"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TEE_MODE_ENCRYPT or TEE_MODE_DECRYPT depending on encrypt.

if (res) {
EMSG("TEE_AllocateOperation(TEE_MODE_ENCRYPT, %#" PRIx32 ", %" PRId32 "): %#" PRIx32, alg, key_info.keySize, res);
EMSG("TEE_AllocateOperation(TEE_MODE_ENCRYPT, %#"
PRIx32 ", %" PRId32 "): %#" PRIx32,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The show argument do not match the order used in TEE_AllocateOperation(). Not a big issue but one may found that confusing.

/*
* in params[1].memref input
* out params[2].memref output
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually:

/*
 * in	params[0].memref  Input data to cipher
 * out	params[1].memref  Ciphered output data
 * in   params[2].value.a  Mode: 0 for decryption, any other value for encryption
 * in   params[3].value.a  Algorithm (TA_ALG_*)
 */

#define TA_ALG_OAEP_MGF1_SHA256 3
#define TA_ALG_OAEP_MGF1_SHA384 4
#define TA_ALG_OAEP_MGF1_SHA512 5

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use GP TEE Internal Core API algorithm IDs? as suggestion by @jenswi-linaro in another P-R?
Nitpicking: could you remove the extra empty line.

Update acipher TA and host as per review comments.

Signed-off-by: Amey Avinash Raghatate <ameyavinash.raghatate@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants