• 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 SecurityDataHuksDecTestSuite
29  */
30 LITE_TEST_SUIT(security, securityData, SecurityDataHuksDecTestSuite);
31 
32 /* *
33  * @tc.setup     : setup for all testcases
34  * @return       : setup result, TRUE is success, FALSE is fail
35  */
SecurityDataHuksDecTestSuiteSetUp(void)36 static BOOL SecurityDataHuksDecTestSuiteSetUp(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  */
SecurityDataHuksDecTestSuiteTearDown(void)51 static BOOL SecurityDataHuksDecTestSuiteTearDown(void)
52 {
53     printf("-++++++++++++++++++++++++++++++++++++++++++++-\n");
54     return TRUE;
55 }
56 
57 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Decrypt key
58 // begin++++++++++++++++++++++++++++++++++++++++++++++++++++0760-0990
59 
60 /*
61  * @tc.number    : SUB_SEC_DataPro_HuksL0_0760
62  * @tc.name      : Aead Decrypt, normal input parameters key, keyParam.ken_len is 128, cryptParam, plaintext, ciphertext
63  * @tc.desc      : [C- SECURITY -1400]
64  */
65 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0760, Function | MediumTest | Level1)
66 {
67     char alias[] = "test_hks_aead_encrypt";
68     int32_t statusEncrypt;
69     int32_t statusDecrypt;
70 
71     struct hks_blob key;
72     HksStBlobInit1(&key, 1, NUM16, HKS_BLOB_TYPE_KEY);
73     hks_generate_random(&key);
74 
75     struct hks_key_param keyParam;
76     keyParam.key_type = HKS_KEY_TYPE_AES;
77     keyParam.key_len = NUM128;
78     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
79     keyParam.key_mode = HKS_ALG_GCM;
80     keyParam.key_pad = HKS_PADDING_NONE;
81     keyParam.key_auth_id.data = (uint8_t *)alias;
82     keyParam.key_auth_id.size = sizeof(alias);
83     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
84 
85     struct hks_crypt_param cryptParam;
86     struct hks_blob nonce = {0};
87     HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV);
88     hks_generate_random(&nonce);
89 
90     struct hks_blob aad = {0};
91     HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD);
92     hks_generate_random(&aad);
93 
94     cryptParam.nonce = nonce;
95     cryptParam.aad = aad;
96 
97     struct hks_blob plaintext;
98     HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT);
99     hks_generate_random(&plaintext);
100 
101     struct hks_blob ciphertext;
102     HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT);
103     statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
104     TEST_ASSERT_EQUAL_INT(0, statusEncrypt);
105 
106     struct hks_blob decrypted;
107     HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT);
108     statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
109     TEST_ASSERT_EQUAL_INT(0, statusDecrypt);
110 
111     size_t k;
112     for (k = 0; k < decrypted.size; k++) {
113         TEST_ASSERT_EQUAL_INT(plaintext.data[k], decrypted.data[k]);
114     }
115     HksBlobDestroyT1(&key);
116     HksBlobDestroyT1(&nonce);
117     HksBlobDestroyT1(&aad);
118     HksBlobDestroyT1(&plaintext);
119     HksBlobDestroyT1(&ciphertext);
120     HksBlobDestroyT1(&decrypted);
121 };
122 
123 /*
124  * @tc.number    : SUB_SEC_DataPro_HuksL0_0770
125  * @tc.name      : Aead Decrypt, normal input parameters key, keyParam.ken_len is 192, cryptParam, plaintext, ciphertext
126  * @tc.desc      : [C- SECURITY -1400]
127  */
128 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0770, Function | MediumTest | Level1)
129 {
130     char alias[] = "test_hks_aead_encrypt";
131     int32_t statusEncrypt;
132     int32_t statusDecrypt;
133 
134     struct hks_blob key;
135     HksStBlobInit1(&key, 1, NUM24, HKS_BLOB_TYPE_KEY);
136     hks_generate_random(&key);
137 
138     struct hks_key_param keyParam;
139     keyParam.key_type = HKS_KEY_TYPE_AES;
140     keyParam.key_len = NUM192;
141     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
142     keyParam.key_mode = HKS_ALG_GCM;
143     keyParam.key_pad = HKS_PADDING_NONE;
144     keyParam.key_auth_id.data = (uint8_t *)alias;
145     keyParam.key_auth_id.size = sizeof(alias);
146     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
147 
148     struct hks_crypt_param cryptParam;
149     struct hks_blob nonce = {0};
150     HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV);
151     hks_generate_random(&nonce);
152 
153     struct hks_blob aad = {0};
154     HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD);
155     hks_generate_random(&aad);
156 
157     cryptParam.nonce = nonce;
158     cryptParam.aad = aad;
159 
160     struct hks_blob plaintext;
161     HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT);
162     hks_generate_random(&plaintext);
163 
164     struct hks_blob ciphertext;
165     HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT);
166     statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
167     TEST_ASSERT_EQUAL_INT(0, statusEncrypt);
168 
169     struct hks_blob decrypted;
170     HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT);
171     statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
172     TEST_ASSERT_EQUAL_INT(0, statusDecrypt);
173 
174     size_t k;
175     for (k = 0; k < decrypted.size; k++) {
176         TEST_ASSERT_EQUAL_INT(plaintext.data[k], decrypted.data[k]);
177     }
178     HksBlobDestroyT1(&key);
179     HksBlobDestroyT1(&nonce);
180     HksBlobDestroyT1(&aad);
181     HksBlobDestroyT1(&plaintext);
182     HksBlobDestroyT1(&ciphertext);
183     HksBlobDestroyT1(&decrypted);
184 };
185 
186 /*
187  * @tc.number    : SUB_SEC_DataPro_HuksL0_0780
188  * @tc.name      : Aead Decrypt, normal input parameters key, keyParam.ken_len is 256, cryptParam, plaintext, ciphertext
189  * @tc.desc      : [C- SECURITY -1400]
190  */
191 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0780, Function | MediumTest | Level1)
192 {
193     char alias[] = "test_hks_aead_encrypt";
194     int32_t statusEncrypt;
195     int32_t statusDecrypt;
196     struct hks_blob key;
197     HksStBlobInit1(&key, 1, NUM32, HKS_BLOB_TYPE_KEY);
198     hks_generate_random(&key);
199 
200     struct hks_key_param keyParam;
201     keyParam.key_type = HKS_KEY_TYPE_AES;
202     keyParam.key_len = NUM256;
203     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
204     keyParam.key_mode = HKS_ALG_GCM;
205     keyParam.key_pad = HKS_PADDING_NONE;
206     keyParam.key_auth_id.data = (uint8_t *)alias;
207     keyParam.key_auth_id.size = sizeof(alias);
208     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
209 
210     struct hks_crypt_param cryptParam;
211     struct hks_blob nonce = {0};
212     HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV);
213     hks_generate_random(&nonce);
214 
215     struct hks_blob aad = {0};
216     HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD);
217     hks_generate_random(&aad);
218 
219     cryptParam.nonce = nonce;
220     cryptParam.aad = aad;
221 
222     struct hks_blob plaintext;
223     HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT);
224     hks_generate_random(&plaintext);
225 
226     struct hks_blob ciphertext;
227     HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT);
228     statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
229     TEST_ASSERT_EQUAL_INT(0, statusEncrypt);
230 
231     struct hks_blob decrypted;
232     HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT);
233     statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
234     TEST_ASSERT_EQUAL_INT(0, statusDecrypt);
235 
236     size_t k;
237     for (k = 0; k < decrypted.size; k++) {
238         TEST_ASSERT_EQUAL_INT(plaintext.data[k], decrypted.data[k]);
239     }
240     HksBlobDestroyT1(&key);
241     HksBlobDestroyT1(&nonce);
242     HksBlobDestroyT1(&aad);
243     HksBlobDestroyT1(&plaintext);
244     HksBlobDestroyT1(&ciphertext);
245     HksBlobDestroyT1(&decrypted);
246 };
247 
248 /*
249  * @tc.number    : SUB_SEC_DataPro_HuksL0_0790
250  * @tc.name      : Aead Decrypt, abnormal input parameters key is null
251  * @tc.desc      : [C- SECURITY -1400]
252  */
253 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0790, Function | MediumTest | Level2)
254 {
255     char alias[] = "test_hks_aead_decrypt";
256 
257     uint8_t nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
258 
259     int32_t status;
260     struct hks_blob *key = NULL;
261 
262     struct hks_key_param keyParam;
263     keyParam.key_type = HKS_KEY_TYPE_AES;
264     keyParam.key_len = NUM128;
265     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
266     keyParam.key_mode = HKS_ALG_GCM;
267     keyParam.key_pad = HKS_PADDING_NONE;
268     keyParam.key_auth_id.data = (uint8_t *)alias;
269     keyParam.key_auth_id.size = sizeof(alias);
270     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
271 
272     struct hks_crypt_param cryptParam;
273 
274     struct hks_blob nonce = {0};
275     nonce.data = (uint8_t *)nonce1;
276     nonce.size = sizeof(nonce1);
277 
278     struct hks_blob aad = {0};
279     aad.data = (uint8_t *)aad1;
280     aad.size = sizeof(aad1);
281 
282     cryptParam.nonce = nonce;
283     cryptParam.aad = aad;
284 
285     struct hks_blob decrypted;
286     decrypted.data = (uint8_t *)decrypted1;
287     decrypted.size = sizeof(decrypted1);
288 
289     struct hks_blob ciphertext;
290     ciphertext.data = (uint8_t *)ciphertext1;
291     ciphertext.size = sizeof(ciphertext1);
292 
293     status = hks_aead_decrypt(key, &keyParam, &cryptParam, &decrypted, &ciphertext);
294     TEST_ASSERT_EQUAL_INT(NUM1000, status);
295 }
296 
297 /*
298  * @tc.number    : SUB_SEC_DataPro_HuksL0_0800
299  * @tc.name      : Aead Decrypt, abnormal input parameters key.size is not equal to keyParam.key_len divided by 8
300  * @tc.desc      : [C- SECURITY -1400]
301  */
302 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0800, Function | MediumTest | Level2)
303 {
304     char alias[] = "test_hks_aead_decrypt";
305 
306     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
307 
308     int32_t status;
309     struct hks_blob key;
310     key.type = HKS_BLOB_TYPE_KEY;
311     key.data = (uint8_t *)key1;
312     key.size = NUM32;
313     struct hks_key_param keyParam;
314     keyParam.key_type = HKS_KEY_TYPE_AES;
315     keyParam.key_len = NUM128;
316     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
317     keyParam.key_mode = HKS_ALG_GCM;
318     keyParam.key_pad = HKS_PADDING_NONE;
319     keyParam.key_auth_id.data = (uint8_t *)alias;
320     keyParam.key_auth_id.size = sizeof(alias);
321     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
322 
323     struct hks_crypt_param cryptParam;
324 
325     struct hks_blob nonce = {0};
326     nonce.data = (uint8_t *)nonce1;
327     nonce.size = sizeof(nonce1);
328 
329     struct hks_blob aad = {0};
330     aad.data = (uint8_t *)aad1;
331     aad.size = sizeof(aad1);
332 
333     cryptParam.nonce = nonce;
334     cryptParam.aad = aad;
335 
336     struct hks_blob decrypted;
337     decrypted.data = (uint8_t *)decrypted1;
338     decrypted.size = sizeof(decrypted1);
339 
340     struct hks_blob ciphertext;
341     ciphertext.data = (uint8_t *)ciphertext1;
342     ciphertext.size = sizeof(ciphertext1);
343 
344     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
345     TEST_ASSERT_EQUAL_INT(NUM1006, status);
346 }
347 
348 /*
349  * @tc.number    : SUB_SEC_DataPro_HuksL0_0810
350  * @tc.name      : Aead Decrypt, abnormal input parameters key.data is null
351  * @tc.desc      : [C- SECURITY -1400]
352  */
353 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0810, Function | MediumTest | Level2)
354 {
355     char alias[] = "test_hks_aead_decrypt";
356 
357     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
358 
359     int32_t status;
360     struct hks_blob key;
361     key.type = HKS_BLOB_TYPE_KEY;
362     key.data = NULL;
363     key.size = sizeof(key1);
364 
365     struct hks_key_param keyParam;
366     keyParam.key_type = HKS_KEY_TYPE_AES;
367     keyParam.key_len = NUM128;
368     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
369     keyParam.key_mode = HKS_ALG_GCM;
370     keyParam.key_pad = HKS_PADDING_NONE;
371     keyParam.key_auth_id.data = (uint8_t *)alias;
372     keyParam.key_auth_id.size = sizeof(alias);
373     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
374 
375     struct hks_crypt_param cryptParam;
376 
377     struct hks_blob nonce = {0};
378     nonce.data = (uint8_t *)nonce1;
379     nonce.size = sizeof(nonce1);
380 
381     struct hks_blob aad = {0};
382     aad.data = (uint8_t *)aad1;
383     aad.size = sizeof(aad1);
384 
385     cryptParam.nonce = nonce;
386     cryptParam.aad = aad;
387 
388     struct hks_blob decrypted;
389     decrypted.data = (uint8_t *)decrypted1;
390     decrypted.size = sizeof(decrypted1);
391 
392     struct hks_blob ciphertext;
393     ciphertext.data = (uint8_t *)ciphertext1;
394     ciphertext.size = sizeof(ciphertext1);
395 
396     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
397     TEST_ASSERT_EQUAL_INT(NUM1006, status);
398 }
399 
400 /*
401  * @tc.number    : SUB_SEC_DataPro_HuksL0_0820
402  * @tc.name      : Aead Decrypt, abnormal input parameters key.type is not equal to HKS_KEY_TYPE_AES
403  * @tc.desc      : [C- SECURITY -1400]
404  */
405 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0820, Function | MediumTest | Level2)
406 {
407     char alias[] = "test_hks_aead_decrypt";
408 
409     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
410 
411     int32_t status;
412     struct hks_blob key;
413     key.type = 0;
414     key.data = (uint8_t *)key1;
415     key.size = sizeof(key1);
416 
417     struct hks_key_param keyParam;
418     keyParam.key_type = HKS_KEY_TYPE_AES;
419     keyParam.key_len = NUM128;
420     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
421     keyParam.key_mode = HKS_ALG_GCM;
422     keyParam.key_pad = HKS_PADDING_NONE;
423     keyParam.key_auth_id.data = (uint8_t *)alias;
424     keyParam.key_auth_id.size = sizeof(alias);
425     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
426 
427     struct hks_crypt_param cryptParam;
428 
429     struct hks_blob nonce = {0};
430     nonce.data = (uint8_t *)nonce1;
431     nonce.size = sizeof(nonce1);
432 
433     struct hks_blob aad = {0};
434     aad.data = (uint8_t *)aad1;
435     aad.size = sizeof(aad1);
436 
437     cryptParam.nonce = nonce;
438     cryptParam.aad = aad;
439 
440     struct hks_blob decrypted;
441     decrypted.data = (uint8_t *)decrypted1;
442     decrypted.size = sizeof(decrypted1);
443 
444     struct hks_blob ciphertext;
445     ciphertext.data = (uint8_t *)ciphertext1;
446     ciphertext.size = sizeof(ciphertext1);
447 
448     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
449     TEST_ASSERT_EQUAL_INT(NUM1006, status);
450 }
451 
452 /*
453  * @tc.number    : SUB_SEC_DataPro_HuksL0_0830
454  * @tc.name      : Aead Decrypt, abnormal input parameters keyParam is null
455  * @tc.desc      : [C- SECURITY -1400]
456  */
457 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0830, Function | MediumTest | Level2)
458 {
459     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
460 
461     int32_t status;
462     struct hks_blob key;
463     key.type = HKS_BLOB_TYPE_KEY;
464     key.data = (uint8_t *)key1;
465     key.size = sizeof(key1);
466 
467     struct hks_key_param *keyParam = NULL;
468 
469     struct hks_crypt_param cryptParam;
470 
471     struct hks_blob nonce = {0};
472     nonce.data = (uint8_t *)nonce1;
473     nonce.size = sizeof(nonce1);
474 
475     struct hks_blob aad = {0};
476     aad.data = (uint8_t *)aad1;
477     aad.size = sizeof(aad1);
478 
479     cryptParam.nonce = nonce;
480     cryptParam.aad = aad;
481 
482     struct hks_blob decrypted;
483     decrypted.data = (uint8_t *)decrypted1;
484     decrypted.size = sizeof(decrypted1);
485 
486     struct hks_blob ciphertext;
487     ciphertext.data = (uint8_t *)ciphertext1;
488     ciphertext.size = sizeof(ciphertext1);
489 
490     status = hks_aead_decrypt(&key, keyParam, &cryptParam, &decrypted, &ciphertext);
491     TEST_ASSERT_EQUAL_INT(NUM1000, status);
492 }
493 
494 /*
495  * @tc.number    : SUB_SEC_DataPro_HuksL0_0840
496  * @tc.name      : Aead Decrypt, abnormal input parameters keyParam.key_mode is not equal to HKS_ALG_GCM
497  * @tc.desc      : [C- SECURITY -1400]
498  */
499 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0840, Function | MediumTest | Level2)
500 {
501     char alias[] = "test_hks_aead_decrypt";
502 
503     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
504 
505     int32_t status;
506     struct hks_blob key;
507     key.type = HKS_BLOB_TYPE_KEY;
508     key.data = (uint8_t *)key1;
509     key.size = sizeof(key1);
510 
511     struct hks_key_param keyParam;
512     keyParam.key_type = HKS_KEY_TYPE_AES;
513     keyParam.key_len = NUM128;
514     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
515     keyParam.key_mode = 0;
516     keyParam.key_pad = HKS_PADDING_NONE;
517     keyParam.key_auth_id.data = (uint8_t *)alias;
518     keyParam.key_auth_id.size = sizeof(alias);
519     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
520 
521     struct hks_crypt_param cryptParam;
522 
523     struct hks_blob nonce = {0};
524     nonce.data = (uint8_t *)nonce1;
525     nonce.size = sizeof(nonce1);
526 
527     struct hks_blob aad = {0};
528     aad.data = (uint8_t *)aad1;
529     aad.size = sizeof(aad1);
530 
531     cryptParam.nonce = nonce;
532     cryptParam.aad = aad;
533 
534     struct hks_blob decrypted;
535     decrypted.data = (uint8_t *)decrypted1;
536     decrypted.size = sizeof(decrypted1);
537 
538     struct hks_blob ciphertext;
539     ciphertext.data = (uint8_t *)ciphertext1;
540     ciphertext.size = sizeof(ciphertext1);
541 
542     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
543     TEST_ASSERT_EQUAL_INT(NUM134, status);
544 }
545 
546 /*
547  * @tc.number    : SUB_SEC_DataPro_HuksL0_0850
548  * @tc.name      : Aead Decrypt, abnormal input parameters keyParam.key_len is not equal to 128, 192, 256
549  * @tc.desc      : [C- SECURITY -1400]
550  */
551 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0850, Function | MediumTest | Level2)
552 {
553     char alias[] = "test_hks_aead_decrypt";
554 
555     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
556 
557     int32_t status;
558     struct hks_blob key;
559     key.type = HKS_BLOB_TYPE_KEY;
560     key.data = (uint8_t *)key1;
561     key.size = sizeof(key1);
562 
563     struct hks_key_param keyParam;
564     keyParam.key_type = HKS_KEY_TYPE_AES;
565     keyParam.key_len = NUM12;
566     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
567     keyParam.key_mode = HKS_ALG_GCM;
568     keyParam.key_pad = HKS_PADDING_NONE;
569     keyParam.key_auth_id.data = (uint8_t *)alias;
570     keyParam.key_auth_id.size = sizeof(alias);
571     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
572 
573     struct hks_crypt_param cryptParam;
574 
575     struct hks_blob nonce = {0};
576     nonce.data = (uint8_t *)nonce1;
577     nonce.size = sizeof(nonce1);
578 
579     struct hks_blob aad = {0};
580     aad.data = (uint8_t *)aad1;
581     aad.size = sizeof(aad1);
582 
583     cryptParam.nonce = nonce;
584     cryptParam.aad = aad;
585 
586     struct hks_blob decrypted;
587     decrypted.data = (uint8_t *)decrypted1;
588     decrypted.size = sizeof(decrypted1);
589 
590     struct hks_blob ciphertext;
591     ciphertext.data = (uint8_t *)ciphertext1;
592     ciphertext.size = sizeof(ciphertext1);
593 
594     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
595     TEST_ASSERT_EQUAL_INT(NUM134, status);
596 }
597 
598 /*
599  * @tc.number    : SUB_SEC_DataPro_HuksL0_0860
600  * @tc.name      : Aead Decrypt, abnormal input parameters keyParam.key_type is not equal to HKS_KEY_TYPE_AES
601  * @tc.desc      : [C- SECURITY -1400]
602  */
603 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0860, Function | MediumTest | Level2)
604 {
605     char alias[] = "test_hks_aead_decrypt";
606 
607     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
608 
609     int32_t status;
610     struct hks_blob key;
611     key.type = HKS_BLOB_TYPE_KEY;
612     key.data = (uint8_t *)key1;
613     key.size = sizeof(key1);
614 
615     struct hks_key_param keyParam;
616     keyParam.key_type = 0;
617     keyParam.key_len = NUM128;
618     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
619     keyParam.key_mode = HKS_ALG_GCM;
620     keyParam.key_pad = HKS_PADDING_NONE;
621     keyParam.key_auth_id.data = (uint8_t *)alias;
622     keyParam.key_auth_id.size = sizeof(alias);
623     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
624 
625     struct hks_crypt_param cryptParam;
626 
627     struct hks_blob nonce = {0};
628     nonce.data = (uint8_t *)nonce1;
629     nonce.size = sizeof(nonce1);
630 
631     struct hks_blob aad = {0};
632     aad.data = (uint8_t *)aad1;
633     aad.size = sizeof(aad1);
634 
635     cryptParam.nonce = nonce;
636     cryptParam.aad = aad;
637 
638     struct hks_blob decrypted;
639     decrypted.data = (uint8_t *)decrypted1;
640     decrypted.size = sizeof(decrypted1);
641 
642     struct hks_blob ciphertext;
643     ciphertext.data = (uint8_t *)ciphertext1;
644     ciphertext.size = sizeof(ciphertext1);
645 
646     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
647     TEST_ASSERT_EQUAL_INT(NUM134, status);
648 }
649 
650 /*
651  * @tc.number    : SUB_SEC_DataPro_HuksL0_0870
652  * @tc.name      : Aead Decrypt, abnormal input parameters keyParam.key_pad is not equal to HKS_PADDING_NONE
653  * @tc.desc      : [C- SECURITY -1400]
654  */
655 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0870, Function | MediumTest | Level2)
656 {
657     char alias[] = "test_hks_aead_decrypt";
658 
659     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
660 
661     int32_t status;
662     struct hks_blob key;
663     key.type = HKS_BLOB_TYPE_KEY;
664     key.data = (uint8_t *)key1;
665     key.size = sizeof(key1);
666 
667     struct hks_key_param keyParam;
668     keyParam.key_type = HKS_KEY_TYPE_AES;
669     keyParam.key_len = NUM128;
670     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
671     keyParam.key_mode = HKS_ALG_GCM;
672     keyParam.key_pad = NUM88;
673     keyParam.key_auth_id.data = (uint8_t *)alias;
674     keyParam.key_auth_id.size = sizeof(alias);
675     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
676 
677     struct hks_crypt_param cryptParam;
678 
679     struct hks_blob nonce = {0};
680     nonce.data = (uint8_t *)nonce1;
681     nonce.size = sizeof(nonce1);
682 
683     struct hks_blob aad = {0};
684     aad.data = (uint8_t *)aad1;
685     aad.size = sizeof(aad1);
686 
687     cryptParam.nonce = nonce;
688     cryptParam.aad = aad;
689 
690     struct hks_blob decrypted;
691     decrypted.data = (uint8_t *)decrypted1;
692     decrypted.size = sizeof(decrypted1);
693 
694     struct hks_blob ciphertext;
695     ciphertext.data = (uint8_t *)ciphertext1;
696     ciphertext.size = sizeof(ciphertext1);
697 
698     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
699     TEST_ASSERT_EQUAL_INT(NUM134, status);
700 }
701 
702 /*
703  * @tc.number    : SUB_SEC_DataPro_HuksL0_0880
704  * @tc.name      : Aead Decrypt, abnormal input parameters keyParam.key_usage
705                    is not equal to HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT
706  * @tc.desc      : [C- SECURITY -1400]
707  */
708 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0880, Function | MediumTest | Level2)
709 {
710     char alias[] = "test_hks_aead_decrypt";
711     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
712 
713     int32_t status;
714     struct hks_blob key;
715     key.type = HKS_BLOB_TYPE_KEY;
716     key.data = (uint8_t *)key1;
717     key.size = sizeof(key1);
718 
719     struct hks_key_param keyParam;
720     keyParam.key_type = HKS_KEY_TYPE_AES;
721     keyParam.key_len = NUM128;
722     keyParam.key_usage = 0;
723     keyParam.key_mode = HKS_ALG_GCM;
724     keyParam.key_pad = HKS_PADDING_NONE;
725     keyParam.key_auth_id.data = (uint8_t *)alias;
726     keyParam.key_auth_id.size = sizeof(alias);
727     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
728 
729     struct hks_crypt_param cryptParam;
730 
731     struct hks_blob nonce = {0};
732     nonce.data = (uint8_t *)nonce1;
733     nonce.size = sizeof(nonce1);
734 
735     struct hks_blob aad = {0};
736     aad.data = (uint8_t *)aad1;
737     aad.size = sizeof(aad1);
738 
739     cryptParam.nonce = nonce;
740     cryptParam.aad = aad;
741 
742     struct hks_blob decrypted;
743     decrypted.data = (uint8_t *)decrypted1;
744     decrypted.size = sizeof(decrypted1);
745 
746     struct hks_blob ciphertext;
747     ciphertext.data = (uint8_t *)ciphertext1;
748     ciphertext.size = sizeof(ciphertext1);
749 
750     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
751     TEST_ASSERT_EQUAL_INT(NUM134, status);
752 }
753 
754 /*
755  * @tc.number    : SUB_SEC_DataPro_HuksL0_0890
756  * @tc.name      : Aead Decrypt, abnormal input parameters cryptParam is null
757  * @tc.desc      : [C- SECURITY -1400]
758  */
759 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0890, Function | MediumTest | Level2)
760 {
761     char alias[] = "test_hks_aead_decrypt";
762 
763     uint8_t key1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
764 
765     int32_t status;
766     struct hks_blob key;
767     key.type = HKS_BLOB_TYPE_KEY;
768     key.data = (uint8_t *)key1;
769     key.size = sizeof(key1);
770 
771     struct hks_key_param keyParam;
772     keyParam.key_type = HKS_KEY_TYPE_AES;
773     keyParam.key_len = NUM128;
774     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
775     keyParam.key_mode = HKS_ALG_GCM;
776     keyParam.key_pad = HKS_PADDING_NONE;
777     keyParam.key_auth_id.data = (uint8_t *)alias;
778     keyParam.key_auth_id.size = sizeof(alias);
779     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
780 
781     struct hks_crypt_param *cryptParam = NULL;
782 
783     struct hks_blob decrypted;
784     decrypted.data = (uint8_t *)decrypted1;
785     decrypted.size = sizeof(decrypted1);
786 
787     struct hks_blob ciphertext;
788     ciphertext.data = (uint8_t *)ciphertext1;
789     ciphertext.size = sizeof(ciphertext1);
790 
791     status = hks_aead_decrypt(&key, &keyParam, cryptParam, &decrypted, &ciphertext);
792     TEST_ASSERT_EQUAL_INT(NUM1000, status);
793 }
794 
795 /*
796  * @tc.number    : SUB_SEC_DataPro_HuksL0_0900
797  * @tc.name      : Aead Decrypt, abnormal input parameters nonce.size is 0
798  * @tc.desc      : [C- SECURITY -1400]
799  */
800 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0900, Function | MediumTest | Level2)
801 {
802     char alias[] = "test_hks_aead_decrypt";
803 
804     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
805 
806     int32_t status;
807     struct hks_blob key;
808     key.type = HKS_BLOB_TYPE_KEY;
809     key.data = (uint8_t *)key1;
810     key.size = sizeof(key1);
811 
812     struct hks_key_param keyParam;
813     keyParam.key_type = HKS_KEY_TYPE_AES;
814     keyParam.key_len = NUM128;
815     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
816     keyParam.key_mode = HKS_ALG_GCM;
817     keyParam.key_pad = HKS_PADDING_NONE;
818     keyParam.key_auth_id.data = (uint8_t *)alias;
819     keyParam.key_auth_id.size = sizeof(alias);
820     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
821 
822     struct hks_crypt_param cryptParam;
823 
824     struct hks_blob nonce = {0};
825     nonce.data = (uint8_t *)nonce1;
826     nonce.size = 0;
827 
828     struct hks_blob aad = {0};
829     aad.data = (uint8_t *)aad1;
830     aad.size = sizeof(aad1);
831 
832     cryptParam.nonce = nonce;
833     cryptParam.aad = aad;
834 
835     struct hks_blob decrypted;
836     decrypted.data = (uint8_t *)decrypted1;
837     decrypted.size = sizeof(decrypted1);
838 
839     struct hks_blob ciphertext;
840     ciphertext.data = (uint8_t *)ciphertext1;
841     ciphertext.size = sizeof(ciphertext1);
842 
843     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
844     TEST_ASSERT_EQUAL_INT(NUM135, status);
845 }
846 
847 /*
848  * @tc.number    : SUB_SEC_DataPro_HuksL0_0910
849  * @tc.name      : Aead Decrypt, abnormal input parameters nonce.data is null
850  * @tc.desc      : [C- SECURITY -1400]
851  */
852 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0910, Function | MediumTest | Level2)
853 {
854     char alias[] = "test_hks_aead_decrypt";
855 
856     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
857 
858     int32_t status;
859     struct hks_blob key;
860     key.type = HKS_BLOB_TYPE_KEY;
861     key.data = (uint8_t *)key1;
862     key.size = sizeof(key1);
863 
864     struct hks_key_param keyParam;
865     keyParam.key_type = HKS_KEY_TYPE_AES;
866     keyParam.key_len = NUM128;
867     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
868     keyParam.key_mode = HKS_ALG_GCM;
869     keyParam.key_pad = HKS_PADDING_NONE;
870     keyParam.key_auth_id.data = (uint8_t *)alias;
871     keyParam.key_auth_id.size = sizeof(alias);
872     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
873 
874     struct hks_crypt_param cryptParam;
875 
876     struct hks_blob nonce = {0};
877     nonce.data = NULL;
878     nonce.size = sizeof(nonce1);
879 
880     struct hks_blob aad = {0};
881     aad.data = (uint8_t *)aad1;
882     aad.size = sizeof(aad1);
883 
884     cryptParam.nonce = nonce;
885     cryptParam.aad = aad;
886 
887     struct hks_blob decrypted;
888     decrypted.data = (uint8_t *)decrypted1;
889     decrypted.size = sizeof(decrypted1);
890 
891     struct hks_blob ciphertext;
892     ciphertext.data = (uint8_t *)ciphertext1;
893     ciphertext.size = sizeof(ciphertext1);
894 
895     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
896     TEST_ASSERT_EQUAL_INT(NUM135, status);
897 }
898 
899 /*
900  * @tc.number    : SUB_SEC_DataPro_HuksL0_0920
901  * @tc.name      : Aead Decrypt, abnormal input parameters aad.size is 0
902  * @tc.desc      : [C- SECURITY -1400]
903  */
904 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0920, Function | MediumTest | Level2)
905 {
906     char alias[] = "test_hks_aead_decrypt";
907 
908     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
909 
910     int32_t status;
911     struct hks_blob key;
912     key.type = HKS_BLOB_TYPE_KEY;
913     key.data = (uint8_t *)key1;
914     key.size = sizeof(key1);
915 
916     struct hks_key_param keyParam;
917     keyParam.key_type = HKS_KEY_TYPE_AES;
918     keyParam.key_len = NUM128;
919     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
920     keyParam.key_mode = HKS_ALG_GCM;
921     keyParam.key_pad = HKS_PADDING_NONE;
922     keyParam.key_auth_id.data = (uint8_t *)alias;
923     keyParam.key_auth_id.size = sizeof(alias);
924     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
925 
926     struct hks_crypt_param cryptParam;
927 
928     struct hks_blob nonce = {0};
929     nonce.data = (uint8_t *)nonce1;
930     nonce.size = sizeof(nonce1);
931 
932     struct hks_blob aad = {0};
933     aad.data = (uint8_t *)aad1;
934     aad.size = 0;
935 
936     cryptParam.nonce = nonce;
937     cryptParam.aad = aad;
938 
939     struct hks_blob decrypted;
940     decrypted.data = (uint8_t *)decrypted1;
941     decrypted.size = sizeof(decrypted1);
942 
943     struct hks_blob ciphertext;
944     ciphertext.data = (uint8_t *)ciphertext1;
945     ciphertext.size = sizeof(ciphertext1);
946 
947     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
948     TEST_ASSERT_EQUAL_INT(NUM135, status);
949 }
950 
951 /*
952  * @tc.number    : SUB_SEC_DataPro_HuksL0_0930
953  * @tc.name      : Aead Decrypt, abnormal input parameters aad.data is null
954  * @tc.desc      : [C- SECURITY -1400]
955  */
956 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0930, Function | MediumTest | Level2)
957 {
958     char alias[] = "test_hks_aead_decrypt";
959 
960     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
961 
962     int32_t status;
963     struct hks_blob key;
964     key.type = HKS_BLOB_TYPE_KEY;
965     key.data = (uint8_t *)key1;
966     key.size = sizeof(key1);
967 
968     struct hks_key_param keyParam;
969     keyParam.key_type = HKS_KEY_TYPE_AES;
970     keyParam.key_len = NUM128;
971     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
972     keyParam.key_mode = HKS_ALG_GCM;
973     keyParam.key_pad = HKS_PADDING_NONE;
974     keyParam.key_auth_id.data = (uint8_t *)alias;
975     keyParam.key_auth_id.size = sizeof(alias);
976     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
977 
978     struct hks_crypt_param cryptParam;
979 
980     struct hks_blob nonce = {0};
981     nonce.data = (uint8_t *)nonce1;
982     nonce.size = sizeof(nonce1);
983 
984     struct hks_blob aad = {0};
985     aad.data = NULL;
986     aad.size = sizeof(aad1);
987 
988     cryptParam.nonce = nonce;
989     cryptParam.aad = aad;
990 
991     struct hks_blob decrypted;
992     decrypted.data = (uint8_t *)decrypted1;
993     decrypted.size = sizeof(decrypted1);
994 
995     struct hks_blob ciphertext;
996     ciphertext.data = (uint8_t *)ciphertext1;
997     ciphertext.size = sizeof(ciphertext1);
998 
999     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
1000     TEST_ASSERT_EQUAL_INT(NUM135, status);
1001 }
1002 
1003 /*
1004  * @tc.number    : SUB_SEC_DataPro_HuksL0_0940
1005  * @tc.name      : Aead Decrypt, abnormal input decrypted plaintext is null
1006  * @tc.desc      : [C- SECURITY -1400]
1007  */
1008 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0940, Function | MediumTest | Level2)
1009 {
1010     char alias[] = "test_hks_aead_decrypt";
1011 
1012     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], ciphertext1[NUM100];
1013 
1014     int32_t status;
1015     struct hks_blob key;
1016     key.type = HKS_BLOB_TYPE_KEY;
1017     key.data = (uint8_t *)key1;
1018     key.size = sizeof(key1);
1019 
1020     struct hks_key_param keyParam;
1021     keyParam.key_type = HKS_KEY_TYPE_AES;
1022     keyParam.key_len = NUM128;
1023     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1024     keyParam.key_mode = HKS_ALG_GCM;
1025     keyParam.key_pad = HKS_PADDING_NONE;
1026     keyParam.key_auth_id.data = (uint8_t *)alias;
1027     keyParam.key_auth_id.size = sizeof(alias);
1028     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1029 
1030     struct hks_crypt_param cryptParam;
1031 
1032     struct hks_blob nonce = {0};
1033     nonce.data = (uint8_t *)nonce1;
1034     nonce.size = sizeof(nonce1);
1035 
1036     struct hks_blob aad = {0};
1037     aad.data = (uint8_t *)aad1;
1038     aad.size = sizeof(aad1);
1039 
1040     cryptParam.nonce = nonce;
1041     cryptParam.aad = aad;
1042 
1043     struct hks_blob *decrypted = NULL;
1044 
1045     struct hks_blob ciphertext;
1046     ciphertext.data = (uint8_t *)ciphertext1;
1047     ciphertext.size = sizeof(ciphertext1);
1048 
1049     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, decrypted, &ciphertext);
1050     TEST_ASSERT_EQUAL_INT(NUM1000, status);
1051 }
1052 
1053 /*
1054  * @tc.number    : SUB_SEC_DataPro_HuksL0_0950
1055  * @tc.name      : Aead Decrypt, abnormal input decrypted plaintext.data is null
1056  * @tc.desc      : [C- SECURITY -1400]
1057  */
1058 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0950, Function | MediumTest | Level2)
1059 {
1060     char alias[] = "test_hks_aead_decrypt";
1061 
1062     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
1063 
1064     int32_t status;
1065     struct hks_blob key;
1066     key.type = HKS_BLOB_TYPE_KEY;
1067     key.data = (uint8_t *)key1;
1068     key.size = sizeof(key1);
1069 
1070     struct hks_key_param keyParam;
1071     keyParam.key_type = HKS_KEY_TYPE_AES;
1072     keyParam.key_len = NUM128;
1073     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1074     keyParam.key_mode = HKS_ALG_GCM;
1075     keyParam.key_pad = HKS_PADDING_NONE;
1076     keyParam.key_auth_id.data = (uint8_t *)alias;
1077     keyParam.key_auth_id.size = sizeof(alias);
1078     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1079 
1080     struct hks_crypt_param cryptParam;
1081 
1082     struct hks_blob nonce = {0};
1083     nonce.data = (uint8_t *)nonce1;
1084     nonce.size = sizeof(nonce1);
1085 
1086     struct hks_blob aad = {0};
1087     aad.data = (uint8_t *)aad1;
1088     aad.size = sizeof(aad1);
1089 
1090     cryptParam.nonce = nonce;
1091     cryptParam.aad = aad;
1092 
1093     struct hks_blob decrypted;
1094     decrypted.data = NULL;
1095     decrypted.size = sizeof(decrypted1);
1096 
1097     struct hks_blob ciphertext;
1098     ciphertext.data = (uint8_t *)ciphertext1;
1099     ciphertext.size = sizeof(ciphertext1);
1100 
1101     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
1102     TEST_ASSERT_EQUAL_INT(NUM135, status);
1103 }
1104 
1105 /*
1106  * @tc.number    : SUB_SEC_DataPro_HuksL0_0960
1107  * @tc.name      : Aead Decrypt, abnormal input parameters decrypted.size is less than ciphertext.size minus 16
1108  * @tc.desc      : [C- SECURITY -1400]
1109  */
1110 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0960, Function | MediumTest | Level2)
1111 {
1112     char alias[] = "test_hks_aead_decrypt";
1113 
1114     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
1115 
1116     int32_t status;
1117     struct hks_blob key;
1118     key.type = HKS_BLOB_TYPE_KEY;
1119     key.data = (uint8_t *)key1;
1120     key.size = sizeof(key1);
1121 
1122     struct hks_key_param keyParam;
1123     keyParam.key_type = HKS_KEY_TYPE_AES;
1124     keyParam.key_len = NUM128;
1125     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1126     keyParam.key_mode = HKS_ALG_GCM;
1127     keyParam.key_pad = HKS_PADDING_NONE;
1128     keyParam.key_auth_id.data = (uint8_t *)alias;
1129     keyParam.key_auth_id.size = sizeof(alias);
1130     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1131 
1132     struct hks_crypt_param cryptParam;
1133 
1134     struct hks_blob nonce = {0};
1135     nonce.data = (uint8_t *)nonce1;
1136     nonce.size = sizeof(nonce1);
1137 
1138     struct hks_blob aad = {0};
1139     aad.data = (uint8_t *)aad1;
1140     aad.size = sizeof(aad1);
1141 
1142     cryptParam.nonce = nonce;
1143     cryptParam.aad = aad;
1144 
1145     struct hks_blob decrypted;
1146     decrypted.data = (uint8_t *)decrypted1;
1147     decrypted.size = NUM15;
1148 
1149     struct hks_blob ciphertext;
1150     ciphertext.data = (uint8_t *)ciphertext1;
1151     ciphertext.size = sizeof(ciphertext1);
1152 
1153     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
1154     TEST_ASSERT_EQUAL_INT(NUM135, status);
1155 }
1156 
1157 /*
1158  * @tc.number    : SUB_SEC_DataPro_HuksL0_0970
1159  * @tc.name      : Aead Decrypt, abnormal input parameters ciphertext.size is null
1160  * @tc.desc      : [C- SECURITY -1400]
1161  */
1162 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0970, Function | MediumTest | Level2)
1163 {
1164     char alias[] = "test_hks_aead_decrypt";
1165 
1166     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100];
1167 
1168     int32_t status;
1169     struct hks_blob key;
1170     key.type = HKS_BLOB_TYPE_KEY;
1171     key.data = (uint8_t *)key1;
1172     key.size = sizeof(key1);
1173 
1174     struct hks_key_param keyParam;
1175     keyParam.key_type = HKS_KEY_TYPE_AES;
1176     keyParam.key_len = NUM128;
1177     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1178     keyParam.key_mode = HKS_ALG_GCM;
1179     keyParam.key_pad = HKS_PADDING_NONE;
1180     keyParam.key_auth_id.data = (uint8_t *)alias;
1181     keyParam.key_auth_id.size = sizeof(alias);
1182     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1183 
1184     struct hks_crypt_param cryptParam;
1185 
1186     struct hks_blob nonce = {0};
1187     nonce.data = (uint8_t *)nonce1;
1188     nonce.size = sizeof(nonce1);
1189 
1190     struct hks_blob aad = {0};
1191     aad.data = (uint8_t *)aad1;
1192     aad.size = sizeof(aad1);
1193 
1194     cryptParam.nonce = nonce;
1195     cryptParam.aad = aad;
1196 
1197     struct hks_blob decrypted;
1198     decrypted.data = (uint8_t *)decrypted1;
1199     decrypted.size = sizeof(decrypted1);
1200 
1201     struct hks_blob *ciphertext = NULL;
1202 
1203     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, ciphertext);
1204     TEST_ASSERT_EQUAL_INT(NUM1000, status);
1205 }
1206 
1207 /*
1208  * @tc.number    : SUB_SEC_DataPro_HuksL0_0980
1209  * @tc.name      : Aead Decrypt, abnormal input parameters ciphertext.data is null
1210  * @tc.desc      : [C- SECURITY -1400]
1211  */
1212 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0980, Function | MediumTest | Level2)
1213 {
1214     char alias[] = "test_hks_aead_decrypt";
1215 
1216     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
1217 
1218     int32_t status;
1219     struct hks_blob key;
1220     key.type = HKS_BLOB_TYPE_KEY;
1221     key.data = (uint8_t *)key1;
1222     key.size = sizeof(key1);
1223 
1224     struct hks_key_param keyParam;
1225     keyParam.key_type = HKS_KEY_TYPE_AES;
1226     keyParam.key_len = NUM128;
1227     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1228     keyParam.key_mode = HKS_ALG_GCM;
1229     keyParam.key_pad = HKS_PADDING_NONE;
1230     keyParam.key_auth_id.data = (uint8_t *)alias;
1231     keyParam.key_auth_id.size = sizeof(alias);
1232     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1233 
1234     struct hks_crypt_param cryptParam;
1235 
1236     struct hks_blob nonce = {0};
1237     nonce.data = (uint8_t *)nonce1;
1238     nonce.size = sizeof(nonce1);
1239 
1240     struct hks_blob aad = {0};
1241     aad.data = (uint8_t *)aad1;
1242     aad.size = sizeof(aad1);
1243 
1244     cryptParam.nonce = nonce;
1245     cryptParam.aad = aad;
1246 
1247     struct hks_blob decrypted;
1248     decrypted.data = (uint8_t *)decrypted1;
1249     decrypted.size = sizeof(decrypted1);
1250 
1251     struct hks_blob ciphertext;
1252     ciphertext.data = NULL;
1253     ciphertext.size = sizeof(ciphertext1);
1254 
1255     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
1256     TEST_ASSERT_EQUAL_INT(NUM135, status);
1257 }
1258 
1259 /*
1260  * @tc.number    : SUB_SEC_DataPro_HuksL0_0990
1261  * @tc.name      : Aead Decrypt, abnormal input parameters ciphertext.size is less than 16
1262  * @tc.desc      : [C- SECURITY -1400]
1263  */
1264 LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0990, Function | MediumTest | Level2)
1265 {
1266     char alias[] = "test_hks_aead_decrypt";
1267 
1268     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100];
1269 
1270     int32_t status;
1271     struct hks_blob key;
1272     key.type = HKS_BLOB_TYPE_KEY;
1273     key.data = (uint8_t *)key1;
1274     key.size = sizeof(key1);
1275 
1276     struct hks_key_param keyParam;
1277     keyParam.key_type = HKS_KEY_TYPE_AES;
1278     keyParam.key_len = NUM128;
1279     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1280     keyParam.key_mode = HKS_ALG_GCM;
1281     keyParam.key_pad = HKS_PADDING_NONE;
1282     keyParam.key_auth_id.data = (uint8_t *)alias;
1283     keyParam.key_auth_id.size = sizeof(alias);
1284     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1285 
1286     struct hks_crypt_param cryptParam;
1287 
1288     struct hks_blob nonce = {0};
1289     nonce.data = (uint8_t *)nonce1;
1290     nonce.size = sizeof(nonce1);
1291 
1292     struct hks_blob aad = {0};
1293     aad.data = (uint8_t *)aad1;
1294     aad.size = sizeof(aad1);
1295 
1296     cryptParam.nonce = nonce;
1297     cryptParam.aad = aad;
1298 
1299     struct hks_blob decrypted;
1300     decrypted.data = (uint8_t *)decrypted1;
1301     decrypted.size = sizeof(decrypted1);
1302 
1303     struct hks_blob ciphertext;
1304     ciphertext.data = (uint8_t *)ciphertext1;
1305     ciphertext.size = NUM10;
1306 
1307     status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext);
1308     TEST_ASSERT_EQUAL_INT(NUM135, status);
1309 }
1310 
1311 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Decrypt key
1312 // begin++++++++++++++++++++++++++++++++++++++++++++++++++++0760-0990
1313 
1314 RUN_TEST_SUITE(SecurityDataHuksDecTestSuite);
1315