• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
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 __HI_UNF_CIPHER_H__
17 #define __HI_UNF_CIPHER_H__
18 
19 #include "hi_types.h"
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif /* __cplusplus */
26 /* ************************** Structure Definition *************************** */
27 /* max length of SM2, unit: word */
28 #define SM2_LEN_IN_WROD                   8
29 
30 /* max length of SM2, unit: byte */
31 #define SM2_LEN_IN_BYTE                   (SM2_LEN_IN_WROD * 4)
32 
33 /* CIPHER set IV for first package */
34 #define CIPHER_IV_CHANGE_ONE_PKG          1
35 
36 /* CIPHER set IV for first package */
37 #define CIPHER_IV_CHANGE_ALL_PKG          2
38 
39 #define DES_IV_SIZE_IN_WORD       2
40 #define IV_SIZE_IN_WORD           4
41 #define DES_KEY_SIZE_IN_WORD      2
42 #define TDES_KEY_SIZE_IN_WORD     6
43 #define AES_KEY_SIZE_IN_WORD      8
44 #define SM1_KEY_SIZE_IN_WORD      4
45 #define SM4_KEY_SIZE_IN_WORD      4
46 
47 /* Cipher work mode */
48 typedef enum hiHI_UNF_CIPHER_WORK_MODE_E {
49     HI_UNF_CIPHER_WORK_MODE_ECB,        /* Electronic codebook (ECB) mode */
50     HI_UNF_CIPHER_WORK_MODE_CBC,        /* Cipher block chaining (CBC) mode */
51     HI_UNF_CIPHER_WORK_MODE_CFB,        /* Cipher feedback (CFB) mode */
52     HI_UNF_CIPHER_WORK_MODE_OFB,        /* Output feedback (OFB) mode */
53     HI_UNF_CIPHER_WORK_MODE_CTR,        /* Counter (CTR) mode */
54     HI_UNF_CIPHER_WORK_MODE_CCM,        /* Counter (CCM) mode */
55     HI_UNF_CIPHER_WORK_MODE_GCM,        /* Counter (GCM) mode */
56     HI_UNF_CIPHER_WORK_MODE_CBC_CTS,    /* Cipher block chaining CipherStealing mode */
57     HI_UNF_CIPHER_WORK_MODE_BUTT,
58     HI_UNF_CIPHER_WORK_MODE_INVALID  = 0xffffffff,
59 } HI_UNF_CIPHER_WORK_MODE_E;
60 
61 /* Cipher algorithm */
62 typedef enum hiHI_UNF_CIPHER_ALG_E {
63     HI_UNF_CIPHER_ALG_DES           = 0x0,  /* Data encryption standard (DES) algorithm */
64     HI_UNF_CIPHER_ALG_3DES          = 0x1,  /* 3DES algorithm */
65     HI_UNF_CIPHER_ALG_AES           = 0x2,  /* Advanced encryption standard (AES) algorithm */
66     HI_UNF_CIPHER_ALG_SM1           = 0x3,  /* SM1 algorithm */
67     HI_UNF_CIPHER_ALG_SM4           = 0x4,  /* SM4 algorithm */
68     HI_UNF_CIPHER_ALG_DMA           = 0x5,  /* DMA copy */
69     HI_UNF_CIPHER_ALG_BUTT          = 0x6,
70     HI_UNF_CIPHER_ALG_INVALID       = 0xffffffff,
71 } HI_UNF_CIPHER_ALG_E;
72 
73 /* Key length */
74 typedef enum hiHI_UNF_CIPHER_KEY_LENGTH_E {
75     HI_UNF_CIPHER_KEY_AES_128BIT    = 0x0,  /* 128-bit key for the AES algorithm */
76     HI_UNF_CIPHER_KEY_AES_192BIT    = 0x1,  /* 192-bit key for the AES algorithm */
77     HI_UNF_CIPHER_KEY_AES_256BIT    = 0x2,  /* 256-bit key for the AES algorithm */
78     HI_UNF_CIPHER_KEY_DES_3KEY      = 0x2,  /* Three keys for the DES algorithm */
79     HI_UNF_CIPHER_KEY_DES_2KEY      = 0x3,  /* Two keys for the DES algorithm */
80     HI_UNF_CIPHER_KEY_DEFAULT       = 0x0,  /* default key length, DES-8, SM1-48, SM4-16 */
81     HI_UNF_CIPHER_KEY_INVALID       = 0xffffffff,
82 } HI_UNF_CIPHER_KEY_LENGTH_E;
83 
84 /* Cipher bit width */
85 typedef enum hiHI_UNF_CIPHER_BIT_WIDTH_E {
86     HI_UNF_CIPHER_BIT_WIDTH_64BIT   = 0x0,  /* 64-bit width */
87     HI_UNF_CIPHER_BIT_WIDTH_8BIT    = 0x1,  /* 8-bit width */
88     HI_UNF_CIPHER_BIT_WIDTH_1BIT    = 0x2,  /* 1-bit width */
89     HI_UNF_CIPHER_BIT_WIDTH_128BIT  = 0x3,  /* 128-bit width */
90     HI_UNF_CIPHER_BIT_WIDTH_INVALID = 0xffffffff,
91 } HI_UNF_CIPHER_BIT_WIDTH_E;
92 
93 /* Cipher control parameters */
94 typedef struct hiTEE_CIPHER_CTRL_CHANGE_FLAG_S {
95     HI_U32   bit1IV : 2;              /* Initial Vector change flag, 0-don't set, 1-set IV for first package, 2-set IV
96                                          for each package. */
97     HI_U32   bitsResv : 30;           /* Reserved */
98 } HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S;
99 
100 /* Key ladder selecting parameters */
101 typedef enum hiTEE_CIPHER_CA_TYPE_E {
102     HI_UNF_CIPHER_KEY_SRC_USER       = 0x0, /* User Key */
103     HI_UNF_CIPHER_KEY_SRC_KLAD_1,           /* KLAD Key 1 */
104     HI_UNF_CIPHER_KEY_SRC_KLAD_2,           /* KLAD Key 2 */
105     HI_UNF_CIPHER_KEY_SRC_KLAD_3,           /* KLAD Key 3 */
106     HI_UNF_CIPHER_KEY_SRC_BUTT,
107     HI_UNF_CIPHER_KEY_SRC_INVALID = 0xffffffff,
108 } HI_UNF_CIPHER_CA_TYPE_E;
109 
110 /* Encryption/Decryption type selecting */
111 typedef enum {
112     HI_UNF_CIPHER_KLAD_TARGET_AES       = 0x0,  /* Klad for AES */
113     HI_UNF_CIPHER_KLAD_TARGET_RSA,              /* Klad for RSA */
114     HI_UNF_CIPHER_KLAD_TARGET_BUTT,
115 } HI_UNF_CIPHER_KLAD_TARGET_E;
116 
117 /* Encryption/Decryption type selecting */
118 typedef enum {
119     HI_UNF_CIPHER_TYPE_NORMAL  = 0x0,
120     HI_UNF_CIPHER_TYPE_COPY_AVOID,
121     HI_UNF_CIPHER_TYPE_BUTT,
122     HI_UNF_CIPHER_TYPE_INVALID = 0xffffffff,
123 } HI_UNF_CIPHER_TYPE_E;
124 
125 /* Structure of the cipher type */
126 typedef struct {
127     HI_UNF_CIPHER_TYPE_E enCipherType;
128 } HI_UNF_CIPHER_ATTS_S;
129 
130 /* sm1 round config */
131 typedef enum hiHI_UNF_CIPHER_SM1_ROUND_E {
132     HI_UNF_CIPHER_SM1_ROUND_08 = 0x00,            /* sm1 round 08 */
133     HI_UNF_CIPHER_SM1_ROUND_10 = 0x01,            /* sm1 round 10 */
134     HI_UNF_CIPHER_SM1_ROUND_12 = 0x02,            /* sm1 round 12 */
135     HI_UNF_CIPHER_SM1_ROUND_14 = 0x03,            /* sm1 round 14 */
136     HI_UNF_CIPHER_SM1_ROUND_BUTT,
137     HI_UNF_CIPHER_SM1_ROUND_INVALID  = 0xffffffff,
138 } HI_UNF_CIPHER_SM1_ROUND_E;
139 
140 /* Structure of the cipher control information */
141 typedef struct hiHI_UNF_CIPHER_CTRL_S {
142     HI_U32 u32Key[AES_KEY_SIZE_IN_WORD];            /* Key input */
143     HI_U32 u32IV[IV_SIZE_IN_WORD];                  /* Initialization vector (IV) */
144     HI_BOOL bKeyByCA;                               /* Encryption using advanced conditional access (CA) or decryption
145                                                        using keys */
146     HI_UNF_CIPHER_CA_TYPE_E enCaType;               /* Select keyladder type when using advanced CA */
147     HI_UNF_CIPHER_ALG_E enAlg;                      /* Cipher algorithm */
148     HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth;           /* Bit width for encryption or decryption */
149     HI_UNF_CIPHER_WORK_MODE_E enWorkMode;           /* Operating mode */
150     HI_UNF_CIPHER_KEY_LENGTH_E enKeyLen;            /* Key length */
151     HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /* control information exchange choices, we default all would be
152                                                        change except they have been in the choices */
153 } HI_UNF_CIPHER_CTRL_S;
154 
155 /* Structure of the cipher AES control information */
156 typedef struct hiHI_UNF_CIPHER_CTRL_AES_S {
157     HI_U32 u32EvenKey[AES_KEY_SIZE_IN_WORD];        /* Key input, default use this key. */
158     HI_U32 u32OddKey[AES_KEY_SIZE_IN_WORD];         /* Key input, only valid for Multi encrypt/decrypt. */
159     HI_U32 u32IV[IV_SIZE_IN_WORD];                  /* Initialization vector (IV) */
160     HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth;           /* Bit width for encryption or decryption */
161     HI_UNF_CIPHER_KEY_LENGTH_E enKeyLen;            /* Key length */
162     HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /* control information exchange choices, we default all woulde be
163                                                        change except they have been in the choices */
164 } HI_UNF_CIPHER_CTRL_AES_S;
165 
166 /* Structure of the cipher AES CCM/GCM control information */
167 typedef struct hiHI_UNF_CIPHER_CTRL_AES_CCM_GCM_S {
168     HI_U32 u32Key[AES_KEY_SIZE_IN_WORD];            /* Key input */
169     HI_U32 u32IV[IV_SIZE_IN_WORD];                  /* Initialization vector (IV) */
170     HI_UNF_CIPHER_KEY_LENGTH_E enKeyLen;            /* Key length */
171     HI_U32 u32IVLen;                                /* IV length for CCM/GCM, which is an element of {4, 6, 8, 10, 12,
172                                                        14, 16}for CCM, and is an element of [1-16] for GCM. */
173     HI_U32 u32TagLen;                               /* Tag length for CCM which is an element of {4, 6, 8, 10, 12, 14,
174                                                        16}. */
175     HI_U32 u32ALen;                                 /* Associated data for CCM and GCM. */
176     HI_SIZE_T szAPhyAddr;                           /* Physical address of Associated data for CCM and GCM. */
177 } HI_UNF_CIPHER_CTRL_AES_CCM_GCM_S;
178 
179 /* Structure of the cipher DES control information */
180 typedef struct hiHI_UNF_CIPHER_CTRL_DES_S {
181     HI_U32 u32Key[DES_KEY_SIZE_IN_WORD];            /* Key input */
182     HI_U32 u32IV[DES_IV_SIZE_IN_WORD];              /* Initialization vector (IV) */
183     HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth;           /* Bit width for encryption or decryption */
184     HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /* control information exchange choices, we default all woulde be
185                                                        change except they have been in the choices */
186 } HI_UNF_CIPHER_CTRL_DES_S;
187 
188 /* Structure of the cipher 3DES control information */
189 typedef struct hiHI_UNF_CIPHER_CTRL_3DES_S {
190     HI_U32 u32Key[TDES_KEY_SIZE_IN_WORD];           /* Key input */
191     HI_U32 u32IV[DES_IV_SIZE_IN_WORD];              /* Initialization vector (IV) */
192     HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth;           /* Bit width for encryption or decryption */
193     HI_UNF_CIPHER_KEY_LENGTH_E enKeyLen;            /* Key length */
194     HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /* control information exchange choices, we default all woulde be
195                                                        change except they have been in the choices */
196 } HI_UNF_CIPHER_CTRL_3DES_S;
197 
198 /* Structure of the cipher SM1 control information */
199 typedef struct hiHI_UNF_CIPHER_CTRL_SM1_S {
200     HI_U32 u32EK[SM1_KEY_SIZE_IN_WORD];             /* Key of EK input */
201     HI_U32 u32AK[SM1_KEY_SIZE_IN_WORD];             /* Key of AK input */
202     HI_U32 u32SK[SM1_KEY_SIZE_IN_WORD];             /* Key of SK input */
203     HI_U32 u32IV[IV_SIZE_IN_WORD];                  /* Initialization vector (IV) */
204     HI_UNF_CIPHER_BIT_WIDTH_E enBitWidth;           /* Bit width for encryption or decryption */
205     HI_UNF_CIPHER_SM1_ROUND_E enSm1Round;           /* SM1 round number, should be 8, 10, 12 or 14. */
206     HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /* control information exchange choices, we default all woulde be
207                                                        change except they have been in the choices */
208 } HI_UNF_CIPHER_CTRL_SM1_S;
209 
210 /* Structure of the cipher SM4 control information */
211 typedef struct hiHI_UNF_CIPHER_CTRL_SM4_S {
212     HI_U32 u32Key[SM4_KEY_SIZE_IN_WORD];            /* Key  input */
213     HI_U32 u32IV[IV_SIZE_IN_WORD];                  /* Initialization vector (IV) */
214     HI_UNF_CIPHER_CTRL_CHANGE_FLAG_S stChangeFlags; /* control information exchange choices, we default all woulde be
215                                                        change except they have been in the choices */
216 } HI_UNF_CIPHER_CTRL_SM4_S;
217 
218 /* Expand Structure of the cipher control information */
219 typedef struct hiHI_UNF_CIPHER_CTRL_EX_S {
220     HI_UNF_CIPHER_ALG_E enAlg;                      /* Cipher algorithm */
221     HI_UNF_CIPHER_WORK_MODE_E enWorkMode;           /* Operating mode */
222     HI_BOOL bKeyByCA;                               /* Encryption using advanced conditional access (CA) or decryption
223                                                        using keys */
224     /* Parameter for special algorithm
225      * for AES, the pointer should point to HI_UNF_CIPHER_CTRL_AES_S;
226      * for AES_CCM or AES_GCM, the pointer should point to HI_UNF_CIPHER_CTRL_AES_CCM_GCM_S;
227      * for DES, the pointer should point to HI_UNF_CIPHER_CTRL_DES_S;
228      * for 3DES, the pointer should point to HI_UNF_CIPHER_CTRL_3DES_S;
229      * for SM1, the pointer should point to HI_UNF_CIPHER_CTRL_SM1_S;
230      * for SM4, the pointer should point to HI_UNF_CIPHER_CTRL_SM4_S;
231      */
232     HI_VOID *pParam;
233 } HI_UNF_CIPHER_CTRL_EX_S;
234 
235 /* Cipher data */
236 typedef struct hiHI_UNF_CIPHER_DATA_S {
237     HI_SIZE_T szSrcPhyAddr;     /* phy address of the original data */
238     HI_SIZE_T szDestPhyAddr;    /* phy address of the purpose data */
239     HI_U32 u32ByteLength;       /* cigher data length. */
240     HI_BOOL bOddKey;            /* Use odd key or even key. */
241 } HI_UNF_CIPHER_DATA_S;
242 
243 /* Hash algrithm type */
244 typedef enum hiHI_UNF_CIPHER_HASH_TYPE_E {
245     HI_UNF_CIPHER_HASH_TYPE_SHA1,
246     HI_UNF_CIPHER_HASH_TYPE_SHA224,
247     HI_UNF_CIPHER_HASH_TYPE_SHA256,
248     HI_UNF_CIPHER_HASH_TYPE_SHA384,
249     HI_UNF_CIPHER_HASH_TYPE_SHA512,
250     HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA1,
251     HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA224,
252     HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA256,
253     HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA384,
254     HI_UNF_CIPHER_HASH_TYPE_HMAC_SHA512,
255     HI_UNF_CIPHER_HASH_TYPE_SM3,
256     HI_UNF_CIPHER_HASH_TYPE_BUTT,
257     HI_UNF_CIPHER_HASH_TYPE_INVALID  = 0xffffffff,
258 } HI_UNF_CIPHER_HASH_TYPE_E;
259 
260 /* Hash init struct input */
261 typedef struct {
262     HI_U8 *pu8HMACKey;
263     HI_U32 u32HMACKeyLen;
264     HI_UNF_CIPHER_HASH_TYPE_E eShaType;
265 } HI_UNF_CIPHER_HASH_ATTS_S;
266 
267 typedef enum hiHI_UNF_CIPHER_RSA_ENC_SCHEME_E {
268     HI_UNF_CIPHER_RSA_ENC_SCHEME_NO_PADDING,            /* without padding */
269     HI_UNF_CIPHER_RSA_ENC_SCHEME_BLOCK_TYPE_0,          /* PKCS#1 block type 0 padding */
270     HI_UNF_CIPHER_RSA_ENC_SCHEME_BLOCK_TYPE_1,          /* PKCS#1 block type 1 padding */
271     HI_UNF_CIPHER_RSA_ENC_SCHEME_BLOCK_TYPE_2,          /* PKCS#1 block type 2 padding */
272     HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA1,       /* PKCS#1 RSAES-OAEP-SHA1 padding */
273     HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA224,     /* PKCS#1 RSAES-OAEP-SHA224 padding */
274     HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA256,     /* PKCS#1 RSAES-OAEP-SHA256 padding */
275     HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA384,     /* PKCS#1 RSAES-OAEP-SHA384 padding */
276     HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_OAEP_SHA512,     /* PKCS#1 RSAES-OAEP-SHA512 padding */
277     HI_UNF_CIPHER_RSA_ENC_SCHEME_RSAES_PKCS1_V1_5,      /* PKCS#1 RSAES-PKCS1_V1_5 padding */
278     HI_UNF_CIPHER_RSA_ENC_SCHEME_BUTT,
279     HI_UNF_CIPHER_RSA_ENC_SCHEME_INVALID  = 0xffffffff,
280 } HI_UNF_CIPHER_RSA_ENC_SCHEME_E;
281 
282 typedef enum hiHI_UNF_CIPHER_RSA_SIGN_SCHEME_E {
283     HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA1 = 0x100, /* PKCS#1 RSASSA_PKCS1_V15_SHA1 signature */
284     HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA224,       /* PKCS#1 RSASSA_PKCS1_V15_SHA224 signature */
285     HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA256,       /* PKCS#1 RSASSA_PKCS1_V15_SHA256 signature */
286     HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA384,       /* PKCS#1 RSASSA_PKCS1_V15_SHA384 signature */
287     HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_V15_SHA512,       /* PKCS#1 RSASSA_PKCS1_V15_SHA512 signature */
288     HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA1,         /* PKCS#1 RSASSA_PKCS1_PSS_SHA1 signature */
289     HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA224,       /* PKCS#1 RSASSA_PKCS1_PSS_SHA224 signature */
290     HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA256,       /* PKCS#1 RSASSA_PKCS1_PSS_SHA256 signature */
291     HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA384,       /* PKCS#1 RSASSA_PKCS1_PSS_SHA1 signature */
292     HI_UNF_CIPHER_RSA_SIGN_SCHEME_RSASSA_PKCS1_PSS_SHA512,       /* PKCS#1 RSASSA_PKCS1_PSS_SHA256 signature */
293     HI_UNF_CIPHER_RSA_SIGN_SCHEME_BUTT,
294     HI_UNF_CIPHER_RSA_SIGN_SCHEME_INVALID  = 0xffffffff,
295 } HI_UNF_CIPHER_RSA_SIGN_SCHEME_E;
296 
297 typedef struct {
298     HI_U8  *pu8N;              /* point to public modulus  */
299     HI_U8  *pu8E;              /* point to public exponent */
300     HI_U16 u16NLen;            /* length of public modulus, max value is 512Byte. */
301     HI_U16 u16ELen;            /* length of public exponent, max value is 512Byte. */
302 } HI_UNF_CIPHER_RSA_PUB_KEY_S;
303 
304 /* RSA private key struct */
305 typedef struct {
306     HI_U8 *pu8N;                      /* public modulus    */
307     HI_U8 *pu8E;                      /* public exponent   */
308     HI_U8 *pu8D;                      /* private exponent  */
309     HI_U8 *pu8P;                      /* 1st prime factor  */
310     HI_U8 *pu8Q;                      /* 2nd prime factor  */
311     HI_U8 *pu8DP;                     /* D % (P - 1)       */
312     HI_U8 *pu8DQ;                     /* D % (Q - 1)       */
313     HI_U8 *pu8QP;                     /* 1 / (Q % P)       */
314     HI_U16 u16NLen;                   /* length of public modulus */
315     HI_U16 u16ELen;                   /* length of public exponent */
316     HI_U16 u16DLen;                   /* length of private exponent */
317     HI_U16 u16PLen;                   /* length of 1st prime factor */
318     HI_U16 u16QLen;                   /* length of 2nd prime factor */
319     HI_U16 u16DPLen;                  /* length of D % (P - 1) */
320     HI_U16 u16DQLen;                  /* length of D % (Q - 1) */
321     HI_U16 u16QPLen;                  /* length of 1 / (Q % P) */
322 } HI_UNF_CIPHER_RSA_PRI_KEY_S;
323 
324 /* RSA public key encryption struct input */
325 typedef struct {
326     HI_UNF_CIPHER_RSA_ENC_SCHEME_E enScheme;   /* RSA encryption scheme */
327     HI_UNF_CIPHER_RSA_PUB_KEY_S stPubKey;      /* RSA private key struct */
328     HI_UNF_CIPHER_CA_TYPE_E enCaType;
329 } HI_UNF_CIPHER_RSA_PUB_ENC_S;
330 
331 /* RSA private key decryption struct input */
332 typedef struct {
333     HI_UNF_CIPHER_RSA_ENC_SCHEME_E enScheme;   /* RSA encryption scheme */
334     HI_UNF_CIPHER_RSA_PRI_KEY_S stPriKey;      /* RSA public key struct */
335     HI_UNF_CIPHER_CA_TYPE_E enCaType;
336 } HI_UNF_CIPHER_RSA_PRI_ENC_S;
337 
338 /* RSA signature struct input */
339 typedef struct {
340     HI_UNF_CIPHER_RSA_SIGN_SCHEME_E enScheme;  /* RSA signature scheme */
341     HI_UNF_CIPHER_RSA_PRI_KEY_S stPriKey;      /* RSA private key struct */
342     HI_UNF_CIPHER_CA_TYPE_E enCaType;
343 } HI_UNF_CIPHER_RSA_SIGN_S;
344 
345 /* RSA signature verify struct input */
346 typedef struct {
347     HI_UNF_CIPHER_RSA_SIGN_SCHEME_E enScheme;  /* RSA signature scheme */
348     HI_UNF_CIPHER_RSA_PUB_KEY_S stPubKey;      /* RSA public key struct */
349 } HI_UNF_CIPHER_RSA_VERIFY_S;
350 
351 /* bignum modular exponentiation struct. */
352 typedef struct {
353     const HI_U8 *pu8N;      /* RSA input N */
354     const HI_U8 *pu8K;      /* RSA input E/D */
355     const HI_U8 *pu8In;     /* RSA input data */
356     HI_U8 *pu8Out;          /* RSA output data */
357     HI_U16 u16Length;       /* RSA N/E/D, input/output data length */
358 } HI_UNF_CIPHER_BN_EXP_MOD_S;
359 
360 #define HI_UNF_CIPHER_Open(HI_VOID) HI_UNF_CIPHER_Init(HI_VOID);
361 #define HI_UNF_CIPHER_Close(HI_VOID) HI_UNF_CIPHER_DeInit(HI_VOID);
362 
363 /* ****************************** API Declaration **************************** */
364 /*
365  * brief  Init the cipher device.
366  *
367  * attention  \n
368  * This API is used to start the cipher device.
369  *
370  * param N/A
371  * retval ::HI_SUCCESS  Call this API successful.
372  * retval ::HI_FAILURE  Call this API fails.
373  * retval ::HI_ERR_CIPHER_FAILED_INIT  The cipher device fails to be initialized.
374  * see \n
375  * N/A
376  */
377 HI_S32 HI_UNF_CIPHER_Init(HI_VOID);
378 
379 /*
380  * brief  Deinit the cipher device.
381  *
382  * attention  \n
383  * This API is used to stop the cipher device. If this API is called repeatedly, HI_SUCCESS is returned, but only the
384  * first operation takes effect.
385  *
386  * param N/A
387  * retval ::HI_SUCCESS  Call this API successful.
388  * retval ::HI_FAILURE  Call this API fails.
389  * retval ::HI_ERR_CIPHER_NOT_INIT  The cipher device is not initialized.
390  * see \n
391  * N/A
392  */
393 HI_S32 HI_UNF_CIPHER_DeInit(HI_VOID);
394 
395 /*
396  * brief Obtain a cipher handle for encryption and decryption.
397  *
398  * param[out] phCipher Cipher handle
399  * param[in] cipher attributes
400  * retval ::HI_SUCCESS Call this API successful.
401  * retval ::HI_FAILURE Call this API fails.
402  * retval ::HI_ERR_CIPHER_NOT_INIT  The cipher device is not initialized.
403  * retval ::HI_ERR_CIPHER_INVALID_POINT  The pointer is null.
404  * retval ::HI_ERR_CIPHER_FAILED_GETHANDLE  The cipher handle fails to be obtained, because there are no available
405  * cipher.
406  * handles.
407  * see \n
408  * N/A
409  */
410 HI_S32 HI_UNF_CIPHER_CreateHandle(HI_HANDLE *phCipher, const HI_UNF_CIPHER_ATTS_S *pstCipherAttr);
411 
412 /*
413  * brief Destroy the cipher handle.
414  * attention  \n
415  * This API is used to destroy existing cipher handles.
416  * param[in] hCipher Cipher handle
417  * retval ::HI_SUCCESS  Call this API successful.
418  * retval ::HI_FAILURE  Call this API fails.
419  * retval ::HI_ERR_CIPHER_NOT_INIT  The cipher device is not initialized.
420  * see \n
421  * N/A
422  */
423 HI_S32 HI_UNF_CIPHER_DestroyHandle(HI_HANDLE hCipher);
424 
425 /*
426  * brief Configures the cipher control information.
427  *
428  * attention  \n
429  * Before encryption or decryption, you must call this API to configure the cipher control information.
430  * The first 64-bit data and the last 64-bit data should not be the same when using TDES algorithm.
431  *
432  * param[in] hCipher Cipher handle.
433  * param[in] pstCtrl Cipher control information.
434  * retval ::HI_SUCCESS Call this API successful.
435  * retval ::HI_FAILURE Call this API fails.
436  * retval ::HI_ERR_CIPHER_NOT_INIT  The cipher device is not initialized.
437  * retval ::HI_ERR_CIPHER_INVALID_POINT  The pointer is null.
438  * retval ::HI_ERR_CIPHER_INVALID_PARA  The parameter is invalid.
439  * retval ::HI_ERR_CIPHER_INVALID_HANDLE  The handle is invalid.
440  * see \n
441  * N/A
442  */
443 HI_S32 HI_UNF_CIPHER_ConfigHandle(HI_HANDLE hCipher, const HI_UNF_CIPHER_CTRL_S *pstCtrl);
444 
445 /*
446  * brief Configures the cipher control information.
447  *
448  * attention  \n
449  * Before encryption or decryption, you must call this API to configure the cipher control information.
450  * The first 64-bit data and the last 64-bit data should not be the same when using TDES algorithm.
451  *
452  * param[in] hCipher Cipher handle.
453  * param[in] pstExCtrl Cipher control information.
454  * retval ::HI_SUCCESS Call this API successful.
455  * retval ::HI_FAILURE Call this API fails.
456  * retval ::HI_ERR_CIPHER_NOT_INIT  The cipher device is not initialized.
457  * retval ::HI_ERR_CIPHER_INVALID_POINT  The pointer is null.
458  * retval ::HI_ERR_CIPHER_INVALID_PARA  The parameter is invalid.
459  * retval ::HI_ERR_CIPHER_INVALID_HANDLE  The handle is invalid.
460  * see \n
461  * N/A
462  */
463 HI_S32 HI_UNF_CIPHER_ConfigHandleEx(HI_HANDLE hCipher, const HI_UNF_CIPHER_CTRL_EX_S *pstExCtrl);
464 
465 /*
466  * brief Performs encryption.
467  *
468  * attention  \n
469  * This API is used to perform encryption by using the cipher module.
470  * The length of the encrypted data should be a multiple of 8 in TDES mode and 16 in AES mode. Besides, the length can
471  * not be bigger than 0xFFFFF.After this operation, the result will affect next operation.If you want to remove vector,
472  * you need to config IV(config pstCtrl->stChangeFlags.bit1IV with 1) by transferring HI_UNF_CIPHER_ConfigHandle.
473  *
474  * param[in] hCipher Cipher handle
475  * param[in] u32SrcPhyAddr Physical address of the source data
476  * param[in] u32DestPhyAddr Physical address of the target data
477  * param[in] u32ByteLength   Length of the encrypted data
478  * retval ::HI_SUCCESS  Call this API successful.
479  * retval ::HI_FAILURE  Call this API fails.
480  * retval ::HI_ERR_CIPHER_NOT_INIT  The cipher device is not initialized.
481  * retval ::HI_ERR_CIPHER_INVALID_PARA  The parameter is invalid.
482  * retval ::HI_ERR_CIPHER_INVALID_HANDLE  The handle is invalid.
483  * see \n
484  * N/A
485  */
486 HI_S32 HI_UNF_CIPHER_Encrypt(HI_HANDLE hCipher,
487     HI_SIZE_T szSrcPhyAddr, HI_SIZE_T szDestPhyAddr, HI_U32 u32ByteLength);
488 
489 /*
490  * brief Performs decryption.
491  *
492  * attention  \n
493  * This API is used to perform decryption by using the cipher module.
494  * The length of the decrypted data should be a multiple of 8 in TDES mode and 16 in AES mode. Besides, the length can
495  * not be bigger than 0xFFFFF.After this operation, the result will affect next operation.If you want to remove vector,
496  * you need to config IV(config pstCtrl->stChangeFlags.bit1IV with 1) by transferring HI_UNF_CIPHER_ConfigHandle.
497  *
498  * param[in] hCipher Cipher handle.
499  * param[in] u32SrcPhyAddr Physical address of the source data.
500  * param[in] u32DestPhyAddr Physical address of the target data.
501  * param[in] u32ByteLength Length of the decrypted data
502  * retval ::HI_SUCCESS Call this API successful.
503  * retval ::HI_FAILURE Call this API fails.
504  * retval ::HI_ERR_CIPHER_NOT_INIT  The cipher device is not initialized.
505  * retval ::HI_ERR_CIPHER_INVALID_PARA  The parameter is invalid.
506  * retval ::HI_ERR_CIPHER_INVALID_HANDLE  The handle is invalid.
507  * see \n
508  * N/A
509  */
510 HI_S32 HI_UNF_CIPHER_Decrypt(HI_HANDLE hCipher,
511     HI_SIZE_T szSrcPhyAddr, HI_SIZE_T szDestPhyAddr, HI_U32 u32ByteLength);
512 
513 /*
514  * brief Performs encryption.
515  *
516  * attention  \n
517  * This API is used to perform encryption by using the cipher module.
518  * The length of the encrypted data should be a multiple of 8 in TDES mode and 16 in AES mode. Besides, the length can
519  * not be bigger than 0xFFFFF.After this operation, the result will affect next operation.If you want to remove vector,
520  * you need to config IV(config pstCtrl->stChangeFlags.bit1IV with 1) by transferring HI_UNF_CIPHER_ConfigHandle.
521  *
522  * param[in] hCipher Cipher handle
523  * param[in] pu8SrcData: buffer of the source data.
524  * param[out] pu8DestData: buffer of the target data
525  * param[in] u32ByteLength   Length of the encrypted data
526  * retval ::HI_SUCCESS  Call this API successful.
527  * retval ::HI_FAILURE  Call this API fails.
528  * retval ::HI_ERR_CIPHER_NOT_INIT  The cipher device is not initialized.
529  * retval ::HI_ERR_CIPHER_INVALID_PARA  The parameter is invalid.
530  * retval ::HI_ERR_CIPHER_INVALID_HANDLE  The handle is invalid.
531  * see \n
532  * N/A
533  */
534 HI_S32 HI_UNF_CIPHER_EncryptVir(HI_HANDLE hCipher,
535     const HI_U8 *pu8SrcData, HI_U8 *pu8DestData, HI_U32 u32ByteLength);
536 
537 /*
538  * brief Performs decryption.
539  *
540  * attention  \n
541  * This API is used to perform decryption by using the cipher module.
542  * The length of the decrypted data should be a multiple of 8 in TDES mode and 16 in AES mode. Besides, the length can
543  * not be bigger than 0xFFFFF.After this operation, the result will affect next operation.If you want to remove vector,
544  * you need to config IV(config pstCtrl->stChangeFlags.bit1IV with 1) by transferring HI_UNF_CIPHER_ConfigHandle.
545  *
546  * param[in] hCipher Cipher handle.
547  * param[in] pu8SrcData: buffer of the source data.
548  * param[out] pu8DestData: buffer of the target data
549  * param[in] u32ByteLength Length of the decrypted data
550  * retval ::HI_SUCCESS Call this API successful.
551  * retval ::HI_FAILURE Call this API fails.
552  * retval ::HI_ERR_CIPHER_NOT_INIT  The cipher device is not initialized.
553  * retval ::HI_ERR_CIPHER_INVALID_PARA  The parameter is invalid.
554  * retval ::HI_ERR_CIPHER_INVALID_HANDLE  The handle is invalid.
555  * see \n
556  * N/A
557  */
558 HI_S32 HI_UNF_CIPHER_DecryptVir(HI_HANDLE hCipher,
559     const HI_U8 *pu8SrcData, HI_U8 *pu8DestData, HI_U32 u32ByteLength);
560 
561 /*
562  * brief Encrypt multiple packaged data.
563  *
564  * attention  \n
565  * You can not encrypt more than 128 data package one time. When HI_ERR_CIPHER_BUSY return, the data package you send
566  * will not be deal, the customer should decrease the number of data package or run cipher again.Note:When encrypting
567  * more than one packaged data, every one package will be calculated using initial vector configured by
568  * HI_UNF_CIPHER_ConfigHandle. Previous result will not affect the later result.
569  *
570  * param[in] hCipher cipher handle
571  * param[in] pstDataPkg data package ready for cipher
572  * param[in] u32DataPkgNum  number of package ready for cipher
573  * retval ::HI_SUCCESS  Call this API successful.
574  * retval ::HI_FAILURE  Call this API fails.
575  * retval ::HI_ERR_CIPHER_NOT_INIT  cipher device have not been initialized
576  * retval ::HI_ERR_CIPHER_INVALID_PARA  parameter error
577  * retval ::HI_ERR_CIPHER_INVALID_HANDLE  handle invalid
578  * retval ::HI_ERR_CIPHER_BUSY  hardware is busy, it can not deal with all data package once time
579  * see \n
580  * N/A
581  */
582 HI_S32 HI_UNF_CIPHER_EncryptMulti(HI_HANDLE hCipher,
583     const HI_UNF_CIPHER_DATA_S *pstDataPkg, HI_U32 u32DataPkgNum);
584 
585 /*
586  * brief Get the cipher control information.
587  *
588  * param[in] hCipher Cipher handle.
589  * param[in] pstCtrl Cipher control information.
590  * retval ::HI_SUCCESS Call this API successful.
591  * retval ::HI_FAILURE Call this API fails.
592  * retval ::HI_ERR_CIPHER_NOT_INIT  The cipher device is not initialized.
593  * retval ::HI_ERR_CIPHER_INVALID_POINT  The pointer is null.
594  * retval ::HI_ERR_CIPHER_INVALID_PARA  The parameter is invalid.
595  * retval ::HI_ERR_CIPHER_INVALID_HANDLE  The handle is invalid.
596  * see \n
597  * N/A
598  */
599 HI_S32 HI_UNF_CIPHER_GetHandleConfig(HI_HANDLE hCipher, HI_UNF_CIPHER_CTRL_S *pstCtrl);
600 
601 /*
602  * brief Decrypt multiple packaged data.
603  *
604  * attention  \n
605  * You can not decrypt more than 128 data package one time.When HI_ERR_CIPHER_BUSY return, the data package you send
606  * will not be deal, the custmer should decrease the number of data package or run cipher again.Note:When decrypting
607  * more than one packaged data, every one package will be calculated using initial vector configured by
608  * HI_UNF_CIPHER_ConfigHandle. Previous result will not affect the later result.
609  *
610  * param[in] hCipher cipher handle
611  * param[in] pstDataPkg data package ready for cipher
612  * param[in] u32DataPkgNum  number of package ready for cipher
613  * retval ::HI_SUCCESS  Call this API successful.
614  * retval ::HI_FAILURE  Call this API fails.
615  * retval ::HI_ERR_CIPHER_NOT_INIT  cipher device have not been initialized
616  * retval ::HI_ERR_CIPHER_INVALID_PARA  parameter error
617  * retval ::HI_ERR_CIPHER_INVALID_HANDLE  handle invalid
618  * retval ::HI_ERR_CIPHER_BUSY  hardware is busy, it can not deal with all data package once time
619  * see \n
620  * N/A
621  */
622 HI_S32 HI_UNF_CIPHER_DecryptMulti(HI_HANDLE hCipher,
623     const HI_UNF_CIPHER_DATA_S *pstDataPkg, HI_U32 u32DataPkgNum);
624 
625 /*
626  * brief Get the tag data of CCM/GCM.
627  *
628  * attention  \n
629  * This API is used to get the tag data of CCM/GCM.
630  *
631  * param[in] hCipher cipher handle
632  * param[out] pu8Tag tag data of CCM/GCM
633  * param[in/out] pu32TagLen tag data length of CCM/GCM, the input should be 16 now.
634  * retval ::HI_SUCCESS  Call this API succussful.
635  * retval ::HI_FAILURE  Call this API fails.
636  * retval ::HI_ERR_CIPHER_NOT_INIT  The cipher device is not initialized.
637  * retval ::HI_ERR_CIPHER_INVALID_PARA  The parameter is invalid.
638  * see \n
639  * N/A
640  */
641 HI_S32 HI_UNF_CIPHER_GetTag(HI_HANDLE hCipher, HI_U8 *pu8Tag, HI_U32 *pu32TagLen);
642 
643 /*
644  * brief Encrypt the clean key data by KLAD.
645  * attention  \n
646  * N/A
647  * param[in] enRootKey klad root key.
648  * param[in] pu8CleanKey clean key.
649  * param[in] enTarget the module who to use this key.
650  * param[out] pu8EcnryptKey encrypt key.
651  * param[in] u32KeyLen clean key.
652  * retval ::HI_SUCCESS Call this API successful.
653  * retval ::HI_FAILURE Call this API fails.
654  * retval ::HI_ERR_CIPHER_NOT_INIT  The cipher device is not initialized.
655  * retval ::HI_ERR_CIPHER_INVALID_POINT  The pointer is null.
656  * retval ::HI_ERR_CIPHER_INVALID_PARA  The parameter is invalid.
657  * retval ::HI_ERR_CIPHER_INVALID_HANDLE  The handle is invalid.
658  * see \n
659  * N/A
660  */
661 HI_S32 HI_UNF_CIPHER_KladEncryptKey(HI_UNF_CIPHER_CA_TYPE_E enRootKey,
662     HI_UNF_CIPHER_KLAD_TARGET_E enTarget, const HI_U8 *pu8CleanKey, HI_U8 *pu8EcnryptKey, HI_U32 u32KeyLen);
663 
664 /*
665  * brief Get the random number.
666  *
667  * attention  \n
668  * This API is used to obtain the random number from the hardware.
669  *
670  * param[out] pu32RandomNumber Point to the random number.
671  * retval ::HI_SUCCESS  Call this API successful.
672  * retval ::HI_FAILURE  Call this API fails.
673  *
674  * see \n
675  * N/A
676  */
677 HI_S32 HI_UNF_CIPHER_GetRandomNumber(HI_U32 *pu32RandomNumber);
678 
679 /*
680  * brief Init the hash module, if other program is using the hash module, the API will return failure.
681  *
682  * attention  \n
683  * N/A
684  *
685  * param[in] pstHashAttr: The hash calculating structure input.
686  * param[out] pHashHandle: The output hash handle.
687  * retval ::HI_SUCCESS  Call this API successful.
688  * retval ::HI_FAILURE  Call this API fails.
689  *
690  * see \n
691  * N/A
692  */
693 HI_S32 HI_UNF_CIPHER_HashInit(const HI_UNF_CIPHER_HASH_ATTS_S *pstHashAttr, HI_HANDLE *pHashHandle);
694 
695 /*
696  * brief Calculate the hash, if the size of the data to be calculated is very big and the DDR ram is not enough, this
697  * API can calculate the data one block by one block. Attention: The input block length must be 64bytes aligned except
698  * for the last block.
699  *
700  * attention  \n
701  * N/A
702  *
703  * param[in] hHashHandl:  Hash handle.
704  * param[in] pu8InputData:  The input data buffer.
705  * param[in] u32InputDataLen:  The input data length, attention: the block length input must be 64bytes aligned except
706  * the last block!
707  * retval ::HI_SUCCESS  Call this API successful.
708  * retval ::HI_FAILURE  Call this API fails.
709  *
710  * see \n
711  * N/A
712  */
713 HI_S32 HI_UNF_CIPHER_HashUpdate(HI_HANDLE hHashHandle,
714     const HI_U8 *pu8InputData, HI_U32 u32InputDataLen);
715 
716 /*
717  * brief Get the final hash value, after calculate all of the data, call this API to get the final hash value and close
718  * the handle.If there is some reason need to interrupt the calculation, this API should also be call to close the
719  * handle.
720  *
721  * attention  \n
722  * N/A
723  *
724  * param[in] hHashHandle:  Hash handle.
725  * param[out] pu8OutputHash:  The final output hash value.
726  *
727  * retval ::HI_SUCCESS  Call this API successful.
728  * retval ::HI_FAILURE  Call this API fails.
729  *
730  * see \n
731  * N/A
732  */
733 HI_S32 HI_UNF_CIPHER_HashFinal(HI_HANDLE hHashHandle, HI_U8 *pu8OutputHash);
734 
735 /*
736  * brief RSA encryption a plaintext with a RSA public key.
737  *
738  * attention  \n
739  * N/A
740  *
741  * param[in] pstRsaEnc:   encryption struct.
742  * param[in] pu8Input:    input data to be encryption
743  * param[out] u32InLen:   length of input data to be encryption
744  * param[out] pu8Output: output data to be encryption
745  * param[out] pu32OutLen: length of output data to be encryption
746  *
747  * retval ::HI_SUCCESS  Call this API successful.
748  * retval ::HI_FAILURE  Call this API fails.
749  *
750  * see \n
751  * N/A
752  */
753 HI_S32 HI_UNF_CIPHER_RsaPublicEncrypt(const HI_UNF_CIPHER_RSA_PUB_ENC_S *pstRsaEnc,
754     const HI_U8 *pu8Input, HI_U32 u32InLen, HI_U8 *pu8Output, HI_U32 *pu32OutLen);
755 
756 /*
757  * brief RSA decryption a ciphertext with a RSA private key.
758  *
759  * attention  \n
760  * N/A
761  *
762  * param[in] pstRsaDec:   decryption struct.
763  * param[in] pu8Input:    input data to be decryption
764  * param[out] u32InLen:   length of input data to be decryption
765  * param[out] pu8Output:  output data to be decryption
766  * param[out] pu32OutLen: length of output data to be decryption
767  *
768  * retval ::HI_SUCCESS  Call this API successful.
769  * retval ::HI_FAILURE  Call this API fails.
770  *
771  * see \n
772  * N/A
773  */
774 HI_S32 HI_UNF_CIPHER_RsaPrivateDecrypt(const HI_UNF_CIPHER_RSA_PRI_ENC_S *pstRsaDec,
775     const HI_U8 *pu8Input, HI_U32 u32InLen, HI_U8 *pu8Output, HI_U32 *pu32OutLen);
776 
777 /*
778  * brief RSA encryption a plaintext with a RSA private key.
779  *
780  * attention  \n
781  * N/A
782  *
783  * param[in] pstRsaSign:   encryption struct.
784  * param[in] pu8Input:     input data to be encryption
785  * param[out] u32InLen:   length of input data to be encryption
786  * param[out] pu8Output:  output data to be encryption
787  * param[out] pu32OutLen: length of output data to be encryption
788  *
789  * retval ::HI_SUCCESS  Call this API successful.
790  * retval ::HI_FAILURE  Call this API fails.
791  *
792  * see \n
793  * N/A
794  */
795 HI_S32 HI_UNF_CIPHER_RsaPrivateEncrypt(const HI_UNF_CIPHER_RSA_PRI_ENC_S *pstRsaEnc,
796     const HI_U8 *pu8Input, HI_U32 u32InLen, HI_U8 *pu8Output, HI_U32 *pu32OutLen);
797 
798 /*
799  * brief RSA decryption a ciphertext with a RSA public key.
800  *
801  * attention  \n
802  * N/A
803  *
804  * param[in] pstRsaVerify:   decryption struct.
805  * param[in] pu8Input:   input data to be decryption
806  * param[out] u32InLen:   length of input data to be decryption
807  * param[out] pu8Output: output data to be decryption
808  * param[out] pu32OutLen: length of output data to be decryption
809  *
810  * retval ::HI_SUCCESS  Call this API successful.
811  * retval ::HI_FAILURE  Call this API fails.
812  *
813  * see \n
814  * N/A
815  */
816 HI_S32 HI_UNF_CIPHER_RsaPublicDecrypt(const HI_UNF_CIPHER_RSA_PUB_ENC_S *pstRsaDec,
817     const HI_U8 *pu8Input, HI_U32 u32InLen, HI_U8 *pu8Output, HI_U32 *pu32OutLen);
818 
819 /*
820  * brief RSA signature a context with appendix, where a signer's RSA private key is used.
821  *
822  * attention  \n
823  * N/A
824  *
825  * param[in] pstRsaSign:      signature struct.
826  * param[in] pu8Input:        input context to be signature.
827  * param[in] u32InLen:        length of input context to be signature
828  * param[in] pu8HashData:    hash value of context,if NULL, let pu8HashData = Hash(context) automatically
829  * param[out] pu8OutSign:    output message of signature
830  * param[out] pu32OutSignLen: length of message of signature
831  *
832  * retval ::HI_SUCCESS  Call this API successful.
833  * retval ::HI_FAILURE  Call this API fails.
834  *
835  * see \n
836  * N/A
837  */
838 HI_S32 HI_UNF_CIPHER_RsaSign(const HI_UNF_CIPHER_RSA_SIGN_S *pstRsaSign,
839     const HI_U8 *pu8InData, HI_U32 u32InDataLen,
840     const HI_U8 *pu8HashData,
841     HI_U8 *pu8OutSign, HI_U32 *pu32OutSignLen);
842 
843 /*
844  * brief RSA signature verification a context with appendix, where a signer's RSA public key is used.
845  *
846  * attention  \n
847  * N/A
848  *
849  * param[in] pstRsaVerify:    signature verification struct.
850  * param[in] pu8Input:       input context to be signature verification, maybe null
851  * param[in] u32InLen:        length of input context to be signature
852  * param[in] pu8HashData:    hash value of context,if NULL, let pu8HashData = Hash(context) automatically
853  * param[in] pu8InSign:      message of signature
854  * param[in] pu32InSignLen:   length of message of signature
855  *
856  * retval ::HI_SUCCESS  Call this API successful.
857  * retval ::HI_FAILURE  Call this API fails.
858  *
859  * see \n
860  * N/A
861  */
862 HI_S32 HI_UNF_CIPHER_RsaVerify(const HI_UNF_CIPHER_RSA_VERIFY_S *pstRsaVerify,
863     const HI_U8 *pu8InData, HI_U32 u32InDataLen,
864     const HI_U8 *pu8HashData,
865     const HI_U8 *pu8InSign, HI_U32 u32InSignLen);
866 
867 /*
868  * brief Calculate bignum modular exponentiation
869  *
870  * attention  \n
871  * N/A
872  *
873  * param[in] pstExpMod:    bignum modular exponentiation struct.
874  *
875  * retval ::HI_SUCCESS  Call this API successful.
876  * retval ::HI_FAILURE  Call this API fails.
877  *
878  * see \n
879  * N/A
880  */
881 HI_S32 HI_UNF_CIPHER_BnExpMod(HI_UNF_CIPHER_BN_EXP_MOD_S *pstExpMod);
882 
883 #ifdef __cplusplus
884 #if __cplusplus
885 }
886 #endif
887 #endif /* __cplusplus */
888 
889 #endif /* __HI_UNF_CIPHER_H__ */
890 
891