• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
2  * Licensed under the Apache License, Version 2.0 (the "License");
3  * you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13 */
14 #include "security_data_huks.h"
15 #include "hctest.h"
16 #include "hks_client.h"
17 #include "hks_types.h"
18 #include <securec.h>
19 #include <stdbool.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 /* *
25  * @tc.desc      : register a test suite, this suite is used to test basic flow and interface dependency
26  * @param        : subsystem name is security
27  * @param        : module name is securityData
28  * @param        : test suit name is SecurityDataHuksSignVerifyTestSuite
29  */
30 LITE_TEST_SUIT(security, securityData, SecurityDataHuksSignVerifyTestSuite);
31 
32 /* *
33  * @tc.setup     : setup for all testcases
34  * @return       : setup result, TRUE is success, FALSE is fail
35  */
SecurityDataHuksSignVerifyTestSuiteSetUp(void)36 static BOOL SecurityDataHuksSignVerifyTestSuiteSetUp(void)
37 {
38     int32_t status;
39     status = hks_init();
40     if (status != 0) {
41         status = hks_refresh_key_info();
42     }
43     TEST_ASSERT_EQUAL_INT(0, status);
44     return TRUE;
45 }
46 
47 /* *
48  * @tc.teardown  : teardown for all testcases
49  * @return       : teardown result, TRUE is success, FALSE is fail
50  */
SecurityDataHuksSignVerifyTestSuiteTearDown(void)51 static BOOL SecurityDataHuksSignVerifyTestSuiteTearDown(void)
52 {
53     printf("-++++++++++++++++++++++++++++++++++++++++++++-\n");
54     return TRUE;
55 }
56 #ifndef _CUT_AUTHENTICATE_
57 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Sign key
58 // begin+++++++++++++++++++++++++++++++++++++++++++++++++++++++0200-0340
59 
60 /*
61  * @tc.number    : SUB_SEC_DataPro_HuksL0_0200
62  * @tc.name      : Asymmetric Sign, normal input parameters keyAlias, keyParam, hash, signature
63  * @tc.desc      : [C- SECURITY -1900]
64  */
65 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0200, Function | MediumTest | Level2)
66 {
67     int32_t statusAsymmetricSign;
68     int32_t statusAsymmetricVerify;
69     unsigned char testFileName[] = "keyalias1";
70     struct hks_blob keyAlias = { 0 };
71 
72     keyAlias.data = (uint8_t *)testFileName;
73     keyAlias.size = sizeof(testFileName);
74     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
75 
76     uint8_t hash1[NUM32];
77     struct hks_blob hash;
78     hash.data = (uint8_t *)hash1;
79     hash.size = sizeof(hash1);
80 
81     uint32_t alg = HKS_ALG_HASH_SHA_256;
82     struct hks_blob src;
83     src.data = (uint8_t *)"123456";
84     src.size = NUM6;
85     int32_t status = hks_hash(alg, &src, &hash);
86     TEST_ASSERT_EQUAL_INT(0, status);
87 
88     struct hks_key_param keyParam = { 0 };
89     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
90     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
91     keyParam.key_mode = HKS_ALG_GCM;
92     keyParam.key_len = NUM32;
93     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
94     keyParam.key_auth_id.data = (uint8_t *)testFileName;
95     keyParam.key_auth_id.size = sizeof(testFileName);
96 
97     (void)TestSecShuksGenerateKeyNormal();
98     struct hks_blob signature = { 0 };
99     HksStBlobInit1(&signature, 1, NUM64, 0);
100     statusAsymmetricSign = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature);
101     TEST_ASSERT_EQUAL_INT(0, statusAsymmetricSign);
102 
103     statusAsymmetricVerify = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
104     TEST_ASSERT_EQUAL_INT(0, statusAsymmetricVerify);
105 
106     HksBlobDestroyT1(&signature);
107     (void)TestSecShuksDeleteKeyNormal();
108 };
109 
110 /*
111  * @tc.number    : SUB_SEC_DataPro_HuksL0_0210
112  * @tc.name      : Asymmetric Sign, abnormal input parameters keyAlias is null
113  * @tc.desc      : [C- SECURITY -1900]
114  */
115 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0210, Function | MediumTest | Level2)
116 {
117     int32_t status;
118     unsigned char testFileName[] = "test_ed25519_6";
119     struct hks_blob *keyAlias = NULL;
120 
121     uint8_t hash1[NUM32], sig[NUM64];
122 
123     struct hks_blob hash;
124     hash.data = (uint8_t *)hash1;
125     hash.size = sizeof(hash1);
126 
127     struct hks_blob signature;
128     signature.data = sig;
129     signature.size = sizeof(sig);
130 
131     struct hks_key_param keyParam = { 0 };
132     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
133     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
134     keyParam.key_mode = HKS_ALG_GCM;
135     keyParam.key_len = NUM32;
136     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
137     keyParam.key_auth_id.data = (uint8_t *)testFileName;
138     keyParam.key_auth_id.size = sizeof(testFileName);
139 
140 
141     status = hks_asymmetric_sign(keyAlias, &keyParam, &hash, &signature);
142     TEST_ASSERT_EQUAL_INT(NUM1000, status);
143 }
144 
145 /*
146  * @tc.number    : SUB_SEC_DataPro_HuksL0_0220
147  * @tc.name      : Asymmetric Sign, abnormal input parameters keyAlias.data is null
148  * @tc.desc      : [C- SECURITY -1900]
149  */
150 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0220, Function | MediumTest | Level2)
151 {
152     int32_t status;
153     unsigned char testFileName[] = "test_ed25519_6";
154     struct hks_blob keyAlias;
155     keyAlias.data = NULL;
156     keyAlias.size = sizeof(testFileName);
157     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
158 
159     uint8_t hash1[NUM32], sig[NUM64];
160 
161     struct hks_blob hash;
162     hash.data = (uint8_t *)hash1;
163     hash.size = sizeof(hash1);
164 
165     struct hks_blob signature;
166     signature.data = sig;
167     signature.size = sizeof(sig);
168 
169     struct hks_key_param keyParam = { 0 };
170     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
171     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
172     keyParam.key_mode = HKS_ALG_GCM;
173     keyParam.key_len = NUM32;
174     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
175     keyParam.key_auth_id.data = (uint8_t *)testFileName;
176     keyParam.key_auth_id.size = sizeof(testFileName);
177 
178     status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature);
179     TEST_ASSERT_EQUAL_INT(NUM135, status);
180 }
181 
182 /*
183  * @tc.number    : SUB_SEC_DataPro_HuksL0_0230
184  * @tc.name      : Asymmetric Sign, abnormal input parameters keyAlias.size is 0
185  * @tc.desc      : [C- SECURITY -1900]
186  */
187 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0230, Function | MediumTest | Level2)
188 {
189     int32_t status;
190     unsigned char testFileName[] = "test_ed25519_6";
191     struct hks_blob keyAlias;
192     keyAlias.data = (uint8_t *)testFileName;
193     keyAlias.size = 0;
194     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
195 
196     uint8_t hash1[NUM32], sig[NUM64];
197 
198     struct hks_blob hash;
199     hash.data = (uint8_t *)hash1;
200     hash.size = sizeof(hash1);
201 
202     struct hks_blob signature;
203     signature.data = sig;
204     signature.size = sizeof(sig);
205 
206     struct hks_key_param keyParam = { 0 };
207     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
208     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
209     keyParam.key_mode = HKS_ALG_GCM;
210     keyParam.key_len = NUM32;
211     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
212     keyParam.key_auth_id.data = (uint8_t *)testFileName;
213     keyParam.key_auth_id.size = sizeof(testFileName);
214 
215     status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature);
216     TEST_ASSERT_EQUAL_INT(NUM135, status);
217 }
218 
219 /*
220  * @tc.number    : SUB_SEC_DataPro_HuksL0_0240
221  * @tc.name      : Asymmetric Sign, abnormal input parameters keyAlias.size is more than 64
222  * @tc.desc      : [C- SECURITY -1900]
223  */
224 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0240, Function | MediumTest | Level2)
225 {
226     int32_t status;
227     unsigned char testFileName[] = "test_ed25519_6";
228     struct hks_blob keyAlias;
229     keyAlias.data = (uint8_t *)testFileName;
230     keyAlias.size = NUM65;
231     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
232 
233     uint8_t hash1[NUM32], sig[NUM64];
234 
235     struct hks_blob hash;
236     hash.data = (uint8_t *)hash1;
237     hash.size = sizeof(hash1);
238 
239     struct hks_blob signature;
240     signature.data = sig;
241     signature.size = sizeof(sig);
242 
243     struct hks_key_param keyParam = { 0 };
244     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
245     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
246     keyParam.key_mode = HKS_ALG_GCM;
247     keyParam.key_len = NUM32;
248     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
249     keyParam.key_auth_id.data = (uint8_t *)testFileName;
250     keyParam.key_auth_id.size = sizeof(testFileName);
251 
252     status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature);
253     TEST_ASSERT_EQUAL_INT(NUM135, status);
254 }
255 
256 /*
257  * @tc.number    : SUB_SEC_DataPro_HuksL0_0250
258  * @tc.name      : Asymmetric Sign, abnormal input parameters keyAlias.type is not equal to HKS_BLOB_TYPE_ALIAS
259  * @tc.desc      : [C- SECURITY -1900]
260  */
261 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0250, Function | MediumTest | Level2)
262 {
263     int32_t status;
264     unsigned char testFileName[] = "test_ed25519_6";
265     struct hks_blob keyAlias;
266     keyAlias.data = (uint8_t *)testFileName;
267     keyAlias.size = sizeof(testFileName);
268     keyAlias.type = 0;
269 
270     uint8_t hash1[NUM32], sig[NUM64];
271 
272     struct hks_blob hash;
273     hash.data = (uint8_t *)hash1;
274     hash.size = sizeof(hash1);
275 
276     struct hks_blob signature;
277     signature.data = sig;
278     signature.size = sizeof(sig);
279 
280     struct hks_key_param keyParam = { 0 };
281     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
282     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
283     keyParam.key_mode = HKS_ALG_GCM;
284     keyParam.key_len = NUM32;
285     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
286     keyParam.key_auth_id.data = (uint8_t *)testFileName;
287     keyParam.key_auth_id.size = sizeof(testFileName);
288 
289     status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature);
290     TEST_ASSERT_EQUAL_INT(NUM135, status);
291 }
292 
293 /*
294  * @tc.number    : SUB_SEC_DataPro_HuksL0_0260
295  * @tc.name      : Asymmetric Sign, abnormal input parameters keyParam is null
296  * @tc.desc      : [C- SECURITY -1900]
297  */
298 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0260, Function | MediumTest | Level2)
299 {
300     int32_t status;
301     unsigned char testFileName[] = "test_ed25519_6";
302     struct hks_blob keyAlias;
303     keyAlias.data = (uint8_t *)testFileName;
304     keyAlias.size = sizeof(testFileName);
305     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
306 
307     uint8_t hash1[NUM32], sig[NUM64];
308 
309     struct hks_blob hash;
310     hash.data = (uint8_t *)hash1;
311     hash.size = sizeof(hash1);
312 
313     struct hks_blob signature;
314     signature.data = sig;
315     signature.size = sizeof(sig);
316 
317     struct hks_key_param *keyParam = NULL;
318 
319     status = hks_asymmetric_sign(&keyAlias, keyParam, &hash, &signature);
320     TEST_ASSERT_EQUAL_INT(NUM1000, status);
321 }
322 
323 /*
324  * @tc.number    : SUB_SEC_DataPro_HuksL0_0270
325  * @tc.name      : Asymmetric Sign, abnormal input parameters keyParam.key_usage
326                    is not equal to HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY
327  * @tc.desc      : [C- SECURITY -1900]
328  */
329 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0270, Function | MediumTest | Level2)
330 {
331     int32_t status;
332     unsigned char testFileName[] = "test_ed25519_6";
333     struct hks_blob keyAlias;
334     keyAlias.data = (uint8_t *)testFileName;
335     keyAlias.size = sizeof(testFileName);
336     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
337 
338     uint8_t hash1[NUM32], sig[NUM64];
339 
340     struct hks_blob hash;
341     hash.data = (uint8_t *)hash1;
342     hash.size = sizeof(hash1);
343 
344     struct hks_blob signature;
345     signature.data = sig;
346     signature.size = sizeof(sig);
347 
348     struct hks_key_param keyParam = { 0 };
349     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
350     keyParam.key_usage = 0;
351     keyParam.key_mode = HKS_ALG_GCM;
352     keyParam.key_len = NUM32;
353     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
354     keyParam.key_auth_id.data = (uint8_t *)testFileName;
355     keyParam.key_auth_id.size = sizeof(testFileName);
356 
357 
358     status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature);
359     TEST_ASSERT_EQUAL_INT(NUM134, status);
360 }
361 
362 /*
363  * @tc.number    : SUB_SEC_DataPro_HuksL0_0280
364  * @tc.name      : Asymmetric Sign, abnormal input parameters keyParam.type
365                    is not equal to HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519
366  * @tc.desc      : [C- SECURITY -1900]
367  */
368 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0280, Function | MediumTest | Level2)
369 {
370     int32_t status;
371     unsigned char testFileName[] = "test_ed25519_6";
372     struct hks_blob keyAlias;
373     keyAlias.data = (uint8_t *)testFileName;
374     keyAlias.size = sizeof(testFileName);
375     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
376 
377     uint8_t hash1[NUM32], sig[NUM64];
378 
379     struct hks_blob hash;
380     hash.data = (uint8_t *)hash1;
381     hash.size = sizeof(hash1);
382 
383     struct hks_blob signature;
384     signature.data = sig;
385     signature.size = sizeof(sig);
386 
387     struct hks_key_param keyParam = { 0 };
388     keyParam.key_type = 0;
389     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
390     keyParam.key_mode = HKS_ALG_GCM;
391     keyParam.key_len = NUM32;
392     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
393     keyParam.key_auth_id.data = (uint8_t *)testFileName;
394     keyParam.key_auth_id.size = sizeof(testFileName);
395 
396     status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature);
397     TEST_ASSERT_EQUAL_INT(NUM134, status);
398 }
399 
400 /*
401  * @tc.number    : SUB_SEC_DataPro_HuksL0_0290
402  * @tc.name      : Asymmetric Sign, abnormal input parameters hash is null
403  * @tc.desc      : [C- SECURITY -1900]
404  */
405 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0290, Function | MediumTest | Level2)
406 {
407     int32_t status;
408     unsigned char testFileName[] = "test_ed25519_6";
409     struct hks_blob keyAlias;
410     keyAlias.data = (uint8_t *)testFileName;
411     keyAlias.size = sizeof(testFileName);
412     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
413 
414     uint8_t sig[NUM64];
415 
416     struct hks_blob *hash = NULL;
417 
418     struct hks_blob signature;
419     signature.data = sig;
420     signature.size = sizeof(sig);
421 
422     struct hks_key_param keyParam = { 0 };
423     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
424     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
425     keyParam.key_mode = HKS_ALG_GCM;
426     keyParam.key_len = NUM32;
427     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
428     keyParam.key_auth_id.data = (uint8_t *)testFileName;
429     keyParam.key_auth_id.size = sizeof(testFileName);
430 
431     status = hks_asymmetric_sign(&keyAlias, &keyParam, hash, &signature);
432     TEST_ASSERT_EQUAL_INT(NUM1000, status);
433 }
434 
435 /*
436  * @tc.number    : SUB_SEC_DataPro_HuksL0_0300
437  * @tc.name      : Asymmetric Sign, abnormal input parameters hash.data is null
438  * @tc.desc      : [C- SECURITY -1900]
439  */
440 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0300, Function | MediumTest | Level2)
441 {
442     int32_t status;
443     unsigned char testFileName[] = "test_ed25519_6";
444     struct hks_blob keyAlias;
445     keyAlias.data = (uint8_t *)testFileName;
446     keyAlias.size = sizeof(testFileName);
447     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
448 
449     uint8_t hash1[NUM32], sig[NUM64];
450 
451     struct hks_blob hash;
452     hash.data = NULL;
453     hash.size = sizeof(hash1);
454 
455     struct hks_blob signature;
456     signature.data = sig;
457     signature.size = sizeof(sig);
458 
459     struct hks_key_param keyParam = { 0 };
460     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
461     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
462     keyParam.key_mode = HKS_ALG_GCM;
463     keyParam.key_len = NUM32;
464     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
465     keyParam.key_auth_id.data = (uint8_t *)testFileName;
466     keyParam.key_auth_id.size = sizeof(testFileName);
467 
468     status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature);
469     TEST_ASSERT_EQUAL_INT(NUM135, status);
470 }
471 
472 /*
473  * @tc.number    : SUB_SEC_DataPro_HuksL0_0310
474  * @tc.name      : Asymmetric Sign, abnormal input parameters hash.size is 0
475  * @tc.desc      : [C- SECURITY -1900]
476  */
477 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0310, Function | MediumTest | Level2)
478 {
479     int32_t status;
480     unsigned char testFileName[] = "test_ed25519_6";
481     struct hks_blob keyAlias;
482     keyAlias.data = (uint8_t *)testFileName;
483     keyAlias.size = sizeof(testFileName);
484     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
485 
486     uint8_t hash1[NUM32], sig[NUM64];
487 
488     struct hks_blob hash;
489     hash.data = (uint8_t *)hash1;
490     hash.size = 0;
491 
492     struct hks_blob signature;
493     signature.data = sig;
494     signature.size = sizeof(sig);
495 
496     struct hks_key_param keyParam = { 0 };
497     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
498     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
499     keyParam.key_mode = HKS_ALG_GCM;
500     keyParam.key_len = NUM32;
501     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
502     keyParam.key_auth_id.data = (uint8_t *)testFileName;
503     keyParam.key_auth_id.size = sizeof(testFileName);
504 
505     status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature);
506     TEST_ASSERT_EQUAL_INT(NUM135, status);
507 }
508 
509 /*
510  * @tc.number    : SUB_SEC_DataPro_HuksL0_0320
511  * @tc.name      : Asymmetric Sign, abnormal input parameters signature is null
512  * @tc.desc      : [C- SECURITY -1900]
513  */
514 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0320, Function | MediumTest | Level2)
515 {
516     int32_t status;
517     unsigned char testFileName[] = "test_ed25519_6";
518     struct hks_blob keyAlias;
519     keyAlias.data = (uint8_t *)testFileName;
520     keyAlias.size = sizeof(testFileName);
521     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
522 
523     uint8_t hash1[NUM32];
524 
525     struct hks_blob hash;
526     hash.data = (uint8_t *)hash1;
527     hash.size = sizeof(hash1);
528 
529     struct hks_blob *signature = NULL;
530 
531     struct hks_key_param keyParam = { 0 };
532     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
533     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
534     keyParam.key_mode = HKS_ALG_GCM;
535     keyParam.key_len = NUM32;
536     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
537     keyParam.key_auth_id.data = (uint8_t *)testFileName;
538     keyParam.key_auth_id.size = sizeof(testFileName);
539 
540 
541     status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, signature);
542     TEST_ASSERT_EQUAL_INT(NUM1000, status);
543 }
544 
545 /*
546  * @tc.number    : SUB_SEC_DataPro_HuksL0_0330
547  * @tc.name      : Asymmetric Sign, abnormal input parameters signature.data is null
548  * @tc.desc      : [C- SECURITY -1900]
549  */
550 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0330, Function | MediumTest | Level2)
551 {
552     int32_t status;
553     unsigned char testFileName[] = "test_ed25519_6";
554     struct hks_blob keyAlias;
555     keyAlias.data = (uint8_t *)testFileName;
556     keyAlias.size = sizeof(testFileName);
557     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
558 
559     uint8_t hash1[NUM32], sig[NUM64];
560 
561     struct hks_blob hash;
562     hash.data = (uint8_t *)hash1;
563     hash.size = sizeof(hash1);
564 
565     struct hks_blob signature;
566     signature.data = NULL;
567     signature.size = sizeof(sig);
568 
569     struct hks_key_param keyParam = { 0 };
570     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
571     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
572     keyParam.key_mode = HKS_ALG_GCM;
573     keyParam.key_len = NUM32;
574     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
575     keyParam.key_auth_id.data = (uint8_t *)testFileName;
576     keyParam.key_auth_id.size = sizeof(testFileName);
577 
578     status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature);
579     TEST_ASSERT_EQUAL_INT(NUM138, status);
580 }
581 
582 /*
583  * @tc.number    : SUB_SEC_DataPro_HuksL0_0340
584  * @tc.name      : Asymmetric Sign, abnormal input parameters signature.size is less than 64
585  * @tc.desc      : [C- SECURITY -1900]
586  */
587 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0340, Function | MediumTest | Level2)
588 {
589     int32_t status;
590     unsigned char testFileName[] = "test_ed25519_6";
591     struct hks_blob keyAlias;
592     keyAlias.data = (uint8_t *)testFileName;
593     keyAlias.size = sizeof(testFileName);
594     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
595 
596     uint8_t hash1[NUM32], sig[NUM64];
597 
598     struct hks_blob hash;
599     hash.data = (uint8_t *)hash1;
600     hash.size = sizeof(hash1);
601 
602     struct hks_blob signature;
603     signature.data = sig;
604     signature.size = NUM63;
605 
606     struct hks_key_param keyParam = { 0 };
607     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
608     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
609     keyParam.key_mode = HKS_ALG_GCM;
610     keyParam.key_len = NUM32;
611     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
612     keyParam.key_auth_id.data = (uint8_t *)testFileName;
613     keyParam.key_auth_id.size = sizeof(testFileName);
614 
615     status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature);
616     TEST_ASSERT_EQUAL_INT(NUM138, status);
617 }
618 
619 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Sign key
620 // end+++++++++++++++++++++++++++++++++++++++++++++++++++++++++0200-0340
621 
622 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Verify key
623 // begin+++++++++++++++++++++++++++++++++++++++++++++++++++++0350-0510
624 
625 /*
626  * @tc.number    : SUB_SEC_DataPro_HuksL0_0350
627  * @tc.name      : Asymmetric Verify, normal input parameters keyAlias, keyParam, hash, signature
628  * @tc.desc      : [C- SECURITY -1900]
629  */
630 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0350, Function | MediumTest | Level2)
631 {
632     int32_t statusAsymmetricSign;
633     int32_t statusAsymmetricVerify;
634 
635     unsigned char testFileName[] = "keyalias1";
636     struct hks_blob keyAlias = { 0 };
637 
638     keyAlias.data = (uint8_t *)testFileName;
639     keyAlias.size = sizeof(testFileName);
640     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
641 
642     uint8_t hash1[NUM32];
643     struct hks_blob hash;
644     hash.data = (uint8_t *)hash1;
645     hash.size = sizeof(hash1);
646 
647     uint32_t alg = HKS_ALG_HASH_SHA_256;
648     struct hks_blob src;
649     src.data = (uint8_t *)"123456";
650     src.size = NUM6;
651     int32_t status = hks_hash(alg, &src, &hash);
652     TEST_ASSERT_EQUAL_INT(0, status);
653 
654     struct hks_key_param keyParam = { 0 };
655     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
656     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
657     keyParam.key_mode = HKS_ALG_GCM;
658     keyParam.key_len = NUM32;
659     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
660     keyParam.key_auth_id.data = (uint8_t *)testFileName;
661     keyParam.key_auth_id.size = sizeof(testFileName);
662 
663     struct hks_key_param keyParam2 = { 0 };
664     keyParam2.key_type = HKS_KEY_TYPE_EDDSA_PUBLIC_KEY_ED25519;
665     keyParam2.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
666     keyParam2.key_mode = HKS_ALG_GCM;
667     keyParam2.key_len = NUM32;
668     keyParam2.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
669     keyParam2.key_auth_id.data = (uint8_t *)testFileName;
670     keyParam2.key_auth_id.size = sizeof(testFileName);
671 
672     (void)TestSecShuksGenerateKeyNormal();
673     struct hks_blob pubKey = { 0 };
674     HksStBlobInit1(&pubKey, 1, NUM32, HKS_BLOB_TYPE_KEY);
675 
676     (void)TestSecShuksExportPublicNormal(&keyAlias, &pubKey);
677     struct hks_blob signature = { 0 };
678     HksStBlobInit1(&signature, 1, NUM64, 0);
679     statusAsymmetricSign = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature);
680     TEST_ASSERT_EQUAL_INT(0, statusAsymmetricSign);
681 
682     statusAsymmetricVerify = hks_asymmetric_verify(&pubKey, &keyParam2, &hash, &signature);
683     TEST_ASSERT_EQUAL_INT(0, statusAsymmetricVerify);
684 
685     HksBlobDestroyT1(&signature);
686     (void)TestSecShuksDeleteKeyNormal();
687     HksBlobDestroyT1(&pubKey);
688 };
689 
690 /*
691  * @tc.number    : SUB_SEC_DataPro_HuksL0_0360
692  * @tc.name      : Asymmetric Verify, abnormal input parameters keyAlias is null
693  * @tc.desc      : [C- SECURITY -1900]
694  */
695 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0360, Function | MediumTest | Level2)
696 {
697     int32_t status;
698     unsigned char testFileName[NUM32];
699     struct hks_blob *keyAlias = NULL;
700 
701     uint8_t hash1[NUM32], sig[NUM64];
702 
703     struct hks_blob hash;
704     hash.data = (uint8_t *)hash1;
705     hash.size = sizeof(hash1);
706 
707     struct hks_blob signature;
708     signature.data = sig;
709     signature.size = sizeof(sig);
710 
711     struct hks_key_param keyParam = { 0 };
712     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
713     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
714     keyParam.key_mode = HKS_ALG_GCM;
715     keyParam.key_len = NUM32;
716     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
717     keyParam.key_auth_id.data = (uint8_t *)testFileName;
718     keyParam.key_auth_id.size = sizeof(testFileName);
719 
720     status = hks_asymmetric_verify(keyAlias, &keyParam, &hash, &signature);
721     TEST_ASSERT_EQUAL_INT(NUM1000, status);
722 }
723 
724 /*
725  * @tc.number    : SUB_SEC_DataPro_HuksL0_0370
726  * @tc.name      : Asymmetric Verify, abnormal input parameters keyAlias.type
727                    is HKS_BLOB_TYPE_ALIAS and keyAlias.data is null
728  * @tc.desc      : [C- SECURITY -1900]
729  */
730 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0370, Function | MediumTest | Level2)
731 {
732     int32_t status;
733     unsigned char testFileName[NUM32];
734     struct hks_blob keyAlias;
735     keyAlias.data = NULL;
736     keyAlias.size = sizeof(testFileName);
737     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
738 
739     uint8_t hash1[NUM32], sig[NUM64];
740 
741     struct hks_blob hash;
742     hash.data = (uint8_t *)hash1;
743     hash.size = sizeof(hash1);
744 
745     struct hks_blob signature;
746     signature.data = sig;
747     signature.size = sizeof(sig);
748 
749     struct hks_key_param keyParam = { 0 };
750     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
751     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
752     keyParam.key_mode = HKS_ALG_GCM;
753     keyParam.key_len = NUM32;
754     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
755     keyParam.key_auth_id.data = (uint8_t *)testFileName;
756     keyParam.key_auth_id.size = sizeof(testFileName);
757 
758     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
759     TEST_ASSERT_EQUAL_INT(NUM135, status);
760 }
761 
762 /*
763  * @tc.number    : SUB_SEC_DataPro_HuksL0_0380
764  * @tc.name      : Asymmetric Verify, abnormal input parameters keyAlias.size is 0
765  * @tc.desc      : [C- SECURITY -1900]
766  */
767 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0380, Function | MediumTest | Level2)
768 {
769     int32_t status;
770     unsigned char testFileName[NUM32];
771     struct hks_blob keyAlias;
772     keyAlias.data = (uint8_t *)testFileName;
773     keyAlias.size = 0;
774     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
775 
776     uint8_t hash1[NUM32], sig[NUM64];
777 
778     struct hks_blob hash;
779     hash.data = (uint8_t *)hash1;
780     hash.size = sizeof(hash1);
781 
782     struct hks_blob signature;
783     signature.data = sig;
784     signature.size = sizeof(sig);
785 
786     struct hks_key_param keyParam = { 0 };
787     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
788     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
789     keyParam.key_mode = HKS_ALG_GCM;
790     keyParam.key_len = NUM32;
791     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
792     keyParam.key_auth_id.data = (uint8_t *)testFileName;
793     keyParam.key_auth_id.size = sizeof(testFileName);
794 
795     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
796     TEST_ASSERT_EQUAL_INT(NUM135, status);
797 }
798 
799 /*
800  * @tc.number    : SUB_SEC_DataPro_HuksL0_0390
801  * @tc.name      : Asymmetric Verify, abnormal input parameters keyAlias.size is more than 64
802  * @tc.desc      : [C- SECURITY -1900]
803  */
804 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0390, Function | MediumTest | Level2)
805 {
806     int32_t status;
807     unsigned char testFileName[NUM32];
808     struct hks_blob keyAlias;
809     keyAlias.data = (uint8_t *)testFileName;
810     keyAlias.size = NUM65;
811     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
812 
813     uint8_t hash1[NUM32], sig[NUM64];
814 
815     struct hks_blob hash;
816     hash.data = (uint8_t *)hash1;
817     hash.size = sizeof(hash1);
818 
819     struct hks_blob signature;
820     signature.data = sig;
821     signature.size = sizeof(sig);
822 
823     struct hks_key_param keyParam = { 0 };
824     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
825     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
826     keyParam.key_mode = HKS_ALG_GCM;
827     keyParam.key_len = NUM32;
828     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
829     keyParam.key_auth_id.data = (uint8_t *)testFileName;
830     keyParam.key_auth_id.size = sizeof(testFileName);
831 
832     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
833     TEST_ASSERT_EQUAL_INT(NUM135, status);
834 }
835 
836 /*
837  * @tc.number    : SUB_SEC_DataPro_HuksL0_0400
838  * @tc.name      : Asymmetric Verify, abnormal input parameters keyAlias.type
839                    is HKS_BLOB_TYPE_KEY and keyAlias.data is null
840  * @tc.desc      : [C- SECURITY -1900]
841  */
842 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0400, Function | MediumTest | Level2)
843 {
844     int32_t status;
845     unsigned char testFileName[NUM32];
846     struct hks_blob keyAlias;
847     keyAlias.data = NULL;
848     keyAlias.size = sizeof(testFileName);
849     keyAlias.type = HKS_BLOB_TYPE_KEY;
850 
851     uint8_t hash1[NUM32], sig[NUM64];
852 
853     struct hks_blob hash;
854     hash.data = (uint8_t *)hash1;
855     hash.size = sizeof(hash1);
856 
857     struct hks_blob signature;
858     signature.data = sig;
859     signature.size = sizeof(sig);
860 
861     struct hks_key_param keyParam = { 0 };
862     keyParam.key_type = HKS_KEY_TYPE_EDDSA_PUBLIC_KEY_ED25519;
863     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
864     keyParam.key_mode = HKS_ALG_GCM;
865     keyParam.key_len = NUM32;
866     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
867     keyParam.key_auth_id.data = (uint8_t *)testFileName;
868     keyParam.key_auth_id.size = sizeof(testFileName);
869 
870     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
871     TEST_ASSERT_EQUAL_INT(NUM1006, status);
872 }
873 
874 /*
875  * @tc.number    : SUB_SEC_DataPro_HuksL0_0410
876  * @tc.name      : Asymmetric Verify, abnormal input parameters keyAlias.size is not equal to 32
877  * @tc.desc      : [C- SECURITY -1900]
878  */
879 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0410, Function | MediumTest | Level2)
880 {
881     int32_t status;
882     unsigned char testFileName[NUM32];
883     struct hks_blob keyAlias;
884     keyAlias.data = (uint8_t *)testFileName;
885     keyAlias.size = NUM25;
886     keyAlias.type = HKS_BLOB_TYPE_KEY;
887 
888     uint8_t hash1[NUM32], sig[NUM64];
889 
890     struct hks_blob hash;
891     hash.data = (uint8_t *)hash1;
892     hash.size = sizeof(hash1);
893 
894     struct hks_blob signature;
895     signature.data = sig;
896     signature.size = sizeof(sig);
897 
898     struct hks_key_param keyParam = { 0 };
899     keyParam.key_type = HKS_KEY_TYPE_EDDSA_PUBLIC_KEY_ED25519;
900     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
901     keyParam.key_mode = HKS_ALG_GCM;
902     keyParam.key_len = NUM32;
903     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
904     keyParam.key_auth_id.data = (uint8_t *)testFileName;
905     keyParam.key_auth_id.size = sizeof(testFileName);
906 
907     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
908     TEST_ASSERT_EQUAL_INT(NUM1006, status);
909 }
910 
911 /*
912  * @tc.number    : SUB_SEC_DataPro_HuksL0_0420
913  * @tc.name      : Asymmetric Verify, abnormal input parameters keyAlias.type is not equal to HKS_BLOB_TYPE_KEY
914  * @tc.desc      : [C- SECURITY -1900]
915  */
916 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0420, Function | MediumTest | Level2)
917 {
918     int32_t status;
919     unsigned char testFileName[NUM32];
920     struct hks_blob keyAlias;
921     keyAlias.data = (uint8_t *)testFileName;
922     keyAlias.size = sizeof(testFileName);
923     keyAlias.type = 0;
924 
925     uint8_t hash1[NUM32], sig[NUM64];
926 
927     struct hks_blob hash;
928     hash.data = (uint8_t *)hash1;
929     hash.size = sizeof(hash1);
930 
931     struct hks_blob signature;
932     signature.data = sig;
933     signature.size = sizeof(sig);
934 
935     struct hks_key_param keyParam = { 0 };
936     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
937     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
938     keyParam.key_mode = HKS_ALG_GCM;
939     keyParam.key_len = NUM32;
940     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
941     keyParam.key_auth_id.data = (uint8_t *)testFileName;
942     keyParam.key_auth_id.size = sizeof(testFileName);
943 
944     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
945     TEST_ASSERT_EQUAL_INT(NUM1006, status);
946 }
947 
948 /*
949  * @tc.number    : SUB_SEC_DataPro_HuksL0_0430
950  * @tc.name      : Asymmetric Verify, abnormal input parameters keyParam is null
951  * @tc.desc      : [C- SECURITY -1900]
952  */
953 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0430, Function | MediumTest | Level2)
954 {
955     int32_t status;
956     unsigned char testFileName[NUM32];
957     struct hks_blob keyAlias;
958     keyAlias.data = (uint8_t *)testFileName;
959     keyAlias.size = sizeof(testFileName);
960     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
961 
962     uint8_t hash1[NUM32], sig[NUM64];
963 
964     struct hks_blob hash;
965     hash.data = (uint8_t *)hash1;
966     hash.size = sizeof(hash1);
967 
968     struct hks_blob signature;
969     signature.data = sig;
970     signature.size = sizeof(sig);
971 
972     struct hks_key_param *keyParam = NULL;
973 
974     status = hks_asymmetric_verify(&keyAlias, keyParam, &hash, &signature);
975     TEST_ASSERT_EQUAL_INT(NUM1000, status);
976 }
977 
978 /*
979  * @tc.number    : SUB_SEC_DataPro_HuksL0_0440
980  * @tc.name      : Asymmetric Verify, abnormal input parameters keyParam.key_usage
981                    is not equal to HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY
982  * @tc.desc      : [C- SECURITY -1900]
983  */
984 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0440, Function | MediumTest | Level2)
985 {
986     int32_t status;
987     unsigned char testFileName[NUM32];
988     struct hks_blob keyAlias;
989     keyAlias.data = (uint8_t *)testFileName;
990     keyAlias.size = sizeof(testFileName);
991     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
992 
993     uint8_t hash1[NUM32], sig[NUM64];
994 
995     struct hks_blob hash;
996     hash.data = (uint8_t *)hash1;
997     hash.size = sizeof(hash1);
998 
999     struct hks_blob signature;
1000     signature.data = sig;
1001     signature.size = sizeof(sig);
1002 
1003     struct hks_key_param keyParam = { 0 };
1004     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
1005     keyParam.key_usage = 0; // = 0
1006     keyParam.key_mode = HKS_ALG_GCM;
1007     keyParam.key_len = NUM32;
1008     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1009     keyParam.key_auth_id.data = (uint8_t *)testFileName;
1010     keyParam.key_auth_id.size = sizeof(testFileName);
1011 
1012     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
1013     TEST_ASSERT_EQUAL_INT(NUM134, status);
1014 }
1015 
1016 /*
1017  * @tc.number    : SUB_SEC_DataPro_HuksL0_0450
1018  * @tc.name      : Asymmetric Verify, abnormal input parameters keyParam.key_type is not equal to HKS_ALG_GCM
1019  * @tc.desc      : [C- SECURITY -1900]
1020  */
1021 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0450, Function | MediumTest | Level2)
1022 {
1023     int32_t status;
1024     unsigned char testFileName[NUM32];
1025     struct hks_blob keyAlias;
1026     keyAlias.data = (uint8_t *)testFileName;
1027     keyAlias.size = sizeof(testFileName);
1028     keyAlias.type = HKS_BLOB_TYPE_KEY;
1029 
1030     uint8_t hash1[NUM32], sig[NUM64];
1031 
1032     struct hks_blob hash;
1033     hash.data = (uint8_t *)hash1;
1034     hash.size = sizeof(hash1);
1035 
1036     struct hks_blob signature;
1037     signature.data = sig;
1038     signature.size = sizeof(sig);
1039 
1040     struct hks_key_param keyParam = { 0 };
1041     keyParam.key_type = 0;
1042     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
1043     keyParam.key_mode = HKS_ALG_GCM;
1044     keyParam.key_len = NUM32;
1045     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1046     keyParam.key_auth_id.data = (uint8_t *)testFileName;
1047     keyParam.key_auth_id.size = sizeof(testFileName);
1048 
1049     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
1050     TEST_ASSERT_EQUAL_INT(NUM134, status);
1051 }
1052 
1053 /*
1054  * @tc.number    : SUB_SEC_DataPro_HuksL0_0460
1055  * @tc.name      : Asymmetric Verify, abnormal input parameters hash is null
1056  * @tc.desc      : [C- SECURITY -1900]
1057  */
1058 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0460, Function | MediumTest | Level2)
1059 {
1060     int32_t status;
1061     unsigned char testFileName[NUM32];
1062     struct hks_blob keyAlias;
1063     keyAlias.data = (uint8_t *)testFileName;
1064     keyAlias.size = sizeof(testFileName);
1065     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
1066 
1067     uint8_t sig[NUM64];
1068 
1069     struct hks_blob *hash = NULL;
1070 
1071     struct hks_blob signature;
1072     signature.data = sig;
1073     signature.size = sizeof(sig);
1074 
1075     struct hks_key_param keyParam = { 0 };
1076     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
1077     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
1078     keyParam.key_mode = HKS_ALG_GCM;
1079     keyParam.key_len = NUM32;
1080     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1081     keyParam.key_auth_id.data = (uint8_t *)testFileName;
1082     keyParam.key_auth_id.size = sizeof(testFileName);
1083 
1084     status = hks_asymmetric_verify(&keyAlias, &keyParam, hash, &signature);
1085     TEST_ASSERT_EQUAL_INT(NUM1000, status);
1086 }
1087 
1088 /*
1089  * @tc.number    : SUB_SEC_DataPro_HuksL0_0470
1090  * @tc.name      : Asymmetric Verify, abnormal input parameters hash.data is null
1091  * @tc.desc      : [C- SECURITY -1900]
1092  */
1093 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0470, Function | MediumTest | Level2)
1094 {
1095     int32_t status;
1096     unsigned char testFileName[NUM32];
1097     struct hks_blob keyAlias;
1098     keyAlias.data = (uint8_t *)testFileName;
1099     keyAlias.size = sizeof(testFileName);
1100     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
1101 
1102     uint8_t hash1[NUM32], sig[NUM64];
1103 
1104     struct hks_blob hash;
1105     hash.data = NULL;
1106     hash.size = sizeof(hash1);
1107 
1108     struct hks_blob signature;
1109     signature.data = sig;
1110     signature.size = sizeof(sig);
1111 
1112     struct hks_key_param keyParam = { 0 };
1113     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
1114     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
1115     keyParam.key_mode = HKS_ALG_GCM;
1116     keyParam.key_len = NUM32;
1117     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1118     keyParam.key_auth_id.data = (uint8_t *)testFileName;
1119     keyParam.key_auth_id.size = sizeof(testFileName);
1120 
1121     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
1122     TEST_ASSERT_EQUAL_INT(NUM135, status);
1123 }
1124 
1125 /*
1126  * @tc.number    : SUB_SEC_DataPro_HuksL0_0480
1127  * @tc.name      : Asymmetric Verify, abnormal input parameters hash.size is 0
1128  * @tc.desc      : [C- SECURITY -1900]
1129  */
1130 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0480, Function | MediumTest | Level2)
1131 {
1132     int32_t status;
1133     unsigned char testFileName[NUM32];
1134     struct hks_blob keyAlias;
1135     keyAlias.data = (uint8_t *)testFileName;
1136     keyAlias.size = sizeof(testFileName);
1137     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
1138 
1139     uint8_t hash1[NUM32], sig[NUM64];
1140 
1141     struct hks_blob hash;
1142     hash.data = (uint8_t *)hash1;
1143     hash.size = 0;
1144 
1145     struct hks_blob signature;
1146     signature.data = sig;
1147     signature.size = sizeof(sig);
1148 
1149     struct hks_key_param keyParam = { 0 };
1150     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
1151     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
1152     keyParam.key_mode = HKS_ALG_GCM;
1153     keyParam.key_len = NUM32;
1154     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1155     keyParam.key_auth_id.data = (uint8_t *)testFileName;
1156     keyParam.key_auth_id.size = sizeof(testFileName);
1157 
1158     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
1159     TEST_ASSERT_EQUAL_INT(NUM135, status);
1160 }
1161 
1162 /*
1163  * @tc.number    : SUB_SEC_DataPro_HuksL0_0490
1164  * @tc.name      : Asymmetric Verify, abnormal input parameters signature is null
1165  * @tc.desc      : [C- SECURITY -1900]
1166  */
1167 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0490, Function | MediumTest | Level2)
1168 {
1169     int32_t status;
1170     unsigned char testFileName[NUM32];
1171     struct hks_blob keyAlias;
1172     keyAlias.data = (uint8_t *)testFileName;
1173     keyAlias.size = sizeof(testFileName);
1174     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
1175 
1176     uint8_t hash1[NUM32];
1177 
1178     struct hks_blob hash;
1179     hash.data = (uint8_t *)hash1;
1180     hash.size = sizeof(hash1);
1181 
1182     struct hks_blob *signature = NULL;
1183 
1184     struct hks_key_param keyParam = { 0 };
1185     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
1186     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
1187     keyParam.key_mode = HKS_ALG_GCM;
1188     keyParam.key_len = NUM32;
1189     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1190     keyParam.key_auth_id.data = (uint8_t *)testFileName;
1191     keyParam.key_auth_id.size = sizeof(testFileName);
1192 
1193     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, signature);
1194     TEST_ASSERT_EQUAL_INT(NUM1000, status);
1195 }
1196 
1197 /*
1198  * @tc.number    : SUB_SEC_DataPro_HuksL0_0500
1199  * @tc.name      : Asymmetric Verify, abnormal input parameters signature.data is null
1200  * @tc.desc      : [C- SECURITY -1900]
1201  */
1202 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0500, Function | MediumTest | Level2)
1203 {
1204     int32_t status;
1205     unsigned char testFileName[NUM32];
1206     struct hks_blob keyAlias;
1207     keyAlias.data = (uint8_t *)testFileName;
1208     keyAlias.size = sizeof(testFileName);
1209     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
1210 
1211     uint8_t hash1[NUM32], sig[NUM64];
1212 
1213     struct hks_blob hash;
1214     hash.data = (uint8_t *)hash1;
1215     hash.size = sizeof(hash1);
1216 
1217     struct hks_blob signature;
1218     signature.data = NULL;
1219     signature.size = sizeof(sig);
1220 
1221     struct hks_key_param keyParam = { 0 };
1222     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
1223     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
1224     keyParam.key_mode = HKS_ALG_GCM;
1225     keyParam.key_len = NUM32;
1226     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1227     keyParam.key_auth_id.data = (uint8_t *)testFileName;
1228     keyParam.key_auth_id.size = sizeof(testFileName);
1229 
1230     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
1231     TEST_ASSERT_EQUAL_INT(NUM135, status);
1232 }
1233 
1234 /*
1235  * @tc.number    : SUB_SEC_DataPro_HuksL0_0510
1236  * @tc.name      : Asymmetric Verify, abnormal input parameters signature.size is less than 64
1237  * @tc.desc      : [C- SECURITY -1900]
1238  */
1239 LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0510, Function | MediumTest | Level2)
1240 {
1241     int32_t status;
1242     unsigned char testFileName[NUM32];
1243     struct hks_blob keyAlias;
1244     keyAlias.data = (uint8_t *)testFileName;
1245     keyAlias.size = sizeof(testFileName);
1246     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
1247 
1248     uint8_t hash1[NUM32], sig[NUM64];
1249 
1250     struct hks_blob hash;
1251     hash.data = (uint8_t *)hash1;
1252     hash.size = sizeof(hash1);
1253 
1254     struct hks_blob signature;
1255     signature.data = sig;
1256     signature.size = NUM63;
1257 
1258     struct hks_key_param keyParam = { 0 };
1259     keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519;
1260     keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY;
1261     keyParam.key_mode = HKS_ALG_GCM;
1262     keyParam.key_len = NUM32;
1263     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1264     keyParam.key_auth_id.data = (uint8_t *)testFileName;
1265     keyParam.key_auth_id.size = sizeof(testFileName);
1266 
1267     status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature);
1268     TEST_ASSERT_EQUAL_INT(NUM135, status);
1269 }
1270 #endif
1271 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Verify key
1272 // end+++++++++++++++++++++++++++++++++++++++++++++++++++++++0350-0510
1273 
1274 RUN_TEST_SUITE(SecurityDataHuksSignVerifyTestSuite);
1275