• 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 SecurityDataHuksEncTestSuite : 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 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Encrypt key
69 // begin++++++++++++++++++++++++++++++++++++++++++++++++++++0520-0750
70 
71 /*
72  * @tc.number    : SUB_SEC_DataPro_HuksL1_0520
73  * @tc.name      : Aead Encrypt, normal input parameters key, keyParam.ken_len is 128, cryptParam, plaintext, ciphertext
74  * @tc.desc      : [C- SECURITY -1500]
75  */
76 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0520, 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_0530
136  * @tc.name      : Aead Encrypt, normal input parameters key, keyParam.ken_len is 192, cryptParam, plaintext, ciphertext
137  * @tc.desc      : [C- SECURITY -1500]
138  */
139 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0530, 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_0540
199  * @tc.name      : Aead Encrypt, normal input parameters key, keyParam.ken_len is 256, cryptParam, plaintext, ciphertext
200  * @tc.desc      : [C- SECURITY -1500]
201  */
202 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0540, 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_0550
262  * @tc.name      : Aead Encrypt, abnormal input parameters key is null
263  * @tc.desc      : [C- SECURITY -1500]
264  */
265 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0550, Function | MediumTest | Level2)
266 {
267     char alias[] = "test_hks_aead_encrypt";
268 
269     uint8_t nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
270 
271     int32_t status;
272 
273     struct hks_blob *key = nullptr;
274 
275     struct hks_key_param keyParam;
276     keyParam.key_type = HKS_KEY_TYPE_AES;
277     keyParam.key_len = NUM128;
278     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
279     keyParam.key_mode = HKS_ALG_GCM;
280     keyParam.key_pad = HKS_PADDING_NONE;
281     keyParam.key_auth_id.data = (uint8_t *)alias;
282     keyParam.key_auth_id.size = sizeof(alias);
283     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
284 
285     struct hks_crypt_param cryptParam;
286 
287     struct hks_blob nonce = {0};
288     nonce.data = (uint8_t *)nonce1;
289     nonce.size = sizeof(nonce1);
290 
291     struct hks_blob aad = {0};
292     aad.data = (uint8_t *)aad1;
293     aad.size = sizeof(aad1);
294 
295     cryptParam.nonce = nonce;
296     cryptParam.aad = aad;
297 
298     struct hks_blob plaintext;
299     plaintext.data = (uint8_t *)plaintext1;
300     plaintext.size = sizeof(plaintext1);
301 
302     struct hks_blob ciphertext;
303     ciphertext.data = (uint8_t *)ciphertext1;
304     ciphertext.size = sizeof(ciphertext1);
305 
306     status = hks_aead_encrypt(key, &keyParam, &cryptParam, &plaintext, &ciphertext);
307     EXPECT_EQ(NUM1000, status);
308 }
309 
310 /*
311  * @tc.number    : SUB_SEC_DataPro_HuksL1_0560
312  * @tc.name      : Aead Encrypt, abnormal input parameters key.size is not equal to keyParam.key_len divided by 8
313  * @tc.desc      : [C- SECURITY -1500]
314  */
315 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0560, Function | MediumTest | Level2)
316 {
317     char alias[] = "test_hks_aead_encrypt";
318 
319     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
320 
321     int32_t status;
322 
323     struct hks_blob key;
324     key.type = HKS_BLOB_TYPE_KEY;
325     key.data = (uint8_t *)key1;
326     key.size = NUM32;
327 
328     struct hks_key_param keyParam;
329     keyParam.key_type = HKS_KEY_TYPE_AES;
330     keyParam.key_len = NUM128;
331     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
332     keyParam.key_mode = HKS_ALG_GCM;
333     keyParam.key_pad = HKS_PADDING_NONE;
334     keyParam.key_auth_id.data = (uint8_t *)alias;
335     keyParam.key_auth_id.size = sizeof(alias);
336     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
337 
338     struct hks_crypt_param cryptParam;
339 
340     struct hks_blob nonce = {0};
341     nonce.data = (uint8_t *)nonce1;
342     nonce.size = sizeof(nonce1);
343 
344     struct hks_blob aad = {0};
345     aad.data = (uint8_t *)aad1;
346     aad.size = sizeof(aad1);
347 
348     cryptParam.nonce = nonce;
349     cryptParam.aad = aad;
350 
351     struct hks_blob plaintext;
352     plaintext.data = (uint8_t *)plaintext1;
353     plaintext.size = sizeof(plaintext1);
354 
355     struct hks_blob ciphertext;
356     ciphertext.data = (uint8_t *)ciphertext1;
357     ciphertext.size = sizeof(ciphertext1);
358 
359     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
360     EXPECT_EQ(NUM1006, status);
361 }
362 
363 /*
364  * @tc.number    : SUB_SEC_DataPro_HuksL1_0570
365  * @tc.name      : Aead Encrypt, abnormal input parameters key.data is null
366  * @tc.desc      : [C- SECURITY -1500]
367  */
368 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0570, Function | MediumTest | Level2)
369 {
370     char alias[] = "test_hks_aead_encrypt";
371 
372     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
373 
374     int32_t status;
375 
376     struct hks_blob key;
377     key.type = HKS_BLOB_TYPE_KEY;
378     key.data = NULL;
379     key.size = sizeof(key1);
380 
381     struct hks_key_param keyParam;
382     keyParam.key_type = HKS_KEY_TYPE_AES;
383     keyParam.key_len = NUM128;
384     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
385     keyParam.key_mode = HKS_ALG_GCM;
386     keyParam.key_pad = HKS_PADDING_NONE;
387     keyParam.key_auth_id.data = (uint8_t *)alias;
388     keyParam.key_auth_id.size = sizeof(alias);
389     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
390 
391     struct hks_crypt_param cryptParam;
392 
393     struct hks_blob nonce = {0};
394     nonce.data = (uint8_t *)nonce1;
395     nonce.size = sizeof(nonce1);
396 
397     struct hks_blob aad = {0};
398     aad.data = (uint8_t *)aad1;
399     aad.size = sizeof(aad1);
400 
401     cryptParam.nonce = nonce;
402     cryptParam.aad = aad;
403 
404     struct hks_blob plaintext;
405     plaintext.data = (uint8_t *)plaintext1;
406     plaintext.size = sizeof(plaintext1);
407 
408     struct hks_blob ciphertext;
409     ciphertext.data = (uint8_t *)ciphertext1;
410     ciphertext.size = sizeof(ciphertext1);
411 
412     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
413     EXPECT_EQ(NUM1006, status);
414 }
415 
416 /*
417  * @tc.number    : SUB_SEC_DataPro_HuksL1_0580
418  * @tc.name      : Aead Encrypt, abnormal input parameters key.type is not equal to HKS_BLOB_TYPE_KEY
419  * @tc.desc      : [C- SECURITY -1500]
420  */
421 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0580, Function | MediumTest | Level2)
422 {
423     char alias[] = "test_hks_aead_encrypt";
424 
425     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
426 
427     int32_t status;
428 
429     struct hks_blob key;
430     key.type = 0;
431     key.data = (uint8_t *)key1;
432     key.size = sizeof(key1);
433 
434     struct hks_key_param keyParam;
435     keyParam.key_type = HKS_KEY_TYPE_AES;
436     keyParam.key_len = NUM128;
437     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
438     keyParam.key_mode = HKS_ALG_GCM;
439     keyParam.key_pad = HKS_PADDING_NONE;
440     keyParam.key_auth_id.data = (uint8_t *)alias;
441     keyParam.key_auth_id.size = sizeof(alias);
442     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
443 
444     struct hks_crypt_param cryptParam;
445 
446     struct hks_blob nonce = {0};
447     nonce.data = (uint8_t *)nonce1;
448     nonce.size = sizeof(nonce1);
449 
450     struct hks_blob aad = {0};
451     aad.data = (uint8_t *)aad1;
452     aad.size = sizeof(aad1);
453 
454     cryptParam.nonce = nonce;
455     cryptParam.aad = aad;
456 
457     struct hks_blob plaintext;
458     plaintext.data = (uint8_t *)plaintext1;
459     plaintext.size = sizeof(plaintext1);
460 
461     struct hks_blob ciphertext;
462     ciphertext.data = (uint8_t *)ciphertext1;
463     ciphertext.size = sizeof(ciphertext1);
464 
465     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
466     EXPECT_EQ(NUM1006, status);
467 }
468 
469 /*
470  * @tc.number    : SUB_SEC_DataPro_HuksL1_0590
471  * @tc.name      : Aead Encrypt, abnormal input parameters keyParam is null
472  * @tc.desc      : [C- SECURITY -1500]
473  */
474 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0590, Function | MediumTest | Level2)
475 {
476     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
477 
478     int32_t status;
479 
480     struct hks_blob key;
481     key.type = HKS_BLOB_TYPE_KEY;
482     key.data = (uint8_t *)key1;
483     key.size = sizeof(key1);
484 
485     struct hks_key_param *keyParam = nullptr;
486 
487     struct hks_crypt_param cryptParam;
488 
489     struct hks_blob nonce = {0};
490     nonce.data = (uint8_t *)nonce1;
491     nonce.size = sizeof(nonce1);
492 
493     struct hks_blob aad = {0};
494     aad.data = (uint8_t *)aad1;
495     aad.size = sizeof(aad1);
496 
497     cryptParam.nonce = nonce;
498     cryptParam.aad = aad;
499 
500     struct hks_blob plaintext;
501     plaintext.data = (uint8_t *)plaintext1;
502     plaintext.size = sizeof(plaintext1);
503 
504     struct hks_blob ciphertext;
505     ciphertext.data = (uint8_t *)ciphertext1;
506     ciphertext.size = sizeof(ciphertext1);
507 
508     status = hks_aead_encrypt(&key, keyParam, &cryptParam, &plaintext, &ciphertext);
509     EXPECT_EQ(NUM1000, status);
510 }
511 
512 /*
513  * @tc.number    : SUB_SEC_DataPro_HuksL1_0600
514  * @tc.name      : Aead Encrypt, abnormal input parameters keyParam.key_mode is not equal to HKS_ALG_GCM
515  * @tc.desc      : [C- SECURITY -1500]
516  */
517 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0600, Function | MediumTest | Level2)
518 {
519     char alias[] = "test_hks_aead_encrypt";
520 
521     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
522 
523     int32_t status;
524 
525     struct hks_blob key;
526     key.type = HKS_BLOB_TYPE_KEY;
527     key.data = (uint8_t *)key1;
528     key.size = sizeof(key1);
529 
530     struct hks_key_param keyParam;
531     keyParam.key_type = HKS_KEY_TYPE_AES;
532     keyParam.key_len = NUM128;
533     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
534     keyParam.key_mode = 0;
535     keyParam.key_pad = HKS_PADDING_NONE;
536     keyParam.key_auth_id.data = (uint8_t *)alias;
537     keyParam.key_auth_id.size = sizeof(alias);
538     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
539 
540     struct hks_crypt_param cryptParam;
541 
542     struct hks_blob nonce = {0};
543     nonce.data = (uint8_t *)nonce1;
544     nonce.size = sizeof(nonce1);
545 
546     struct hks_blob aad = {0};
547     aad.data = (uint8_t *)aad1;
548     aad.size = sizeof(aad1);
549 
550     cryptParam.nonce = nonce;
551     cryptParam.aad = aad;
552 
553     struct hks_blob plaintext;
554     plaintext.data = (uint8_t *)plaintext1;
555     plaintext.size = sizeof(plaintext1);
556 
557     struct hks_blob ciphertext;
558     ciphertext.data = (uint8_t *)ciphertext1;
559     ciphertext.size = sizeof(ciphertext1);
560 
561     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
562     EXPECT_EQ(NUM134, status);
563 }
564 
565 /*
566  * @tc.number    : SUB_SEC_DataPro_HuksL1_0610
567  * @tc.name      : Aead Encrypt, abnormal input parameters keyParam.key_len is not equal to 128, 192, 256
568  * @tc.desc      : [C- SECURITY -1500]
569  */
570 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0610, Function | MediumTest | Level2)
571 {
572     char alias[] = "test_hks_aead_encrypt";
573 
574     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
575 
576     int32_t status;
577 
578     struct hks_blob key;
579     key.type = HKS_BLOB_TYPE_KEY;
580     key.data = (uint8_t *)key1;
581     key.size = sizeof(key1);
582 
583     struct hks_key_param keyParam;
584     keyParam.key_type = HKS_KEY_TYPE_AES;
585     keyParam.key_len = NUM11;
586     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
587     keyParam.key_mode = HKS_ALG_GCM;
588     keyParam.key_pad = HKS_PADDING_NONE;
589     keyParam.key_auth_id.data = (uint8_t *)alias;
590     keyParam.key_auth_id.size = sizeof(alias);
591     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
592 
593     struct hks_crypt_param cryptParam;
594 
595     struct hks_blob nonce = {0};
596     nonce.data = (uint8_t *)nonce1;
597     nonce.size = sizeof(nonce1);
598 
599     struct hks_blob aad = {0};
600     aad.data = (uint8_t *)aad1;
601     aad.size = sizeof(aad1);
602 
603     cryptParam.nonce = nonce;
604     cryptParam.aad = aad;
605 
606     struct hks_blob plaintext;
607     plaintext.data = (uint8_t *)plaintext1;
608     plaintext.size = sizeof(plaintext1);
609 
610     struct hks_blob ciphertext;
611     ciphertext.data = (uint8_t *)ciphertext1;
612     ciphertext.size = sizeof(ciphertext1);
613 
614     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
615     EXPECT_EQ(NUM134, status);
616 }
617 
618 /*
619  * @tc.number    : SUB_SEC_DataPro_HuksL1_0620
620  * @tc.name      : Aead Encrypt, abnormal input parameters keyParam.key_type is not equal to HKS_KEY_TYPE_AES
621  * @tc.desc      : [C- SECURITY -1500]
622  */
623 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0620, Function | MediumTest | Level2)
624 {
625     char alias[] = "test_hks_aead_encrypt";
626 
627     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
628 
629     int32_t status;
630 
631     struct hks_blob key;
632     key.type = HKS_BLOB_TYPE_KEY;
633     key.data = (uint8_t *)key1;
634     key.size = sizeof(key1);
635 
636     struct hks_key_param keyParam;
637     keyParam.key_type = 0;
638     keyParam.key_len = NUM128;
639     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
640     keyParam.key_mode = HKS_ALG_GCM;
641     keyParam.key_pad = HKS_PADDING_NONE;
642     keyParam.key_auth_id.data = (uint8_t *)alias;
643     keyParam.key_auth_id.size = sizeof(alias);
644     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
645 
646     struct hks_crypt_param cryptParam;
647 
648     struct hks_blob nonce = {0};
649     nonce.data = (uint8_t *)nonce1;
650     nonce.size = sizeof(nonce1);
651 
652     struct hks_blob aad = {0};
653     aad.data = (uint8_t *)aad1;
654     aad.size = sizeof(aad1);
655 
656     cryptParam.nonce = nonce;
657     cryptParam.aad = aad;
658 
659     struct hks_blob plaintext;
660     plaintext.data = (uint8_t *)plaintext1;
661     plaintext.size = sizeof(plaintext1);
662 
663     struct hks_blob ciphertext;
664     ciphertext.data = (uint8_t *)ciphertext1;
665     ciphertext.size = sizeof(ciphertext1);
666 
667     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
668     EXPECT_EQ(NUM134, status);
669 }
670 
671 /*
672  * @tc.number    : SUB_SEC_DataPro_HuksL1_0630
673  * @tc.name      : Aead Encrypt, abnormal input parameters keyParam.key_pad is not equal to HKS_PADDING_NONE
674  * @tc.desc      : [C- SECURITY -1500]
675  */
676 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0630, Function | MediumTest | Level2)
677 {
678     char alias[] = "test_hks_aead_encrypt";
679 
680     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
681 
682     int32_t status;
683     struct hks_blob key;
684     key.type = HKS_BLOB_TYPE_KEY;
685     key.data = (uint8_t *)key1;
686     key.size = sizeof(key1);
687 
688     struct hks_key_param keyParam;
689     keyParam.key_type = HKS_KEY_TYPE_AES;
690     keyParam.key_len = NUM128;
691     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
692     keyParam.key_mode = HKS_ALG_GCM;
693     keyParam.key_pad = NUM88;
694     keyParam.key_auth_id.data = (uint8_t *)alias;
695     keyParam.key_auth_id.size = sizeof(alias);
696     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
697 
698     struct hks_crypt_param cryptParam;
699 
700     struct hks_blob nonce = {0};
701     nonce.data = (uint8_t *)nonce1;
702     nonce.size = sizeof(nonce1);
703 
704     struct hks_blob aad = {0};
705     aad.data = (uint8_t *)aad1;
706     aad.size = sizeof(aad1);
707 
708     cryptParam.nonce = nonce;
709     cryptParam.aad = aad;
710 
711     struct hks_blob plaintext;
712     plaintext.data = (uint8_t *)plaintext1;
713     plaintext.size = sizeof(plaintext1);
714 
715     struct hks_blob ciphertext;
716     ciphertext.data = (uint8_t *)ciphertext1;
717     ciphertext.size = sizeof(ciphertext1);
718 
719     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
720     EXPECT_EQ(NUM134, status);
721 }
722 
723 /*
724  * @tc.number    : SUB_SEC_DataPro_HuksL1_0640
725  * @tc.name      : Aead Encrypt, abnormal input parameters keyParam.key_usage
726                    is not equal to HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT
727  * @tc.desc      : [C- SECURITY -1500]
728  */
729 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0640, Function | MediumTest | Level2)
730 {
731     char alias[] = "test_hks_aead_encrypt";
732 
733     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
734 
735     int32_t status;
736 
737     struct hks_blob key;
738     key.type = HKS_BLOB_TYPE_KEY;
739     key.data = (uint8_t *)key1;
740     key.size = sizeof(key1);
741 
742     struct hks_key_param keyParam;
743     keyParam.key_type = HKS_KEY_TYPE_AES;
744     keyParam.key_len = NUM128;
745     keyParam.key_usage = 0;
746     keyParam.key_mode = HKS_ALG_GCM;
747     keyParam.key_pad = HKS_PADDING_NONE;
748     keyParam.key_auth_id.data = (uint8_t *)alias;
749     keyParam.key_auth_id.size = sizeof(alias);
750     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
751 
752     struct hks_crypt_param cryptParam;
753 
754     struct hks_blob nonce = {0};
755     nonce.data = (uint8_t *)nonce1;
756     nonce.size = sizeof(nonce1);
757 
758     struct hks_blob aad = {0};
759     aad.data = (uint8_t *)aad1;
760     aad.size = sizeof(aad1);
761 
762     cryptParam.nonce = nonce;
763     cryptParam.aad = aad;
764 
765     struct hks_blob plaintext;
766     plaintext.data = (uint8_t *)plaintext1;
767     plaintext.size = sizeof(plaintext1);
768 
769     struct hks_blob ciphertext;
770     ciphertext.data = (uint8_t *)ciphertext1;
771     ciphertext.size = sizeof(ciphertext1);
772 
773     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
774     EXPECT_EQ(NUM134, status);
775 }
776 
777 /*
778  * @tc.number    : SUB_SEC_DataPro_HuksL1_0650
779  * @tc.name      : Aead Encrypt, abnormal input parameters cryptParam is null
780  * @tc.desc      : [C- SECURITY -1500]
781  */
782 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0650, Function | MediumTest | Level2)
783 {
784     char alias[] = "test_hks_aead_encrypt";
785 
786     uint8_t key1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
787 
788     int32_t status;
789 
790     struct hks_blob key;
791     key.type = HKS_BLOB_TYPE_KEY;
792     key.data = (uint8_t *)key1;
793     key.size = sizeof(key1);
794 
795     struct hks_key_param keyParam;
796     keyParam.key_type = HKS_KEY_TYPE_AES;
797     keyParam.key_len = NUM128;
798     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
799     keyParam.key_mode = HKS_ALG_GCM;
800     keyParam.key_pad = HKS_PADDING_NONE;
801     keyParam.key_auth_id.data = (uint8_t *)alias;
802     keyParam.key_auth_id.size = sizeof(alias);
803     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
804 
805     struct hks_crypt_param *cryptParam = nullptr;
806 
807 
808     struct hks_blob plaintext;
809     plaintext.data = (uint8_t *)plaintext1;
810     plaintext.size = sizeof(plaintext1);
811 
812     struct hks_blob ciphertext;
813     ciphertext.data = (uint8_t *)ciphertext1;
814     ciphertext.size = sizeof(ciphertext1);
815 
816     status = hks_aead_encrypt(&key, &keyParam, cryptParam, &plaintext, &ciphertext);
817     EXPECT_EQ(NUM1000, status);
818 }
819 
820 /*
821  * @tc.number    : SUB_SEC_DataPro_HuksL1_0660
822  * @tc.name      : Aead Encrypt, abnormal input parameters nonce.size is less than 12
823  * @tc.desc      : [C- SECURITY -1500]
824  */
825 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0660, Function | MediumTest | Level2)
826 {
827     char alias[] = "test_hks_aead_encrypt";
828 
829     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
830 
831     int32_t status;
832 
833     struct hks_blob key;
834     key.type = HKS_BLOB_TYPE_KEY;
835     key.data = (uint8_t *)key1;
836     key.size = sizeof(key1);
837 
838     struct hks_key_param keyParam;
839     keyParam.key_type = HKS_KEY_TYPE_AES;
840     keyParam.key_len = NUM128;
841     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
842     keyParam.key_mode = HKS_ALG_GCM;
843     keyParam.key_pad = HKS_PADDING_NONE;
844     keyParam.key_auth_id.data = (uint8_t *)alias;
845     keyParam.key_auth_id.size = sizeof(alias);
846     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
847 
848     struct hks_crypt_param cryptParam;
849 
850     struct hks_blob nonce = {0};
851     nonce.data = (uint8_t *)nonce1;
852     nonce.size = NUM10;
853 
854     struct hks_blob aad = {0};
855     aad.data = (uint8_t *)aad1;
856     aad.size = sizeof(aad1);
857 
858     cryptParam.nonce = nonce;
859     cryptParam.aad = aad;
860 
861     struct hks_blob plaintext;
862     plaintext.data = (uint8_t *)plaintext1;
863     plaintext.size = sizeof(plaintext1);
864 
865     struct hks_blob ciphertext;
866     ciphertext.data = (uint8_t *)ciphertext1;
867     ciphertext.size = sizeof(ciphertext1);
868 
869     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
870     EXPECT_EQ(NUM135, status);
871 }
872 
873 /*
874  * @tc.number    : SUB_SEC_DataPro_HuksL1_0670
875  * @tc.name      : Aead Encrypt, abnormal input parameters nonce.data is null
876  * @tc.desc      : [C- SECURITY -1500]
877  */
878 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0670, Function | MediumTest | Level2)
879 {
880     char alias[] = "test_hks_aead_encrypt";
881 
882     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
883 
884     int32_t status;
885 
886     struct hks_blob key;
887     key.type = HKS_BLOB_TYPE_KEY;
888     key.data = (uint8_t *)key1;
889     key.size = sizeof(key1);
890 
891     struct hks_key_param keyParam;
892     keyParam.key_type = HKS_KEY_TYPE_AES;
893     keyParam.key_len = NUM128;
894     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
895     keyParam.key_mode = HKS_ALG_GCM;
896     keyParam.key_pad = HKS_PADDING_NONE;
897     keyParam.key_auth_id.data = (uint8_t *)alias;
898     keyParam.key_auth_id.size = sizeof(alias);
899     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
900 
901     struct hks_crypt_param cryptParam;
902 
903     struct hks_blob nonce = {0};
904     nonce.data = NULL;
905     nonce.size = sizeof(nonce1);
906 
907     struct hks_blob aad = {0};
908     aad.data = (uint8_t *)aad1;
909     aad.size = sizeof(aad1);
910 
911     cryptParam.nonce = nonce;
912     cryptParam.aad = aad;
913 
914     struct hks_blob plaintext;
915     plaintext.data = (uint8_t *)plaintext1;
916     plaintext.size = sizeof(plaintext1);
917 
918     struct hks_blob ciphertext;
919     ciphertext.data = (uint8_t *)ciphertext1;
920     ciphertext.size = sizeof(ciphertext1);
921 
922     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
923     EXPECT_EQ(NUM135, status);
924 }
925 
926 /*
927  * @tc.number    : SUB_SEC_DataPro_HuksL1_0680
928  * @tc.name      : Aead Encrypt, abnormal input parameters aad.size is 0
929  * @tc.desc      : [C- SECURITY -1500]
930  */
931 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0680, Function | MediumTest | Level2)
932 {
933     char alias[] = "test_hks_aead_encrypt";
934 
935     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
936 
937     int32_t status;
938 
939     struct hks_blob key;
940     key.type = HKS_BLOB_TYPE_KEY;
941     key.data = (uint8_t *)key1;
942     key.size = sizeof(key1);
943 
944     struct hks_key_param keyParam;
945     keyParam.key_type = HKS_KEY_TYPE_AES;
946     keyParam.key_len = NUM128;
947     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
948     keyParam.key_mode = HKS_ALG_GCM;
949     keyParam.key_pad = HKS_PADDING_NONE;
950     keyParam.key_auth_id.data = (uint8_t *)alias;
951     keyParam.key_auth_id.size = sizeof(alias);
952     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
953 
954     struct hks_crypt_param cryptParam;
955 
956     struct hks_blob nonce = {0};
957     nonce.data = (uint8_t *)nonce1;
958     nonce.size = sizeof(nonce1);
959 
960     struct hks_blob aad = {0};
961     aad.data = (uint8_t *)aad1;
962     aad.size = 0;
963 
964     cryptParam.nonce = nonce;
965     cryptParam.aad = aad;
966 
967     struct hks_blob plaintext;
968     plaintext.data = (uint8_t *)plaintext1;
969     plaintext.size = sizeof(plaintext1);
970 
971     struct hks_blob ciphertext;
972     ciphertext.data = (uint8_t *)ciphertext1;
973     ciphertext.size = sizeof(ciphertext1);
974 
975     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
976     EXPECT_EQ(NUM135, status);
977 }
978 
979 /*
980  * @tc.number    : SUB_SEC_DataPro_HuksL1_0690
981  * @tc.name      : Aead Encrypt, abnormal input parameters aad.data is null
982  * @tc.desc      : [C- SECURITY -1500]
983  */
984 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0690, Function | MediumTest | Level2)
985 {
986     char alias[] = "test_hks_aead_encrypt";
987 
988     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
989 
990     int32_t status;
991 
992     struct hks_blob key;
993     key.type = HKS_BLOB_TYPE_KEY;
994     key.data = (uint8_t *)key1;
995     key.size = sizeof(key1);
996 
997     struct hks_key_param keyParam;
998     keyParam.key_type = HKS_KEY_TYPE_AES;
999     keyParam.key_len = NUM128;
1000     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1001     keyParam.key_mode = HKS_ALG_GCM;
1002     keyParam.key_pad = HKS_PADDING_NONE;
1003     keyParam.key_auth_id.data = (uint8_t *)alias;
1004     keyParam.key_auth_id.size = sizeof(alias);
1005     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1006 
1007     struct hks_crypt_param cryptParam;
1008 
1009     struct hks_blob nonce = {0};
1010     nonce.data = (uint8_t *)nonce1;
1011     nonce.size = sizeof(nonce1);
1012 
1013     struct hks_blob aad = {0};
1014     aad.data = NULL;
1015     aad.size = sizeof(aad1);
1016 
1017     cryptParam.nonce = nonce;
1018     cryptParam.aad = aad;
1019 
1020     struct hks_blob plaintext;
1021     plaintext.data = (uint8_t *)plaintext1;
1022     plaintext.size = sizeof(plaintext1);
1023 
1024     struct hks_blob ciphertext;
1025     ciphertext.data = (uint8_t *)ciphertext1;
1026     ciphertext.size = sizeof(ciphertext1);
1027 
1028     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
1029     EXPECT_EQ(NUM135, status);
1030 }
1031 
1032 /*
1033  * @tc.number    : SUB_SEC_DataPro_HuksL1_0700
1034  * @tc.name      : Aead Encrypt, abnormal input parameters plaintext is null
1035  * @tc.desc      : [C- SECURITY -1500]
1036  */
1037 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0700, Function | MediumTest | Level2)
1038 {
1039     char alias[] = "test_hks_aead_encrypt";
1040 
1041     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], ciphertext1[NUM100];
1042 
1043     int32_t status;
1044 
1045     struct hks_blob key;
1046     key.type = HKS_BLOB_TYPE_KEY;
1047     key.data = (uint8_t *)key1;
1048     key.size = sizeof(key1);
1049 
1050     struct hks_key_param keyParam;
1051     keyParam.key_type = HKS_KEY_TYPE_AES;
1052     keyParam.key_len = NUM128;
1053     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1054     keyParam.key_mode = HKS_ALG_GCM;
1055     keyParam.key_pad = HKS_PADDING_NONE;
1056     keyParam.key_auth_id.data = (uint8_t *)alias;
1057     keyParam.key_auth_id.size = sizeof(alias);
1058     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1059 
1060     struct hks_crypt_param cryptParam;
1061 
1062     struct hks_blob nonce = {0};
1063     nonce.data = (uint8_t *)nonce1;
1064     nonce.size = sizeof(nonce1);
1065 
1066     struct hks_blob aad = {0};
1067     aad.data = (uint8_t *)aad1;
1068     aad.size = sizeof(aad1);
1069 
1070     cryptParam.nonce = nonce;
1071     cryptParam.aad = aad;
1072 
1073     struct hks_blob *plaintext = nullptr;
1074 
1075     struct hks_blob ciphertext;
1076     ciphertext.data = (uint8_t *)ciphertext1;
1077     ciphertext.size = sizeof(ciphertext1);
1078 
1079     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, plaintext, &ciphertext);
1080     EXPECT_EQ(NUM1000, status);
1081 }
1082 
1083 /*
1084  * @tc.number    : SUB_SEC_DataPro_HuksL1_0710
1085  * @tc.name      : Aead Encrypt, abnormal input parameters plaintext.data is null
1086  * @tc.desc      : [C- SECURITY -1500]
1087  */
1088 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0710, Function | MediumTest | Level2)
1089 {
1090     char alias[] = "test_hks_aead_encrypt";
1091 
1092     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
1093 
1094     int32_t status;
1095 
1096     struct hks_blob key;
1097     key.type = HKS_BLOB_TYPE_KEY;
1098     key.data = (uint8_t *)key1;
1099     key.size = sizeof(key1);
1100 
1101     struct hks_key_param keyParam;
1102     keyParam.key_type = HKS_KEY_TYPE_AES;
1103     keyParam.key_len = NUM128;
1104     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1105     keyParam.key_mode = HKS_ALG_GCM;
1106     keyParam.key_pad = HKS_PADDING_NONE;
1107     keyParam.key_auth_id.data = (uint8_t *)alias;
1108     keyParam.key_auth_id.size = sizeof(alias);
1109     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1110 
1111     struct hks_crypt_param cryptParam;
1112 
1113     struct hks_blob nonce = {0};
1114     nonce.data = (uint8_t *)nonce1;
1115     nonce.size = sizeof(nonce1);
1116 
1117     struct hks_blob aad = {0};
1118     aad.data = (uint8_t *)aad1;
1119     aad.size = sizeof(aad1);
1120 
1121     cryptParam.nonce = nonce;
1122     cryptParam.aad = aad;
1123 
1124     struct hks_blob plaintext;
1125     plaintext.data = NULL;
1126     plaintext.size = sizeof(plaintext1);
1127 
1128     struct hks_blob ciphertext;
1129     ciphertext.data = (uint8_t *)ciphertext1;
1130     ciphertext.size = sizeof(ciphertext1);
1131 
1132     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
1133     EXPECT_EQ(NUM135, status);
1134 }
1135 
1136 /*
1137  * @tc.number    : SUB_SEC_DataPro_HuksL1_0720
1138  * @tc.name      : Aead Encrypt, abnormal input parameters plaintext.size is 0
1139  * @tc.desc      : [C- SECURITY -1500]
1140  */
1141 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0720, Function | MediumTest | Level2)
1142 {
1143     char alias[] = "test_hks_aead_encrypt";
1144 
1145     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
1146 
1147     int32_t status;
1148 
1149     struct hks_blob key;
1150     key.type = HKS_BLOB_TYPE_KEY;
1151     key.data = (uint8_t *)key1;
1152     key.size = sizeof(key1);
1153 
1154     struct hks_key_param keyParam;
1155     keyParam.key_type = HKS_KEY_TYPE_AES;
1156     keyParam.key_len = NUM128;
1157     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1158     keyParam.key_mode = HKS_ALG_GCM;
1159     keyParam.key_pad = HKS_PADDING_NONE;
1160     keyParam.key_auth_id.data = (uint8_t *)alias;
1161     keyParam.key_auth_id.size = sizeof(alias);
1162     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1163 
1164     struct hks_crypt_param cryptParam;
1165 
1166     struct hks_blob nonce = {0};
1167     nonce.data = (uint8_t *)nonce1;
1168     nonce.size = sizeof(nonce1);
1169 
1170     struct hks_blob aad = {0};
1171     aad.data = (uint8_t *)aad1;
1172     aad.size = sizeof(aad1);
1173 
1174     cryptParam.nonce = nonce;
1175     cryptParam.aad = aad;
1176 
1177     struct hks_blob plaintext;
1178     plaintext.data = (uint8_t *)plaintext1;
1179     plaintext.size = 0;
1180 
1181     struct hks_blob ciphertext;
1182     ciphertext.data = (uint8_t *)ciphertext1;
1183     ciphertext.size = sizeof(ciphertext1);
1184 
1185     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
1186     EXPECT_EQ(NUM135, status);
1187 }
1188 
1189 /*
1190  * @tc.number    : SUB_SEC_DataPro_HuksL1_0730
1191  * @tc.name      : Aead Encrypt, abnormal input parameters ciphertext is null
1192  * @tc.desc      : [C- SECURITY -1500]
1193  */
1194 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0730, Function | MediumTest | Level2)
1195 {
1196     char alias[] = "test_hks_aead_encrypt";
1197 
1198     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64];
1199 
1200     int32_t status;
1201 
1202     struct hks_blob key;
1203     key.type = HKS_BLOB_TYPE_KEY;
1204     key.data = (uint8_t *)key1;
1205     key.size = sizeof(key1);
1206 
1207     struct hks_key_param keyParam;
1208     keyParam.key_type = HKS_KEY_TYPE_AES;
1209     keyParam.key_len = NUM128;
1210     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1211     keyParam.key_mode = HKS_ALG_GCM;
1212     keyParam.key_pad = HKS_PADDING_NONE;
1213     keyParam.key_auth_id.data = (uint8_t *)alias;
1214     keyParam.key_auth_id.size = sizeof(alias);
1215     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1216 
1217     struct hks_crypt_param cryptParam;
1218 
1219     struct hks_blob nonce = {0};
1220     nonce.data = (uint8_t *)nonce1;
1221     nonce.size = sizeof(nonce1);
1222 
1223     struct hks_blob aad = {0};
1224     aad.data = (uint8_t *)aad1;
1225     aad.size = sizeof(aad1);
1226 
1227     cryptParam.nonce = nonce;
1228     cryptParam.aad = aad;
1229 
1230     struct hks_blob plaintext;
1231     plaintext.data = (uint8_t *)plaintext1;
1232     plaintext.size = sizeof(plaintext1);
1233 
1234     struct hks_blob *ciphertext = nullptr;
1235     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, ciphertext);
1236     EXPECT_EQ(NUM1000, status);
1237 }
1238 
1239 /*
1240  * @tc.number    : SUB_SEC_DataPro_HuksL1_0740
1241  * @tc.name      : Aead Encrypt, abnormal input parameters ciphertext.data is null
1242  * @tc.desc      : [C- SECURITY -1500]
1243  */
1244 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0740, Function | MediumTest | Level2)
1245 {
1246     char alias[] = "test_hks_aead_encrypt";
1247 
1248     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
1249 
1250     int32_t status;
1251 
1252     struct hks_blob key;
1253     key.type = HKS_BLOB_TYPE_KEY;
1254     key.data = (uint8_t *)key1;
1255     key.size = sizeof(key1);
1256 
1257     struct hks_key_param keyParam;
1258     keyParam.key_type = HKS_KEY_TYPE_AES;
1259     keyParam.key_len = NUM128;
1260     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1261     keyParam.key_mode = HKS_ALG_GCM;
1262     keyParam.key_pad = HKS_PADDING_NONE;
1263     keyParam.key_auth_id.data = (uint8_t *)alias;
1264     keyParam.key_auth_id.size = sizeof(alias);
1265     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1266 
1267     struct hks_crypt_param cryptParam;
1268 
1269     struct hks_blob nonce = {0};
1270     nonce.data = (uint8_t *)nonce1;
1271     nonce.size = sizeof(nonce1);
1272 
1273     struct hks_blob aad = {0};
1274     aad.data = (uint8_t *)aad1;
1275     aad.size = sizeof(aad1);
1276 
1277     cryptParam.nonce = nonce;
1278     cryptParam.aad = aad;
1279 
1280     struct hks_blob plaintext;
1281     plaintext.data = (uint8_t *)plaintext1;
1282     plaintext.size = sizeof(plaintext1);
1283 
1284     struct hks_blob ciphertext;
1285     ciphertext.data = NULL;
1286     ciphertext.size = sizeof(ciphertext1);
1287 
1288     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
1289     EXPECT_EQ(NUM135, status);
1290 }
1291 
1292 /*
1293  * @tc.number    : SUB_SEC_DataPro_HuksL1_0750
1294  * @tc.name      : Aead Encrypt, abnormal input parameters ciphertext.size is less than plaintext.size minus 16
1295  * @tc.desc      : [C- SECURITY -1500]
1296  */
1297 HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0750, Function | MediumTest | Level2)
1298 {
1299     char alias[] = "test_hks_aead_encrypt";
1300 
1301     uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100];
1302 
1303     int32_t status;
1304     struct hks_blob key;
1305     key.type = HKS_BLOB_TYPE_KEY;
1306     key.data = (uint8_t *)key1;
1307     key.size = sizeof(key1);
1308 
1309     struct hks_key_param keyParam;
1310     keyParam.key_type = HKS_KEY_TYPE_AES;
1311     keyParam.key_len = NUM128;
1312     keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT;
1313     keyParam.key_mode = HKS_ALG_GCM;
1314     keyParam.key_pad = HKS_PADDING_NONE;
1315     keyParam.key_auth_id.data = (uint8_t *)alias;
1316     keyParam.key_auth_id.size = sizeof(alias);
1317     keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID;
1318 
1319     struct hks_crypt_param cryptParam;
1320 
1321     struct hks_blob nonce = {0};
1322     nonce.data = (uint8_t *)nonce1;
1323     nonce.size = sizeof(nonce1);
1324 
1325     struct hks_blob aad = {0};
1326     aad.data = (uint8_t *)aad1;
1327     aad.size = sizeof(aad1);
1328 
1329     cryptParam.nonce = nonce;
1330     cryptParam.aad = aad;
1331 
1332     struct hks_blob plaintext;
1333     plaintext.data = (uint8_t *)plaintext1;
1334     plaintext.size = sizeof(plaintext1);
1335 
1336     struct hks_blob ciphertext;
1337     ciphertext.data = (uint8_t *)ciphertext1;
1338     ciphertext.size = NUM10;
1339 
1340     status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext);
1341     EXPECT_EQ(NUM135, status);
1342 }
1343 
1344 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Encrypt key
1345 // end==++++++++++++++++++++++++++++++++++++++++++++++++++++0520-0750
1346 
1347