hifn7751var.h revision 1.1.2.2 1 1.1.2.2 bouyer /* $NetBSD: hifn7751var.h,v 1.1.2.2 2000/11/20 11:42:20 bouyer Exp $ */
2 1.1.2.2 bouyer /* $OpenBSD: hifn7751var.h,v 1.18 2000/06/02 22:36:45 deraadt Exp $ */
3 1.1.2.2 bouyer
4 1.1.2.2 bouyer /*
5 1.1.2.2 bouyer * Invertex AEON / Hi/fn 7751 driver
6 1.1.2.2 bouyer * Copyright (c) 1999 Invertex Inc. All rights reserved.
7 1.1.2.2 bouyer * Copyright (c) 1999 Theo de Raadt
8 1.1.2.2 bouyer * Copyright (c) 2000 Network Security Technologies, Inc.
9 1.1.2.2 bouyer * http://www.netsec.net
10 1.1.2.2 bouyer *
11 1.1.2.2 bouyer * Please send any comments, feedback, bug-fixes, or feature requests to
12 1.1.2.2 bouyer * software (at) invertex.com.
13 1.1.2.2 bouyer *
14 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
15 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
16 1.1.2.2 bouyer * are met:
17 1.1.2.2 bouyer *
18 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
19 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
20 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
21 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
22 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
23 1.1.2.2 bouyer * 3. The name of the author may not be used to endorse or promote products
24 1.1.2.2 bouyer * derived from this software without specific prior written permission.
25 1.1.2.2 bouyer *
26 1.1.2.2 bouyer *
27 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 1.1.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 1.1.2.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 1.1.2.2 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31 1.1.2.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 1.1.2.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 1.1.2.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 1.1.2.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 1.1.2.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36 1.1.2.2 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.2 bouyer *
38 1.1.2.2 bouyer */
39 1.1.2.2 bouyer
40 1.1.2.2 bouyer #ifndef __DEV_PCI_HIFN7751VAR_H__
41 1.1.2.2 bouyer #define __DEV_PCI_HIFN7751VAR_H__
42 1.1.2.2 bouyer
43 1.1.2.2 bouyer /*
44 1.1.2.2 bouyer * Length values for cryptography
45 1.1.2.2 bouyer */
46 1.1.2.2 bouyer #define HIFN_DES_KEY_LENGTH 8
47 1.1.2.2 bouyer #define HIFN_3DES_KEY_LENGTH 24
48 1.1.2.2 bouyer #define HIFN_MAX_CRYPT_KEY_LENGTH HIFN_3DES_KEY_LENGTH
49 1.1.2.2 bouyer #define HIFN_IV_LENGTH 8
50 1.1.2.2 bouyer
51 1.1.2.2 bouyer /*
52 1.1.2.2 bouyer * Length values for authentication
53 1.1.2.2 bouyer */
54 1.1.2.2 bouyer #define HIFN_MAC_KEY_LENGTH 64
55 1.1.2.2 bouyer #define HIFN_MD5_LENGTH 16
56 1.1.2.2 bouyer #define HIFN_SHA1_LENGTH 20
57 1.1.2.2 bouyer #define HIFN_MAC_TRUNC_LENGTH 12
58 1.1.2.2 bouyer
59 1.1.2.2 bouyer #define MAX_SCATTER 64
60 1.1.2.2 bouyer
61 1.1.2.2 bouyer /*
62 1.1.2.2 bouyer * hifn_command_t
63 1.1.2.2 bouyer *
64 1.1.2.2 bouyer * This is the control structure used to pass commands to hifn_encrypt().
65 1.1.2.2 bouyer *
66 1.1.2.2 bouyer * flags
67 1.1.2.2 bouyer * -----
68 1.1.2.2 bouyer * Flags is the bitwise "or" values for command configuration. A single
69 1.1.2.2 bouyer * encrypt direction needs to be set:
70 1.1.2.2 bouyer *
71 1.1.2.2 bouyer * HIFN_ENCODE or HIFN_DECODE
72 1.1.2.2 bouyer *
73 1.1.2.2 bouyer * To use cryptography, a single crypto algorithm must be included:
74 1.1.2.2 bouyer *
75 1.1.2.2 bouyer * HIFN_CRYPT_3DES or HIFN_CRYPT_DES
76 1.1.2.2 bouyer *
77 1.1.2.2 bouyer * To use authentication is used, a single MAC algorithm must be included:
78 1.1.2.2 bouyer *
79 1.1.2.2 bouyer * HIFN_MAC_MD5 or HIFN_MAC_SHA1
80 1.1.2.2 bouyer *
81 1.1.2.2 bouyer * By default MD5 uses a 16 byte hash and SHA-1 uses a 20 byte hash.
82 1.1.2.2 bouyer * If the value below is set, hash values are truncated or assumed
83 1.1.2.2 bouyer * truncated to 12 bytes:
84 1.1.2.2 bouyer *
85 1.1.2.2 bouyer * HIFN_MAC_TRUNC
86 1.1.2.2 bouyer *
87 1.1.2.2 bouyer * Keys for encryption and authentication can be sent as part of a command,
88 1.1.2.2 bouyer * or the last key value used with a particular session can be retrieved
89 1.1.2.2 bouyer * and used again if either of these flags are not specified.
90 1.1.2.2 bouyer *
91 1.1.2.2 bouyer * HIFN_CRYPT_NEW_KEY, HIFN_MAC_NEW_KEY
92 1.1.2.2 bouyer *
93 1.1.2.2 bouyer * result_flags
94 1.1.2.2 bouyer * ------------
95 1.1.2.2 bouyer * result_flags is a bitwise "or" of result values. The result_flags
96 1.1.2.2 bouyer * values should not be considered valid until:
97 1.1.2.2 bouyer *
98 1.1.2.2 bouyer * callback routine NULL: hifn_crypto() returns
99 1.1.2.2 bouyer * callback routine set: callback routine called
100 1.1.2.2 bouyer *
101 1.1.2.2 bouyer * Right now there is only one result flag: HIFN_MAC_BAD
102 1.1.2.2 bouyer * It's bit is set on decode operations using authentication when a
103 1.1.2.2 bouyer * hash result does not match the input hash value.
104 1.1.2.2 bouyer * The HIFN_MAC_OK(r) macro can be used to help inspect this flag.
105 1.1.2.2 bouyer *
106 1.1.2.2 bouyer * session_num
107 1.1.2.2 bouyer * -----------
108 1.1.2.2 bouyer * A number between 0 and 2048 (for DRAM models) or a number between
109 1.1.2.2 bouyer * 0 and 768 (for SRAM models). Those who don't want to use session
110 1.1.2.2 bouyer * numbers should leave value at zero and send a new crypt key and/or
111 1.1.2.2 bouyer * new MAC key on every command. If you use session numbers and
112 1.1.2.2 bouyer * don't send a key with a command, the last key sent for that same
113 1.1.2.2 bouyer * session number will be used.
114 1.1.2.2 bouyer *
115 1.1.2.2 bouyer * Warning: Using session numbers and multiboard at the same time
116 1.1.2.2 bouyer * is currently broken.
117 1.1.2.2 bouyer *
118 1.1.2.2 bouyer * mbuf
119 1.1.2.2 bouyer * ----
120 1.1.2.2 bouyer * Either fill in the mbuf pointer and npa=0 or
121 1.1.2.2 bouyer * fill packp[] and packl[] and set npa to > 0
122 1.1.2.2 bouyer *
123 1.1.2.2 bouyer * mac_header_skip
124 1.1.2.2 bouyer * ---------------
125 1.1.2.2 bouyer * The number of bytes of the source_buf that are skipped over before
126 1.1.2.2 bouyer * authentication begins. This must be a number between 0 and 2^16-1
127 1.1.2.2 bouyer * and can be used by IPSec implementers to skip over IP headers.
128 1.1.2.2 bouyer * *** Value ignored if authentication not used ***
129 1.1.2.2 bouyer *
130 1.1.2.2 bouyer * crypt_header_skip
131 1.1.2.2 bouyer * -----------------
132 1.1.2.2 bouyer * The number of bytes of the source_buf that are skipped over before
133 1.1.2.2 bouyer * the cryptographic operation begins. This must be a number between 0
134 1.1.2.2 bouyer * and 2^16-1. For IPSec, this number will always be 8 bytes larger
135 1.1.2.2 bouyer * than the auth_header_skip (to skip over the ESP header).
136 1.1.2.2 bouyer * *** Value ignored if cryptography not used ***
137 1.1.2.2 bouyer *
138 1.1.2.2 bouyer * source_length
139 1.1.2.2 bouyer * -------------
140 1.1.2.2 bouyer * Length of input data including all skipped headers. On decode
141 1.1.2.2 bouyer * operations using authentication, the length must also include the
142 1.1.2.2 bouyer * the appended MAC hash (12, 16, or 20 bytes depending on algorithm
143 1.1.2.2 bouyer * and truncation settings).
144 1.1.2.2 bouyer *
145 1.1.2.2 bouyer * If encryption is used, the encryption payload must be a non-zero
146 1.1.2.2 bouyer * multiple of 8. On encode operations, the encryption payload size
147 1.1.2.2 bouyer * is (source_length - crypt_header_skip - (MAC hash size)). On
148 1.1.2.2 bouyer * decode operations, the encryption payload is
149 1.1.2.2 bouyer * (source_length - crypt_header_skip).
150 1.1.2.2 bouyer *
151 1.1.2.2 bouyer * dest_length
152 1.1.2.2 bouyer * -----------
153 1.1.2.2 bouyer * Length of the dest buffer. It must be at least as large as the
154 1.1.2.2 bouyer * source buffer when authentication is not used. When authentication
155 1.1.2.2 bouyer * is used on an encode operation, it must be at least as long as the
156 1.1.2.2 bouyer * source length plus an extra 12, 16, or 20 bytes to hold the MAC
157 1.1.2.2 bouyer * value (length of mac value varies with algorithm used). When
158 1.1.2.2 bouyer * authentication is used on decode operations, it must be at least
159 1.1.2.2 bouyer * as long as the source buffer minus 12, 16, or 20 bytes for the MAC
160 1.1.2.2 bouyer * value which is not included in the dest data. Unlike source_length,
161 1.1.2.2 bouyer * the dest_length does not have to be exact, values larger than required
162 1.1.2.2 bouyer * are fine.
163 1.1.2.2 bouyer *
164 1.1.2.2 bouyer * private_data
165 1.1.2.2 bouyer * ------------
166 1.1.2.2 bouyer * An unsigned long quantity (i.e. large enough to hold a pointer), that
167 1.1.2.2 bouyer * can be used by the callback routine if desired.
168 1.1.2.2 bouyer */
169 1.1.2.2 bouyer struct hifn_softc;
170 1.1.2.2 bouyer
171 1.1.2.2 bouyer typedef struct hifn_command {
172 1.1.2.2 bouyer volatile u_int result_flags;
173 1.1.2.2 bouyer
174 1.1.2.2 bouyer u_short session_num;
175 1.1.2.2 bouyer u_int16_t base_masks, cry_masks, mac_masks;
176 1.1.2.2 bouyer
177 1.1.2.2 bouyer u_char iv[HIFN_IV_LENGTH], *ck, mac[HIFN_MAC_KEY_LENGTH];
178 1.1.2.2 bouyer
179 1.1.2.2 bouyer struct mbuf *src_m;
180 1.1.2.2 bouyer long src_packp[MAX_SCATTER];
181 1.1.2.2 bouyer int src_packl[MAX_SCATTER];
182 1.1.2.2 bouyer int src_npa;
183 1.1.2.2 bouyer int src_l;
184 1.1.2.2 bouyer
185 1.1.2.2 bouyer struct mbuf *dst_m;
186 1.1.2.2 bouyer long dst_packp[MAX_SCATTER];
187 1.1.2.2 bouyer int dst_packl[MAX_SCATTER];
188 1.1.2.2 bouyer int dst_npa;
189 1.1.2.2 bouyer int dst_l;
190 1.1.2.2 bouyer
191 1.1.2.2 bouyer u_short mac_header_skip, mac_process_len;
192 1.1.2.2 bouyer u_short crypt_header_skip, crypt_process_len;
193 1.1.2.2 bouyer
194 1.1.2.2 bouyer u_long private_data;
195 1.1.2.2 bouyer struct hifn_softc *softc;
196 1.1.2.2 bouyer } hifn_command_t;
197 1.1.2.2 bouyer
198 1.1.2.2 bouyer /*
199 1.1.2.2 bouyer * Return values for hifn_crypto()
200 1.1.2.2 bouyer */
201 1.1.2.2 bouyer #define HIFN_CRYPTO_SUCCESS 0
202 1.1.2.2 bouyer #define HIFN_CRYPTO_BAD_INPUT (-1)
203 1.1.2.2 bouyer #define HIFN_CRYPTO_RINGS_FULL (-2)
204 1.1.2.2 bouyer
205 1.1.2.2 bouyer /*
206 1.1.2.2 bouyer * Defines for the "result_flags" parameter of hifn_command_t.
207 1.1.2.2 bouyer */
208 1.1.2.2 bouyer #define HIFN_MAC_BAD 1
209 1.1.2.2 bouyer #define HIFN_MAC_OK(r) (!((r) & HIFN_MAC_BAD))
210 1.1.2.2 bouyer
211 1.1.2.2 bouyer #ifdef _KERNEL
212 1.1.2.2 bouyer
213 1.1.2.2 bouyer /**************************************************************************
214 1.1.2.2 bouyer *
215 1.1.2.2 bouyer * Function: hifn_crypto
216 1.1.2.2 bouyer *
217 1.1.2.2 bouyer * Purpose: Called by external drivers to begin an encryption on the
218 1.1.2.2 bouyer * HIFN board.
219 1.1.2.2 bouyer *
220 1.1.2.2 bouyer * Blocking/Non-blocking Issues
221 1.1.2.2 bouyer * ============================
222 1.1.2.2 bouyer * The driver cannot block in hifn_crypto (no calls to tsleep) currently.
223 1.1.2.2 bouyer * hifn_crypto() returns HIFN_CRYPTO_RINGS_FULL if there is not enough
224 1.1.2.2 bouyer * room in any of the rings for the request to proceed.
225 1.1.2.2 bouyer *
226 1.1.2.2 bouyer * Return Values
227 1.1.2.2 bouyer * =============
228 1.1.2.2 bouyer * 0 for success, negative values on error
229 1.1.2.2 bouyer *
230 1.1.2.2 bouyer * Defines for negative error codes are:
231 1.1.2.2 bouyer *
232 1.1.2.2 bouyer * HIFN_CRYPTO_BAD_INPUT : The passed in command had invalid settings.
233 1.1.2.2 bouyer * HIFN_CRYPTO_RINGS_FULL : All DMA rings were full and non-blocking
234 1.1.2.2 bouyer * behaviour was requested.
235 1.1.2.2 bouyer *
236 1.1.2.2 bouyer *************************************************************************/
237 1.1.2.2 bouyer
238 1.1.2.2 bouyer /*
239 1.1.2.2 bouyer * Convert back and forth from 'sid' to 'card' and 'session'
240 1.1.2.2 bouyer */
241 1.1.2.2 bouyer #define HIFN_CARD(sid) (((sid) & 0xf0000000) >> 28)
242 1.1.2.2 bouyer #define HIFN_SESSION(sid) ((sid) & 0x000007ff)
243 1.1.2.2 bouyer #define HIFN_SID(crd,ses) (((crd) << 28) | ((ses) & 0x7ff))
244 1.1.2.2 bouyer
245 1.1.2.2 bouyer #endif /* _KERNEL */
246 1.1.2.2 bouyer
247 1.1.2.2 bouyer #endif /* __DEV_PCI_HIFN7751VAR_H__ */
248