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