1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3 * Copyright (c) 2014, STMicroelectronics International N.V.
4 * All rights reserved.
5 */
6
7 #include "sha2_taf.h"
8 #include "sha2_impl.h"
9
ta_entry_sha224(uint32_t param_types,TEE_Param params[4])10 TEE_Result ta_entry_sha224(uint32_t param_types, TEE_Param params[4])
11 {
12 /*
13 * It is expected that memRef[0] is input buffer and memRef[1] is
14 * output buffer.
15 */
16 if (param_types !=
17 TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT,
18 TEE_PARAM_TYPE_MEMREF_OUTPUT, TEE_PARAM_TYPE_NONE,
19 TEE_PARAM_TYPE_NONE)) {
20 return TEE_ERROR_BAD_PARAMETERS;
21 }
22
23 if (params[1].memref.size < SHA224_DIGEST_SIZE)
24 return TEE_ERROR_BAD_PARAMETERS;
25
26 sha224((unsigned char *)params[0].memref.buffer,
27 (unsigned int)params[0].memref.size,
28 (unsigned char *)params[1].memref.buffer);
29
30 return TEE_SUCCESS;
31 }
32
ta_entry_sha256(uint32_t param_types,TEE_Param params[4])33 TEE_Result ta_entry_sha256(uint32_t param_types, TEE_Param params[4])
34 {
35 /*
36 * It is expected that memRef[0] is input buffer and memRef[1] is
37 * output buffer.
38 */
39 if (param_types !=
40 TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT,
41 TEE_PARAM_TYPE_MEMREF_OUTPUT, TEE_PARAM_TYPE_NONE,
42 TEE_PARAM_TYPE_NONE)) {
43 return TEE_ERROR_BAD_PARAMETERS;
44 }
45
46 if (params[1].memref.size < SHA256_DIGEST_SIZE)
47 return TEE_ERROR_BAD_PARAMETERS;
48
49 sha256((unsigned char *)params[0].memref.buffer,
50 (unsigned int)params[0].memref.size,
51 (unsigned char *)params[1].memref.buffer);
52
53 return TEE_SUCCESS;
54 }
55