xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/mvl88w8977/mlan/esa/common/crypt_new_rom.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /** @file crypt_new_rom.c
2  *
3  *  @brief This file contains the api for AES based functions
4  *
5  * Copyright (C) 2014-2017, Marvell International Ltd.
6  *
7  * This software file (the "File") is distributed by Marvell International
8  * Ltd. under the terms of the GNU General Public License Version 2, June 1991
9  * (the "License").  You may use, redistribute and/or modify this File in
10  * accordance with the terms and conditions of the License, a copy of which
11  * is available by writing to the Free Software Foundation, Inc.,
12  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
13  * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14  *
15  * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
17  * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
18  * this warranty disclaimer.
19  */
20 
21 /******************************************************
22 Change log:
23     03/07/2014: Initial version
24 ******************************************************/
25 #ifndef _CRYPT_NEW_ROM_H_
26 #define _CRYPT_NEW_ROM_H_
27 
28 #define MRVL_AES_CMD_REQUEST_TYPE_INVALID (1)
29 #define MRVL_AES_ALGORITHM_INVALID        (1<<1)
30 #define MRVL_AES_KEY_SIZE_INVALID         (1<<2)
31 #define MRVL_AES_KEY_IV_SIZE_INVALID      (1<<3)
32 #define MRVL_AES_ENCRYPT_DATA_OVER_127    (1<<4)
33 #define MRVL_AES_ENCRYPT_DATA_LESS_2      (1<<5)
34 #define MRVL_AES_NOT_EN_AND_DECRYPT       (1<<6)
35 #define MRVL_AES_KEY_IV_INVALID_AES       (1<<7)
36 #define MRVL_AES_KEY_IV_INVALID_AES_WRAP  (1<<8)
37 #define MRVL_AES_KEY_IV_INVALID_RC4       (1<<9)
38 #define MRVL_AES_DATA_SIZE_INVALID        (1<<10)
39 
40 #define MRVL_AES_NONCE_INVALID            (1<<11)
41 #define MRVL_AES_AAD_INVALID              (1<<12)
42 
43 #define host_AES_ENCRYPT  0x1
44 #define host_AES_DECRYPT  0x0
45 
46 #define MRVL_CRYPTO_TEST_RC4        1
47 #define MRVL_CRYPTO_TEST_AES_ECB    2
48 #define MRVL_CRYPTO_TEST_AES_WRAP   3
49 #define MRVL_CRYPTO_TEST_AEC_CCM    4
50 #define MRVL_CRYPTO_TEST_WAPI       5
51 
52 /* basic data structs to support AES feature */
53 /* enum for encrypt/decrypt */
54 typedef enum {
55 	CRYPT_DECRYPT = 0,
56 	CRYPT_ENCRYPT = 1,
57 	CRYPT_UNKNOWN
58 } MRVL_ENDECRYPT_e;
59 
60 /* data strcut to hold action type and data to be processed */
61 typedef struct {
62 	UINT8 enDeAction;	/* encrypt or decrypt */
63 	UINT8 *pData;
64 } MRVL_ENDECRYPT_t;
65 
66 #ifdef WAPI_HW_SUPPORT
67 extern void MRVL_WapiEncrypt(MRVL_ENDECRYPT_t *crypt, int *pErr);
68 extern void MRVL_WapiDecrypt(MRVL_ENDECRYPT_t *crypt, int *pErr);
69 #endif
70 
71 extern BOOLEAN (*MRVL_AesPrimitiveEncrypt_hook) (MRVL_ENDECRYPT_t *crypt,
72 						 int *pErr);
73 extern void MRVL_AesPrimitiveEncrypt(MRVL_ENDECRYPT_t *crypt, int *pErr);
74 
75 extern BOOLEAN (*MRVL_AesPrimitiveDecrypt_hook) (MRVL_ENDECRYPT_t *crypt,
76 						 int *pErr);
77 extern void MRVL_AesPrimitiveDecrypt(MRVL_ENDECRYPT_t *crypt, int *pErr);
78 
79 extern BOOLEAN (*MRVL_AesWrapEncrypt_hook) (MRVL_ENDECRYPT_t *crypt, int *pErr);
80 extern void MRVL_AesWrapEncrypt(MRVL_ENDECRYPT_t *crypt, int *pErr);
81 
82 extern BOOLEAN (*MRVL_AesWrapDecrypt_hook) (MRVL_ENDECRYPT_t *crypt, int *pErr);
83 extern void MRVL_AesWrapDecrypt(MRVL_ENDECRYPT_t *crypt, int *pErr);
84 
85 #ifdef DIAG_AES_CCM
86 extern BOOLEAN (*MRVL_AesCCMPollingMode_hook) (MRVL_ENDECRYPT_t *crypt,
87 					       int *pErr, int decEnable);
88 extern void MRVL_AesCCMPollingMode(MRVL_ENDECRYPT_t *crypt, int *pErr,
89 				   int decEnable);
90 #endif
91 
92 extern BOOLEAN (*MRVL_AesEncrypt_hook) (UINT8 *kek, UINT8 kekLen, UINT8 *data,
93 					UINT8 *ret, int *ptr_val);
94 extern int MRVL_AesEncrypt(UINT8 *kek, UINT8 kekLen, UINT8 *data, UINT8 *ret);
95 
96 extern BOOLEAN (*MRVL_AesValidateHostRequest_hook) (UINT32 *pBitMap,
97 						    UINT8 *pCmdPtr,
98 						    UINT8 *pCryptData,
99 						    SINT8 *pAESWrapEnc,
100 						    int *ptr_val);
101 extern int MRVL_AesValidateHostRequest(UINT32 *pBitMap, UINT8 *pCmdPtr,
102 				       UINT8 *pCryptData, SINT8 *pAESWrapEnc);
103 
104 #ifdef RC4
105 extern BOOLEAN (*MRVL_Rc4Cryption_hook) (MRVL_ENDECRYPT_t *crypt, int *pErr);
106 extern void MRVL_Rc4Cryption(void *priv, MRVL_ENDECRYPT_t *crypt, int *pErr);
107 #endif
108 
109 extern BOOLEAN (*MRVL_AesWrap_hook) (UINT8 *kek, UINT8 kekLen, UINT32 n,
110 				     UINT8 *plain, UINT8 *keyIv, UINT8 *cipher,
111 				     int *ptr_val);
112 extern int MRVL_AesWrap(UINT8 *kek, UINT8 kekLen, UINT32 n, UINT8 *plain,
113 			UINT8 *keyIv, UINT8 *cipher);
114 
115 extern BOOLEAN (*MRVL_AesUnWrap_hook) (UINT8 *kek, UINT8 kekLen, UINT32 n,
116 				       UINT8 *cipher, UINT8 *keyIv,
117 				       UINT8 *plain, int *ptr_val);
118 extern int MRVL_AesUnWrap(UINT8 *kek, UINT8 kekLen, UINT32 n, UINT8 *cipher,
119 			  UINT8 *keyIv, UINT8 *plain);
120 
121 extern BOOLEAN (*MRVL_AesSetKey_hook) (const UINT8 *kek, UINT8 kekLen,
122 				       int *ptr_val);
123 extern int MRVL_AesSetKey(const UINT8 *kek, UINT8 kekLen);
124 
125 /* AES related defines */
126 #define MRVL_AES_KEY_UPDATE_DONE    5
127 #define MRVL_AES_DONE           6
128 #define MRVL_AES_ENGINE_BITS_POS    12
129 
130 #define MRVL_AES_KEYUPDATE_LOC      0x00000900
131 #define MRVL_AES_ENABLE_ENCR_LOC    0x00000500
132 #define MRVL_AES_ENABLE_DECR_LOC    0x00000700
133 
134 /* convert 4 individual bytes into a 4 byte unsigned int */
135 #define MRVL_AES_GET_UINT32(x) ((x[3]<<24)|(x[2]<<16)|(x[1]<<8)|x[0])
136 
137 /* convert 4 byte unsigned int back to a 4 individual bytes */
138 #define MRVL_AES_CONVERT_UINT32_UINT8(x,u)              \
139     *u  = (UINT8)((((UINT32)x)&0x000000ff));            \
140     *(u + 1)= (UINT8)((((UINT32)x)&0x0000ff00)>>8);     \
141     *(u + 2)= (UINT8)((((UINT32)x)&0x00ff0000)>>16);    \
142     *(u + 3)= (UINT8)((((UINT32)x)&0xff000000)>>24)     \
143 
144 
145 /* HW register read macros */
146 #define MRVL_AES_READ32(x) (WL_REGS32(x))
147 #define MRVL_AES_READ16(x) (WL_REGS16(x))
148 #define MRVL_AES_READ8(x)  (WL_REGS8(x) )
149 
150 /* HW register write macros */
151 #define MRVL_AES_WRITE32(reg,val) (WL_WRITE_REGS32(reg,val))
152 #define MRVL_AES_WRITE16(reg,val) (WL_WRITE_REGS16(reg,val))
153 #define MRVL_AES_WRITE8(reg,val)  (WL_WRITE_REGS8(reg,val))
154 
155 extern UINT32 (*ramHook_CryptNew_EnterCritical) (void);
156 extern void (*ramHook_CryptNew_ExitCritical) (UINT32 intSave);
157 
158 extern int MRVL_AES_MEMCMP(UINT8 *dst, UINT8 *src, int len);
159 extern void MRVL_AES_MEMSET(UINT8 *dst, UINT8 val, int size);
160 extern void MRVL_AES_MEMCPY(UINT8 *dst, UINT8 *src, int size);
161 extern int MRVL_AesInterCheck(UINT8 *inter, UINT8 *d);
162 #ifdef DIAG_AES_CCM
163 extern void MRVL_AesCCMEncrypt(MRVL_ENDECRYPT_t *crypt, int *pErr);
164 extern void MRVL_AesCCMDecrypt(MRVL_ENDECRYPT_t *crypt, int *pErr);
165 #endif
166 
167 #endif /* _CRYPT_NEW_ROM_H_ */
168