提交 8bde6c20 编写于 作者: O openharmony_ci 提交者: Gitee

!540 L0/L1 hks_testcase code merge

Merge pull request !540 from 胡吉翔/security_lite_20210908
......@@ -12,8 +12,8 @@
# limitations under the License.
import("//build/lite/config/subsystem/aafwk/config.gni")
import("//test/xts/tools/lite/build/suite_lite.gni")
import("//build/lite/config/test.gni")
import("//test/xts/tools/lite/build/suite_lite.gni")
lite_component("acts_component") {
all_features = []
......@@ -40,7 +40,9 @@ lite_component("acts_component") {
"//test/xts/acts/iot_hardware_lite/iot_controller_hal:ActsWifiIotTest",
"//test/xts/acts/kernel_lite/kernelcmsis_hal:ActsCMSISTest",
"//test/xts/acts/utils_lite/kv_store_hal:ActsKvStoreTest",
#"//test/xts/acts/security_lite/huks_hal:ActsSecurityDataTest",
"//test/xts/acts/security_lite/huks/liteos_m_adapter:ActsHuksHalFunctionTest",
"//test/xts/acts/hiviewdfx_lite/hilog_hal:ActsDfxFuncTest",
"//test/xts/acts/hiviewdfx_lite/hievent_hal:ActsHieventLiteTest",
......@@ -59,6 +61,7 @@ lite_component("acts_component") {
"//test/xts/acts/startup_lite/bootstrap_posix:ActsBootstrapTest",
"//test/xts/acts/multimedia_lite/camera_lite_posix/camera_native:ActsMediaCameraTest",
"//test/xts/acts/open_posix_testsuite/conformance/interfaces:ActsOpenPosixTest",
#"//test/xts/acts/multimedia_lite/media_lite_posix/player_native:ActsMediaPlayerTest",
"//test/xts/acts/distributed_schedule_lite/system_ability_manager_posix:ActsSamgrTest",
......@@ -85,6 +88,7 @@ lite_component("acts_component") {
all_features += [
"//test/xts/acts/utils_lite/kv_store_posix:ActsKvStoreTest",
"//test/xts/acts/startup_lite/syspara_posix:ActsParameterTest",
#"//test/xts/acts/security_lite/huks_posix:ActsSecurityDataTest",
#"//test/xts/acts/multimedia_lite/camera_lite_posix/camera_native:ActsMediaCameraTest",
#"//test/xts/acts/multimedia_lite/media_lite_posix/player_native:ActsMediaPlayerTest",
......
......@@ -14,6 +14,7 @@
group("securitytest") {
deps = [
#"//test/xts/acts/security_lite/huks_posix:ActsSecurityDataTest",
"//test/xts/acts/security_lite/huks/liteos_a_adapter:Hukslitetest",
"//test/xts/acts/security_lite/permission_posix/capability:ActsCapabilityTest",
"//test/xts/acts/security_lite/permission_posix/dac:ActsDacTest",
]
......
#
# Copyright (c) 2020 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.
#
config("hilog_dir") {
include_dirs =
[ "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog/" ]
}
config("hilog_lite_dir") {
include_dirs =
[ "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite/" ]
}
config("huks_test_common") {
include_dirs = [
"//base/security/huks/interfaces/innerkits/huks_standard/main/include",
"include",
]
}
static_library("huks_new_test_common") {
sources = [
"hks_test_aes.c",
"hks_test_api_performance.c",
"hks_test_cipher.c",
"hks_test_common.c",
"hks_test_curve25519.c",
"hks_test_file_operator.c",
#"hks_test_log.c",
"hks_test_mem.c",
]
deps = []
include_dirs = [
"//utils/native/base/include",
"//third_party/bounds_checking_function/include",
#"unittest/include",
"include",
]
configs += [ ":huks_test_common" ]
if (defined(ohos_lite)) {
if (ohos_kernel_type == "liteos_m") {
configs += [ ":hilog_lite_dir" ]
deps += [ "//base/hiviewdfx/hilog_lite/frameworks/mini:hilog_lite" ]
} else if (ohos_kernel_type == "liteos_a") {
configs += [ ":hilog_dir" ]
deps += [ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared" ]
}
}
}
此差异已折叠。
/*
* 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 <assert.h>
#include "hks_test_api_performance.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_log.h"
#define USEC_MINT 1000
#define USEC_UINT 1000000
int32_t HksGenerateKeyRun(const struct HksBlob *keyAlias, const struct HksParamSet *paramSetIn,
struct HksParamSet *paramSetOut, uint32_t performTimes)
{
int32_t ret;
/* if keyAlias exist, the key will be generated and refreshed */
for (uint32_t i = 0; i < performTimes; ++i) {
ret = HksGenerateKey(keyAlias, paramSetIn, paramSetOut);
if (ret != HKS_SUCCESS) {
return ret;
}
}
return HKS_SUCCESS;
}
int32_t HksEncryptRun(const struct HksBlob *key, const struct HksParamSet *paramSet,
const struct HksBlob *plainText, struct HksBlob *cipherText, uint32_t performTimes)
{
int32_t ret;
uint32_t oriCipherTestSize = 0;
if (cipherText != NULL) {
oriCipherTestSize = cipherText->size;
}
for (uint32_t i = 0; i < performTimes; ++i) {
if (cipherText != NULL) {
(void)memset_s(cipherText->data, oriCipherTestSize, 0, oriCipherTestSize);
cipherText->size = oriCipherTestSize;
}
ret = HksEncrypt(key, paramSet, plainText, cipherText);
if (ret != HKS_SUCCESS) {
return ret;
}
}
return HKS_SUCCESS;
}
int32_t HksDecryptRun(const struct HksBlob *key, const struct HksParamSet *paramSet,
const struct HksBlob *cipherText, struct HksBlob *plainText, uint32_t performTimes)
{
int32_t ret;
uint32_t oriPlainTextSize = 0;
if (plainText != NULL) {
oriPlainTextSize = plainText->size;
}
for (uint32_t i = 0; i < performTimes; ++i) {
if (plainText != NULL) {
(void)memset_s(plainText->data, oriPlainTextSize, 0, oriPlainTextSize);
plainText->size = oriPlainTextSize;
}
ret = HksDecrypt(key, paramSet, cipherText, plainText);
if (ret != HKS_SUCCESS) {
return ret;
}
}
return HKS_SUCCESS;
}
int32_t HksMacRun(const struct HksBlob *key, const struct HksParamSet *paramSet,
const struct HksBlob *srcData, struct HksBlob *mac, uint32_t performTimes)
{
int32_t ret;
uint32_t oriMacSize = 0;
if (mac != NULL) {
oriMacSize = mac->size;
}
for (uint32_t i = 0; i < performTimes; ++i) {
if (mac != NULL) {
(void)memset_s(mac->data, oriMacSize, 0, oriMacSize);
mac->size = oriMacSize;
}
ret = HksMac(key, paramSet, srcData, mac);
if (ret != HKS_SUCCESS) {
return ret;
}
}
return HKS_SUCCESS;
}
int32_t HksDeriveKeyRun(const struct HksParamSet *paramSet, const struct HksBlob *masterKey,
struct HksBlob *derivedKey, uint32_t performTimes)
{
int32_t ret;
uint32_t oriDerivedKeySize = 0;
if (derivedKey != NULL) {
oriDerivedKeySize = derivedKey->size;
}
for (uint32_t i = 0; i < performTimes; ++i) {
if (derivedKey != NULL) {
(void)memset_s(derivedKey->data, oriDerivedKeySize, 0, oriDerivedKeySize);
derivedKey->size = oriDerivedKeySize;
}
ret = HksDeriveKey(paramSet, masterKey, derivedKey);
if (ret != HKS_SUCCESS) {
return ret;
}
}
return HKS_SUCCESS;
}
int32_t HksDeleteKeyRun(const struct HksBlob *keyAlias, uint32_t performTimes)
{
(void)performTimes;
return HksDeleteKey(keyAlias, NULL);
}
int32_t HksKeyExistRun(const struct HksBlob *keyAlias, uint32_t performTimes)
{
int32_t ret;
for (uint32_t i = 0; i < performTimes; ++i) {
ret = HksKeyExist(keyAlias, NULL);
if (ret != HKS_SUCCESS) {
return ret;
}
}
return HKS_SUCCESS;
}
int32_t HksGenerateRandomRun(struct HksBlob *random, uint32_t performTimes)
{
int32_t ret;
uint32_t oriRandomSize = 0;
if (random != NULL) {
oriRandomSize = random->size;
}
for (uint32_t i = 0; i < performTimes; ++i) {
if (random != NULL) {
(void)memset_s(random->data, oriRandomSize, 0, oriRandomSize);
random->size = oriRandomSize;
}
ret = HksGenerateRandom(NULL, random);
if (ret != HKS_SUCCESS) {
return ret;
}
}
return HKS_SUCCESS;
}
int32_t HksAgreeKeyRun(const struct HksParamSet *paramSet, const struct HksBlob *privateKey,
const struct HksBlob *peerPublicKey, struct HksBlob *agreedKey, uint32_t performTimes)
{
int32_t ret;
uint32_t oriAgreedKeySize = 0;
if (agreedKey != NULL) {
oriAgreedKeySize = agreedKey->size;
}
for (uint32_t i = 0; i < performTimes; ++i) {
if (agreedKey != NULL) {
(void)memset_s(agreedKey->data, oriAgreedKeySize, 0, oriAgreedKeySize);
agreedKey->size = oriAgreedKeySize;
}
ret = HksAgreeKey(paramSet, privateKey, peerPublicKey, agreedKey);
if (ret != HKS_SUCCESS) {
return ret;
}
}
return HKS_SUCCESS;
}
int32_t HksHashRun(const struct HksParamSet *paramSet,
const struct HksBlob *srcData, struct HksBlob *hash, uint32_t performTimes)
{
int32_t ret;
uint32_t oriHashSize = 0;
if (hash != NULL) {
oriHashSize = hash->size;
}
for (uint32_t i = 0; i < performTimes; ++i) {
if (hash != NULL) {
(void)memset_s(hash->data, oriHashSize, 0, oriHashSize);
hash->size = oriHashSize;
}
ret = HksHash(paramSet, srcData, hash);
if (ret != HKS_SUCCESS) {
return ret;
}
}
return HKS_SUCCESS;
}
int32_t HksBnExpModRun(struct HksBlob *x, const struct HksBlob *a,
const struct HksBlob *e, const struct HksBlob *n, uint32_t performTimes)
{
int32_t ret;
uint32_t oriXSize = 0;
if (x != NULL) {
oriXSize = x->size;
}
for (uint32_t i = 0; i < performTimes; ++i) {
if (x != NULL) {
(void)memset_s(x->data, oriXSize, 0, oriXSize);
x->size = oriXSize;
}
ret = HksBnExpMod(x, a, e, n);
if (ret != HKS_SUCCESS) {
return ret;
}
}
return HKS_SUCCESS;
}
此差异已折叠。
此差异已折叠。
/*
* 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 "hks_test_curve25519.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_log.h"
#include "hks_type.h"
#define TEST_ALIAS_ED25519 "test_ed25519"
#define TEST_PLAIN_TEST_ED25519 "This is a plain text! Hello world and thanks for watching ED25519~"
#define TEST_CURVE_256 256
#define TEST_CURVE_512 512
static uint8_t g_buffer[TEST_CURVE_256];
static uint32_t g_bufferSize = TEST_CURVE_256;
static uint8_t g_pubKey[TEST_CURVE_512] = {0};
static uint32_t g_pubKeyLen = TEST_CURVE_512;
int32_t TestGenerateEd25519Key(struct HksBlob alias)
{
HKS_TEST_LOG_I("Test_GenerateEd25519!\n");
struct HksParamSet *paramSet = NULL;
int32_t ret = HksInitParamSet(&paramSet);
HKS_TEST_ASSERT(ret == 0);
struct HksParam algParam = {0};
algParam.tag = HKS_TAG_ALGORITHM;
algParam.uint32Param = HKS_ALG_ED25519;
ret = HksAddParams(paramSet, &algParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam keySizeParam = {0};
keySizeParam.tag = HKS_TAG_KEY_SIZE;
keySizeParam.uint32Param = TEST_CURVE_256;
ret = HksAddParams(paramSet, &keySizeParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam purposeParam = {0};
purposeParam.tag = HKS_TAG_PURPOSE;
purposeParam.uint32Param = HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY;
ret = HksAddParams(paramSet, &purposeParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam digestParam = {0};
digestParam.tag = HKS_TAG_DIGEST;
digestParam.uint32Param = HKS_DIGEST_SHA512;
ret = HksAddParams(paramSet, &digestParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam paddingParam = {0};
paddingParam.tag = HKS_TAG_PADDING;
paddingParam.uint32Param = HKS_PADDING_NONE;
ret = HksAddParams(paramSet, &paddingParam, 1);
HKS_TEST_ASSERT(ret == 0);
ret = HksBuildParamSet(&paramSet);
HKS_TEST_ASSERT(ret == 0);
ret = HksGenerateKey(&alias, paramSet, NULL);
HKS_TEST_ASSERT(ret == 0);
HksFreeParamSet(&paramSet);
return ret;
}
static int32_t TestSignEd25519(struct HksBlob alias)
{
struct HksBlob msg = {strlen(TEST_PLAIN_TEST_ED25519), (uint8_t *)TEST_PLAIN_TEST_ED25519};
struct HksParamSet *paramSet = NULL;
int32_t ret = HksInitParamSet(&paramSet);
HKS_TEST_ASSERT(ret == 0);
struct HksParam algParam = {0};
algParam.tag = HKS_TAG_ALGORITHM;
algParam.uint32Param = HKS_ALG_ED25519;
ret = HksAddParams(paramSet, &algParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam purposeParam = {0};
purposeParam.tag = HKS_TAG_PURPOSE;
purposeParam.uint32Param = HKS_KEY_PURPOSE_SIGN;
ret = HksAddParams(paramSet, &purposeParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam digestParam = {0};
digestParam.tag = HKS_TAG_DIGEST;
digestParam.uint32Param = HKS_DIGEST_SHA512;
ret = HksAddParams(paramSet, &digestParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam paddingParam = {0};
paddingParam.tag = HKS_TAG_PADDING;
paddingParam.uint32Param = HKS_PADDING_NONE;
ret = HksAddParams(paramSet, &paddingParam, 1);
HKS_TEST_ASSERT(ret == 0);
ret = HksBuildParamSet(&paramSet);
HKS_TEST_ASSERT(ret == 0);
struct HksBlob signature = { TEST_CURVE_256, g_buffer };
ret = HksSign(&alias, paramSet, &msg, &signature);
HKS_TEST_ASSERT(ret == 0);
g_bufferSize = signature.size;
HKS_TEST_LOG_I("TestSignEd25519 signature size is %u", signature.size);
HksFreeParamSet(&paramSet);
return ret;
}
static int32_t TestVerifyEd25519(struct HksBlob alias)
{
struct HksBlob msg = {strlen(TEST_PLAIN_TEST_ED25519), (uint8_t *)TEST_PLAIN_TEST_ED25519};
HKS_TEST_LOG_I("TestVerifyEd25519!\n");
struct HksParamSet *paramSet = NULL;
int32_t ret = HksInitParamSet(&paramSet);
HKS_TEST_ASSERT(ret == 0);
struct HksParam algParam = {0};
algParam.tag = HKS_TAG_ALGORITHM;
algParam.uint32Param = HKS_ALG_ED25519;
ret = HksAddParams(paramSet, &algParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam purposeParam = {0};
purposeParam.tag = HKS_TAG_PURPOSE;
purposeParam.uint32Param = HKS_KEY_PURPOSE_VERIFY;
ret = HksAddParams(paramSet, &purposeParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam digestParam = {0};
digestParam.tag = HKS_TAG_DIGEST;
digestParam.uint32Param = HKS_DIGEST_SHA512;
ret = HksAddParams(paramSet, &digestParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam paddingParam = {0};
paddingParam.tag = HKS_TAG_PADDING;
paddingParam.uint32Param = HKS_PADDING_NONE;
ret = HksAddParams(paramSet, &paddingParam, 1);
HKS_TEST_ASSERT(ret == 0);
ret = HksBuildParamSet(&paramSet);
HKS_TEST_ASSERT(ret == 0);
struct HksBlob signature = { g_bufferSize, g_buffer };
ret = HksVerify(&alias, paramSet, &msg, &signature);
HKS_TEST_ASSERT(ret == 0);
HksFreeParamSet(&paramSet);
return ret;
}
int32_t TestImportEd25519(struct HksBlob alias, struct HksBlob *pubKeyInfo)
{
HKS_TEST_LOG_I("TestImportEd25519!\n");
struct HksParamSet *paramSet = NULL;
int32_t ret = HksInitParamSet(&paramSet);
HKS_TEST_ASSERT(ret == 0);
struct HksParam algParam = {0};
algParam.tag = HKS_TAG_ALGORITHM;
algParam.uint32Param = HKS_ALG_ED25519;
ret = HksAddParams(paramSet, &algParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam keySizeParam = {0};
keySizeParam.tag = HKS_TAG_KEY_SIZE;
keySizeParam.uint32Param = TEST_CURVE_256;
ret = HksAddParams(paramSet, &keySizeParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam purposeParam = {0};
purposeParam.tag = HKS_TAG_PURPOSE;
purposeParam.uint32Param = HKS_KEY_PURPOSE_VERIFY;
ret = HksAddParams(paramSet, &purposeParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam digestParam = {0};
digestParam.tag = HKS_TAG_DIGEST;
digestParam.uint32Param = HKS_DIGEST_SHA512;
ret = HksAddParams(paramSet, &digestParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam paddingParam = {0};
paddingParam.tag = HKS_TAG_PADDING;
paddingParam.uint32Param = HKS_PADDING_NONE;
ret = HksAddParams(paramSet, &paddingParam, 1);
HKS_TEST_ASSERT(ret == 0);
ret = HksBuildParamSet(&paramSet);
HKS_TEST_ASSERT(ret == 0);
ret = HksImportKey(&alias, paramSet, pubKeyInfo);
HKS_TEST_ASSERT(ret == 0);
HksFreeParamSet(&paramSet);
return ret;
}
static int32_t TestExportImportEd25519SignVerify(struct HksBlob alias)
{
uint8_t pubKey[32] = {0};
uint32_t pubKeyLen = 32;
struct HksBlob pubKeyInfo = { pubKeyLen, pubKey };
int32_t ret = TestGenerateEd25519Key(alias);
HKS_TEST_ASSERT(ret == 0);
ret = HksExportPublicKey(&alias, NULL, &pubKeyInfo);
HKS_TEST_ASSERT(ret == 0);
ret = TestSignEd25519(alias);
HKS_TEST_ASSERT(ret == 0);
ret = HksDeleteKey(&alias, NULL);
HKS_TEST_ASSERT(ret == 0);
struct HksBlob newAlias = { strlen("test_ed25519_2"), (uint8_t *)"test_ed25519_2" };
ret = TestImportEd25519(newAlias, &pubKeyInfo);
HKS_TEST_ASSERT(ret == 0);
ret = TestVerifyEd25519(newAlias);
HKS_TEST_ASSERT(ret == 0);
ret = HksDeleteKey(&newAlias, NULL);
HKS_TEST_ASSERT(ret == 0);
return ret;
}
int32_t TestCurve25519All()
{
struct HksBlob ed25519Alias = { strlen(TEST_ALIAS_ED25519), (uint8_t *)TEST_ALIAS_ED25519 };
int32_t ret = TestGenerateEd25519Key(ed25519Alias);
HKS_TEST_ASSERT(ret == 0);
ret = TestSignEd25519(ed25519Alias);
HKS_TEST_ASSERT(ret == 0);
ret = TestVerifyEd25519(ed25519Alias);
HKS_TEST_ASSERT(ret == 0);
ret = HksDeleteKey(&ed25519Alias, NULL);
HKS_TEST_ASSERT(ret == 0);
ret = TestExportImportEd25519SignVerify(ed25519Alias);
HKS_TEST_ASSERT(ret == 0);
return ret;
}
static int32_t BuildTeeSignParamSet(struct HksParamSet **paramSet)
{
int32_t ret = HksInitParamSet(paramSet);
HKS_TEST_ASSERT(ret == 0);
struct HksParam algParam = {0};
algParam.tag = HKS_TAG_ALGORITHM;
algParam.uint32Param = HKS_ALG_ED25519;
ret = HksAddParams(*paramSet, &algParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam purposeParam = {0};
purposeParam.tag = HKS_TAG_PURPOSE;
purposeParam.uint32Param = HKS_KEY_PURPOSE_SIGN;
ret = HksAddParams(*paramSet, &purposeParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam digestParam = {0};
digestParam.tag = HKS_TAG_DIGEST;
digestParam.uint32Param = HKS_DIGEST_SHA512;
ret = HksAddParams(*paramSet, &digestParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam paddingParam = {0};
paddingParam.tag = HKS_TAG_PADDING;
paddingParam.uint32Param = HKS_PADDING_NONE;
ret = HksAddParams(*paramSet, &paddingParam, 1);
HKS_TEST_ASSERT(ret == 0);
ret = HksBuildParamSet(paramSet);
HKS_TEST_ASSERT(ret == 0);
return ret;
}
static int32_t BuildLocalVerifyParamSet(struct HksParamSet **paramSet)
{
int32_t ret = HksInitParamSet(paramSet);
HKS_TEST_ASSERT(ret == 0);
struct HksParam algParam = {0};
algParam.tag = HKS_TAG_ALGORITHM;
algParam.uint32Param = HKS_ALG_ED25519;
ret = HksAddParams(*paramSet, &algParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam isKeyAlias = {0};
isKeyAlias.tag = HKS_TAG_IS_KEY_ALIAS;
isKeyAlias.boolParam = false;
ret = HksAddParams(*paramSet, &isKeyAlias, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam keySizeParam = {0};
keySizeParam.tag = HKS_TAG_KEY_SIZE;
keySizeParam.uint32Param = TEST_CURVE_256;
ret = HksAddParams(*paramSet, &keySizeParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam purposeParam = {0};
purposeParam.tag = HKS_TAG_PURPOSE;
purposeParam.uint32Param = HKS_KEY_PURPOSE_VERIFY;
ret = HksAddParams(*paramSet, &purposeParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam digestParam = {0};
digestParam.tag = HKS_TAG_DIGEST;
digestParam.uint32Param = HKS_DIGEST_SHA512;
ret = HksAddParams(*paramSet, &digestParam, 1);
HKS_TEST_ASSERT(ret == 0);
ret = HksBuildParamSet(paramSet);
HKS_TEST_ASSERT(ret == 0);
return ret;
}
int32_t TestEd25519SignTeeVerifyLocal()
{
HKS_TEST_LOG_D("TestEd25519SignTeeVerifyLocal enter!");
struct HksBlob ed25519Alias = { strlen(TEST_ALIAS_ED25519), (uint8_t *)TEST_ALIAS_ED25519 };
struct HksBlob msg = {strlen(TEST_PLAIN_TEST_ED25519), (uint8_t *)TEST_PLAIN_TEST_ED25519};
struct HksBlob signature = { TEST_CURVE_256, g_buffer };
struct HksParamSet *paramSetSign = NULL;
struct HksParamSet *paramSetVerify = NULL;
struct HksBlob pubKeyInfo = { g_pubKeyLen, g_pubKey };
int32_t ret = TestGenerateEd25519Key(ed25519Alias);
HKS_TEST_ASSERT(ret == 0);
ret = HksExportPublicKey(&ed25519Alias, NULL, &pubKeyInfo);
HKS_TEST_ASSERT(ret == 0);
HKS_TEST_LOG_I("HksExportPublicKey puKey size is %u", pubKeyInfo.size);
ret = BuildTeeSignParamSet(&paramSetSign);
HKS_TEST_ASSERT(ret == 0);
ret = HksSign(&ed25519Alias, paramSetSign, &msg, &signature);
HKS_TEST_ASSERT(ret == 0);
HKS_TEST_LOG_I("Test_Ed25519_Sign_TEE signature size is %u", signature.size);
ret = BuildLocalVerifyParamSet(&paramSetVerify);
HKS_TEST_ASSERT(ret == 0);
ret = HksVerify(&pubKeyInfo, paramSetVerify, &msg, &signature);
HKS_TEST_ASSERT(ret == 0);
HKS_TEST_LOG_I("Test_Ed25519_Verify_Local Success");
ret = HksDeleteKey(&ed25519Alias, NULL);
HKS_TEST_ASSERT(ret == 0);
HksFreeParamSet(&paramSetSign);
HksFreeParamSet(&paramSetVerify);
HKS_TEST_LOG_D("TestEd25519SignTeeVerifyLocal End!\n");
return ret;
}
static int32_t TestSignEd25519Wrong(struct HksBlob alias)
{
struct HksBlob msg = {strlen(TEST_PLAIN_TEST_ED25519), (uint8_t *)TEST_PLAIN_TEST_ED25519};
struct HksParamSet *paramSet = NULL;
int32_t ret = HksInitParamSet(&paramSet);
HKS_TEST_ASSERT(ret == 0);
struct HksParam algParam = {0};
algParam.tag = HKS_TAG_ALGORITHM;
algParam.uint32Param = HKS_ALG_ED25519;
ret = HksAddParams(paramSet, &algParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam purposeParam = {0};
purposeParam.tag = HKS_TAG_PURPOSE;
purposeParam.uint32Param = HKS_KEY_PURPOSE_VERIFY;
ret = HksAddParams(paramSet, &purposeParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam digestParam = {0};
digestParam.tag = HKS_TAG_DIGEST;
digestParam.uint32Param = HKS_DIGEST_SHA256;
ret = HksAddParams(paramSet, &digestParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam paddingParam = {0};
paddingParam.tag = HKS_TAG_PADDING;
paddingParam.uint32Param = HKS_PADDING_PKCS5;
ret = HksAddParams(paramSet, &paddingParam, 1);
HKS_TEST_ASSERT(ret == 0);
ret = HksBuildParamSet(&paramSet);
HKS_TEST_ASSERT(ret == 0);
struct HksBlob signature = { TEST_CURVE_256, g_buffer };
ret = HksSign(&alias, paramSet, &msg, &signature);
HKS_TEST_ASSERT(ret != 0);
g_bufferSize = signature.size;
HKS_TEST_LOG_I("TestSignEd25519 signature size is %u", signature.size);
HksFreeParamSet(&paramSet);
return ret;
}
int32_t TestCurve25519SignWrong()
{
struct HksBlob ed25519Alias = { strlen(TEST_ALIAS_ED25519), (uint8_t *)TEST_ALIAS_ED25519 };
int32_t ret = TestGenerateEd25519Key(ed25519Alias);
HKS_TEST_ASSERT(ret == 0);
ret = TestSignEd25519Wrong(ed25519Alias);
HKS_TEST_ASSERT(ret != 0);
int32_t retTwo = HksDeleteKey(&ed25519Alias, NULL);
HKS_TEST_ASSERT(retTwo == 0);
if ((ret != 0) && (retTwo == 0)) {
return 0;
}
return 1;
}
static int32_t TestVerifyEd25519Wrong(struct HksBlob alias)
{
struct HksBlob msg = {strlen(TEST_PLAIN_TEST_ED25519), (uint8_t *)TEST_PLAIN_TEST_ED25519};
HKS_TEST_LOG_I("TestVerifyEd25519!\n");
struct HksParamSet *paramSet = NULL;
int32_t ret = HksInitParamSet(&paramSet);
HKS_TEST_ASSERT(ret == 0);
struct HksParam algParam = {0};
algParam.tag = HKS_TAG_ALGORITHM;
algParam.uint32Param = HKS_ALG_ED25519;
ret = HksAddParams(paramSet, &algParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam purposeParam = {0};
purposeParam.tag = HKS_TAG_PURPOSE;
purposeParam.uint32Param = HKS_KEY_PURPOSE_SIGN;
ret = HksAddParams(paramSet, &purposeParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam digestParam = {0};
digestParam.tag = HKS_TAG_DIGEST;
digestParam.uint32Param = HKS_DIGEST_SHA256;
ret = HksAddParams(paramSet, &digestParam, 1);
HKS_TEST_ASSERT(ret == 0);
struct HksParam paddingParam = {0};
paddingParam.tag = HKS_TAG_PADDING;
paddingParam.uint32Param = HKS_PADDING_PKCS5;
ret = HksAddParams(paramSet, &paddingParam, 1);
HKS_TEST_ASSERT(ret == 0);
ret = HksBuildParamSet(&paramSet);
HKS_TEST_ASSERT(ret == 0);
struct HksBlob signature = { g_bufferSize, g_buffer };
ret = HksVerify(&alias, paramSet, &msg, &signature);
HKS_TEST_ASSERT(ret != 0);
HksFreeParamSet(&paramSet);
return ret;
}
int32_t TestCurve25519verifyWrong()
{
struct HksBlob ed25519Alias = { strlen(TEST_ALIAS_ED25519), (uint8_t *)TEST_ALIAS_ED25519 };
int32_t ret = TestGenerateEd25519Key(ed25519Alias);
HKS_TEST_ASSERT(ret == 0);
ret = TestSignEd25519(ed25519Alias);
HKS_TEST_ASSERT(ret == 0);
ret = TestVerifyEd25519Wrong(ed25519Alias);
HKS_TEST_ASSERT(ret != 0);
int32_t retTwo = HksDeleteKey(&ed25519Alias, NULL);
HKS_TEST_ASSERT(retTwo == 0);
if ((ret != 0) && (retTwo == 0)) {
return 0;
}
return 1;
}
\ 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 "hks_test_file_operator.h"
#ifndef __LITEOS_M__
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdint.h>
#include <sys/stat.h>
#include <unistd.h>
/* use product definitions temporarily */
#define DEFAULT_FILE_PERMISSION 0666
#else
#include <utils_file.h>
#endif /* _STORAGE_LITE_ */
#include "hks_param.h"
#include "hks_test_log.h"
#include "hks_test_mem.h"
#include "hks_type.h"
#include "securec.h"
#define HKS_MAX_FILE_NAME_LEN 512
static int32_t GetFileName(const char *path, const char *fileName, char *fullFileName, uint32_t fullFileNameLen)
{
if (path != NULL) {
if (strncpy_s(fullFileName, fullFileNameLen, path, strlen(path)) != EOK) {
return HKS_ERROR_INTERNAL_ERROR;
}
if (path[strlen(path) - 1] != '/') {
if (strncat_s(fullFileName, fullFileNameLen, "/", strlen("/")) != EOK) {
return HKS_ERROR_INTERNAL_ERROR;
}
}
if (strncat_s(fullFileName, fullFileNameLen, fileName, strlen(fileName)) != EOK) {
return HKS_ERROR_INTERNAL_ERROR;
}
} else {
if (strncpy_s(fullFileName, fullFileNameLen, fileName, strlen(fileName)) != EOK) {
return HKS_ERROR_INTERNAL_ERROR;
}
}
return HKS_SUCCESS;
}
static int32_t GetFullFileName(const char *path, const char *fileName, char **fullFileName)
{
uint32_t nameLen = HKS_MAX_FILE_NAME_LEN;
char *tmpFileName = (char *)HksTestMalloc(nameLen);
if (tmpFileName == NULL) {
return HKS_ERROR_MALLOC_FAIL;
}
(void)memset_s(tmpFileName, nameLen, 0, nameLen);
int32_t ret = GetFileName(path, fileName, tmpFileName, nameLen);
if (ret != HKS_SUCCESS) {
HKS_TEST_LOG_E("get full fileName failed");
HksTestFree(tmpFileName);
return ret;
}
*fullFileName = tmpFileName;
return HKS_SUCCESS;
}
#ifndef __LITEOS_M__
static int32_t IsFileExist(const char *fileName)
{
if (access(fileName, F_OK) != 0) {
return HKS_ERROR_NOT_EXIST;
}
return HKS_SUCCESS;
}
static uint32_t FileRead(const char *fileName, uint32_t offset, uint8_t *buf, uint32_t len)
{
(void)offset;
if (IsFileExist(fileName) != HKS_SUCCESS) {
return 0;
}
char filePath[PATH_MAX + 1] = {0};
(void)realpath(fileName, filePath);
if (strstr(filePath, "../") != NULL) {
HKS_TEST_LOG_E("invalid filePath, path %s", filePath);
return 0;
}
FILE *fp = fopen(filePath, "rb");
if (fp == NULL) {
HKS_TEST_LOG_E("failed to open file");
return 0;
}
uint32_t size = fread(buf, 1, len, fp);
if (fclose(fp) < 0) {
HKS_TEST_LOG_E("failed to close file");
return 0;
}
return size;
}
static uint32_t FileSize(const char *fileName)
{
if (IsFileExist(fileName) != HKS_SUCCESS) {
return 0;
}
struct stat fileStat;
(void)memset_s(&fileStat, sizeof(fileStat), 0, sizeof(fileStat));
if (stat(fileName, &fileStat) != 0) {
HKS_TEST_LOG_E("file stat fail.");
return 0;
}
return fileStat.st_size;
}
static int32_t FileWrite(const char *fileName, uint32_t offset, const uint8_t *buf, uint32_t len)
{
(void)offset;
char filePath[PATH_MAX + 1] = {0};
if (memcpy_s(filePath, sizeof(filePath) - 1, fileName, strlen(fileName)) != EOK) {
return HKS_ERROR_BAD_STATE;
}
(void)realpath(fileName, filePath);
if (strstr(filePath, "../") != NULL) {
HKS_TEST_LOG_E("invalid filePath, path %s", filePath);
return HKS_ERROR_INVALID_KEY_FILE;
}
/* caller function ensures that the folder exists */
FILE *fp = fopen(filePath, "wb+");
if (fp == NULL) {
HKS_TEST_LOG_E("open file fail");
return HKS_ERROR_OPEN_FILE_FAIL;
}
if (chmod(filePath, S_IRUSR | S_IWUSR) < 0) {
HKS_TEST_LOG_E("chmod file fail.");
fclose(fp);
return HKS_ERROR_OPEN_FILE_FAIL;
}
uint32_t size = fwrite(buf, 1, len, fp);
if (size != len) {
HKS_TEST_LOG_E("write file size fail.");
fclose(fp);
return HKS_ERROR_WRITE_FILE_FAIL;
}
if (fclose(fp) < 0) {
HKS_TEST_LOG_E("failed to close file");
return HKS_ERROR_CLOSE_FILE_FAIL;
}
return HKS_SUCCESS;
}
int32_t HksIsFileExist(const char *path, const char *fileName)
{
if (fileName == NULL) {
return HKS_ERROR_NULL_POINTER;
}
char *fullFileName = NULL;
int32_t ret = GetFullFileName(path, fileName, &fullFileName);
if (ret != HKS_SUCCESS) {
return ret;
}
ret = IsFileExist(fullFileName);
HksTestFree(fullFileName);
return ret;
}
#else
static uint32_t FileRead(const char *fileName, uint32_t offset, uint8_t *buf, uint32_t len)
{
/* now offset is 0, but we maybe extend hi1131 file interfaces in the future */
if (offset != 0) {
return HKS_ERROR_INVALID_ARGUMENT;
}
unsigned int fileSize;
int32_t ret = UtilsFileStat(fileName, &fileSize);
if (ret < 0) {
HKS_TEST_LOG_E("stat file failed, errno = 0x%x", ret);
return 0;
}
if (len > fileSize) {
HKS_TEST_LOG_E("read data over file size!\n, file size = %d\n, buf len = %d\n", fileSize, len);
return 0;
}
int fd = UtilsFileOpen(fileName, O_RDONLY_FS, 0);
if (fd < 0) {
HKS_TEST_LOG_E("failed to open file, errno = 0x%x", fd);
return 0;
}
ret = UtilsFileRead(fd, buf, len);
UtilsFileClose(fd);
if (ret < 0) {
HKS_TEST_LOG_E("failed to read file, errno = 0x%x", ret);
return 0;
}
return len;
}
static int32_t FileWrite(const char *fileName, uint32_t offset, const uint8_t *buf, uint32_t len)
{
/* now offset is 0, but we maybe extend hi1131 file interfaces in the future */
if (offset != 0) {
return HKS_ERROR_INVALID_ARGUMENT;
}
int fd = UtilsFileOpen(fileName, O_CREAT_FS | O_TRUNC_FS | O_RDWR_FS, 0);
if (fd < 0) {
HKS_TEST_LOG_E("failed to open key file, errno = 0x%x\n", fd);
return HKS_ERROR_OPEN_FILE_FAIL;
}
int32_t ret = UtilsFileWrite(fd, buf, len);
if (ret < 0) {
HKS_TEST_LOG_E("failed to write key file, errno = 0x%x\n", ret);
ret = HKS_ERROR_WRITE_FILE_FAIL;
}
ret = UtilsFileClose(fd);
if (ret < 0) {
HKS_TEST_LOG_E("failed to close file, errno = 0x%x\n", ret);
ret = HKS_ERROR_CLOSE_FILE_FAIL;
}
return ret;
}
static uint32_t FileSize(const char *fileName)
{
unsigned int fileSize;
int32_t ret = UtilsFileStat(fileName, &fileSize);
if (ret < 0) {
HKS_TEST_LOG_E("stat file failed, errno = 0x%x", ret);
return 0;
}
return fileSize;
}
int32_t HksTestFileRemove(const char *path, const char *fileName)
{
char *fullFileName = NULL;
int32_t ret = GetFullFileName(path, fileName, &fullFileName);
if (ret != HKS_SUCCESS) {
return 0;
}
return UtilsFileDelete(fullFileName);
}
#endif
uint32_t HksTestFileRead(const char *path, const char *fileName, uint32_t offset, uint8_t *buf, uint32_t len)
{
if ((fileName == NULL) || (buf == NULL) || (len == 0)) {
return 0;
}
char *fullFileName = NULL;
int32_t ret = GetFullFileName(path, fileName, &fullFileName);
if (ret != HKS_SUCCESS) {
return 0;
}
uint32_t size = FileRead(fullFileName, offset, buf, len);
HksTestFree(fullFileName);
return size;
}
int32_t HksTestFileWrite(const char *path, const char *fileName, uint32_t offset, const uint8_t *buf, uint32_t len)
{
if ((fileName == NULL) || (buf == NULL) || (len == 0)) {
return HKS_ERROR_INVALID_ARGUMENT;
}
char *fullFileName = NULL;
int32_t ret = GetFullFileName(path, fileName, &fullFileName);
if (ret != HKS_SUCCESS) {
return ret;
}
ret = FileWrite(fullFileName, offset, buf, len);
HksTestFree(fullFileName);
return ret;
}
uint32_t HksTestFileSize(const char *path, const char *fileName)
{
if (fileName == NULL) {
return 0;
}
char *fullFileName = NULL;
int32_t ret = GetFullFileName(path, fileName, &fullFileName);
if (ret != HKS_SUCCESS) {
return 0;
}
uint32_t size = FileSize(fullFileName);
HksTestFree(fullFileName);
return size;
}
/*
* 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.
*/
#include "hks_test_log.h"
#include "securec.h"
#include "stdlib.h"
#include "time.h"
#define MAX_LOG_BUFF_LEN 512
#define WAIT_TO_LOG_DONE 100000
void HksTestLog(uint32_t logLevel, const char *funcName, int32_t lineNo, const char *format, ...)
{
char buf[MAX_LOG_BUFF_LEN] = { 0 };
va_list ap;
va_start(ap, format);
int32_t ret = vsnprintf_s(buf, MAX_LOG_BUFF_LEN, MAX_LOG_BUFF_LEN - 1, format, ap);
va_end(ap);
if (ret < 0) {
printf("hks log concatenate error.");
return;
}
switch (logLevel) {
case HKS_LOG_LEVEL_I:
printf("[INFO] %s [%d]: %s\n", funcName, lineNo, buf);
break;
case HKS_LOG_LEVEL_E:
printf("[ERROR] %s [%d]: %s\n", funcName, lineNo, buf);
break;
case HKS_LOG_LEVEL_W:
printf("[WARNING] %s [%d]: %s\n", funcName, lineNo, buf);
break;
case HKS_LOG_LEVEL_D:
printf("[DEBUG] %s [%d]: %s\n", funcName, lineNo, buf);
break;
default:
return;
}
usleep(WAIT_TO_LOG_DONE);
}
void HksAssertLog(bool test)
{
if (!(test)) {
HKS_TEST_LOG_E("[ASSERT] :fail\n");
}
}
/*
* 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 "hks_test_mem.h"
#include <stdint.h>
#include <stdio.h>
void *HksTestMalloc(size_t size)
{
return malloc(size);
}
void HksTestFree(void *ptr)
{
free(ptr);
}
/*
* 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.
*/
#ifndef HUKS_AES_TEST_H
#define HUKS_AES_TEST_H
int HksAesTest001(void);
int HksAesTest002(void);
int HksAesTest003(void);
#endif
/*
* 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.
*/
#ifndef HUKS_AGREEMENT_TEST_H
#define HUKS_AGREEMENT_TEST_H
int HksAgreementTest001(void);
#endif
/*
* 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.
*/
#ifndef HUKS_BN_EXP_MOD_TEST_H
#define HUKS_BN_EXP_MOD_TEST_H
int HksBnExpModTest001(void);
#endif
/*
* 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.
*/
#ifndef HUKS_CIPHER_TEST_H
#define HUKS_CIPHER_TEST_H
int HksCipherTest001(void);
int HksCipherTest002(void);
int HksCipherTest003(void);
int HksCipherTest004(void);
int HksCipherTest005(void);
int HksCipherTest006(void);
int HksCipherTest007(void);
int HksCipherTest008(void);
int HksCipherTest009(void);
int HksCipherTest010(void);
int HksCipherTest011(void);
int HksCipherTest012(void);
#endif
/*
* 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.
*/
#ifndef HUKS_CURVE25519_TEST_H
#define HUKS_CURVE25519_TEST_H
int HksCurve25519Test001(void);
int HksCurve25519Test002(void);
int HksCurve25519Test003(void);
int HksCurve25519Test004(void);
#endif
\ 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.
*/
#ifndef HUKS_DELETE_TEST_H
#define HUKS_DELETE_TEST_H
int HksDeleteTest001(void);
#endif
/*
* 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.
*/
#ifndef HUKS_DERIVE_TEST_H
#define HUKS_DERIVE_TEST_H
int HksDeriveTest001(void);
int HksDeriveTest002(void);
#endif
/*
* 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.
*/
#ifndef HUKS_EXIST_TEST_H
#define HUKS_EXIST_TEST_H
int HksExistTest001(void);
#endif
/*
* 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.
*/
#ifndef HUKS_GENERATE_KEY_TEST_H
#define HUKS_GENERATE_KEY_TEST_H
int HksGenerateKeyTest001(void);
#endif
/*
* 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.
*/
#ifndef HUKS_GENERATE_RANDOM_TEST_H
#define HUKS_GENERATE_RANDOM_TEST_H
int HksGenerateRandomTest001(void);
#endif
/*
* 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.
*/
#ifndef HUKS_HASH_TEST_H
#define HUKS_HASH_TEST_H
int HksHashTest001(void);
#endif
/*
* 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.
*/
#ifndef HUKS_MAC_TEST_H
#define HUKS_MAC_TEST_H
int HksMacTest001(void);
int HksMacTest002(void);
#endif
/*
* 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.
*/
#ifndef HUKS_MODIFY_KEY_TEST_H
#define HUKS_MODIFY_KEY_TEST_H
int HksModifyKeyTest001(void);
#endif
/*
* 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.
*/
#ifndef HUKS_OTHERS_TEST_H
#define HUKS_OTHERS_TEST_H
int HksOthersTest001(void);
int HksOthersTest002(void);
int HksOthersTest003(void);
int HksOthersTest004(void);
int HksOthersTest005(void);
int HksOthersTest006(void);
int HksOthersTest007(void);
int HksOthersTest008(void);
#endif
/*
* 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.
*/
#ifndef HUKS_SAFE_CIPHER_KEY_TEST_H
#define HUKS_SAFE_CIPHER_KEY_TEST_H
int HksSafeCipherKeyTest001(void);
#endif
/*
* 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.
*/
#ifndef HUKS_SAFE_COMPARE_KEY_TEST_H
#define HUKS_SAFE_COMPARE_KEY_TEST_H
int HksSafeCompareKeyTest001(void);
#endif
/*
* 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.
*/
#ifndef HKS_TEST_AES_H
#define HKS_TEST_AES_H
#include "hks_type.h"
#include "securec.h"
#define TEST_ALIAS_AES "test_key_alias_aes"
#ifdef __cplusplus
extern "C" {
#endif
int32_t TestAes256ByAgree();
int32_t TestAes256ByAgree1();
int32_t TestAes256ByAgree2();
int32_t TestAes256ByLocal();
#ifdef __cplusplus
}
#endif
#endif /* HKS_TEST_AES_H */
/*
* 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.
*/
#ifndef HKS_TEST_API_PERFORMANCE_H
#define HKS_TEST_API_PERFORMANCE_H
#include "hks_type.h"
#include "securec.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t HksGenerateKeyRun(const struct HksBlob *keyAlias, const struct HksParamSet *paramSetIn,
struct HksParamSet *paramSetOut, uint32_t performTimes);
int32_t HksEncryptRun(const struct HksBlob *key, const struct HksParamSet *paramSet,
const struct HksBlob *plainText, struct HksBlob *cipherText, uint32_t performTimes);
int32_t HksDecryptRun(const struct HksBlob *key, const struct HksParamSet *paramSet,
const struct HksBlob *cipherText, struct HksBlob *plainText, uint32_t performTimes);
int32_t HksMacRun(const struct HksBlob *key, const struct HksParamSet *paramSet,
const struct HksBlob *srcData, struct HksBlob *mac, uint32_t performTimes);
int32_t HksDeriveKeyRun(const struct HksParamSet *paramSet, const struct HksBlob *masterKey,
struct HksBlob *derivedKey, uint32_t performTimes);
int32_t HksDeleteKeyRun(const struct HksBlob *keyAlias, uint32_t performTimes);
int32_t HksKeyExistRun(const struct HksBlob *keyAlias, uint32_t performTimes);
int32_t HksGenerateRandomRun(struct HksBlob *random, uint32_t performTimes);
int32_t HksAgreeKeyRun(const struct HksParamSet *paramSet, const struct HksBlob *privateKey,
const struct HksBlob *peerPublicKey, struct HksBlob *agreedKey, uint32_t performTimes);
int32_t HksHashRun(const struct HksParamSet *paramSet,
const struct HksBlob *srcData, struct HksBlob *hash, uint32_t performTimes);
int32_t HksBnExpModRun(struct HksBlob *x, const struct HksBlob *a,
const struct HksBlob *e, const struct HksBlob *n, uint32_t performTimes);
#ifdef __cplusplus
}
#endif
#endif /* HKS_TEST_API_PERFORMANCE_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.
*/
#ifndef HKS_TEST_CIPHER_H
#define HKS_TEST_CIPHER_H
#include "hks_type.h"
struct CipherEncryptStructure {
const struct HksBlob *keyAlias;
const struct HksTestCipherParamsParamSet *cipherParms;
struct HksBlob *plainData;
struct HksBlob *cipherData;
struct HksBlob **ivData;
struct HksBlob **nonceData;
struct HksBlob **aadData;
uint32_t performTimes;
};
struct OnlyDecryptStructure {
struct HksBlob *keyAlias;
const struct HksTestCipherParamsParamSet *cipherParms;
struct HksBlob *cipherData;
struct HksBlob *decryptedData;
struct HksBlob **ivData;
struct HksBlob **nonceData;
struct HksBlob **aadData;
uint32_t performTimes;
};
struct CipherDecryptStructure {
struct HksBlob *keyAlias;
const struct HksTestCipherParams *cipherParms;
struct HksBlob *cipherData;
struct HksBlob **decryptedData;
struct HksBlob *ivData;
struct HksBlob *nonceData;
struct HksBlob *aadData;
uint32_t performTimes;
};
#ifdef __cplusplus
extern "C" {
#endif
int32_t BaseTestCipher(uint32_t times, uint32_t index, uint32_t performTimes);
int32_t BaseTestEncrypt(uint32_t times, uint32_t index, uint32_t performTimes);
int32_t BaseTestDecrypt(uint32_t times, uint32_t index, uint32_t performTimes);
#ifdef __cplusplus
}
#endif
#endif /* HKS_TEST_COMMON_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.
*/
#ifndef HKS_TEST_COMMON_H
#define HKS_TEST_COMMON_H
#include "hks_type.h"
#include "securec.h"
#define GOTO_ERROR_IF_FAIL(ret, err) \
if ((ret) != 0) { \
goto err; \
}
#define GOTO_ERROR_IF_SUCCESS(ret, err) \
if ((ret) == 0) { \
goto err; \
}
#define HKS_SLICE_MAX_LEN 64 * 1024
#define DEFAULT_TEST_CASE_ID 0xFFFFFFFF
#define DEFAULT_EXECUTION_TIMES 0xFFFFFFFF
#define DEFAULT_PERFORM_TIMES 0xFFFFFFFF
#define MAX_ARGS_LEN 20
#define DEFAULT_KEY_ALIAS_SIZE 64
#define DEFAULT_SLICE_SIZE (2 * 128 + 1)
#define DEFAULT_PARAM_SET_OUT_SIZE 4096
#define HKS_MAX_RANDOM_LEN 1024
#define MAX_OUT_BLOB_SIZE (5 * 1024 * 1024)
#define TEST_MAX_FILE_NAME_LEN 512
#define DEFAULT_LOCAL_KEY_SIZE 256
/* inputparams: struct HksBlob *blob */
struct HksTestBlobParams {
bool blobExist; /* blob null or not */
uint32_t blobSize; /* blob->size value */
bool blobDataExist; /* blob->data null or not */
uint32_t blobDataSize; /* blob->data malloc size */
};
/* inputparams: struct HksParamSet *paramSet */
struct HksTestGenKeyParamsParamSet {
bool paramSetExist; /* paramSet null or not */
bool setAlg;
uint32_t alg;
bool setKeySize;
uint32_t keySize;
bool setPurpose;
uint32_t purpose;
bool setDigest;
uint32_t digest;
bool setPadding;
uint32_t padding;
bool setBlockMode;
uint32_t mode;
bool setKeyStorageFlag;
uint32_t keyStorageFlag;
};
struct HksTestGenKeyParamsParamSetOut {
bool paramSetExist; /* paramSet null or not */
uint32_t paramSetSize;
};
enum HksTestCipherType {
HKS_TEST_CIPHER_TYPE_AES,
HKS_TEST_CIPHER_TYPE_RSA,
};
struct TestRsaCipherParamSet {
struct HksParamSet **outParamSet;
bool paramSetExist;
bool setAlg;
uint32_t alg;
bool setPurpose;
uint32_t purpose;
bool setDigest;
uint32_t digest;
bool setPadding;
uint32_t padding;
};
struct HksTestCipherParamsParamSet {
enum HksTestCipherType cipherType;
bool paramSetExist; /* paramSet null or not */
bool setAlg;
uint32_t alg;
bool setPurpose;
uint32_t purpose;
bool setDigest;
uint32_t digest;
bool setPadding;
uint32_t padding;
bool setBlockMode;
uint32_t mode;
bool setIv;
uint32_t ivSize;
bool setNonce;
uint32_t nonceSize;
bool setAad;
uint32_t aadSize;
bool setIsKeyAlias;
bool isKeyAlias;
};
struct HksTestMacParamSet {
bool paramSetExist; /* paramSet null or not */
bool setPurpose;
uint32_t purpose;
bool setDigest;
uint32_t digest;
};
struct HksTestDeriveParamSet {
bool paramSetExist; /* paramSet null or not */
bool setAlg;
uint32_t alg;
bool setPurpose;
uint32_t purpose;
bool setDigest;
uint32_t digest;
bool setIteration;
uint32_t iteration;
bool setSalt;
uint32_t saltSize;
bool setInfo;
uint32_t infoSize;
bool setIsKeyAlias;
bool isKeyAlias;
};
struct HksTestAgreeParamSet {
bool paramSetExist; /* paramSet null or not */
bool setAlg;
uint32_t alg;
bool setKeySize;
uint32_t keySize;
bool setIsKeyAlias;
bool isKeyAlias;
};
enum HksTestMacType {
HKS_TEST_MAC_TYPE_REE,
HKS_TEST_MAC_TYPE_TEE,
};
struct HksTestHashParamsParamSet {
bool paramSetExist; /* paramSet null or not */
bool setDigest;
uint32_t digest;
};
struct HksTestParamSetOut {
bool paramSetExist;
uint32_t paramSetSize;
uint32_t realParamSetSize;
};
struct HksTestGenKeyParams {
uint32_t testId;
int32_t expectResult;
struct HksTestBlobParams keyAliasParams;
struct HksTestGenKeyParamsParamSet paramSetParams;
struct HksTestGenKeyParamsParamSetOut paramSetParamsOut;
};
struct HksTestCipherParams {
uint32_t testId;
int32_t expectResult;
struct HksTestBlobParams keyAliasParams;
struct HksTestGenKeyParamsParamSet genKeyParamSetParams;
struct HksTestGenKeyParamsParamSetOut genKeyParamSetParamsOut;
struct HksTestCipherParamsParamSet encryptParamSetParams;
struct HksTestCipherParamsParamSet decryptParamSetParams;
struct HksTestBlobParams plainTextParams;
struct HksTestBlobParams cipherTextParams;
struct HksTestBlobParams decryptedTextParams;
struct HksTestBlobParams localKeyParams;
};
struct HksTestEncryptParams {
uint32_t testId;
int32_t expectResult;
struct HksTestBlobParams keyAliasParams;
struct HksTestGenKeyParamsParamSet genKeyParamSetParams;
struct HksTestBlobParams encryptAliasParams;
struct HksTestCipherParamsParamSet encryptParamSetParams;
struct HksTestBlobParams inDataParams;
struct HksTestBlobParams outDataParams;
struct HksTestBlobParams localKeyParams;
};
struct HksTestDecryptParams {
uint32_t testId;
int32_t expectResult;
struct HksTestBlobParams keyAliasParams;
struct HksTestGenKeyParamsParamSet genKeyParamSetParams;
struct HksTestBlobParams decryptAliasParams;
struct HksTestCipherParamsParamSet decryptParamSetParams;
struct HksTestBlobParams inDataParams;
struct HksTestBlobParams outDataParams;
struct HksTestBlobParams localKeyParams;
};
struct HksTestMacParams {
uint32_t testId;
int32_t expectResult;
enum HksTestMacType macType;
struct HksTestBlobParams keyAliasParams;
struct HksTestGenKeyParamsParamSet genKeyParamSetParams;
struct HksTestBlobParams keyParams;
struct HksTestMacParamSet macParamSetParams;
struct HksTestBlobParams srcDataParams;
struct HksTestBlobParams macParams;
};
struct HksTestDeriveParams {
uint32_t testId;
int32_t expectResult;
struct HksTestBlobParams keyAliasParams;
struct HksTestGenKeyParamsParamSet genKeyParamSetParams;
struct HksTestBlobParams masterKeyParams;
struct HksTestDeriveParamSet deriveParamSetParams;
struct HksTestBlobParams derivedKeyParams;
struct HksTestBlobParams localKeyParams;
};
struct HksTestKeyExistParams {
uint32_t testId;
int32_t expectResult;
bool isGenKey;
struct HksTestBlobParams keyAliasParams;
};
struct HksTestGetKeyParamSetParams {
uint32_t testId;
int32_t expectResult;
bool isGenKey;
struct HksTestBlobParams keyAliasParams;
struct HksTestParamSetOut paramSetOutParams;
};
struct HksTestGenRandomParams {
uint32_t testId;
int32_t expectResult;
struct HksTestBlobParams randomParams;
};
struct HksTestHashParams {
uint32_t testId;
int32_t expectResult;
struct HksTestHashParamsParamSet paramSetParams;
struct HksTestBlobParams srcDataParams;
struct HksTestBlobParams hashParams;
};
struct HksTestBnExpModParams {
uint32_t testId;
int32_t expectResult;
bool isTestValue;
struct HksTestBlobParams xParams;
struct HksTestBlobParams aParams;
struct HksTestBlobParams eParams;
struct HksTestBlobParams nParams;
};
struct HksTestAgreeParams {
uint32_t testId;
int32_t expectResult;
struct HksTestBlobParams keyAlias1Params;
struct HksTestBlobParams keyAlias2Params;
struct HksTestGenKeyParamsParamSet genKeyParamSetParams;
struct HksTestBlobParams privateKeyParams;
struct HksTestAgreeParamSet agreeParamSetParams;
struct HksTestBlobParams peerPublicParams;
struct HksTestBlobParams agreedKeyParams;
struct HksTestBlobParams localPrivateKeyParams;
struct HksTestBlobParams localPublicKeyParams;
};
struct TestAgreeParamSetStructure {
struct HksParamSet **outParamSet;
bool paramSetExist;
bool setAlg;
uint32_t alg;
bool setKeySize;
uint32_t keySize;
bool setIsKeyAlias;
bool isKeyAlias;
};
struct GenerateKeyParamSetStructure {
struct HksParamSet **outParamSet;
bool paramSetExist;
bool setAlg;
uint32_t alg;
bool setKeySize;
uint32_t keySize;
bool setPurpose;
uint32_t purpose;
bool setDigest;
uint32_t digest;
bool setPadding;
uint32_t padding;
bool setBlockMode;
uint32_t mode;
bool setKeyStorageFlag;
uint32_t keyStorageFlag;
};
struct AesCipherParamSetStructure {
struct HksParamSet **outParamSet;
bool paramSetExist;
bool setAlg;
uint32_t alg;
bool setPurpose;
uint32_t purpose;
bool setPadding;
uint32_t padding;
bool setBlockMode;
uint32_t mode;
bool setIv;
const struct HksBlob *ivBlob;
bool setNonce;
const struct HksBlob *nonceBlob;
bool setAad;
const struct HksBlob *aadBlob;
bool setIsKeyAlias;
bool isKeyAlias;
};
struct TestMacParamSetStructure {
struct HksParamSet **outParamSet;
bool paramSetExist;
bool setPurpose;
uint32_t purpose;
bool setDigest;
uint32_t digest;
bool setKeyAlias;
bool isKeyAlias;
};
struct TestDeriveParamSetStructure {
struct HksParamSet **outParamSet;
bool paramSetExist;
bool setAlg;
uint32_t alg;
bool setPurpose;
uint32_t purpose;
bool setDigest;
uint32_t digest;
bool setIteration;
uint32_t iteration;
bool setSalt;
const struct HksBlob *saltBlob;
bool setInfo;
const struct HksBlob *infoBlob;
bool setIsKeyAlias;
bool isKeyAlias;
};
#ifdef __cplusplus
extern "C" {
#endif
void TestFreeBlob(struct HksBlob **key);
int32_t TestConstuctBlob(struct HksBlob **blob,
bool blobExist,
uint32_t blobSize,
bool blobDataExist,
uint32_t realBlobDataSize);
int32_t TestConstructGenerateKeyParamSetOut(
struct HksParamSet **outParamSet,
bool paramSetExist, uint32_t paramSetSize);
int32_t TestConstructGenerateKeyParamSet(struct GenerateKeyParamSetStructure *paramStruct);
int32_t TestConstructRsaCipherParamSet(struct TestRsaCipherParamSet *paramStruct);
int32_t TestConstructAesCipherParamSet(struct AesCipherParamSetStructure *paramStruct);
int32_t TestConstructMacParamSet(struct TestMacParamSetStructure *paramStruct);
int32_t TestConstructAgreeParamSet(struct TestAgreeParamSetStructure *paramStruct);
int32_t GenerateLocalX25519Key(struct HksBlob **privateKey, struct HksBlob **publicKey,
const struct HksTestBlobParams *localPrivateKeyParams, const struct HksTestBlobParams *localPublicKeyParams);
int32_t TestConstructDeriveParamSet(struct TestDeriveParamSetStructure *paramStruct);
int32_t TestConstructHashParamSet(
struct HksParamSet **outParamSet,
bool paramSetExist,
bool setDigest, uint32_t digest);
int32_t GenerateKey(struct HksBlob **keyAlias, const struct HksTestBlobParams *keyAliasParams,
const struct HksTestGenKeyParamsParamSet *genKeyParamSetParams,
const struct HksTestGenKeyParamsParamSetOut *genKeyParamSetParamsOut);
int32_t GenerateLocalRandomKey(struct HksBlob **keyAlias, const struct HksTestBlobParams *localKeyParams);
int32_t TestConstructBlobOut(struct HksBlob **blob,
bool blobExist,
uint32_t blobSize,
bool blobDataExist,
uint32_t realBlobDataSize);
int32_t TestGenDefaultKeyAndGetAlias(struct HksBlob **keyAlias);
#ifdef __cplusplus
}
#endif
#endif /* HKS_TEST_COMMON_H */
/*
* 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.
*/
#ifndef HKS_TEST_CURVE25519
#define HKS_TEST_CURVE25519
#include "hks_type.h"
#include "securec.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t TestGenerateEd25519Key(struct HksBlob alias);
int32_t TestImportEd25519(struct HksBlob alias, struct HksBlob *pubKeyInfo);
int32_t TestCurve25519All();
int32_t TestEd25519SignTeeVerifyLocal();
int32_t TestCurve25519SignWrong();
int32_t TestCurve25519verifyWrong();
#ifdef __cplusplus
}
#endif
#endif
/*
* 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 "hks_type.h"
#ifndef HKS_TEST_FILE_OPERATOR_H
#define HKS_TEST_FILE_OPERATOR_H
#ifdef __cplusplus
extern "C" {
#endif
int32_t HksIsFileExist(const char *path, const char *fileName);
uint32_t HksTestFileSize(const char *path, const char *fileName);
uint32_t HksTestFileRead(const char *path, const char *fileName, uint32_t offset, uint8_t *buf, uint32_t len);
int32_t HksTestFileWrite(const char *path, const char *fileName, uint32_t offset, const uint8_t *buf, uint32_t len);
int32_t HksTestFileRemove(const char *path, const char *fileName);
#ifdef __cplusplus
}
#endif
#endif /* HKS_TEST_FILE_OPERATOR_H */
/*
* 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.
*/
#ifndef HKS_TEST_LOG_H
#define HKS_TEST_LOG_H
#include "stdint.h"
#include "stdbool.h"
#define HKS_TEST_ASSERT(test) \
if (!(test)) { \
printf("[ASSERT][%s](%d):fail\n", __func__, __LINE__); \
}
#ifndef _CUT_LOG_
#define HKS_TEST_LOG_E(fmt...) \
do { \
printf("[ERROR]\t[%s](%d): ", __func__, __LINE__); \
printf(fmt); \
printf("\r\n"); \
} while (0)
#define HKS_TEST_LOG_I(fmt...) \
do { \
printf("[INFO]\t[%s](%d): ", __func__, __LINE__); \
printf(fmt); \
printf("\r\n"); \
} while (0)
#define HKS_TEST_LOG_W(fmt...) \
do { \
printf("[WARN]\t[%s](%d): ", __func__, __LINE__); \
printf(fmt); \
printf("\r\n"); \
} while (0)
#define HKS_TEST_LOG_D(fmt...) \
do { \
printf("[DEBUG]\t[%s](%d): ", __func__, __LINE__); \
printf(fmt); \
printf("\r\n"); \
} while (0)
#else
#define HKS_TEST_LOG_E(...)
#define HKS_TEST_LOG_I(...)
#define HKS_TEST_LOG_W(...)
#define HKS_TEST_LOG_D(...)
#endif
#endif /* HKS_TEST_LOG_H */
/*
* 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.
*/
#ifndef HKS_TEST_MEM_H
#define HKS_TEST_MEM_H
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
void *HksTestMalloc(size_t size);
void HksTestFree(void *ptr);
#ifdef __cplusplus
}
#endif
#endif /* HKS_TEST_MEM_H */
#
# 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("//base/security/huks/build/config.gni")
import("//build/lite/config/component/lite_component.gni")
import("//build/lite/config/test.gni")
import("//test/xts/tools/lite/build/suite_lite.gni")
hcpptest_suite("huks_lite_function_test") {
suite_name = "acts"
sources = [
"hks_aes_test.cpp",
"hks_agreement_test.cpp",
"hks_bn_exp_mod_test.cpp",
"hks_cipher_test.cpp",
"hks_curve25519_test.cpp",
"hks_delete_test.cpp",
"hks_derive_test.cpp",
"hks_exist_test.cpp",
"hks_generate_key_test.cpp",
"hks_generate_random_test.cpp",
"hks_hash_test.cpp",
"hks_mac_test.cpp",
"hks_modify_key_test.cpp",
"hks_others_test.cpp",
"hks_safe_cipher_key_test.cpp",
"hks_safe_compare_key_test.cpp",
]
include_dirs = [
"//utils/native/base/include",
"//third_party/bounds_checking_function/include",
"//base/security/huks/huawei_property/include",
"../common/include",
]
deps = [
"//base/security/huks/interfaces/innerkits/huks_lite:huks_3.0_sdk",
"//test/xts/acts/security_lite/huks/common:huks_new_test_common",
]
cflags = [ "-Wno-error" ]
defines = [ "_LITEONE_SYSTEM_" ]
if (disable_authenticate == true) {
defines = [ "_CUT_AUTHENTICATE_" ]
}
}
group("Hukslitetest") {
deps = [ ":huks_lite_function_test" ]
}
{
"description": "Config for hcpptest demo test cases",
"environment": [
{
"type": "device",
"label": "ipcamera"
}
],
"kits": [
{
"type": "MountKit",
"server": "NfsServer",
"mount": [
{
"source": "testcases/security",
"target": "/test_root/security"
}
]
}
],
"driver": {
"type": "CppTestLite",
"execute": "/test_root/security/ActsSecurityHukslitetest.bin"
}
}
\ 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 <gtest/gtest.h>
#include "hks_aes_test.h"
#include "securec.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_aes.h"
using namespace testing::ext;
namespace {
class HksAesTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksAesTest::SetUpTestCase(void)
{
}
void HksAesTest::TearDownTestCase(void)
{
}
void HksAesTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksAesTest::TearDown()
{
}
#ifndef _CUT_AUTHENTICATE_
/**
* @tc.name: HksCipherTest.HksCipherTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksAesTest, HksAesTest001, TestSize.Level1)
{
ASSERT_TRUE(TestAes256ByAgree() == 0);
}
/**
* @tc.name: HksCipherTest.HksCipherTest002
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksAesTest, HksAesTest002, TestSize.Level1)
{
ASSERT_TRUE(TestAes256ByAgree1() == 0);
}
/**
* @tc.name: HksCipherTest.HksCipherTest003
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksAesTest, HksAesTest003, TestSize.Level1)
{
ASSERT_TRUE(TestAes256ByAgree2() == 0);
}
#endif /* _CUT_AUTHENTICATE_ */
/**
* @tc.name: HksCipherTest.HksCipherTest003
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksAesTest, HksAesTest004, TestSize.Level1)
{
ASSERT_EQ(TestAes256ByLocal(), 0);
}
}
/*
* 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 <gtest/gtest.h>
#include "hks_agreement_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_common.h"
#include "hks_test_log.h"
#include "hks_type.h"
using namespace testing::ext;
namespace {
#ifndef _CUT_AUTHENTICATE_
class HksAgreementTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksAgreementTest::SetUpTestCase(void)
{
}
void HksAgreementTest::TearDownTestCase(void)
{
}
void HksAgreementTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksAgreementTest::TearDown()
{
}
const int TMP_SIZE = 512;
const int X25519_KEY_SIZE = 32;
const struct HksTestAgreeParams g_testAgreeParams[] = {
/* ree x25519 success */
{ 0, HKS_SUCCESS, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE },
{ true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE },
{ true, true, HKS_ALG_X25519, true, HKS_CURVE25519_KEY_SIZE_256, true,
HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY, true, HKS_DIGEST_SHA256,
false, 0, false, 0, true, HKS_STORAGE_TEMP },
{ 0 },
{ true, true, HKS_ALG_X25519, true, HKS_CURVE25519_KEY_SIZE_256, true, false },
{ true, TMP_SIZE, true, TMP_SIZE },
{ true, X25519_KEY_SIZE, true, X25519_KEY_SIZE },
{ true, X25519_KEY_SIZE, true, X25519_KEY_SIZE },
{ true, X25519_KEY_SIZE, true, X25519_KEY_SIZE }
},
};
static int32_t AgreeKey(const struct HksTestAgreeParamSet *agreeParamSetParams, struct HksBlob *privateKey,
struct HksBlob *peerPublicKey, struct HksBlob *agreedKey)
{
struct HksParamSet *agreeParamSet = NULL;
struct TestAgreeParamSetStructure paramStruct = {
&agreeParamSet,
agreeParamSetParams->paramSetExist,
agreeParamSetParams->setAlg, agreeParamSetParams->alg,
agreeParamSetParams->setKeySize, agreeParamSetParams->keySize,
agreeParamSetParams->setIsKeyAlias, agreeParamSetParams->isKeyAlias
};
int32_t ret = TestConstructAgreeParamSet(&paramStruct);
HKS_TEST_ASSERT(ret == 0);
ret = HksAgreeKeyRun(agreeParamSet, privateKey, peerPublicKey, agreedKey, 1);
HksFreeParamSet(&agreeParamSet);
return ret;
}
/**
* @tc.name: HksDeleteTest.HksDeleteTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksAgreementTest, HksAgreementTest001, TestSize.Level1)
{
/* 1. generate key */
struct HksBlob *privateKey = NULL;
struct HksBlob *peerPubKeyAlias = NULL;
struct HksBlob *peerPublicKey = NULL;
int32_t ret;
if (g_testAgreeParams[0].genKeyParamSetParams.setKeyStorageFlag &&
(g_testAgreeParams[0].genKeyParamSetParams.keyStorageFlag == HKS_STORAGE_TEMP)) {
ret = GenerateLocalX25519Key(&privateKey, NULL, &g_testAgreeParams[0].localPrivateKeyParams, NULL);
ASSERT_TRUE(ret == 0);
ret = GenerateLocalX25519Key(NULL, &peerPublicKey, NULL, &g_testAgreeParams[0].localPublicKeyParams);
ASSERT_TRUE(ret == 0);
}
/* 2. agreeKey */
struct HksBlob *agreeKey = NULL;
ret = TestConstuctBlob(&agreeKey,
g_testAgreeParams[0].agreedKeyParams.blobExist,
g_testAgreeParams[0].agreedKeyParams.blobSize,
g_testAgreeParams[0].agreedKeyParams.blobDataExist,
g_testAgreeParams[0].agreedKeyParams.blobDataSize);
ASSERT_TRUE(ret == 0);
ret = AgreeKey(&g_testAgreeParams[0].agreeParamSetParams, privateKey, peerPublicKey, agreeKey);
ASSERT_TRUE(ret == g_testAgreeParams[0].expectResult);
/* 3. delete key */
if (!(g_testAgreeParams[0].genKeyParamSetParams.setKeyStorageFlag &&
(g_testAgreeParams[0].genKeyParamSetParams.keyStorageFlag == HKS_STORAGE_TEMP)) &&
((g_testAgreeParams[0].keyAlias1Params.blobExist) &&
(g_testAgreeParams[0].keyAlias2Params.blobExist))) {
ret = HksDeleteKey(privateKey, NULL);
ASSERT_TRUE(ret == 0);
ret = HksDeleteKey(peerPubKeyAlias, NULL);
ASSERT_TRUE(ret == 0);
}
TestFreeBlob(&privateKey);
TestFreeBlob(&peerPubKeyAlias);
TestFreeBlob(&peerPublicKey);
TestFreeBlob(&agreeKey);
ASSERT_TRUE(ret == 0);
}
/**
* @tc.name: HksDeleteTest.HksDeleteTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksAgreementTest, HksAgreementTest002, TestSize.Level1)
{
/* 1. generate key */
struct HksBlob *privateKey = NULL;
struct HksBlob *peerPubKeyAlias = NULL;
struct HksBlob *peerPublicKey = NULL;
struct HksBlob *privateKey2 = NULL;
struct HksBlob *peerPubKeyAlias2 = NULL;
struct HksBlob *peerPublicKey2 = NULL;
int32_t ret;
if (g_testAgreeParams[0].genKeyParamSetParams.setKeyStorageFlag &&
(g_testAgreeParams[0].genKeyParamSetParams.keyStorageFlag == HKS_STORAGE_TEMP)) {
ret = GenerateLocalX25519Key(&privateKey, &peerPublicKey, &g_testAgreeParams[0].localPrivateKeyParams, \
&g_testAgreeParams[0].localPublicKeyParams);
ASSERT_TRUE(ret == 0);
ret = GenerateLocalX25519Key(&privateKey2, &peerPublicKey2, &g_testAgreeParams[0].localPrivateKeyParams, \
&g_testAgreeParams[0].localPublicKeyParams);
ASSERT_TRUE(ret == 0);
}
/* 2. agreeKey */
struct HksBlob *agreeKey = NULL;
ret = TestConstuctBlob(&agreeKey, g_testAgreeParams[0].agreedKeyParams.blobExist, \
g_testAgreeParams[0].agreedKeyParams.blobSize, g_testAgreeParams[0].agreedKeyParams.blobDataExist, \
g_testAgreeParams[0].agreedKeyParams.blobDataSize);
ASSERT_TRUE(ret == 0);
struct HksBlob *agreeKey2 = NULL;
ret = TestConstuctBlob(&agreeKey2, g_testAgreeParams[0].agreedKeyParams.blobExist, \
g_testAgreeParams[0].agreedKeyParams.blobSize, g_testAgreeParams[0].agreedKeyParams.blobDataExist, \
g_testAgreeParams[0].agreedKeyParams.blobDataSize);
ASSERT_TRUE(ret == 0);
ret = AgreeKey(&g_testAgreeParams[0].agreeParamSetParams, privateKey, peerPublicKey2, agreeKey);
ASSERT_TRUE(ret == g_testAgreeParams[0].expectResult);
ret = AgreeKey(&g_testAgreeParams[0].agreeParamSetParams, privateKey2, peerPublicKey, agreeKey2);
ASSERT_TRUE(ret == g_testAgreeParams[0].expectResult);
EXPECT_EQ(agreeKey->size, agreeKey2->size);
EXPECT_EQ(memcmp(agreeKey->data, agreeKey2->data, agreeKey->size), 0);
/* 3. delete key */
if (!(g_testAgreeParams[0].genKeyParamSetParams.setKeyStorageFlag && \
(g_testAgreeParams[0].genKeyParamSetParams.keyStorageFlag == HKS_STORAGE_TEMP)) && \
((g_testAgreeParams[0].keyAlias1Params.blobExist) && (g_testAgreeParams[0].keyAlias2Params.blobExist))) {
ASSERT_TRUE(HksDeleteKey(privateKey, NULL) == 0);
ASSERT_TRUE(HksDeleteKey(peerPubKeyAlias, NULL) == 0);
}
TestFreeBlob(&privateKey);
TestFreeBlob(&peerPubKeyAlias);
TestFreeBlob(&peerPublicKey);
TestFreeBlob(&agreeKey);
}
#endif /* _CUT_AUTHENTICATE_ */
}
\ 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 <gtest/gtest.h>
#include "hks_cipher_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_cipher.h"
using namespace testing::ext;
namespace {
class HksCipherTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksCipherTest::SetUpTestCase(void)
{
}
void HksCipherTest::TearDownTestCase(void)
{
}
void HksCipherTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksCipherTest::TearDown()
{
}
/**
* @tc.name: HksCipherTest.HksCipherTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksCipherTest, HksCipherTest001, TestSize.Level1)
{
ASSERT_TRUE(BaseTestCipher(1, 0, 1) == 0);
}
#ifndef _CUT_AUTHENTICATE_
HWTEST_F(HksCipherTest, HksCipherTest002, TestSize.Level1)
{
ASSERT_TRUE(BaseTestCipher(1, 1, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest003, TestSize.Level1)
{
ASSERT_TRUE(BaseTestEncrypt(1, 0, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest004, TestSize.Level1)
{
ASSERT_TRUE(BaseTestEncrypt(1, 1, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest005, TestSize.Level1)
{
ASSERT_TRUE(BaseTestEncrypt(1, 2, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest006, TestSize.Level1)
{
ASSERT_TRUE(BaseTestEncrypt(1, 3, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest007, TestSize.Level1)
{
ASSERT_TRUE(BaseTestEncrypt(1, 4, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest008, TestSize.Level1)
{
ASSERT_TRUE(BaseTestDecrypt(1, 0, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest009, TestSize.Level1)
{
ASSERT_TRUE(BaseTestDecrypt(1, 1, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest010, TestSize.Level1)
{
ASSERT_TRUE(BaseTestDecrypt(1, 2, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest011, TestSize.Level1)
{
ASSERT_TRUE(BaseTestDecrypt(1, 3, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest012, TestSize.Level1)
{
ASSERT_TRUE(BaseTestDecrypt(1, 4, 1) == 0);
}
#endif /* _CUT_AUTHENTICATE_ */
}
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册