Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sep_crypto.h
Go to the documentation of this file.
1 /*
2  *
3  * sep_crypto.h - Crypto interface structures
4  *
5  * Copyright(c) 2009-2011 Intel Corporation. All rights reserved.
6  * Contributions(c) 2009-2010 Discretix. All rights reserved.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the Free
10  * Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc., 59
19  * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * CONTACTS:
22  *
23  * Mark Allyn [email protected]
24  * Jayant Mangalampalli [email protected]
25  *
26  * CHANGES:
27  *
28  * 2009.06.26 Initial publish
29  * 2011.02.22 Enable Kernel Crypto
30  *
31  */
32 
33 /* Constants for SEP (from vendor) */
34 #define SEP_START_MSG_TOKEN 0x02558808
35 
36 #define SEP_DES_IV_SIZE_WORDS 2
37 #define SEP_DES_IV_SIZE_BYTES (SEP_DES_IV_SIZE_WORDS * \
38  sizeof(u32))
39 #define SEP_DES_KEY_SIZE_WORDS 2
40 #define SEP_DES_KEY_SIZE_BYTES (SEP_DES_KEY_SIZE_WORDS * \
41  sizeof(u32))
42 #define SEP_DES_BLOCK_SIZE 8
43 #define SEP_DES_DUMMY_SIZE 16
44 
45 #define SEP_DES_INIT_OPCODE 0x10
46 #define SEP_DES_BLOCK_OPCODE 0x11
47 
48 #define SEP_AES_BLOCK_SIZE_WORDS 4
49 #define SEP_AES_BLOCK_SIZE_BYTES \
50  (SEP_AES_BLOCK_SIZE_WORDS * sizeof(u32))
51 
52 #define SEP_AES_DUMMY_BLOCK_SIZE 16
53 #define SEP_AES_IV_SIZE_WORDS SEP_AES_BLOCK_SIZE_WORDS
54 #define SEP_AES_IV_SIZE_BYTES \
55  (SEP_AES_IV_SIZE_WORDS * sizeof(u32))
56 
57 #define SEP_AES_KEY_128_SIZE 16
58 #define SEP_AES_KEY_192_SIZE 24
59 #define SEP_AES_KEY_256_SIZE 32
60 #define SEP_AES_KEY_512_SIZE 64
61 #define SEP_AES_MAX_KEY_SIZE_WORDS 16
62 #define SEP_AES_MAX_KEY_SIZE_BYTES \
63  (SEP_AES_MAX_KEY_SIZE_WORDS * sizeof(u32))
64 
65 #define SEP_AES_WRAP_MIN_SIZE 8
66 #define SEP_AES_WRAP_MAX_SIZE 0x10000000
67 
68 #define SEP_AES_WRAP_BLOCK_SIZE_WORDS 2
69 #define SEP_AES_WRAP_BLOCK_SIZE_BYTES \
70  (SEP_AES_WRAP_BLOCK_SIZE_WORDS * sizeof(u32))
71 
72 #define SEP_AES_SECRET_RKEK1 0x1
73 #define SEP_AES_SECRET_RKEK2 0x2
74 
75 #define SEP_AES_INIT_OPCODE 0x2
76 #define SEP_AES_BLOCK_OPCODE 0x3
77 #define SEP_AES_FINISH_OPCODE 0x4
78 #define SEP_AES_WRAP_OPCODE 0x6
79 #define SEP_AES_UNWRAP_OPCODE 0x7
80 #define SEP_AES_XTS_FINISH_OPCODE 0x8
81 
82 #define SEP_HASH_RESULT_SIZE_WORDS 16
83 #define SEP_MD5_DIGEST_SIZE_WORDS 4
84 #define SEP_MD5_DIGEST_SIZE_BYTES \
85  (SEP_MD5_DIGEST_SIZE_WORDS * sizeof(u32))
86 #define SEP_SHA1_DIGEST_SIZE_WORDS 5
87 #define SEP_SHA1_DIGEST_SIZE_BYTES \
88  (SEP_SHA1_DIGEST_SIZE_WORDS * sizeof(u32))
89 #define SEP_SHA224_DIGEST_SIZE_WORDS 7
90 #define SEP_SHA224_DIGEST_SIZE_BYTES \
91  (SEP_SHA224_DIGEST_SIZE_WORDS * sizeof(u32))
92 #define SEP_SHA256_DIGEST_SIZE_WORDS 8
93 #define SEP_SHA256_DIGEST_SIZE_BYTES \
94  (SEP_SHA256_DIGEST_SIZE_WORDS * sizeof(u32))
95 #define SEP_SHA384_DIGEST_SIZE_WORDS 12
96 #define SEP_SHA384_DIGEST_SIZE_BYTES \
97  (SEP_SHA384_DIGEST_SIZE_WORDS * sizeof(u32))
98 #define SEP_SHA512_DIGEST_SIZE_WORDS 16
99 #define SEP_SHA512_DIGEST_SIZE_BYTES \
100  (SEP_SHA512_DIGEST_SIZE_WORDS * sizeof(u32))
101 #define SEP_HASH_BLOCK_SIZE_WORDS 16
102 #define SEP_HASH_BLOCK_SIZE_BYTES \
103  (SEP_HASH_BLOCK_SIZE_WORDS * sizeof(u32))
104 #define SEP_SHA2_BLOCK_SIZE_WORDS 32
105 #define SEP_SHA2_BLOCK_SIZE_BYTES \
106  (SEP_SHA2_BLOCK_SIZE_WORDS * sizeof(u32))
107 
108 #define SEP_HASH_INIT_OPCODE 0x20
109 #define SEP_HASH_UPDATE_OPCODE 0x21
110 #define SEP_HASH_FINISH_OPCODE 0x22
111 #define SEP_HASH_SINGLE_OPCODE 0x23
112 
113 #define SEP_HOST_ERROR 0x0b000000
114 #define SEP_OK 0x0
115 #define SEP_INVALID_START (SEP_HOST_ERROR + 0x3)
116 #define SEP_WRONG_OPCODE (SEP_HOST_ERROR + 0x1)
117 
118 #define SEP_TRANSACTION_WAIT_TIME 5
119 
120 #define SEP_QUEUE_LENGTH 2
121 /* Macros */
122 #ifndef __LITTLE_ENDIAN
123 #define CHG_ENDIAN(val) \
124  (((val) >> 24) | \
125  (((val) & 0x00FF0000) >> 8) | \
126  (((val) & 0x0000FF00) << 8) | \
127  (((val) & 0x000000FF) << 24))
128 #else
129 #define CHG_ENDIAN(val) val
130 #endif
131 /* Enums for SEP (from vendor) */
137  SEP_NUMKEY_LAST = 0x7fffffff,
138 };
139 
144  SEP_DES_ENC_LAST = 0x7fffffff,
145 };
146 
151  SEP_OP_LAST = 0x7fffffff,
152 };
153 
155  AES_128 = 0,
156  AES_192 = 1,
157  AES_256 = 2,
158  AES_512 = 3,
160  AEA_SIZE_LAST = 0x7FFFFFFF,
161 };
162 
167  SEP_AES_ENC_LAST = 0x7FFFFFFF,
168 };
169 
179  SEP_AES_OP_LAST = 0x7FFFFFFF,
180 };
181 
190  SEP_HASH_LAST_MODE = 0x7FFFFFFF,
191 };
192 
193 /* Structures for SEP (from vendor) */
198 };
199 
207 };
208 
213 };
214 
215 /* This is the structure passed to SEP via msg area */
216 struct sep_des_key {
221 };
222 
235  union {
236  struct {
240  } cmac_data;
241  struct {
245  } xtx_data;
246  } s_data;
248 };
249 
255 };
256 
265 };
266 
271 };
272 
273 union key_t {
274  struct sep_des_key des;
276 };
277 
278 /* Context structures for crypto API */
294  unsigned char iv[100];
301  size_t data_length;
302  size_t ivlen;
304  int i_own_sep; /* Do I have custody of the sep? */
309  size_t nbytes;
314  void *msgptr;
335  unsigned long end_time;
336  };
337 
339  union key_t key;
340  size_t keylen;
341  int key_sent;
344  unsigned long end_time;
348  };
349 
350 /* work queue structures */
353  void (*callback)(void *);
354  void *data;
355  };
356 
357 /* Functions */
358 int sep_crypto_setup(void);
359 void sep_crypto_takedown(void);