• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HUKS_THREE_STAGE_TEST_COMMON_H
17 #define HUKS_THREE_STAGE_TEST_COMMON_H
18 
19 #include <securec.h>
20 
21 #include "native_huks_api.h"
22 #include "native_huks_param.h"
23 #include "native_huks_type.h"
24 #include "huks_mem.h"
25 #include <openssl/err.h>
26 #include <openssl/evp.h>
27 #include <stdbool.h>
28 #include <stddef.h>
29 #include "hks_api.h"
30 
31 #define HKS_DIGEST_MD5_LEN 16
32 #define HKS_DIGEST_SHA1_LEN 20
33 #define HKS_DIGEST_SHA224_LEN 28
34 #define HKS_DIGEST_SHA256_LEN 32
35 #define HKS_DIGEST_SHA384_LEN 48
36 #define HKS_DIGEST_SHA512_LEN 64
37 #define HKS_DIGEST_SM3_LEN 32
38 
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif
43 
44     static const uint32_t TIMES = 4;
45     static const uint32_t MAX_UPDATE_SIZE = 64;
46     static const uint32_t MAX_OUTDATA_SIZE = MAX_UPDATE_SIZE * TIMES;
47 
48     OH_Huks_Result InitParamSet(
49         struct OH_Huks_ParamSet **paramSet,
50         const struct OH_Huks_Param *params,
51         uint32_t paramcount);
52 
53     OH_Huks_Result HksTestUpdate(
54         const struct OH_Huks_Blob *handle,
55         const struct OH_Huks_ParamSet *paramSet,
56         const struct OH_Huks_Blob *inData);
57 
58     OH_Huks_Result TestUpdateLoopFinish(
59         const struct OH_Huks_Blob *handle,
60         const struct OH_Huks_ParamSet *paramSet,
61         const struct OH_Huks_Blob *inData,
62         struct OH_Huks_Blob *outData);
63 
64     OH_Huks_Result TestUpdateFinish(
65         const struct OH_Huks_Blob *handle,
66         const struct OH_Huks_ParamSet *paramSet,
67         uint32_t purpose,
68         const struct OH_Huks_Blob *inData,
69         struct OH_Huks_Blob *outData);
70 
71     OH_Huks_Result MallocAndCheckBlobData(
72         struct OH_Huks_Blob *blob,
73         const uint32_t blobSize);
74 
75     OH_Huks_Result TestCmpKeyAliasHash(
76         const struct OH_Huks_Blob *srcData1,
77         const struct OH_Huks_Blob *srcData2);
78 
79     OH_Huks_Result HuksEncrypt(
80         const struct OH_Huks_Blob *key,
81         const struct OH_Huks_ParamSet *paramSet,
82         const struct OH_Huks_Blob *plainText,
83         struct OH_Huks_Blob *cipherText);
84 
85     OH_Huks_Result HuksHash(
86         const struct OH_Huks_ParamSet *paramSet,
87         const struct OH_Huks_Blob *srcData,
88         struct OH_Huks_Blob *hash);
89 
90     OH_Huks_Result HuksAgreeKey(
91         const struct OH_Huks_ParamSet *paramSet,
92         const struct OH_Huks_Blob *keyAlias,
93         const struct OH_Huks_Blob *peerPublicKey,
94         struct OH_Huks_Blob *agreedKey);
95     bool checkUseSoftware();
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 #endif // HUKS_THREE_STAGE_TEST_COMMON_H