• 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 SecurityDataHuksExportHashRandomHmacTestSuite
29  */
30 LITE_TEST_SUIT(security, securityData, SecurityDataHuksExportHashRandomHmacTestSuite);
31 
32 /* *
33  * @tc.setup     : setup for all testcases
34  * @return       : setup result, TRUE is success, FALSE is fail
35  */
SecurityDataHuksExportHashRandomHmacTestSuiteSetUp(void)36 static BOOL SecurityDataHuksExportHashRandomHmacTestSuiteSetUp(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  */
SecurityDataHuksExportHashRandomHmacTestSuiteTearDown(void)51 static BOOL SecurityDataHuksExportHashRandomHmacTestSuiteTearDown(void)
52 {
53     printf("-++++++++++++++++++++++++++++++++++++++++++++-\n");
54     return TRUE;
55 }
56 #ifndef _CUT_AUTHENTICATE_
57 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Export Public key
58 // begin++++++++++++++++++++++++++++++++++++++++++++++1000-1090
59 
60 /*
61  * @tc.number    : SUB_SEC_DataPro_HuksL0_1000
62  * @tc.name      : Export Public Key, normal input parameters keyAlias and publicKey
63  * @tc.desc      : [C- SECURITY -1800]
64  */
65 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
66 securityDataExportPublicKey1000, Function | MediumTest | Level1)
67 {
68     int32_t status;
69     char testFileName[] = "keyalias1";
70     struct hks_blob keyAlias = { 0 };
71 
72     keyAlias.data = (uint8_t *)testFileName;
73     keyAlias.size = sizeof(testFileName);
74     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
75 
76     (void)TestSecShuksGenerateKeyNormal();
77 
78     struct hks_blob publicKey1 = { 0 };
79     HksStBlobInit1(&publicKey1, 1, NUM32, HKS_BLOB_TYPE_KEY);
80     status = hks_export_public_key(&keyAlias, &publicKey1);
81     TEST_ASSERT_EQUAL_INT(0, status);
82     HksBlobDestroyT1(&publicKey1);
83     (void)TestSecShuksDeleteKeyNormal();
84 };
85 
86 /*
87  * @tc.number    : SUB_SEC_DataPro_HuksL0_1010
88  * @tc.name      : Export Public Key, abnormal input parameters keyAlias is null
89  * @tc.desc      : [C- SECURITY -1800]
90  */
91 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
92 securityDataExportPublicKey1010, Function | MediumTest | Level2)
93 {
94     int32_t status;
95     struct hks_blob *keyAlias = NULL;
96     struct hks_blob publicKey1 = { 0 };
97 
98     publicKey1.data = (uint8_t *)malloc(NUM32);
99     if (publicKey1.data == NULL) {
100         return;
101     }
102     publicKey1.size = NUM32;
103     publicKey1.type = HKS_BLOB_TYPE_KEY;
104 
105     status = hks_export_public_key(keyAlias, &publicKey1);
106     TEST_ASSERT_EQUAL_INT(NUM1000, status);
107     HksBlobDestroyT1(&publicKey1);
108 }
109 
110 /*
111  * @tc.number    : SUB_SEC_DataPro_HuksL0_1020
112  * @tc.name      : Export Public Key, abnormal input parameters keyAlias.data is null
113  * @tc.desc      : [C- SECURITY -1800]
114  */
115 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
116 securityDataExportPublicKey1020, Function | MediumTest | Level2)
117 {
118     int32_t status;
119     char testFileName[] = "Test_file_north_interfaces";
120     struct hks_blob keyAlias = { 0 };
121     struct hks_blob publicKey1 = { 0 };
122     keyAlias.data = NULL;
123     keyAlias.size = sizeof(testFileName);
124     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
125 
126     publicKey1.data = (uint8_t *)malloc(NUM32);
127     if (publicKey1.data == NULL) {
128         return;
129     }
130     publicKey1.size = NUM32;
131     publicKey1.type = HKS_BLOB_TYPE_KEY;
132 
133     status = hks_export_public_key(&keyAlias, &publicKey1);
134     TEST_ASSERT_EQUAL_INT(NUM135, status);
135     HksBlobDestroyT1(&publicKey1);
136 }
137 
138 /*
139  * @tc.number    : SUB_SEC_DataPro_HuksL0_1030
140  * @tc.name      : Export Public Key, abnormal input parameters keyAlias.type is not equal to HKS_BLOB_TYPE_ALIAS
141  * @tc.desc      : [C- SECURITY -1800]
142  */
143 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
144 securityDataExportPublicKey1030, Function | MediumTest | Level2)
145 {
146     int32_t status;
147     char testFileName[] = "Test_file_north_interfaces";
148     struct hks_blob keyAlias = { 0 };
149     struct hks_blob publicKey1 = { 0 };
150     keyAlias.data = (uint8_t *)testFileName;
151     keyAlias.size = sizeof(testFileName);
152     keyAlias.type = 0;
153 
154     publicKey1.data = (uint8_t *)malloc(NUM32);
155     if (publicKey1.data == NULL) {
156         return;
157     }
158     publicKey1.size = NUM32;
159     publicKey1.type = HKS_BLOB_TYPE_KEY;
160 
161     status = hks_export_public_key(&keyAlias, &publicKey1);
162     TEST_ASSERT_EQUAL_INT(NUM135, status);
163     HksBlobDestroyT1(&publicKey1);
164 }
165 
166 /*
167  * @tc.number    : SUB_SEC_DataPro_HuksL0_1040
168  * @tc.name      : Export Public Key, abnormal input parameters keyAlias.size is 0
169  * @tc.desc      : [C- SECURITY -1800]
170  */
171 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
172 securityDataExportPublicKey1040, Function | MediumTest | Level2)
173 {
174     int32_t status;
175     char testFileName[] = "Test_file_north_interfaces";
176     struct hks_blob keyAlias = { 0 };
177     struct hks_blob publicKey1 = { 0 };
178 
179     keyAlias.data = (uint8_t *)testFileName;
180     keyAlias.size = 0;
181     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
182 
183     publicKey1.data = (uint8_t *)malloc(NUM32);
184     if (publicKey1.data == NULL) {
185         return;
186     }
187     publicKey1.size = NUM32;
188     publicKey1.type = HKS_BLOB_TYPE_KEY;
189 
190     status = hks_export_public_key(&keyAlias, &publicKey1);
191     TEST_ASSERT_EQUAL_INT(NUM135, status);
192     HksBlobDestroyT1(&publicKey1);
193 }
194 
195 /*
196  * @tc.number    : SUB_SEC_DataPro_HuksL0_1050
197  * @tc.name      : Export Public Key, abnormal input parameters keyAlias.size is more than 64
198  * @tc.desc      : [C- SECURITY -1800]
199  */
200 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
201 securityDataExportPublicKey1050, Function | MediumTest | Level2)
202 {
203     int32_t status;
204     char testFileName[] = "Test_file_north_interfaces";
205     struct hks_blob keyAlias = { 0 };
206     struct hks_blob publicKey1 = { 0 };
207 
208     keyAlias.data = (uint8_t *)testFileName;
209     keyAlias.size = NUM65;
210     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
211 
212     publicKey1.data = (uint8_t *)malloc(NUM32);
213     if (publicKey1.data == NULL) {
214         return;
215     }
216     publicKey1.size = NUM32;
217     publicKey1.type = HKS_BLOB_TYPE_KEY;
218 
219     status = hks_export_public_key(&keyAlias, &publicKey1);
220     TEST_ASSERT_EQUAL_INT(NUM135, status);
221     HksBlobDestroyT1(&publicKey1);
222 }
223 
224 /*
225  * @tc.number    : SUB_SEC_DataPro_HuksL0_1060
226  * @tc.name      : Export Public Key, abnormal input parameters publicKey is null
227  * @tc.desc      : [C- SECURITY -1800]
228  */
229 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
230 securityDataExportPublicKey1060, Function | MediumTest | Level2)
231 {
232     int32_t status;
233     char testFileName[] = "Test_file_north_interfaces";
234     struct hks_blob keyAlias = { 0 };
235     struct hks_blob *publicKey1 = NULL;
236 
237     keyAlias.data = (uint8_t *)testFileName;
238     keyAlias.size = sizeof(testFileName);
239     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
240 
241     status = hks_export_public_key(&keyAlias, publicKey1);
242     TEST_ASSERT_EQUAL_INT(NUM1000, status);
243     HksBlobDestroyT1(&keyAlias);
244 }
245 
246 /*
247  * @tc.number    : SUB_SEC_DataPro_HuksL0_1070
248  * @tc.name      : Export Public Key, abnormal input parameters publicKey.size is less than 32
249  * @tc.desc      : [C- SECURITY -1800]
250  */
251 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
252 securityDataExportPublicKey1070, Function | MediumTest | Level2)
253 {
254     int32_t status;
255     char testFileName[] = "Test_file_north_interfaces";
256     struct hks_blob keyAlias = { 0 };
257     struct hks_blob publicKey1 = { 0 };
258 
259     keyAlias.data = (uint8_t *)testFileName;
260     keyAlias.size = sizeof(testFileName);
261     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
262 
263     publicKey1.data = (uint8_t *)malloc(NUM31);
264     if (publicKey1.data == NULL) {
265         return;
266     }
267     publicKey1.size = NUM31;
268     publicKey1.type = HKS_BLOB_TYPE_KEY;
269 
270     status = hks_export_public_key(&keyAlias, &publicKey1);
271     TEST_ASSERT_EQUAL_INT(NUM1007, status);
272     HksBlobDestroyT1(&publicKey1);
273 }
274 
275 /*
276  * @tc.number    : SUB_SEC_DataPro_HuksL0_1080
277  * @tc.name      : Export Public Key, abnormal input parameters publicKey.data is null
278  * @tc.desc      : [C- SECURITY -1800]
279  */
280 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
281 securityDataExportPublicKey1080, Function | MediumTest | Level2)
282 {
283     int32_t status;
284     char testFileName[] = "Test_file_north_interfaces";
285     struct hks_blob keyAlias = { 0 };
286     struct hks_blob publicKey1 = { 0 };
287 
288     keyAlias.data = (uint8_t *)testFileName;
289     keyAlias.size = sizeof(testFileName);
290     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
291 
292     publicKey1.data = NULL;
293     publicKey1.size = NUM32;
294     publicKey1.type = HKS_BLOB_TYPE_KEY;
295 
296     status = hks_export_public_key(&keyAlias, &publicKey1);
297     TEST_ASSERT_EQUAL_INT(NUM1007, status);
298     HksBlobDestroyT1(&publicKey1);
299 }
300 
301 /*
302  * @tc.number    : SUB_SEC_DataPro_HuksL0_1090
303  * @tc.name      : Export Public Key, the key does not exist
304  * @tc.desc      : [C- SECURITY -1800]
305  */
306 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
307 securityDataExportPublicKey1090, Function | MediumTest | Level2)
308 {
309     int32_t status;
310     char testFileName[] = "Test_file_north_interfaces";
311     struct hks_blob keyAlias = { 0 };
312     struct hks_blob publicKey1 = { 0 };
313 
314     keyAlias.data = (uint8_t *)testFileName;
315     keyAlias.size = sizeof(testFileName);
316     keyAlias.type = HKS_BLOB_TYPE_ALIAS;
317 
318     publicKey1.data = (uint8_t *)malloc(NUM32);
319     if (publicKey1.data == NULL) {
320         return;
321     }
322     publicKey1.size = NUM32;
323     publicKey1.type = HKS_BLOB_TYPE_KEY;
324 
325     status = hks_export_public_key(&keyAlias, &publicKey1);
326     TEST_ASSERT_EQUAL_INT(NUM1010, status);
327     HksBlobDestroyT1(&publicKey1);
328 }
329 #endif
330 
331 #ifndef _CUT_AUTHENTICATE_
332 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Export Public key
333 // end++++++++++++++++++++++++++++++++++++++++++++++++1000-1090
334 
335 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Hash
336 // begin+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++1100-1190
337 
338 /*
339  * @tc.number    : SUB_SEC_DataPro_HuksL0_1100
340  * @tc.name      : Hash, normal input parameters SHA256, src, dst
341  * @tc.desc      : [C- SOFTWARE -0200]
342  */
343 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1100, Function | MediumTest | Level1)
344 {
345     struct hks_blob src, dst;
346     src.data = (uint8_t *)"123456";
347     src.size = NUM6;
348     dst.data = (uint8_t *)malloc(NUM65);
349     if (dst.data == NULL) {
350         return;
351     }
352     dst.size = NUM65;
353 
354     int32_t res = hks_hash(HKS_ALG_HASH_SHA_256, &src, &dst);
355     TEST_ASSERT_EQUAL_INT(0, res);
356     free(dst.data);
357 };
358 
359 /*
360  * @tc.number    : SUB_SEC_DataPro_HuksL0_1110
361  * @tc.name      : Hash, normal input parameters SHA512, src, dst
362  * @tc.desc      : [C- SOFTWARE -0200]
363  */
364 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1110, Function | MediumTest | Level1)
365 {
366     struct hks_blob src, dst;
367     src.data = (uint8_t *)"123456";
368     src.size = NUM6;
369     dst.data = (uint8_t *)malloc(NUM65);
370     if (dst.data == NULL) {
371         return;
372     }
373     dst.size = NUM65;
374 
375     int32_t res = hks_hash(HKS_ALG_HASH_SHA_512, &src, &dst);
376     TEST_ASSERT_EQUAL_INT(0, res);
377     free(dst.data);
378 };
379 
380 /*
381  * @tc.number    : SUB_SEC_DataPro_HuksL0_1120
382  * @tc.name      : Hash, normal input parameters alg is not equal to HKS_ALG_HASH_SHA_256 or HKS_ALG_HASH_SHA_512
383  * @tc.desc      : [C- SOFTWARE -0200]
384  */
385 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1120, Function | MediumTest | Level2)
386 {
387     struct hks_blob srcData = { 0 };
388     const char tmpData6[] = "30313233343536373839616263646566";
389     BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0);
390 
391     struct hks_blob hash = { 0 };
392     const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566";
393     BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0);
394 
395     uint32_t alg = HKS_ALG_HASH_SHA_1;
396     int32_t status = hks_hash(alg, &srcData, &hash);
397     HksBlobDestroyT1(&srcData);
398     HksBlobDestroyT1(&hash);
399     TEST_ASSERT_EQUAL_INT(NUM135, status);
400 }
401 
402 /*
403  * @tc.number    : SUB_SEC_DataPro_HuksL0_1130
404  * @tc.name      : Hash, normal input parameters srcData is null
405  * @tc.desc      : [C- SOFTWARE -0200]
406  */
407 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1130, Function | MediumTest | Level2)
408 {
409     struct hks_blob *srcData = NULL;
410 
411     struct hks_blob hash = { 0 };
412     const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566";
413     BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0);
414 
415     uint32_t alg = HKS_ALG_HASH_SHA_256;
416     int32_t status = hks_hash(alg, srcData, &hash);
417     HksBlobDestroyT1(&hash);
418     TEST_ASSERT_EQUAL_INT(NUM1000, status);
419 }
420 
421 /*
422  * @tc.number    : SUB_SEC_DataPro_HuksL0_1140
423  * @tc.name      : Hash, normal input parameters srcData.data is null
424  * @tc.desc      : [C- SOFTWARE -0200]
425  */
426 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1140, Function | MediumTest | Level2)
427 {
428     struct hks_blob srcData = { 0 };
429     const char tmpData6[] = "30313233343536373839616263646566";
430     BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 1);
431 
432     struct hks_blob hash = { 0 };
433     const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566";
434     BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0);
435 
436     uint32_t alg = HKS_ALG_HASH_SHA_256;
437     int32_t status = hks_hash(alg, &srcData, &hash);
438     HksBlobDestroyT1(&srcData);
439     HksBlobDestroyT1(&hash);
440     TEST_ASSERT_EQUAL_INT(NUM1000, status);
441 }
442 
443 /*
444  * @tc.number    : SUB_SEC_DataPro_HuksL0_1150
445  * @tc.name      : Hash, normal input parameters srcData.size is 0
446  * @tc.desc      : [C- SOFTWARE -0200]
447  */
448 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1150, Function | MediumTest | Level2)
449 {
450     struct hks_blob srcData = { 0 };
451     srcData.data = (uint8_t *)"1234567890abcdefghigkl0123456789";
452     srcData.size = 0;
453     srcData.type = HKS_BLOB_TYPE_RAW;
454 
455     struct hks_blob hash = { 0 };
456     const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566";
457     BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0);
458 
459     uint32_t alg = HKS_ALG_HASH_SHA_256;
460     int32_t status = hks_hash(alg, &srcData, &hash);
461     HksBlobDestroyT1(&hash);
462     TEST_ASSERT_EQUAL_INT(NUM1000, status);
463 }
464 
465 /*
466  * @tc.number    : SUB_SEC_DataPro_HuksL0_1160
467  * @tc.name      : Hash, normal input parameters hash is null
468  * @tc.desc      : [C- SOFTWARE -0200]
469  */
470 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1160, Function | MediumTest | Level2)
471 {
472     struct hks_blob srcData = { 0 };
473     const char tmpData6[] = "30313233343536373839616263646566";
474     BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0);
475 
476     struct hks_blob *hash = NULL;
477 
478     uint32_t alg = HKS_ALG_HASH_SHA_256;
479     int32_t status = hks_hash(alg, &srcData, hash);
480     HksBlobDestroyT1(&srcData);
481     TEST_ASSERT_EQUAL_INT(NUM1000, status);
482 }
483 
484 /*
485  * @tc.number    : SUB_SEC_DataPro_HuksL0_1170
486  * @tc.name      : Hash, normal input parameters hash.data is null
487  * @tc.desc      : [C- SOFTWARE -0200]
488  */
489 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1170, Function | MediumTest | Level2)
490 {
491     struct hks_blob srcData = { 0 };
492     const char tmpData6[] = "30313233343536373839616263646566";
493     BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0);
494 
495     struct hks_blob hash = { 0 };
496     const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566";
497     BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 1);
498 
499     uint32_t alg = HKS_ALG_HASH_SHA_256;
500     int32_t status = hks_hash(alg, &srcData, &hash);
501     HksBlobDestroyT1(&srcData);
502     HksBlobDestroyT1(&hash);
503     TEST_ASSERT_EQUAL_INT(NUM1000, status);
504 }
505 
506 /*
507  * @tc.number    : SUB_SEC_DataPro_HuksL0_1180
508  * @tc.name      : Hash, normal input parameters hash.size is less than 32
509  * @tc.desc      : [C- SOFTWARE -0200]
510  */
511 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1180, Function | MediumTest | Level2)
512 {
513     struct hks_blob srcData = { 0 };
514     const char tmpData6[] = "30313233343536373839616263646566";
515     BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0);
516 
517     struct hks_blob hash = { 0 };
518     const char tmpData7[] = "303132333435363738396162636465663031323334353637383961626361";
519     BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM30, 0);
520 
521     uint32_t alg = HKS_ALG_HASH_SHA_256;
522     int32_t status = hks_hash(alg, &srcData, &hash);
523     HksBlobDestroyT1(&srcData);
524     HksBlobDestroyT1(&hash);
525     TEST_ASSERT_EQUAL_INT(NUM1007, status);
526 }
527 
528 /*
529  * @tc.number    : SUB_SEC_DataPro_HuksL0_1190
530  * @tc.name      : Hash, normal input parameters hash.size is less than 64
531  * @tc.desc      : [C- SOFTWARE -0200]
532  */
533 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1190, Function | MediumTest | Level2)
534 {
535     struct hks_blob srcData = { 0 };
536     const char tmpData6[] = "30313233343536373839616263646566";
537     BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0);
538 
539     struct hks_blob hash = { 0 };
540     const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263613031323334353637383961626"
541     "36465663031323334353637383961626361";
542     BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM60, 0);
543 
544     uint32_t alg = HKS_ALG_HASH_SHA_512;
545     int32_t status = hks_hash(alg, &srcData, &hash);
546     HksBlobDestroyT1(&srcData);
547     HksBlobDestroyT1(&hash);
548     TEST_ASSERT_EQUAL_INT(NUM1007, status);
549 }
550 #endif
551 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Hash
552 // end+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++1100-1190
553 
554 
555 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Generate random
556 // beign++++++++++++++++++++++++++++++++++++++++++++++++1200-1230
557 
558 /*
559  * @tc.number    : SUB_SEC_DataPro_HuksL0_1200
560  * @tc.name      : Generate Random, normal input parameters random
561  * @tc.desc      : [C- SECURITY -1700]
562  */
563 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
564 securityDataGenerateRandom1200, Function | MediumTest | Level1)
565 {
566     int32_t statusFirst;
567     int32_t statusSecond;
568     struct hks_blob randomFirst = { 0 };
569     struct hks_blob randomSecond = { 0 };
570 
571     HksStBlobInit1(&randomFirst, 1, NUM64, 0);
572     HksStBlobInit1(&randomSecond, 1, NUM64, 0);
573     statusFirst = hks_generate_random(&randomFirst);
574     statusSecond = hks_generate_random(&randomSecond);
575     TEST_ASSERT_EQUAL_INT(0, statusFirst);
576     TEST_ASSERT_EQUAL_INT(0, statusSecond);
577     TEST_ASSERT_NOT_EQUAL(randomFirst.data, randomSecond.data);
578 
579     HksBlobDestroyT1(&randomFirst);
580     HksBlobDestroyT1(&randomSecond);
581 };
582 
583 /*
584  * @tc.number    : SUB_SEC_DataPro_HuksL0_1210
585  * @tc.name      : Generate Random, normal input parameters random is null
586  * @tc.desc      : [C- SECURITY -1700]
587  */
588 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
589 securityDataGenerateRandom1210, Function | MediumTest | Level2)
590 {
591     int32_t status;
592     struct hks_blob *random = NULL;
593 
594     status = hks_generate_random(random);
595     TEST_ASSERT_EQUAL_INT(NUM1000, status);
596 }
597 
598 /*
599  * @tc.number    : SUB_SEC_DataPro_HuksL0_1220
600  * @tc.name      : Generate Random, normal input parameters random.data is null
601  * @tc.desc      : [C- SECURITY -1700]
602  */
603 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
604 securityDataGenerateRandom1220, Function | MediumTest | Level2)
605 {
606     int32_t status;
607     struct hks_blob random = { 0 };
608 
609     random.data = NULL;
610     random.size = NUM32;
611     random.type = HKS_BLOB_TYPE_KEY;
612 
613     status = hks_generate_random(&random);
614     TEST_ASSERT_EQUAL_INT(NUM1000, status);
615     HksBlobDestroyT1(&random);
616 }
617 
618 /*
619  * @tc.number    : SUB_SEC_DataPro_HuksL0_1230
620  * @tc.name      : Generate Random, normal input parameters random.size is more than 1024
621  * @tc.desc      : [C- SECURITY -1700]
622  */
623 LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite,
624 securityDataGenerateRandom1230, Function | MediumTest | Level2)
625 {
626     int32_t status;
627     struct hks_blob random = { 0 };
628 
629     random.data = (uint8_t *)malloc(NUM1025);
630     if (random.data == NULL) {
631         return;
632     }
633     random.size = NUM1025;
634     random.type = HKS_BLOB_TYPE_KEY;
635 
636     status = hks_generate_random(&random);
637     TEST_ASSERT_EQUAL_INT(NUM135, status);
638     HksBlobDestroyT1(&random);
639 }
640 
641 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Generate random
642 // end++++++++++++++++++++++++++++++++++++++++++++++++++1200-1230
643 
644 RUN_TEST_SUITE(SecurityDataHuksExportHashRandomHmacTestSuite);
645