• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025-2025 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_EVENT_INFO_H
17 #define HKS_EVENT_INFO_H
18 
19 #include <stdbool.h>
20 #include <stdint.h>
21 #include <time.h>
22 
23 #include "hks_type_enum.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 // modify this please sync modify g_threeStageEvent
30 enum HksEventId {
31     HKS_EVENT_CRYPTO = 1,
32     HKS_EVENT_SIGN_VERIFY = 2,
33     HKS_EVENT_DERIVE = 3,
34     HKS_EVENT_AGREE = 4,
35     HKS_EVENT_MAC = 5,
36     HKS_EVENT_ATTEST = 6,
37     HKS_EVENT_GENERATE_KEY = 7,
38     HKS_EVENT_CHECK_KEY_EXISTED = 8,
39     HKS_EVENT_DELETE_KEY = 9,
40     HKS_EVENT_IMPORT_KEY = 10,
41     HKS_EVENT_LIST_ALIASES = 11,
42     HKS_EVENT_RENAME_KEY = 12,
43     HKS_EVENT_GET_PROPERTIES = 13,
44     HKS_EVENT_KEY_LEVEL_CHANGE = 14,
45     /* closed source event start with 15, end with 19 */
46     HKS_EVENT_DATA_SIZE_STATISTICS = 30,
47 };
48 
49 // modify this please sync modify g_threeStage
50 enum HksReportStage {
51     HKS_INIT = 1,
52     HKS_UPDATE = 2,
53     HKS_FINISH = 3,
54     HKS_ABORT = 4,
55     HKS_ONE_STAGE = 5,
56     HKS_ONE_STAGE_CRYPTO = 6,
57     HKS_ONE_STAGE_SIGN_VERIFY = 7,
58     HKS_ONE_STAGE_DERIVE = 8,
59     HKS_ONE_STAGE_AGREE = 9,
60     HKS_ONE_STAGE_MAC = 10,
61     HKS_ONE_STAGE_ATTEST = 11,
62 };
63 
64 typedef struct HksEventKeyAccessInfo {
65     uint32_t authType;
66     uint32_t accessType;
67     uint32_t challengeType;
68     uint32_t challengePos;
69     uint32_t authTimeOut;
70     uint32_t authPurpose;
71     uint32_t frontUserId;
72     uint32_t authMode;
73     uint32_t needPwdSet;
74 } HksEventKeyAccessInfo;
75 
76 typedef struct HksEventKeyInfo {
77     uint32_t storageLevel;
78     int32_t specificUserId;
79     uint32_t alg;
80     uint32_t purpose;
81     uint32_t keySize;
82     uint32_t keyFlag;
83     uint16_t keyHash;
84     uint8_t aliasHash;
85     bool isBatch;
86     uint32_t batchPur;
87     uint32_t batchTimeOut;
88 } HksEventKeyInfo;
89 
90 typedef struct HksEventStatInfo {
91     uint32_t saCost;
92     uint32_t ca2taCost;
93     uint32_t taCost;
94     uint32_t gpCost;
95     uint32_t initCost;
96     uint32_t updateCost;
97     uint32_t updateCount;
98     uint32_t finishCost;
99     uint32_t totalCost;
100     uint32_t dataLen;
101 } HksEventStatInfo;
102 
103 typedef struct HksEventResultInfo {
104     int32_t code;
105     uint32_t module;
106     uint32_t stage;
107     char *errMsg;
108 } HksEventResultInfo;
109 
110 typedef struct HksEventCallerInfo {
111     uint32_t uid;
112     char *name;
113 } HksEventCallerInfo;
114 
115 typedef struct HksEventCommonInfo {
116     uint64_t traceId;
117     struct timespec time;
118     HksEventCallerInfo callerInfo;
119     HksEventResultInfo result;
120     HksEventStatInfo statInfo;
121     uint32_t eventId;
122     uint32_t operation;
123     uint32_t count;
124     char *function;
125 } HksEventCommonInfo;
126 
127 typedef struct HksEventCryptoInfo {
128     HksEventKeyInfo keyInfo;
129     HksEventKeyAccessInfo accessCtlInfo;
130     uint32_t blockMode;
131     uint32_t padding;
132     uint32_t digest;
133     uint32_t mgfDigest;
134     uint32_t handleId;
135 } HksEventCryptoInfo;
136 
137 typedef struct HksEventAgreeDeriveInfo {
138     HksEventKeyInfo keyInfo;
139     HksEventKeyAccessInfo accessCtlInfo;
140     uint32_t iterCnt;
141     uint32_t storageFlag;
142     uint32_t keySize;
143     uint32_t pubKeyType;
144     uint32_t handleId;
145 } HksEventAgreeDeriveInfo;
146 
147 typedef struct HksEventMacInfo {
148     HksEventKeyInfo keyInfo;
149     HksEventKeyAccessInfo accessCtlInfo;
150     uint32_t handleId;
151 } HksEventMacInfo;
152 
153 typedef struct HksEventAttestInfo {
154     HksEventKeyInfo keyInfo;
155     uint32_t baseCertType;
156     uint32_t isAnonymous;
157 } HksEventAttestInfo;
158 
159 typedef struct GenerateInfo {
160     struct HksEventKeyInfo keyInfo;
161     struct HksEventKeyAccessInfo keyAccessInfo;
162     uint32_t agreeAlg;
163     uint32_t pubKeyIsAlias;
164 } GenerateInfo;
165 
166 typedef struct ImportInfo {
167     struct HksEventKeyInfo keyInfo;
168     struct HksEventKeyAccessInfo keyAccessInfo;
169     uint32_t keyType;
170     uint32_t algSuit;
171 } ImportInfo;
172 
173 typedef struct RenameInfo {
174     struct HksEventKeyInfo keyInfo;
175     uint8_t dstAliasHash;
176     bool isCopy;
177 } RenameInfo;
178 
179 typedef struct DataSizeInfo {
180     char *component;
181     char *partition;
182     char *foldPath;
183     char *foldSize;
184     uint64_t partitionRemain;
185 } DataSizeInfo;
186 
187 typedef struct HksEventInfo {
188     struct HksEventCommonInfo common;
189     union {
190         HksEventKeyInfo keyInfo;
191         HksEventKeyAccessInfo keyAccessInfo;
192         HksEventCryptoInfo cryptoInfo;
193         HksEventAgreeDeriveInfo agreeDeriveInfo;
194         HksEventMacInfo macInfo;
195         HksEventAttestInfo attestInfo;
196         GenerateInfo generateInfo;
197         ImportInfo importInfo;
198         RenameInfo renameInfo;
199         DataSizeInfo dataSizeInfo;
200     };
201 } HksEventInfo;
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 #endif  // HKS_EVENT_INFO_H
208