• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 #include "tee_crypto_api.h"
13 #include <string.h>
14 #include <tee_log.h>
15 #include <tee_property_inner.h>
16 #include <tee_object_api.h>
17 #include <crypto_inner_defines.h>
18 #include <crypto_hal_hash.h>
19 #include <crypto_driver_adaptor.h>
20 #include "tee_operation.h"
21 #include "tee_crypto_common_hash.h"
22 
23 /* For GP compatible, we add some panic when there is some error, For common use, we need to disable this panic */
24 #ifndef GP_COMPATIBLE
25 #define TEE_Panic(x) \
26     do {             \
27     } while (0)
28 #endif
29 
TEE_DigestUpdate(TEE_OperationHandle operation,const void * chunk,size_t chunkSize)30 void TEE_DigestUpdate(TEE_OperationHandle operation, const void *chunk, size_t chunkSize)
31 {
32     TEE_Result ret;
33     bool check = (operation == NULL || chunk == NULL || chunkSize == 0 ||
34         (check_operation((const TEE_OperationHandle)operation) != TEE_SUCCESS));
35     if (check) {
36         tloge("The params is invalid");
37         TEE_Panic(TEE_ERROR_BAD_PARAMETERS);
38         return;
39     }
40 
41     if (crypto_lock_operation(operation) != TEE_SUCCESS)
42         return;
43 
44     ret = digest_operation_state_check((const TEE_OperationHandle)operation);
45     if (ret != TEE_SUCCESS) {
46         crypto_unlock_operation(operation);
47         TEE_Panic(ret);
48         return;
49     }
50 
51     ret = proc_hal_digest_update(operation, chunk, chunkSize);
52     if (ret != TEE_SUCCESS) {
53         tloge("Do digest update failed, ret=0x%x\n", ret);
54         operation->handleState &= ~TEE_HANDLE_FLAG_INITIALIZED;
55         crypto_unlock_operation(operation);
56         TEE_Panic(ret);
57         return;
58     }
59     crypto_unlock_operation(operation);
60 }
61 
62