• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  * http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 
13 #ifndef TEST_CRYPTO_API_TYPES_H
14 #define TEST_CRYPTO_API_TYPES_H
15 #include "tee_trusted_storage_api.h"
16 #include "stddef.h"
17 #include "tee_crypto_api.h"
18 #include "tee_log.h"
19 
20 enum {
21     DATA_MODE_WHOLE  = 0,
22     DATA_MODE_SLICE = 1,
23 };
24 
25 #define DATA_EXPAND_SIZE 1024
26 #define AE_TAG_MAX_SIZE 64
27 #define MAX_STRING_NAME_LEN 100
28 
29 typedef struct {
30     uint32_t dataMode;
31     void *data;
32     size_t dataMallocSize;
33     size_t dataSize;
34     size_t dataUsed;
35     size_t sliceSize;
36     uint8_t aeTag[AE_TAG_MAX_SIZE];
37     size_t aeTagSize;
38 } ProcessInOutData;
39 
40 struct _IntermediateReprestation;
41 typedef int (*ActionEntryType)(struct _IntermediateReprestation *ir);
42 #define MAX_ACTIONS_SIZE 100
43 typedef struct {
44     // common test vector
45     char algName[MAX_STRING_NAME_LEN];                // ae, asymEn, asymSg, derive, digest, symEn, mac,
46     size_t operaMaxKeySize;                           // ae, asymEn, asymSg, derive,         symEn, mac,
47     size_t keySize;                                   // ae, asymEn, asymSg, derive,         symEn, mac,
48     char fwdKeyTypeName[MAX_STRING_NAME_LEN];         // ae, asymEn, asymSg, derive,         symEn, mac,
49     char bckKeyTypeName[MAX_STRING_NAME_LEN];         //     asymEn, asymSg, derive,                mac,
50     uint32_t fwdEngine;                               // ae, asymEn, asymSg, derive, digest, symEn, mac,
51     uint32_t bckEngine;                               // ae, asymEn, asymSg, derive, digest, symEn, mac,
52     size_t dataSize;                                  // ae, asymEn, asymSg, derive, digest, symEn, mac,
53     size_t sliceSize;                                 // ae, asymEn, asymSg, derive, digest, symEn, mac,
54     uint32_t expRet;                                  // ae, asymEn, asymSg, derive, digest, symEn, mac,
55     size_t ivLen;                                     //                                     symEn, mac,
56 
57     // ae test vector
58     size_t aeTagLen;                                  // ae,
59     size_t aeTagOSize;                                // ae,
60     size_t aeNonceLen;                                // ae,
61     uint8_t nonceByte;                                // ae,
62     size_t aeAadLenInit;                              // aes-ccm,
63     size_t aeAadLen;                                  // ae,
64     uint8_t aadByte;                                  // ae,
65 
66     // asym encrypt test vector
67     uint32_t rsaEnMgf1Hash;                           //     asymEn,
68 
69     // asym sign test vector
70     uint32_t rsaSgPssLen;                             //             asymSg,
71 
72     // ecc key gen nist
73     uint32_t ecKeyCurve;                              //     asymEn, asymSg, derive,
74     // rsa key gen pub exp id
75     uint32_t rsaGenPubExpId;                          //     asymEn, asymSg,
76     // dh key gen base prime xbits
77     uint32_t dhGenKeySize;                           //                     derive,
78     // common action sequence
79     ActionEntryType actions[MAX_ACTIONS_SIZE];        // ae, asymEn, asymSg, derive, digest, symEn, mac,
80     uint32_t actionsSize;                             // ae, asymEn, asymSg, derive, digest, symEn, mac,
81 } TestVector;
82 
83 enum {
84     ER_OK = 0,
85     ER_JF = 1,
86 };
87 
88 #define MAX_ACT_SEQ_LIST_SIZE  100
89 
90 typedef struct {
91     char algName[MAX_STRING_NAME_LEN];
92     uint32_t algValue;
93     uint32_t fwdMode;
94     uint32_t bckMode;
95     uint32_t operaKeyCount;
96     uint32_t needKeyCount;
97     uint32_t isSwitchFwdBckOperaKey;
98     char algOperaClassName[MAX_STRING_NAME_LEN];
99     uint32_t algOperaClassValue;
100 } AlgMapInfo;
101 enum {
102     NEED_NO_GEN_PARAMS = 0,
103     NEED_GEN_ECC_CURVE = 1,
104     NEED_DH_BASE_PRIME_XBITS = 2,
105     NEED_RSA_EXP_MAYBE = 3,
106 };
107 typedef struct {
108     uint8_t  keyTypeName[MAX_STRING_NAME_LEN];
109     uint32_t keyType;
110     uint32_t keyGenType;
111     uint32_t needGenParams;
112 } KeyTypeMapInfo;
113 
114 enum {
115     XTS_KEY_COUNT_TWO = 2,
116 };
117 
118 enum {
119     GROUP_BALANCED = 0,
120     GRUPP_NOT_BALANCED = 1,
121 };
122 typedef struct {
123     char *elementName;
124     ActionEntryType element;
125     char *inverseElementName;
126     ActionEntryType inverseElement;
127     uint32_t isBalanced;
128 } MonadReversibilityProperty;
129 #define MONAD_REVERSE_PROP_LIST_SIZE 100
130 #define AE_NONCE_BUFFER_SIZE 32
131 #define AE_TAG_BUFFER_SIZE 32
132 #define MAX_KEY_OBJECT_HANDLE_LIST_SIZE 2
133 #define MAX_TEST_KEY_ITEM_LIST_SIZE 100
134 typedef struct {
135     uint32_t keyType;
136     uint32_t keySize;
137     TEE_ObjectHandle keyObjList[MAX_KEY_OBJECT_HANDLE_LIST_SIZE];
138     size_t keyObjListSize;
139 } TestKeyItem;
140 
141 typedef struct _IntermediateReprestation {
142     // input factor space
143     TestVector *tv;  // ae, asymEn, asymSg, derive, digest, symEn, mac,
144 
145     // inner state factor space
146     AlgMapInfo *algMap;     // ae, asymEn, asymSg, derive, digest, symEn, mac,
147     KeyTypeMapInfo *fwdKeyMap; // ae, asymEn, asymSg, derive,         symEn, mac,
148     KeyTypeMapInfo *bckKeyMap; // ae, asymEn, asymSg, derive,         symEn, mac,
149 
150     // common factor
151     uint32_t algValue;      // ae, asymEn, asymSg, derive, digest, symEn, mac,
152 
153     uint32_t algOperaClassValue;  // ae, asymEn, asymSg, derive, digest, symEn, mac,
154 
155     uint32_t fwdMode;  // ae, asymEn, asymSg, derive, digest, symEn, mac,
156     uint32_t bckMode;  // ae, asymEn, asymSg, derive, digest, symEn, mac,
157 
158     uint32_t operaKeyCount;            // ae, asymEn, asymSg, derive,         symEn, mac,
159     uint32_t needKeyCount;             // ae, asymEn, asymSg, derive,         symEn, mac,
160     uint32_t isSwitchFwdBckOperaKey;   // ae, asymEn, asymSg, derive,         symEn, mac,
161 
162     size_t operaMaxKeySize;            // ae, asymEn, asymSg, derive,         symEn, mac,
163     size_t keySize;                    // ae, asymEn, asymSg, derive,         symEn, mac,
164 
165     uint32_t fwdKeyType;               // ae, asymEn, asymSg, derive,         symEn, mac,
166     uint32_t bckKeyType;               // ae, asymEn, asymSg, derive,         symEn, mac,
167     uint32_t genKeyType;               // ae, asymEn, asymSg, derive,         symEn, mac,
168 
169     uint32_t dataSize;                 // ae, asymEn, asymSg, derive, digest, symEn, mac,
170     uint32_t sliceSize;                // ae, asymEn, asymSg, derive, digest, symEn, mac,
171 
172     size_t ivLen;                      //                             digest, symEn, mac,
173 
174     size_t aeNonceLen;                 // ae,
175     uint8_t nonceByte;                 // ae,
176     uint8_t nonce[AE_NONCE_BUFFER_SIZE];  // ae,
177     size_t aeTagLen;                      // ae,
178     size_t aeTagOSize;                     // ae,
179     uint8_t aeTag[AE_TAG_BUFFER_SIZE];    // ae,
180     size_t aeAadLenInit;                      // aes-ccm,
181     size_t aeAadLen;                      // ae,
182     uint8_t aadByte;                      // ae,
183     uint8_t *pAad;                        // ae,
184 
185     size_t rsaEnMgf1Hash;              //     asymEn,
186     size_t rsaSgPssLen;                //             asymSg,
187 
188     uint32_t fwdEngine;                // ae, asymEn, asymSg, derive, digest, symEn, mac,
189     uint32_t bckEngine;                // ae, asymEn, asymSg, derive, digest, symEn, mac,
190 
191     uint32_t tvExpRet;                 // ae, asymEn, asymSg, derive, digest, symEn, mac,
192 
193     ProcessInOutData plainData;        // ae, asymEn, asymSg, derive, digest, symEn, mac,
194     ProcessInOutData cipherData;       // ae, asymEn, asymSg, derive, digest, symEn, mac,
195     ProcessInOutData decryptedData;    // ae, asymEn, asymSg, derive, digest, symEn, mac,
196 
197     TEE_OperationHandle fwdOperaHandle; // ae, asymEn, asymSg, derive, digest, symEn, mac,
198     TEE_OperationHandle bckOperaHandle; // ae, asymEn, asymSg, derive, digest, symEn, mac,
199 
200     TestKeyItem *tki;                   //                     derive,
201     // ecc key gen nist
202     uint32_t ecKeyCurve;                //     asymEn, asymSg, derive,
203     // rsa key gen pub exp id
204     uint32_t rsaGenPubExpId;            //     asymEn, asymSg,
205     // dh key gen base prime xbits
206     uint32_t dhGenKeySize;             //                     derive,
207 
208     MonadReversibilityProperty mrpl[MONAD_REVERSE_PROP_LIST_SIZE];
209     uint32_t mrplSize;
210 } IntermediateReprestation;
211 
212 enum {
213     ERROR_OK = 0,
214 };
215 
216 enum {
217     USE_DX = 0, // 使用DX引擎
218     USE_SW = 1, // 使用SW软引擎
219     USE_EP = 2, // 使用EPS引擎
220     USE_SE = 3, // 使用SEC引擎
221     USE_DF = 4, // 使用默认引擎
222 };
223 
224 typedef enum {
225     RSA_ENCRYPT_MGF_DEF = 0,
226     RSA_ENCYPT_MGF_SHA1 = 1,      // TEE_DH_HASH_SHA1_mode = 0
227     RSA_ENCYPT_MGF_SHA224 = 2,    // TEE_DH_HASH_SHA224_mode = 1,
228     RSA_ENCYPT_MGF_SHA256 = 3,    // TEE_DH_HASH_SHA256_mode = 2,
229     RSA_ENCYPT_MGF_SHA384 = 4,    // TEE_DH_HASH_SHA384_mode = 3,
230     RSA_ENCYPT_MGF_SHA512 = 5,    // TEE_DH_HASH_SHA512_mode = 4,
231     RSA_ENCYPT_MGF_COUNT,
232 } RsaEncryptMgfType;
233 
234 typedef enum {
235     TST_ECC_CURVE_NIST_NONE = 0,
236     TST_ECC_CURVE_NIST_P192 = 1,
237     TST_ECC_CURVE_NIST_P224 = 2,
238     TST_ECC_CURVE_NIST_P256 = 3,
239     TST_ECC_CURVE_NIST_P384 = 4,
240     TST_ECC_CURVE_NIST_P521 = 5,
241     TST_ECC_CURVE_SM2 = 6,
242     TST_ECC_CURVE_25519 = 7,
243     TST_ECC_CURVE_COUNT = 8,
244 } EccKeyGenCurve;
245 
246 enum {
247     TST_RSA_KEYGEN_PUB_EXP_ID_NULL = 0,
248     TST_RSA_KEYGEN_PUB_EXP_ID_0 = 1,
249     TST_RSA_KEYGEN_PUB_EXP_ID_1 = 2,
250     TST_RSA_KEYGEN_PUB_EXP_ID_2 = 3,
251     TST_RSA_KEYGEN_PUB_EXP_ID_3 = 4,
252     TST_RSA_KEYGEN_PUB_EXP_ID_4 = 5,
253 };
254 
255 #endif // end TEST_CRYPTO_API_TYPES_H
256