xform.c revision 1.18.4.3 1 1.18.4.1 rmind /* $NetBSD: xform.c,v 1.18.4.3 2011/05/31 03:05:10 rmind Exp $ */
2 1.1 jonathan /* $FreeBSD: src/sys/opencrypto/xform.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $ */
3 1.1 jonathan /* $OpenBSD: xform.c,v 1.19 2002/08/16 22:47:25 dhartmei Exp $ */
4 1.1 jonathan
5 1.1 jonathan /*
6 1.1 jonathan * The authors of this code are John Ioannidis (ji (at) tla.org),
7 1.1 jonathan * Angelos D. Keromytis (kermit (at) csd.uch.gr) and
8 1.1 jonathan * Niels Provos (provos (at) physnet.uni-hamburg.de).
9 1.1 jonathan *
10 1.1 jonathan * This code was written by John Ioannidis for BSD/OS in Athens, Greece,
11 1.1 jonathan * in November 1995.
12 1.1 jonathan *
13 1.1 jonathan * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
14 1.1 jonathan * by Angelos D. Keromytis.
15 1.1 jonathan *
16 1.1 jonathan * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
17 1.1 jonathan * and Niels Provos.
18 1.1 jonathan *
19 1.1 jonathan * Additional features in 1999 by Angelos D. Keromytis.
20 1.1 jonathan *
21 1.1 jonathan * Copyright (C) 1995, 1996, 1997, 1998, 1999 by John Ioannidis,
22 1.1 jonathan * Angelos D. Keromytis and Niels Provos.
23 1.1 jonathan *
24 1.1 jonathan * Copyright (C) 2001, Angelos D. Keromytis.
25 1.1 jonathan *
26 1.1 jonathan * Permission to use, copy, and modify this software with or without fee
27 1.1 jonathan * is hereby granted, provided that this entire notice is included in
28 1.1 jonathan * all copies of any software which is or includes a copy or
29 1.1 jonathan * modification of this software.
30 1.1 jonathan * You may use this code under the GNU public license if you so wish. Please
31 1.1 jonathan * contribute changes back to the authors under this freer than GPL license
32 1.1 jonathan * so that we may further the use of strong encryption without limitations to
33 1.1 jonathan * all.
34 1.1 jonathan *
35 1.1 jonathan * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
36 1.1 jonathan * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
37 1.1 jonathan * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
38 1.1 jonathan * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
39 1.1 jonathan * PURPOSE.
40 1.1 jonathan */
41 1.1 jonathan
42 1.1 jonathan #include <sys/cdefs.h>
43 1.18.4.1 rmind __KERNEL_RCSID(0, "$NetBSD: xform.c,v 1.18.4.3 2011/05/31 03:05:10 rmind Exp $");
44 1.1 jonathan
45 1.1 jonathan #include <sys/param.h>
46 1.1 jonathan #include <sys/malloc.h>
47 1.1 jonathan
48 1.1 jonathan #include <opencrypto/cryptodev.h>
49 1.1 jonathan #include <opencrypto/xform.h>
50 1.1 jonathan
51 1.15 thorpej MALLOC_DEFINE(M_XDATA, "xform", "xform data buffers");
52 1.1 jonathan
53 1.18.4.1 rmind const u_int8_t hmac_ipad_buffer[128] = {
54 1.18.4.1 rmind 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
55 1.18.4.1 rmind 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
56 1.18.4.1 rmind 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
57 1.18.4.1 rmind 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
58 1.18.4.1 rmind 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
59 1.18.4.1 rmind 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
60 1.18.4.1 rmind 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
61 1.18.4.1 rmind 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
62 1.15 thorpej 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
63 1.15 thorpej 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
64 1.15 thorpej 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
65 1.15 thorpej 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
66 1.15 thorpej 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
67 1.15 thorpej 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
68 1.15 thorpej 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
69 1.15 thorpej 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36
70 1.15 thorpej };
71 1.15 thorpej
72 1.18.4.1 rmind const u_int8_t hmac_opad_buffer[128] = {
73 1.18.4.1 rmind 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
74 1.18.4.1 rmind 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
75 1.18.4.1 rmind 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
76 1.18.4.1 rmind 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
77 1.18.4.1 rmind 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
78 1.18.4.1 rmind 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
79 1.18.4.1 rmind 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
80 1.18.4.1 rmind 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
81 1.15 thorpej 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
82 1.15 thorpej 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
83 1.15 thorpej 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
84 1.15 thorpej 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
85 1.15 thorpej 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
86 1.15 thorpej 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
87 1.15 thorpej 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
88 1.15 thorpej 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C
89 1.15 thorpej };
90 1.1 jonathan
91 1.1 jonathan /* Encryption instances */
92 1.18.4.2 rmind const struct enc_xform enc_xform_null = {
93 1.1 jonathan CRYPTO_NULL_CBC, "NULL",
94 1.1 jonathan /* NB: blocksize of 4 is to generate a properly aligned ESP header */
95 1.18.4.3 rmind 4, 0, 0, 256 /* 2048 bits, max key */
96 1.1 jonathan };
97 1.1 jonathan
98 1.18.4.2 rmind const struct enc_xform enc_xform_des = {
99 1.1 jonathan CRYPTO_DES_CBC, "DES",
100 1.18.4.3 rmind 8, 8, 8, 8
101 1.1 jonathan };
102 1.1 jonathan
103 1.18.4.2 rmind const struct enc_xform enc_xform_3des = {
104 1.1 jonathan CRYPTO_3DES_CBC, "3DES",
105 1.18.4.3 rmind 8, 8, 24, 24
106 1.1 jonathan };
107 1.1 jonathan
108 1.18.4.2 rmind const struct enc_xform enc_xform_blf = {
109 1.1 jonathan CRYPTO_BLF_CBC, "Blowfish",
110 1.18.4.3 rmind 8, 8, 5, 56 /* 448 bits, max key */
111 1.1 jonathan };
112 1.1 jonathan
113 1.18.4.2 rmind const struct enc_xform enc_xform_cast5 = {
114 1.1 jonathan CRYPTO_CAST_CBC, "CAST-128",
115 1.18.4.3 rmind 8, 8, 5, 16
116 1.1 jonathan };
117 1.1 jonathan
118 1.18.4.2 rmind const struct enc_xform enc_xform_skipjack = {
119 1.1 jonathan CRYPTO_SKIPJACK_CBC, "Skipjack",
120 1.18.4.3 rmind 8, 8, 10, 10
121 1.1 jonathan };
122 1.1 jonathan
123 1.18.4.2 rmind const struct enc_xform enc_xform_rijndael128 = {
124 1.1 jonathan CRYPTO_RIJNDAEL128_CBC, "Rijndael-128/AES",
125 1.18.4.3 rmind 16, 16, 16, 32
126 1.1 jonathan };
127 1.1 jonathan
128 1.18.4.2 rmind const struct enc_xform enc_xform_arc4 = {
129 1.1 jonathan CRYPTO_ARC4, "ARC4",
130 1.18.4.3 rmind 1, 0, 1, 32
131 1.18.4.3 rmind };
132 1.18.4.3 rmind
133 1.18.4.3 rmind const struct enc_xform enc_xform_camellia = {
134 1.18.4.3 rmind CRYPTO_CAMELLIA_CBC, "Camellia",
135 1.18.4.3 rmind 16, 16, 8, 32
136 1.18.4.3 rmind };
137 1.18.4.3 rmind
138 1.18.4.3 rmind const struct enc_xform enc_xform_aes_ctr = {
139 1.18.4.3 rmind CRYPTO_AES_CTR, "AES-CTR",
140 1.18.4.3 rmind 16, 8, 16+4, 32+4
141 1.18.4.3 rmind };
142 1.18.4.3 rmind
143 1.18.4.3 rmind const struct enc_xform enc_xform_aes_gcm = {
144 1.18.4.3 rmind CRYPTO_AES_GCM_16, "AES-GCM",
145 1.18.4.3 rmind 4 /* ??? */, 8, 16+4, 32+4
146 1.18.4.3 rmind };
147 1.18.4.3 rmind
148 1.18.4.3 rmind const struct enc_xform enc_xform_aes_gmac = {
149 1.18.4.3 rmind CRYPTO_AES_GMAC, "AES-GMAC",
150 1.18.4.3 rmind 4 /* ??? */, 8, 16+4, 32+4
151 1.1 jonathan };
152 1.1 jonathan
153 1.1 jonathan /* Authentication instances */
154 1.18.4.2 rmind const struct auth_hash auth_hash_null = {
155 1.1 jonathan CRYPTO_NULL_HMAC, "NULL-HMAC",
156 1.18.4.3 rmind 0, 0, 12, 64
157 1.1 jonathan };
158 1.1 jonathan
159 1.18.4.2 rmind const struct auth_hash auth_hash_hmac_md5 = {
160 1.16 tls CRYPTO_MD5_HMAC, "HMAC-MD5",
161 1.18.4.3 rmind 16, 16, 16, 64
162 1.16 tls };
163 1.16 tls
164 1.18.4.2 rmind const struct auth_hash auth_hash_hmac_sha1 = {
165 1.16 tls CRYPTO_SHA1_HMAC, "HMAC-SHA1",
166 1.18.4.3 rmind 20, 20, 20, 64
167 1.16 tls };
168 1.16 tls
169 1.18.4.2 rmind const struct auth_hash auth_hash_hmac_ripemd_160 = {
170 1.16 tls CRYPTO_RIPEMD160_HMAC, "HMAC-RIPEMD-160",
171 1.18.4.3 rmind 20, 20, 20, 64
172 1.16 tls };
173 1.16 tls
174 1.18.4.2 rmind const struct auth_hash auth_hash_hmac_md5_96 = {
175 1.17 tls CRYPTO_MD5_HMAC_96, "HMAC-MD5-96",
176 1.18.4.3 rmind 16, 16, 12, 64
177 1.1 jonathan };
178 1.1 jonathan
179 1.18.4.2 rmind const struct auth_hash auth_hash_hmac_sha1_96 = {
180 1.17 tls CRYPTO_SHA1_HMAC_96, "HMAC-SHA1-96",
181 1.18.4.3 rmind 20, 20, 12, 64
182 1.1 jonathan };
183 1.1 jonathan
184 1.18.4.2 rmind const struct auth_hash auth_hash_hmac_ripemd_160_96 = {
185 1.17 tls CRYPTO_RIPEMD160_HMAC_96, "HMAC-RIPEMD-160",
186 1.18.4.3 rmind 20, 20, 12, 64
187 1.1 jonathan };
188 1.1 jonathan
189 1.18.4.2 rmind const struct auth_hash auth_hash_key_md5 = {
190 1.1 jonathan CRYPTO_MD5_KPDK, "Keyed MD5",
191 1.18.4.3 rmind 0, 16, 16, 0
192 1.1 jonathan };
193 1.1 jonathan
194 1.18.4.2 rmind const struct auth_hash auth_hash_key_sha1 = {
195 1.1 jonathan CRYPTO_SHA1_KPDK, "Keyed SHA1",
196 1.18.4.3 rmind 0, 20, 20, 0
197 1.1 jonathan };
198 1.1 jonathan
199 1.18.4.2 rmind const struct auth_hash auth_hash_md5 = {
200 1.1 jonathan CRYPTO_MD5, "MD5",
201 1.18.4.3 rmind 0, 16, 16, 0
202 1.1 jonathan };
203 1.1 jonathan
204 1.18.4.2 rmind const struct auth_hash auth_hash_sha1 = {
205 1.1 jonathan CRYPTO_SHA1, "SHA1",
206 1.18.4.3 rmind 0, 20, 20, 0
207 1.1 jonathan };
208 1.1 jonathan
209 1.18.4.2 rmind const struct auth_hash auth_hash_hmac_sha2_256 = {
210 1.18.4.1 rmind CRYPTO_SHA2_256_HMAC, "HMAC-SHA2",
211 1.18.4.3 rmind 32, 32, 16, 64
212 1.1 jonathan };
213 1.1 jonathan
214 1.18.4.2 rmind const struct auth_hash auth_hash_hmac_sha2_384 = {
215 1.18.4.1 rmind CRYPTO_SHA2_384_HMAC, "HMAC-SHA2-384",
216 1.18.4.3 rmind 48, 48, 24, 128
217 1.1 jonathan };
218 1.1 jonathan
219 1.18.4.2 rmind const struct auth_hash auth_hash_hmac_sha2_512 = {
220 1.18.4.1 rmind CRYPTO_SHA2_512_HMAC, "HMAC-SHA2-512",
221 1.18.4.3 rmind 64, 64, 32, 128
222 1.18.4.3 rmind };
223 1.18.4.3 rmind
224 1.18.4.3 rmind const struct auth_hash auth_hash_aes_xcbc_mac_96 = {
225 1.18.4.3 rmind CRYPTO_AES_XCBC_MAC_96, "AES-XCBC-MAC-96",
226 1.18.4.3 rmind 16, 16, 12, 0
227 1.18.4.3 rmind };
228 1.18.4.3 rmind
229 1.18.4.3 rmind const struct auth_hash auth_hash_gmac_aes_128 = {
230 1.18.4.3 rmind CRYPTO_AES_128_GMAC, "GMAC-AES-128",
231 1.18.4.3 rmind 16+4, 16, 16, 16 /* ??? */
232 1.18.4.3 rmind };
233 1.18.4.3 rmind
234 1.18.4.3 rmind const struct auth_hash auth_hash_gmac_aes_192 = {
235 1.18.4.3 rmind CRYPTO_AES_192_GMAC, "GMAC-AES-192",
236 1.18.4.3 rmind 24+4, 16, 16, 16 /* ??? */
237 1.18.4.3 rmind };
238 1.18.4.3 rmind
239 1.18.4.3 rmind const struct auth_hash auth_hash_gmac_aes_256 = {
240 1.18.4.3 rmind CRYPTO_AES_256_GMAC, "GMAC-AES-256",
241 1.18.4.3 rmind 32+4, 16, 16, 16 /* ??? */
242 1.1 jonathan };
243 1.1 jonathan
244 1.1 jonathan /* Compression instance */
245 1.18.4.2 rmind const struct comp_algo comp_algo_deflate = {
246 1.1 jonathan CRYPTO_DEFLATE_COMP, "Deflate",
247 1.15 thorpej 90
248 1.1 jonathan };
249 1.18 darran
250 1.18.4.2 rmind const struct comp_algo comp_algo_deflate_nogrow = {
251 1.18.4.1 rmind CRYPTO_DEFLATE_COMP_NOGROW, "Deflate",
252 1.18.4.1 rmind 90
253 1.18.4.1 rmind };
254 1.18.4.1 rmind
255 1.18.4.2 rmind const struct comp_algo comp_algo_gzip = {
256 1.18 darran CRYPTO_GZIP_COMP, "GZIP",
257 1.18 darran 90
258 1.18 darran };
259