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