1 /* 2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HKS_KEYNODE_H 17 #define HKS_KEYNODE_H 18 19 #include <stdint.h> 20 21 #include "hks_double_list.h" 22 #include "hks_type.h" 23 #include "hks_mutex.h" 24 25 #define HKS_OPERATION_PARAM_CNT 3 26 #define HKS_UINT64_MAX 0xFFFFFFFFFFFFFFFF 27 #define HKS_KEYNODE_HANDLE_INVALID_VALUE 0 28 #define HKS_KEYNODE_HANDLE_INITIAL_VALUE 1 29 30 struct HuksKeyNode { 31 struct DoubleList listHead; 32 struct HksParamSet *keyBlobParamSet; 33 34 /** 35 * @brief used to cache params of caller and state or temp prop in memory during using key 36 * CURRENT state: 37 * uint64_t crypto_ctx; // crypto engine context 38 */ 39 struct HksParamSet *runtimeParamSet; // only used to store caller's paramset 40 41 /** 42 * @brief used to cache params of caller and state or temp prop in memory during using key 43 * CURRENT state: 44 * bool isSecureAccess; // is set secure access 45 * bool isSupportSecureSign; // is set secure sign tag 46 * bool isAppendUpdateData; // is append update data for auth info 47 * uint8 challenge[TOKEN_SIZE];// key challenge(token) 48 * uint32_t accessTime; // key init access timestamp in second 49 * int32_t keyAuthResult; // key auth result cache 50 */ 51 struct HksParamSet *authRuntimeParamSet; 52 uint64_t handle; 53 uint64_t batchOperationTimestamp; 54 bool isBatchOperation; 55 }; 56 57 #ifdef __cplusplus 58 extern "C" { 59 #endif 60 61 HksMutex *HksGetHuksMutex(void); 62 63 int32_t HksInitHuksMutex(void); 64 65 void HksDestroyHuksMutex(void); 66 67 struct HuksKeyNode *HksCreateBatchKeyNode(const struct HuksKeyNode *keyNode, const struct HksParamSet *paramSet); 68 69 struct HuksKeyNode *HksCreateKeyNode(const struct HksBlob *key, const struct HksParamSet *paramSet); 70 71 struct HuksKeyNode *HksQueryKeyNode(uint64_t handle); 72 73 void HksDeleteKeyNode(uint64_t handle); 74 75 void HksFreeUpdateKeyNode(struct HuksKeyNode *keyNode); 76 77 #ifdef __cplusplus 78 } 79 #endif 80 81 #endif