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 "sha2_taf.h" |
| 8 | #include "sha2_impl.h" |
| 9 | |
| 10 | TEE_Result ta_entry_sha224(uint32_t param_types, TEE_Param params[4]) |
| 11 | { |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 12 | /* |
| 13 | * It is expected that memRef[0] is input buffer and memRef[1] is |
| 14 | * output buffer. |
| 15 | */ |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 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 | |
| 33 | TEE_Result ta_entry_sha256(uint32_t param_types, TEE_Param params[4]) |
| 34 | { |
Etienne Carriere | 102092e | 2019-03-28 15:24:22 +0100 | [diff] [blame] | 35 | /* |
| 36 | * It is expected that memRef[0] is input buffer and memRef[1] is |
| 37 | * output buffer. |
| 38 | */ |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 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 | } |