提交 3cfd7023 编写于 作者: Z zhanghanlin9

add case

Signed-off-by: Nzhanghanlin9 <zhanghanlin9@huawei.com>
上级 98b1ed51
......@@ -21,6 +21,8 @@ group("security") {
"cipher/datacipher:datacipher",
"cryptoFramework:ActsCryptoFrameworkJSNormalTest",
"security_huks_basic",
"security_huks_reformed_test",
"huks_napi_BasicTest:ActsHuksNAPITest",
]
}
}
{
"files.associations": {
"array": "cpp",
"string": "cpp",
"string_view": "cpp"
}
}
\ No newline at end of file
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/security/huks/huks.gni")
import("//test/xts/tools/build/suite.gni")
config("module_private_config"){
visibility = [":*"]
include_dirs=[
"//commonlibrary/c_utils/base/include",
"//third_party/bounds_checking_function/include",
"include",
]
}
ohos_moduletest_suite("ActsHuksNAPITest"){
configs = [":module_private_config"]
cflags_cc = ["-DHILOG_ENABLE"]
defines = [
"_STANDARD_SYSTEM_",
"CONFIG_HUKS_STAGED",
"_USE_OPENSSL_"
]
subsystem_name = "security"
part_name = "huks"
sources=[
"src/huks_agree_dh_test.cpp",
"src/huks_agree_ecdh_test.cpp",
"src/huks_agree_ecdh_test_common.cpp",
"src/huks_agree_x25519_test.cpp",
"src/huks_attest_test.cpp",
"src/huks_attest_test_common.cpp",
"src/huks_cipher_aes_test.cpp",
"src/huks_cipher_aes_test_common.cpp",
"src/huks_cipher_rsa_test.cpp",
"src/huks_cipher_rsa_test_common.cpp",
"src/huks_cipher_sm4_test.cpp",
"src/huks_cipher_sm4_test_common.cpp",
"src/huks_derive_hkdf_test.cpp",
"src/huks_derive_hkdf_test_common.cpp",
"src/huks_derive_pbkdf_test.cpp",
"src/huks_derive_pbkdf_test_common.cpp",
"src/huks_hmac_test.cpp",
"src/huks_mem.cpp",
"src/huks_misc_test.cpp",
"src/huks_nullptr_test.cpp",
"src/huks_signverify_dsa_test.cpp",
"src/huks_signverify_ecc_test.cpp",
"src/huks_signverify_ecc_test_common.cpp",
"src/huks_signverify_ed25519_test.cpp",
"src/huks_signverify_rsa_test.cpp",
"src/huks_signverify_rsa_test_common.cpp",
"src/huks_signverify_sm2_test.cpp",
"src/huks_three_stage_test_common.cpp",
"src/huks_warpped_test.cpp",
]
include_dirs=[
"//test/xts/acts/security/security_huks_basic/huks_napi_BasicTest/include",
"include",
"//base/security/huks/interfaces/kits/c/include",
"commonlibrary/c_utils/base/include"
]
external_deps = ["c_utils:utils"]
deps = [
"//base/security/huks/frameworks/huks_standard/main:huks_standard_frameworks",
"//base/security/huks/frameworks/huks_standard/main/common:libhuks_common_standard_static",
"//base/security/huks/interfaces/innerkits/huks_standard/main:libhukssdk",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/openssl:libcrypto_shared",
"//base/security/huks/interfaces/kits/c:huks_ndk",
]
}
\ No newline at end of file
{
"description": "NAPI Tests",
"driver": {
"native-test-timeout":"600",
"type": "CppTest",
"module-name": "ActsHuksNAPITest",
"runtime-hint": "1s",
"native-test-device-path":"/data/local/tmp"
},
"kits": [
{
"push":[
"ActsHuksNAPITest->/data/local/tmp/ActsHuksNAPITest"
],
"type": "PushKit"
}
]
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_AGREE_DH_TEST_H
#define HUKS_AGREE_DH_TEST_H
#include <string>
#include "huks_three_stage_test_common.h"
#include "native_huks_api.h"
#include "native_huks_param.h"
#include "native_huks_type.h"
namespace Unittest::DhAgree {
static const std::string g_inData = "OH_HUKS_DH_Agree_Test_00000000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
static const uint32_t DH_COMMON_SIZE = 2048;
static struct OH_Huks_Blob g_keyAlias01001 = {
strlen("HksDHAgreeKeyAliasTest001_1"),
(uint8_t *)"HksDHAgreeKeyAliasTest001_1"
};
static struct OH_Huks_Blob g_keyAlias02001 = {
strlen("HksDHAgreeKeyAliasTest001_2"),
(uint8_t *)"HksDHAgreeKeyAliasTest001_2"
};
static struct OH_Huks_Blob g_keyAliasFinal1001 = {
strlen("HksDHAgreeKeyAliasTest001_1_final"),
(uint8_t *)"HksDHAgreeKeyAliasTest001_1_final"
};
static struct OH_Huks_Blob g_keyAliasFinal2001 = {
strlen("HksDHAgreeKeyAliasTest001_2_final"),
(uint8_t *)"HksDHAgreeKeyAliasTest001_2_final"
};
static struct OH_Huks_Param g_genParams001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_DH
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_AGREE
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_DH_KEY_SIZE_2048
}
};
static struct OH_Huks_Param g_agreeParams01Init001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_DH
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_AGREE
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_DH_KEY_SIZE_2048
}
};
static struct OH_Huks_Param g_agreeParams01Finish001[] = {
{
.tag = OH_HUKS_TAG_KEY_STORAGE_FLAG,
.uint32Param = OH_HUKS_STORAGE_PERSISTENT
}, {
.tag = OH_HUKS_TAG_IS_KEY_ALIAS,
.boolParam = true
}, {
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA256
}, {
.tag = OH_HUKS_TAG_KEY_ALIAS,
.blob = g_keyAliasFinal1001
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}
};
static struct OH_Huks_Param g_agreeParams02Init001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_DH
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_AGREE
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_DH_KEY_SIZE_2048
}
};
static struct OH_Huks_Param g_agreeParams02Finish001[] = {
{
.tag = OH_HUKS_TAG_KEY_STORAGE_FLAG,
.uint32Param = OH_HUKS_STORAGE_PERSISTENT
}, {
.tag = OH_HUKS_TAG_IS_KEY_ALIAS,
.boolParam = true
}, {
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA256
}, {
.tag = OH_HUKS_TAG_KEY_ALIAS,
.blob = g_keyAliasFinal2001
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}
};
int Security_HUKS_NAPI_Agree_DH_0100(void);
} // namespace Unittest::DhAgree
#endif // HUKS_AGREE_DH_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HUKS_AGREE_ECDH_TEST_H
#define HUKS_AGREE_ECDH_TEST_H
namespace Unittest::EcdhAgree {
int Security_HUKS_NAPI_Agree_ECDH_0100(void);
} // namespace Unittest::EcdhAgree
#endif // HUKS_AGREE_ECDH_TEST_H
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_AGREE_ECDH_TEST_COMMON_H
#define HUKS_AGREE_ECDH_TEST_COMMON_H
#include <string>
#include "huks_three_stage_test_common.h"
#include "native_huks_api.h"
#include "native_huks_param.h"
#include "native_huks_type.h"
namespace Unittest::EcdhAgree {
static const std::string g_inData = "Hks_ECDH_Agree_Test_000000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
static const uint32_t ECDH_COMMON_SIZE = 1024;
OH_Huks_Result HksEcdhAgreeFinish(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_Blob *publicKey,
const struct OH_Huks_ParamSet *initParamSet, const struct OH_Huks_ParamSet *finishParamSet, struct OH_Huks_Blob *outData);
OH_Huks_Result HksEcdhAgreeAbort(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_Blob *publicKey,
const struct OH_Huks_ParamSet *initParamSet);
OH_Huks_Result HksEcdhAgreeExport(const struct OH_Huks_Blob *keyAlias1, const struct OH_Huks_Blob *keyAlias2,
struct OH_Huks_Blob *publicKey1, struct OH_Huks_Blob *publicKey2, const struct OH_Huks_ParamSet *genParamSet);
void HksEcdhAgreeFreeParamSet(struct OH_Huks_ParamSet *paramSet1, struct OH_Huks_ParamSet *paramSet2,
struct OH_Huks_ParamSet *paramSet3);
void HksEcdhAgreeFreeParamSet(struct OH_Huks_ParamSet *paramSet1, struct OH_Huks_ParamSet *paramSet2,
struct OH_Huks_ParamSet *paramSet3, struct OH_Huks_ParamSet *paramSet4, struct OH_Huks_ParamSet *paramSet5);
void HksEcdhAgreeFreeBlob(struct OH_Huks_Blob *blob1, struct OH_Huks_Blob *blob2);
void HksEcdhAgreeFreeBlob(struct OH_Huks_Blob *blob1, struct OH_Huks_Blob *blob2,
struct OH_Huks_Blob *blob3, struct OH_Huks_Blob *blob4);
} // namespace Unittest::EcdhAgree
#endif // HUKS_AGREE_ECDH_TEST_COMMON_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_AGREE_X25519_TEST_H
#define HUKS_AGREE_X25519_TEST_H
#include <string>
#include "huks_three_stage_test_common.h"
namespace Unittest::X25519Agree {
static const std::string g_inData = "Hks_X25519_Agree_Test_0000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
static const uint32_t X25519_COMMON_SIZE = 4096;
int Security_HUKS_NAPI_Agree_X25519_0100(void);
}
#endif // HUKS_AGREE_X25519_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HUKS_ATTEST_TEST_H
#define HUKS_ATTEST_TEST_H
namespace Unittest::AttestTest {
int Security_HUKS_NAPI_Attest_0100(void);
} // namespace Unittest::AttestTest
#endif // HUKS_ATTEST_TEST_H
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HUKS_ATTEST_TEST_COMMON_H
#define HUKS_ATTEST_TEST_COMMON_H
#include <securec.h>
#include "native_huks_api.h"
#include "huks_mem.h"
#include "native_huks_param.h"
#include "native_huks_type.h"
enum ParamType {
IDS_PARAM,
NON_IDS_PARAM,
};
struct HksTestCertChain {
bool certChainExist;
bool certCountValid;
bool certDataExist;
uint32_t certDataSize;
};
static uint32_t g_size = 4096;
static uint32_t CERT_COUNT = 4;
namespace Unittest::AttestKey {
#define SEC_INFO_DATA "hi_security_level_info"
#define CHALLENGE_DATA "hi_challenge_data"
#define VERSION_DATA "hi_os_version_data"
#define ALIAS "testKey"
#define UDID_DATA "hi_udid_data"
#define SN_DATA "hi_sn_data"
#define DEVICE_ID "test_device_id"
void FreeCertChain(struct OH_Huks_CertChain **certChain, const uint32_t pos);
OH_Huks_Result TestGenerateKey(const struct OH_Huks_Blob *keyAlias);
int32_t ConstructDataToCertChain(struct OH_Huks_CertChain **certChain,
const struct HksTestCertChain *certChainParam);
OH_Huks_Result GenerateParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param tmpParams[], uint32_t paramCount);
OH_Huks_Result ValidateCertChainTest(const struct OH_Huks_CertChain *certChain, const struct OH_Huks_Param tmpParam[],
ParamType type);
}
#endif
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HUKS_CIPHER_AES_TEST_H
#define HUKS_CIPHER_AES_TEST_H
namespace Unittest::AesCipher {
int Security_HUKS_NAPI_Cipher_AES_0100(void);
int Security_HUKS_NAPI_Cipher_AES_0200(void);
} // namespace Unittest::AesCipher
#endif // HUKS_CIPHER_AES_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_CIPHER_AES_TEST_COMMON_H
#define HUKS_CIPHER_AES_TEST_COMMON_H
#include <string>
#include "huks_three_stage_test_common.h"
namespace Unittest::AesCipher
{
static const uint32_t AES_COMMON_SIZE = 1024;
static const uint32_t IV_SIZE = 16;
static const uint32_t AAD_SIZE = 16;
static const uint32_t NONCE_SIZE = 12;
static const uint32_t AEAD_SIZE = 16;
static uint8_t IV[IV_SIZE] = {0};
static uint8_t AAD[AAD_SIZE] = {0};
static uint8_t NONCE[NONCE_SIZE] = {0};
static uint8_t AEAD[AEAD_SIZE] = {0};
static const std::string g_inData = "Hks_AES_Cipher_Test_000000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
OH_Huks_Result HksAesCipherTestEncrypt(
const struct OH_Huks_Blob *keyAlias,
const struct OH_Huks_ParamSet *encryptParamSet,
const struct OH_Huks_Blob *inData,
struct OH_Huks_Blob *cipherText);
OH_Huks_Result HksAesCipherTestDecrypt(
const struct OH_Huks_Blob *keyAlias,
const struct OH_Huks_ParamSet *decryptParamSet,
const struct OH_Huks_Blob *cipherText,
struct OH_Huks_Blob *plainText, const struct OH_Huks_Blob *inData);
OH_Huks_Result HksAesCipherTestCaseOther(
const struct OH_Huks_Blob *keyAlias,
struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *encryptParamSet,
struct OH_Huks_ParamSet *decryptParamSet);
OH_Huks_Result HksAesCipherTestCaseGcm2(
const struct OH_Huks_Blob *keyAlias,
struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *encryptParamSet,
struct OH_Huks_ParamSet *decryptParamSet, struct OH_Huks_ParamSet *decrypt1ParamSet);
} // namespace Unittest::AesCipher
#endif // HUKS_CIPHER_AES_TEST_COMMON_H
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HUKS_CIPHER_RSA_TEST_H
#define HUKS_CIPHER_RSA_TEST_H
namespace Unittest::RsaCipher {
int Security_HUKS_NAPI_Cipher_RSA_0100(void);
} // namespace Unittest::RsaCipher
#endif // HUKS_CIPHER_RSA_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_COMMON_RSA_TEST_COMMON_H
#define HUKS_COMMON_RSA_TEST_COMMON_H
#include <string>
#include "huks_three_stage_test_common.h"
namespace Unittest::RsaCipher {
static const uint32_t RSA_COMMON_SIZE = 1024;
static const std::string g_inData_5 = "RSA_5";
static const std::string g_inData_12 = "RSA_12_ttttt";
static const std::string g_inData_14 = "RSA_14_ttttttt";
static const std::string g_inData_20 = "RSA_20_ttttttttttttt";
static const std::string g_inData_32 = "RSA_32_ttttttttttttttttttttttttt";
static const std::string g_inData_64 = "RSA_64_ttttttttttttttttttttttttttttttttttttttttttttttttttttttttt";
static const std::string g_inData_96 = "RSA_96_ttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttt";
static const std::string g_inData_128 = "RSA_128_tttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt";
static const std::string g_inData_256 = "RSA_256_tttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt";
static const std::string g_inData_384 = "RSA_384_tttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt";
static const std::string g_inData_512 = "RSA_512_tttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
"tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt";
OH_Huks_Result HksRsaCipherTestCase(const struct OH_Huks_Blob *keyAlias, struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *encryptParamSet, struct OH_Huks_ParamSet *decryptParamSet, const struct OH_Huks_Blob *inData);
OH_Huks_Result HksRsaCipherTestCaseAbnormal(const struct OH_Huks_Blob *keyAlias, struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *encryptParamSet, struct OH_Huks_ParamSet *decryptParamSet, const struct OH_Huks_Blob *inData);
OH_Huks_Result HksRsaCipherTestEncrypt(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *encryptParamSet,
const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *cipherText);
OH_Huks_Result HksRsaCipherTestEncryptAbnormal(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *encryptParamSet,
const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *cipherText);
OH_Huks_Result HksRsaCipherTestDecrypt(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *decryptParamSet,
const struct OH_Huks_Blob *cipherText, struct OH_Huks_Blob *plainText, const struct OH_Huks_Blob *inData);
} // namespace Unittest::RsaCipher
#endif // HUKS_COMMON_RSA_TEST_COMMON_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HUKS_CIPHER_SM4_TEST_H
#define HUKS_CIPHER_SM4_TEST_H
namespace Unittest::SM4Cipher {
int Security_HUKS_NAPI_Cipher_SM4_0100(void);
} // namespace Unittest::SM4Cipher
#endif // HUKS_CIPHER_SM4_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_CIPHER_SM4_TEST_COMMON_H
#define HUKS_CIPHER_SM4_TEST_COMMON_H
#include <string>
#include "huks_three_stage_test_common.h"
namespace Unittest::Sm4Cipher {
static const uint32_t SM4_COMMON_SIZE = 256;
static const uint32_t IV_SIZE = 16;
static const uint32_t AAD_SIZE = 16;
static const uint32_t NONCE_SIZE = 12;
static const uint32_t AEAD_SIZE = 16;
static const uint32_t HKS_SM4_IV_SIZE = 16;
static uint8_t IV[IV_SIZE] = {0};
static uint8_t AAD[AAD_SIZE] = {0};
static uint8_t NONCE[NONCE_SIZE] = {0};
static uint8_t AEAD[AEAD_SIZE] = {0};
static const std::string g_inData = "Hks_SM4_Cipher_Test_000000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
struct FailureCaseParam {
uint32_t id;
int32_t result;
struct OH_Huks_Param params[6];
};
OH_Huks_Result HksSm4CipherTestCaseOther(const struct OH_Huks_Blob *keyAlias, struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *encryptParamSet, struct OH_Huks_ParamSet *decryptParamSet);
} // namespace Unittest::Sm4Cipher
#endif // HUKS_CIPHER_SM4_TEST_COMMON_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HUKS_DERIVE_HKDF_TEST_H
#define HUKS_DERIVE_HKDF_TEST_H
namespace Unittest::HkdfDerive {
int Security_HUKS_NAPI_Derive_hkdf_0100(void);
} // namespace Unittest::HkdfDerive
#endif // HUKS_DERIVE_HKDF_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_DERIVE_HKDF_TEST_COMMON_H
#define HUKS_DERIVE_HKDF_TEST_COMMON_H
#include <string>
#include "huks_three_stage_test_common.h"
namespace Unittest::HkdfDerive {
static const std::string g_inData = "Hks_HKDF_Derive_Test_00000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
static const uint32_t COMMON_SIZE = 2048;
static const uint32_t DERIVE_KEY_SIZE_32 = 32;
static const uint32_t DERIVE_KEY_SIZE_48 = 48;
static const uint32_t DERIVE_KEY_SIZE_64 = 64;
OH_Huks_Result HksHkdfDeriveTestNormalCase(const struct OH_Huks_Blob keyAlias, const struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *DeriveParamSet, struct OH_Huks_ParamSet *DeriveFinalParamsSet);
OH_Huks_Result HksHkdfDeriveTestCmpCase(const struct OH_Huks_Blob keyAlias, const struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *DeriveParamSet, struct OH_Huks_ParamSet *DeriveFinalParamsSet);
}
#endif // HUKS_DERIVE_HKDF_TEST_COMMON_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HUKS_DERIVE_PBKDF_TEST_H
#define HUKS_DERIVE_PBKDF_TEST_H
namespace Unittest::PbkdfDerive {
int Security_HUKS_NAPI_Derive_pbkdf_0100(void);
} // namespace Unittest::PbkdfDerive
#endif // HUKS_DERIVE_PBKDF_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_DERIVE_PBKDF_TEST_COMMON_H
#define HUKS_DERIVE_PBKDF_TEST_COMMON_H
#include <string>
#include "huks_three_stage_test_common.h"
namespace Unittest::Pbkdf2Derive {
static const std::string g_inData = "Hks_PBKDF2_Derive_Test_000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
static const uint32_t COMMON_SIZE = 2048;
static const uint32_t DERIVE_KEY_SIZE_32 = 32;
static const uint32_t DERIVE_KEY_SIZE_48 = 48;
static const uint32_t DERIVE_KEY_SIZE_64 = 64;
static const uint32_t DERIVE_ITERATION = 1000;
OH_Huks_Result HksPbkdf2DeriveTestNormalCase(const struct OH_Huks_Blob keyAlias, const struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *deriveParamSet, struct OH_Huks_ParamSet *deriveFinalParamsSet);
OH_Huks_Result HksPbkdf2DeriveTestCmpCase(const struct OH_Huks_Blob keyAlias, const struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *deriveParamSet, struct OH_Huks_ParamSet *deriveFinalParamsSet);
} // namespace Unittest::Pbkdf2Derive
#endif // HUKS_DERIVE_PBKDF2_TEST_COMMON_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_HMAC_TEST_H
#define HUKS_HMAC_TEST_H
#include <string>
#include "huks_three_stage_test_common.h"
namespace Unittest::Hmac {
static const std::string g_inData = "Hks_HMAC_Test_000000000000000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
const uint32_t COMMON_SIZE = 256;
struct GenerateKeyCaseParam {
uint32_t id;
int32_t result;
struct OH_Huks_Param params[4];
};
int Security_HUKS_NAPI_HMAC_hmac_0100(void);
int Security_HUKS_NAPI_HMAC_SM3_0100(void);
}
#endif // HUKS_HMAC_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HUKS_MEM_H
#define HUKS_MEM_H
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
void *HksMalloc(size_t size);
void HksFree(void *ptr);
int32_t HksMemCmp(const void *ptr1, const void *ptr2, uint32_t size);
#define OH_HUKS_KEY_BYTES(keySize) (((keySize) + 7) / 8)
#ifdef __cplusplus
}
#endif
#endif /* HUKS_MEM_H */
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#include <gtest/gtest.h>
#include <unistd.h>
#include "native_huks_api.h"
#include "native_huks_type.h"
#include "native_huks_param.h"
#ifndef HUKS_MISC_TEST_H
#define HUKS_MISC_TEST_H
namespace Unittest::MiscTest {
int Security_HUKS_NAPI_Misc_0100(void);
} // namespace Unittest::MiscTest
#endif // HUKS_MISC_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HUKS_NULLPTR_TEST_H
#define HUKS_NULLPTR_TEST_H
namespace Unittest::NullptrTest {
int Security_HUKS_NAPI_nullptr_0100(void);
} // namespace Unittest::NullptrTest
#endif // HUKS_NULLPTR_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_SIGNVERIFY_DSA_TEST_H
#define HUKS_SIGNVERIFY_DSA_TEST_H
#include <string>
#include "huks_three_stage_test_common.h"
namespace Unittest::DsaSignVerify {
static const uint32_t DSA_COMMON_SIZE = 1024;
static const std::string g_inData = "Hks_DSA_Sign_Verify_Test_0000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
}
#endif // HUKS_SIGNVERIFY_DSA_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HKS_SIGNVERIFY_ECC_TEST_H
#define HKS_SIGNVERIFY_ECC_TEST_H
namespace Unittest::EccSignVerify {
int Security_HUKS_NAPI_SignVerify_ECC_0100(void);
} // namespace Unittest::AesCipher
#endif // HKS_SIGNVERIFY_ECC_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_SIGNVERIFY_ECC_TEST_COMMON_H
#define HUKS_SIGNVERIFY_ECC_TEST_COMMON_H
#include <string>
#include "huks_three_stage_test_common.h"
namespace Unittest::EccSifnVerify {
static const std::string g_inData = "Hks_ECC_Sign_Verify_Test_0000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
static const uint32_t ECC_COMMON_SIZE = 1024;
OH_Huks_Result HksEccSignVerifyTestNormalCase(struct OH_Huks_Blob keyAlias, struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *signParamSet, struct OH_Huks_ParamSet *verifyParamSet);
OH_Huks_Result HksTestSignVerify(struct OH_Huks_Blob *keyAlias, struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *inData,
struct OH_Huks_Blob *outData, bool isSign);
} // namespace Unittest::EccSifnVerify
#endif // HUKS_SIGNVERIFY_ECC_TEST_COMMON_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_SIGNVERIFY_ED25519_TEST_H
#define HUKS_SIGNVERIFY_ED25519_TEST_H
#include <string>
#include "huks_three_stage_test_common.h"
namespace Unittest::Ed25519 {
static const std::string tmpInData = "OH_HUKS_ED25519_Sign_Verify_Test_000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
static const struct OH_Huks_Blob g_inData = { tmpInData.length(), (uint8_t *)tmpInData.c_str() };
static const uint32_t ED25519_COMMON_SIZE = 1024;
static struct OH_Huks_Param g_genParamsTest001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ED25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_SIGN | OH_HUKS_KEY_PURPOSE_VERIFY
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
static struct OH_Huks_Param g_signParamsTest001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ED25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_SIGN
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
static struct OH_Huks_Param g_verifyParamsTest001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ED25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_VERIFY
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
static struct OH_Huks_Param g_genParamsTest002[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ED25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_SIGN | OH_HUKS_KEY_PURPOSE_VERIFY
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
static struct OH_Huks_Param g_signParamsTest002[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ED25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_SIGN
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
static struct OH_Huks_Param g_verifyParamsTest002[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ED25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_VERIFY
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
static struct OH_Huks_Param g_genParamsTest003[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ED25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_SIGN | OH_HUKS_KEY_PURPOSE_VERIFY
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
static struct OH_Huks_Param g_signParamsTest003[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ED25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_SIGN
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
static struct OH_Huks_Param g_genParamsTest004[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ED25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_SIGN | OH_HUKS_KEY_PURPOSE_VERIFY
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
static struct OH_Huks_Param g_signParamsTest004[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ED25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_SIGN
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}
};
} // namespace Unittest::Ed25519
#endif // HUKS_SIGNVERIFY_ED25519_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HKS_SIGNVERIFY_RSA_TEST_H
#define HKS_SIGNVERIFY_RSA_TEST_H
namespace Unittest::RsaSignVerify {
int Security_HUKS_NAPI_SignVerify_RSA_0100(void);
} // namespace Unittest::AesCipher
#endif // HKS_SIGNVERIFY_RSA_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HKS_SIGNVERIFY_RSA_TEST_COMMON_H
#define HKS_SIGNVERIFY_RSA_TEST_COMMON_H
#include <string>
#include "huks_three_stage_test_common.h"
namespace Unittest::RsaSignVerify {
static const std::string g_inData = "Hks_RSA_Sign_Verify_Test_0000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
static const uint32_t RSA_COMMON_SIZE = 1024;
OH_Huks_Result HksRsaSignVerifyTestNormalCase(struct OH_Huks_Blob keyAlias, struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *signParamSet, struct OH_Huks_ParamSet *verifyParamSet);
OH_Huks_Result HksRSASignVerifyTestAbnormalCase(struct OH_Huks_Blob keyAlias, struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *signParamSet, struct OH_Huks_ParamSet *verifyParamSet);
OH_Huks_Result HksTestSignVerify(struct OH_Huks_Blob *keyAlias, struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *inData,
struct OH_Huks_Blob *outData, bool isSign);
} // namespace Unittest::RsaSignVerify
#endif // HKS_SIGNVERIFY_RSA_TEST_COMMON_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_SIGNVERIFY_SM2_TEST_H
#define HUKS_SIGNVERIFY_SM2_TEST_H
#include <string>
#include "huks_three_stage_test_common.h"
namespace Unittest::Sm2SignVerify {
static const std::string g_inData = "Hks_SM2_Sign_Verify_Test_0000000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000000000000_string";
static const uint32_t SM2_COMMON_SIZE = 1024;
struct GenerateKeyCaseParam {
uint32_t id;
int32_t result;
struct OH_Huks_Param params[4];
};
int Security_HUKS_NAPI_SignVerify_SM2_0100(void);
}
#endif // HUKS_SIGNVERIFY_SM2_TEST_H
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HUKS_THREE_STAGE_TEST_COMMON_H
#define HUKS_THREE_STAGE_TEST_COMMON_H
#include <securec.h>
#include "native_huks_api.h"
#include "native_huks_param.h"
#include "native_huks_type.h"
#include "huks_mem.h"
#include <openssl/err.h>
#include <openssl/evp.h>
#include <stdbool.h>
#include <stddef.h>
#include "hks_api.h"
#define HKS_DIGEST_MD5_LEN 16
#define HKS_DIGEST_SHA1_LEN 20
#define HKS_DIGEST_SHA224_LEN 28
#define HKS_DIGEST_SHA256_LEN 32
#define HKS_DIGEST_SHA384_LEN 48
#define HKS_DIGEST_SHA512_LEN 64
#define HKS_DIGEST_SM3_LEN 32
#ifdef __cplusplus
extern "C"
{
#endif
static const uint32_t TIMES = 4;
static const uint32_t MAX_UPDATE_SIZE = 64;
static const uint32_t MAX_OUTDATA_SIZE = MAX_UPDATE_SIZE * TIMES;
OH_Huks_Result InitParamSet(
struct OH_Huks_ParamSet **paramSet,
const struct OH_Huks_Param *params,
uint32_t paramcount);
OH_Huks_Result HksTestUpdate(
const struct OH_Huks_Blob *handle,
const struct OH_Huks_ParamSet *paramSet,
const struct OH_Huks_Blob *inData);
OH_Huks_Result TestUpdateLoopFinish(
const struct OH_Huks_Blob *handle,
const struct OH_Huks_ParamSet *paramSet,
const struct OH_Huks_Blob *inData,
struct OH_Huks_Blob *outData);
OH_Huks_Result TestUpdateFinish(
const struct OH_Huks_Blob *handle,
const struct OH_Huks_ParamSet *paramSet,
uint32_t purpose,
const struct OH_Huks_Blob *inData,
struct OH_Huks_Blob *outData);
OH_Huks_Result MallocAndCheckBlobData(
struct OH_Huks_Blob *blob,
const uint32_t blobSize);
OH_Huks_Result TestCmpKeyAliasHash(
const struct OH_Huks_Blob *srcData1,
const struct OH_Huks_Blob *srcData2);
OH_Huks_Result HuksEncrypt(
const struct OH_Huks_Blob *key,
const struct OH_Huks_ParamSet *paramSet,
const struct OH_Huks_Blob *plainText,
struct OH_Huks_Blob *cipherText);
OH_Huks_Result HuksHash(
const struct OH_Huks_ParamSet *paramSet,
const struct OH_Huks_Blob *srcData,
struct OH_Huks_Blob *hash);
#ifdef __cplusplus
}
#endif
#endif // HUKS_THREE_STAGE_TEST_COMMON_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_three_stage_test_common.h"
#ifndef HUKS_WARPPED_TEST_H
#define HUKS_WARPPED_TEST_H
namespace Unittest::ImportWrapped {
int Security_HUKS_NAPI_Wrapped_0100(void);
} // namespace Unittest::ImportWrapped
#endif // HUKS_WARPPED_TEST_H
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_agree_dh_test.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::DhAgree {
class HuksAgreeDHTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HuksAgreeDHTest::SetUpTestCase(void)
{
}
void HuksAgreeDHTest::TearDownTestCase(void)
{
}
void HuksAgreeDHTest::SetUp()
{
}
void HuksAgreeDHTest::TearDown()
{
}
OH_Huks_Result HksDhAgreeFinish(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_Blob *publicKey,
const struct OH_Huks_ParamSet *initParamSet, const struct OH_Huks_ParamSet *finishParamSet,
struct OH_Huks_Blob *outData)
{
struct OH_Huks_Blob inData = { g_inData.length(), (uint8_t *)g_inData.c_str() };
uint8_t handleU[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handle = { sizeof(uint64_t), handleU };
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, initParamSet, &handle, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
uint8_t outDataU[DH_COMMON_SIZE] = {0};
struct OH_Huks_Blob outDataUpdate = { DH_COMMON_SIZE, outDataU };
ret = OH_Huks_UpdateSession(&handle, initParamSet, publicKey, &outDataUpdate);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Update failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = OH_Huks_FinishSession(&handle, finishParamSet, &inData, outData);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Finish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
return ret;
}
OH_Huks_Result HksDhAgreeAbort(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_Blob *publicKey,
const struct OH_Huks_ParamSet *initParamSet)
{
uint8_t handleU[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handle = { sizeof(uint64_t), handleU };
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, initParamSet, &handle, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
uint8_t outDataU[DH_COMMON_SIZE] = {0};
struct OH_Huks_Blob outDataUpdate = { DH_COMMON_SIZE, outDataU };
ret = OH_Huks_UpdateSession(&handle, initParamSet, publicKey, &outDataUpdate);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Update failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = OH_Huks_AbortSession(&handle, initParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Finish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
return ret;
}
OH_Huks_Result HksDhAgreeExport(const struct OH_Huks_Blob *keyAlias1, const struct OH_Huks_Blob *keyAlias2,
struct OH_Huks_Blob *publicKey1, struct OH_Huks_Blob *publicKey2,
const struct OH_Huks_ParamSet *genParamSet)
{
OH_Huks_Result ret = OH_Huks_ExportPublicKeyItem(keyAlias1, genParamSet, publicKey1);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "ExportPublicKey01 failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = OH_Huks_ExportPublicKeyItem(keyAlias2, genParamSet, publicKey2);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "ExportPublicKey02 failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
return ret;
}
void HksDhAgreeFreeParamSet(struct OH_Huks_ParamSet *paramSet1, struct OH_Huks_ParamSet *paramSet2,
struct OH_Huks_ParamSet *paramSet3)
{
OH_Huks_FreeParamSet(&paramSet1);
OH_Huks_FreeParamSet(&paramSet2);
OH_Huks_FreeParamSet(&paramSet3);
}
void HksDhAgreeFreeParamSet(struct OH_Huks_ParamSet *paramSet1, struct OH_Huks_ParamSet *paramSet2,
struct OH_Huks_ParamSet *paramSet3, struct OH_Huks_ParamSet *paramSet4,
struct OH_Huks_ParamSet *paramSet5)
{
OH_Huks_FreeParamSet(&paramSet1);
OH_Huks_FreeParamSet(&paramSet2);
OH_Huks_FreeParamSet(&paramSet3);
OH_Huks_FreeParamSet(&paramSet4);
OH_Huks_FreeParamSet(&paramSet5);
}
void HksDhAgreeFreeBlob(struct OH_Huks_Blob *blob1, struct OH_Huks_Blob *blob2)
{
HksFree(blob1->data);
HksFree(blob2->data);
}
void HksDhAgreeFreeBlob(struct OH_Huks_Blob *blob1, struct OH_Huks_Blob *blob2, struct OH_Huks_Blob *blob3, struct OH_Huks_Blob *blob4)
{
HksFree(blob1->data);
HksFree(blob2->data);
HksFree(blob3->data);
HksFree(blob4->data);
}
/**
* @tc.name: HuksAgreeDHTest.Security_HUKS_NAPI_Agree_DH_0100
* @tc.desc: alg-DH, pur-AGREE
* @tc.type: FUNC
*/
HWTEST_F(HuksAgreeDHTest, Security_HUKS_NAPI_Agree_DH_0100, TestSize.Level0)
{
struct OH_Huks_ParamSet *genParamSet = nullptr;
struct OH_Huks_ParamSet *initParamSet01 = nullptr;
struct OH_Huks_ParamSet *finishParamSet01 = nullptr;
struct OH_Huks_ParamSet *initParamSet02 = nullptr;
struct OH_Huks_ParamSet *finishParamSet02 = nullptr;
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParams001, sizeof(g_genParams001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(gen) failed.";
ret = InitParamSet(&initParamSet01, g_agreeParams01Init001, sizeof(g_agreeParams01Init001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(init & update)01 failed.";
ret = InitParamSet(&finishParamSet01, g_agreeParams01Finish001,
sizeof(g_agreeParams01Finish001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(finish)01 failed.";
ret = InitParamSet(&initParamSet02, g_agreeParams02Init001, sizeof(g_agreeParams02Init001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(init & update)02 failed.";
ret = InitParamSet(&finishParamSet02, g_agreeParams02Finish001,
sizeof(g_agreeParams02Finish001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(finish)02 failed.";
OH_Huks_Result ret1 = OH_Huks_GenerateKeyItem(&g_keyAlias01001, genParamSet, nullptr);
EXPECT_EQ(ret1.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey01 failed.";
ret1 = OH_Huks_GenerateKeyItem(&g_keyAlias02001, genParamSet, nullptr);
EXPECT_EQ(ret1.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey02 failed.";
struct OH_Huks_Blob publicKey01 = { .size = OH_HUKS_DH_KEY_SIZE_4096, .data = nullptr };
struct OH_Huks_Blob publicKey02 = { .size = OH_HUKS_DH_KEY_SIZE_4096, .data = nullptr };
ret = MallocAndCheckBlobData(&publicKey01, publicKey01.size);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Malloc publicKey01 failed.";
ret = MallocAndCheckBlobData(&publicKey02, publicKey02.size);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Malloc publicKey02 failed.";
ret = HksDhAgreeExport(&g_keyAlias01001, &g_keyAlias02001, &publicKey01, &publicKey02, genParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "ExportKey failed.";
struct OH_Huks_Blob outData01 = { .size = DH_COMMON_SIZE, .data = nullptr };
struct OH_Huks_Blob outData02 = { .size = DH_COMMON_SIZE, .data = nullptr };
ret = MallocAndCheckBlobData(&outData01, outData01.size);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Malloc outData01 failed.";
ret = MallocAndCheckBlobData(&outData02, outData02.size);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Malloc outData02 failed.";
ret = HksDhAgreeFinish(&g_keyAlias01001, &publicKey02, initParamSet01, finishParamSet01, &outData01);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksDhAgreeFinish01 failed.";
ret = HksDhAgreeFinish(&g_keyAlias02001, &publicKey01, initParamSet02, finishParamSet02, &outData02);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksDhAgreeFinish02 failed.";
OH_Huks_DeleteKeyItem(&g_keyAlias01001, genParamSet);
OH_Huks_DeleteKeyItem(&g_keyAlias02001, genParamSet);
OH_Huks_DeleteKeyItem(&g_keyAliasFinal1001, NULL);
OH_Huks_DeleteKeyItem(&g_keyAliasFinal2001, NULL);
HksDhAgreeFreeParamSet(genParamSet, initParamSet01, finishParamSet01, initParamSet02, finishParamSet02);
HksDhAgreeFreeBlob(&publicKey01, &publicKey02, &outData01, &outData02);
}
} // namespace Unittest::DhAgree
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_agree_ecdh_test.h"
#include "huks_agree_ecdh_test_common.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::EcdhAgree {
class HuksAgreeECDHTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HuksAgreeECDHTest::SetUpTestCase(void)
{
}
void HuksAgreeECDHTest::TearDownTestCase(void)
{
}
void HuksAgreeECDHTest::SetUp()
{
}
void HuksAgreeECDHTest::TearDown()
{
}
static struct OH_Huks_Blob g_keyAlias01001 = {
strlen("HksECDHAgreeKeyAliasTest001_1"),
(uint8_t *)"HksECDHAgreeKeyAliasTest001_1"
};
static struct OH_Huks_Blob g_keyAlias02001 = {
strlen("HksECDHAgreeKeyAliasTest001_2"),
(uint8_t *)"HksECDHAgreeKeyAliasTest001_2"
};
static struct OH_Huks_Blob g_keyAliasFinal1001 = {
strlen("HksECDHAgreeKeyAliasTest001_1_final"),
(uint8_t *)"HksECDHAgreeKeyAliasTest001_1_final"
};
static struct OH_Huks_Blob g_keyAliasFinal2001 = {
strlen("HksECDHAgreeKeyAliasTest001_2_final"),
(uint8_t *)"HksECDHAgreeKeyAliasTest001_2_final"
};
static struct OH_Huks_Param g_genParams001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ECC
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_AGREE
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_ECC_KEY_SIZE_224
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_NONE
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}
};
static struct OH_Huks_Param g_agreeParams01Init001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ECDH
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_AGREE
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_ECC_KEY_SIZE_224
}
};
static struct OH_Huks_Param g_agreeParams01Finish001[] = {
{
.tag = OH_HUKS_TAG_KEY_STORAGE_FLAG,
.uint32Param = OH_HUKS_STORAGE_PERSISTENT
}, {
.tag = OH_HUKS_TAG_IS_KEY_ALIAS,
.boolParam = true
}, {
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA256
}, {
.tag = OH_HUKS_TAG_KEY_ALIAS,
.blob = g_keyAliasFinal1001
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}
};
static struct OH_Huks_Param g_agreeParams02Init001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_ECDH
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_AGREE
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_ECC_KEY_SIZE_224
}
};
static struct OH_Huks_Param g_agreeParams02Finish001[] = {
{
.tag = OH_HUKS_TAG_KEY_STORAGE_FLAG,
.uint32Param = OH_HUKS_STORAGE_PERSISTENT
}, {
.tag = OH_HUKS_TAG_IS_KEY_ALIAS,
.boolParam = true
}, {
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA256
}, {
.tag = OH_HUKS_TAG_KEY_ALIAS,
.blob = g_keyAliasFinal2001
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}
};
/**
* @tc.name: HuksAgreeECDHTest.Security_HUKS_NAPI_Agree_ECDH_0100
* @tc.desc: alg-ECDH, pur-AGREE
* @tc.type: FUNC
*/
HWTEST_F(HuksAgreeECDHTest, Security_HUKS_NAPI_Agree_ECDH_0100, TestSize.Level0)
{
struct OH_Huks_ParamSet *genParamSet = nullptr;
struct OH_Huks_ParamSet *initParamSet01 = nullptr;
struct OH_Huks_ParamSet *finishParamSet01 = nullptr;
struct OH_Huks_ParamSet *initParamSet02 = nullptr;
struct OH_Huks_ParamSet *finishParamSet02 = nullptr;
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParams001, sizeof(g_genParams001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(gen) failed.";
ret = InitParamSet(&initParamSet01, g_agreeParams01Init001, sizeof(g_agreeParams01Init001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(init & update)01 failed.";
ret = InitParamSet(&finishParamSet01, g_agreeParams01Finish001,
sizeof(g_agreeParams01Finish001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(finish)01 failed.";
ret = InitParamSet(&initParamSet02, g_agreeParams02Init001, sizeof(g_agreeParams02Init001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(init & update)02 failed.";
ret = InitParamSet(&finishParamSet02, g_agreeParams02Finish001,
sizeof(g_agreeParams02Finish001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(finish)02 failed.";
OH_Huks_Result ret1 = OH_Huks_GenerateKeyItem(&g_keyAlias01001, genParamSet, nullptr);
EXPECT_EQ(ret1.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey01 failed.";
ret1 = OH_Huks_GenerateKeyItem(&g_keyAlias02001, genParamSet, nullptr);
EXPECT_EQ(ret1.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey02 failed.";
struct OH_Huks_Blob publicKey01 = { .size = OH_HUKS_ECC_KEY_SIZE_224, .data = nullptr };
struct OH_Huks_Blob publicKey02 = { .size = OH_HUKS_ECC_KEY_SIZE_224, .data = nullptr };
ret = MallocAndCheckBlobData(&publicKey01, publicKey01.size);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Malloc publicKey01 failed.";
ret = MallocAndCheckBlobData(&publicKey02, publicKey02.size);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Malloc publicKey02 failed.";
ret = HksEcdhAgreeExport(&g_keyAlias01001, &g_keyAlias02001, &publicKey01, &publicKey02, genParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "ExportKey failed.";
struct OH_Huks_Blob outData01 = { .size = ECDH_COMMON_SIZE, .data = nullptr };
struct OH_Huks_Blob outData02 = { .size = ECDH_COMMON_SIZE, .data = nullptr };
ret = MallocAndCheckBlobData(&outData01, outData01.size);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Malloc outData01 failed.";
ret = MallocAndCheckBlobData(&outData02, outData02.size);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Malloc outData02 failed.";
ret = HksEcdhAgreeFinish(&g_keyAlias01001, &publicKey02, initParamSet01, finishParamSet01, &outData01);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksEcdhAgreeFinish01 failed.";
ret = HksEcdhAgreeFinish(&g_keyAlias02001, &publicKey01, initParamSet02, finishParamSet02, &outData02);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksEcdhAgreeFinish02 failed.";
OH_Huks_DeleteKeyItem(&g_keyAlias01001, genParamSet);
OH_Huks_DeleteKeyItem(&g_keyAlias02001, genParamSet);
OH_Huks_DeleteKeyItem(&g_keyAliasFinal1001, NULL);
OH_Huks_DeleteKeyItem(&g_keyAliasFinal2001, NULL);
HksEcdhAgreeFreeParamSet(genParamSet, initParamSet01, finishParamSet01, initParamSet02, finishParamSet02);
HksEcdhAgreeFreeBlob(&publicKey01, &publicKey02, &outData01, &outData02);
}
} // namespace Unittest::EcdhAgree
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_agree_ecdh_test_common.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::EcdhAgree {
OH_Huks_Result HksEcdhAgreeFinish(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_Blob *publicKey,
const struct OH_Huks_ParamSet *initParamSet, const struct OH_Huks_ParamSet *finishParamSet, struct OH_Huks_Blob *outData)
{
struct OH_Huks_Blob inData = {
g_inData.length(),
(uint8_t *)g_inData.c_str()
};
uint8_t handleU[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handle = { sizeof(uint64_t), handleU };
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, initParamSet, &handle, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
uint8_t outDataU[ECDH_COMMON_SIZE] = {0};
struct OH_Huks_Blob outDataUpdate = { ECDH_COMMON_SIZE, outDataU };
ret = OH_Huks_UpdateSession(&handle, initParamSet, publicKey, &outDataUpdate);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Update failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = OH_Huks_FinishSession(&handle, finishParamSet, &inData, outData);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Finish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
return ret;
}
OH_Huks_Result HksEcdhAgreeAbort(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_Blob *publicKey,
const struct OH_Huks_ParamSet *initParamSet)
{
uint8_t handleU[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handle = { sizeof(uint64_t), handleU };
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, initParamSet, &handle, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
uint8_t outDataU[ECDH_COMMON_SIZE] = {0};
struct OH_Huks_Blob outDataUpdate = { ECDH_COMMON_SIZE, outDataU };
ret = OH_Huks_UpdateSession(&handle, initParamSet, publicKey, &outDataUpdate);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Update failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = OH_Huks_AbortSession(&handle, initParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Finish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
return ret;
}
OH_Huks_Result HksEcdhAgreeExport(const struct OH_Huks_Blob *keyAlias1, const struct OH_Huks_Blob *keyAlias2,
struct OH_Huks_Blob *publicKey1, struct OH_Huks_Blob *publicKey2, const struct OH_Huks_ParamSet *genParamSet)
{
OH_Huks_Result ret = OH_Huks_ExportPublicKeyItem(keyAlias1, genParamSet, publicKey1);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "ExportPublicKey01 failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = OH_Huks_ExportPublicKeyItem(keyAlias2, genParamSet, publicKey2);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "ExportPublicKey02 failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
return ret;
}
void HksEcdhAgreeFreeParamSet(struct OH_Huks_ParamSet *paramSet1, struct OH_Huks_ParamSet *paramSet2,
struct OH_Huks_ParamSet *paramSet3)
{
OH_Huks_FreeParamSet(&paramSet1);
OH_Huks_FreeParamSet(&paramSet2);
OH_Huks_FreeParamSet(&paramSet3);
}
void HksEcdhAgreeFreeParamSet(struct OH_Huks_ParamSet *paramSet1, struct OH_Huks_ParamSet *paramSet2,
struct OH_Huks_ParamSet *paramSet3, struct OH_Huks_ParamSet *paramSet4, struct OH_Huks_ParamSet *paramSet5)
{
OH_Huks_FreeParamSet(&paramSet1);
OH_Huks_FreeParamSet(&paramSet2);
OH_Huks_FreeParamSet(&paramSet3);
OH_Huks_FreeParamSet(&paramSet4);
OH_Huks_FreeParamSet(&paramSet5);
}
void HksEcdhAgreeFreeBlob(struct OH_Huks_Blob *blob1, struct OH_Huks_Blob *blob2)
{
HksFree(blob1->data);
HksFree(blob2->data);
}
void HksEcdhAgreeFreeBlob(struct OH_Huks_Blob *blob1, struct OH_Huks_Blob *blob2,
struct OH_Huks_Blob *blob3, struct OH_Huks_Blob *blob4)
{
HksFree(blob1->data);
HksFree(blob2->data);
HksFree(blob3->data);
HksFree(blob4->data);
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_agree_x25519_test.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::X25519Agree {
class HuksAgreeX25519Test : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HuksAgreeX25519Test::SetUpTestCase(void)
{
}
void HuksAgreeX25519Test::TearDownTestCase(void)
{
}
void HuksAgreeX25519Test::SetUp()
{
}
void HuksAgreeX25519Test::TearDown()
{
}
static struct OH_Huks_Blob g_keyAlias01001 = {
strlen("HksX25519AgreeKeyAliasTest001_1"),
(uint8_t *)"HksX25519AgreeKeyAliasTest001_1"
};
static struct OH_Huks_Blob g_keyAlias02001 = {
strlen("HksX25519AgreeKeyAliasTest001_2"),
(uint8_t *)"HksX25519AgreeKeyAliasTest001_2"
};
static struct OH_Huks_Blob g_keyAliasFinal1001 = {
strlen("HksX25519AgreeKeyAliasTest001_final"),
(uint8_t *)"HksX25519AgreeKeyAliasTest001_final"
};
static struct OH_Huks_Blob g_keyAliasFinal2001 = {
strlen("HksX25519AgreeKeyAliasTest002_final"),
(uint8_t *)"HksX25519AgreeKeyAliasTest002_final"
};
static struct OH_Huks_Param g_genParams001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_X25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_AGREE
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}
};
static struct OH_Huks_Param g_agreeParams01Init001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_X25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_AGREE
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}
};
static struct OH_Huks_Param g_agreeParams01Finish001[] = {
{
.tag = OH_HUKS_TAG_KEY_STORAGE_FLAG,
.uint32Param = OH_HUKS_STORAGE_PERSISTENT
}, {
.tag = OH_HUKS_TAG_IS_KEY_ALIAS, .boolParam = true
}, {
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA256
}, {
.tag = OH_HUKS_TAG_KEY_ALIAS, .blob = g_keyAliasFinal1001
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}
};
static struct OH_Huks_Param g_agreeParams02Init001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_X25519
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_AGREE
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256
}
};
static struct OH_Huks_Param g_agreeParams02Finish001[] = {
{
.tag = OH_HUKS_TAG_KEY_STORAGE_FLAG,
.uint32Param = OH_HUKS_STORAGE_PERSISTENT
}, {
.tag = OH_HUKS_TAG_IS_KEY_ALIAS, .boolParam = true
}, {
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA256
}, {
.tag = OH_HUKS_TAG_KEY_ALIAS, .blob = g_keyAliasFinal2001
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}
};
OH_Huks_Result HksX25519AgreeFinish(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_Blob *publicKey,
const struct OH_Huks_ParamSet *initParamSet, const struct OH_Huks_ParamSet *finishParamSet, struct OH_Huks_Blob *outData)
{
struct OH_Huks_Blob inData = {
g_inData.length(),
(uint8_t *)g_inData.c_str()
};
uint8_t handleU[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handle = { sizeof(uint64_t), handleU };
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, initParamSet, &handle, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
uint8_t outDataU[X25519_COMMON_SIZE] = {0};
struct OH_Huks_Blob outDataUpdate = { X25519_COMMON_SIZE, outDataU };
ret = OH_Huks_UpdateSession(&handle, initParamSet, publicKey, &outDataUpdate);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Update failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = OH_Huks_FinishSession(&handle, finishParamSet, &inData, outData);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Finish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
return ret;
}
OH_Huks_Result HksX25519AgreeAbort(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_Blob *publicKey,
const struct OH_Huks_ParamSet *initParamSet)
{
uint8_t handleU[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handle = { sizeof(uint64_t), handleU };
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, initParamSet, &handle, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
uint8_t outDataU[X25519_COMMON_SIZE] = {0};
struct OH_Huks_Blob outDataUpdate = { X25519_COMMON_SIZE, outDataU };
ret = OH_Huks_UpdateSession(&handle, initParamSet, publicKey, &outDataUpdate);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Update failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = OH_Huks_AbortSession(&handle, initParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Finish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
return ret;
}
OH_Huks_Result HksX25519AgreeExport(const struct OH_Huks_Blob *keyAlias1, const struct OH_Huks_Blob *keyAlias2,
struct OH_Huks_Blob *publicKey1, struct OH_Huks_Blob *publicKey2, const struct OH_Huks_ParamSet *genParamSet)
{
OH_Huks_Result ret = OH_Huks_ExportPublicKeyItem(keyAlias1, genParamSet, publicKey1);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "ExportPublicKey01 failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = OH_Huks_ExportPublicKeyItem(keyAlias2, genParamSet, publicKey2);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "ExportPublicKey02 failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
return ret;
}
void HksX25519AgreeFreeParamSet(struct OH_Huks_ParamSet *paramSet1, struct OH_Huks_ParamSet *paramSet2,
struct OH_Huks_ParamSet *paramSet3)
{
OH_Huks_FreeParamSet(&paramSet1);
OH_Huks_FreeParamSet(&paramSet2);
OH_Huks_FreeParamSet(&paramSet3);
}
void HksX25519AgreeFreeParamSet(struct OH_Huks_ParamSet *paramSet1, struct OH_Huks_ParamSet *paramSet2,
struct OH_Huks_ParamSet *paramSet3, struct OH_Huks_ParamSet *paramSet4, struct OH_Huks_ParamSet *paramSet5)
{
OH_Huks_FreeParamSet(&paramSet1);
OH_Huks_FreeParamSet(&paramSet2);
OH_Huks_FreeParamSet(&paramSet3);
OH_Huks_FreeParamSet(&paramSet4);
OH_Huks_FreeParamSet(&paramSet5);
}
void HksX25519AgreeFreeBlob(struct OH_Huks_Blob *blob1, struct OH_Huks_Blob *blob2)
{
HksFree(blob1->data);
HksFree(blob2->data);
}
void HksX25519AgreeFreeBlob(struct OH_Huks_Blob *blob1, struct OH_Huks_Blob *blob2, struct OH_Huks_Blob *blob3, struct OH_Huks_Blob *blob4)
{
HksFree(blob1->data);
HksFree(blob2->data);
HksFree(blob3->data);
HksFree(blob4->data);
}
/**
* @tc.name: HuksAgreeX25519Test.Security_HUKS_NAPI_Agree_X25519_0100
* @tc.desc: alg-x25519, pur-AGREE
* @tc.type: FUNC
*/
HWTEST_F(HuksAgreeX25519Test, Security_HUKS_NAPI_Agree_X25519_0100, TestSize.Level0)
{
struct OH_Huks_ParamSet *genParamSet = nullptr;
struct OH_Huks_ParamSet *initParamSet01 = nullptr;
struct OH_Huks_ParamSet *finishParamSet01 = nullptr;
struct OH_Huks_ParamSet *initParamSet02 = nullptr;
struct OH_Huks_ParamSet *finishParamSet02 = nullptr;
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParams001, sizeof(g_genParams001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(gen) failed.";
ret = InitParamSet(&initParamSet01, g_agreeParams01Init001, sizeof(g_agreeParams01Init001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(init & update)01 failed.";
ret = InitParamSet(&finishParamSet01, g_agreeParams01Finish001,
sizeof(g_agreeParams01Finish001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(finish)01 failed.";
ret = InitParamSet(&initParamSet02, g_agreeParams02Init001, sizeof(g_agreeParams02Init001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(init & update)02 failed.";
ret = InitParamSet(&finishParamSet02, g_agreeParams02Finish001,
sizeof(g_agreeParams02Finish001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(finish)02 failed.";
ret = OH_Huks_GenerateKeyItem(&g_keyAlias01001, genParamSet, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey01 failed.";
ret = OH_Huks_GenerateKeyItem(&g_keyAlias02001, genParamSet, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey02 failed.";
struct OH_Huks_Blob publicKey01 = { .size = OH_HUKS_CURVE25519_KEY_SIZE_256, .data = nullptr };
struct OH_Huks_Blob publicKey02 = { .size = OH_HUKS_CURVE25519_KEY_SIZE_256, .data = nullptr };
EXPECT_EQ(MallocAndCheckBlobData(&publicKey01, publicKey01.size).errorCode, (int32_t)OH_HUKS_SUCCESS) << "Malloc publicKey01 failed.";
EXPECT_EQ(MallocAndCheckBlobData(&publicKey02, publicKey02.size).errorCode, (int32_t)OH_HUKS_SUCCESS) << "Malloc publicKey02 failed.";
ret = HksX25519AgreeExport(&g_keyAlias01001, &g_keyAlias02001, &publicKey01, &publicKey02, genParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "ExportKey failed.";
struct OH_Huks_Blob outData01 = { .size = X25519_COMMON_SIZE, .data = nullptr };
struct OH_Huks_Blob outData02 = { .size = X25519_COMMON_SIZE, .data = nullptr };
EXPECT_EQ(MallocAndCheckBlobData(&outData01, outData01.size).errorCode, (int32_t)OH_HUKS_SUCCESS) << "Malloc outData01 failed.";
EXPECT_EQ(MallocAndCheckBlobData(&outData02, outData02.size).errorCode, (int32_t)OH_HUKS_SUCCESS) << "Malloc outData02 failed.";
ret = HksX25519AgreeFinish(&g_keyAlias01001, &publicKey02, initParamSet01, finishParamSet01, &outData01);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksX25519AgreeFinish01 failed.";
ret = HksX25519AgreeFinish(&g_keyAlias02001, &publicKey01, initParamSet02, finishParamSet02, &outData02);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksX25519AgreeFinish02 failed.";
OH_Huks_DeleteKeyItem(&g_keyAlias01001, genParamSet);
OH_Huks_DeleteKeyItem(&g_keyAlias02001, genParamSet);
OH_Huks_DeleteKeyItem(&g_keyAliasFinal1001, NULL);
OH_Huks_DeleteKeyItem(&g_keyAliasFinal2001, NULL);
HksX25519AgreeFreeParamSet(genParamSet, initParamSet01, finishParamSet01, initParamSet02, finishParamSet02);
HksX25519AgreeFreeBlob(&publicKey01, &publicKey02, &outData01, &outData02);
}
} // namespace Unittest::X25519Agree
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "huks_attest_test.h"
#include "huks_attest_test_common.h"
using namespace testing::ext;
namespace Unittest::AttestKey {
static struct OH_Huks_Blob g_secInfo = { sizeof(SEC_INFO_DATA), (uint8_t *)SEC_INFO_DATA };
static struct OH_Huks_Blob g_challenge = { sizeof(CHALLENGE_DATA), (uint8_t *)CHALLENGE_DATA };
static struct OH_Huks_Blob g_version = { sizeof(VERSION_DATA), (uint8_t *)VERSION_DATA };
class HuksAttestKeyNoIdsTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HuksAttestKeyNoIdsTest::SetUpTestCase(void)
{
}
void HuksAttestKeyNoIdsTest::TearDownTestCase(void)
{
}
void HuksAttestKeyNoIdsTest::SetUp()
{
}
void HuksAttestKeyNoIdsTest::TearDown()
{
}
static const struct OH_Huks_Blob g_keyAlias = { sizeof(ALIAS), (uint8_t *)ALIAS };
static const struct OH_Huks_Param g_commonParams[] = {
{ .tag = OH_HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO, .blob = g_secInfo },
{ .tag = OH_HUKS_TAG_ATTESTATION_CHALLENGE, .blob = g_challenge },
{ .tag = OH_HUKS_TAG_ATTESTATION_ID_VERSION_INFO, .blob = g_version },
{ .tag = OH_HUKS_TAG_ATTESTATION_ID_ALIAS, .blob = g_keyAlias },
};
/**
* @tc.name: HuksAttestKeyNoIdsTest.Security_HUKS_NAPI_Attest_0100
* @tc.desc: attest with right params and validate success.
* @tc.type: FUNC
* @tc.require: issueI5NY0L
*/
HWTEST_F(HuksAttestKeyNoIdsTest, Security_HUKS_NAPI_Attest_0100, TestSize.Level0)
{
OH_Huks_Result ret = TestGenerateKey(&g_keyAlias);
ASSERT_TRUE(ret.errorCode == (int32_t)OH_HUKS_SUCCESS);
struct OH_Huks_ParamSet *paramSet = NULL;
GenerateParamSet(&paramSet, g_commonParams, sizeof(g_commonParams) / sizeof(g_commonParams[0]));
OH_Huks_CertChain *certChain = NULL;
const struct HksTestCertChain certParam = { true, true, true, g_size };
(void)ConstructDataToCertChain(&certChain, &certParam);
ret = OH_Huks_AttestKeyItem(&g_keyAlias, paramSet, certChain);
ASSERT_TRUE(ret.errorCode == (int32_t)OH_HUKS_SUCCESS);
ret = ValidateCertChainTest(certChain, g_commonParams, NON_IDS_PARAM);
ASSERT_TRUE(ret.errorCode == (int32_t)OH_HUKS_SUCCESS);
FreeCertChain(&certChain, certChain->certsCount);
certChain = NULL;
OH_Huks_FreeParamSet(&paramSet);
OH_Huks_Result ret1 = OH_Huks_DeleteKeyItem(&g_keyAlias, NULL);
ASSERT_TRUE(ret1.errorCode == (int32_t)OH_HUKS_SUCCESS);
}
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_attest_test_common.h"
#include <cstdlib>
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::AttestKey {
const static uint32_t g_paramCountInKeyAttest = 4;
const static uint32_t g_paramCountInIdAttest = 7;
const static uint32_t g_index0 = 0;
const static uint32_t g_index1 = 1;
const static uint32_t g_index2 = 2;
const static uint32_t g_index3 = 3;
const static uint32_t g_index4 = 4;
const static uint32_t g_index5 = 5;
const static uint32_t g_index6 = 6;
void FreeCertChain(struct OH_Huks_CertChain **certChain, const uint32_t pos)
{
if (certChain == nullptr || *certChain == nullptr) {
return;
}
if ((*certChain)->certs == nullptr) {
HksFree(*certChain);
*certChain = nullptr;
return;
}
for (uint32_t j = 0; j < pos; j++) {
if ((*certChain)->certs[j].data != nullptr) {
HksFree((*certChain)->certs[j].data);
(*certChain)->certs[j].data = nullptr;
}
}
if ((*certChain)->certs != nullptr) {
HksFree((*certChain)->certs);
(*certChain)->certs = nullptr;
}
if (*certChain != nullptr) {
HksFree(*certChain);
*certChain = nullptr;
}
}
OH_Huks_Result TestGenerateKey(const struct OH_Huks_Blob *keyAlias)
{
struct OH_Huks_Param tmpParams[] = {
{ .tag = OH_HUKS_TAG_KEY_STORAGE_FLAG, .uint32Param = OH_HUKS_STORAGE_PERSISTENT },
{ .tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_RSA },
{ .tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_RSA_KEY_SIZE_2048 },
{ .tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_VERIFY },
{ .tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256 },
{ .tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_PSS },
{ .tag = OH_HUKS_TAG_KEY_GENERATE_TYPE, .uint32Param = OH_HUKS_KEY_GENERATE_TYPE_DEFAULT },
{ .tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_ECB },
};
struct OH_Huks_ParamSet *paramSet = nullptr;
OH_Huks_Result ret = OH_Huks_InitParamSet(&paramSet);
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = OH_Huks_AddParams(paramSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0]));
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
OH_Huks_FreeParamSet(&paramSet);
return ret;
}
ret = OH_Huks_BuildParamSet(&paramSet);
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
OH_Huks_FreeParamSet(&paramSet);
return ret;
}
ret = OH_Huks_GenerateKeyItem(keyAlias, paramSet, nullptr);
OH_Huks_FreeParamSet(&paramSet);
return ret;
}
int32_t ConstructDataToCertChain(struct OH_Huks_CertChain **certChain,
const struct HksTestCertChain *certChainParam)
{
if (!certChainParam->certChainExist) {
return 0;
}
*certChain = (struct OH_Huks_CertChain *)HksMalloc(sizeof(struct OH_Huks_CertChain));
if (*certChain == nullptr) {
return OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT;
}
if (!certChainParam->certCountValid) {
(*certChain)->certsCount = 0;
(*certChain)->certs = nullptr;
return 0;
}
(*certChain)->certsCount = CERT_COUNT;
if (!certChainParam->certDataExist) {
(*certChain)->certs = nullptr;
return 0;
}
(*certChain)->certs = (struct OH_Huks_Blob *)HksMalloc(sizeof(struct OH_Huks_Blob) * ((*certChain)->certsCount));
if ((*certChain)->certs == nullptr) {
HksFree(*certChain);
*certChain = nullptr;
}
for (uint32_t i = 0; i < (*certChain)->certsCount; i++) {
(*certChain)->certs[i].size = certChainParam->certDataSize;
(*certChain)->certs[i].data = (uint8_t *)HksMalloc((*certChain)->certs[i].size);
if ((*certChain)->certs[i].data == nullptr) {
FreeCertChain(certChain, i);
return OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT;
}
memset_s((*certChain)->certs[i].data, certChainParam->certDataSize, 0, certChainParam->certDataSize);
}
return 0;
}
OH_Huks_Result GenerateParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param tmpParams[], uint32_t paramCount)
{
OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet);
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = OH_Huks_AddParams(*paramSet, tmpParams, paramCount);
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
OH_Huks_FreeParamSet(paramSet);
return ret;
}
ret = OH_Huks_BuildParamSet(paramSet);
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
OH_Huks_FreeParamSet(paramSet);
return ret;
}
return ret;
}
static int32_t ValidataAndCompareCertInfo(ParamType type, const struct OH_Huks_CertChain *certChain,
struct OH_Huks_ParamSet *paramSet)
{
if (certChain == nullptr || paramSet == nullptr) {
return OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT;
}
int32_t ret = HksValidateCertChain((HksCertChain *)certChain, (HksParamSet *)paramSet);
if (ret == OH_HUKS_SUCCESS) {
ret |= strcmp(SEC_INFO_DATA, (char *)paramSet->params[g_index0].blob.data);
ret |= strcmp(CHALLENGE_DATA, (char *)paramSet->params[g_index1].blob.data);
ret |= strcmp(VERSION_DATA, (char *)paramSet->params[g_index2].blob.data);
ret |= strcmp(ALIAS, (char *)paramSet->params[g_index3].blob.data);
}
if (type == IDS_PARAM) {
if (ret == OH_HUKS_SUCCESS) {
ret |= strcmp(UDID_DATA, (char *)paramSet->params[g_index4].blob.data);
ret |= strcmp(SN_DATA, (char *)paramSet->params[g_index5].blob.data);
ret |= strcmp(DEVICE_ID, (char *)paramSet->params[g_index6].blob.data);
}
}
return ret;
}
OH_Huks_Result ValidateCertChainTest(const struct OH_Huks_CertChain *certChain, const struct OH_Huks_Param tmpParam[], ParamType type)
{
OH_Huks_Result ret;
struct OH_Huks_ParamSet *paramSet = nullptr;
do {
ret = OH_Huks_InitParamSet(&paramSet);
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
break;
}
uint32_t paramCount = 0;
if (type == IDS_PARAM) {
paramCount = g_paramCountInIdAttest;
} else if (type == NON_IDS_PARAM) {
paramCount = g_paramCountInKeyAttest;
}
ret = OH_Huks_AddParams(paramSet, tmpParam, paramCount);
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
break;
}
ret = OH_Huks_BuildParamSet(&paramSet);
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
break;
}
ret.errorCode = ValidataAndCompareCertInfo(type, certChain, paramSet);
} while (0);
OH_Huks_FreeParamSet(&paramSet);
return ret;
}
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_cipher_aes_test.h"
#include "huks_cipher_aes_test_common.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::AesCipher {
class HuksCipherAESTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HuksCipherAESTest::SetUpTestCase(void)
{
}
void HuksCipherAESTest::TearDownTestCase(void)
{
}
void HuksCipherAESTest::SetUp()
{
}
void HuksCipherAESTest::TearDown()
{
}
static struct OH_Huks_Param g_genParams015[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT | OH_HUKS_KEY_PURPOSE_DECRYPT
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}
};
static struct OH_Huks_Param g_encryptParams015[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_NONE
}, {
.tag = OH_HUKS_TAG_IV,
.blob = {
.size = IV_SIZE,
.data = (uint8_t *)IV
}
}
};
static struct OH_Huks_Param g_decryptParams015[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DECRYPT
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_NONE
}, {
.tag = OH_HUKS_TAG_IV,
.blob = {
.size = IV_SIZE,
.data = (uint8_t *)IV
}
}
};
static struct OH_Huks_Param g_genParams019[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT | OH_HUKS_KEY_PURPOSE_DECRYPT
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CTR
}
};
static struct OH_Huks_Param g_encryptParams019[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CTR
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_NONE
}, {
.tag = OH_HUKS_TAG_IV,
.blob = {
.size = IV_SIZE,
.data = (uint8_t *)IV
}
}
};
static struct OH_Huks_Param g_decryptParams019[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DECRYPT
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_256
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_NONE
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CTR
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_NONE
}, {
.tag = OH_HUKS_TAG_IV,
.blob = {
.size = IV_SIZE,
.data = (uint8_t *)IV
}
}
};
/**
* @tc.name: HuksCipherAESTest.Security_HUKS_NAPI_Cipher_AES_0100
* @tc.desc: alg-AES pur-ENCRYPT&DECRYPT mod-CBC pad-NONE size-256.
* @tc.type: FUNC
*/
HWTEST_F(HuksCipherAESTest, Security_HUKS_NAPI_Cipher_AES_0100, TestSize.Level0)
{
char tmpKeyAlias[] = "HksAESCipherKeyAliasTest015";
struct OH_Huks_Blob keyAlias = { strlen(tmpKeyAlias), (uint8_t *)tmpKeyAlias };
struct OH_Huks_ParamSet *genParamSet = nullptr;
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParams015, sizeof(g_genParams015) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(gen) failed.";
struct OH_Huks_ParamSet *encryptParamSet = nullptr;
ret = InitParamSet(&encryptParamSet, g_encryptParams015, sizeof(g_encryptParams015) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(encrypt) failed.";
struct OH_Huks_ParamSet *decryptParamSet = nullptr;
ret = InitParamSet(&decryptParamSet, g_decryptParams015, sizeof(g_decryptParams015) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(decrypt) failed.";
ret = HksAesCipherTestCaseOther(&keyAlias, genParamSet, encryptParamSet, decryptParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "this case failed.";
OH_Huks_FreeParamSet(&genParamSet);
OH_Huks_FreeParamSet(&encryptParamSet);
OH_Huks_FreeParamSet(&decryptParamSet);
}
/**
* @tc.name: HuksCipherAESTest.Security_HUKS_NAPI_Cipher_AES_0200
* @tc.desc: alg-AES pur-ENCRYPT&DECRYPT mod-CBC pad-PKCS7 size-256. Decrypt-Abort
* @tc.type: FUNC
*/
HWTEST_F(HuksCipherAESTest, Security_HUKS_NAPI_Cipher_AES_0200, TestSize.Level0)
{
char tmpKeyAlias[] = "HksAESDecryptKeyAliasTest022";
struct OH_Huks_Blob keyAlias = { strlen(tmpKeyAlias), (uint8_t *)tmpKeyAlias };
struct OH_Huks_Blob inData = { g_inData.length(),
(uint8_t *)g_inData.c_str() };
/* 1. Generate Key */
struct OH_Huks_ParamSet *genParamSet = nullptr;
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParams019, sizeof(g_genParams019) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
// Generate Key
ret = OH_Huks_GenerateKeyItem(&keyAlias, genParamSet, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey failed.";
/* 2. Encrypt Three Stage */
struct OH_Huks_ParamSet *encryptParamSet = nullptr;
ret = InitParamSet(&encryptParamSet, g_encryptParams019, sizeof(g_encryptParams019) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
// Init
uint8_t handleE[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleEncrypt = { sizeof(uint64_t), handleE };
ret = OH_Huks_InitSession(&keyAlias, encryptParamSet, &handleEncrypt, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
// Update & Finish
uint8_t cipher[AES_COMMON_SIZE] = {0};
struct OH_Huks_Blob cipherText = { AES_COMMON_SIZE, cipher };
ret = TestUpdateLoopFinish(&handleEncrypt, encryptParamSet, &inData, &cipherText);
EXPECT_NE(HksMemCmp(inData.data, cipherText.data, inData.size), OH_HUKS_SUCCESS) << "cipherText equals inData";
/* 3. Decrypt Three Stage */
struct OH_Huks_ParamSet *decryptParamSet = nullptr;
ret = InitParamSet(&decryptParamSet, g_decryptParams019, sizeof(g_decryptParams019) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
// Init
uint8_t handleD[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleDecrypt = { sizeof(uint64_t), handleD };
ret = OH_Huks_InitSession(&keyAlias, decryptParamSet, &handleDecrypt, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
// Update loop
ret = HksTestUpdate(&handleDecrypt, decryptParamSet, &cipherText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Update failed.";
// Abort
ret = OH_Huks_AbortSession(&handleDecrypt, decryptParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Abort failed.";
/* 4. Delete Key */
ret = OH_Huks_DeleteKeyItem(&keyAlias, genParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
OH_Huks_FreeParamSet(&genParamSet);
OH_Huks_FreeParamSet(&encryptParamSet);
OH_Huks_FreeParamSet(&decryptParamSet);
}
} // namespace Unittest::AesCipher
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_cipher_aes_test_common.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::AesCipher
{
OH_Huks_Result HksAesCipherTestEncrypt(
const struct OH_Huks_Blob *keyAlias,
const struct OH_Huks_ParamSet *encryptParamSet, const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *cipherText)
{
uint8_t handleE[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleEncrypt = {sizeof(uint64_t), handleE};
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, encryptParamSet, &handleEncrypt, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS)
{
return ret;
}
ret = TestUpdateLoopFinish(&handleEncrypt, encryptParamSet, inData, cipherText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "TestUpdateLoopFinish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS)
{
return ret;
}
EXPECT_NE(HksMemCmp(inData->data, cipherText->data, inData->size), (int32_t)OH_HUKS_SUCCESS) << "cipherText equals inData";
return ret;
}
OH_Huks_Result HksAesCipherTestDecrypt(
const struct OH_Huks_Blob *keyAlias,
const struct OH_Huks_ParamSet *decryptParamSet, const struct OH_Huks_Blob *cipherText, struct OH_Huks_Blob *plainText,
const struct OH_Huks_Blob *inData)
{
uint8_t handleD[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleDecrypt = {sizeof(uint64_t), handleD};
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, decryptParamSet, &handleDecrypt, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS)
{
return ret;
}
ret = TestUpdateLoopFinish(&handleDecrypt, decryptParamSet, cipherText, plainText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "TestUpdateLoopFinish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS)
{
return ret;
}
EXPECT_EQ(HksMemCmp(inData->data, plainText->data, inData->size), (int32_t)OH_HUKS_SUCCESS) << "plainText not equals inData";
return ret;
}
OH_Huks_Result HksAesCipherTestCaseOther(
const struct OH_Huks_Blob *keyAlias, struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *encryptParamSet, struct OH_Huks_ParamSet *decryptParamSet)
{
char tmpInData[] = "AES_ECB_INDATA_1";
struct OH_Huks_Blob inData = {
g_inData.length(),
(uint8_t *)g_inData.c_str()};
struct OH_Huks_Param *modeParam = nullptr;
OH_Huks_Result ret = OH_Huks_GetParam(genParamSet, OH_HUKS_TAG_BLOCK_MODE, &modeParam);
if (modeParam->uint32Param == OH_HUKS_MODE_ECB)
{
inData.size = strlen(tmpInData);
inData.data = (uint8_t *)tmpInData;
}
/* 1. Generate Key */
ret = OH_Huks_GenerateKeyItem(keyAlias, genParamSet, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS)
{
return ret;
}
/* 2. Encrypt */
uint8_t cipher[AES_COMMON_SIZE] = {0};
struct OH_Huks_Blob cipherText = {AES_COMMON_SIZE, cipher};
ret = HksAesCipherTestEncrypt(keyAlias, encryptParamSet, &inData, &cipherText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksAesCipherTestEncrypt failed.";
/* 3. Decrypt Three Stage */
uint8_t plain[AES_COMMON_SIZE] = {0};
struct OH_Huks_Blob plainText = {AES_COMMON_SIZE, plain};
ret = HksAesCipherTestDecrypt(keyAlias, decryptParamSet, &cipherText, &plainText, &inData);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksAesCipherTestDecrypt failed.";
/* 3. Delete Key */
EXPECT_EQ(OH_Huks_DeleteKeyItem(keyAlias, genParamSet).errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
return ret;
}
OH_Huks_Result HksAesCipherTestCaseGcm2(
const struct OH_Huks_Blob *keyAlias, struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *encryptParamSet, struct OH_Huks_ParamSet *decryptParamSet, struct OH_Huks_ParamSet *decrypt1ParamSet)
{
struct OH_Huks_Blob inData = {
g_inData.length(),
(uint8_t *)g_inData.c_str()};
/* 1. Generate Key */
OH_Huks_Result ret = OH_Huks_GenerateKeyItem(keyAlias, genParamSet, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS)
{
return ret;
}
/* 2. Encrypt Three Stage */
uint8_t cipher[AES_COMMON_SIZE] = {0};
struct OH_Huks_Blob cipherText = {AES_COMMON_SIZE, cipher};
ret = HksAesCipherTestEncrypt(keyAlias, encryptParamSet, &inData, &cipherText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksAesCipherTestEncrypt failed.";
cipherText.size -= AEAD_SIZE;
uint32_t i = 0;
for (i = 0; i < decryptParamSet->paramsCnt; i++)
{
if (decryptParamSet->params[i].tag == OH_HUKS_TAG_KEY_FLAG)
{
uint8_t *tempPtr = cipherText.data;
(void)memcpy_s(decryptParamSet->params[i].blob.data, AEAD_SIZE,
tempPtr + cipherText.size, AEAD_SIZE);
break;
}
}
/* 3. Decrypt Three Stage */
// Init
uint8_t handleD[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleDecrypt = {sizeof(uint64_t), handleD};
ret = OH_Huks_InitSession(keyAlias, decryptParamSet, &handleDecrypt, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
// Update & Finish
uint8_t plain[AES_COMMON_SIZE] = {0};
struct OH_Huks_Blob plainText = {AES_COMMON_SIZE, plain};
ret = TestUpdateLoopFinish(&handleDecrypt, decryptParamSet, &cipherText, &plainText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "TestUpdateLoopFinish failed.";
EXPECT_EQ(HksMemCmp(inData.data, plainText.data, inData.size), (int32_t)OH_HUKS_SUCCESS) << "plainText not equals inData";
/* 3. Delete Key */
EXPECT_EQ(OH_Huks_DeleteKeyItem(keyAlias, genParamSet).errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
return ret;
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_cipher_rsa_test.h"
#include "huks_cipher_rsa_test_common.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::RsaCipher {
class HuksCipherRSATest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HuksCipherRSATest::SetUpTestCase(void)
{
}
void HuksCipherRSATest::TearDownTestCase(void)
{
}
void HuksCipherRSATest::SetUp()
{
}
void HuksCipherRSATest::TearDown()
{
}
static struct OH_Huks_Param g_genParams041[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_RSA
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT | OH_HUKS_KEY_PURPOSE_DECRYPT
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_RSA_KEY_SIZE_4096
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_OAEP
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA384
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_ECB
}
};
static struct OH_Huks_Param g_encryptParams041[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_RSA
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_RSA_KEY_SIZE_4096
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_OAEP
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA384
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_ECB
}
};
static struct OH_Huks_Param g_decryptParams041[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_RSA
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DECRYPT
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_RSA_KEY_SIZE_4096
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_OAEP
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA384
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_ECB
}
};
/**
* @tc.name: HuksCipherRSATest.Security_HUKS_NAPI_Cipher_RSA_0100
* @tc.desc: alg-RSA pur-ENCRYPT-DECRYPT size-4096 pad-OAEP dig-SHA384 mode-ECB.
* @tc.type: FUNC
*/
HWTEST_F(HuksCipherRSATest, Security_HUKS_NAPI_Cipher_RSA_0100, TestSize.Level1)
{
char tmpKeyAlias[] = "HksRSACipherKeyAliasTest041";
struct OH_Huks_Blob keyAlias = { strlen(tmpKeyAlias), (uint8_t *)tmpKeyAlias };
struct OH_Huks_Blob inData = { g_inData_32.length(),
(uint8_t *)g_inData_32.c_str() };
struct OH_Huks_ParamSet *genParamSet = nullptr;
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParams041, sizeof(g_genParams041) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(gen) failed.";
struct OH_Huks_ParamSet *encryptParamSet = nullptr;
ret = InitParamSet(&encryptParamSet, g_encryptParams041, sizeof(g_encryptParams041) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(encrypt) failed.";
struct OH_Huks_ParamSet *decryptParamSet = nullptr;
ret = InitParamSet(&decryptParamSet, g_decryptParams041, sizeof(g_decryptParams041) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(decrypt) failed.";
ret = HksRsaCipherTestCase(&keyAlias, genParamSet, encryptParamSet, decryptParamSet, &inData);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "this case failed.";
OH_Huks_FreeParamSet(&genParamSet);
OH_Huks_FreeParamSet(&encryptParamSet);
OH_Huks_FreeParamSet(&decryptParamSet);
}
} // namespace Unittest::RsaCipher
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_cipher_rsa_test_common.h"
#include <gtest/gtest.h>
OH_Huks_Result Unittest::RsaCipher::HksRsaCipherTestEncryptAbnormal(const struct OH_Huks_Blob *keyAlias,
const struct OH_Huks_ParamSet *encryptParamSet, const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *cipherText)
{
uint8_t handleE[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleEncrypt = { sizeof(uint64_t), handleE };
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, encryptParamSet, &handleEncrypt, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = TestUpdateFinish(&handleEncrypt, encryptParamSet, OH_HUKS_KEY_PURPOSE_ENCRYPT, inData, cipherText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT) << "TestUpdateFinish should failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
OH_Huks_Result abortRet = OH_Huks_AbortSession(&handleEncrypt, encryptParamSet);
EXPECT_EQ(abortRet.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Abort failed.";
return ret;
}
int32_t ret1 = HksMemCmp(inData->data, cipherText->data, inData->size);
EXPECT_NE(ret1, (int32_t)OH_HUKS_SUCCESS) << "cipherText equals inData";
return ret;
}
OH_Huks_Result Unittest::RsaCipher::HksRsaCipherTestEncrypt(const struct OH_Huks_Blob *keyAlias,
const struct OH_Huks_ParamSet *encryptParamSet, const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *cipherText)
{
uint8_t handleE[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleEncrypt = { sizeof(uint64_t), handleE };
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, encryptParamSet, &handleEncrypt, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = TestUpdateFinish(&handleEncrypt, encryptParamSet, OH_HUKS_KEY_PURPOSE_ENCRYPT, inData, cipherText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "TestUpdateFinish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
int32_t ret1 = HksMemCmp(inData->data, cipherText->data, inData->size);
EXPECT_NE(ret1, (int32_t)OH_HUKS_SUCCESS) << "cipherText equals inData";
return ret;
}
OH_Huks_Result Unittest::RsaCipher::HksRsaCipherTestDecrypt(const struct OH_Huks_Blob *keyAlias,
const struct OH_Huks_ParamSet *decryptParamSet, const struct OH_Huks_Blob *cipherText, struct OH_Huks_Blob *plainText,
const struct OH_Huks_Blob *inData)
{
uint8_t handleD[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleDecrypt = { sizeof(uint64_t), handleD };
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, decryptParamSet, &handleDecrypt, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = TestUpdateFinish(&handleDecrypt, decryptParamSet, OH_HUKS_KEY_PURPOSE_DECRYPT, cipherText, plainText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "TestUpdateFinish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
int32_t ret1 = HksMemCmp(inData->data, plainText->data, inData->size);
EXPECT_EQ(ret1, (int32_t)OH_HUKS_SUCCESS) << "plainText not equals inData";
return ret;
}
OH_Huks_Result Unittest::RsaCipher::HksRsaCipherTestCase(const struct OH_Huks_Blob *keyAlias, struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *encryptParamSet, struct OH_Huks_ParamSet *decryptParamSet, const struct OH_Huks_Blob *inData)
{
/* 1. Generate Key */
OH_Huks_Result ret = OH_Huks_GenerateKeyItem(keyAlias, genParamSet, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey failed.";
/* 2. Export Public Key */
uint8_t tmpPublicKey[OH_HUKS_RSA_KEY_SIZE_1024] = {0};
struct OH_Huks_Blob publicKey = { OH_HUKS_RSA_KEY_SIZE_1024, (uint8_t *)tmpPublicKey };
ret = OH_Huks_ExportPublicKeyItem(keyAlias, genParamSet, &publicKey);
/* 3. Import Key */
char tmpKey[] = "RSA_Encrypt_Decrypt_KeyAlias";
struct OH_Huks_Blob newKeyAlias = { .size = strlen(tmpKey), .data = (uint8_t *)tmpKey };
ret = OH_Huks_ImportKeyItem(&newKeyAlias, encryptParamSet, &publicKey);
/* 4. Encrypt Three Stage */
uint8_t cipher[Unittest::RsaCipher::RSA_COMMON_SIZE] = {0};
struct OH_Huks_Blob cipherText = { Unittest::RsaCipher::RSA_COMMON_SIZE, cipher };
ret = HksRsaCipherTestEncrypt(&newKeyAlias, encryptParamSet, inData, &cipherText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksRsaCipherTestEncrypt failed.";
/* 5. Decrypt Three Stage */
uint8_t plain[Unittest::RsaCipher::RSA_COMMON_SIZE] = {0};
struct OH_Huks_Blob plainText = { Unittest::RsaCipher::RSA_COMMON_SIZE, plain };
ret = HksRsaCipherTestDecrypt(keyAlias, decryptParamSet, &cipherText, &plainText, inData);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksRsaCipherTestDecrypt failed.";
/* 6. Delete Key */
EXPECT_EQ(OH_Huks_DeleteKeyItem(keyAlias, genParamSet).errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
EXPECT_EQ(OH_Huks_DeleteKeyItem(&newKeyAlias, encryptParamSet).errorCode, (int32_t)OH_HUKS_SUCCESS) << "Delete ImportKey failed.";
return ret;
}
OH_Huks_Result Unittest::RsaCipher::HksRsaCipherTestCaseAbnormal(const struct OH_Huks_Blob *keyAlias,
struct OH_Huks_ParamSet *genParamSet, struct OH_Huks_ParamSet *encryptParamSet, struct OH_Huks_ParamSet *decryptParamSet,
const struct OH_Huks_Blob *inData)
{
/* 1. Generate Key */
OH_Huks_Result ret = OH_Huks_GenerateKeyItem(keyAlias, genParamSet, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey failed.";
/* 2. Export Public Key */
uint8_t tmpPublicKey[OH_HUKS_RSA_KEY_SIZE_1024] = {0};
struct OH_Huks_Blob publicKey = { OH_HUKS_RSA_KEY_SIZE_1024, (uint8_t *)tmpPublicKey };
ret = OH_Huks_ExportPublicKeyItem(keyAlias, genParamSet, &publicKey);
/* 3. Import Key */
char tmpKey[] = "RSA_Encrypt_Decrypt_KeyAlias";
struct OH_Huks_Blob newKeyAlias = { .size = strlen(tmpKey), .data = (uint8_t *)tmpKey };
ret = OH_Huks_ImportKeyItem(&newKeyAlias, encryptParamSet, &publicKey);
/* 4. Encrypt Three Stage */
uint8_t cipher[Unittest::RsaCipher::RSA_COMMON_SIZE] = {0};
struct OH_Huks_Blob cipherText = { Unittest::RsaCipher::RSA_COMMON_SIZE, cipher };
ret = HksRsaCipherTestEncryptAbnormal(&newKeyAlias, encryptParamSet, inData, &cipherText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT) << "HksRsaCipherTestEncrypt should failed.";
/* 6. Delete Key */
EXPECT_EQ(OH_Huks_DeleteKeyItem(keyAlias, genParamSet).errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
EXPECT_EQ(OH_Huks_DeleteKeyItem(&newKeyAlias, encryptParamSet).errorCode, (int32_t)OH_HUKS_SUCCESS) << "Delete ImportKey failed.";
return ret;
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_cipher_sm4_test.h"
#include <gtest/gtest.h>
#include "huks_cipher_sm4_test_common.h"
using namespace testing::ext;
namespace Unittest::Sm4Cipher {
class HuksCipherSM4Test : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HuksCipherSM4Test::SetUpTestCase(void)
{
}
void HuksCipherSM4Test::TearDownTestCase(void)
{
}
void HuksCipherSM4Test::SetUp()
{
}
void HuksCipherSM4Test::TearDown()
{
}
static struct OH_Huks_Param g_genParams001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_SM4,
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT | OH_HUKS_KEY_PURPOSE_DECRYPT
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_SM4_KEY_SIZE_128
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_PKCS7
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}
};
static uint8_t g_hksSm4TestIv[HKS_SM4_IV_SIZE] = {0};
static struct OH_Huks_Param g_encryptParams001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_SM4
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_SM4_KEY_SIZE_128
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_PKCS7
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}, {
.tag = OH_HUKS_TAG_IV,
.blob = {
.size = HKS_SM4_IV_SIZE,
.data = (uint8_t *)g_hksSm4TestIv
}
}
};
static struct OH_Huks_Param g_decryptParams001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_SM4
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DECRYPT
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_SM4_KEY_SIZE_128
}, {
.tag = OH_HUKS_TAG_PADDING,
.uint32Param = OH_HUKS_PADDING_PKCS7
}, {
.tag = OH_HUKS_TAG_BLOCK_MODE,
.uint32Param = OH_HUKS_MODE_CBC
}, {
.tag = OH_HUKS_TAG_IV,
.blob = {
.size = HKS_SM4_IV_SIZE,
.data = (uint8_t *)g_hksSm4TestIv
}
}
};
/**
* @tc.name: HuksCipherSM4Test.Security_HUKS_NAPI_Cipher_SM4_0100
* @tc.desc: alg-SM4
* @tc.type: FUNC
*/
HWTEST_F(HuksCipherSM4Test, Security_HUKS_NAPI_Cipher_SM4_0100, TestSize.Level0)
{
char tmpKeyAlias[] = "HksSm4CipherKeyAliasTest001";
struct OH_Huks_Blob keyAlias = { strlen(tmpKeyAlias), (uint8_t *)tmpKeyAlias };
struct OH_Huks_ParamSet *genParamSet = nullptr;
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParams001, sizeof(g_genParams001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(gen) failed.";
struct OH_Huks_ParamSet *encryptParamSet = nullptr;
ret = InitParamSet(&encryptParamSet, g_encryptParams001, sizeof(g_encryptParams001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(encrypt) failed.";
struct OH_Huks_ParamSet *decryptParamSet = nullptr;
ret = InitParamSet(&decryptParamSet, g_decryptParams001, sizeof(g_decryptParams001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet(decrypt) failed.";
ret = HksSm4CipherTestCaseOther(&keyAlias, genParamSet, encryptParamSet, decryptParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "this case failed.";
OH_Huks_FreeParamSet(&genParamSet);
OH_Huks_FreeParamSet(&encryptParamSet);
OH_Huks_FreeParamSet(&decryptParamSet);
}
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_cipher_sm4_test_common.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::Sm4Cipher {
static OH_Huks_Result HksSm4CipherTestEncrypt(const struct OH_Huks_Blob *keyAlias,
const struct OH_Huks_ParamSet *encryptParamSet, const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *cipherText)
{
uint8_t handleE[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleEncrypt = { sizeof(uint64_t), handleE };
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, encryptParamSet, &handleEncrypt, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = TestUpdateLoopFinish(&handleEncrypt, encryptParamSet, inData, cipherText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "TestUpdateLoopFinish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
EXPECT_NE(HksMemCmp(inData->data, cipherText->data, inData->size), (int32_t)OH_HUKS_SUCCESS) << "cipherText equals inData";
return ret;
}
static OH_Huks_Result HksSm4CipherTestDecrypt(const struct OH_Huks_Blob *keyAlias,
const struct OH_Huks_ParamSet *decryptParamSet, const struct OH_Huks_Blob *cipherText, struct OH_Huks_Blob *plainText,
const struct OH_Huks_Blob *inData)
{
uint8_t handleD[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleDecrypt = { sizeof(uint64_t), handleD };
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, decryptParamSet, &handleDecrypt, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = TestUpdateLoopFinish(&handleDecrypt, decryptParamSet, cipherText, plainText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "TestUpdateLoopFinish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
EXPECT_EQ(HksMemCmp(inData->data, plainText->data, inData->size), (int32_t)OH_HUKS_SUCCESS) << "plainText not equals inData";
return ret;
}
OH_Huks_Result HksSm4CipherTestCaseOther(const struct OH_Huks_Blob *keyAlias, struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *encryptParamSet, struct OH_Huks_ParamSet *decryptParamSet)
{
char tmpInData[] = "SM4_ECB_INDATA_1";
struct OH_Huks_Blob inData = {
g_inData.length(),
(uint8_t *)g_inData.c_str()
};
struct OH_Huks_Param *modeParam = nullptr;
OH_Huks_GetParam(genParamSet, OH_HUKS_TAG_BLOCK_MODE, &modeParam);
if (modeParam->uint32Param == OH_HUKS_MODE_ECB) {
inData.size = strlen(tmpInData);
inData.data = (uint8_t *)tmpInData;
}
/* 1. Generate Key */
OH_Huks_Result ret = OH_Huks_GenerateKeyItem(keyAlias, genParamSet, nullptr);
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
/* 2. Encrypt */
uint8_t cipher[SM4_COMMON_SIZE] = {0};
struct OH_Huks_Blob cipherText = { SM4_COMMON_SIZE, cipher };
ret = HksSm4CipherTestEncrypt(keyAlias, encryptParamSet, &inData, &cipherText);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksAesCipherTestEncrypt failed.";
/* 3. Decrypt Three Stage */
uint8_t plain[SM4_COMMON_SIZE] = {0};
struct OH_Huks_Blob plainText = { SM4_COMMON_SIZE, plain };
ret = HksSm4CipherTestDecrypt(keyAlias, decryptParamSet, &cipherText, &plainText, &inData);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "HksAesCipherTestDecrypt failed.";
/* 3. Delete Key */
EXPECT_EQ(OH_Huks_DeleteKeyItem(keyAlias, genParamSet).errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
return ret;
}
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_derive_hkdf_test.h"
#include "huks_derive_hkdf_test_common.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::HkdfDerive {
class HuksDeriveHKDFTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HuksDeriveHKDFTest::SetUpTestCase(void)
{
}
void HuksDeriveHKDFTest::TearDownTestCase(void)
{
}
void HuksDeriveHKDFTest::SetUp()
{
}
void HuksDeriveHKDFTest::TearDown()
{
}
static struct OH_Huks_Param g_genParams001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA256
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = OH_HUKS_AES_KEY_SIZE_128
}
};
static struct OH_Huks_Param g_hkdfParams001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_HKDF
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA256
}, {
.tag = OH_HUKS_TAG_DERIVE_KEY_SIZE,
.uint32Param = DERIVE_KEY_SIZE_32
}
};
static struct OH_Huks_Param g_hkdfFinishParams001[] = {
{
.tag = OH_HUKS_TAG_KEY_STORAGE_FLAG,
.uint32Param = OH_HUKS_STORAGE_PERSISTENT
}, {
.tag = OH_HUKS_TAG_KEY_ALIAS,
.blob = {
strlen("HksHKDFDeriveKeyAliasFinalTest001"),
(uint8_t *)"HksHKDFDeriveKeyAliasFinalTest001"
}
}, {
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_HKDF
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = DERIVE_KEY_SIZE_32
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA256
}
};
/**
* @tc.name: HuksDeriveHKDFTest.Security_HUKS_NAPI_Derive_hkdf_0100
* @tc.desc: alg-HKDF pur-Derive dig-SHA256 KEY_SIZE-128
* @tc.type: FUNC
*/
HWTEST_F(HuksDeriveHKDFTest, Security_HUKS_NAPI_Derive_hkdf_0100, TestSize.Level0)
{
struct OH_Huks_Blob keyAlias = { strlen("HksHKDFDeriveKeyAliasTest001"), (uint8_t *)"HksHKDFDeriveKeyAliasTest001" };
/* 1. Generate Key */
struct OH_Huks_ParamSet *genParamSet = nullptr;
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParams001, sizeof(g_genParams001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
/* 2. HKDF Three Stage */
struct OH_Huks_ParamSet *hkdfParamSet = nullptr;
struct OH_Huks_ParamSet *hkdfFinishParamSet = nullptr;
ret = InitParamSet(&hkdfParamSet, g_hkdfParams001, sizeof(g_hkdfParams001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
// finish paramset
ret = InitParamSet(&hkdfFinishParamSet, g_hkdfFinishParams001, sizeof(g_hkdfFinishParams001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
// Init-Update-final
HksHkdfDeriveTestNormalCase(keyAlias, genParamSet, hkdfParamSet, hkdfFinishParamSet);
/* 3. Delete Key */
ret = OH_Huks_DeleteKeyItem(&keyAlias, genParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
struct OH_Huks_Blob deleteKeyAlias = { .size = strlen("HksHKDFDeriveKeyAliasFinalTest001"),
.data = (uint8_t *)"HksHKDFDeriveKeyAliasFinalTest001"};
ret = OH_Huks_DeleteKeyItem(&deleteKeyAlias, NULL);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Delete Final Key failed.";
OH_Huks_FreeParamSet(&genParamSet);
OH_Huks_FreeParamSet(&hkdfParamSet);
OH_Huks_FreeParamSet(&hkdfFinishParamSet);
}
} // namespace Unittest::HkdfDerive
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_derive_hkdf_test_common.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::HkdfDerive {
OH_Huks_Result HksHkdfDeriveTestNormalCase(const struct OH_Huks_Blob keyAlias,
const struct OH_Huks_ParamSet *genParamSet, struct OH_Huks_ParamSet *deriveParamSet, struct OH_Huks_ParamSet *deriveFinalParamsSet)
{
struct OH_Huks_Blob inData = {
g_inData.length(),
(uint8_t *)g_inData.c_str()
};
/* 1. Generate Key */
// Generate Key
OH_Huks_Result ret = OH_Huks_GenerateKeyItem(&keyAlias, genParamSet, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey failed.";
/* 2. Derive Three Stage */
// Init
uint8_t handleD[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleDerive = { sizeof(uint64_t), handleD };
ret = OH_Huks_InitSession(&keyAlias, deriveParamSet, &handleDerive, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
// Update
uint8_t tmpOut[COMMON_SIZE] = {0};
struct OH_Huks_Blob outData = { COMMON_SIZE, tmpOut };
ret = OH_Huks_UpdateSession(&handleDerive, deriveParamSet, &inData, &outData);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Update failed.";
// Finish
uint8_t outDataD[COMMON_SIZE] = {0};
struct OH_Huks_Blob outDataDerive = { COMMON_SIZE, outDataD };
ret = OH_Huks_FinishSession(&handleDerive, deriveFinalParamsSet, &inData, &outDataDerive);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Finish failed.";
return ret;
}
OH_Huks_Result HksHkdfDeriveTestCmpCase(const struct OH_Huks_Blob keyAlias,
const struct OH_Huks_ParamSet *genParamSet, struct OH_Huks_ParamSet *deriveParamSet, struct OH_Huks_ParamSet *deriveFinalParamsSet)
{
struct OH_Huks_Blob inData = {
g_inData.length(),
(uint8_t *)g_inData.c_str()
};
/* 1. Generate Key */
// Generate Key
OH_Huks_Result ret = OH_Huks_GenerateKeyItem(&keyAlias, genParamSet, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey failed.";
/* 2. Derive Three Stage */
// Init
uint8_t handleD[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleDerive = { sizeof(uint64_t), handleD };
ret = OH_Huks_InitSession(&keyAlias, deriveParamSet, &handleDerive, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
// Update
uint8_t tmpOut[COMMON_SIZE] = {0};
struct OH_Huks_Blob outData = { COMMON_SIZE, tmpOut };
ret = OH_Huks_UpdateSession(&handleDerive, deriveParamSet, &inData, &outData);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Update failed.";
// Finish
uint8_t outDataD[COMMON_SIZE] = {0};
struct OH_Huks_Blob outDataDerive = { COMMON_SIZE, outDataD };
ret = OH_Huks_FinishSession(&handleDerive, deriveFinalParamsSet, &inData, &outDataDerive);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Finish failed.";
return ret;
}
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_derive_pbkdf_test.h"
#include "huks_derive_pbkdf_test_common.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::Pbkdf2Derive {
class HuksDerivePBKDFTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HuksDerivePBKDFTest::SetUpTestCase(void)
{
}
void HuksDerivePBKDFTest::TearDownTestCase(void)
{
}
void HuksDerivePBKDFTest::SetUp()
{
}
void HuksDerivePBKDFTest::TearDown()
{
}
uint8_t g_saltdata1[16] = {0};
static struct OH_Huks_Param g_genParams001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA256
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = 256
}
};
static struct OH_Huks_Param g_pbkdf2Params001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_PBKDF2
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA256
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = 256
}, {
.tag = OH_HUKS_TAG_ITERATION,
.int32Param = DERIVE_ITERATION
}, {
.tag = OH_HUKS_TAG_SALT,
.blob = {
sizeof(g_saltdata1),
(uint8_t *)g_saltdata1
}
}, {
.tag = OH_HUKS_TAG_DERIVE_KEY_SIZE,
.uint32Param = DERIVE_KEY_SIZE_32
}
};
static struct OH_Huks_Param g_pbkdf2FinishParams001[] = {
{
.tag = OH_HUKS_TAG_KEY_STORAGE_FLAG,
.uint32Param = OH_HUKS_STORAGE_PERSISTENT
}, {
.tag = OH_HUKS_TAG_KEY_ALIAS,
.blob = {
strlen("HksPBKDF2DeriveKeyAliasTest001_2"),
(uint8_t *)"HksPBKDF2DeriveKeyAliasTest001_2"
}
}, {
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_AES
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = DERIVE_KEY_SIZE_32
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA256
}
};
/**
* @tc.name: HuksDerivePBKDFTest.Security_HUKS_NAPI_Derive_pbkdf_0100
* @tc.desc: alg-PBKDF2 pur-Derive dig-SHA256.
* @tc.type: FUNC
*/
HWTEST_F(HuksDerivePBKDFTest, Security_HUKS_NAPI_Derive_pbkdf_0100, TestSize.Level0)
{
struct OH_Huks_Blob keyAlias = { strlen("HksPBKDF2DeriveKeyAliasTest001_1"),
(uint8_t *)"HksPBKDF2DeriveKeyAliasTest001_1" };
/* 1. Generate Key */
struct OH_Huks_ParamSet *genParamSet = nullptr;
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParams001, sizeof(g_genParams001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
/* 2. PBKDF2 Three Stage */
struct OH_Huks_ParamSet *pbkdf2ParamSet = nullptr;
struct OH_Huks_ParamSet *pbkdf2FinishParamSet = nullptr;
ret = InitParamSet(&pbkdf2ParamSet, g_pbkdf2Params001, sizeof(g_pbkdf2Params001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
struct OH_Huks_Param *saltParam = nullptr;
OH_Huks_GetParam(pbkdf2ParamSet, OH_HUKS_TAG_SALT, &saltParam);
int32_t ret1 = HksGenerateRandom(NULL, (struct HksBlob *)&(saltParam->blob));
EXPECT_EQ(ret1, (int32_t)OH_HUKS_SUCCESS) << "GenerateRandom failed.";
// Finish paramset
ret = InitParamSet(&pbkdf2FinishParamSet, g_pbkdf2FinishParams001,
sizeof(g_pbkdf2FinishParams001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
// init-update-final
HksPbkdf2DeriveTestNormalCase(keyAlias, genParamSet, pbkdf2ParamSet, pbkdf2FinishParamSet);
/* 3. Delete Key */
ret = OH_Huks_DeleteKeyItem(&keyAlias, genParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
struct OH_Huks_Blob deleteKeyAlias = { .size = strlen("HksPBKDF2DeriveKeyAliasTest001_2"),
.data = (uint8_t *)"HksPBKDF2DeriveKeyAliasTest001_2"};
ret = OH_Huks_DeleteKeyItem(&deleteKeyAlias, NULL);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Delete Final Key failed.";
OH_Huks_FreeParamSet(&genParamSet);
OH_Huks_FreeParamSet(&pbkdf2ParamSet);
OH_Huks_FreeParamSet(&pbkdf2FinishParamSet);
}
} // namespace Unittest::Pbkdf2Derive
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_derive_pbkdf_test_common.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::Pbkdf2Derive {
OH_Huks_Result HksPbkdf2DeriveTestNormalCase(const struct OH_Huks_Blob keyAlias,
const struct OH_Huks_ParamSet *genParamSet, struct OH_Huks_ParamSet *deriveParamSet, struct OH_Huks_ParamSet *deriveFinalParamsSet)
{
struct OH_Huks_Blob inData = {
g_inData.length(),
(uint8_t *)g_inData.c_str()
};
/* 1. Generate Key */
// Generate Key
OH_Huks_Result ret = OH_Huks_GenerateKeyItem(&keyAlias, genParamSet, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey failed.";
/* 2. Derive Three Stage */
// Init
uint8_t handleD[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleDerive = { sizeof(uint64_t), handleD };
ret = OH_Huks_InitSession(&keyAlias, deriveParamSet, &handleDerive, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
// Update
uint8_t tmpOut[COMMON_SIZE] = {0};
struct OH_Huks_Blob outData = { COMMON_SIZE, tmpOut };
ret = OH_Huks_UpdateSession(&handleDerive, deriveParamSet, &inData, &outData);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Update failed.";
// Finish
uint8_t outDataD[COMMON_SIZE] = {0};
struct OH_Huks_Blob outDataDerive = { COMMON_SIZE, outDataD };
ret = OH_Huks_FinishSession(&handleDerive, deriveFinalParamsSet, &inData, &outDataDerive);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Finish failed.";
return ret;
}
OH_Huks_Result HksPbkdf2DeriveTestCmpCase(const struct OH_Huks_Blob keyAlias,
const struct OH_Huks_ParamSet *genParamSet, struct OH_Huks_ParamSet *deriveParamSet, struct OH_Huks_ParamSet *deriveFinalParamsSet)
{
struct OH_Huks_Blob inData = {
g_inData.length(),
(uint8_t *)g_inData.c_str()
};
/* 1. Generate Key */
// Generate Key
OH_Huks_Result ret = OH_Huks_GenerateKeyItem(&keyAlias, genParamSet, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey failed.";
/* 2. Derive Three Stage */
// Init
uint8_t handleD[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleDerive = { sizeof(uint64_t), handleD };
ret = OH_Huks_InitSession(&keyAlias, deriveParamSet, &handleDerive, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
// Update
uint8_t tmpOut[COMMON_SIZE] = {0};
struct OH_Huks_Blob outData = { COMMON_SIZE, tmpOut };
ret = OH_Huks_UpdateSession(&handleDerive, deriveParamSet, &inData, &outData);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Update failed.";
// Finish
uint8_t outDataD[COMMON_SIZE] = {0};
struct OH_Huks_Blob outDataDerive = { COMMON_SIZE, outDataD };
ret = OH_Huks_FinishSession(&handleDerive, deriveFinalParamsSet, &inData, &outDataDerive);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Finish failed.";
return ret;
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_hmac_test.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::Hmac {
class HksHmacTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksHmacTest::SetUpTestCase(void)
{
}
void HksHmacTest::TearDownTestCase(void)
{
}
void HksHmacTest::SetUp()
{
}
void HksHmacTest::TearDown()
{
}
static struct OH_Huks_Param g_genParams001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_HMAC
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_MAC
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = Unittest::Hmac::COMMON_SIZE
}
};
static struct OH_Huks_Param g_hmacParams001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_HMAC
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_MAC
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
static struct OH_Huks_Param g_genParams006[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_HMAC
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_MAC
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SM3
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = Unittest::Hmac::COMMON_SIZE
}
};
static struct OH_Huks_Param g_hmacParams006[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_HMAC
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_MAC
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SM3
}
};
static OH_Huks_Result HksHmacTestCase(const struct OH_Huks_Blob *keyAlias, struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *hmacParamSet)
{
struct OH_Huks_Blob inData = { g_inData.length(), (uint8_t *)g_inData.c_str() };
/* 1. Generate Key */
OH_Huks_Result ret = OH_Huks_GenerateKeyItem(keyAlias, genParamSet, nullptr);
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
/* 2. HMAC Three Stage */
// Init
uint8_t handle[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handleHMAC = { sizeof(uint64_t), handle };
ret = OH_Huks_InitSession(keyAlias, hmacParamSet, &handleHMAC, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
OH_Huks_DeleteKeyItem(keyAlias, genParamSet);
return ret;
}
// Update & Finish
uint8_t out[Unittest::Hmac::COMMON_SIZE] = {0};
struct OH_Huks_Blob outData = { Unittest::Hmac::COMMON_SIZE, out };
ret = TestUpdateFinish(&handleHMAC, hmacParamSet, OH_HUKS_KEY_PURPOSE_MAC, &inData, &outData);
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
OH_Huks_DeleteKeyItem(keyAlias, genParamSet);
return ret;
}
/* 3. Delete Key */
ret = OH_Huks_DeleteKeyItem(keyAlias, genParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
return ret;
}
/**
* @tc.name: HksHmacTest.Security_HUKS_NAPI_HMAC_hmac_0100
* @tc.desc: alg-HMAC pur-MAC dig-SHA1.
* @tc.type: FUNC
*/
HWTEST_F(HksHmacTest, Security_HUKS_NAPI_HMAC_hmac_0100, TestSize.Level0)
{
char tmpKeyAlias[] = "HksHMACKeyAliasTest001";
struct OH_Huks_Blob keyAlias = { strlen(tmpKeyAlias), (uint8_t *)tmpKeyAlias };
struct OH_Huks_ParamSet *genParamSet = nullptr;
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParams001, sizeof(g_genParams001) / sizeof(OH_Huks_Param));
struct OH_Huks_ParamSet *hmacParamSet = nullptr;
ret = InitParamSet(&hmacParamSet, g_hmacParams001, sizeof(g_hmacParams001) / sizeof(OH_Huks_Param));
ret = HksHmacTestCase(&keyAlias, genParamSet, hmacParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "this case failed.";
OH_Huks_FreeParamSet(&genParamSet);
OH_Huks_FreeParamSet(&hmacParamSet);
}
/**
* @tc.name: HksHmacTest.Security_HUKS_NAPI_HMAC_SM3_0100
* @tc.desc: alg-HMAC pur-MAC dig-sm3.
* @tc.type: FUNC
*/
HWTEST_F(HksHmacTest, Security_HUKS_NAPI_HMAC_SM3_0100, TestSize.Level0)
{
char tmpKeyAlias[] = "HksHMACKeyAliasTest008";
struct OH_Huks_Blob keyAlias = { strlen(tmpKeyAlias), (uint8_t *)tmpKeyAlias };
struct OH_Huks_ParamSet *genParamSet = nullptr;
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParams006, sizeof(g_genParams006) / sizeof(OH_Huks_Param));
struct OH_Huks_ParamSet *hmacParamSet = nullptr;
ret = InitParamSet(&hmacParamSet, g_hmacParams006, sizeof(g_hmacParams006) / sizeof(OH_Huks_Param));
ret = HksHmacTestCase(&keyAlias, genParamSet, hmacParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "this case failed.";
OH_Huks_FreeParamSet(&genParamSet);
OH_Huks_FreeParamSet(&hmacParamSet);
}
} // namespace Unittest::Hmac
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_mem.h"
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
void *HksMalloc(size_t size)
{
return malloc(size);
}
void HksFree(void *ptr)
{
free(ptr);
}
int32_t HksMemCmp(const void *ptr1, const void *ptr2, uint32_t size)
{
return memcmp(ptr1, ptr2, size);
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_misc_test.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::HuksMisc
{
class HuksMiscTest : public testing::Test
{
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HuksMiscTest::SetUpTestCase(void)
{
}
void HuksMiscTest::TearDownTestCase(void)
{
}
void HuksMiscTest::SetUp()
{
}
void HuksMiscTest::TearDown()
{
}
/**
* @tc.name: HuksMiscTest.Security_HUKS_NAPI_Misc_0100
* @tc.desc: misc test
* @tc.type: FUNC
*/
HWTEST_F(HuksMiscTest, Security_HUKS_NAPI_Misc_0100, TestSize.Level0)
{
ASSERT_EQ((uint32_t)OH_HUKS_DIGEST_NONE == 0, true);
ASSERT_EQ((uint32_t)OH_HUKS_DIGEST_MD5 == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_DIGEST_SM3 == 2, true);
ASSERT_EQ((uint32_t)OH_HUKS_DIGEST_SHA1 == 10, true);
ASSERT_EQ((uint32_t)OH_HUKS_DIGEST_SHA224 == 11, true);
ASSERT_EQ((uint32_t)OH_HUKS_DIGEST_SHA256 == 12, true);
ASSERT_EQ((uint32_t)OH_HUKS_DIGEST_SHA384 == 13, true);
ASSERT_EQ((uint32_t)OH_HUKS_DIGEST_SHA512 == 14, true);
ASSERT_EQ((uint32_t)OH_HUKS_PADDING_NONE == 0, true);
ASSERT_EQ((uint32_t)OH_HUKS_PADDING_OAEP == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_PADDING_PSS == 2, true);
ASSERT_EQ((uint32_t)OH_HUKS_PADDING_PKCS1_V1_5 == 3, true);
ASSERT_EQ((uint32_t)OH_HUKS_PADDING_PKCS5 == 4, true);
ASSERT_EQ((uint32_t)OH_HUKS_PADDING_PKCS7 == 5, true);
ASSERT_EQ((uint32_t)OH_HUKS_MODE_ECB == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_MODE_CBC == 2, true);
ASSERT_EQ((uint32_t)OH_HUKS_MODE_CTR == 3, true);
ASSERT_EQ((uint32_t)OH_HUKS_MODE_OFB == 4, true);
ASSERT_EQ((uint32_t)OH_HUKS_MODE_CCM == 31, true);
ASSERT_EQ((uint32_t)OH_HUKS_MODE_GCM == 32, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_PURPOSE_ENCRYPT == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_PURPOSE_DECRYPT == 2, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_PURPOSE_SIGN == 4, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_PURPOSE_VERIFY == 8, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_PURPOSE_DERIVE == 16, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_PURPOSE_WRAP == 32, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_PURPOSE_UNWRAP == 64, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_PURPOSE_MAC == 128, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_PURPOSE_AGREE == 256, true);
ASSERT_EQ((uint32_t)OH_HUKS_RSA_KEY_SIZE_512 == 512, true);
ASSERT_EQ((uint32_t)OH_HUKS_RSA_KEY_SIZE_768 == 768, true);
ASSERT_EQ((uint32_t)OH_HUKS_RSA_KEY_SIZE_1024 == 1024, true);
ASSERT_EQ((uint32_t)OH_HUKS_RSA_KEY_SIZE_2048 == 2048, true);
ASSERT_EQ((uint32_t)OH_HUKS_RSA_KEY_SIZE_3072 == 3072, true);
ASSERT_EQ((uint32_t)OH_HUKS_RSA_KEY_SIZE_4096 == 4096, true);
ASSERT_EQ((uint32_t)OH_HUKS_ECC_KEY_SIZE_224 == 224, true);
ASSERT_EQ((uint32_t)OH_HUKS_ECC_KEY_SIZE_256 == 256, true);
ASSERT_EQ((uint32_t)OH_HUKS_ECC_KEY_SIZE_384 == 384, true);
ASSERT_EQ((uint32_t)OH_HUKS_ECC_KEY_SIZE_521 == 521, true);
ASSERT_EQ((uint32_t)OH_HUKS_AES_KEY_SIZE_128 == 128, true);
ASSERT_EQ((uint32_t)OH_HUKS_AES_KEY_SIZE_192 == 192, true);
ASSERT_EQ((uint32_t)OH_HUKS_AES_KEY_SIZE_256 == 256, true);
ASSERT_EQ((uint32_t)OH_HUKS_AES_KEY_SIZE_512 == 512, true);
ASSERT_EQ((uint32_t)OH_HUKS_DH_KEY_SIZE_2048 == 2048, true);
ASSERT_EQ((uint32_t)OH_HUKS_DH_KEY_SIZE_3072 == 3072, true);
ASSERT_EQ((uint32_t)OH_HUKS_DH_KEY_SIZE_4096 == 4096, true);
ASSERT_EQ((uint32_t)OH_HUKS_SM2_KEY_SIZE_256 == 256, true);
ASSERT_EQ((uint32_t)OH_HUKS_SM4_KEY_SIZE_128 == 128, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_RSA == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_ECC == 2, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_DSA == 3, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_AES == 20, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_HMAC == 50, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_HKDF == 51, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_PBKDF2 == 52, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_ECDH == 100, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_X25519 == 101, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_ED25519 == 102, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_DH == 103, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_SM2 == 150, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_SM3 == 151, true);
ASSERT_EQ((uint32_t)OH_HUKS_ALG_SM4 == 152, true);
ASSERT_EQ((uint32_t)OH_HUKS_UNWRAP_SUITE_X25519_AES_256_GCM_NOPADDING == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_UNWRAP_SUITE_ECDH_AES_256_GCM_NOPADDING == 2, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_GENERATE_TYPE_DEFAULT == 0, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_GENERATE_TYPE_DERIVE == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_GENERATE_TYPE_AGREE == 2, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_FLAG_IMPORT_KEY == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_FLAG_GENERATE_KEY == 2, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_FLAG_AGREE_KEY == 3, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_FLAG_DERIVE_KEY == 4, true);
ASSERT_EQ((uint32_t)OH_HUKS_STORAGE_TEMP == 0, true);
ASSERT_EQ((uint32_t)OH_HUKS_STORAGE_PERSISTENT == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_TYPE_PUBLIC_KEY == 0, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_TYPE_PRIVATE_KEY == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_KEY_TYPE_KEY_PAIR == 2, true);
ASSERT_EQ((uint32_t)OH_HUKS_SUCCESS == 0, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_PERMISSION_FAIL == 201, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT == 401, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_NOT_SUPPORTED_API == 801, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_FEATURE_NOT_SUPPORTED == 12000001, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT == 12000002, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT == 12000003, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_FILE_OPERATION_FAIL == 12000004, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_COMMUNICATION_FAIL == 12000005, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_CRYPTO_FAIL == 12000006, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_KEY_AUTH_PERMANENTLY_INVALIDATED == 12000007, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_KEY_AUTH_VERIFY_FAILED == 12000008, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_KEY_AUTH_TIME_OUT == 12000009, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_SESSION_LIMIT == 12000010, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_ITEM_NOT_EXIST == 12000011, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_INTERNAL_ERROR == 12000012, true);
ASSERT_EQ((uint32_t)OH_HUKS_ERR_CODE_CREDENTIAL_NOT_EXIST == 12000013, true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_TYPE_INVALID == 0 << 28, true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_TYPE_INT == 1 << 28, true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_TYPE_UINT == 2 << 28, true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_TYPE_ULONG == 3 << 28, true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_TYPE_BOOL == 4 << 28, true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_TYPE_BYTES == 5 << 28, true);
ASSERT_EQ((uint32_t)OH_HUKS_USER_AUTH_TYPE_FINGERPRINT == 1 << 0, true);
ASSERT_EQ((uint32_t)OH_HUKS_USER_AUTH_TYPE_FACE == 1 << 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_USER_AUTH_TYPE_PIN == 1 << 2, true);
ASSERT_EQ((uint32_t)OH_HUKS_AUTH_ACCESS_INVALID_CLEAR_PASSWORD == 1 << 0, true);
ASSERT_EQ((uint32_t)OH_HUKS_AUTH_ACCESS_INVALID_NEW_BIO_ENROLL == 1 << 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_CHALLENGE_TYPE_NORMAL == 0, true);
ASSERT_EQ((uint32_t)OH_HUKS_CHALLENGE_TYPE_CUSTOM == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_CHALLENGE_TYPE_NONE == 2, true);
ASSERT_EQ((uint32_t)OH_HUKS_CHALLENGE_POS_0 == 0, true);
ASSERT_EQ((uint32_t)OH_HUKS_CHALLENGE_POS_1 == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_CHALLENGE_POS_2 == 2, true);
ASSERT_EQ((uint32_t)OH_HUKS_CHALLENGE_POS_3 == 3, true);
ASSERT_EQ((uint32_t)OH_HUKS_SECURE_SIGN_WITH_AUTHINFO == 1, true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_INVALID == (OH_HUKS_TAG_TYPE_INVALID | 0), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ALGORITHM == (OH_HUKS_TAG_TYPE_UINT | 1), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_PURPOSE == (OH_HUKS_TAG_TYPE_UINT | 2), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_KEY_SIZE == (OH_HUKS_TAG_TYPE_UINT | 3), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_DIGEST == (OH_HUKS_TAG_TYPE_UINT | 4), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_PADDING == (OH_HUKS_TAG_TYPE_UINT | 5), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_BLOCK_MODE == (OH_HUKS_TAG_TYPE_UINT | 6), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_KEY_TYPE == (OH_HUKS_TAG_TYPE_UINT | 7), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ASSOCIATED_DATA == (OH_HUKS_TAG_TYPE_BYTES | 8), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_NONCE == (OH_HUKS_TAG_TYPE_BYTES | 9), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_IV == (OH_HUKS_TAG_TYPE_BYTES | 10), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_INFO == (OH_HUKS_TAG_TYPE_BYTES | 11), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_SALT == (OH_HUKS_TAG_TYPE_BYTES | 12), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_PWD == (OH_HUKS_TAG_TYPE_BYTES | 13), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ITERATION == (OH_HUKS_TAG_TYPE_UINT | 14), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_KEY_GENERATE_TYPE == (OH_HUKS_TAG_TYPE_UINT | 15), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_DERIVE_MAIN_KEY == (OH_HUKS_TAG_TYPE_BYTES | 16), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_DERIVE_FACTOR == (OH_HUKS_TAG_TYPE_BYTES | 17), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_DERIVE_ALG == (OH_HUKS_TAG_TYPE_UINT | 18), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_AGREE_ALG == (OH_HUKS_TAG_TYPE_UINT | 19), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_AGREE_PUBLIC_KEY_IS_KEY_ALIAS == (OH_HUKS_TAG_TYPE_BOOL | 20), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_AGREE_PRIVATE_KEY_ALIAS == (OH_HUKS_TAG_TYPE_BYTES | 21), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_AGREE_PUBLIC_KEY == (OH_HUKS_TAG_TYPE_BYTES | 22), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_KEY_ALIAS == (OH_HUKS_TAG_TYPE_BYTES | 23), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_DERIVE_KEY_SIZE == (OH_HUKS_TAG_TYPE_UINT | 24), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_IMPORT_KEY_TYPE == (OH_HUKS_TAG_TYPE_UINT | 25), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_UNWRAP_ALGORITHM_SUITE == (OH_HUKS_TAG_TYPE_UINT | 26), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ALL_USERS == (OH_HUKS_TAG_TYPE_BOOL | 301), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_USER_ID == (OH_HUKS_TAG_TYPE_UINT | 302), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_NO_AUTH_REQUIRED == (OH_HUKS_TAG_TYPE_BOOL | 303), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_USER_AUTH_TYPE == (OH_HUKS_TAG_TYPE_UINT | 304), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_AUTH_TIMEOUT == (OH_HUKS_TAG_TYPE_UINT | 305), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_AUTH_TOKEN == (OH_HUKS_TAG_TYPE_BYTES | 306), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_KEY_AUTH_ACCESS_TYPE == (OH_HUKS_TAG_TYPE_UINT | 307), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_KEY_SECURE_SIGN_TYPE == (OH_HUKS_TAG_TYPE_UINT | 308), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_CHALLENGE_TYPE == (OH_HUKS_TAG_TYPE_UINT | 309), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_CHALLENGE_POS == (OH_HUKS_TAG_TYPE_UINT | 310), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_CHALLENGE == (OH_HUKS_TAG_TYPE_BYTES | 501), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_APPLICATION_ID == (OH_HUKS_TAG_TYPE_BYTES | 502), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_BRAND == (OH_HUKS_TAG_TYPE_BYTES | 503), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_DEVICE == (OH_HUKS_TAG_TYPE_BYTES | 504), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_PRODUCT == (OH_HUKS_TAG_TYPE_BYTES | 505), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_SERIAL == (OH_HUKS_TAG_TYPE_BYTES | 506), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_IMEI == (OH_HUKS_TAG_TYPE_BYTES | 507), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_MEID == (OH_HUKS_TAG_TYPE_BYTES | 508), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_MANUFACTURER == (OH_HUKS_TAG_TYPE_BYTES | 509), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_MODEL == (OH_HUKS_TAG_TYPE_BYTES | 510), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_ALIAS == (OH_HUKS_TAG_TYPE_BYTES | 511), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_SOCID == (OH_HUKS_TAG_TYPE_BYTES | 512), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_UDID == (OH_HUKS_TAG_TYPE_BYTES | 513), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO == (OH_HUKS_TAG_TYPE_BYTES | 514), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ATTESTATION_ID_VERSION_INFO == (OH_HUKS_TAG_TYPE_BYTES | 515), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_IS_KEY_ALIAS == (OH_HUKS_TAG_TYPE_BOOL | 1001), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_KEY_STORAGE_FLAG == (OH_HUKS_TAG_TYPE_UINT | 1002), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_IS_ALLOWED_WRAP == (OH_HUKS_TAG_TYPE_BOOL | 1003), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_KEY_WRAP_TYPE == (OH_HUKS_TAG_TYPE_UINT | 1004), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_KEY_AUTH_ID == (OH_HUKS_TAG_TYPE_BYTES | 1005), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_KEY_ROLE == (OH_HUKS_TAG_TYPE_UINT | 1006), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_KEY_FLAG == (OH_HUKS_TAG_TYPE_UINT | 1007), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_IS_ASYNCHRONIZED == (OH_HUKS_TAG_TYPE_UINT | 1008), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_SECURE_KEY_ALIAS == (OH_HUKS_TAG_TYPE_BOOL | 1009), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_SECURE_KEY_UUID == (OH_HUKS_TAG_TYPE_BYTES | 1010), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_KEY_DOMAIN == (OH_HUKS_TAG_TYPE_UINT | 1011), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_SYMMETRIC_KEY_DATA == (OH_HUKS_TAG_TYPE_BYTES | 20001), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ASYMMETRIC_PUBLIC_KEY_DATA == (OH_HUKS_TAG_TYPE_BYTES | 20002), true);
ASSERT_EQ((uint32_t)OH_HUKS_TAG_ASYMMETRIC_PRIVATE_KEY_DATA == (OH_HUKS_TAG_TYPE_BYTES | 20003), true);
struct OH_Huks_Result result;
ASSERT_EQ(sizeof(result.errorCode) == sizeof(int32_t), true);
ASSERT_EQ(sizeof(result.errorMsg) == sizeof(const char *), true);
ASSERT_EQ(sizeof(result.data) == sizeof(uint8_t *), true);
struct OH_Huks_Blob blob;
ASSERT_EQ(sizeof(blob.size) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(blob.data) == sizeof(uint8_t *), true);
struct OH_Huks_Param param;
ASSERT_EQ(sizeof(param.tag) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(param.boolParam) == sizeof(bool), true);
ASSERT_EQ(sizeof(param.int32Param) == sizeof(int32_t), true);
ASSERT_EQ(sizeof(param.uint32Param) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(param.uint64Param) == sizeof(uint64_t), true);
ASSERT_EQ(sizeof(param.blob) == sizeof(struct OH_Huks_Blob), true);
struct OH_Huks_ParamSet paramset;
ASSERT_EQ(sizeof(paramset.paramSetSize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(paramset.paramsCnt) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(paramset.params[0]) == sizeof(struct OH_Huks_Param), true);
struct OH_Huks_CertChain certChain;
ASSERT_EQ(sizeof(certChain.certs) == sizeof(struct OH_Huks_Blob *), true);
ASSERT_EQ(sizeof(certChain.certsCount) == sizeof(uint32_t), true);
struct OH_Huks_KeyInfo keyInfo;
ASSERT_EQ(sizeof(keyInfo.alias) == sizeof(struct OH_Huks_Blob), true);
ASSERT_EQ(sizeof(keyInfo.paramSet) == sizeof(struct OH_Huks_ParamSet *), true);
struct OH_Huks_PubKeyInfo pubKeyInfo;
ASSERT_EQ(sizeof(pubKeyInfo.keyAlg) == sizeof(OH_Huks_KeyAlg), true);
ASSERT_EQ(sizeof(pubKeyInfo.keySize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(pubKeyInfo.nOrXSize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(pubKeyInfo.eOrYSize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(pubKeyInfo.placeHolder) == sizeof(uint32_t), true);
struct OH_Huks_KeyMaterialRsa keyMaterialRsa;
ASSERT_EQ(sizeof(keyMaterialRsa.keyAlg) == sizeof(OH_Huks_KeyAlg), true);
ASSERT_EQ(sizeof(keyMaterialRsa.keySize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialRsa.nSize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialRsa.eSize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialRsa.dSize) == sizeof(uint32_t), true);
struct OH_Huks_KeyMaterialEcc keyMaterialEcc;
ASSERT_EQ(sizeof(keyMaterialEcc.keyAlg) == sizeof(OH_Huks_KeyAlg), true);
ASSERT_EQ(sizeof(keyMaterialEcc.keySize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialEcc.xSize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialEcc.ySize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialEcc.zSize) == sizeof(uint32_t), true);
struct OH_Huks_KeyMaterialDsa keyMaterialDsa;
ASSERT_EQ(sizeof(keyMaterialDsa.keyAlg) == sizeof(OH_Huks_KeyAlg), true);
ASSERT_EQ(sizeof(keyMaterialDsa.keySize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialDsa.xSize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialDsa.ySize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialDsa.pSize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialDsa.qSize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialDsa.gSize) == sizeof(uint32_t), true);
struct OH_Huks_KeyMaterialDh keyMaterialDh;
ASSERT_EQ(sizeof(keyMaterialDh.keyAlg) == sizeof(OH_Huks_KeyAlg), true);
ASSERT_EQ(sizeof(keyMaterialDh.keySize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialDh.pubKeySize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialDh.priKeySize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterialDh.reserved) == sizeof(uint32_t), true);
struct OH_Huks_KeyMaterial25519 keyMaterial25519;
ASSERT_EQ(sizeof(keyMaterial25519.keyAlg) == sizeof(OH_Huks_KeyAlg), true);
ASSERT_EQ(sizeof(keyMaterial25519.keySize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterial25519.pubKeySize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterial25519.priKeySize) == sizeof(uint32_t), true);
ASSERT_EQ(sizeof(keyMaterial25519.reserved) == sizeof(uint32_t), true);
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_nullptr_test.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::NullPtrTest{
class HuksNullptrTest : public testing::Test{
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HuksNullptrTest::SetUpTestCase(void)
{
}
void HuksNullptrTest::TearDownTestCase(void)
{
}
void HuksNullptrTest::SetUp()
{
}
void HuksNullptrTest::TearDown()
{
}
static struct OH_Huks_ParamSet *paramSetNullptr=nullptr;
static struct OH_Huks_Param *paramNullptr=nullptr;
static struct OH_Huks_Blob *blobNullptr=nullptr;
static struct OH_Huks_CertChain *certChainNullptr=nullptr;
/**
* @tc.name: HuksNullptrTest.Security_HUKS_NAPI_nullptr_0100
* @tc.desc: use nullptr.
* @tc.type: FUNC
*/
HWTEST_F(HuksNullptrTest, Security_HUKS_NAPI_nullptr_0100, TestSize.Level0)
{
OH_Huks_Result ret=OH_Huks_InitParamSet(&paramSetNullptr);
EXPECT_EQ(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_AddParams(paramSetNullptr,paramNullptr,0);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_BuildParamSet(&paramSetNullptr);
EXPECT_EQ(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_CopyParamSet(paramSetNullptr,0,&paramSetNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_GetParam(paramSetNullptr,0,&paramNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_FreshParamSet(paramSetNullptr,0);
EXPECT_EQ(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_IsParamSetTagValid(paramSetNullptr);
EXPECT_EQ(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_IsParamSetValid(paramSetNullptr,0);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
struct OH_Huks_Param baseParam = { .tag = OH_HUKS_TAG_INVALID, .uint64Param = (uint64_t)1 };
struct OH_Huks_Param otherParam = { .tag = OH_HUKS_TAG_INVALID, .uint64Param = (uint64_t)2 };
ret=OH_Huks_CheckParamMatch(&baseParam,&otherParam);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_GetSdkVersion(blobNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_GenerateKeyItem(blobNullptr,paramSetNullptr,paramSetNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_ImportWrappedKeyItem(blobNullptr,blobNullptr,paramSetNullptr,blobNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_ExportPublicKeyItem(blobNullptr,paramSetNullptr,blobNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_DeleteKeyItem(blobNullptr,paramSetNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_GetKeyItemParamSet(blobNullptr,paramSetNullptr,paramSetNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_IsKeyItemExist(blobNullptr,paramSetNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_AttestKeyItem(blobNullptr,paramSetNullptr,certChainNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_InitSession(blobNullptr,paramSetNullptr,blobNullptr,blobNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_UpdateSession(blobNullptr,paramSetNullptr,blobNullptr,blobNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_FinishSession(blobNullptr,paramSetNullptr,blobNullptr,blobNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
ret=OH_Huks_AbortSession(blobNullptr,paramSetNullptr);
EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
}
};
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "huks_signverify_dsa_test.h"
#include <gtest/gtest.h>
using namespace testing::ext;
namespace Unittest::DsaSignVerify {
class HuksSignVerifyDSATest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HuksSignVerifyDSATest::SetUpTestCase(void)
{
}
void HuksSignVerifyDSATest::TearDownTestCase(void)
{
}
void HuksSignVerifyDSATest::SetUp()
{
}
void HuksSignVerifyDSATest::TearDown()
{
}
static struct OH_Huks_Param g_genParamsTest001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_DSA
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_SIGN | OH_HUKS_KEY_PURPOSE_VERIFY
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = DSA_COMMON_SIZE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
static struct OH_Huks_Param g_signParamsTest001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_DSA
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_SIGN
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
static struct OH_Huks_Param g_verifyParamsTest001[] = {
{
.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_DSA
}, {
.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_VERIFY
}, {
.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = DSA_COMMON_SIZE
}, {
.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1
}
};
OH_Huks_Result HksTestSignVerify(struct OH_Huks_Blob *keyAlias, struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *inData,
struct OH_Huks_Blob *outData, bool isSign)
{
uint8_t tmpHandle[sizeof(uint64_t)] = {0};
struct OH_Huks_Blob handle = { sizeof(uint64_t), tmpHandle };
OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, paramSet, &handle, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Init failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
struct OH_Huks_Param *tmpParam = NULL;
ret = OH_Huks_GetParam(paramSet, OH_HUKS_TAG_PURPOSE, &tmpParam);
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
ret = TestUpdateFinish(&handle, paramSet, tmpParam->uint32Param, inData, outData);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "TestUpdateFinish failed.";
if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) {
return ret;
}
return ret;
}
OH_Huks_Result HksDsaSignVerifyTestNormalCase(struct OH_Huks_Blob keyAlias, struct OH_Huks_ParamSet *genParamSet,
struct OH_Huks_ParamSet *signParamSet, struct OH_Huks_ParamSet *verifyParamSet)
{
struct OH_Huks_Blob inData = {
g_inData.length(),
(uint8_t *)g_inData.c_str()
};
/* 1. Generate Key */
// Generate Key
OH_Huks_Result ret = OH_Huks_GenerateKeyItem(&keyAlias, genParamSet, nullptr);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "GenerateKey failed.";
/* 2. Sign Three Stage */
uint8_t outDataS[DSA_COMMON_SIZE] = {0};
struct OH_Huks_Blob outDataSign = { DSA_COMMON_SIZE, outDataS };
ret = HksTestSignVerify(&keyAlias, signParamSet, &inData, &outDataSign, true);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Sign failed.";
/* 3. Export Public Key */
uint8_t pubKey[DSA_COMMON_SIZE] = {0};
struct OH_Huks_Blob publicKey = { DSA_COMMON_SIZE, pubKey };
ret = OH_Huks_ExportPublicKeyItem(&keyAlias, genParamSet, &publicKey);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "ExportPublicKey failed.";
/* 4. Import Key */
char newKey[] = "DSA_Sign_Verify_Import_KeyAlias";
struct OH_Huks_Blob newKeyAlias = { .size = strlen(newKey), .data = (uint8_t *)newKey };
ret = OH_Huks_ImportKeyItem(&newKeyAlias, verifyParamSet, &publicKey);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "ImportKey failed";
/* 5. Verify Three Stage */
ret = HksTestSignVerify(&newKeyAlias, verifyParamSet, &inData, &outDataSign, false);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Verify failed.";
/* 6. Delete New Key */
ret = OH_Huks_DeleteKeyItem(&newKeyAlias, verifyParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "Delete ImportKey failed.";
return ret;
}
/**
* @tc.name: HuksSignVerifyDSATest.Security_HUKS_NAPI_SignVerify_DSA_0100
* @tc.desc: alg-DSA pur-Sign-verify dig-SHA1
* @tc.type: FUNC
*/
HWTEST_F(HuksSignVerifyDSATest, Security_HUKS_NAPI_SignVerify_DSA_0100, TestSize.Level0)
{
const char *keyAliasString = "HksDSASignVerifyKeyAliasTest001";
struct OH_Huks_ParamSet *genParamSet = nullptr;
struct OH_Huks_ParamSet *signParamSet = nullptr;
struct OH_Huks_ParamSet *verifyParamSet = nullptr;
struct OH_Huks_Blob keyAlias = { strlen(keyAliasString), (uint8_t *)keyAliasString };
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParamsTest001, sizeof(g_genParamsTest001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
ret = InitParamSet(&signParamSet, g_signParamsTest001, sizeof(g_signParamsTest001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
ret = InitParamSet(&verifyParamSet, g_verifyParamsTest001, sizeof(g_verifyParamsTest001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
if ((genParamSet != nullptr) || (signParamSet != nullptr) || (verifyParamSet != nullptr)) {
ret = HksDsaSignVerifyTestNormalCase(keyAlias, genParamSet, signParamSet, verifyParamSet);
}
/* 5. Delete Key */
ret = OH_Huks_DeleteKeyItem(&keyAlias, genParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
OH_Huks_FreeParamSet(&genParamSet);
OH_Huks_FreeParamSet(&signParamSet);
OH_Huks_FreeParamSet(&verifyParamSet);
}
} // namespace Unittest::DsaSignVerify
\ No newline at end of file
此差异已折叠。
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
group("security_huks_reformed_test") {
testonly = true
if (is_standard_system) {
deps = [
"huks_agree_callback_BasicTest:huksagree_callback_basic_js_test",
"huks_agree_promise_BasicTest:huksagree_promise_basic_js_test",
"huks_cipher_callback_BasicTest:hukscipher_callback_basic_js_test",
"huks_cipher_promise_BasicTest:hukscipher_promise_basic_js_test",
"huks_derive_callback_BasicTest:huksderive_callback_basic_js_test",
"huks_derive_promise_BasicTest:huksderive_promise_basic_js_test",
"huks_hmac_callback_BasicTest:hukshmac_callback_basic_js_test",
"huks_hmac_promise_BasicTest:hukshmac_promise_basic_js_test",
"huks_signverify_callback_BasicTest:hukssignverify_callback_basic_js_test",
"huks_signverify_promise_BasicTest:hukssignverify_promise_basic_js_test",
]
}
}
{
"description": "Configuration for huksAgreeBasicCallback js api Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "4200000",
"shell-timeout": "4200000",
"bundle-name": "com.example.huksagreebasiccallback",
"package-name": "com.example.huksagreebasiccallback",
"testcase-timeout": 1500000
},
"kits": [
{
"test-file-name": [
"ActsHuksAgreeBasicCallbackJSApiTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册