1 /*
2 * Copyright (C) 2021 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 "hctest.h"
17 #include "hi_watchdog.h"
18 #include "hks_bn_exp_mod_test_c.h"
19
20 /*
21 * @tc.register: register a test suit named "CalcMultiTest"
22 * @param: test subsystem name
23 * @param: c_example module name
24 * @param: CalcMultiTest test suit name
25 */
26 LITE_TEST_SUIT(husk, huks_lite, HksBnExpModTest);
27
28 /**
29 * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
30 * @return: true——setup success
31 */
HksBnExpModTestSetUp()32 static BOOL HksBnExpModTestSetUp()
33 {
34 LiteTestPrint("setup\n");
35 hi_watchdog_disable();
36 TEST_ASSERT_TRUE(HksInitialize() == 0);
37 return TRUE;
38 }
39
40 /**
41 * @tc.teardown: define a setup for test suit, format:"CalcMultiTest + TearDown"
42 * @return: true——teardown success
43 */
HksBnExpModTestTearDown()44 static BOOL HksBnExpModTestTearDown()
45 {
46 LiteTestPrint("tearDown\n");
47 hi_watchdog_enable();
48 return TRUE;
49 }
50
51 /**
52 * @tc.name: HksBnExpModTest.HksBnExpModTest001
53 * @tc.desc: The static function will return true;
54 * @tc.type: FUNC
55 */
LITE_TEST_CASE(HksBnExpModTest,HksBnExpModTest001,Level1)56 LITE_TEST_CASE(HksBnExpModTest, HksBnExpModTest001, Level1)
57 {
58 int32_t ret;
59 if (g_testBnExpModParams[0].isTestValue) {
60 ret = TestValue();
61 TEST_ASSERT_TRUE(ret == 0);
62 } else {
63 struct HksBlob *x = NULL;
64 struct HksBlob *a = NULL;
65 struct HksBlob *e = NULL;
66 struct HksBlob *n = NULL;
67 ret = TestConstuctBlob(&x, g_testBnExpModParams[0].xParams.blobExist,
68 g_testBnExpModParams[0].xParams.blobSize, g_testBnExpModParams[0].xParams.blobDataExist,
69 g_testBnExpModParams[0].xParams.blobDataSize);
70 TEST_ASSERT_TRUE(ret == 0);
71
72 ret = TestConstructBlobOut(&a, g_testBnExpModParams[0].aParams.blobExist,
73 g_testBnExpModParams[0].aParams.blobSize, g_testBnExpModParams[0].aParams.blobDataExist,
74 g_testBnExpModParams[0].aParams.blobDataSize);
75 TEST_ASSERT_TRUE(ret == 0);
76
77 ret = TestConstuctBlob(&e, g_testBnExpModParams[0].eParams.blobExist,
78 g_testBnExpModParams[0].eParams.blobSize, g_testBnExpModParams[0].eParams.blobDataExist,
79 g_testBnExpModParams[0].eParams.blobDataSize);
80 TEST_ASSERT_TRUE(ret == 0);
81
82 ret = TestConstuctBlob(&n, g_testBnExpModParams[0].nParams.blobExist,
83 g_testBnExpModParams[0].nParams.blobSize, g_testBnExpModParams[0].nParams.blobDataExist,
84 g_testBnExpModParams[0].nParams.blobDataSize);
85 TEST_ASSERT_TRUE(ret == 0);
86 if ((n != NULL) && (n->data != NULL) && (n->size != 0)) {
87 n->data[n->size - 1] = n->data[n->size - 1] | 0x00000001; /* make sure n is odd */
88 }
89
90 ret = HksBnExpModRun(x, a, e, n, 1);
91
92 TEST_ASSERT_TRUE(ret == g_testBnExpModParams[0].expectResult);
93
94 TestFreeBlob(&x);
95 TestFreeBlob(&a);
96 TestFreeBlob(&e);
97 TestFreeBlob(&n);
98 TEST_ASSERT_TRUE(ret == 0);
99 }
100 }
101
102 RUN_TEST_SUITE(HksBnExpModTest);
103