1526fd984Sopenharmony_ci/* 2526fd984Sopenharmony_ci * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3526fd984Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4526fd984Sopenharmony_ci * you may not use this file except in compliance with the License. 5526fd984Sopenharmony_ci * You may obtain a copy of the License at 6526fd984Sopenharmony_ci * 7526fd984Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8526fd984Sopenharmony_ci * 9526fd984Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10526fd984Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11526fd984Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12526fd984Sopenharmony_ci * See the License for the specific language governing permissions and 13526fd984Sopenharmony_ci * limitations under the License. 14526fd984Sopenharmony_ci */ 15526fd984Sopenharmony_ci 16526fd984Sopenharmony_ci#include <chrono> 17526fd984Sopenharmony_ci#include <gtest/gtest.h> 18526fd984Sopenharmony_ci#include <securec.h> 19526fd984Sopenharmony_ci#include <sys/time.h> 20526fd984Sopenharmony_ci 21526fd984Sopenharmony_ci#include "hks_api.h" 22526fd984Sopenharmony_ci#include "hks_log.h" 23526fd984Sopenharmony_ci#include "hks_mem.h" 24526fd984Sopenharmony_ci#include "hks_param.h" 25526fd984Sopenharmony_ci 26526fd984Sopenharmony_ci#define HKS_VERIFY_FINISH_ECC_224_COMMON \ 27526fd984Sopenharmony_ci{ .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_PERSISTENT }, \ 28526fd984Sopenharmony_ci{ .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_ECC }, \ 29526fd984Sopenharmony_ci{ .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_ECC_KEY_SIZE_224 }, \ 30526fd984Sopenharmony_ci{ .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_VERIFY }, \ 31526fd984Sopenharmony_ci{ .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }, \ 32526fd984Sopenharmony_ci{ .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = true }, \ 33526fd984Sopenharmony_ci{ .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 34526fd984Sopenharmony_ci 35526fd984Sopenharmony_ciusing namespace testing::ext; 36526fd984Sopenharmony_cinamespace { 37526fd984Sopenharmony_cinamespace { 38526fd984Sopenharmony_ciconst char GENERATE_KEY[] = "This is for generate key"; 39526fd984Sopenharmony_ciconst char IMPORT_KEY[] = "This is for import key"; 40526fd984Sopenharmony_ciconst uint32_t TEST_FREQUENCY = 1000; 41526fd984Sopenharmony_ciconst uint32_t MAX_SDK_VERSION_SIZE = 64; 42526fd984Sopenharmony_ciconst uint32_t IV_SIZE = 16; 43526fd984Sopenharmony_ciconst uint32_t COMPLEMENT_LEN = 16; 44526fd984Sopenharmony_ciconst uint32_t KEY_PARAMSET_SIZE = 1024; 45526fd984Sopenharmony_ciconst uint32_t MESSAGE_SIZE = 64; 46526fd984Sopenharmony_ciconst uint32_t TEST_KEY_SIZE = 512; 47526fd984Sopenharmony_ciconst uint32_t DERIVED_KEY_SIZE = 64; 48526fd984Sopenharmony_ci 49526fd984Sopenharmony_cistatic const struct HksParam PARAMS_FOR_ENCRYPT[] = { 50526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_TEMP }, 51526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_AES }, 52526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_AES_KEY_SIZE_128 }, 53526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT }, 54526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }, 55526fd984Sopenharmony_ci { .tag = HKS_TAG_PADDING, .uint32Param = HKS_PADDING_PKCS7 }, 56526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = false }, 57526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 58526fd984Sopenharmony_ci { .tag = HKS_TAG_BLOCK_MODE, .uint32Param = HKS_MODE_CBC }, 59526fd984Sopenharmony_ci}; 60526fd984Sopenharmony_ci 61526fd984Sopenharmony_cistatic const struct HksParam PARAMS_FOR_DECRYPT[] = { 62526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_TEMP }, 63526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_AES }, 64526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_AES_KEY_SIZE_128 }, 65526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT }, 66526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }, 67526fd984Sopenharmony_ci { .tag = HKS_TAG_PADDING, .uint32Param = HKS_PADDING_PKCS7 }, 68526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = false }, 69526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 70526fd984Sopenharmony_ci { .tag = HKS_TAG_BLOCK_MODE, .uint32Param = HKS_MODE_CBC }, 71526fd984Sopenharmony_ci}; 72526fd984Sopenharmony_ci} // namespace 73526fd984Sopenharmony_ciclass PressureTest : public testing::Test { 74526fd984Sopenharmony_cipublic: 75526fd984Sopenharmony_ci int32_t LocalHksGenerate(const uint32_t keyLen, const struct HksBlob *authId, const struct HksParamSet *paramSetIn, 76526fd984Sopenharmony_ci struct HksBlob *priKey, struct HksBlob *pubKey) const; 77526fd984Sopenharmony_ci}; 78526fd984Sopenharmony_ci 79526fd984Sopenharmony_ciint32_t PressureTest::LocalHksGenerate(const uint32_t keyLen, const struct HksBlob *authId, 80526fd984Sopenharmony_ci const struct HksParamSet *paramSetIn, struct HksBlob *priKey, struct HksBlob *pubKey) const 81526fd984Sopenharmony_ci{ 82526fd984Sopenharmony_ci struct HksParamSet *paramOutSet = nullptr; 83526fd984Sopenharmony_ci HksInitParamSet(¶mOutSet); 84526fd984Sopenharmony_ci struct HksParam localKey = { 85526fd984Sopenharmony_ci .tag = HKS_TAG_SYMMETRIC_KEY_DATA, 86526fd984Sopenharmony_ci .blob = { .size = keyLen, .data = (uint8_t *)HksMalloc(keyLen) } 87526fd984Sopenharmony_ci }; 88526fd984Sopenharmony_ci if (localKey.blob.data == nullptr) { 89526fd984Sopenharmony_ci HksFreeParamSet(¶mOutSet); 90526fd984Sopenharmony_ci return HKS_FAILURE; 91526fd984Sopenharmony_ci } 92526fd984Sopenharmony_ci HksAddParams(paramOutSet, &localKey, 1); 93526fd984Sopenharmony_ci HksBuildParamSet(¶mOutSet); 94526fd984Sopenharmony_ci 95526fd984Sopenharmony_ci if (HksGenerateKey(authId, paramSetIn, paramOutSet) != HKS_SUCCESS) { 96526fd984Sopenharmony_ci HKS_FREE(localKey.blob.data); 97526fd984Sopenharmony_ci HksFreeParamSet(¶mOutSet); 98526fd984Sopenharmony_ci return HKS_SUCCESS; 99526fd984Sopenharmony_ci } 100526fd984Sopenharmony_ci 101526fd984Sopenharmony_ci HksParam *priParam = nullptr; 102526fd984Sopenharmony_ci HksGetParam(paramOutSet, HKS_TAG_ASYMMETRIC_PRIVATE_KEY_DATA, &priParam); 103526fd984Sopenharmony_ci priKey->size = priParam->blob.size; 104526fd984Sopenharmony_ci (void)memcpy_s(priKey->data, priParam->blob.size, priParam->blob.data, priParam->blob.size); 105526fd984Sopenharmony_ci 106526fd984Sopenharmony_ci HksParam *pubParam = nullptr; 107526fd984Sopenharmony_ci HksGetParam(paramOutSet, HKS_TAG_ASYMMETRIC_PUBLIC_KEY_DATA, &pubParam); 108526fd984Sopenharmony_ci pubKey->size = pubParam->blob.size; 109526fd984Sopenharmony_ci (void)memcpy_s(pubKey->data, pubParam->blob.size, pubParam->blob.data, pubParam->blob.size); 110526fd984Sopenharmony_ci 111526fd984Sopenharmony_ci HKS_FREE(localKey.blob.data); 112526fd984Sopenharmony_ci HksFreeParamSet(¶mOutSet); 113526fd984Sopenharmony_ci return HKS_SUCCESS; 114526fd984Sopenharmony_ci} 115526fd984Sopenharmony_ci 116526fd984Sopenharmony_ci/** 117526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest00100 118526fd984Sopenharmony_ci * @tc.name : PressureTest00100 119526fd984Sopenharmony_ci * @tc.desc : HksGetSdkVersion 120526fd984Sopenharmony_ci */ 121526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest00100, TestSize.Level1) 122526fd984Sopenharmony_ci{ 123526fd984Sopenharmony_ci double programTimes = 0; 124526fd984Sopenharmony_ci 125526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 126526fd984Sopenharmony_ci struct HksBlob sdkVersion = { .size = MAX_SDK_VERSION_SIZE, 127526fd984Sopenharmony_ci .data = (uint8_t *)HksMalloc(MAX_SDK_VERSION_SIZE) }; 128526fd984Sopenharmony_ci ASSERT_NE(sdkVersion.data, nullptr); 129526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 130526fd984Sopenharmony_ci int32_t ret = HksGetSdkVersion(&sdkVersion); 131526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 132526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 133526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 134526fd984Sopenharmony_ci HKS_FREE(sdkVersion.data); 135526fd984Sopenharmony_ci } 136526fd984Sopenharmony_ci HKS_LOG_I("HksGetSdkVersion Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 137526fd984Sopenharmony_ci} 138526fd984Sopenharmony_ci 139526fd984Sopenharmony_ci/** 140526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest00200 141526fd984Sopenharmony_ci * @tc.name : PressureTest00200 142526fd984Sopenharmony_ci * @tc.desc : HksInitialize 143526fd984Sopenharmony_ci */ 144526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest00200, TestSize.Level1) 145526fd984Sopenharmony_ci{ 146526fd984Sopenharmony_ci double programTimes = 0; 147526fd984Sopenharmony_ci 148526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 149526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 150526fd984Sopenharmony_ci int32_t ret = HksInitialize(); 151526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 152526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 153526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 154526fd984Sopenharmony_ci } 155526fd984Sopenharmony_ci HKS_LOG_I("HksInitialize Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 156526fd984Sopenharmony_ci} 157526fd984Sopenharmony_ci 158526fd984Sopenharmony_ci/** 159526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest00300 160526fd984Sopenharmony_ci * @tc.name : PressureTest00300 161526fd984Sopenharmony_ci * @tc.desc : HksRefreshKeyInfo 162526fd984Sopenharmony_ci */ 163526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest00300, TestSize.Level1) 164526fd984Sopenharmony_ci{ 165526fd984Sopenharmony_ci double programTimes = 0; 166526fd984Sopenharmony_ci 167526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 168526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 169526fd984Sopenharmony_ci int32_t ret = HksRefreshKeyInfo(); 170526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 171526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 172526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 173526fd984Sopenharmony_ci } 174526fd984Sopenharmony_ci HKS_LOG_I("HksRefreshKeyInfo Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 175526fd984Sopenharmony_ci} 176526fd984Sopenharmony_ci 177526fd984Sopenharmony_ci/** 178526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest00400 179526fd984Sopenharmony_ci * @tc.name : PressureTest00400 180526fd984Sopenharmony_ci * @tc.desc : HksGenerateKey 181526fd984Sopenharmony_ci */ 182526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest00400, TestSize.Level1) 183526fd984Sopenharmony_ci{ 184526fd984Sopenharmony_ci double programTimes = 0; 185526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 186526fd984Sopenharmony_ci 187526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 188526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 189526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 190526fd984Sopenharmony_ci 191526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 192526fd984Sopenharmony_ci HKS_VERIFY_FINISH_ECC_224_COMMON 193526fd984Sopenharmony_ci }; 194526fd984Sopenharmony_ci 195526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 196526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 197526fd984Sopenharmony_ci 198526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 199526fd984Sopenharmony_ci int32_t ret = HksGenerateKey(&authId, paramInSet, NULL); 200526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 201526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 202526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 203526fd984Sopenharmony_ci 204526fd984Sopenharmony_ci HksDeleteKey(&authId, paramInSet); 205526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 206526fd984Sopenharmony_ci } 207526fd984Sopenharmony_ci HKS_LOG_I("HksGenerateKey Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 208526fd984Sopenharmony_ci} 209526fd984Sopenharmony_ci 210526fd984Sopenharmony_ci/** 211526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest00500 212526fd984Sopenharmony_ci * @tc.name : PressureTest00500 213526fd984Sopenharmony_ci * @tc.desc : HksImportKey 214526fd984Sopenharmony_ci */ 215526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest00500, TestSize.Level1) 216526fd984Sopenharmony_ci{ 217526fd984Sopenharmony_ci double programTimes = 0; 218526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 219526fd984Sopenharmony_ci 220526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 221526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 222526fd984Sopenharmony_ci 223526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 224526fd984Sopenharmony_ci HKS_VERIFY_FINISH_ECC_224_COMMON 225526fd984Sopenharmony_ci }; 226526fd984Sopenharmony_ci 227526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 228526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 229526fd984Sopenharmony_ci 230526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, NULL); 231526fd984Sopenharmony_ci 232526fd984Sopenharmony_ci struct HksBlob pubKey = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 233526fd984Sopenharmony_ci ASSERT_NE(pubKey.data, nullptr); 234526fd984Sopenharmony_ci HksExportPublicKey(&authId, paramInSet, &pubKey); 235526fd984Sopenharmony_ci 236526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 237526fd984Sopenharmony_ci struct HksBlob importId = { strlen(IMPORT_KEY), (uint8_t *)IMPORT_KEY }; 238526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 239526fd984Sopenharmony_ci int32_t ret = HksImportKey(&importId, paramInSet, &pubKey); 240526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 241526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 242526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 243526fd984Sopenharmony_ci HksDeleteKey(&importId, paramInSet); 244526fd984Sopenharmony_ci } 245526fd984Sopenharmony_ci HksDeleteKey(&authId, paramInSet); 246526fd984Sopenharmony_ci HKS_FREE(pubKey.data); 247526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 248526fd984Sopenharmony_ci HKS_LOG_I("HksImportKey Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 249526fd984Sopenharmony_ci} 250526fd984Sopenharmony_ci 251526fd984Sopenharmony_ci/** 252526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest00600 253526fd984Sopenharmony_ci * @tc.name : PressureTest00600 254526fd984Sopenharmony_ci * @tc.desc : HksExportPublicKey 255526fd984Sopenharmony_ci */ 256526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest00600, TestSize.Level1) 257526fd984Sopenharmony_ci{ 258526fd984Sopenharmony_ci double programTimes = 0; 259526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 260526fd984Sopenharmony_ci 261526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 262526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 263526fd984Sopenharmony_ci 264526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 265526fd984Sopenharmony_ci HKS_VERIFY_FINISH_ECC_224_COMMON 266526fd984Sopenharmony_ci }; 267526fd984Sopenharmony_ci 268526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 269526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 270526fd984Sopenharmony_ci 271526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, NULL); 272526fd984Sopenharmony_ci 273526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 274526fd984Sopenharmony_ci struct HksBlob pubKey = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 275526fd984Sopenharmony_ci ASSERT_NE(pubKey.data, nullptr); 276526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 277526fd984Sopenharmony_ci int32_t ret = HksExportPublicKey(&authId, paramInSet, &pubKey); 278526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 279526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 280526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 281526fd984Sopenharmony_ci 282526fd984Sopenharmony_ci HKS_FREE(pubKey.data); 283526fd984Sopenharmony_ci } 284526fd984Sopenharmony_ci HksDeleteKey(&authId, paramInSet); 285526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 286526fd984Sopenharmony_ci HKS_LOG_I("HksExportPublicKey Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 287526fd984Sopenharmony_ci} 288526fd984Sopenharmony_ci 289526fd984Sopenharmony_ci/** 290526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest00700 291526fd984Sopenharmony_ci * @tc.name : PressureTest00700 292526fd984Sopenharmony_ci * @tc.desc : HksDeleteKey 293526fd984Sopenharmony_ci */ 294526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest00700, TestSize.Level1) 295526fd984Sopenharmony_ci{ 296526fd984Sopenharmony_ci double programTimes = 0; 297526fd984Sopenharmony_ci 298526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 299526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 300526fd984Sopenharmony_ci 301526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 302526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 303526fd984Sopenharmony_ci 304526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 305526fd984Sopenharmony_ci HKS_VERIFY_FINISH_ECC_224_COMMON 306526fd984Sopenharmony_ci }; 307526fd984Sopenharmony_ci 308526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 309526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 310526fd984Sopenharmony_ci 311526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, NULL); 312526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 313526fd984Sopenharmony_ci int32_t ret = HksDeleteKey(&authId, paramInSet); 314526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 315526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 316526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 317526fd984Sopenharmony_ci 318526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 319526fd984Sopenharmony_ci } 320526fd984Sopenharmony_ci HKS_LOG_I("HksDeleteKey Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 321526fd984Sopenharmony_ci} 322526fd984Sopenharmony_ci 323526fd984Sopenharmony_ci/** 324526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest00800 325526fd984Sopenharmony_ci * @tc.name : PressureTest00800 326526fd984Sopenharmony_ci * @tc.desc : HksGetKeyParamSet 327526fd984Sopenharmony_ci */ 328526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest00800, TestSize.Level1) 329526fd984Sopenharmony_ci{ 330526fd984Sopenharmony_ci double programTimes = 0; 331526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 332526fd984Sopenharmony_ci 333526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 334526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 335526fd984Sopenharmony_ci 336526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 337526fd984Sopenharmony_ci HKS_VERIFY_FINISH_ECC_224_COMMON 338526fd984Sopenharmony_ci }; 339526fd984Sopenharmony_ci 340526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 341526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 342526fd984Sopenharmony_ci 343526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, NULL); 344526fd984Sopenharmony_ci 345526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 346526fd984Sopenharmony_ci struct HksParamSet *paramOutSet = nullptr; 347526fd984Sopenharmony_ci HksInitParamSet(¶mOutSet); 348526fd984Sopenharmony_ci struct HksParam localKey = { .tag = HKS_TAG_SYMMETRIC_KEY_DATA, 349526fd984Sopenharmony_ci .blob = { .size = KEY_PARAMSET_SIZE, .data = (uint8_t *)HksMalloc(KEY_PARAMSET_SIZE) } }; 350526fd984Sopenharmony_ci ASSERT_NE(localKey.blob.data, nullptr); 351526fd984Sopenharmony_ci HksAddParams(paramOutSet, &localKey, 1); 352526fd984Sopenharmony_ci 353526fd984Sopenharmony_ci HksBuildParamSet(¶mOutSet); 354526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 355526fd984Sopenharmony_ci int32_t ret = HksGetKeyParamSet(&authId, paramInSet, paramOutSet); 356526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 357526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 358526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 359526fd984Sopenharmony_ci 360526fd984Sopenharmony_ci HKS_FREE(localKey.blob.data); 361526fd984Sopenharmony_ci HksFreeParamSet(¶mOutSet); 362526fd984Sopenharmony_ci } 363526fd984Sopenharmony_ci HksDeleteKey(&authId, paramInSet); 364526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 365526fd984Sopenharmony_ci HKS_LOG_I("HksGetKeyParamSet Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 366526fd984Sopenharmony_ci} 367526fd984Sopenharmony_ci 368526fd984Sopenharmony_ci/** 369526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest00900 370526fd984Sopenharmony_ci * @tc.name : PressureTest00900 371526fd984Sopenharmony_ci * @tc.desc : HksKeyExist 372526fd984Sopenharmony_ci */ 373526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest00900, TestSize.Level1) 374526fd984Sopenharmony_ci{ 375526fd984Sopenharmony_ci double programTimes = 0; 376526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 377526fd984Sopenharmony_ci 378526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 379526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 380526fd984Sopenharmony_ci 381526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 382526fd984Sopenharmony_ci HKS_VERIFY_FINISH_ECC_224_COMMON 383526fd984Sopenharmony_ci }; 384526fd984Sopenharmony_ci 385526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 386526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 387526fd984Sopenharmony_ci 388526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, NULL); 389526fd984Sopenharmony_ci 390526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 391526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 392526fd984Sopenharmony_ci int32_t ret = HksKeyExist(&authId, paramInSet); 393526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 394526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 395526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 396526fd984Sopenharmony_ci } 397526fd984Sopenharmony_ci HksDeleteKey(&authId, paramInSet); 398526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 399526fd984Sopenharmony_ci HKS_LOG_I("HksKeyExist Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 400526fd984Sopenharmony_ci} 401526fd984Sopenharmony_ci 402526fd984Sopenharmony_ci/** 403526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest01000 404526fd984Sopenharmony_ci * @tc.name : PressureTest01000 405526fd984Sopenharmony_ci * @tc.desc : HksGenerateRandom 406526fd984Sopenharmony_ci */ 407526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest01000, TestSize.Level1) 408526fd984Sopenharmony_ci{ 409526fd984Sopenharmony_ci double programTimes = 0; 410526fd984Sopenharmony_ci 411526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 412526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 413526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 414526fd984Sopenharmony_ci struct HksBlob authId = { .size = TEST_KEY_SIZE, .data = (uint8_t *)HksMalloc(TEST_KEY_SIZE) }; 415526fd984Sopenharmony_ci ASSERT_NE(authId.data, nullptr); 416526fd984Sopenharmony_ci 417526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 418526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_ECC }, 419526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_ECC_KEY_SIZE_224 }, 420526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY }, 421526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }, 422526fd984Sopenharmony_ci }; 423526fd984Sopenharmony_ci 424526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 425526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 426526fd984Sopenharmony_ci 427526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 428526fd984Sopenharmony_ci int32_t ret = HksGenerateRandom(paramInSet, &authId); 429526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 430526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 431526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 432526fd984Sopenharmony_ci 433526fd984Sopenharmony_ci HKS_FREE(authId.data); 434526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 435526fd984Sopenharmony_ci } 436526fd984Sopenharmony_ci HKS_LOG_I("HksGenerateRandom Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 437526fd984Sopenharmony_ci} 438526fd984Sopenharmony_ci 439526fd984Sopenharmony_ci/** 440526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest01100 441526fd984Sopenharmony_ci * @tc.name : PressureTest01100 442526fd984Sopenharmony_ci * @tc.desc : HksSign 443526fd984Sopenharmony_ci */ 444526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest01100, TestSize.Level1) 445526fd984Sopenharmony_ci{ 446526fd984Sopenharmony_ci double programTimes = 0; 447526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 448526fd984Sopenharmony_ci 449526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 450526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 451526fd984Sopenharmony_ci 452526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 453526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_PERSISTENT }, 454526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_ECC }, 455526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_ECC_KEY_SIZE_224 }, 456526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY }, 457526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }, 458526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = true }, 459526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 460526fd984Sopenharmony_ci }; 461526fd984Sopenharmony_ci 462526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 463526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 464526fd984Sopenharmony_ci 465526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, NULL); 466526fd984Sopenharmony_ci 467526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 468526fd984Sopenharmony_ci const char *hexData = "0123456789abcdef"; 469526fd984Sopenharmony_ci uint32_t dataLen = strlen(hexData); 470526fd984Sopenharmony_ci HksBlob message = { .size = dataLen, .data = (uint8_t *)hexData }; 471526fd984Sopenharmony_ci HksBlob signature = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 472526fd984Sopenharmony_ci ASSERT_NE(signature.data, nullptr); 473526fd984Sopenharmony_ci 474526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 475526fd984Sopenharmony_ci int32_t ret = HksSign(&authId, paramInSet, &message, &signature); 476526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 477526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 478526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 479526fd984Sopenharmony_ci 480526fd984Sopenharmony_ci HKS_FREE(signature.data); 481526fd984Sopenharmony_ci } 482526fd984Sopenharmony_ci HksDeleteKey(&authId, paramInSet); 483526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 484526fd984Sopenharmony_ci HKS_LOG_I("HksSign Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 485526fd984Sopenharmony_ci} 486526fd984Sopenharmony_ci 487526fd984Sopenharmony_ci/** 488526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest01200 489526fd984Sopenharmony_ci * @tc.name : PressureTest01200 490526fd984Sopenharmony_ci * @tc.desc : HksVerify 491526fd984Sopenharmony_ci */ 492526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest01200, TestSize.Level1) 493526fd984Sopenharmony_ci{ 494526fd984Sopenharmony_ci double programTimes = 0; 495526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 496526fd984Sopenharmony_ci 497526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 498526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 499526fd984Sopenharmony_ci 500526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 501526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_PERSISTENT }, 502526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_ECC }, 503526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_ECC_KEY_SIZE_224 }, 504526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY }, 505526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }, 506526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = true }, 507526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 508526fd984Sopenharmony_ci }; 509526fd984Sopenharmony_ci 510526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 511526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 512526fd984Sopenharmony_ci 513526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, NULL); 514526fd984Sopenharmony_ci const char *hexData = "0123456789abcdef"; 515526fd984Sopenharmony_ci uint32_t dataLen = strlen(hexData); 516526fd984Sopenharmony_ci HksBlob message = { .size = dataLen, .data = (uint8_t *)hexData }; 517526fd984Sopenharmony_ci HksBlob signature = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 518526fd984Sopenharmony_ci ASSERT_NE(signature.data, nullptr); 519526fd984Sopenharmony_ci 520526fd984Sopenharmony_ci HksSign(&authId, paramInSet, &message, &signature); 521526fd984Sopenharmony_ci 522526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 523526fd984Sopenharmony_ci 524526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 525526fd984Sopenharmony_ci int32_t ret = HksVerify(&authId, paramInSet, &message, &signature); 526526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 527526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 528526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 529526fd984Sopenharmony_ci } 530526fd984Sopenharmony_ci HksDeleteKey(&authId, paramInSet); 531526fd984Sopenharmony_ci HKS_FREE(signature.data); 532526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 533526fd984Sopenharmony_ci HKS_LOG_I("HksVerify Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 534526fd984Sopenharmony_ci} 535526fd984Sopenharmony_ci 536526fd984Sopenharmony_ci/** 537526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest01300 538526fd984Sopenharmony_ci * @tc.name : PressureTest01300 539526fd984Sopenharmony_ci * @tc.desc : HksEncrypt 540526fd984Sopenharmony_ci */ 541526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest01300, TestSize.Level1) 542526fd984Sopenharmony_ci{ 543526fd984Sopenharmony_ci double programTimes = 0; 544526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 545526fd984Sopenharmony_ci 546526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 547526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 548526fd984Sopenharmony_ci 549526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 550526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_PERSISTENT }, 551526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_AES }, 552526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, 553526fd984Sopenharmony_ci .uint32Param = HKS_AES_KEY_SIZE_128 }, 554526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT }, 555526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }, 556526fd984Sopenharmony_ci { .tag = HKS_TAG_PADDING, .uint32Param = HKS_PADDING_PKCS7 }, 557526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, 558526fd984Sopenharmony_ci .boolParam = true }, 559526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 560526fd984Sopenharmony_ci { .tag = HKS_TAG_BLOCK_MODE, .uint32Param = HKS_MODE_CBC }, 561526fd984Sopenharmony_ci }; 562526fd984Sopenharmony_ci 563526fd984Sopenharmony_ci uint8_t iv[IV_SIZE] = {0}; 564526fd984Sopenharmony_ci struct HksParam tagIv = { .tag = HKS_TAG_IV, .blob = { .size = IV_SIZE, .data = iv } }; 565526fd984Sopenharmony_ci HksAddParams(paramInSet, &tagIv, 1); 566526fd984Sopenharmony_ci 567526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 568526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 569526fd984Sopenharmony_ci 570526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, NULL); 571526fd984Sopenharmony_ci 572526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 573526fd984Sopenharmony_ci const char *hexData = "0123456789abcdef"; 574526fd984Sopenharmony_ci uint32_t dataLen = strlen(hexData); 575526fd984Sopenharmony_ci HksBlob plainText = { .size = dataLen, .data = (uint8_t *)hexData }; 576526fd984Sopenharmony_ci 577526fd984Sopenharmony_ci uint32_t inLen = dataLen + COMPLEMENT_LEN; 578526fd984Sopenharmony_ci HksBlob cipherText = { .size = inLen, .data = (uint8_t *)HksMalloc(inLen) }; 579526fd984Sopenharmony_ci ASSERT_NE(cipherText.data, nullptr); 580526fd984Sopenharmony_ci 581526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 582526fd984Sopenharmony_ci int32_t ret = HksEncrypt(&authId, paramInSet, &plainText, &cipherText); 583526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 584526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 585526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 586526fd984Sopenharmony_ci 587526fd984Sopenharmony_ci HKS_FREE(cipherText.data); 588526fd984Sopenharmony_ci } 589526fd984Sopenharmony_ci HksDeleteKey(&authId, paramInSet); 590526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 591526fd984Sopenharmony_ci HKS_LOG_I("HksEncrypt Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 592526fd984Sopenharmony_ci} 593526fd984Sopenharmony_ci 594526fd984Sopenharmony_ci/** 595526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest01400 596526fd984Sopenharmony_ci * @tc.name : PressureTest01400 597526fd984Sopenharmony_ci * @tc.desc : HksDecrypt 598526fd984Sopenharmony_ci */ 599526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest01400, TestSize.Level1) 600526fd984Sopenharmony_ci{ 601526fd984Sopenharmony_ci double programTimes = 0; 602526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 603526fd984Sopenharmony_ci uint8_t iv[IV_SIZE] = {0}; 604526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 605526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 606526fd984Sopenharmony_ci 607526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 608526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, 609526fd984Sopenharmony_ci .uint32Param = HKS_STORAGE_PERSISTENT }, 610526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_AES }, 611526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_AES_KEY_SIZE_128 }, 612526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT }, 613526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }, 614526fd984Sopenharmony_ci { .tag = HKS_TAG_PADDING, 615526fd984Sopenharmony_ci .uint32Param = HKS_PADDING_PKCS7 }, 616526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = true }, 617526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 618526fd984Sopenharmony_ci { .tag = HKS_TAG_BLOCK_MODE, .uint32Param = HKS_MODE_CBC }, 619526fd984Sopenharmony_ci }; 620526fd984Sopenharmony_ci 621526fd984Sopenharmony_ci struct HksParam tagIv = { .tag = HKS_TAG_IV, .blob = { .size = IV_SIZE, .data = iv } }; 622526fd984Sopenharmony_ci HksAddParams(paramInSet, &tagIv, 1); 623526fd984Sopenharmony_ci 624526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 625526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 626526fd984Sopenharmony_ci 627526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, NULL); 628526fd984Sopenharmony_ci 629526fd984Sopenharmony_ci const char *hexData = "0123456789abcdef"; 630526fd984Sopenharmony_ci uint32_t dataLen = strlen(hexData); 631526fd984Sopenharmony_ci HksBlob plainText = { .size = dataLen, .data = (uint8_t *)hexData }; 632526fd984Sopenharmony_ci 633526fd984Sopenharmony_ci uint32_t inLen = dataLen + COMPLEMENT_LEN; 634526fd984Sopenharmony_ci HksBlob cipherText = { .size = inLen, .data = (uint8_t *)HksMalloc(inLen) }; 635526fd984Sopenharmony_ci ASSERT_NE(cipherText.data, nullptr); 636526fd984Sopenharmony_ci 637526fd984Sopenharmony_ci HksEncrypt(&authId, paramInSet, &plainText, &cipherText); 638526fd984Sopenharmony_ci 639526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 640526fd984Sopenharmony_ci HksBlob plainTextDecrypt = { .size = inLen, .data = (uint8_t *)HksMalloc(inLen) }; 641526fd984Sopenharmony_ci ASSERT_NE(plainTextDecrypt.data, nullptr); 642526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 643526fd984Sopenharmony_ci int32_t ret = HksDecrypt(&authId, paramInSet, &cipherText, &plainTextDecrypt); 644526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 645526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 646526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 647526fd984Sopenharmony_ci 648526fd984Sopenharmony_ci HKS_FREE(plainTextDecrypt.data); 649526fd984Sopenharmony_ci } 650526fd984Sopenharmony_ci HksDeleteKey(&authId, paramInSet); 651526fd984Sopenharmony_ci HKS_FREE(cipherText.data); 652526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 653526fd984Sopenharmony_ci HKS_LOG_I("HksDecrypt Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 654526fd984Sopenharmony_ci} 655526fd984Sopenharmony_ci 656526fd984Sopenharmony_ci/** 657526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest01500 658526fd984Sopenharmony_ci * @tc.name : PressureTest01500 659526fd984Sopenharmony_ci * @tc.desc : HksAgreeKey 660526fd984Sopenharmony_ci */ 661526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest01500, TestSize.Level1) 662526fd984Sopenharmony_ci{ 663526fd984Sopenharmony_ci double programTimes = 0; 664526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 665526fd984Sopenharmony_ci 666526fd984Sopenharmony_ci struct HksParamSet *paramInSetForKey = nullptr; 667526fd984Sopenharmony_ci HksInitParamSet(¶mInSetForKey); 668526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 669526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 670526fd984Sopenharmony_ci 671526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 672526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_PERSISTENT }, 673526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_ECC_KEY_SIZE_224 }, 674526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_AGREE }, 675526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = true }, 676526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 677526fd984Sopenharmony_ci }; 678526fd984Sopenharmony_ci 679526fd984Sopenharmony_ci HksAddParams(paramInSetForKey, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 680526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 681526fd984Sopenharmony_ci 682526fd984Sopenharmony_ci HksParam algForKey = { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_ECC }; 683526fd984Sopenharmony_ci HksParam alg = { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_ECDH }; 684526fd984Sopenharmony_ci 685526fd984Sopenharmony_ci HksAddParams(paramInSetForKey, &algForKey, 1); 686526fd984Sopenharmony_ci HksAddParams(paramInSet, &alg, 1); 687526fd984Sopenharmony_ci HksParam degistForKey = { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }; 688526fd984Sopenharmony_ci HksAddParams(paramInSetForKey, °istForKey, 1); 689526fd984Sopenharmony_ci HksBuildParamSet(¶mInSetForKey); 690526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 691526fd984Sopenharmony_ci 692526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSetForKey, NULL); 693526fd984Sopenharmony_ci 694526fd984Sopenharmony_ci struct HksBlob pubKey = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 695526fd984Sopenharmony_ci ASSERT_NE(pubKey.data, nullptr); 696526fd984Sopenharmony_ci HksExportPublicKey(&authId, paramInSetForKey, &pubKey); 697526fd984Sopenharmony_ci 698526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 699526fd984Sopenharmony_ci HksBlob agreeKey = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 700526fd984Sopenharmony_ci ASSERT_NE(agreeKey.data, nullptr); 701526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 702526fd984Sopenharmony_ci int32_t ret = HksAgreeKey(paramInSet, &authId, &pubKey, &agreeKey); 703526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 704526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 705526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 706526fd984Sopenharmony_ci 707526fd984Sopenharmony_ci HKS_FREE(agreeKey.data); 708526fd984Sopenharmony_ci } 709526fd984Sopenharmony_ci HksDeleteKey(&authId, paramInSet); 710526fd984Sopenharmony_ci HKS_FREE(pubKey.data); 711526fd984Sopenharmony_ci HksFreeParamSet(¶mInSetForKey); 712526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 713526fd984Sopenharmony_ci HKS_LOG_I("HksAgreeKey Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 714526fd984Sopenharmony_ci} 715526fd984Sopenharmony_ci 716526fd984Sopenharmony_ci/** 717526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest01600 718526fd984Sopenharmony_ci * @tc.name : PressureTest01600 719526fd984Sopenharmony_ci * @tc.desc : HksDeriveKey 720526fd984Sopenharmony_ci */ 721526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest01600, TestSize.Level1) 722526fd984Sopenharmony_ci{ 723526fd984Sopenharmony_ci double programTimes = 0; 724526fd984Sopenharmony_ci 725526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 726526fd984Sopenharmony_ci 727526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 728526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 729526fd984Sopenharmony_ci 730526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 731526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_PERSISTENT }, 732526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_AES }, 733526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_AES_KEY_SIZE_128 }, 734526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_DERIVE }, 735526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_SHA256 }, 736526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = true }, 737526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 738526fd984Sopenharmony_ci }; 739526fd984Sopenharmony_ci 740526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 741526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 742526fd984Sopenharmony_ci 743526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, NULL); 744526fd984Sopenharmony_ci 745526fd984Sopenharmony_ci struct HksParamSet *paramInSetHkdf = nullptr; 746526fd984Sopenharmony_ci HksInitParamSet(¶mInSetHkdf); 747526fd984Sopenharmony_ci struct HksParam tmpParamsHkdf[] = { 748526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_PERSISTENT }, 749526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_HKDF }, 750526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = DERIVED_KEY_SIZE }, 751526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_DERIVE }, 752526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_SHA256 }, 753526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = true }, 754526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 755526fd984Sopenharmony_ci }; 756526fd984Sopenharmony_ci 757526fd984Sopenharmony_ci HksAddParams(paramInSetHkdf, tmpParamsHkdf, sizeof(tmpParamsHkdf) / sizeof(tmpParamsHkdf[0])); 758526fd984Sopenharmony_ci HksBuildParamSet(¶mInSetHkdf); 759526fd984Sopenharmony_ci 760526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 761526fd984Sopenharmony_ci HksBlob derivedKey = { .size = DERIVED_KEY_SIZE, .data = (uint8_t *)HksMalloc(DERIVED_KEY_SIZE) }; 762526fd984Sopenharmony_ci ASSERT_NE(derivedKey.data, nullptr); 763526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 764526fd984Sopenharmony_ci int32_t ret = HksDeriveKey(paramInSetHkdf, &authId, &derivedKey); 765526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 766526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 767526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 768526fd984Sopenharmony_ci 769526fd984Sopenharmony_ci HKS_FREE(derivedKey.data); 770526fd984Sopenharmony_ci } 771526fd984Sopenharmony_ci HksDeleteKey(&authId, paramInSet); 772526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 773526fd984Sopenharmony_ci HksFreeParamSet(¶mInSetHkdf); 774526fd984Sopenharmony_ci HKS_LOG_I("HksDeriveKey Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 775526fd984Sopenharmony_ci} 776526fd984Sopenharmony_ci 777526fd984Sopenharmony_ci/** 778526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest01700 779526fd984Sopenharmony_ci * @tc.name : PressureTest01700 780526fd984Sopenharmony_ci * @tc.desc : HksMac 781526fd984Sopenharmony_ci */ 782526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest01700, TestSize.Level1) 783526fd984Sopenharmony_ci{ 784526fd984Sopenharmony_ci double programTimes = 0; 785526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 786526fd984Sopenharmony_ci 787526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 788526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 789526fd984Sopenharmony_ci 790526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 791526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_PERSISTENT }, 792526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_HMAC }, 793526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = TEST_KEY_SIZE }, 794526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_MAC }, 795526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_SHA1 }, 796526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = true }, 797526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 798526fd984Sopenharmony_ci }; 799526fd984Sopenharmony_ci 800526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 801526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 802526fd984Sopenharmony_ci 803526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, NULL); 804526fd984Sopenharmony_ci 805526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 806526fd984Sopenharmony_ci const char *hexData = "0123456789abcdef"; 807526fd984Sopenharmony_ci uint32_t dataLen = strlen(hexData); 808526fd984Sopenharmony_ci HksBlob message = { .size = dataLen, .data = (uint8_t *)hexData }; 809526fd984Sopenharmony_ci HksBlob macMessage = { .size = MESSAGE_SIZE, .data = (uint8_t *)HksMalloc(MESSAGE_SIZE) }; 810526fd984Sopenharmony_ci ASSERT_NE(macMessage.data, nullptr); 811526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 812526fd984Sopenharmony_ci int32_t ret = HksMac(&authId, paramInSet, &message, &macMessage); 813526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 814526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 815526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 816526fd984Sopenharmony_ci 817526fd984Sopenharmony_ci HKS_FREE(macMessage.data); 818526fd984Sopenharmony_ci } 819526fd984Sopenharmony_ci HksDeleteKey(&authId, paramInSet); 820526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 821526fd984Sopenharmony_ci HKS_LOG_I("HksMac Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 822526fd984Sopenharmony_ci} 823526fd984Sopenharmony_ci 824526fd984Sopenharmony_ci/** 825526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest01800 826526fd984Sopenharmony_ci * @tc.name : PressureTest01800 827526fd984Sopenharmony_ci * @tc.desc : HksHash 828526fd984Sopenharmony_ci */ 829526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest01800, TestSize.Level1) 830526fd984Sopenharmony_ci{ 831526fd984Sopenharmony_ci double programTimes = 0; 832526fd984Sopenharmony_ci 833526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 834526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 835526fd984Sopenharmony_ci 836526fd984Sopenharmony_ci struct HksParam digest = { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_SHA1 }; 837526fd984Sopenharmony_ci HksAddParams(paramInSet, &digest, 1); 838526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 839526fd984Sopenharmony_ci 840526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 841526fd984Sopenharmony_ci const char *hexData = "0123456789abcdef"; 842526fd984Sopenharmony_ci uint32_t dataLen = strlen(hexData); 843526fd984Sopenharmony_ci HksBlob message = { .size = dataLen, .data = (uint8_t *)hexData }; 844526fd984Sopenharmony_ci HksBlob shaMessage = { .size = MESSAGE_SIZE, .data = (uint8_t *)HksMalloc(MESSAGE_SIZE) }; 845526fd984Sopenharmony_ci ASSERT_NE(shaMessage.data, nullptr); 846526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 847526fd984Sopenharmony_ci int32_t ret = HksHash(paramInSet, &message, &shaMessage); 848526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 849526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 850526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 851526fd984Sopenharmony_ci 852526fd984Sopenharmony_ci HKS_FREE(shaMessage.data); 853526fd984Sopenharmony_ci } 854526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 855526fd984Sopenharmony_ci HKS_LOG_I("HksHash Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 856526fd984Sopenharmony_ci} 857526fd984Sopenharmony_ci 858526fd984Sopenharmony_ci/** 859526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest01900 860526fd984Sopenharmony_ci * @tc.name : PressureTest01900 861526fd984Sopenharmony_ci * @tc.desc : HksGenerateKey 862526fd984Sopenharmony_ci */ 863526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest01900, TestSize.Level1) 864526fd984Sopenharmony_ci{ 865526fd984Sopenharmony_ci double programTimes = 0; 866526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 867526fd984Sopenharmony_ci 868526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 869526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 870526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 871526fd984Sopenharmony_ci 872526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 873526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_TEMP }, 874526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_ECC }, 875526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_ECC_KEY_SIZE_224 }, 876526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_VERIFY }, 877526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }, 878526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = false }, 879526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 880526fd984Sopenharmony_ci }; 881526fd984Sopenharmony_ci 882526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 883526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 884526fd984Sopenharmony_ci 885526fd984Sopenharmony_ci struct HksParamSet *paramOutSet = nullptr; 886526fd984Sopenharmony_ci HksInitParamSet(¶mOutSet); 887526fd984Sopenharmony_ci struct HksParam localKey = { .tag = HKS_TAG_SYMMETRIC_KEY_DATA, 888526fd984Sopenharmony_ci .blob = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) } }; 889526fd984Sopenharmony_ci ASSERT_NE(localKey.blob.data, nullptr); 890526fd984Sopenharmony_ci HksAddParams(paramOutSet, &localKey, 1); 891526fd984Sopenharmony_ci 892526fd984Sopenharmony_ci HksBuildParamSet(¶mOutSet); 893526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 894526fd984Sopenharmony_ci int32_t ret = HksGenerateKey(&authId, paramInSet, paramOutSet); 895526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 896526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 897526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 898526fd984Sopenharmony_ci 899526fd984Sopenharmony_ci HKS_FREE(localKey.blob.data); 900526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 901526fd984Sopenharmony_ci HksFreeParamSet(¶mOutSet); 902526fd984Sopenharmony_ci } 903526fd984Sopenharmony_ci HKS_LOG_I("Local HksGenerateKey Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 904526fd984Sopenharmony_ci} 905526fd984Sopenharmony_ci 906526fd984Sopenharmony_ci/** 907526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest02000 908526fd984Sopenharmony_ci * @tc.name : PressureTest02000 909526fd984Sopenharmony_ci * @tc.desc : HksSign 910526fd984Sopenharmony_ci */ 911526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest02000, TestSize.Level1) 912526fd984Sopenharmony_ci{ 913526fd984Sopenharmony_ci double programTimes = 0; 914526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 915526fd984Sopenharmony_ci 916526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 917526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 918526fd984Sopenharmony_ci 919526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 920526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_TEMP }, 921526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_ECC }, 922526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_ECC_KEY_SIZE_224 }, 923526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, 924526fd984Sopenharmony_ci .uint32Param = HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY }, 925526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }, 926526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = false }, 927526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, 928526fd984Sopenharmony_ci .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 929526fd984Sopenharmony_ci }; 930526fd984Sopenharmony_ci 931526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 932526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 933526fd984Sopenharmony_ci 934526fd984Sopenharmony_ci HksBlob priKey = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 935526fd984Sopenharmony_ci ASSERT_NE(priKey.data, nullptr); 936526fd984Sopenharmony_ci HksBlob pubKey = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 937526fd984Sopenharmony_ci ASSERT_NE(pubKey.data, nullptr); 938526fd984Sopenharmony_ci 939526fd984Sopenharmony_ci PressureTest::LocalHksGenerate(HKS_ECC_KEY_SIZE_224, &authId, paramInSet, &priKey, &pubKey); 940526fd984Sopenharmony_ci 941526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 942526fd984Sopenharmony_ci const char *hexData = "0123456789abcdef"; 943526fd984Sopenharmony_ci uint32_t dataLen = strlen(hexData); 944526fd984Sopenharmony_ci HksBlob message = { .size = dataLen, .data = (uint8_t *)hexData }; 945526fd984Sopenharmony_ci HksBlob signature = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 946526fd984Sopenharmony_ci ASSERT_NE(signature.data, nullptr); 947526fd984Sopenharmony_ci 948526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 949526fd984Sopenharmony_ci int32_t ret = HksSign(&priKey, paramInSet, &message, &signature); 950526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 951526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 952526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 953526fd984Sopenharmony_ci 954526fd984Sopenharmony_ci HKS_FREE(signature.data); 955526fd984Sopenharmony_ci } 956526fd984Sopenharmony_ci HKS_FREE(priKey.data); 957526fd984Sopenharmony_ci HKS_FREE(pubKey.data); 958526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 959526fd984Sopenharmony_ci HKS_LOG_I("Local HksSign Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 960526fd984Sopenharmony_ci} 961526fd984Sopenharmony_ci 962526fd984Sopenharmony_ci/** 963526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest02100 964526fd984Sopenharmony_ci * @tc.name : PressureTest02100 965526fd984Sopenharmony_ci * @tc.desc : HksVerify 966526fd984Sopenharmony_ci */ 967526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest02100, TestSize.Level1) 968526fd984Sopenharmony_ci{ 969526fd984Sopenharmony_ci double programTimes = 0; 970526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 971526fd984Sopenharmony_ci 972526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 973526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 974526fd984Sopenharmony_ci 975526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 976526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_TEMP }, 977526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_ECC }, 978526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_ECC_KEY_SIZE_224 }, 979526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY }, 980526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }, 981526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = false }, 982526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 983526fd984Sopenharmony_ci }; 984526fd984Sopenharmony_ci 985526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 986526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 987526fd984Sopenharmony_ci 988526fd984Sopenharmony_ci HksBlob priKey = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 989526fd984Sopenharmony_ci ASSERT_NE(priKey.data, nullptr); 990526fd984Sopenharmony_ci HksBlob pubKey = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 991526fd984Sopenharmony_ci ASSERT_NE(pubKey.data, nullptr); 992526fd984Sopenharmony_ci 993526fd984Sopenharmony_ci PressureTest::LocalHksGenerate(HKS_ECC_KEY_SIZE_224, &authId, paramInSet, &priKey, &pubKey); 994526fd984Sopenharmony_ci 995526fd984Sopenharmony_ci const char *hexData = "0123456789abcdef"; 996526fd984Sopenharmony_ci uint32_t dataLen = strlen(hexData); 997526fd984Sopenharmony_ci HksBlob message = { .size = dataLen, .data = (uint8_t *)hexData }; 998526fd984Sopenharmony_ci HksBlob signature = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 999526fd984Sopenharmony_ci ASSERT_NE(signature.data, nullptr); 1000526fd984Sopenharmony_ci 1001526fd984Sopenharmony_ci HksSign(&priKey, paramInSet, &message, &signature); 1002526fd984Sopenharmony_ci 1003526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 1004526fd984Sopenharmony_ci 1005526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 1006526fd984Sopenharmony_ci int32_t ret = HksVerify(&pubKey, paramInSet, &message, &signature); 1007526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 1008526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 1009526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 1010526fd984Sopenharmony_ci } 1011526fd984Sopenharmony_ci HKS_FREE(priKey.data); 1012526fd984Sopenharmony_ci HKS_FREE(pubKey.data); 1013526fd984Sopenharmony_ci HKS_FREE(signature.data); 1014526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 1015526fd984Sopenharmony_ci HKS_LOG_I("Local HksVerify Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 1016526fd984Sopenharmony_ci} 1017526fd984Sopenharmony_ci 1018526fd984Sopenharmony_ci/** 1019526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest02200 1020526fd984Sopenharmony_ci * @tc.name : PressureTest02200 1021526fd984Sopenharmony_ci * @tc.desc : HksEncrypt 1022526fd984Sopenharmony_ci */ 1023526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest02200, TestSize.Level1) 1024526fd984Sopenharmony_ci{ 1025526fd984Sopenharmony_ci double programTimes = 0; 1026526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 1027526fd984Sopenharmony_ci 1028526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 1029526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 1030526fd984Sopenharmony_ci 1031526fd984Sopenharmony_ci uint8_t iv[IV_SIZE] = {0}; 1032526fd984Sopenharmony_ci struct HksParam tagIv = { .tag = HKS_TAG_IV, .blob = { .size = IV_SIZE, .data = iv } }; 1033526fd984Sopenharmony_ci HksAddParams(paramInSet, &tagIv, 1); 1034526fd984Sopenharmony_ci 1035526fd984Sopenharmony_ci HksAddParams(paramInSet, PARAMS_FOR_ENCRYPT, sizeof(PARAMS_FOR_ENCRYPT) / sizeof(PARAMS_FOR_ENCRYPT[0])); 1036526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 1037526fd984Sopenharmony_ci 1038526fd984Sopenharmony_ci struct HksParamSet *paramOutSet = nullptr; 1039526fd984Sopenharmony_ci HksInitParamSet(¶mOutSet); 1040526fd984Sopenharmony_ci struct HksParam localKey = { .tag = HKS_TAG_SYMMETRIC_KEY_DATA, 1041526fd984Sopenharmony_ci .blob = { .size = HKS_AES_KEY_SIZE_128, .data = (uint8_t *)HksMalloc(HKS_AES_KEY_SIZE_128) } }; 1042526fd984Sopenharmony_ci ASSERT_NE(localKey.blob.data, nullptr); 1043526fd984Sopenharmony_ci HksAddParams(paramOutSet, &localKey, 1); 1044526fd984Sopenharmony_ci HksBuildParamSet(¶mOutSet); 1045526fd984Sopenharmony_ci 1046526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, paramOutSet); 1047526fd984Sopenharmony_ci 1048526fd984Sopenharmony_ci HksParam *paramOut = nullptr; 1049526fd984Sopenharmony_ci HksGetParam(paramOutSet, HKS_TAG_SYMMETRIC_KEY_DATA, ¶mOut); 1050526fd984Sopenharmony_ci HksBlob authKey = { .size = paramOut->blob.size, .data = (uint8_t *)HksMalloc(paramOut->blob.size) }; 1051526fd984Sopenharmony_ci ASSERT_NE(authKey.data, nullptr); 1052526fd984Sopenharmony_ci (void)memcpy_s(authKey.data, paramOut->blob.size, paramOut->blob.data, paramOut->blob.size); 1053526fd984Sopenharmony_ci 1054526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 1055526fd984Sopenharmony_ci const char *hexData = "0123456789abcdef"; 1056526fd984Sopenharmony_ci uint32_t dataLen = strlen(hexData); 1057526fd984Sopenharmony_ci HksBlob plainText = { .size = dataLen, .data = (uint8_t *)hexData }; 1058526fd984Sopenharmony_ci 1059526fd984Sopenharmony_ci uint32_t inLen = dataLen + COMPLEMENT_LEN; 1060526fd984Sopenharmony_ci HksBlob cipherText = { .size = inLen, .data = (uint8_t *)HksMalloc(inLen) }; 1061526fd984Sopenharmony_ci ASSERT_NE(cipherText.data, nullptr); 1062526fd984Sopenharmony_ci 1063526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 1064526fd984Sopenharmony_ci int32_t ret = HksEncrypt(&authKey, paramInSet, &plainText, &cipherText); 1065526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 1066526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 1067526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 1068526fd984Sopenharmony_ci 1069526fd984Sopenharmony_ci HKS_FREE(cipherText.data); 1070526fd984Sopenharmony_ci } 1071526fd984Sopenharmony_ci HKS_FREE(localKey.blob.data); 1072526fd984Sopenharmony_ci HKS_FREE(authKey.data); 1073526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 1074526fd984Sopenharmony_ci HksFreeParamSet(¶mOutSet); 1075526fd984Sopenharmony_ci HKS_LOG_I("Local HksEncrypt Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 1076526fd984Sopenharmony_ci} 1077526fd984Sopenharmony_ci 1078526fd984Sopenharmony_ci/** 1079526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest02300 1080526fd984Sopenharmony_ci * @tc.name : PressureTest02300 1081526fd984Sopenharmony_ci * @tc.desc : HksDecrypt 1082526fd984Sopenharmony_ci */ 1083526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest02300, TestSize.Level1) 1084526fd984Sopenharmony_ci{ 1085526fd984Sopenharmony_ci double programTimes = 0; 1086526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 1087526fd984Sopenharmony_ci 1088526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 1089526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 1090526fd984Sopenharmony_ci 1091526fd984Sopenharmony_ci uint8_t iv[IV_SIZE] = {0}; 1092526fd984Sopenharmony_ci struct HksParam tagIv = { .tag = HKS_TAG_IV, .blob = { .size = IV_SIZE, .data = iv } }; 1093526fd984Sopenharmony_ci HksAddParams(paramInSet, &tagIv, 1); 1094526fd984Sopenharmony_ci 1095526fd984Sopenharmony_ci HksAddParams(paramInSet, PARAMS_FOR_DECRYPT, sizeof(PARAMS_FOR_DECRYPT) / sizeof(PARAMS_FOR_DECRYPT[0])); 1096526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 1097526fd984Sopenharmony_ci 1098526fd984Sopenharmony_ci struct HksParamSet *paramOutSet = nullptr; 1099526fd984Sopenharmony_ci HksInitParamSet(¶mOutSet); 1100526fd984Sopenharmony_ci struct HksParam localKey = { .tag = HKS_TAG_SYMMETRIC_KEY_DATA, 1101526fd984Sopenharmony_ci .blob = { .size = HKS_AES_KEY_SIZE_128, .data = (uint8_t *)HksMalloc(HKS_AES_KEY_SIZE_128) } }; 1102526fd984Sopenharmony_ci ASSERT_NE(localKey.blob.data, nullptr); 1103526fd984Sopenharmony_ci HksAddParams(paramOutSet, &localKey, 1); 1104526fd984Sopenharmony_ci HksBuildParamSet(¶mOutSet); 1105526fd984Sopenharmony_ci 1106526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, paramOutSet); 1107526fd984Sopenharmony_ci 1108526fd984Sopenharmony_ci HksParam *paramOut = nullptr; 1109526fd984Sopenharmony_ci HksGetParam(paramOutSet, HKS_TAG_SYMMETRIC_KEY_DATA, ¶mOut); 1110526fd984Sopenharmony_ci HksBlob authKey = { .size = paramOut->blob.size, .data = (uint8_t *)HksMalloc(paramOut->blob.size) }; 1111526fd984Sopenharmony_ci ASSERT_NE(authKey.data, nullptr); 1112526fd984Sopenharmony_ci (void)memcpy_s(authKey.data, paramOut->blob.size, paramOut->blob.data, paramOut->blob.size); 1113526fd984Sopenharmony_ci 1114526fd984Sopenharmony_ci const char *hexData = "0123456789abcdef"; 1115526fd984Sopenharmony_ci uint32_t dataLen = strlen(hexData); 1116526fd984Sopenharmony_ci HksBlob plainText = { .size = dataLen, .data = (uint8_t *)hexData }; 1117526fd984Sopenharmony_ci 1118526fd984Sopenharmony_ci uint32_t inLen = dataLen + COMPLEMENT_LEN; 1119526fd984Sopenharmony_ci HksBlob cipherText = { .size = inLen, .data = (uint8_t *)HksMalloc(inLen) }; 1120526fd984Sopenharmony_ci ASSERT_NE(cipherText.data, nullptr); 1121526fd984Sopenharmony_ci 1122526fd984Sopenharmony_ci HksEncrypt(&authKey, paramInSet, &plainText, &cipherText); 1123526fd984Sopenharmony_ci 1124526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 1125526fd984Sopenharmony_ci HksBlob plainTextDecrypt = { .size = inLen, .data = (uint8_t *)HksMalloc(inLen) }; 1126526fd984Sopenharmony_ci ASSERT_NE(plainTextDecrypt.data, nullptr); 1127526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 1128526fd984Sopenharmony_ci int32_t ret = HksDecrypt(&authKey, paramInSet, &cipherText, &plainTextDecrypt); 1129526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 1130526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 1131526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 1132526fd984Sopenharmony_ci 1133526fd984Sopenharmony_ci HKS_FREE(plainTextDecrypt.data); 1134526fd984Sopenharmony_ci } 1135526fd984Sopenharmony_ci HKS_FREE(localKey.blob.data); 1136526fd984Sopenharmony_ci HKS_FREE(authKey.data); 1137526fd984Sopenharmony_ci HKS_FREE(cipherText.data); 1138526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 1139526fd984Sopenharmony_ci HksFreeParamSet(¶mOutSet); 1140526fd984Sopenharmony_ci HKS_LOG_I("Local HksDecrypt Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 1141526fd984Sopenharmony_ci} 1142526fd984Sopenharmony_ci 1143526fd984Sopenharmony_ci/** 1144526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest02400 1145526fd984Sopenharmony_ci * @tc.name : PressureTest02400 1146526fd984Sopenharmony_ci * @tc.desc : HksAgreeKey 1147526fd984Sopenharmony_ci */ 1148526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest02400, TestSize.Level1) 1149526fd984Sopenharmony_ci{ 1150526fd984Sopenharmony_ci double programTimes = 0; 1151526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 1152526fd984Sopenharmony_ci 1153526fd984Sopenharmony_ci struct HksParamSet *paramInSetForKey = nullptr; 1154526fd984Sopenharmony_ci HksInitParamSet(¶mInSetForKey); 1155526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 1156526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 1157526fd984Sopenharmony_ci 1158526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 1159526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_TEMP }, 1160526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_ECC_KEY_SIZE_224 }, 1161526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_AGREE }, 1162526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = false }, 1163526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 1164526fd984Sopenharmony_ci }; 1165526fd984Sopenharmony_ci 1166526fd984Sopenharmony_ci HksAddParams(paramInSetForKey, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 1167526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 1168526fd984Sopenharmony_ci 1169526fd984Sopenharmony_ci HksParam algForKey = { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_ECC }; 1170526fd984Sopenharmony_ci HksParam alg = { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_ECDH }; 1171526fd984Sopenharmony_ci 1172526fd984Sopenharmony_ci HksAddParams(paramInSetForKey, &algForKey, 1); 1173526fd984Sopenharmony_ci HksAddParams(paramInSet, &alg, 1); 1174526fd984Sopenharmony_ci HksParam degistForKey = { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_NONE }; 1175526fd984Sopenharmony_ci HksAddParams(paramInSetForKey, °istForKey, 1); 1176526fd984Sopenharmony_ci HksBuildParamSet(¶mInSetForKey); 1177526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 1178526fd984Sopenharmony_ci 1179526fd984Sopenharmony_ci HksBlob priKey = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 1180526fd984Sopenharmony_ci ASSERT_NE(priKey.data, nullptr); 1181526fd984Sopenharmony_ci HksBlob pubKey = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 1182526fd984Sopenharmony_ci ASSERT_NE(pubKey.data, nullptr); 1183526fd984Sopenharmony_ci 1184526fd984Sopenharmony_ci PressureTest::LocalHksGenerate(HKS_ECC_KEY_SIZE_224, &authId, paramInSetForKey, &priKey, &pubKey); 1185526fd984Sopenharmony_ci 1186526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 1187526fd984Sopenharmony_ci HksBlob agreeKey = { .size = HKS_ECC_KEY_SIZE_224, .data = (uint8_t *)HksMalloc(HKS_ECC_KEY_SIZE_224) }; 1188526fd984Sopenharmony_ci ASSERT_NE(agreeKey.data, nullptr); 1189526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 1190526fd984Sopenharmony_ci int32_t ret = HksAgreeKey(paramInSet, &priKey, &pubKey, &agreeKey); 1191526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 1192526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 1193526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 1194526fd984Sopenharmony_ci 1195526fd984Sopenharmony_ci HKS_FREE(agreeKey.data); 1196526fd984Sopenharmony_ci } 1197526fd984Sopenharmony_ci HKS_FREE(priKey.data); 1198526fd984Sopenharmony_ci HKS_FREE(pubKey.data); 1199526fd984Sopenharmony_ci HksFreeParamSet(¶mInSetForKey); 1200526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 1201526fd984Sopenharmony_ci HKS_LOG_I("Local HksAgreeKey Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 1202526fd984Sopenharmony_ci} 1203526fd984Sopenharmony_ci 1204526fd984Sopenharmony_ci/** 1205526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest02500 1206526fd984Sopenharmony_ci * @tc.name : PressureTest02500 1207526fd984Sopenharmony_ci * @tc.desc : HksDeriveKey 1208526fd984Sopenharmony_ci */ 1209526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest02500, TestSize.Level1) 1210526fd984Sopenharmony_ci{ 1211526fd984Sopenharmony_ci double programTimes = 0; 1212526fd984Sopenharmony_ci struct HksBlob authId = { .size = TEST_KEY_SIZE, .data = (uint8_t *)HksMalloc(TEST_KEY_SIZE) }; 1213526fd984Sopenharmony_ci ASSERT_NE(authId.data, nullptr); 1214526fd984Sopenharmony_ci 1215526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 1216526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 1217526fd984Sopenharmony_ci 1218526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 1219526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_TEMP }, 1220526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_HKDF }, 1221526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = DERIVED_KEY_SIZE }, 1222526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_DERIVE }, 1223526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_SHA256 }, 1224526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = false }, 1225526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 1226526fd984Sopenharmony_ci }; 1227526fd984Sopenharmony_ci 1228526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 1229526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 1230526fd984Sopenharmony_ci 1231526fd984Sopenharmony_ci HksGenerateRandom(paramInSet, &authId); 1232526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 1233526fd984Sopenharmony_ci HksBlob derivedKey = { .size = DERIVED_KEY_SIZE, .data = (uint8_t *)HksMalloc(DERIVED_KEY_SIZE) }; 1234526fd984Sopenharmony_ci ASSERT_NE(derivedKey.data, nullptr); 1235526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 1236526fd984Sopenharmony_ci int32_t ret = HksDeriveKey(paramInSet, &authId, &derivedKey); 1237526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 1238526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 1239526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 1240526fd984Sopenharmony_ci 1241526fd984Sopenharmony_ci HKS_FREE(derivedKey.data); 1242526fd984Sopenharmony_ci } 1243526fd984Sopenharmony_ci HKS_FREE(authId.data); 1244526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 1245526fd984Sopenharmony_ci HKS_LOG_I("Local HksDeriveKey Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 1246526fd984Sopenharmony_ci} 1247526fd984Sopenharmony_ci 1248526fd984Sopenharmony_ci/** 1249526fd984Sopenharmony_ci * @tc.number : PressureTest.PressureTest02600 1250526fd984Sopenharmony_ci * @tc.name : PressureTest02600 1251526fd984Sopenharmony_ci * @tc.desc : HksMac 1252526fd984Sopenharmony_ci */ 1253526fd984Sopenharmony_ciHWTEST_F(PressureTest, PressureTest02600, TestSize.Level1) 1254526fd984Sopenharmony_ci{ 1255526fd984Sopenharmony_ci double programTimes = 0; 1256526fd984Sopenharmony_ci struct HksBlob authId = { strlen(GENERATE_KEY), (uint8_t *)GENERATE_KEY }; 1257526fd984Sopenharmony_ci 1258526fd984Sopenharmony_ci struct HksParamSet *paramInSet = nullptr; 1259526fd984Sopenharmony_ci HksInitParamSet(¶mInSet); 1260526fd984Sopenharmony_ci 1261526fd984Sopenharmony_ci struct HksParam tmpParams[] = { 1262526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_STORAGE_FLAG, .uint32Param = HKS_STORAGE_TEMP }, 1263526fd984Sopenharmony_ci { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_HMAC }, 1264526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_SIZE, .uint32Param = TEST_KEY_SIZE }, 1265526fd984Sopenharmony_ci { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_MAC }, 1266526fd984Sopenharmony_ci { .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_SHA1 }, 1267526fd984Sopenharmony_ci { .tag = HKS_TAG_IS_KEY_ALIAS, .boolParam = false }, 1268526fd984Sopenharmony_ci { .tag = HKS_TAG_KEY_GENERATE_TYPE, .uint32Param = HKS_KEY_GENERATE_TYPE_DEFAULT }, 1269526fd984Sopenharmony_ci }; 1270526fd984Sopenharmony_ci 1271526fd984Sopenharmony_ci HksAddParams(paramInSet, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0])); 1272526fd984Sopenharmony_ci HksBuildParamSet(¶mInSet); 1273526fd984Sopenharmony_ci 1274526fd984Sopenharmony_ci struct HksParamSet *paramOutSet = nullptr; 1275526fd984Sopenharmony_ci HksInitParamSet(¶mOutSet); 1276526fd984Sopenharmony_ci struct HksParam localKey = { .tag = HKS_TAG_SYMMETRIC_KEY_DATA, 1277526fd984Sopenharmony_ci .blob = { .size = HKS_AES_KEY_SIZE_128, .data = (uint8_t *)HksMalloc(HKS_AES_KEY_SIZE_128) } }; 1278526fd984Sopenharmony_ci ASSERT_NE(localKey.blob.data, nullptr); 1279526fd984Sopenharmony_ci HksAddParams(paramOutSet, &localKey, 1); 1280526fd984Sopenharmony_ci HksBuildParamSet(¶mOutSet); 1281526fd984Sopenharmony_ci 1282526fd984Sopenharmony_ci HksGenerateKey(&authId, paramInSet, paramOutSet); 1283526fd984Sopenharmony_ci 1284526fd984Sopenharmony_ci HksParam *paramOut = nullptr; 1285526fd984Sopenharmony_ci HksGetParam(paramOutSet, HKS_TAG_SYMMETRIC_KEY_DATA, ¶mOut); 1286526fd984Sopenharmony_ci HksBlob authKey = { .size = paramOut->blob.size, .data = (uint8_t *)HksMalloc(paramOut->blob.size) }; 1287526fd984Sopenharmony_ci ASSERT_NE(authKey.data, nullptr); 1288526fd984Sopenharmony_ci (void)memcpy_s(authKey.data, paramOut->blob.size, paramOut->blob.data, paramOut->blob.size); 1289526fd984Sopenharmony_ci 1290526fd984Sopenharmony_ci for (uint32_t ii = 0; ii < TEST_FREQUENCY; ii++) { 1291526fd984Sopenharmony_ci const char *hexData = "0123456789abcdef"; 1292526fd984Sopenharmony_ci uint32_t dataLen = strlen(hexData); 1293526fd984Sopenharmony_ci HksBlob message = { .size = dataLen, .data = (uint8_t *)hexData }; 1294526fd984Sopenharmony_ci HksBlob macMessage = { .size = MESSAGE_SIZE, .data = (uint8_t *)HksMalloc(MESSAGE_SIZE) }; 1295526fd984Sopenharmony_ci ASSERT_NE(macMessage.data, nullptr); 1296526fd984Sopenharmony_ci auto start = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 1297526fd984Sopenharmony_ci int32_t ret = HksMac(&authKey, paramInSet, &message, &macMessage); 1298526fd984Sopenharmony_ci auto end = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); 1299526fd984Sopenharmony_ci EXPECT_EQ(ret, HKS_SUCCESS); 1300526fd984Sopenharmony_ci programTimes += (end.time_since_epoch().count() - start.time_since_epoch().count()); 1301526fd984Sopenharmony_ci 1302526fd984Sopenharmony_ci HKS_FREE(macMessage.data); 1303526fd984Sopenharmony_ci } 1304526fd984Sopenharmony_ci HKS_FREE(localKey.blob.data); 1305526fd984Sopenharmony_ci HKS_FREE(authKey.data); 1306526fd984Sopenharmony_ci HksFreeParamSet(¶mInSet); 1307526fd984Sopenharmony_ci HksFreeParamSet(¶mOutSet); 1308526fd984Sopenharmony_ci HKS_LOG_I("Local HksMac Interface Call Duration: %" LOG_PUBLIC "f", (programTimes / TEST_FREQUENCY)); 1309526fd984Sopenharmony_ci} 1310526fd984Sopenharmony_ci} // namespace