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_hal.h" 13 #include <tee_log.h> 14 #include <tee_defines.h> 15 #include <crypto_hal.h> 16 #include <tee_object_api.h> 17 #include <crypto_inner_defines.h> 18 #include "tee_crypto_api.h" 19 TEE_SetCryptoFlag(TEE_OperationHandle operation,uint32_t crypto)20TEE_Result TEE_SetCryptoFlag(TEE_OperationHandle operation, uint32_t crypto) 21 { 22 if (operation == NULL) { 23 tloge("operation is null\n"); 24 return TEE_ERROR_BAD_PARAMETERS; 25 } 26 crypto_hal_info *crypto_hal_data = (crypto_hal_info *)(operation->hal_info); 27 if (crypto_hal_data == NULL) { 28 tloge("Crypto hal info is null\n"); 29 return TEE_ERROR_BAD_PARAMETERS; 30 } 31 32 bool check = 33 (((operation->operationClass == TEE_OPERATION_DIGEST) && (crypto_hal_data->digestalloc_flag == 1)) || 34 ((operation->operationClass != TEE_OPERATION_DIGEST) && 35 ((operation->handleState & TEE_HANDLE_FLAG_INITIALIZED) || 36 (operation->handleState & TEE_HANDLE_FLAG_KEY_SET)))); 37 if (check) { 38 tloge("operation state is invalid\n"); 39 return TEE_ERROR_BAD_PARAMETERS; 40 } 41 42 crypto_hal_data->crypto_flag = crypto; 43 return TEE_SUCCESS; 44 } TEE_SetObjectFlag(TEE_ObjectHandle object,uint32_t crypto)45TEE_Result TEE_SetObjectFlag(TEE_ObjectHandle object, uint32_t crypto) 46 { 47 if (object == NULL) { 48 tloge("object is null\n"); 49 return TEE_ERROR_BAD_PARAMETERS; 50 } 51 if (crypto >= CRYPTO_ENGINE_MAX) { 52 tloge("flag is invalid!\n"); 53 return TEE_ERROR_BAD_PARAMETERS; 54 } 55 object->generate_flag = crypto; 56 return TEE_SUCCESS; 57 } 58 TEE_IsHardWareSupportAlgorithm(uint32_t alg_type)59TEE_Result TEE_IsHardWareSupportAlgorithm(uint32_t alg_type) 60 { 61 TEE_Result ret; 62 63 ret = (TEE_Result)tee_crypto_check_alg_support(alg_type); 64 if (ret == 0) 65 return TEE_SUCCESS; 66 67 return TEE_ERROR_NOT_SUPPORTED; 68 } 69