Etienne Carriere | 7514117 | 2020-05-16 11:58:23 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-2-Clause |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014, STMicroelectronics International N.V. |
| 4 | * All rights reserved. |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 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 */ |
| 16 | TEE_Result TA_CreateEntryPoint(void) |
| 17 | { |
| 18 | return TEE_SUCCESS; |
| 19 | } |
| 20 | |
| 21 | /* Called each time an instance is destroyed */ |
| 22 | void TA_DestroyEntryPoint(void) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | /* Called each time a session is opened */ |
| 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 */ |
| 37 | void TA_CloseSessionEntryPoint(void *pSessionContext) |
| 38 | { |
| 39 | (void)pSessionContext; |
| 40 | } |
| 41 | |
| 42 | /* Called when a command is invoked */ |
| 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: |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 51 | return rpc_sha224(false, nParamTypes, pParams); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 52 | |
| 53 | case TA_RPC_CMD_CRYPT_SHA256: |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 54 | return rpc_sha256(false, nParamTypes, pParams); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 55 | |
| 56 | case TA_RPC_CMD_CRYPT_AES256ECB_ENC: |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 57 | return rpc_aes256ecb_encrypt(false, nParamTypes, pParams); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 58 | |
| 59 | case TA_RPC_CMD_CRYPT_AES256ECB_DEC: |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 60 | return rpc_aes256ecb_decrypt(false, nParamTypes, pParams); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 61 | |
| 62 | case TA_RPC_CMD_OPEN: |
| 63 | return rpc_open(pSessionContext, nParamTypes, pParams); |
| 64 | |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 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 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 77 | default: |
| 78 | return TEE_ERROR_BAD_PARAMETERS; |
| 79 | } |
| 80 | } |