xref: /utopia/UTPA2-700.0.x/mxlib/include/drvCIPHER.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2006-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 ////////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// @file   drvCIPHER.h
98 /// @brief  CIPHER Driver Interface
99 /// @author MStar Semiconductor,Inc.
100 ///
101 ////////////////////////////////////////////////////////////////////////////////////////////////////
102 #ifndef __DRVCIPHER_H__
103 #define __DRVCIPHER_H__
104 
105 #include "MsTypes.h"
106 #include "MsDevice.h"
107 #include "MsCommon.h"
108 
109 #ifdef __cplusplus
110 extern "C"
111 {
112 #endif
113 
114 
115 //--------------------------------------------------------------------------------------------------
116 //  Define
117 //--------------------------------------------------------------------------------------------------
118 #define HASH_TIMEOUT_VALUE      (5000UL)
119 
120 typedef enum
121 {
122     CIPHER_DBG_NONE,
123     CIPHER_DBG_ERR,
124     CIPHER_DBG_WARN,
125     CIPHER_DBG_INFO,
126 }CIPHER_DBGMSG_LEVEL;
127 
128 #define MSIF_CIPHER_LIB_CODE                     {'D','M','A','_'}    //Lib code
129 #define MSIF_CIPHER_LIBVER                       {'0','1'}            //LIB version
130 #define MSIF_CIPHER_BUILDNUM                     {'0','1'}            //Build Number
131 #define MSIF_CIPHER_CHANGELIST                   {'0','0','8','2','9','9','2','7'} //P4 ChangeList Number
132 
133 #define CIPHER_DRV_VERSION                 /* Character String for DRV/API version             */  \
134     MSIF_TAG,                           /* 'MSIF'                                           */  \
135     MSIF_CLASS,                         /* '00'                                             */  \
136     MSIF_CUS,                           /* 0x0000                                           */  \
137     MSIF_MOD,                           /* 0x0000                                           */  \
138     MSIF_CHIP,                                                                                  \
139     MSIF_CPU,                                                                                   \
140     MSIF_CIPHER_LIB_CODE,                  /* IP__                                             */  \
141     MSIF_CIPHER_LIBVER,                          /* 0.0 ~ Z.Z                                        */  \
142     MSIF_CIPHER_BUILDNUM,                          /* 00 ~ 99                                          */  \
143     MSIF_CIPHER_CHANGELIST,  /* CL#                                              */  \
144     MSIF_OS
145 
146 
147 //--------------------------------------------------------------------------------------------------
148 //  Driver Capability
149 //--------------------------------------------------------------------------------------------------
150 
151 //--------------------------------------------------------------------------------------------------
152 //  Local variable
153 //--------------------------------------------------------------------------------------------------
154 
155 //--------------------------------------------------------------------------------------------------
156 //  Type and Structure
157 //--------------------------------------------------------------------------------------------------
158 /// AESDMA DDI return value
159 typedef MS_U32                         DRV_CIPHER_RET;
160 
161 typedef void (*P_DrvCIPHER_EvtCallback)(MS_U32 u32CmdId, MS_BOOL bSuccess, MS_U32 u32Exception);
162 
163 typedef enum
164 {
165     E_CIPHER_MAIN_NONE,
166     E_CIPHER_MAIN_AES,
167     E_CIPHER_MAIN_DES,
168     E_CIPHER_MAIN_TDES,
169     E_CIPHER_MAIN_M6_S56_CCBC,
170     E_CIPHER_MAIN_M6_S56,
171     E_CIPHER_MAIN_M6_KE56,
172     E_CIPHER_MAIN_RC4,
173     E_CIPHER_MAIN_RC4_128,
174     E_CIPHER_MAIN_SM4,
175 }CIPHER_MAIN_ALGO;
176 
177 typedef enum
178 {
179     E_CIPHER_SUB_NONE,
180     E_CIPHER_SUB_ECB,
181     E_CIPHER_SUB_CBC,
182     E_CIPHER_SUB_CTR,
183     E_CIPHER_SUB_CBC_MAC,
184     E_CIPHER_SUB_CTR_64,
185     E_CIPHER_SUB_CMAC_Key,
186     E_CIPHER_SUB_CMAC_Algo,
187     E_CIPHER_SUB_PCBC_ADD,
188     E_CIPHER_SUB_PCBC_XOR,
189     E_CIPHER_SUB_OTPHASH,
190 }CIPHER_SUB_ALGO;
191 
192 typedef enum
193 {
194     E_CIPHER_RES_NONE,
195     E_CIPHER_RES_CLR,
196     E_CIPHER_RES_CTS,
197     E_CIPHER_RES_SCTE52,
198 }CIPHER_RES_ALGO;
199 
200 typedef enum
201 {
202     E_CIPHER_SB_NONE,
203     E_CIPHER_SB_CLR,
204     E_CIPHER_SB_IV1,
205     E_CIPHER_SB_IV2,
206 }CIPHER_SB_ALGO;
207 
208 typedef enum
209 {
210     E_CIPHER_KSRC_CPU,
211     E_CIPHER_KSRC_KL,
212     E_CIPHER_KSRC_OTP,
213     E_CIPHER_KSRC_STR,
214     E_CIPHER_KSRC_CAIP = 9,
215 }CIPHER_KEY_SRC;
216 
217 
218 typedef struct
219 {
220     CIPHER_MAIN_ALGO    eMainAlgo;
221     CIPHER_SUB_ALGO     eSubAlgo;
222     CIPHER_RES_ALGO     eResAlgo;
223     CIPHER_SB_ALGO      eSBAlgo;
224 }DRV_CIPHER_ALGO;
225 
226 typedef struct
227 {
228     CIPHER_KEY_SRC  eKeySrc;
229     MS_U8           u8KeyIdx;
230     MS_U8           u8KeyLen;
231     MS_U8           *pu8KeyData;
232     MS_U8           u8IVLen;
233     MS_U8           *pu8IVData;
234 }DRV_CIPHER_KEY;
235 
236 
237 typedef enum
238 {
239 	E_CIPHER_DRAM = 1,
240 	E_CIPHER_DQMEM,
241 	E_CIPHER_IQMEM,
242 	E_CIPHER_DIRECT,
243 	E_CIPHER_OTP,
244 	E_CIPHER_KL_LUT,
245 	E_CIPHER_KL_M,
246 	E_CIPHER_KL_BC,
247 }CIPHER_MEM_TYPE;
248 
249 
250 typedef struct
251 {
252     MS_PHY u32Addr;
253     MS_U32 u32Size;
254 	CIPHER_MEM_TYPE    eMemoryType;
255 }DRV_CIPHER_DATA;
256 
257 typedef struct
258 {
259     DRV_CIPHER_ALGO stAlgo;
260     DRV_CIPHER_KEY  stKey;
261     DRV_CIPHER_DATA stInput;
262     DRV_CIPHER_DATA stOutput;
263     MS_BOOL         bDecrypt;
264 	MS_U32          u32CAVid;
265     P_DrvCIPHER_EvtCallback pfCallback;
266 }DRV_CIPHER_DMACFG;
267 
268 typedef enum
269 {
270     E_CIPHER_HASH_ALGO_SHA1,
271     E_CIPHER_HASH_ALGO_SHA256 ,
272     E_CIPHER_HASH_ALGO_MD5 ,
273     E_CIPHER_HASH_ALGO_SM3 ,
274 }CIPHER_HASH_ALGO;
275 
276 typedef enum
277 {
278     E_CIPHER_HASH_IV_FIPS,
279     E_CIPHER_HASH_IV_CMD,
280     E_CIPHER_HASH_IV_PRV,
281 }CIPHER_HASH_IV;
282 
283 typedef enum
284 {
285     E_CIPHER_HASH_STAGE_FIRST ,
286     E_CIPHER_HASH_STAGE_UPDATE ,
287     E_CIPHER_HASH_STAGE_LAST ,
288 }CIPHER_HASH_STAGE;
289 
290 typedef enum
291 {
292     E_CIPHER_HMAC_IKPAD,
293     E_CIPHER_HMAC_OKPAD,
294 }CIPHER_HMAC_KPAD;
295 
296 typedef struct
297 {
298     CIPHER_KEY_SRC  eKeySrc;
299     MS_U8           u8KeyIdx;
300     MS_U8           u8KeyLen;
301     MS_U8           *pu8KeyData;
302 }DRV_CIPHER_HMAC_KEY;
303 
304 typedef struct
305 {
306     CIPHER_HASH_ALGO        eAlgo;
307     DRV_CIPHER_DATA         stInput;
308     MS_U8                   *pu8Digest_Buf;
309     MS_U32                  u32Digest_Buf_Size;
310     MS_U32                  u32CAVid;
311     P_DrvCIPHER_EvtCallback pfCallback;
312 }DRV_CIPHER_HASHCFG;
313 
314 typedef struct
315 {
316     CIPHER_HASH_ALGO      eAlgo;
317     DRV_CIPHER_DATA       stInput;
318     MS_U8                 *pu8Digest_Buf;
319     MS_U32                u32Digest_Buf_Size;
320     MS_U32                u32CAVid;
321     MS_U32                u32StartByte;
322     MS_U8                 *pu8SetIV;
323     CIPHER_HASH_IV        eIVMode;
324     CIPHER_HASH_STAGE     eStage;
325     CIPHER_HMAC_KPAD      eHMACKPad;
326     DRV_CIPHER_HMAC_KEY   stHMACKey;
327 }DRV_CIPHER_HASHCFG_MANUAL;
328 
329 typedef struct
330 {
331     CIPHER_HASH_ALGO    eAlgo;
332     DRV_CIPHER_DATA     stInput;
333     MS_U8               *pu8Digest_Buf;
334     MS_U32              u32Digest_Buf_Size;
335     MS_U32              u32CAVid;
336     DRV_CIPHER_HMAC_KEY stHMACKey;
337     P_DrvCIPHER_EvtCallback pfCallback;
338 }DRV_CIPHER_HMACCFG;
339 
340 #define DRV_CIPHER_OK                   (0x00000000UL)
341 #define DRV_CIPHER_FAIL                 (0x00000001UL)
342 #define DRV_CIPHER_BAD_PARAM            (0x00000002UL)
343 
344 //Exception Message
345 #define DRV_CIPHER_EXCEPT_CAVID         (0x00000001UL)
346 #define DRV_CIPHER_EXCEPT_DATA          (0x00000002UL)
347 #define DRV_CIPHER_EXCEPT_ALGO          (0x00000004UL)
348 #define DRV_CIPHER_EXCEPT_DMA_KEY       (0x00000008UL)
349 #define DRV_CIPHER_EXCEPT_HMAC_KEY      (0x00000010UL)
350 
351 
352 //--------------------------------------------------------------------------------------------------
353 //  Function Prototype
354 //--------------------------------------------------------------------------------------------------
355 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_Init(void);
356 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_Reset(void);
357 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_ResetKey(MS_U32 u32CAVid, MS_U32 u32KeyIdx);
358 
359 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_DMACalc(DRV_CIPHER_DMACFG stCfg, MS_U32 *pu32CmdId);
360 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_OTPHASHCalc(DRV_CIPHER_DMACFG stCfg, MS_U32 *pu32CmdId);
361 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_HASH(DRV_CIPHER_HASHCFG stCfg, MS_U32 *pu32CmdId);
362 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_HASHManual(DRV_CIPHER_HASHCFG_MANUAL stCfg, MS_U32 *pu32CmdId);
363 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_HMAC(DRV_CIPHER_HMACCFG stCfg, MS_U32 *pu32CmdId);
364 
365 DLL_PUBLIC MS_BOOL MDrv_CIPHER_IsDMADone(MS_U32 u32CmdId, MS_U32 *pu32Exception);
366 DLL_PUBLIC MS_BOOL MDrv_CIPHER_IsHASHDone(MS_U32 u32CmdId, MS_U32 *pu32Exception);
367 
368 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_SetDbgLevel(CIPHER_DBGMSG_LEVEL eDBGMsgLevel);
369 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_GetLibVer(const MSIF_Version **ppVersion);
370 
371 //Key Control API
372 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_KeyCtrl(MS_BOOL bEnable);
373 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_Alloc(MS_U32 *pu32CipherId);
374 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_Free(MS_U32 u32CipherId);
375 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_DMAConfigure(MS_U32 u32CipherId, DRV_CIPHER_DMACFG stCfg);
376 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_DMAStart(MS_U32 u32CipherId, MS_U32 *pu32CmdId);
377 
378 
379 #ifdef ENABLE_BGC
380 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_BGC_Enable(MS_U32 u32EngId,MS_U32 u32Algo, MS_U8 *pu8Golden, MS_PHY u32SAddr, MS_U32 u32Size);
381 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_BGC_Check(MS_U32 u32EngId, MS_BOOL *bOK);
382 #endif
383 
384 #ifdef __cplusplus
385 }
386 #endif
387 
388 //////// Old Interface /////////////////
389 //--------------------------------------------------------------------------------------------------
390 //  Function Prototype
391 //--------------------------------------------------------------------------------------------------
392 #include "drvAESDMA.h"
393 
394 #endif
395