blob: 1d7797f085f94d5e1adc66ba50145563e6d4fe63 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Qualcomm Crypto Engine driver QCEDEV API
2 *
3 * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
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#ifndef __QCEDEV__H
15#define __QCEDEV__H
16
17#include <linux/types.h>
18#include <linux/ioctl.h>
19
20#define QCEDEV_MAX_SHA_BLOCK_SIZE 64
21#define QCEDEV_MAX_BEARER 31
22#define QCEDEV_MAX_KEY_SIZE 64
23#define QCEDEV_MAX_IV_SIZE 32
24
25#define QCEDEV_MAX_BUFFERS 16
26#define QCEDEV_MAX_SHA_DIGEST 32
27
28#define QCEDEV_USE_PMEM 1
29#define QCEDEV_NO_PMEM 0
30
31#define QCEDEV_AES_KEY_128 16
32#define QCEDEV_AES_KEY_192 24
33#define QCEDEV_AES_KEY_256 32
34/**
35*qcedev_oper_enum: Operation types
36* @QCEDEV_OPER_ENC: Encrypt
37* @QCEDEV_OPER_DEC: Decrypt
38* @QCEDEV_OPER_ENC_NO_KEY: Encrypt. Do not need key to be specified by
39* user. Key already set by an external processor.
40* @QCEDEV_OPER_DEC_NO_KEY: Decrypt. Do not need the key to be specified by
41* user. Key already set by an external processor.
42*/
43enum qcedev_oper_enum {
44 QCEDEV_OPER_DEC = 0,
45 QCEDEV_OPER_ENC = 1,
46 QCEDEV_OPER_DEC_NO_KEY = 2,
47 QCEDEV_OPER_ENC_NO_KEY = 3,
48 QCEDEV_OPER_LAST
49};
50
51/**
52*qcedev_oper_enum: Cipher algorithm types
53* @QCEDEV_ALG_DES: DES
54* @QCEDEV_ALG_3DES: 3DES
55* @QCEDEV_ALG_AES: AES
56*/
57enum qcedev_cipher_alg_enum {
58 QCEDEV_ALG_DES = 0,
59 QCEDEV_ALG_3DES = 1,
60 QCEDEV_ALG_AES = 2,
61 QCEDEV_ALG_LAST
62};
63
64/**
65*qcedev_cipher_mode_enum : AES mode
66* @QCEDEV_AES_MODE_CBC: CBC
67* @QCEDEV_AES_MODE_ECB: ECB
68* @QCEDEV_AES_MODE_CTR: CTR
69* @QCEDEV_AES_MODE_XTS: XTS
70* @QCEDEV_AES_MODE_CCM: CCM
71* @QCEDEV_DES_MODE_CBC: CBC
72* @QCEDEV_DES_MODE_ECB: ECB
73*/
74enum qcedev_cipher_mode_enum {
75 QCEDEV_AES_MODE_CBC = 0,
76 QCEDEV_AES_MODE_ECB = 1,
77 QCEDEV_AES_MODE_CTR = 2,
78 QCEDEV_AES_MODE_XTS = 3,
79 QCEDEV_AES_MODE_CCM = 4,
80 QCEDEV_DES_MODE_CBC = 5,
81 QCEDEV_DES_MODE_ECB = 6,
82 QCEDEV_AES_DES_MODE_LAST
83};
84
85/**
86*enum qcedev_sha_alg_enum : Secure Hashing Algorithm
87* @QCEDEV_ALG_SHA1: Digest returned: 20 bytes (160 bits)
88* @QCEDEV_ALG_SHA256: Digest returned: 32 bytes (256 bit)
89* @QCEDEV_ALG_SHA1_HMAC: HMAC returned 20 bytes (160 bits)
90* @QCEDEV_ALG_SHA256_HMAC: HMAC returned 32 bytes (256 bit)
91* @QCEDEV_ALG_AES_CMAC: Configurable MAC size
92*/
93enum qcedev_sha_alg_enum {
94 QCEDEV_ALG_SHA1 = 0,
95 QCEDEV_ALG_SHA256 = 1,
96 QCEDEV_ALG_SHA1_HMAC = 2,
97 QCEDEV_ALG_SHA256_HMAC = 3,
98 QCEDEV_ALG_AES_CMAC = 4,
99 QCEDEV_ALG_SHA_ALG_LAST
100};
101
102/**
103* struct buf_info - Buffer information
104* @offset: Offset from the base address of the buffer
105* (Used when buffer is allocated using PMEM)
106* @vaddr: Virtual buffer address pointer
107* @len: Size of the buffer
108*/
109struct buf_info {
110 union{
111 uint32_t offset;
112 uint8_t *vaddr;
113 };
114 uint32_t len;
115};
116
117/**
118* struct qcedev_vbuf_info - Source and destination Buffer information
119* @src: Array of buf_info for input/source
120* @dst: Array of buf_info for output/destination
121*/
122struct qcedev_vbuf_info {
123 struct buf_info src[QCEDEV_MAX_BUFFERS];
124 struct buf_info dst[QCEDEV_MAX_BUFFERS];
125};
126
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700127/**
128* struct qcedev_pmem_info - Stores PMEM buffer information
129* @fd_src: Handle to /dev/adsp_pmem used to allocate
130* memory for input/src buffer
131* @src: Array of buf_info for input/source
132* @fd_dst: Handle to /dev/adsp_pmem used to allocate
133* memory for output/dst buffer
134* @dst: Array of buf_info for output/destination
135* @pmem_src_offset: The offset from input/src buffer
136* (allocated by PMEM)
137*/
138struct qcedev_pmem_info{
139 int fd_src;
140 struct buf_info src[QCEDEV_MAX_BUFFERS];
141 int fd_dst;
142 struct buf_info dst[QCEDEV_MAX_BUFFERS];
143};
144
145/**
146* struct qcedev_cipher_op_req - Holds the ciphering request information
147* @use_pmem (IN): Flag to indicate if buffer source is PMEM
148* QCEDEV_USE_PMEM/QCEDEV_NO_PMEM
149* @pmem (IN): Stores PMEM buffer information.
150* Refer struct qcedev_pmem_info
151* @vbuf (IN/OUT): Stores Source and destination Buffer information
152* Refer to struct qcedev_vbuf_info
153* @data_len (IN): Total Length of input/src and output/dst in bytes
154* @in_place_op (IN): Indicates whether the operation is inplace where
155* source == destination
156* When using PMEM allocated memory, must set this to 1
157* @enckey (IN): 128 bits of confidentiality key
158* enckey[0] bit 127-120, enckey[1] bit 119-112,..
159* enckey[15] bit 7-0
160* @encklen (IN): Length of the encryption key(set to 128 bits/16
161* bytes in the driver)
162* @iv (IN/OUT): Initialisation vector data
163* This is updated by the driver, incremented by
164* number of blocks encrypted/decrypted.
165* @ivlen (IN): Length of the IV
166* @byteoffset (IN): Offset in the Cipher BLOCK (applicable and to be set
167* for AES-128 CTR mode only)
168* @alg (IN): Type of ciphering algorithm: AES/DES/3DES
169* @mode (IN): Mode use when using AES algorithm: ECB/CBC/CTR
170* Apllicabel when using AES algorithm only
171* @op (IN): Type of operation: QCEDEV_OPER_DEC/QCEDEV_OPER_ENC or
172* QCEDEV_OPER_ENC_NO_KEY/QCEDEV_OPER_DEC_NO_KEY
173*
174*If use_pmem is set to 0, the driver assumes that memory was not allocated
175* via PMEM, and kernel will need to allocate memory and copy data from user
176* space buffer (data_src/dta_dst) and process accordingly and copy data back
177* to the user space buffer
178*
179* If use_pmem is set to 1, the driver assumes that memory was allocated via
180* PMEM.
181* The kernel driver will use the fd_src to determine the kernel virtual address
182* base that maps to the user space virtual address base for the buffer
183* allocated in user space.
184* The final input/src and output/dst buffer pointer will be determined
185* by adding the offsets to the kernel virtual addr.
186*
187* If use of hardware key is supported in the target, user can configure the
188* key paramters (encklen, enckey) to use the hardware key.
189* In order to use the hardware key, set encklen to 0 and set the enckey
190* data array to 0.
191*/
192struct qcedev_cipher_op_req {
193 uint8_t use_pmem;
194 union{
195 struct qcedev_pmem_info pmem;
196 struct qcedev_vbuf_info vbuf;
197 };
198 uint32_t entries;
199 uint32_t data_len;
200 uint8_t in_place_op;
201 uint8_t enckey[QCEDEV_MAX_KEY_SIZE];
202 uint32_t encklen;
203 uint8_t iv[QCEDEV_MAX_IV_SIZE];
204 uint32_t ivlen;
205 uint32_t byteoffset;
206 enum qcedev_cipher_alg_enum alg;
207 enum qcedev_cipher_mode_enum mode;
208 enum qcedev_oper_enum op;
209};
210
211/**
212* struct qcedev_sha_op_req - Holds the hashing request information
213* @data (IN): Array of pointers to the data to be hashed
214* @entries (IN): Number of buf_info entries in the data array
215* @data_len (IN): Length of data to be hashed
216* @digest (IN/OUT): Returns the hashed data information
217* @diglen (OUT): Size of the hashed/digest data
218* @authkey (IN): Pointer to authentication key for HMAC
219* @authklen (IN): Size of the authentication key
220* @alg (IN): Secure Hash algorithm
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700221*/
222struct qcedev_sha_op_req {
223 struct buf_info data[QCEDEV_MAX_BUFFERS];
224 uint32_t entries;
225 uint32_t data_len;
226 uint8_t digest[QCEDEV_MAX_SHA_DIGEST];
227 uint32_t diglen;
228 uint8_t *authkey;
229 uint32_t authklen;
230 enum qcedev_sha_alg_enum alg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700231};
232
233
234#define QCEDEV_IOC_MAGIC 0x87
235
236#define QCEDEV_IOCTL_ENC_REQ \
237 _IOWR(QCEDEV_IOC_MAGIC, 1, struct qcedev_cipher_op_req)
238#define QCEDEV_IOCTL_DEC_REQ \
239 _IOWR(QCEDEV_IOC_MAGIC, 2, struct qcedev_cipher_op_req)
240#define QCEDEV_IOCTL_SHA_INIT_REQ \
241 _IOWR(QCEDEV_IOC_MAGIC, 3, struct qcedev_sha_op_req)
242#define QCEDEV_IOCTL_SHA_UPDATE_REQ \
243 _IOWR(QCEDEV_IOC_MAGIC, 4, struct qcedev_sha_op_req)
244#define QCEDEV_IOCTL_SHA_FINAL_REQ \
245 _IOWR(QCEDEV_IOC_MAGIC, 5, struct qcedev_sha_op_req)
246#define QCEDEV_IOCTL_GET_SHA_REQ \
247 _IOWR(QCEDEV_IOC_MAGIC, 6, struct qcedev_sha_op_req)
248#define QCEDEV_IOCTL_LOCK_CE \
249 _IO(QCEDEV_IOC_MAGIC, 7)
250#define QCEDEV_IOCTL_UNLOCK_CE \
251 _IO(QCEDEV_IOC_MAGIC, 8)
252#define QCEDEV_IOCTL_GET_CMAC_REQ \
253 _IOWR(QCEDEV_IOC_MAGIC, 9, struct qcedev_cipher_op_req)
254#endif /* _QCEDEV__H */