• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "huks_signverify_ecc_test.h"
17 
18 #include <gtest/gtest.h>
19 
20 #include "huks_signverify_ecc_test_common.h"
21 
22 using namespace testing::ext;
23 namespace Unittest::EccSifnVerify
24 {
25 class HuksSignVerifyECCTest : public testing::Test
26 {
27    public:
28     static void SetUpTestCase(void);
29 
30     static void TearDownTestCase(void);
31 
32     void SetUp();
33 
34     void TearDown();
35 };
36 
SetUpTestCase(void)37 void HuksSignVerifyECCTest::SetUpTestCase(void) {}
38 
TearDownTestCase(void)39 void HuksSignVerifyECCTest::TearDownTestCase(void) {}
40 
SetUp()41 void HuksSignVerifyECCTest::SetUp() {}
42 
TearDown()43 void HuksSignVerifyECCTest::TearDown() {}
44 
45 static struct OH_Huks_Param g_genParamsTest001[] = {
46     {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC},
47     {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_SIGN | OH_HUKS_KEY_PURPOSE_VERIFY},
48     {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256},
49     {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256},
50     {.tag = OH_HUKS_TAG_AUTH_STORAGE_LEVEL, .uint32Param = OH_HUKS_AUTH_STORAGE_LEVEL_DE}};
51 static struct OH_Huks_Param g_signParamsTest001[] = {
52     {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC},
53     {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_SIGN},
54     {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256},
55     {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256},
56     {.tag = OH_HUKS_TAG_AUTH_STORAGE_LEVEL, .uint32Param = OH_HUKS_AUTH_STORAGE_LEVEL_DE}};
57 static struct OH_Huks_Param g_verifyParamsTest001[] = {
58     {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC},
59     {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_VERIFY},
60     {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256},
61     {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256},
62     {.tag = OH_HUKS_TAG_AUTH_STORAGE_LEVEL, .uint32Param = OH_HUKS_AUTH_STORAGE_LEVEL_DE}};
63 
64 /**
65  * @tc.name: HuksSignVerifyECCTest.Security_HUKS_NAPI_SignVerify_ECC_0100
66  * @tc.desc: alg-ECC pur-Sign.
67  * @tc.type: FUNC
68  */
69 HWTEST_F(HuksSignVerifyECCTest, Security_HUKS_NAPI_SignVerify_ECC_0100, TestSize.Level0)
70 {
71     const char *keyAliasString = "HksECCSignVerifyKeyAliasTest001";
72     struct OH_Huks_ParamSet *genParamSet = nullptr;
73     struct OH_Huks_ParamSet *signParamSet = nullptr;
74     struct OH_Huks_ParamSet *verifyParamSet = nullptr;
75     struct OH_Huks_Blob keyAlias = {strlen(keyAliasString), (uint8_t *)keyAliasString};
76 
77     OH_Huks_Result ret =
78         InitParamSet(&genParamSet, g_genParamsTest001, sizeof(g_genParamsTest001) / sizeof(OH_Huks_Param));
79     EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
80     ret = InitParamSet(&signParamSet, g_signParamsTest001, sizeof(g_signParamsTest001) / sizeof(OH_Huks_Param));
81     EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
82     ret = InitParamSet(&verifyParamSet, g_verifyParamsTest001, sizeof(g_verifyParamsTest001) / sizeof(OH_Huks_Param));
83     EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
84     if ((genParamSet != nullptr) || (signParamSet != nullptr) || (verifyParamSet != nullptr)) {
85         ret = HksEccSignVerifyTestNormalCase(keyAlias, genParamSet, signParamSet, verifyParamSet);
86     }
87 
88     /* Delete Key */
89     ret = OH_Huks_DeleteKeyItem(&keyAlias, genParamSet);
90     EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
91 
92     OH_Huks_FreeParamSet(&genParamSet);
93     OH_Huks_FreeParamSet(&signParamSet);
94     OH_Huks_FreeParamSet(&verifyParamSet);
95 }
96 }  // namespace Unittest::EccSifnVerify