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