1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3 * Copyright (c) 2014, STMicroelectronics International N.V.
4 * All rights reserved.
5 */
6
7 #include <tee_ta_api.h>
8 #include <user_ta_header_defines.h>
9 #include <ta_rpc.h>
10
11 /*
12 * Trusted Application Entry Points
13 */
14
15 /* Called each time a new instance is created */
TA_CreateEntryPoint(void)16 TEE_Result TA_CreateEntryPoint(void)
17 {
18 return TEE_SUCCESS;
19 }
20
21 /* Called each time an instance is destroyed */
TA_DestroyEntryPoint(void)22 void TA_DestroyEntryPoint(void)
23 {
24 }
25
26 /* Called each time a session is opened */
TA_OpenSessionEntryPoint(uint32_t nParamTypes,TEE_Param pParams[4],void ** ppSessionContext)27 TEE_Result TA_OpenSessionEntryPoint(uint32_t nParamTypes, TEE_Param pParams[4],
28 void **ppSessionContext)
29 {
30 (void)nParamTypes;
31 (void)pParams;
32 (void)ppSessionContext;
33 return TEE_SUCCESS;
34 }
35
36 /* Called each time a session is closed */
TA_CloseSessionEntryPoint(void * pSessionContext)37 void TA_CloseSessionEntryPoint(void *pSessionContext)
38 {
39 (void)pSessionContext;
40 }
41
42 /* Called when a command is invoked */
TA_InvokeCommandEntryPoint(void * pSessionContext,uint32_t nCommandID,uint32_t nParamTypes,TEE_Param pParams[4])43 TEE_Result TA_InvokeCommandEntryPoint(void *pSessionContext,
44 uint32_t nCommandID, uint32_t nParamTypes,
45 TEE_Param pParams[4])
46 {
47 (void)pSessionContext;
48
49 switch (nCommandID) {
50 case TA_RPC_CMD_CRYPT_SHA224:
51 return rpc_sha224(false, nParamTypes, pParams);
52
53 case TA_RPC_CMD_CRYPT_SHA256:
54 return rpc_sha256(false, nParamTypes, pParams);
55
56 case TA_RPC_CMD_CRYPT_AES256ECB_ENC:
57 return rpc_aes256ecb_encrypt(false, nParamTypes, pParams);
58
59 case TA_RPC_CMD_CRYPT_AES256ECB_DEC:
60 return rpc_aes256ecb_decrypt(false, nParamTypes, pParams);
61
62 case TA_RPC_CMD_OPEN:
63 return rpc_open(pSessionContext, nParamTypes, pParams);
64
65 case TA_RPC_CMD_CRYPT_PRIVMEM_SHA224:
66 return rpc_sha224(true, nParamTypes, pParams);
67
68 case TA_RPC_CMD_CRYPT_PRIVMEM_SHA256:
69 return rpc_sha256(true, nParamTypes, pParams);
70
71 case TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_ENC:
72 return rpc_aes256ecb_encrypt(true, nParamTypes, pParams);
73
74 case TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_DEC:
75 return rpc_aes256ecb_decrypt(true, nParamTypes, pParams);
76
77 default:
78 return TEE_ERROR_BAD_PARAMETERS;
79 }
80 }
81