1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include "securec.h"
18 
19 #include "asy_key_generator.h"
20 #include "ecc_asy_key_generator_openssl.h"
21 #include "blob.h"
22 #include "memory.h"
23 #include "memory_mock.h"
24 #include "openssl_adapter_mock.h"
25 #include "params_parser.h"
26 #include "ecc_key_util.h"
27 #include "key_utils.h"
28 #include "key_pair.h"
29 #include "object_base.h"
30 
31 using namespace std;
32 using namespace testing::ext;
33 
34 namespace {
35 class CryptoBrainPoolAsyKeyGeneratorTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     void SetUp();
40     void TearDown();
41 };
42 
TearDownTestCase()43 void CryptoBrainPoolAsyKeyGeneratorTest::TearDownTestCase() {}
SetUp()44 void CryptoBrainPoolAsyKeyGeneratorTest::SetUp() {}
TearDown()45 void CryptoBrainPoolAsyKeyGeneratorTest::TearDown() {}
46 
47 HcfBlob g_mockECC_BrainPool160r1PriKeyBlob = {
48     .data = nullptr,
49     .len = 0
50 };
51 
52 HcfBlob g_mockECC_BrainPool160r1PubKeyBlob = {
53     .data = nullptr,
54     .len = 0
55 };
56 
57 HcfAsyKeyGenerator *g_160r1Generator = nullptr;
58 HcfKeyPair *g_160r1KeyPair = nullptr;
59 HcfKeyPair *g_160r1ConvertKeyPair = nullptr;
60 
GetMockClass(void)61 static const char *GetMockClass(void)
62 {
63     return "HcfSymKeyGenerator";
64 }
65 
66 HcfObjectBase g_obj = {
67     .getClass = GetMockClass,
68     .destroy = nullptr
69 };
70 
HcfAsyKeyGeneratorCreateTest(const char * algName)71 static HcfResult HcfAsyKeyGeneratorCreateTest(const char *algName)
72 {
73     HcfAsyKeyGenerator *generator = nullptr;
74     HcfResult res = HcfAsyKeyGeneratorCreate(algName, &generator);
75     if (res == HCF_SUCCESS) {
76         HcfObjDestroy(generator);
77     }
78     return res;
79 }
80 
SetUpTestCase()81 void CryptoBrainPoolAsyKeyGeneratorTest::SetUpTestCase()
82 {
83     HcfResult res = HcfAsyKeyGeneratorCreate("ECC_BrainPoolP160r1", &g_160r1Generator);
84     EXPECT_EQ(res, HCF_SUCCESS);
85     res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &g_160r1KeyPair);
86     EXPECT_EQ(res, HCF_SUCCESS);
87     res = g_160r1KeyPair->priKey->base.getEncoded(&(g_160r1KeyPair->priKey->base),
88         &g_mockECC_BrainPool160r1PriKeyBlob);
89     EXPECT_EQ(res, HCF_SUCCESS);
90     res = g_160r1KeyPair->pubKey->base.getEncoded(&(g_160r1KeyPair->pubKey->base),
91         &g_mockECC_BrainPool160r1PubKeyBlob);
92     EXPECT_EQ(res, HCF_SUCCESS);
93     res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
94         &g_mockECC_BrainPool160r1PriKeyBlob, &g_160r1ConvertKeyPair);
95     EXPECT_EQ(res, HCF_SUCCESS);
96 }
97 
98 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001, TestSize.Level0)
99 {
100     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP160r1");
101     ASSERT_EQ(res, HCF_SUCCESS);
102 }
103 
104 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_2, TestSize.Level0)
105 {
106     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP160t1");
107     ASSERT_EQ(res, HCF_SUCCESS);
108 }
109 
110 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_3, TestSize.Level0)
111 {
112     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP192r1");
113     ASSERT_EQ(res, HCF_SUCCESS);
114 }
115 
116 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_4, TestSize.Level0)
117 {
118     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP192t1");
119     ASSERT_EQ(res, HCF_SUCCESS);
120 }
121 
122 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_5, TestSize.Level0)
123 {
124     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP224r1");
125     ASSERT_EQ(res, HCF_SUCCESS);
126 }
127 
128 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_6, TestSize.Level0)
129 {
130     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP224t1");
131     ASSERT_EQ(res, HCF_SUCCESS);
132 }
133 
134 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_7, TestSize.Level0)
135 {
136     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP256r1");
137     ASSERT_EQ(res, HCF_SUCCESS);
138 }
139 
140 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_8, TestSize.Level0)
141 {
142     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP256t1");
143     ASSERT_EQ(res, HCF_SUCCESS);
144 }
145 
146 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_9, TestSize.Level0)
147 {
148     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP320r1");
149     ASSERT_EQ(res, HCF_SUCCESS);
150 }
151 
152 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_10, TestSize.Level0)
153 {
154     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP320t1");
155     ASSERT_EQ(res, HCF_SUCCESS);
156 }
157 
158 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_11, TestSize.Level0)
159 {
160     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP384r1");
161     ASSERT_EQ(res, HCF_SUCCESS);
162 }
163 
164 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_12, TestSize.Level0)
165 {
166     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP384t1");
167     ASSERT_EQ(res, HCF_SUCCESS);
168 }
169 
170 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_13, TestSize.Level0)
171 {
172     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP512r1");
173     ASSERT_EQ(res, HCF_SUCCESS);
174 }
175 
176 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest001_14, TestSize.Level0)
177 {
178     HcfResult res = HcfAsyKeyGeneratorCreateTest("ECC_BrainPoolP512t1");
179     ASSERT_EQ(res, HCF_SUCCESS);
180 }
181 
182 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest002, TestSize.Level0)
183 {
184     const char *className = g_160r1Generator->base.getClass();
185     ASSERT_NE(className, nullptr);
186 }
187 
188 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest003, TestSize.Level0)
189 {
190     HcfAsyKeyGenerator *generator = nullptr;
191     HcfResult res = HcfAsyKeyGeneratorCreate("ECC_BrainPoolP160r1", &generator);
192 
193     ASSERT_EQ(res, HCF_SUCCESS);
194     ASSERT_NE(generator, nullptr);
195     generator->base.destroy((HcfObjectBase *)generator);
196 }
197 
198 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest004, TestSize.Level0)
199 {
200     HcfAsyKeyGenerator *generator = nullptr;
201     HcfResult res = HcfAsyKeyGeneratorCreate("ECC_BrainPoolP160r1", &generator);
202 
203     ASSERT_EQ(res, HCF_SUCCESS);
204     ASSERT_NE(generator, nullptr);
205 
206     generator->base.destroy(nullptr);
207     HcfObjDestroy(generator);
208 }
209 
210 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest005, TestSize.Level0)
211 {
212     HcfAsyKeyGenerator *generator = nullptr;
213     HcfResult res = HcfAsyKeyGeneratorCreate("ECC_BrainPoolP160r1", &generator);
214 
215     ASSERT_EQ(res, HCF_SUCCESS);
216     ASSERT_NE(generator, nullptr);
217 
218     generator->base.destroy(&g_obj);
219     HcfObjDestroy(generator);
220 }
221 
222 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest006, TestSize.Level0)
223 {
224     const char *algName = g_160r1Generator->getAlgoName(g_160r1Generator);
225     ASSERT_NE(algName, nullptr);
226 }
227 
228 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest007, TestSize.Level0)
229 {
230     const char *algName = g_160r1Generator->getAlgoName(nullptr);
231     ASSERT_EQ(algName, nullptr);
232 }
233 
234 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest008, TestSize.Level0)
235 {
236     const char *algName = g_160r1Generator->getAlgoName((HcfAsyKeyGenerator *)&g_obj);
237     ASSERT_EQ(algName, nullptr);
238 }
239 
240 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest009, TestSize.Level0)
241 {
242     HcfKeyPair *keyPair = nullptr;
243     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
244     ASSERT_EQ(res, HCF_SUCCESS);
245     ASSERT_NE(keyPair, nullptr);
246 
247     HcfObjDestroy(keyPair);
248 }
249 
250 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest010, TestSize.Level0)
251 {
252     HcfKeyPair *keyPair = nullptr;
253     HcfResult res = g_160r1Generator->generateKeyPair(nullptr, nullptr, &keyPair);
254 
255     ASSERT_EQ(res, HCF_INVALID_PARAMS);
256     ASSERT_EQ(keyPair, nullptr);
257 }
258 
259 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest011, TestSize.Level0)
260 {
261     HcfKeyPair *keyPair = nullptr;
262     HcfResult res = g_160r1Generator->generateKeyPair((HcfAsyKeyGenerator *)&g_obj, nullptr, &keyPair);
263 
264     ASSERT_EQ(res, HCF_INVALID_PARAMS);
265     ASSERT_EQ(keyPair, nullptr);
266 }
267 
268 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest012, TestSize.Level0)
269 {
270     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, nullptr);
271     ASSERT_EQ(res, HCF_INVALID_PARAMS);
272 }
273 
274 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest013, TestSize.Level0)
275 {
276     const char *className = g_160r1KeyPair->base.getClass();
277     ASSERT_NE(className, nullptr);
278 }
279 
280 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest014, TestSize.Level0)
281 {
282     HcfKeyPair *keyPair = nullptr;
283     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
284 
285     ASSERT_EQ(res, HCF_SUCCESS);
286     ASSERT_NE(keyPair, nullptr);
287     keyPair->base.destroy((HcfObjectBase *)(&(keyPair->base)));
288 }
289 
290 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest015, TestSize.Level0)
291 {
292     HcfKeyPair *keyPair = nullptr;
293     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
294 
295     ASSERT_EQ(res, HCF_SUCCESS);
296     ASSERT_NE(keyPair, nullptr);
297 
298     keyPair->base.destroy(nullptr);
299     HcfObjDestroy(keyPair);
300 }
301 
302 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest016, TestSize.Level0)
303 {
304     HcfKeyPair *keyPair = nullptr;
305     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
306 
307     ASSERT_EQ(res, HCF_SUCCESS);
308     ASSERT_NE(keyPair, nullptr);
309 
310     keyPair->base.destroy(&g_obj);
311     HcfObjDestroy(keyPair);
312 }
313 
314 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest017, TestSize.Level0)
315 {
316     const char *className = g_160r1KeyPair->pubKey->base.base.getClass();
317     ASSERT_NE(className, nullptr);
318 }
319 
320 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest018, TestSize.Level0)
321 {
322     HcfKeyPair *keyPair = nullptr;
323     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
324 
325     ASSERT_EQ(res, HCF_SUCCESS);
326     ASSERT_NE(keyPair, nullptr);
327 
328     keyPair->pubKey->base.base.destroy((HcfObjectBase *)(&(keyPair->pubKey->base.base)));
329     keyPair->pubKey = nullptr;
330 
331     HcfObjDestroy(keyPair);
332 }
333 
334 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest019, TestSize.Level0)
335 {
336     HcfKeyPair *keyPair = nullptr;
337     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
338 
339     ASSERT_EQ(res, HCF_SUCCESS);
340     ASSERT_NE(keyPair, nullptr);
341 
342     keyPair->pubKey->base.base.destroy(nullptr);
343     HcfObjDestroy(keyPair);
344 }
345 
346 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest020, TestSize.Level0)
347 {
348     HcfKeyPair *keyPair = nullptr;
349     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
350 
351     ASSERT_EQ(res, HCF_SUCCESS);
352     ASSERT_NE(keyPair, nullptr);
353 
354     keyPair->pubKey->base.base.destroy(&g_obj);
355     HcfObjDestroy(keyPair);
356 }
357 
358 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest021, TestSize.Level0)
359 {
360     const char *format = g_160r1KeyPair->pubKey->base.getFormat(&(g_160r1KeyPair->pubKey->base));
361     ASSERT_NE(format, nullptr);
362 }
363 
364 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest022, TestSize.Level0)
365 {
366     const char *format = g_160r1KeyPair->pubKey->base.getFormat(nullptr);
367     ASSERT_EQ(format, nullptr);
368 }
369 
370 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest023, TestSize.Level0)
371 {
372     const char *format = g_160r1KeyPair->pubKey->base.getFormat((HcfKey *)&g_obj);
373     ASSERT_EQ(format, nullptr);
374 }
375 
376 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest024, TestSize.Level0)
377 {
378     const char *algName = g_160r1KeyPair->pubKey->base.getAlgorithm(&(g_160r1KeyPair->pubKey->base));
379     ASSERT_NE(algName, nullptr);
380 }
381 
382 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest025, TestSize.Level0)
383 {
384     const char *algName = g_160r1KeyPair->pubKey->base.getAlgorithm(nullptr);
385     ASSERT_EQ(algName, nullptr);
386 }
387 
388 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest026, TestSize.Level0)
389 {
390     const char *algName = g_160r1KeyPair->pubKey->base.getAlgorithm((HcfKey *)&g_obj);
391     ASSERT_EQ(algName, nullptr);
392 }
393 
394 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest027, TestSize.Level0)
395 {
396     HcfBlob blob = { .data = nullptr, .len = 0 };
397     HcfResult res = g_160r1KeyPair->pubKey->base.getEncoded(&(g_160r1KeyPair->pubKey->base), &blob);
398 
399     ASSERT_EQ(res, HCF_SUCCESS);
400     ASSERT_NE(blob.data, nullptr);
401     ASSERT_NE(blob.len, 0);
402 
403     HcfFree(blob.data);
404 }
405 
406 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest028, TestSize.Level0)
407 {
408     HcfBlob blob = { .data = nullptr, .len = 0 };
409     HcfResult res = g_160r1KeyPair->pubKey->base.getEncoded(nullptr, &blob);
410 
411     ASSERT_NE(res, HCF_SUCCESS);
412     ASSERT_EQ(blob.data, nullptr);
413     ASSERT_EQ(blob.len, 0);
414 }
415 
416 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest029, TestSize.Level0)
417 {
418     HcfBlob blob = { .data = nullptr, .len = 0 };
419     HcfResult res = g_160r1KeyPair->pubKey->base.getEncoded((HcfKey *)&g_obj, &blob);
420 
421     ASSERT_NE(res, HCF_SUCCESS);
422     ASSERT_EQ(blob.data, nullptr);
423     ASSERT_EQ(blob.len, 0);
424 }
425 
426 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest030, TestSize.Level0)
427 {
428     HcfResult res = g_160r1KeyPair->pubKey->base.getEncoded(&(g_160r1KeyPair->pubKey->base), nullptr);
429     ASSERT_NE(res, HCF_SUCCESS);
430 }
431 
432 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest031, TestSize.Level0)
433 {
434     HcfKeyPair *keyPair = nullptr;
435     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
436 
437     ASSERT_EQ(res, HCF_SUCCESS);
438     ASSERT_NE(keyPair, nullptr);
439 
440     keyPair->priKey->clearMem(keyPair->priKey);
441     HcfObjDestroy(keyPair);
442 }
443 
444 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest032, TestSize.Level0)
445 {
446     HcfKeyPair *keyPair = nullptr;
447     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
448 
449     ASSERT_EQ(res, HCF_SUCCESS);
450     ASSERT_NE(keyPair, nullptr);
451 
452     keyPair->priKey->clearMem(nullptr);
453     HcfObjDestroy(keyPair);
454 }
455 
456 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest033, TestSize.Level0)
457 {
458     HcfKeyPair *keyPair = nullptr;
459     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
460 
461     ASSERT_EQ(res, HCF_SUCCESS);
462     ASSERT_NE(keyPair, nullptr);
463 
464     keyPair->priKey->clearMem((HcfPriKey *)&g_obj);
465     HcfObjDestroy(keyPair);
466 }
467 
468 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest034, TestSize.Level0)
469 {
470     HcfKeyPair *keyPair = nullptr;
471     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
472 
473     ASSERT_EQ(res, HCF_SUCCESS);
474     ASSERT_NE(keyPair, nullptr);
475 
476     const char *algName = keyPair->priKey->base.base.getClass();
477     ASSERT_NE(algName, nullptr);
478 
479     HcfObjDestroy(keyPair);
480 }
481 
482 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest035, TestSize.Level0)
483 {
484     HcfKeyPair *keyPair = nullptr;
485     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
486 
487     ASSERT_EQ(res, HCF_SUCCESS);
488     ASSERT_NE(keyPair, nullptr);
489 
490     keyPair->priKey->base.base.destroy((HcfObjectBase *)(&(keyPair->priKey->base.base)));
491     keyPair->priKey = nullptr;
492 
493     HcfObjDestroy(keyPair);
494 }
495 
496 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest036, TestSize.Level0)
497 {
498     HcfKeyPair *keyPair = nullptr;
499     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
500 
501     ASSERT_EQ(res, HCF_SUCCESS);
502     ASSERT_NE(keyPair, nullptr);
503 
504     keyPair->priKey->base.base.destroy(nullptr);
505     HcfObjDestroy(keyPair);
506 }
507 
508 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest037, TestSize.Level0)
509 {
510     HcfKeyPair *keyPair = nullptr;
511     HcfResult res = g_160r1Generator->generateKeyPair(g_160r1Generator, nullptr, &keyPair);
512 
513     ASSERT_EQ(res, HCF_SUCCESS);
514     ASSERT_NE(keyPair, nullptr);
515 
516     keyPair->priKey->base.base.destroy(&g_obj);
517     HcfObjDestroy(keyPair);
518 }
519 
520 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest038, TestSize.Level0)
521 {
522     const char *format = g_160r1KeyPair->priKey->base.getFormat(&g_160r1KeyPair->priKey->base);
523     ASSERT_NE(format, nullptr);
524 }
525 
526 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest039, TestSize.Level0)
527 {
528     const char *format = g_160r1KeyPair->priKey->base.getFormat(nullptr);
529     ASSERT_EQ(format, nullptr);
530 }
531 
532 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest040, TestSize.Level0)
533 {
534     const char *format = g_160r1KeyPair->priKey->base.getFormat((HcfKey *)&g_obj);
535     ASSERT_EQ(format, nullptr);
536 }
537 
538 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest041, TestSize.Level0)
539 {
540     const char *algName = g_160r1KeyPair->pubKey->base.getAlgorithm(&(g_160r1KeyPair->pubKey->base));
541     ASSERT_NE(algName, nullptr);
542 }
543 
544 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest042, TestSize.Level0)
545 {
546     const char *algName = g_160r1KeyPair->pubKey->base.getAlgorithm(nullptr);
547     ASSERT_EQ(algName, nullptr);
548 }
549 
550 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest043, TestSize.Level0)
551 {
552     const char *algName = g_160r1KeyPair->pubKey->base.getAlgorithm((HcfKey *)&g_obj);
553     ASSERT_EQ(algName, nullptr);
554 }
555 
556 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest044, TestSize.Level0)
557 {
558     HcfBlob blob = { .data = nullptr, .len = 0 };
559     HcfResult res = g_160r1KeyPair->priKey->base.getEncoded(&(g_160r1KeyPair->priKey->base), &blob);
560 
561     ASSERT_EQ(res, HCF_SUCCESS);
562     ASSERT_NE(blob.data, nullptr);
563     ASSERT_NE(blob.len, 0);
564 
565     HcfFree(blob.data);
566 }
567 
568 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest045, TestSize.Level0)
569 {
570     HcfBlob blob = { .data = nullptr, .len = 0 };
571     HcfResult res = g_160r1KeyPair->priKey->base.getEncoded(nullptr, &blob);
572 
573     ASSERT_NE(res, HCF_SUCCESS);
574     ASSERT_EQ(blob.data, nullptr);
575     ASSERT_EQ(blob.len, 0);
576 }
577 
578 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest046, TestSize.Level0)
579 {
580     HcfBlob blob = { .data = nullptr, .len = 0 };
581     HcfResult res = g_160r1KeyPair->priKey->base.getEncoded((HcfKey *)&g_obj, &blob);
582     ASSERT_NE(res, HCF_SUCCESS);
583     ASSERT_EQ(blob.data, nullptr);
584     ASSERT_EQ(blob.len, 0);
585 }
586 
587 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest047, TestSize.Level0)
588 {
589     HcfResult res = g_160r1KeyPair->priKey->base.getEncoded(&(g_160r1KeyPair->priKey->base), nullptr);
590     ASSERT_NE(res, HCF_SUCCESS);
591 }
592 
593 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest048, TestSize.Level0)
594 {
595     HcfKeyPair *outKeyPair = nullptr;
596     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
597         &g_mockECC_BrainPool160r1PriKeyBlob, &outKeyPair);
598 
599     ASSERT_EQ(res, HCF_SUCCESS);
600     ASSERT_NE(outKeyPair, nullptr);
601 
602     HcfObjDestroy(outKeyPair);
603 }
604 
605 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest049, TestSize.Level0)
606 {
607     HcfKeyPair *outKeyPair = nullptr;
608     HcfResult res = g_160r1Generator->convertKey(nullptr, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
609         &g_mockECC_BrainPool160r1PriKeyBlob, &outKeyPair);
610 
611     ASSERT_NE(res, HCF_SUCCESS);
612     ASSERT_EQ(outKeyPair, nullptr);
613 
614     HcfObjDestroy(outKeyPair);
615 }
616 
617 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest050, TestSize.Level0)
618 {
619     HcfKeyPair *outKeyPair = nullptr;
620     HcfResult res = g_160r1Generator->convertKey((HcfAsyKeyGenerator *)&g_obj, nullptr,
621         &g_mockECC_BrainPool160r1PubKeyBlob, &g_mockECC_BrainPool160r1PriKeyBlob, &outKeyPair);
622 
623     ASSERT_NE(res, HCF_SUCCESS);
624     ASSERT_EQ(outKeyPair, nullptr);
625 
626     HcfObjDestroy(outKeyPair);
627 }
628 
629 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest051, TestSize.Level0)
630 {
631     HcfKeyPair *outKeyPair = nullptr;
632     HcfResult res = g_160r1Generator->convertKey(nullptr, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
633         &g_mockECC_BrainPool160r1PriKeyBlob, &outKeyPair);
634 
635     ASSERT_NE(res, HCF_SUCCESS);
636     ASSERT_EQ(outKeyPair, nullptr);
637 }
638 
639 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest052, TestSize.Level0)
640 {
641     HcfKeyPair *outKeyPair = nullptr;
642     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, nullptr,
643         &g_mockECC_BrainPool160r1PriKeyBlob, &outKeyPair);
644 
645     ASSERT_EQ(res, HCF_SUCCESS);
646     ASSERT_NE(outKeyPair, nullptr);
647 
648     HcfObjDestroy(outKeyPair);
649 }
650 
651 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest053, TestSize.Level0)
652 {
653     HcfKeyPair *outKeyPair = nullptr;
654     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, nullptr, nullptr, &outKeyPair);
655 
656     ASSERT_NE(res, HCF_SUCCESS);
657     ASSERT_EQ(outKeyPair, nullptr);
658 
659     HcfObjDestroy(outKeyPair);
660 }
661 
662 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest054, TestSize.Level0)
663 {
664     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
665         &g_mockECC_BrainPool160r1PriKeyBlob, nullptr);
666 
667     ASSERT_NE(res, HCF_SUCCESS);
668 }
669 
670 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest055, TestSize.Level0)
671 {
672     const char *className = g_160r1KeyPair->base.getClass();
673     ASSERT_NE(className, nullptr);
674 }
675 
676 
677 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest056, TestSize.Level0)
678 {
679     HcfKeyPair *keyPair = nullptr;
680     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
681         &g_mockECC_BrainPool160r1PriKeyBlob, &keyPair);
682 
683     ASSERT_EQ(res, HCF_SUCCESS);
684     ASSERT_NE(keyPair, nullptr);
685 
686     keyPair->base.destroy((HcfObjectBase *)(&(keyPair->base)));
687 }
688 
689 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest057, TestSize.Level0)
690 {
691     HcfKeyPair *keyPair = nullptr;
692     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
693         &g_mockECC_BrainPool160r1PriKeyBlob, &keyPair);
694 
695     ASSERT_EQ(res, HCF_SUCCESS);
696     ASSERT_NE(keyPair, nullptr);
697 
698     keyPair->base.destroy(nullptr);
699 }
700 
701 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest058, TestSize.Level0)
702 {
703     HcfKeyPair *keyPair = nullptr;
704     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
705         &g_mockECC_BrainPool160r1PriKeyBlob, &keyPair);
706 
707     ASSERT_EQ(res, HCF_SUCCESS);
708     ASSERT_NE(keyPair, nullptr);
709     keyPair->base.destroy(&g_obj);
710 
711     HcfObjDestroy(keyPair);
712 }
713 
714 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest059, TestSize.Level0)
715 {
716     const char *className = g_160r1KeyPair->pubKey->base.base.getClass();
717     ASSERT_NE(className, nullptr);
718 }
719 
720 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest060, TestSize.Level0)
721 {
722     HcfKeyPair *keyPair = nullptr;
723     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
724         &g_mockECC_BrainPool160r1PriKeyBlob, &keyPair);
725 
726     ASSERT_EQ(res, HCF_SUCCESS);
727     ASSERT_NE(keyPair, nullptr);
728 
729     keyPair->pubKey->base.base.destroy((HcfObjectBase *)(&(keyPair->pubKey->base.base)));
730     keyPair->pubKey = nullptr;
731 
732     HcfObjDestroy(keyPair);
733 }
734 
735 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest061, TestSize.Level0)
736 {
737     HcfKeyPair *keyPair = nullptr;
738     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
739         &g_mockECC_BrainPool160r1PriKeyBlob, &keyPair);
740 
741     ASSERT_EQ(res, HCF_SUCCESS);
742     ASSERT_NE(keyPair, nullptr);
743     keyPair->pubKey->base.base.destroy(nullptr);
744     HcfObjDestroy(keyPair);
745 }
746 
747 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest062, TestSize.Level0)
748 {
749     HcfKeyPair *keyPair = nullptr;
750     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
751         &g_mockECC_BrainPool160r1PriKeyBlob, &keyPair);
752 
753     ASSERT_EQ(res, HCF_SUCCESS);
754     ASSERT_NE(keyPair, nullptr);
755     keyPair->pubKey->base.base.destroy(&g_obj);
756     HcfObjDestroy(keyPair);
757 }
758 
759 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest063, TestSize.Level0)
760 {
761     const char *format = g_160r1ConvertKeyPair->pubKey->base.getFormat(&(g_160r1ConvertKeyPair->pubKey->base));
762     ASSERT_NE(format, nullptr);
763 }
764 
765 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest064, TestSize.Level0)
766 {
767     const char *format = g_160r1ConvertKeyPair->pubKey->base.getFormat(nullptr);
768     ASSERT_EQ(format, nullptr);
769 }
770 
771 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest065, TestSize.Level0)
772 {
773     const char *format = g_160r1ConvertKeyPair->pubKey->base.getFormat((HcfKey *)&g_obj);
774     ASSERT_EQ(format, nullptr);
775 }
776 
777 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest066, TestSize.Level0)
778 {
779     const char *algName = g_160r1ConvertKeyPair->pubKey->base.getAlgorithm(&(g_160r1ConvertKeyPair->pubKey->base));
780     ASSERT_NE(algName, nullptr);
781 }
782 
783 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest067, TestSize.Level0)
784 {
785     const char *algName = g_160r1ConvertKeyPair->pubKey->base.getAlgorithm(nullptr);
786     ASSERT_EQ(algName, nullptr);
787 }
788 
789 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest068, TestSize.Level0)
790 {
791     const char *algName = g_160r1ConvertKeyPair->pubKey->base.getAlgorithm((HcfKey *)&g_obj);
792     ASSERT_EQ(algName, nullptr);
793 }
794 
795 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest069, TestSize.Level0)
796 {
797     HcfBlob blob = { .data = nullptr, .len = 0 };
798     HcfResult res = g_160r1ConvertKeyPair->pubKey->base.getEncoded(&(g_160r1ConvertKeyPair->pubKey->base), &blob);
799 
800     ASSERT_EQ(res, HCF_SUCCESS);
801     ASSERT_NE(blob.data, nullptr);
802     ASSERT_NE(blob.len, 0);
803 
804     HcfFree(blob.data);
805 }
806 
807 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest070, TestSize.Level0)
808 {
809     HcfBlob blob = { .data = nullptr, .len = 0 };
810     HcfResult res = g_160r1ConvertKeyPair->pubKey->base.getEncoded(nullptr, &blob);
811 
812     ASSERT_NE(res, HCF_SUCCESS);
813     ASSERT_EQ(blob.data, nullptr);
814     ASSERT_EQ(blob.len, 0);
815 }
816 
817 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest071, TestSize.Level0)
818 {
819     HcfBlob blob = { .data = nullptr, .len = 0 };
820     HcfResult res = g_160r1ConvertKeyPair->pubKey->base.getEncoded((HcfKey *)&g_obj, &blob);
821 
822     ASSERT_NE(res, HCF_SUCCESS);
823     ASSERT_EQ(blob.data, nullptr);
824     ASSERT_EQ(blob.len, 0);
825 }
826 
827 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest072, TestSize.Level0)
828 {
829     HcfResult res = g_160r1ConvertKeyPair->pubKey->base.getEncoded(&(g_160r1ConvertKeyPair->pubKey->base), nullptr);
830     ASSERT_NE(res, HCF_SUCCESS);
831 }
832 
833 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest073, TestSize.Level0)
834 {
835     HcfKeyPair *keyPair = nullptr;
836     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
837         &g_mockECC_BrainPool160r1PriKeyBlob, &keyPair);
838 
839     ASSERT_EQ(res, HCF_SUCCESS);
840     ASSERT_NE(keyPair, nullptr);
841 
842     keyPair->priKey->clearMem(keyPair->priKey);
843     HcfObjDestroy(keyPair);
844 }
845 
846 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest074, TestSize.Level0)
847 {
848     HcfKeyPair *keyPair = nullptr;
849     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
850         &g_mockECC_BrainPool160r1PriKeyBlob, &keyPair);
851 
852     ASSERT_EQ(res, HCF_SUCCESS);
853     ASSERT_NE(keyPair, nullptr);
854 
855     keyPair->priKey->clearMem(nullptr);
856     HcfObjDestroy(keyPair);
857 }
858 
859 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest075, TestSize.Level0)
860 {
861     HcfKeyPair *keyPair = nullptr;
862     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
863         &g_mockECC_BrainPool160r1PriKeyBlob, &keyPair);
864 
865     ASSERT_EQ(res, HCF_SUCCESS);
866     ASSERT_NE(keyPair, nullptr);
867 
868     keyPair->priKey->clearMem((HcfPriKey *)&g_obj);
869     HcfObjDestroy(keyPair);
870 }
871 
872 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest076, TestSize.Level0)
873 {
874     const char *algName = g_160r1ConvertKeyPair->priKey->base.base.getClass();
875     ASSERT_NE(algName, nullptr);
876 }
877 
878 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest077, TestSize.Level0)
879 {
880     HcfKeyPair *keyPair = nullptr;
881     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
882         &g_mockECC_BrainPool160r1PriKeyBlob, &keyPair);
883 
884     ASSERT_EQ(res, HCF_SUCCESS);
885     ASSERT_NE(keyPair, nullptr);
886 
887     keyPair->priKey->base.base.destroy((HcfObjectBase *)(&(keyPair->priKey->base.base)));
888     keyPair->priKey = nullptr;
889 
890     HcfObjDestroy(keyPair);
891 }
892 
893 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest078, TestSize.Level0)
894 {
895     HcfKeyPair *keyPair = nullptr;
896     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
897         &g_mockECC_BrainPool160r1PriKeyBlob, &keyPair);
898 
899     ASSERT_EQ(res, HCF_SUCCESS);
900     ASSERT_NE(keyPair, nullptr);
901 
902     keyPair->priKey->base.base.destroy(nullptr);
903     HcfObjDestroy(keyPair);
904 }
905 
906 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest079, TestSize.Level0)
907 {
908     HcfKeyPair *keyPair = nullptr;
909     HcfResult res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &g_mockECC_BrainPool160r1PubKeyBlob,
910         &g_mockECC_BrainPool160r1PriKeyBlob, &keyPair);
911 
912     ASSERT_EQ(res, HCF_SUCCESS);
913     ASSERT_NE(keyPair, nullptr);
914 
915     keyPair->priKey->base.base.destroy(&g_obj);
916     HcfObjDestroy(keyPair);
917 }
918 
919 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest080, TestSize.Level0)
920 {
921     const char *format = g_160r1ConvertKeyPair->priKey->base.getFormat(&g_160r1ConvertKeyPair->priKey->base);
922     ASSERT_NE(format, nullptr);
923 }
924 
925 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest081, TestSize.Level0)
926 {
927     const char *format = g_160r1ConvertKeyPair->priKey->base.getFormat(nullptr);
928     ASSERT_EQ(format, nullptr);
929 }
930 
931 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest082, TestSize.Level0)
932 {
933     const char *format = g_160r1ConvertKeyPair->priKey->base.getFormat((HcfKey *)&g_obj);
934     ASSERT_EQ(format, nullptr);
935 }
936 
937 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest083, TestSize.Level0)
938 {
939     const char *algName = g_160r1ConvertKeyPair->priKey->base.getAlgorithm(&g_160r1ConvertKeyPair->priKey->base);
940     ASSERT_NE(algName, nullptr);
941 }
942 
943 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest084, TestSize.Level0)
944 {
945     const char *algName = g_160r1ConvertKeyPair->priKey->base.getAlgorithm(nullptr);
946     ASSERT_EQ(algName, nullptr);
947 }
948 
949 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest085, TestSize.Level0)
950 {
951     const char *format = g_160r1ConvertKeyPair->priKey->base.getAlgorithm((HcfKey *)&g_obj);
952     ASSERT_EQ(format, nullptr);
953 }
954 
955 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest086, TestSize.Level0)
956 {
957     HcfBlob blob = { .data = nullptr, .len = 0 };
958     HcfResult res = g_160r1ConvertKeyPair->priKey->base.getEncoded(&(g_160r1ConvertKeyPair->priKey->base), &blob);
959 
960     ASSERT_EQ(res, HCF_SUCCESS);
961     ASSERT_NE(blob.data, nullptr);
962     ASSERT_NE(blob.len, 0);
963 
964     HcfFree(blob.data);
965 }
966 
967 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest087, TestSize.Level0)
968 {
969     HcfBlob blob = { .data = nullptr, .len = 0 };
970     HcfResult res = g_160r1ConvertKeyPair->priKey->base.getEncoded(nullptr, &blob);
971 
972     ASSERT_NE(res, HCF_SUCCESS);
973     ASSERT_EQ(blob.data, nullptr);
974     ASSERT_EQ(blob.len, 0);
975 
976     HcfFree(blob.data);
977 }
978 
979 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest088, TestSize.Level0)
980 {
981     HcfBlob blob = { .data = nullptr, .len = 0 };
982     HcfResult res = g_160r1ConvertKeyPair->priKey->base.getEncoded((HcfKey *)&g_obj, &blob);
983 
984     ASSERT_NE(res, HCF_SUCCESS);
985     ASSERT_EQ(blob.data, nullptr);
986     ASSERT_EQ(blob.len, 0);
987 
988     HcfFree(blob.data);
989 }
990 
991 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest089, TestSize.Level0)
992 {
993     HcfBlob blob = { .data = nullptr, .len = 0 };
994     HcfResult res = g_160r1ConvertKeyPair->priKey->base.getEncoded(&(g_160r1ConvertKeyPair->priKey->base), nullptr);
995 
996     ASSERT_NE(res, HCF_SUCCESS);
997     ASSERT_EQ(blob.data, nullptr);
998     ASSERT_EQ(blob.len, 0);
999 
1000     HcfFree(blob.data);
1001 }
1002 
1003 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest090, TestSize.Level0)
1004 {
1005     HcfBlob pubKeyBlob = { .data = nullptr, .len = 0 };
1006     HcfResult res = g_160r1ConvertKeyPair->pubKey->base.getEncoded(&(g_160r1ConvertKeyPair->pubKey->base), &pubKeyBlob);
1007     ASSERT_EQ(res, HCF_SUCCESS);
1008 
1009     HcfBlob priKeyBlob = { .data = nullptr, .len = 0 };
1010     res = g_160r1ConvertKeyPair->priKey->base.getEncoded(&(g_160r1ConvertKeyPair->priKey->base), &priKeyBlob);
1011 
1012     ASSERT_EQ(res, HCF_SUCCESS);
1013 
1014     HcfKeyPair *outKeyPair = nullptr;
1015     res = g_160r1Generator->convertKey(g_160r1Generator, nullptr, &pubKeyBlob, &priKeyBlob, &outKeyPair);
1016 
1017     ASSERT_EQ(res, HCF_SUCCESS);
1018     ASSERT_NE(outKeyPair, nullptr);
1019 
1020     HcfBlob outPubKeyBlob = { .data = nullptr, .len = 0 };
1021     res = outKeyPair->pubKey->base.getEncoded(&(outKeyPair->pubKey->base), &outPubKeyBlob);
1022 
1023     ASSERT_EQ(res, HCF_SUCCESS);
1024     ASSERT_NE(outPubKeyBlob.data, nullptr);
1025     ASSERT_NE(outPubKeyBlob.len, 0);
1026 
1027     HcfBlob outPriKeyBlob = { .data = nullptr, .len = 0 };
1028     res = outKeyPair->priKey->base.getEncoded(&(outKeyPair->priKey->base), &outPriKeyBlob);
1029 
1030     ASSERT_EQ(res, HCF_SUCCESS);
1031     ASSERT_NE(outPriKeyBlob.data, nullptr);
1032     ASSERT_NE(outPriKeyBlob.len, 0);
1033 
1034     HcfFree(pubKeyBlob.data);
1035     HcfFree(priKeyBlob.data);
1036     HcfFree(outPubKeyBlob.data);
1037     HcfFree(outPriKeyBlob.data);
1038     HcfObjDestroy(outKeyPair);
1039 }
1040 
1041 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest091, TestSize.Level0)
1042 {
1043     HcfAsyKeyGenParams params = {
1044         .algo = HCF_ALG_ECC,
1045         .bits = HCF_ALG_ECC_256,
1046         .primes = HCF_OPENSSL_PRIMES_2,
1047     };
1048 
1049     HcfAsyKeyGeneratorSpi *spiObj = nullptr;
1050     HcfResult res = HcfAsyKeyGeneratorSpiEccCreate(&params, &spiObj);
1051 
1052     ASSERT_EQ(res, HCF_SUCCESS);
1053     ASSERT_NE(spiObj, nullptr);
1054 }
1055 
1056 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest092, TestSize.Level0)
1057 {
1058     HcfAsyKeyGenParams params = {
1059         .algo = HCF_ALG_ECC,
1060         .bits = HCF_ALG_ECC_256,
1061         .primes = HCF_OPENSSL_PRIMES_2,
1062     };
1063 
1064     HcfAsyKeyGeneratorSpi *spiObj = nullptr;
1065     HcfResult res = HcfAsyKeyGeneratorSpiEccCreate(&params, &spiObj);
1066 
1067     ASSERT_EQ(res, HCF_SUCCESS);
1068     ASSERT_NE(spiObj, nullptr);
1069 
1070     HcfKeyPair *keyPair = nullptr;
1071     res = spiObj->engineGenerateKeyPair((HcfAsyKeyGeneratorSpi *)&g_obj, &keyPair);
1072     ASSERT_EQ(res, HCF_INVALID_PARAMS);
1073     HcfObjDestroy(spiObj);
1074 }
1075 
1076 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest093, TestSize.Level0)
1077 {
1078     HcfAsyKeyGenParams params = {
1079         .algo = HCF_ALG_ECC,
1080         .bits = HCF_ALG_ECC_256,
1081         .primes = HCF_OPENSSL_PRIMES_2,
1082     };
1083 
1084     HcfAsyKeyGeneratorSpi *spiObj = nullptr;
1085     HcfResult res = HcfAsyKeyGeneratorSpiEccCreate(&params, &spiObj);
1086 
1087     ASSERT_EQ(res, HCF_SUCCESS);
1088     ASSERT_NE(spiObj, nullptr);
1089 
1090     HcfKeyPair *keyPair = nullptr;
1091     res = spiObj->engineConvertKey((HcfAsyKeyGeneratorSpi *)&g_obj, nullptr, nullptr, nullptr, &keyPair);
1092     ASSERT_EQ(res, HCF_INVALID_PARAMS);
1093     HcfObjDestroy(spiObj);
1094 }
1095 
1096 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest094, TestSize.Level0)
1097 {
1098     HcfAsyKeyGenParams params = {
1099         .algo = HCF_ALG_ECC,
1100         .bits = HCF_ALG_ECC_256,
1101         .primes = HCF_OPENSSL_PRIMES_2,
1102     };
1103 
1104     HcfAsyKeyGeneratorSpi *spiObj = nullptr;
1105     HcfResult res = HcfAsyKeyGeneratorSpiEccCreate(&params, &spiObj);
1106 
1107     ASSERT_EQ(res, HCF_SUCCESS);
1108     ASSERT_NE(spiObj, nullptr);
1109     spiObj->base.destroy(nullptr);
1110     HcfObjDestroy(spiObj);
1111 }
1112 
1113 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest095, TestSize.Level0)
1114 {
1115     HcfAsyKeyGenParams params = {
1116         .algo = HCF_ALG_ECC,
1117         .bits = HCF_ALG_ECC_256,
1118         .primes = HCF_OPENSSL_PRIMES_2,
1119     };
1120 
1121     HcfAsyKeyGeneratorSpi *spiObj = nullptr;
1122     HcfResult res = HcfAsyKeyGeneratorSpiEccCreate(&params, &spiObj);
1123 
1124     ASSERT_EQ(res, HCF_SUCCESS);
1125     ASSERT_NE(spiObj, nullptr);
1126 
1127     spiObj->base.destroy(&g_obj);
1128     HcfObjDestroy(spiObj);
1129 }
1130 
MemoryMallocTestFunc(int32_t mallocCount)1131 static void MemoryMallocTestFunc(int32_t mallocCount)
1132 {
1133     for (int32_t i = 0; i < mallocCount; i++) {
1134         ResetRecordMallocNum();
1135         SetMockMallocIndex(i);
1136         HcfAsyKeyGenerator *tmpGenerator = nullptr;
1137         HcfResult res = HcfAsyKeyGeneratorCreate("ECC_BrainPoolP160r1", &tmpGenerator);
1138         if (res != HCF_SUCCESS) {
1139             continue;
1140         }
1141         HcfKeyPair *tmpKeyPair = nullptr;
1142         res = tmpGenerator->generateKeyPair(tmpGenerator, nullptr, &tmpKeyPair);
1143         if (res != HCF_SUCCESS) {
1144             HcfObjDestroy(tmpGenerator);
1145             continue;
1146         }
1147         HcfBlob tmpPubKeyBlob = {
1148             .data = nullptr,
1149             .len = 0
1150         };
1151         res = tmpKeyPair->pubKey->base.getEncoded(&(tmpKeyPair->pubKey->base), &tmpPubKeyBlob);
1152         if (res != HCF_SUCCESS) {
1153             HcfObjDestroy(tmpKeyPair);
1154             HcfObjDestroy(tmpGenerator);
1155             continue;
1156         }
1157         HcfBlob tmpPriKeyBlob = {
1158             .data = nullptr,
1159             .len = 0
1160         };
1161         res = tmpKeyPair->priKey->base.getEncoded(&(tmpKeyPair->priKey->base), &tmpPriKeyBlob);
1162         if (res != HCF_SUCCESS) {
1163             HcfFree(tmpPubKeyBlob.data);
1164             HcfObjDestroy(tmpKeyPair);
1165             HcfObjDestroy(tmpGenerator);
1166             continue;
1167         }
1168         HcfKeyPair *tmpOutKeyPair = nullptr;
1169         res = tmpGenerator->convertKey(tmpGenerator, nullptr, &tmpPubKeyBlob, &tmpPriKeyBlob, &tmpOutKeyPair);
1170         HcfFree(tmpPubKeyBlob.data);
1171         HcfFree(tmpPriKeyBlob.data);
1172         HcfObjDestroy(tmpKeyPair);
1173         HcfObjDestroy(tmpGenerator);
1174         if (res == HCF_SUCCESS) {
1175             HcfObjDestroy(tmpOutKeyPair);
1176         }
1177     }
1178 }
1179 
1180 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest096, TestSize.Level0)
1181 {
1182     StartRecordMallocNum();
1183     HcfAsyKeyGenerator *generator = nullptr;
1184     HcfResult res = HcfAsyKeyGeneratorCreate("ECC_BrainPoolP160r1", &generator);
1185 
1186     HcfKeyPair *keyPair = nullptr;
1187     res = generator->generateKeyPair(generator, nullptr, &keyPair);
1188 
1189     ASSERT_EQ(res, HCF_SUCCESS);
1190     ASSERT_NE(keyPair, nullptr);
1191 
1192     HcfBlob pubKeyBlob = { .data = nullptr, .len = 0 };
1193     res = keyPair->pubKey->base.getEncoded(&(keyPair->pubKey->base), &pubKeyBlob);
1194 
1195     ASSERT_EQ(res, HCF_SUCCESS);
1196     ASSERT_NE(pubKeyBlob.data, nullptr);
1197     ASSERT_NE(pubKeyBlob.len, 0);
1198 
1199     HcfBlob priKeyBlob = { .data = nullptr, .len = 0 };
1200     res = keyPair->priKey->base.getEncoded(&(keyPair->priKey->base), &priKeyBlob);
1201 
1202     ASSERT_EQ(res, HCF_SUCCESS);
1203     ASSERT_NE(priKeyBlob.data, nullptr);
1204     ASSERT_NE(priKeyBlob.len, 0);
1205 
1206     HcfKeyPair *outKeyPair = nullptr;
1207     res = generator->convertKey(generator, nullptr, &pubKeyBlob, &priKeyBlob, &outKeyPair);
1208 
1209     HcfFree(pubKeyBlob.data);
1210     HcfFree(priKeyBlob.data);
1211     HcfObjDestroy(outKeyPair);
1212     HcfObjDestroy(keyPair);
1213     HcfObjDestroy(generator);
1214 
1215     int32_t mallocCount = GetMallocNum();
1216     MemoryMallocTestFunc(mallocCount);
1217     EndRecordMallocNum();
1218 }
1219 
OpensslMockTestFunc(int32_t mallocCount)1220 static void OpensslMockTestFunc(int32_t mallocCount)
1221 {
1222     for (int32_t i = 0; i < mallocCount; i++) {
1223         ResetOpensslCallNum();
1224         SetOpensslCallMockIndex(i);
1225         HcfAsyKeyGenerator *tmpGenerator = nullptr;
1226         HcfResult res = HcfAsyKeyGeneratorCreate("ECC_BrainPoolP160r1", &tmpGenerator);
1227         if (res != HCF_SUCCESS) {
1228             continue;
1229         }
1230         HcfKeyPair *tmpKeyPair = nullptr;
1231         res = tmpGenerator->generateKeyPair(tmpGenerator, nullptr, &tmpKeyPair);
1232         if (res != HCF_SUCCESS) {
1233             HcfObjDestroy(tmpGenerator);
1234             continue;
1235         }
1236         HcfBlob tmpPubKeyBlob = {
1237             .data = nullptr,
1238             .len = 0
1239         };
1240         res = tmpKeyPair->pubKey->base.getEncoded(&(tmpKeyPair->pubKey->base), &tmpPubKeyBlob);
1241         if (res != HCF_SUCCESS) {
1242             HcfObjDestroy(tmpKeyPair);
1243             HcfObjDestroy(tmpGenerator);
1244             continue;
1245         }
1246         HcfBlob tmpPriKeyBlob = {
1247             .data = nullptr,
1248             .len = 0
1249         };
1250         res = tmpKeyPair->priKey->base.getEncoded(&(tmpKeyPair->priKey->base), &tmpPriKeyBlob);
1251         if (res != HCF_SUCCESS) {
1252             HcfFree(tmpPubKeyBlob.data);
1253             HcfObjDestroy(tmpKeyPair);
1254             HcfObjDestroy(tmpGenerator);
1255             continue;
1256         }
1257         HcfKeyPair *tmpOutKeyPair = nullptr;
1258         res = tmpGenerator->convertKey(tmpGenerator, nullptr, &tmpPubKeyBlob, &tmpPriKeyBlob, &tmpOutKeyPair);
1259         HcfFree(tmpPubKeyBlob.data);
1260         HcfFree(tmpPriKeyBlob.data);
1261         HcfObjDestroy(tmpKeyPair);
1262         HcfObjDestroy(tmpGenerator);
1263         if (res == HCF_SUCCESS) {
1264             HcfObjDestroy(tmpOutKeyPair);
1265         }
1266     }
1267 }
1268 
1269 HWTEST_F(CryptoBrainPoolAsyKeyGeneratorTest, CryptoBrainPoolAsyKeyGeneratorTest097, TestSize.Level0)
1270 {
1271     StartRecordOpensslCallNum();
1272     HcfAsyKeyGenerator *generator = nullptr;
1273     HcfResult res = HcfAsyKeyGeneratorCreate("ECC_BrainPoolP160r1", &generator);
1274 
1275     HcfKeyPair *keyPair = nullptr;
1276     res = generator->generateKeyPair(generator, nullptr, &keyPair);
1277 
1278     ASSERT_EQ(res, HCF_SUCCESS);
1279     ASSERT_NE(keyPair, nullptr);
1280 
1281     HcfBlob pubKeyBlob = { .data = nullptr, .len = 0 };
1282     res = keyPair->pubKey->base.getEncoded(&(keyPair->pubKey->base), &pubKeyBlob);
1283 
1284     ASSERT_EQ(res, HCF_SUCCESS);
1285     ASSERT_NE(pubKeyBlob.data, nullptr);
1286     ASSERT_NE(pubKeyBlob.len, 0);
1287 
1288     HcfBlob priKeyBlob = { .data = nullptr, .len = 0 };
1289     res = keyPair->priKey->base.getEncoded(&(keyPair->priKey->base), &priKeyBlob);
1290 
1291     ASSERT_EQ(res, HCF_SUCCESS);
1292     ASSERT_NE(priKeyBlob.data, nullptr);
1293     ASSERT_NE(priKeyBlob.len, 0);
1294 
1295     HcfKeyPair *outKeyPair = nullptr;
1296     res = generator->convertKey(generator, nullptr, &pubKeyBlob, &priKeyBlob, &outKeyPair);
1297 
1298     HcfFree(pubKeyBlob.data);
1299     HcfFree(priKeyBlob.data);
1300     HcfObjDestroy(outKeyPair);
1301     HcfObjDestroy(keyPair);
1302     HcfObjDestroy(generator);
1303 
1304     int32_t mallocCount = GetOpensslCallNum();
1305     OpensslMockTestFunc(mallocCount);
1306     EndRecordOpensslCallNum();
1307 }
1308 }
1309