1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "hks_test_common.h"
17 
18 #include <limits.h>
19 
20 #include "hks_api.h"
21 #include "hks_param.h"
22 #include "hks_test_log.h"
23 #include "hks_test_mem.h"
24 
25 #define HKS_TEST_1024 1024
26 #define HKS_TEST_COMMON_8 8
27 #define HKS_TEST_COMMON_128 128
28 
29 int32_t TestConstuctBlob(struct HksBlob **blob, bool blobExist, uint32_t blobSize,
30     bool blobDataExist, uint32_t realBlobDataSize);
31 
32 int32_t TestGenerateKeyParamSetPre(struct GenerateKeyParamSetStructure *paramStruct, struct HksParamSet *paramSet);
33 
34 int32_t TestGenerateKeyParamSetPost(struct GenerateKeyParamSetStructure *paramStruct, struct HksParamSet *paramSet);
35 
36 int32_t TestConstructGenerateKeyParamSet(struct GenerateKeyParamSetStructure *paramStruct);
37 
38 int32_t TestConstructGenerateKeyParamSetOut(struct HksParamSet **outParamSet,
39     bool paramSetExist, uint32_t paramSetSize);
40 
41 int32_t TestConstructRsaCipherParamSet(struct TestRsaCipherParamSet *paramStruct);
42 
43 int32_t TestAesCipherParamSetPre(struct AesCipherParamSetStructure *paramStruct, struct HksParamSet *paramSet);
44 
45 int32_t TestAesCipherParamSetPost(struct AesCipherParamSetStructure *paramStruct, struct HksParamSet *paramSet);
46 
47 int32_t TestConstructAesCipherParamSet(struct AesCipherParamSetStructure *paramStruct);
48 
49 int32_t TestConstructMacParamSet(struct TestMacParamSetStructure *paramStruct);
50 
51 int32_t TestConstructAgreeParamSet(struct TestAgreeParamSetStructure *paramStruct);
52 
53 int32_t TestDeriveParamSetPre(struct TestDeriveParamSetStructure *paramStruct, struct HksParamSet *paramSet);
54 
55 int32_t TestDeriveParamSetPost(struct TestDeriveParamSetStructure *paramStruct, struct HksParamSet *paramSet);
56 
57 int32_t TestConstructDeriveParamSet(struct TestDeriveParamSetStructure *paramStruct);
58 
59 int32_t TestConstructHashParamSet(struct HksParamSet **outParamSet,
60     bool paramSetExist, bool setDigest, uint32_t digest);
61 
62 int32_t GenerateKey(struct HksBlob **keyAlias, const struct HksTestBlobParams *keyAliasParams,
63     const struct HksTestGenKeyParamsParamSet *genKeyParamSetParams,
64     const struct HksTestGenKeyParamsParamSetOut *genKeyParamSetParamsOut);
65 
66 int32_t GenerateLocalRandomKey(struct HksBlob **keyAlias, const struct HksTestBlobParams *localKeyParams);
67 
68 int32_t TestConstructBlobOut(struct HksBlob **blob, bool blobExist, uint32_t blobSize,
69     bool blobDataExist, uint32_t realBlobDataSize);
70 
71 int32_t GenerateLocalX25519Key(struct HksBlob **privateKey, struct HksBlob **publicKey,
72     const struct HksTestBlobParams *localPrivateKeyParams, const struct HksTestBlobParams *localPublicKeyParams);
73 
74 int32_t TestGenDefaultKeyAndGetAlias(struct HksBlob **keyAlias);
75 
76