Skip to content

Commit 175cf48

Browse files
amey-raghatateAkshay-Belsare
authored andcommitted
[REVIEW] remove crypto prefix update TA and host as per review
Remove the prefix TA_ALGO_* and instead use the actual name. Below are the changes: <algo_name>: algorithm name. Supported values are: HMAC_SHA1 HMAC_SHA224 HMAC_SHA256 HMAC_SHA384 HMAC_SHA512 AES_CMAC SHA1 SHA224 SHA256 SHA384 SHA512 SHA3_224 SHA3_256 SHA3_384 SHA3_512 SHAKE128 SHAKE256 Signed-off-by: Amey Avinash Raghatate <[email protected]>
1 parent 62ec712 commit 175cf48

File tree

3 files changed

+46
-53
lines changed

3 files changed

+46
-53
lines changed

sha/host/main.c

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct test_ctx {
2525
uint32_t algo_num;
2626
};
2727

28-
void prepare_tee_session(struct test_ctx *ctx)
28+
static void prepare_tee_session(struct test_ctx *ctx)
2929
{
3030
TEEC_UUID uuid = TA_SHA_UUID;
3131
uint32_t origin;
@@ -44,7 +44,7 @@ void prepare_tee_session(struct test_ctx *ctx)
4444
res, origin);
4545
}
4646

47-
void terminate_tee_session(struct test_ctx *ctx)
47+
static void terminate_tee_session(struct test_ctx *ctx)
4848
{
4949
TEEC_CloseSession(&ctx->sess);
5050
TEEC_FinalizeContext(&ctx->ctx);
@@ -57,30 +57,18 @@ static void usage(int argc, char *argv[])
5757
if (argc)
5858
pname = argv[0];
5959

60-
fprintf(stderr, "%s: %s <string to encrypt> <algo name>\n",
60+
fprintf(stderr, "%s: %s <string to process> <algo name>\n",
6161
__func__, pname);
6262
fprintf(stderr, "<algo_name>: algorithm name. Supported values are:\n");
63-
fprintf(stderr, "TA_ALGO_HMAC_SHA1\n");
64-
fprintf(stderr, "TA_ALGO_HMAC_SHA224\n");
65-
fprintf(stderr, "TA_ALGO_HMAC_SHA256\n");
66-
fprintf(stderr, "TA_ALGO_HMAC_SHA384\n");
67-
fprintf(stderr, "TA_ALGO_HMAC_SHA512\n");
68-
fprintf(stderr, "TA_ALG_AES_CMAC\n");
69-
fprintf(stderr, "TA_ALG_SHA1\n");
70-
fprintf(stderr, "TA_ALG_SHA224\n");
71-
fprintf(stderr, "TA_ALG_SHA256\n");
72-
fprintf(stderr, "TA_ALG_SHA384\n");
73-
fprintf(stderr, "TA_ALG_SHA512\n");
74-
fprintf(stderr, "TA_ALG_SHA3_224\n");
75-
fprintf(stderr, "TA_ALG_SHA3_256\n");
76-
fprintf(stderr, "TA_ALG_SHA3_384\n");
77-
fprintf(stderr, "TA_ALG_SHA3_512\n");
78-
fprintf(stderr, "TA_ALG_SHAKE128\n");
79-
fprintf(stderr, "TA_ALG_SHAKE256\n");
63+
fprintf(stderr, "HMAC_SHA1, HMAC_SHA224, HMAC_SHA256, HMAC_SHA384, HMAC_SHA512\n");
64+
fprintf(stderr, "AES_CMAC\n");
65+
fprintf(stderr, "SHA1, SHA224, SHA256, SHA384, SHA512\n");
66+
fprintf(stderr, "SHA3_224, SHA3_256, SHA3_384, SHA3_512\n");
67+
fprintf(stderr, "SHAKE128, SHAKE256\n");
8068
exit(1);
8169
}
8270

83-
void compute_digest(struct test_ctx *ctx, void *message, size_t msg_len,
71+
static void compute_digest(struct test_ctx *ctx, void *message, size_t msg_len,
8472
void *digest, size_t *digest_len)
8573
{
8674
TEEC_Operation op = {0};
@@ -109,7 +97,7 @@ void compute_digest(struct test_ctx *ctx, void *message, size_t msg_len,
10997
}
11098
}
11199

112-
void prepare_hmac_sha(struct test_ctx *ctx, size_t key_size,
100+
static void prepare_hmac_sha(struct test_ctx *ctx, size_t key_size,
113101
enum ta_sha_object_type obj_type)
114102
{
115103
TEEC_Operation op = {0};
@@ -132,7 +120,7 @@ void prepare_hmac_sha(struct test_ctx *ctx, size_t key_size,
132120
res, origin);
133121
}
134122

135-
void set_key(struct test_ctx *ctx, char *key, size_t key_sz)
123+
static void set_key(struct test_ctx *ctx, char *key, size_t key_sz)
136124
{
137125
TEEC_Operation op = {0};
138126
uint32_t origin = 0;
@@ -151,7 +139,7 @@ void set_key(struct test_ctx *ctx, char *key, size_t key_sz)
151139
res, origin);
152140
}
153141

154-
void set_iv(struct test_ctx *ctx, char *iv, size_t iv_sz)
142+
static void set_iv(struct test_ctx *ctx, char *iv, size_t iv_sz)
155143
{
156144
TEEC_Operation op = {0};
157145
uint32_t origin = 0;
@@ -169,7 +157,7 @@ void set_iv(struct test_ctx *ctx, char *iv, size_t iv_sz)
169157
res, origin);
170158
}
171159

172-
void sha_update_ops(struct test_ctx *ctx, void *message, size_t message_sz,
160+
static void sha_update_ops(struct test_ctx *ctx, void *message, size_t message_sz,
173161
void *hmac_buff, size_t *hmac_sz)
174162
{
175163
TEEC_Operation op = {0};
@@ -196,8 +184,9 @@ void sha_update_ops(struct test_ctx *ctx, void *message, size_t message_sz,
196184
}
197185
}
198186

199-
TEEC_Result compare_hmac_sha(struct test_ctx *ctx, void *message, size_t message_sz,
200-
void *hmac_buff, size_t *hmac_sz)
187+
static TEEC_Result compare_hmac_sha(struct test_ctx *ctx, void *message,
188+
size_t message_sz, void *hmac_buff,
189+
size_t *hmac_sz)
201190
{
202191
TEEC_Operation op = {0};
203192
uint32_t origin = 0;
@@ -240,75 +229,75 @@ int main(int argc, char *argv[])
240229
if (argc > 2) {
241230
algo = argv[2];
242231
printf("%s algo selected\n", algo);
243-
if (strcmp(algo, "TA_ALGO_HMAC_SHA256") == 0) {
232+
if (strcmp(algo, "HMAC_SHA256") == 0) {
244233
ctx.algo_num = TEE_ALG_HMAC_SHA256;
245234
obj_type = TA_SHA_OBJ_TYPE_HMAC_SHA256;
246235
key_size = 128; /* 128 bytes */
247236
algo_type = SHA_HMAC;
248-
} else if (strcmp(algo, "TA_ALGO_HMAC_SHA1") == 0) {
237+
} else if (strcmp(algo, "HMAC_SHA1") == 0) {
249238
ctx.algo_num = TEE_ALG_HMAC_SHA1;
250239
obj_type = TA_SHA_OBJ_TYPE_HMAC_SHA1;
251240
key_size = 64; /* 64 bytes */
252241
algo_type = SHA_HMAC;
253-
} else if (strcmp(algo, "TA_ALGO_HMAC_SHA224") == 0) {
242+
} else if (strcmp(algo, "HMAC_SHA224") == 0) {
254243
ctx.algo_num = TEE_ALG_HMAC_SHA224;
255244
obj_type = TA_SHA_OBJ_TYPE_HMAC_SHA224;
256245
key_size = 64; /* 64 bytes */
257246
algo_type = SHA_HMAC;
258-
} else if (strcmp(algo, "TA_ALGO_HMAC_SHA384") == 0) {
247+
} else if (strcmp(algo, "HMAC_SHA384") == 0) {
259248
ctx.algo_num = TEE_ALG_HMAC_SHA384;
260249
obj_type = TA_SHA_OBJ_TYPE_HMAC_SHA384;
261250
key_size = 128; /* 128 bytes */
262251
algo_type = SHA_HMAC;
263-
} else if (strcmp(algo, "TA_ALGO_HMAC_SHA512") == 0) {
252+
} else if (strcmp(algo, "HMAC_SHA512") == 0) {
264253
ctx.algo_num = TEE_ALG_HMAC_SHA512;
265254
obj_type = TA_SHA_OBJ_TYPE_HMAC_SHA512;
266255
key_size = 128; /* 128 bytes */
267256
algo_type = SHA_HMAC;
268-
} else if (strcmp(algo, "TA_ALG_AES_CMAC") == 0) {
257+
} else if (strcmp(algo, "AES_CMAC") == 0) {
269258
ctx.algo_num = TEE_ALG_AES_CMAC;
270259
obj_type = TA_SHA_OBJ_TYPE_AES;
271260
key_size = 16; /* 16 bytes */
272261
algo_type = SHA_HMAC;
273-
} else if (strcmp(algo, "TA_ALG_SHA1") == 0) {
262+
} else if (strcmp(algo, "SHA1") == 0) {
274263
ctx.algo_num = TEE_ALG_SHA1;
275264
algo_type = BASE_SHA;
276-
} else if (strcmp(algo, "TA_ALG_SHA224") == 0) {
265+
} else if (strcmp(algo, "SHA224") == 0) {
277266
ctx.algo_num = TEE_ALG_SHA224;
278267
algo_type = BASE_SHA;
279-
} else if (strcmp(algo, "TA_ALG_SHA256") == 0) {
268+
} else if (strcmp(algo, "SHA256") == 0) {
280269
ctx.algo_num = TEE_ALG_SHA256;
281270
algo_type = BASE_SHA;
282-
} else if (strcmp(algo, "TA_ALG_SHA384") == 0) {
271+
} else if (strcmp(algo, "SHA384") == 0) {
283272
ctx.algo_num = TEE_ALG_SHA384;
284273
algo_type = BASE_SHA;
285-
} else if (strcmp(algo, "TA_ALG_SHA512") == 0) {
274+
} else if (strcmp(algo, "SHA512") == 0) {
286275
ctx.algo_num = TEE_ALG_SHA512;
287276
algo_type = BASE_SHA;
288-
} else if (strcmp(algo, "TA_ALG_SHA3_224") == 0) {
277+
} else if (strcmp(algo, "SHA3_224") == 0) {
289278
ctx.algo_num = TEE_ALG_SHA3_224;
290279
algo_type = BASE_SHA;
291-
} else if (strcmp(algo, "TA_ALG_SHA3_256") == 0) {
280+
} else if (strcmp(algo, "SHA3_256") == 0) {
292281
ctx.algo_num = TEE_ALG_SHA3_256;
293282
algo_type = BASE_SHA;
294-
} else if (strcmp(algo, "TA_ALG_SHA3_384") == 0) {
283+
} else if (strcmp(algo, "SHA3_384") == 0) {
295284
ctx.algo_num = TEE_ALG_SHA3_384;
296285
algo_type = BASE_SHA;
297-
} else if (strcmp(algo, "TA_ALG_SHA3_512") == 0) {
286+
} else if (strcmp(algo, "SHA3_512") == 0) {
298287
ctx.algo_num = TEE_ALG_SHA3_512;
299288
algo_type = BASE_SHA;
300-
} else if (strcmp(algo, "TA_ALG_SHAKE128") == 0) {
289+
} else if (strcmp(algo, "SHAKE128") == 0) {
301290
ctx.algo_num = TEE_ALG_SHAKE128;
302291
algo_type = BASE_SHA;
303-
} else if (strcmp(algo, "TA_ALG_SHAKE256") == 0) {
292+
} else if (strcmp(algo, "SHAKE256") == 0) {
304293
ctx.algo_num = TEE_ALG_SHAKE256;
305294
algo_type = BASE_SHA;
306295
} else {
307296
printf("%s algo is invalid\n", algo);
308297
usage(argc, argv);
309298
}
310299
} else {
311-
printf("TA_ALGO_HMAC_SHA256 algo selected\n");
300+
printf("HMAC_SHA256 algo selected\n");
312301
ctx.algo_num = TEE_ALG_HMAC_SHA256;
313302
key_size = 128; /* 128 bytes */
314303
obj_type = TA_SHA_OBJ_TYPE_HMAC_SHA256;

sha/ta/include/sha_ta.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
{ 0x95, 0x19, 0xea, 0x8a, 0x6c, 0x8c, 0x16, 0xe5 } }
1313

1414
/*
15-
* TA_SHA_CMD_PREPARE - Allocate resources for the SHA operation
16-
* param[0] (value) a: TA_ALGO_HMAC_xxx, b: unused
15+
* TA_SHA_CMD_PREPARE - Allocate resources for the MAC operation
16+
* param[0] (value) a: TEE ID of the algo to use (TEE_ALG_xxx), b: unused
1717
* param[1] (value) a: key size in bytes, b: unused
1818
* param[2] (value) a: obj_type, b: unused
1919
* param[3] unused
@@ -51,7 +51,7 @@ enum ta_sha_object_type {
5151
};
5252

5353
/*
54-
* TA_SHA_CMD_SET_KEY - Allocate resources for the SHA operation
54+
* TA_SHA_CMD_SET_KEY - Allocate resources for the MAC operation
5555
* param[0] (memref) key data, size shall equal key length
5656
* param[1] unused
5757
* param[2] unused
@@ -69,7 +69,7 @@ enum ta_sha_object_type {
6969
#define TA_SHA_CMD_SET_IV 2
7070

7171
/*
72-
* TA_CMD_SHA_INIT - sha_update_ops
72+
* TA_SHA_CMD_INIT - Process MAC operation
7373
* param[0] (memref) message, message size
7474
* param[1] (memref) MAC buffer, buffer size
7575
* param[2] unused
@@ -78,7 +78,7 @@ enum ta_sha_object_type {
7878
#define TA_SHA_CMD_INIT 3
7979

8080
/*
81-
* TA_CMD_SHA_CMPR - compare MAC
81+
* TA_SHA_CMD_COMPARE_MAC - compare MAC values
8282
* param[0] (memref) message, message size
8383
* param[1] (memref) MAC buffer, buffer size
8484
* param[2] unused
@@ -87,7 +87,7 @@ enum ta_sha_object_type {
8787
#define TA_SHA_CMD_COMPARE_MAC 4
8888

8989
/*
90-
* CMD_COMPUTE_DIGEST - Computing the digest
90+
* TA_SHA_CMD_COMPUTE_DIGEST - Computing the digest
9191
* param[0] (memref) message, message size
9292
* param[1] (memref) digest buffer, buffer size
9393
* param[2] (value) a:TA_ALG_SHA*, b: unused

sha/ta/sha_ta.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ static TEE_Result alloc_resources(void *session, uint32_t param_types,
133133
sess->mode = TEE_MODE_MAC;
134134

135135
/* Free potential previous operation */
136-
if (sess->op_handle != TEE_HANDLE_NULL)
136+
if (sess->op_handle != TEE_HANDLE_NULL) {
137137
TEE_FreeOperation(sess->op_handle);
138+
sess->op_handle = TEE_HANDLE_NULL;
139+
}
138140

139141
/* Allocate operation: SHA, mode and size from params */
140142
res = TEE_AllocateOperation(&sess->op_handle,
@@ -147,8 +149,10 @@ static TEE_Result alloc_resources(void *session, uint32_t param_types,
147149
}
148150

149151
/* Free potential previous transient object */
150-
if (sess->key_handle != TEE_HANDLE_NULL)
152+
if (sess->key_handle != TEE_HANDLE_NULL) {
151153
TEE_FreeTransientObject(sess->key_handle);
154+
sess->key_handle = TEE_HANDLE_NULL;
155+
}
152156

153157
/* Allocate transient object according to target key size */
154158
res = TEE_AllocateTransientObject(tee_obj_type,

0 commit comments

Comments
 (0)