• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "hks_config.h"
17 #include "hks_type.h"
18 
19 #ifdef _CUT_AUTHENTICATE_
20 #undef HKS_SUPPORT_RSA_C
21 #undef HKS_SUPPORT_ECC_C
22 #undef HKS_SUPPORT_ECDH_C
23 #undef HKS_SUPPORT_X25519_C
24 #undef HKS_SUPPORT_ED25519_C
25 #endif
26 
27 #define HKS_BLOCK_CIPHER_CBC_IV_LEN 16
28 #define HKS_AES_CCM_AAD_LEN_MIN     4
29 #define HKS_AES_CCM_NONCE_LEN_MIN   7
30 #define HKS_AES_CCM_NONCE_LEN_MAX   13
31 #define HKS_AES_GCM_NONCE_LEN_MIN   12
32 
33 #define HKS_RSA_OAEP_DIGEST_NUM 2
34 #define HKS_RSA_KEY_BLOCK_SIZE 8
35 #define HKS_BLOCK_CIPHER_CBC_BLOCK_SIZE 16
36 
37 #define HKS_ECC_SIGN_MAX_TL_SIZE    8
38 
39 #ifdef HKS_SUPPORT_RSA_C
40 static const uint32_t g_rsaKeySize[] = {
41     HKS_RSA_KEY_SIZE_512,
42     HKS_RSA_KEY_SIZE_768,
43     HKS_RSA_KEY_SIZE_1024,
44     HKS_RSA_KEY_SIZE_2048,
45     HKS_RSA_KEY_SIZE_3072,
46     HKS_RSA_KEY_SIZE_4096
47 };
48 static const uint32_t g_rsaPadding[] = {
49     HKS_PADDING_NONE,
50     HKS_PADDING_OAEP,
51     HKS_PADDING_PSS,
52     HKS_PADDING_PKCS1_V1_5,
53     HKS_PADDING_ISO_IEC_9796_2
54 };
55 static const uint32_t g_rsaDigest[] = {
56     HKS_DIGEST_MD5,
57     HKS_DIGEST_NONE,
58     HKS_DIGEST_SHA1,
59     HKS_DIGEST_SHA224,
60     HKS_DIGEST_SHA256,
61     HKS_DIGEST_SHA384,
62     HKS_DIGEST_SHA512
63 };
64 static const uint32_t g_rsaSignPadding[] = {
65     HKS_PADDING_NONE,
66     HKS_PADDING_PSS,
67     HKS_PADDING_PKCS1_V1_5,
68     HKS_PADDING_ISO_IEC_9796_2
69 };
70 static const uint32_t g_rsaCipherPadding[] = {
71     HKS_PADDING_NONE,
72     HKS_PADDING_OAEP,
73     HKS_PADDING_PKCS1_V1_5,
74 };
75 #endif
76 
77 #ifdef HKS_SUPPORT_AES_C
78 static const uint32_t g_aesKeySize[] = {
79     HKS_AES_KEY_SIZE_128,
80     HKS_AES_KEY_SIZE_192,
81     HKS_AES_KEY_SIZE_256
82 };
83 static const uint32_t g_aesMacKeySize[] = {
84     HKS_AES_KEY_SIZE_256,
85 };
86 static const uint32_t g_aesPadding[] = {
87     HKS_PADDING_NONE,
88     HKS_PADDING_PKCS7
89 };
90 static const uint32_t g_aesMode[] = {
91     HKS_MODE_CBC,
92     HKS_MODE_CCM,
93     HKS_MODE_CTR,
94     HKS_MODE_ECB,
95     HKS_MODE_GCM
96 };
97 static const uint32_t g_aesCbcPadding[] = {
98     HKS_PADDING_NONE,
99     HKS_PADDING_PKCS7
100 };
101 static const uint32_t g_aesAeadPadding[] = {
102     HKS_PADDING_NONE
103 };
104 static const uint32_t g_aesCtrPadding[] = {
105     HKS_PADDING_NONE
106 };
107 static const uint32_t g_aesEcbPadding[] = {
108     HKS_PADDING_NONE,
109     HKS_PADDING_PKCS7
110 };
111 #endif
112 
113 #ifdef HKS_SUPPORT_DES_C
114 static const uint32_t g_desKeySize[] = {
115     HKS_DES_KEY_SIZE_64
116 };
117 static const uint32_t g_desMacKeySize[] = {
118     HKS_DES_KEY_SIZE_64
119 };
120 static const uint32_t g_desPadding[] = {
121     HKS_PADDING_NONE
122 };
123 static const uint32_t g_desMode[] = {
124     HKS_MODE_CBC,
125     HKS_MODE_ECB
126 };
127 static const uint32_t g_desCbcPadding[] = {
128     HKS_PADDING_NONE
129 };
130 static const uint32_t g_desEcbPadding[] = {
131     HKS_PADDING_NONE
132 };
133 #endif
134 
135 #ifdef HKS_SUPPORT_3DES_C
136 static const uint32_t g_3desKeySize[] = {
137     HKS_3DES_KEY_SIZE_128,
138     HKS_3DES_KEY_SIZE_192
139 };
140 static const uint32_t g_3desMacKeySize[] = {
141     HKS_3DES_KEY_SIZE_128,
142     HKS_3DES_KEY_SIZE_192
143 };
144 static const uint32_t g_3desPadding[] = {
145     HKS_PADDING_NONE
146 };
147 static const uint32_t g_3desMode[] = {
148     HKS_MODE_CBC,
149     HKS_MODE_ECB
150 };
151 static const uint32_t g_3desCbcPadding[] = {
152     HKS_PADDING_NONE
153 };
154 static const uint32_t g_3desEcbPadding[] = {
155     HKS_PADDING_NONE
156 };
157 #endif
158 
159 #ifdef HKS_SUPPORT_SM4_C
160 static const uint32_t g_sm4KeySize[] = {
161     HKS_SM4_KEY_SIZE_128,
162 };
163 static const uint32_t g_sm4Padding[] = {
164     HKS_PADDING_NONE,
165     HKS_PADDING_PKCS7
166 };
167 static const uint32_t g_sm4Purpose[] = {
168     HKS_KEY_PURPOSE_ENCRYPT,
169     HKS_KEY_PURPOSE_DECRYPT,
170     HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT,
171 };
172 static const uint32_t g_sm4Mode[] = {
173     HKS_MODE_CBC,
174     HKS_MODE_CTR,
175     HKS_MODE_ECB,
176     HKS_MODE_CFB,
177     HKS_MODE_OFB,
178 };
179 static const uint32_t g_sm4CbcPadding[] = {
180     HKS_PADDING_NONE,
181     HKS_PADDING_PKCS7
182 };
183 static const uint32_t g_sm4CtrPadding[] = {
184     HKS_PADDING_NONE
185 };
186 static const uint32_t g_sm4EcbPadding[] = {
187     HKS_PADDING_NONE,
188     HKS_PADDING_PKCS7
189 };
190 static const uint32_t g_sm4CfbPadding[] = {
191     HKS_PADDING_NONE
192 };
193 static const uint32_t g_sm4OfbPadding[] = {
194     HKS_PADDING_NONE
195 };
196 #endif
197 
198 #ifdef HKS_SUPPORT_ECC_C
199 static const uint32_t g_eccKeySize[] = {
200     HKS_ECC_KEY_SIZE_224,
201     HKS_ECC_KEY_SIZE_256,
202     HKS_ECC_KEY_SIZE_384,
203     HKS_ECC_KEY_SIZE_521
204 };
205 
206 static const uint32_t g_eccDigest[] = {
207     HKS_DIGEST_NONE,
208     HKS_DIGEST_SHA1,
209     HKS_DIGEST_SHA224,
210     HKS_DIGEST_SHA256,
211     HKS_DIGEST_SHA384,
212     HKS_DIGEST_SHA512
213 };
214 #endif
215 
216 #ifdef HKS_SUPPORT_SM2_C
217 static const uint32_t g_sm2KeySize[] = {
218     HKS_SM2_KEY_SIZE_256
219 };
220 
221 static const uint32_t g_sm2Digest[] = {
222     HKS_DIGEST_SM3,
223     HKS_DIGEST_NONE
224 };
225 
226 static const uint32_t g_sm2CipherPadding[] = {
227     HKS_PADDING_NONE,
228 };
229 #endif
230 
231 #ifdef HKS_SUPPORT_SM3_C
232 static const uint32_t g_sm3Digest[] = {
233     HKS_DIGEST_SM3
234 };
235 #endif
236 
237 static const uint32_t g_digest[] = {
238     HKS_DIGEST_SHA256,
239     HKS_DIGEST_SHA384,
240     HKS_DIGEST_SHA512
241 };
242 
243 static const uint32_t g_macDigest[] = {
244     HKS_DIGEST_SHA256
245 };
246 
247 #ifdef HKS_SUPPORT_ECDH_C
248 static const uint32_t g_ecdhKeySize[] = {
249     HKS_ECC_KEY_SIZE_224,
250     HKS_ECC_KEY_SIZE_256,
251     HKS_ECC_KEY_SIZE_384,
252     HKS_ECC_KEY_SIZE_521
253 };
254 #endif
255 
256 #if defined(HKS_SUPPORT_X25519_C) || defined(HKS_SUPPORT_ED25519_C)
257 static const uint32_t g_curve25519KeySize[] = {
258     HKS_CURVE25519_KEY_SIZE_256,
259 };
260 #endif
261 #ifdef HKS_SUPPORT_HMAC_C
262 static const uint32_t g_hmacDigest[] = {
263     HKS_DIGEST_SHA1,
264     HKS_DIGEST_SHA224,
265     HKS_DIGEST_SHA256,
266     HKS_DIGEST_SHA384,
267     HKS_DIGEST_SHA512,
268     HKS_DIGEST_SM3
269 };
270 #endif
271 
272 #ifdef HKS_SUPPORT_DSA_C
273 static const uint32_t g_dsaDigest[] = {
274     HKS_DIGEST_NONE,
275     HKS_DIGEST_SHA1,
276     HKS_DIGEST_SHA224,
277     HKS_DIGEST_SHA256,
278     HKS_DIGEST_SHA384,
279     HKS_DIGEST_SHA512
280 };
281 #endif
282 #ifdef HKS_SUPPORT_DH_C
283 static const uint32_t g_dhKeySize[] = {
284     HKS_DH_KEY_SIZE_2048,
285     HKS_DH_KEY_SIZE_3072,
286     HKS_DH_KEY_SIZE_4096
287 };
288 #endif
289 
290 #ifdef HKS_SUPPORT_RSA_C
291 static const struct ParamsValuesChecker g_rsaParamSet[] = {
292     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { true, 0, false}, { true, 0, false}, { true, 0, false},
293         { false, 0, false} } },
294     { HKS_CHECK_TYPE_USE_KEY, { { true, 0, false}, { true, 0, false}, { true, 0, false}, { true, 0, false},
295         { false, 0, false} } }
296 };
297 static const struct ExpectParamsValuesChecker g_expectRsaParams[] = {
298     { HKS_CHECK_TYPE_GEN_KEY, {
299         { true, g_rsaKeySize, HKS_ARRAY_SIZE(g_rsaKeySize) },
300         { true, g_rsaPadding, HKS_ARRAY_SIZE(g_rsaPadding) },
301         { false, NULL, 0 },
302         { true, g_rsaDigest, HKS_ARRAY_SIZE(g_rsaDigest) },
303         { false, NULL, 0 }
304         }
305     },
306     { HKS_CHECK_TYPE_USE_KEY, {
307         { true, g_rsaKeySize, HKS_ARRAY_SIZE(g_rsaKeySize) },
308         { true, g_rsaPadding, HKS_ARRAY_SIZE(g_rsaPadding) },
309         { false, NULL, 0 },
310         { true, g_rsaDigest, HKS_ARRAY_SIZE(g_rsaDigest) },
311         { false, NULL, 0 }
312         }
313     }
314 };
315 #endif
316 
317 #ifdef HKS_SUPPORT_AES_C
318 static const struct ParamsValuesChecker g_aesParamSet[] = {
319     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { true, 0, false}, { true, 0, false}, { false, 0, false},
320         { true, 0, false} } },
321 	{ HKS_CHECK_TYPE_USE_KEY, { { false, 0, false}, { true, 0, false}, { true, 0, false}, { false, 0, false},
322         { true, 0, false} } },
323     { HKS_CHECK_TYPE_GEN_MAC_KEY, { { true, 0, false}, { false, 0, false}, { false, 0, false}, { true, 0, false},
324         { false, 0, false} } },
325     { HKS_CHECK_TYPE_GEN_DERIVE_KEY, { { true, 0, false}, { false, 0, false}, { false, 0, false}, { true, 0, false},
326         { false, 0, false} } }
327 };
328 
329 static const struct ExpectParamsValuesChecker g_expectAesParams[] = {
330     { HKS_CHECK_TYPE_GEN_KEY, {
331         { true, g_aesKeySize, HKS_ARRAY_SIZE(g_aesKeySize) },
332         { true, g_aesPadding, HKS_ARRAY_SIZE(g_aesPadding) },
333         { false, NULL, 0 },
334         { false, NULL, 0 },
335         { true, g_aesMode, HKS_ARRAY_SIZE(g_aesMode) }
336         }
337     },
338     { HKS_CHECK_TYPE_USE_KEY, {
339         { false, NULL, 0 },
340         { true, g_aesPadding, HKS_ARRAY_SIZE(g_aesPadding) },
341         { false, NULL, 0 },
342         { false, NULL, 0 },
343         { true, g_aesMode, HKS_ARRAY_SIZE(g_aesMode) }
344         }
345     },
346     { HKS_CHECK_TYPE_GEN_MAC_KEY, {
347         { true, g_aesMacKeySize, HKS_ARRAY_SIZE(g_aesMacKeySize) },
348         { false, NULL, 0 },
349         { false, NULL, 0 },
350         { true, g_macDigest, HKS_ARRAY_SIZE(g_macDigest) },
351         { false, NULL, 0 }
352         }
353     },
354     { HKS_CHECK_TYPE_GEN_DERIVE_KEY, {
355         { true, g_aesKeySize, HKS_ARRAY_SIZE(g_aesKeySize) },
356         { false, NULL, 0 },
357         { false, NULL, 0 },
358         { true, g_digest, HKS_ARRAY_SIZE(g_digest) },
359         { false, NULL, 0 }
360         }
361     }
362 };
363 #endif
364 
365 #ifdef HKS_SUPPORT_DES_C
366 static const struct ParamsValuesChecker g_desParamSet[] = {
367     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { true, 0, false}, { true, 0, false}, { false, 0, false},
368         { true, 0, false} } },
369     { HKS_CHECK_TYPE_USE_KEY, { { false, 0, false}, { true, 0, false}, { true, 0, false}, { false, 0, false},
370         { true, 0, false} } },
371     { HKS_CHECK_TYPE_GEN_MAC_KEY, { { true, 0, false}, { false, 0, false}, { false, 0, false}, { true, 0, false},
372         { false, 0, false} } },
373     { HKS_CHECK_TYPE_GEN_DERIVE_KEY, { { true, 0, false}, { false, 0, false}, { false, 0, false}, { true, 0, false},
374         { false, 0, false} } }
375 };
376 
377 static const struct ExpectParamsValuesChecker g_expectDesParams[] = {
378     { HKS_CHECK_TYPE_GEN_KEY, {
379         { true, g_desKeySize, HKS_ARRAY_SIZE(g_desKeySize) },
380         { true, g_desPadding, HKS_ARRAY_SIZE(g_desPadding) },
381         { false, NULL, 0 },
382         { false, NULL, 0 },
383         { true, g_desMode, HKS_ARRAY_SIZE(g_desMode) }
384         }
385     },
386     { HKS_CHECK_TYPE_USE_KEY, {
387         { false, NULL, 0 },
388         { true, g_desPadding, HKS_ARRAY_SIZE(g_desPadding) },
389         { false, NULL, 0 },
390         { false, NULL, 0 },
391         { true, g_desMode, HKS_ARRAY_SIZE(g_desMode) }
392         }
393     },
394     { HKS_CHECK_TYPE_GEN_MAC_KEY, {
395         { true, g_desMacKeySize, HKS_ARRAY_SIZE(g_desMacKeySize) },
396         { false, NULL, 0 },
397         { false, NULL, 0 },
398         { true, g_macDigest, HKS_ARRAY_SIZE(g_macDigest) },
399         { false, NULL, 0 }
400         }
401     },
402     { HKS_CHECK_TYPE_GEN_DERIVE_KEY, {
403         { true, g_desKeySize, HKS_ARRAY_SIZE(g_desKeySize) },
404         { false, NULL, 0 },
405         { false, NULL, 0 },
406         { true, g_digest, HKS_ARRAY_SIZE(g_digest) },
407         { false, NULL, 0 }
408         }
409     }
410 };
411 #endif
412 
413 #ifdef HKS_SUPPORT_3DES_C
414 static const struct ParamsValuesChecker g_3desParamSet[] = {
415     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { true, 0, false}, { true, 0, false}, { false, 0, false},
416         { true, 0, false} } },
417     { HKS_CHECK_TYPE_USE_KEY, { { false, 0, false}, { true, 0, false}, { true, 0, false}, { false, 0, false},
418         { true, 0, false} } },
419     { HKS_CHECK_TYPE_GEN_MAC_KEY, { { true, 0, false}, { false, 0, false}, { false, 0, false}, { true, 0, false},
420         { false, 0, false} } },
421     { HKS_CHECK_TYPE_GEN_DERIVE_KEY, { { true, 0, false}, { false, 0, false}, { false, 0, false}, { true, 0, false},
422         { false, 0, false} } }
423 };
424 
425 static const struct ExpectParamsValuesChecker g_expect3DesParams[] = {
426     { HKS_CHECK_TYPE_GEN_KEY, {
427         { true, g_3desKeySize, HKS_ARRAY_SIZE(g_3desKeySize) },
428         { true, g_3desPadding, HKS_ARRAY_SIZE(g_3desPadding) },
429         { false, NULL, 0 },
430         { false, NULL, 0 },
431         { true, g_3desMode, HKS_ARRAY_SIZE(g_3desMode) }
432         }
433     },
434     { HKS_CHECK_TYPE_USE_KEY, {
435         { false, NULL, 0 },
436         { true, g_3desPadding, HKS_ARRAY_SIZE(g_3desPadding) },
437         { false, NULL, 0 },
438         { false, NULL, 0 },
439         { true, g_3desMode, HKS_ARRAY_SIZE(g_3desMode) }
440         }
441     },
442     { HKS_CHECK_TYPE_GEN_MAC_KEY, {
443         { true, g_3desMacKeySize, HKS_ARRAY_SIZE(g_3desMacKeySize) },
444         { false, NULL, 0 },
445         { false, NULL, 0 },
446         { true, g_macDigest, HKS_ARRAY_SIZE(g_macDigest) },
447         { false, NULL, 0 }
448         }
449     },
450     { HKS_CHECK_TYPE_GEN_DERIVE_KEY, {
451         { true, g_3desKeySize, HKS_ARRAY_SIZE(g_3desKeySize) },
452         { false, NULL, 0 },
453         { false, NULL, 0 },
454         { true, g_digest, HKS_ARRAY_SIZE(g_digest) },
455         { false, NULL, 0 }
456         }
457     }
458 };
459 #endif
460 
461 #ifdef HKS_SUPPORT_ECC_C
462 static const struct ParamsValuesChecker g_eccParamSet[] = {
463     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
464         { false, 0, false} } },
465     { HKS_CHECK_TYPE_USE_KEY, { { false, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
466         { false, 0, false} } }
467 };
468 static const struct ExpectParamsValuesChecker g_expectEccParams[] = {
469     { HKS_CHECK_TYPE_GEN_KEY, {
470         { true, g_eccKeySize, HKS_ARRAY_SIZE(g_eccKeySize) },
471         { false, NULL, 0 },
472         { false, NULL, 0 },
473         { true, g_eccDigest, HKS_ARRAY_SIZE(g_eccDigest) },
474         { false, NULL, 0 }
475         }
476     },
477     { HKS_CHECK_TYPE_USE_KEY, {
478         { false, NULL, 0 },
479         { false, NULL, 0 },
480         { false, NULL, 0 },
481         { true, g_eccDigest, HKS_ARRAY_SIZE(g_eccDigest) },
482         { false, NULL, 0 }
483         }
484     }
485 };
486 #endif
487 
488 #ifdef HKS_SUPPORT_SM2_C
489 static const struct ParamsValuesChecker g_sm2ParamSet[] = {
490     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
491         { false, 0, false} } },
492     { HKS_CHECK_TYPE_USE_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
493         { false, 0, false} } }
494 };
495 static const struct ExpectParamsValuesChecker g_expectSm2Params[] = {
496     { HKS_CHECK_TYPE_GEN_KEY, {
497         { true, g_sm2KeySize, HKS_ARRAY_SIZE(g_sm2KeySize) },
498         { false, NULL, 0 },
499         { false, NULL, 0 },
500         { true, g_sm2Digest, HKS_ARRAY_SIZE(g_sm2Digest) },
501         { false, NULL, 0 }
502         }
503     },
504     { HKS_CHECK_TYPE_USE_KEY, {
505         { true, g_sm2KeySize, HKS_ARRAY_SIZE(g_sm2KeySize) },
506         { false, NULL, 0 },
507         { false, NULL, 0 },
508         { true, g_sm2Digest, HKS_ARRAY_SIZE(g_sm2Digest) },
509         { false, NULL, 0 }
510         }
511     }
512 };
513 #endif
514 
515 #ifdef HKS_SUPPORT_SM3_C
516 static const struct ParamsValuesChecker g_sm3ParamSet[] = {
517     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
518         { false, 0, false} } },
519     { HKS_CHECK_TYPE_GEN_MAC_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
520         { false, 0, false} } }
521 };
522 static const struct ExpectParamsValuesChecker g_expectSm3Params[] = {
523     { HKS_CHECK_TYPE_GEN_KEY, {
524         { false, NULL, 0 },
525         { false, NULL, 0 },
526         { false, NULL, 0 },
527         { true, g_sm3Digest, sizeof(g_sm3Digest) / sizeof(g_sm3Digest[0]) },
528         { false, NULL, 0 }
529         }
530     },
531     { HKS_CHECK_TYPE_GEN_MAC_KEY, {
532         { false, NULL, 0 },
533         { false, NULL, 0 },
534         { false, NULL, 0 },
535         { true, g_sm3Digest, sizeof(g_sm3Digest) / sizeof(g_sm3Digest[0]) },
536         { false, NULL, 0 }
537         }
538     }
539 };
540 #endif
541 
542 #ifdef HKS_SUPPORT_SM4_C
543 static const struct ParamsValuesChecker g_sm4ParamSet[] = {
544     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { true, 0, false}, { true, 0, false}, { false, 0, false},
545         { true, 0, false} } },
546     { HKS_CHECK_TYPE_USE_KEY, { { true, 0, false}, { true, 0, false}, { true, 0, false}, { false, 0, false},
547         { true, 0, false} } },
548     { HKS_CHECK_TYPE_GEN_DERIVE_KEY, { { true, 0, false}, { false, 0, false}, { false, 0, false}, { true, 0, false},
549         { false, 0, false} } }
550 };
551 static const struct ExpectParamsValuesChecker g_expectSm4Params[] = {
552     { HKS_CHECK_TYPE_GEN_KEY, {
553         { true, g_sm4KeySize, HKS_ARRAY_SIZE(g_sm4KeySize) },
554         { true, g_sm4Padding, HKS_ARRAY_SIZE(g_sm4Padding) },
555         { true, g_sm4Purpose, HKS_ARRAY_SIZE(g_sm4Purpose) },
556         { false, NULL, 0 },
557         { true, g_sm4Mode, HKS_ARRAY_SIZE(g_sm4Mode) }
558         }
559     },
560     { HKS_CHECK_TYPE_USE_KEY, {
561         { true, g_sm4KeySize, HKS_ARRAY_SIZE(g_sm4KeySize) },
562         { true, g_sm4Padding, HKS_ARRAY_SIZE(g_sm4Padding) },
563         { true, g_sm4Purpose, HKS_ARRAY_SIZE(g_sm4Purpose) },
564         { false, NULL, 0 },
565         { true, g_sm4Mode, HKS_ARRAY_SIZE(g_sm4Mode) }
566         }
567     },
568     { HKS_CHECK_TYPE_GEN_DERIVE_KEY, {
569         { true, g_sm4KeySize, HKS_ARRAY_SIZE(g_sm4KeySize) },
570         { false, NULL, 0 },
571         { false, NULL, 0 },
572         { true, g_sm3Digest, HKS_ARRAY_SIZE(g_sm3Digest) },
573         { false, NULL, 0 }
574         }
575     }
576 };
577 #endif
578 
579 #if defined(HKS_SUPPORT_X25519_C) || defined(HKS_SUPPORT_ED25519_C)
580 static const struct ParamsValuesChecker g_curve25519ParamSet[] = {
581     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { false, 0, false},
582         { false, 0, false} } },
583     { HKS_CHECK_TYPE_USE_KEY, { { false, 0, false}, { false, 0, false}, { true, 0, false}, { false, 0, false},
584         { false, 0, false} } }
585 };
586 static const struct ExpectParamsValuesChecker g_expectCurve25519Params[] = {
587     { HKS_CHECK_TYPE_GEN_KEY, {
588         { true, g_curve25519KeySize, sizeof(g_curve25519KeySize) / sizeof(g_curve25519KeySize[0]) },
589         { false, NULL, 0 },
590         { false, NULL, 0 },
591         { false, NULL, 0 },
592         { false, NULL, 0 }
593         }
594     },
595     { HKS_CHECK_TYPE_USE_KEY, {
596         { false, NULL, 0 },
597         { false, NULL, 0 },
598         { false, NULL, 0 },
599         { false, NULL, 0 },
600         { false, NULL, 0 }
601         }
602     }
603 };
604 #endif
605 
606 #ifdef HKS_SUPPORT_HMAC_C
607 static const struct ParamsValuesChecker g_hmacParamSet[] = {
608     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
609         { false, 0, false} } },
610     { HKS_CHECK_TYPE_USE_KEY, { { false, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
611         { false, 0, false} } },
612     { HKS_CHECK_TYPE_GEN_MAC_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
613         { false, 0, false} } }
614 };
615 static const struct ExpectParamsValuesChecker g_expectHmacParams[] = {
616     { HKS_CHECK_TYPE_GEN_KEY, {
617         { false, NULL, 0 },
618         { false, NULL, 0 },
619         { false, NULL, 0 },
620         { true, g_hmacDigest, sizeof(g_hmacDigest) / sizeof(g_hmacDigest[0]) },
621         { false, NULL, 0 }
622         }
623     },
624     { HKS_CHECK_TYPE_USE_KEY, {
625         { false, NULL, 0 },
626         { false, NULL, 0 },
627         { false, NULL, 0 },
628         { true, g_hmacDigest, sizeof(g_hmacDigest) / sizeof(g_hmacDigest[0]) },
629         { false, NULL, 0 }
630         }
631     },
632     { HKS_CHECK_TYPE_GEN_MAC_KEY, {
633         { false, NULL, 0 },
634         { false, NULL, 0 },
635         { false, NULL, 0 },
636         { true, g_hmacDigest, sizeof(g_hmacDigest) / sizeof(g_hmacDigest[0]) },
637         { false, NULL, 0 }
638         }
639     }
640 };
641 #endif
642 
643 #ifdef HKS_SUPPORT_CMAC_C
644 static const struct ParamsValuesChecker g_cmacParamSet[] = {
645     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
646         { false, 0, false} } },
647     { HKS_CHECK_TYPE_USE_KEY, { { false, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
648         { false, 0, false} } },
649     { HKS_CHECK_TYPE_GEN_MAC_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
650         { false, 0, false} } }
651 };
652 static const struct ExpectParamsValuesChecker g_expectCmacParams[] = {
653     { HKS_CHECK_TYPE_GEN_KEY, {
654         { false, NULL, 0 },
655         { false, NULL, 0 },
656         { false, NULL, 0 },
657         { false, NULL, 0 },
658         { false, NULL, 0 }
659         }
660     },
661     { HKS_CHECK_TYPE_USE_KEY, {
662         { false, NULL, 0 },
663         { false, NULL, 0 },
664         { false, NULL, 0 },
665         { false, NULL, 0 },
666         { false, NULL, 0 }
667         }
668     },
669     { HKS_CHECK_TYPE_GEN_MAC_KEY, {
670         { false, NULL, 0 },
671         { false, NULL, 0 },
672         { false, NULL, 0 },
673         { false, NULL, 0 },
674         { false, NULL, 0 }
675         }
676     }
677 };
678 #endif
679 
680 #ifdef HKS_SUPPORT_DSA_C
681 static const struct ParamsValuesChecker g_dsaParamSet[] = {
682     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
683         { false, 0, false} } },
684     { HKS_CHECK_TYPE_USE_KEY, { { false, 0, false}, { false, 0, false}, { true, 0, false}, { true, 0, false},
685         { false, 0, false} } }
686 };
687 static const struct ExpectParamsValuesChecker g_expectDsaParams[] = {
688     { HKS_CHECK_TYPE_GEN_KEY, {
689         { false, NULL, 0 },
690         { false, NULL, 0 },
691         { false, NULL, 0 },
692         { true, g_dsaDigest, sizeof(g_dsaDigest) / sizeof(g_dsaDigest[0]) },
693         { false, NULL, 0 }
694         }
695     },
696     { HKS_CHECK_TYPE_USE_KEY, {
697         { false, NULL, 0 },
698         { false, NULL, 0 },
699         { false, NULL, 0 },
700         { true, g_dsaDigest, sizeof(g_dsaDigest) / sizeof(g_dsaDigest[0]) },
701         { false, NULL, 0 }
702         }
703     }
704 };
705 #endif
706 
707 #ifdef HKS_SUPPORT_DH_C
708 static const struct ParamsValuesChecker g_dhParamSet[] = {
709     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { false, 0, false},
710         { false, 0, false} } },
711     { HKS_CHECK_TYPE_USE_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { false, 0, false},
712         { false, 0, false} } }
713 };
714 static const struct ExpectParamsValuesChecker g_expectDhParams[] = {
715     { HKS_CHECK_TYPE_GEN_KEY, {
716         { true, g_dhKeySize, sizeof(g_dhKeySize) / sizeof(g_dhKeySize[0]) },
717         { false, NULL, 0 },
718         { false, NULL, 0 },
719         { false, NULL, 0 },
720         { false, NULL, 0 }
721         }
722     },
723     { HKS_CHECK_TYPE_USE_KEY, {
724         { true, g_dhKeySize, sizeof(g_dhKeySize) / sizeof(g_dhKeySize[0]) },
725         { false, NULL, 0 },
726         { false, NULL, 0 },
727         { false, NULL, 0 },
728         { false, NULL, 0 }
729         }
730     }
731 };
732 #endif
733 
734 #ifdef HKS_SUPPORT_ECDH_C
735 static const struct ParamsValuesChecker g_ecdhParamSet[] = {
736     { HKS_CHECK_TYPE_GEN_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { false, 0, false},
737         { false, 0, false} } },
738     { HKS_CHECK_TYPE_USE_KEY, { { true, 0, false}, { false, 0, false}, { true, 0, false}, { false, 0, false},
739         { false, 0, false} } }
740 };
741 static const struct ExpectParamsValuesChecker g_expectEcdhParams[] = {
742     { HKS_CHECK_TYPE_GEN_KEY, {
743         { true, g_ecdhKeySize, sizeof(g_ecdhKeySize) / sizeof(g_ecdhKeySize[0]) },
744         { false, NULL, 0 },
745         { false, NULL, 0 },
746         { false, NULL, 0 },
747         { false, NULL, 0 }
748         }
749     },
750     { HKS_CHECK_TYPE_USE_KEY, {
751         { true, g_ecdhKeySize, sizeof(g_ecdhKeySize) / sizeof(g_ecdhKeySize[0]) },
752         { false, NULL, 0 },
753         { false, NULL, 0 },
754         { false, NULL, 0 },
755         { false, NULL, 0 }
756         }
757     }
758 };
759 #endif
760 
761 static struct HksAlgParamSetHandler g_hksAlgParamSetHandlerPart1[] = {
762 #ifdef HKS_SUPPORT_RSA_C
763     { HKS_ALG_RSA, g_rsaParamSet, HKS_ARRAY_SIZE(g_rsaParamSet), g_expectRsaParams, HKS_ARRAY_SIZE(g_expectRsaParams) },
764 #endif
765 #ifdef HKS_SUPPORT_AES_C
766     { HKS_ALG_AES, g_aesParamSet, HKS_ARRAY_SIZE(g_aesParamSet), g_expectAesParams, HKS_ARRAY_SIZE(g_expectAesParams) },
767 #endif
768 #ifdef HKS_SUPPORT_DES_C
769     { HKS_ALG_DES, g_desParamSet, HKS_ARRAY_SIZE(g_desParamSet), g_expectDesParams, HKS_ARRAY_SIZE(g_expectDesParams) },
770 #endif
771 #ifdef HKS_SUPPORT_3DES_C
772     { HKS_ALG_3DES, g_3desParamSet, HKS_ARRAY_SIZE(g_3desParamSet), g_expect3DesParams,
773         HKS_ARRAY_SIZE(g_expect3DesParams) },
774 #endif
775 #ifdef HKS_SUPPORT_ECC_C
776     { HKS_ALG_ECC, g_eccParamSet, HKS_ARRAY_SIZE(g_eccParamSet), g_expectEccParams, HKS_ARRAY_SIZE(g_expectEccParams) },
777 #endif
778 #ifdef HKS_SUPPORT_SM2_C
779     { HKS_ALG_SM2, g_sm2ParamSet, HKS_ARRAY_SIZE(g_sm2ParamSet), g_expectSm2Params, HKS_ARRAY_SIZE(g_expectSm2Params) },
780 #endif
781 #ifdef HKS_SUPPORT_SM3_C
782     { HKS_ALG_SM3, g_sm3ParamSet, HKS_ARRAY_SIZE(g_sm3ParamSet), g_expectSm3Params, HKS_ARRAY_SIZE(g_expectSm3Params) },
783 #endif
784 #ifdef HKS_SUPPORT_SM4_C
785     { HKS_ALG_SM4, g_sm4ParamSet, HKS_ARRAY_SIZE(g_sm4ParamSet), g_expectSm4Params, HKS_ARRAY_SIZE(g_expectSm4Params) },
786 #endif
787 };
788 
789 static struct HksAlgParamSetHandler g_hksAlgParamSetHandlerPart2[] = {
790 #ifdef HKS_SUPPORT_X25519_C
791     { HKS_ALG_X25519, g_curve25519ParamSet, HKS_ARRAY_SIZE(g_curve25519ParamSet), g_expectCurve25519Params,
792         HKS_ARRAY_SIZE(g_expectCurve25519Params) },
793 #endif
794 #ifdef HKS_SUPPORT_ED25519_C
795     { HKS_ALG_ED25519, g_curve25519ParamSet, HKS_ARRAY_SIZE(g_curve25519ParamSet), g_expectCurve25519Params,
796         HKS_ARRAY_SIZE(g_expectCurve25519Params) },
797 #endif
798 #ifdef HKS_SUPPORT_HMAC_C
799     { HKS_ALG_HMAC, g_hmacParamSet, HKS_ARRAY_SIZE(g_hmacParamSet), g_expectHmacParams,
800         HKS_ARRAY_SIZE(g_expectHmacParams) },
801 #endif
802 #ifdef HKS_SUPPORT_CMAC_C
803     { HKS_ALG_CMAC, g_cmacParamSet, HKS_ARRAY_SIZE(g_cmacParamSet), g_expectCmacParams,
804         HKS_ARRAY_SIZE(g_expectCmacParams) },
805 #endif
806 #ifdef HKS_SUPPORT_DSA_C
807     { HKS_ALG_DSA, g_dsaParamSet, HKS_ARRAY_SIZE(g_dsaParamSet), g_expectDsaParams, HKS_ARRAY_SIZE(g_expectDsaParams) },
808 #endif
809 #ifdef HKS_SUPPORT_DH_C
810     { HKS_ALG_DH, g_dhParamSet, HKS_ARRAY_SIZE(g_dhParamSet), g_expectDhParams, HKS_ARRAY_SIZE(g_expectDhParams) },
811 #endif
812 #ifdef HKS_SUPPORT_ECDH_C
813     { HKS_ALG_ECDH, g_ecdhParamSet, HKS_ARRAY_SIZE(g_ecdhParamSet), g_expectEcdhParams,
814         HKS_ARRAY_SIZE(g_expectEcdhParams) },
815 #endif
816 };
817 
818 #ifndef _CUT_AUTHENTICATE_
819 static const uint32_t g_invalidPurpose[][2] = {
820 #ifdef HKS_SUPPORT_RSA_C
821     {
822         HKS_ALG_RSA,
823         HKS_KEY_PURPOSE_DERIVE | HKS_KEY_PURPOSE_MAC | HKS_KEY_PURPOSE_WRAP | HKS_KEY_PURPOSE_UNWRAP |
824             HKS_KEY_PURPOSE_AGREE,
825     },
826 #endif
827 #ifdef HKS_SUPPORT_ECC_C
828     {
829         HKS_ALG_ECC,
830         HKS_KEY_PURPOSE_DERIVE | HKS_KEY_PURPOSE_MAC | HKS_KEY_PURPOSE_WRAP |
831             HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT,
832     },
833 #endif
834 #ifdef HKS_SUPPORT_SM2_C
835     {
836         HKS_ALG_SM2,
837         HKS_KEY_PURPOSE_DERIVE | HKS_KEY_PURPOSE_MAC | HKS_KEY_PURPOSE_WRAP,
838     },
839 #endif
840 #ifdef HKS_SUPPORT_SM3_C
841     {
842         HKS_ALG_SM3,
843         HKS_KEY_PURPOSE_DERIVE | HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY | HKS_KEY_PURPOSE_WRAP |
844             HKS_KEY_PURPOSE_UNWRAP | HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT | HKS_KEY_PURPOSE_AGREE,
845     },
846 #endif
847 #ifdef HKS_SUPPORT_SM4_C
848     {
849         HKS_ALG_SM4,
850         HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY | HKS_KEY_PURPOSE_WRAP |
851             HKS_KEY_PURPOSE_UNWRAP | HKS_KEY_PURPOSE_MAC | HKS_KEY_PURPOSE_AGREE,
852     },
853 #endif
854 #ifdef HKS_SUPPORT_AES_C
855     {
856         HKS_ALG_AES,
857         HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY | HKS_KEY_PURPOSE_AGREE | HKS_KEY_PURPOSE_WRAP |
858             HKS_KEY_PURPOSE_UNWRAP,
859     },
860 #endif
861 #ifdef HKS_SUPPORT_DES_C
862     {
863         HKS_ALG_DES,
864         HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY | HKS_KEY_PURPOSE_AGREE | HKS_KEY_PURPOSE_WRAP |
865             HKS_KEY_PURPOSE_UNWRAP,
866     },
867 #endif
868 #ifdef HKS_SUPPORT_3DES_C
869     {
870         HKS_ALG_3DES,
871         HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY | HKS_KEY_PURPOSE_AGREE | HKS_KEY_PURPOSE_WRAP |
872             HKS_KEY_PURPOSE_UNWRAP,
873     },
874 #endif
875 #ifdef HKS_SUPPORT_ED25519_C
876     {
877         HKS_ALG_ED25519,
878         HKS_KEY_PURPOSE_DERIVE | HKS_KEY_PURPOSE_MAC | HKS_KEY_PURPOSE_WRAP | HKS_KEY_PURPOSE_UNWRAP |
879             HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT,
880     },
881 #endif
882 #ifdef HKS_SUPPORT_X25519_C
883     {
884         HKS_ALG_X25519,
885         HKS_KEY_PURPOSE_DERIVE | HKS_KEY_PURPOSE_MAC | HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT |
886             HKS_KEY_PURPOSE_WRAP,
887     },
888 #endif
889 #ifdef HKS_SUPPORT_HMAC_C
890     {
891         HKS_ALG_HMAC,
892         HKS_KEY_PURPOSE_DERIVE | HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY | HKS_KEY_PURPOSE_WRAP |
893             HKS_KEY_PURPOSE_UNWRAP | HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT | HKS_KEY_PURPOSE_AGREE,
894     },
895 #endif
896 #ifdef HKS_SUPPORT_CMAC_C
897     {
898         HKS_ALG_CMAC,
899         HKS_KEY_PURPOSE_DERIVE | HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY | HKS_KEY_PURPOSE_WRAP |
900             HKS_KEY_PURPOSE_UNWRAP | HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT | HKS_KEY_PURPOSE_AGREE,
901     },
902 #endif
903 #ifdef HKS_SUPPORT_DSA_C
904     {
905         HKS_ALG_DSA,
906         HKS_KEY_PURPOSE_DERIVE | HKS_KEY_PURPOSE_MAC | HKS_KEY_PURPOSE_WRAP | HKS_KEY_PURPOSE_UNWRAP |
907             HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT | HKS_KEY_PURPOSE_AGREE,
908     },
909 #endif
910 #ifdef HKS_SUPPORT_DH_C
911     {
912         HKS_ALG_DH,
913         HKS_KEY_PURPOSE_DERIVE | HKS_KEY_PURPOSE_MAC | HKS_KEY_PURPOSE_WRAP | HKS_KEY_PURPOSE_UNWRAP |
914             HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT | HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY,
915     },
916 #endif
917 #ifdef HKS_SUPPORT_ECDH_C
918     {
919         HKS_ALG_ECDH,
920         HKS_KEY_PURPOSE_DERIVE | HKS_KEY_PURPOSE_MAC | HKS_KEY_PURPOSE_WRAP | HKS_KEY_PURPOSE_UNWRAP |
921             HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT | HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY,
922     },
923 #endif
924 };
925 
926 static const uint32_t g_invalidImportKeyPurpose[][2] = {
927 #ifdef HKS_SUPPORT_ECC_C
928     {
929         HKS_ALG_ECC,
930         HKS_KEY_PURPOSE_WRAP | HKS_KEY_PURPOSE_UNWRAP,
931     },
932 #endif
933 #ifdef HKS_SUPPORT_X25519_C
934     {
935         HKS_ALG_X25519,
936         HKS_KEY_PURPOSE_WRAP | HKS_KEY_PURPOSE_UNWRAP,
937     },
938 #endif
939 #ifdef HKS_SUPPORT_SM2_C
940     {
941         HKS_ALG_SM2,
942         HKS_KEY_PURPOSE_WRAP | HKS_KEY_PURPOSE_UNWRAP,
943     },
944 #endif
945 };
946 #endif
947 
948 #ifdef HKS_SUPPORT_USER_AUTH_ACCESS_CONTROL
949 static const uint32_t g_userAuthChallengeType[] = {
950     HKS_CHALLENGE_TYPE_NORMAL,
951     HKS_CHALLENGE_TYPE_CUSTOM,
952     HKS_CHALLENGE_TYPE_NONE,
953 };
954 
955 static const uint32_t g_validBiometricAuthAccessType[] = {
956     HKS_AUTH_ACCESS_INVALID_NEW_BIO_ENROLL,
957     HKS_AUTH_ACCESS_INVALID_CLEAR_PASSWORD,
958     HKS_AUTH_ACCESS_ALWAYS_VALID
959 };
960 
961 static const uint32_t g_validPinAuthAccessType[] = {
962     HKS_AUTH_ACCESS_INVALID_CLEAR_PASSWORD,
963     HKS_AUTH_ACCESS_ALWAYS_VALID
964 };
965 
966 static const uint32_t g_validTuiPinAuthAccessType[] = {
967     HKS_AUTH_ACCESS_ALWAYS_VALID
968 };
969 
970 static const struct AuthAccessTypeChecker g_expectAuthAccessParams[] = {
971     { HKS_USER_AUTH_TYPE_FACE,
972         { true, g_validBiometricAuthAccessType, HKS_ARRAY_SIZE(g_validBiometricAuthAccessType) }
973     },
974     { HKS_USER_AUTH_TYPE_FINGERPRINT,
975         { true, g_validBiometricAuthAccessType, HKS_ARRAY_SIZE(g_validBiometricAuthAccessType) }
976     },
977     { HKS_USER_AUTH_TYPE_PIN,
978         { true, g_validPinAuthAccessType, HKS_ARRAY_SIZE(g_validPinAuthAccessType) }
979     },
980     { HKS_USER_AUTH_TYPE_TUI_PIN,
981         { true, g_validTuiPinAuthAccessType, HKS_ARRAY_SIZE(g_validTuiPinAuthAccessType) }
982     }
983 };
984 
985 static const uint32_t g_supportUserAuthTypes[] = {
986     HKS_USER_AUTH_TYPE_PIN,
987     HKS_USER_AUTH_TYPE_FINGERPRINT,
988     HKS_USER_AUTH_TYPE_FACE,
989     HKS_USER_AUTH_TYPE_PIN | HKS_USER_AUTH_TYPE_FINGERPRINT,
990     HKS_USER_AUTH_TYPE_PIN | HKS_USER_AUTH_TYPE_FACE,
991     HKS_USER_AUTH_TYPE_FACE | HKS_USER_AUTH_TYPE_FINGERPRINT,
992     HKS_USER_AUTH_TYPE_PIN | HKS_USER_AUTH_TYPE_FACE | HKS_USER_AUTH_TYPE_FINGERPRINT,
993     HKS_USER_AUTH_TYPE_TUI_PIN,
994     HKS_USER_AUTH_TYPE_TUI_PIN | HKS_USER_AUTH_TYPE_FINGERPRINT,
995     HKS_USER_AUTH_TYPE_TUI_PIN | HKS_USER_AUTH_TYPE_FACE,
996     HKS_USER_AUTH_TYPE_TUI_PIN | HKS_USER_AUTH_TYPE_FACE | HKS_USER_AUTH_TYPE_FINGERPRINT
997 };
998 
999 static const uint32_t g_supportSecureSignType[] = {
1000     HKS_SECURE_SIGN_WITH_AUTHINFO
1001 };
1002 
1003 #ifdef HKS_SUPPORT_AES_C
1004 static const uint32_t g_supportAesPurpose[] = {
1005     HKS_KEY_PURPOSE_ENCRYPT,
1006     HKS_KEY_PURPOSE_DECRYPT,
1007     HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT,
1008     HKS_KEY_PURPOSE_DERIVE,
1009     HKS_KEY_PURPOSE_MAC
1010 };
1011 
1012 static const uint32_t g_supportAesCipherMode[] = {
1013     HKS_MODE_CBC,
1014     HKS_MODE_GCM,
1015     HKS_MODE_CCM
1016 };
1017 
1018 static const struct KeyInfoParams g_validAesKeyInfo[] = {
1019     { true, HKS_TAG_PURPOSE, g_supportAesPurpose, HKS_ARRAY_SIZE(g_supportAesPurpose) },
1020     { true, HKS_TAG_BLOCK_MODE, g_supportAesCipherMode, HKS_ARRAY_SIZE(g_supportAesCipherMode) }
1021 };
1022 #endif
1023 
1024 #ifdef HKS_SUPPORT_DES_C
1025 static const uint32_t g_supportDesPurpose[] = {
1026     HKS_KEY_PURPOSE_ENCRYPT,
1027     HKS_KEY_PURPOSE_DECRYPT,
1028     HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT,
1029     HKS_KEY_PURPOSE_DERIVE,
1030     HKS_KEY_PURPOSE_MAC
1031 };
1032 
1033 static const uint32_t g_supportDesCipherMode[] = {
1034     HKS_MODE_CBC,
1035     HKS_MODE_ECB
1036 };
1037 
1038 static const struct KeyInfoParams g_validDesKeyInfo[] = {
1039     { true, HKS_TAG_PURPOSE, g_supportDesPurpose, HKS_ARRAY_SIZE(g_supportDesPurpose) },
1040     { true, HKS_TAG_BLOCK_MODE, g_supportDesCipherMode, HKS_ARRAY_SIZE(g_supportDesCipherMode) }
1041 };
1042 #endif
1043 
1044 #ifdef HKS_SUPPORT_3DES_C
1045 static const uint32_t g_support3DesPurpose[] = {
1046     HKS_KEY_PURPOSE_ENCRYPT,
1047     HKS_KEY_PURPOSE_DECRYPT,
1048     HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT,
1049     HKS_KEY_PURPOSE_DERIVE,
1050     HKS_KEY_PURPOSE_MAC
1051 };
1052 
1053 static const uint32_t g_support3DesCipherMode[] = {
1054     HKS_MODE_CBC,
1055     HKS_MODE_ECB
1056 };
1057 
1058 static const struct KeyInfoParams g_valid3DesKeyInfo[] = {
1059     { true, HKS_TAG_PURPOSE, g_support3DesPurpose, HKS_ARRAY_SIZE(g_support3DesPurpose) },
1060     { true, HKS_TAG_BLOCK_MODE, g_support3DesCipherMode, HKS_ARRAY_SIZE(g_support3DesCipherMode) }
1061 };
1062 #endif
1063 
1064 #ifdef HKS_SUPPORT_SM4_C
1065 static const uint32_t g_supportSm4Purpose[] = {
1066     HKS_KEY_PURPOSE_ENCRYPT,
1067     HKS_KEY_PURPOSE_DECRYPT,
1068     HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT
1069 };
1070 
1071 static const uint32_t g_supportSm4CipherMode[] = {
1072     HKS_MODE_CBC
1073 };
1074 
1075 static const struct KeyInfoParams g_validSm4KeyInfo[] = {
1076     { true, HKS_TAG_PURPOSE, g_supportSm4Purpose, HKS_ARRAY_SIZE(g_supportSm4Purpose) },
1077     { true, HKS_TAG_BLOCK_MODE, g_supportSm4CipherMode, HKS_ARRAY_SIZE(g_supportSm4CipherMode) }
1078 };
1079 #endif
1080 
1081 static const struct AuthAcceessKeyInfoChecker g_validKeyInfo[] = {
1082 #ifdef HKS_SUPPORT_AES_C
1083     { HKS_ALG_AES, g_validAesKeyInfo, HKS_ARRAY_SIZE(g_validAesKeyInfo) },
1084 #endif
1085 #ifdef HKS_SUPPORT_DES_C
1086     { HKS_ALG_DES, g_validDesKeyInfo, HKS_ARRAY_SIZE(g_validDesKeyInfo) },
1087 #endif
1088 #ifdef HKS_SUPPORT_3DES_C
1089     { HKS_ALG_3DES, g_valid3DesKeyInfo, HKS_ARRAY_SIZE(g_valid3DesKeyInfo) },
1090 #endif
1091 #ifdef HKS_SUPPORT_SM4_C
1092     { HKS_ALG_SM4, g_validSm4KeyInfo, HKS_ARRAY_SIZE(g_validSm4KeyInfo) }
1093 #endif
1094 };
1095 #endif
1096