-
Notifications
You must be signed in to change notification settings - Fork 163
acipher: add dynamic algorithm selection and decryption support #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,24 +16,29 @@ | |||||||||||
| /* For the UUID (found in the TA's h-file(s)) */ | ||||||||||||
| #include <acipher_ta.h> | ||||||||||||
|
|
||||||||||||
| #define ENCRYPT 1 | ||||||||||||
| #define DECRYPT 0 | ||||||||||||
|
|
||||||||||||
| static void usage(int argc, char *argv[]) | ||||||||||||
| { | ||||||||||||
| const char *pname = "acipher"; | ||||||||||||
|
|
||||||||||||
| if (argc) | ||||||||||||
| pname = argv[0]; | ||||||||||||
|
|
||||||||||||
| fprintf(stderr, "usage: %s <key_size> <string to encrypt>\n", pname); | ||||||||||||
| fprintf(stderr, "%s: %s <key_size> <string to encrypt> <algo name>\n", | ||||||||||||
Akshay-Belsare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
| __func__, pname); | ||||||||||||
| exit(1); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| static void get_args(int argc, char *argv[], size_t *key_size, void **inbuf, | ||||||||||||
| size_t *inbuf_len) | ||||||||||||
| size_t *inbuf_len, uint32_t *algo_num) | ||||||||||||
| { | ||||||||||||
| char *ep; | ||||||||||||
| long ks; | ||||||||||||
| char *algo; | ||||||||||||
|
|
||||||||||||
| if (argc != 3) { | ||||||||||||
| 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 (expected 2)", | |
| argc - 1); | |
| if ((argc > 4) || (argc < 3)) { | |
| warnx("Unexpected number of arguments %d", argc - 1); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency:
| printf("%s algo is invalid\n", algo); | |
| fprintf(stderr, "%s algo is invalid\n", algo); |
There was a problem hiding this comment.
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.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DECRYPT
There was a problem hiding this comment.
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.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DECRYPT
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -32,7 +32,8 @@ static TEE_Result cmd_gen_key(struct acipher *state, uint32_t pt, | |||||
|
|
||||||
| res = TEE_AllocateTransientObject(key_type, key_size, &key); | ||||||
| if (res) { | ||||||
| EMSG("TEE_AllocateTransientObject(%#" PRIx32 ", %" PRId32 "): %#" PRIx32, key_type, key_size, res); | ||||||
| EMSG("TEE_AllocateTransientObject(%#" PRIx32 ", %" PRId32 "): %#" | ||||||
| PRIx32, key_type, key_size, res); | ||||||
| return res; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -49,6 +50,33 @@ static TEE_Result cmd_gen_key(struct acipher *state, uint32_t pt, | |||||
| return TEE_SUCCESS; | ||||||
| } | ||||||
|
|
||||||
| static TEE_Result select_algo(uint32_t param, uint32_t *algo) | ||||||
| { | ||||||
| switch (param) { | ||||||
| case TA_ALG_PKCS1_V1_5: | ||||||
| *algo = TEE_ALG_RSAES_PKCS1_V1_5; | ||||||
| return TEE_SUCCESS; | ||||||
| case TA_ALG_OAEP_MGF1_SHA1: | ||||||
| *algo = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1; | ||||||
| return TEE_SUCCESS; | ||||||
| case TA_ALG_OAEP_MGF1_SHA224: | ||||||
| *algo = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA224; | ||||||
| return TEE_SUCCESS; | ||||||
| case TA_ALG_OAEP_MGF1_SHA256: | ||||||
| *algo = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA256; | ||||||
| return TEE_SUCCESS; | ||||||
| case TA_ALG_OAEP_MGF1_SHA384: | ||||||
| *algo = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA384; | ||||||
| return TEE_SUCCESS; | ||||||
| case TA_ALG_OAEP_MGF1_SHA512: | ||||||
| *algo = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA512; | ||||||
| return TEE_SUCCESS; | ||||||
| default: | ||||||
| EMSG("Invalid algo %u", param); | ||||||
|
||||||
| EMSG("Invalid algo %u", param); | |
| EMSG("Invalid algo %"PRIu32, param); |
Outdated
There was a problem hiding this comment.
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.
Outdated
There was a problem hiding this comment.
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,4 +22,12 @@ | |
| */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to add the algo: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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_ACIPHER_CMD_ENCRYPT 1 | ||
|
|
||
| #define TA_ALG_PKCS1_V1_5 0 | ||
| #define TA_ALG_OAEP_MGF1_SHA1 1 | ||
| #define TA_ALG_OAEP_MGF1_SHA224 2 | ||
| #define TA_ALG_OAEP_MGF1_SHA256 3 | ||
| #define TA_ALG_OAEP_MGF1_SHA384 4 | ||
| #define TA_ALG_OAEP_MGF1_SHA512 5 | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
|
||
| #endif /* __ACIPHER_TA_H */ | ||
Uh oh!
There was an error while loading. Please reload this page.