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