1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
/* $NetBSD: xform.c,v 1.31 2020/06/30 04:14:56 riastradh Exp $ */
/* $FreeBSD: src/sys/opencrypto/xform.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $ */
/* $OpenBSD: xform.c,v 1.19 2002/08/16 22:47:25 dhartmei Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr) and
* Niels Provos (provos@physnet.uni-hamburg.de).
*
* This code was written by John Ioannidis for BSD/OS in Athens, Greece,
* in November 1995.
*
* Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
* by Angelos D. Keromytis.
*
* Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
* and Niels Provos.
*
* Additional features in 1999 by Angelos D. Keromytis.
*
* Copyright (C) 1995, 1996, 1997, 1998, 1999 by John Ioannidis,
* Angelos D. Keromytis and Niels Provos.
*
* Copyright (C) 2001, Angelos D. Keromytis.
*
* Permission to use, copy, and modify this software with or without fee
* is hereby granted, provided that this entire notice is included in
* all copies of any software which is or includes a copy or
* modification of this software.
* You may use this code under the GNU public license if you so wish. Please
* contribute changes back to the authors under this freer than GPL license
* so that we may further the use of strong encryption without limitations to
* all.
*
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
* MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
* PURPOSE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: xform.c,v 1.31 2020/06/30 04:14:56 riastradh Exp $");
#include <sys/param.h>
#include <sys/malloc.h>
#include <opencrypto/cryptodev.h>
#include <opencrypto/xform.h>
MALLOC_DEFINE(M_XDATA, "xform", "xform data buffers");
const u_int8_t hmac_ipad_buffer[128] = {
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36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C, 0x5C,
0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C
};
/* Encryption instances */
const struct enc_xform enc_xform_null = {
.type = CRYPTO_NULL_CBC,
.name = "NULL",
/* NB: blocksize of 4 is to generate a properly aligned ESP header */
.blocksize = 4,
.ivsize = 0,
.minkey = 0,
.maxkey = 256, /* 2048 bits, max key */
};
const struct enc_xform enc_xform_des = {
.type = CRYPTO_DES_CBC,
.name = "DES",
.blocksize = 8,
.ivsize = 8,
.minkey = 8,
.maxkey = 8,
};
const struct enc_xform enc_xform_3des = {
.type = CRYPTO_3DES_CBC,
.name = "3DES",
.blocksize = 8,
.ivsize = 8,
.minkey = 24,
.maxkey = 24,
};
const struct enc_xform enc_xform_blf = {
.type = CRYPTO_BLF_CBC,
.name = "Blowfish",
.blocksize = 8,
.ivsize = 8,
.minkey = 5,
.maxkey = 56, /* 448 bits, max key */
};
const struct enc_xform enc_xform_cast5 = {
.type = CRYPTO_CAST_CBC,
.name = "CAST-128",
.blocksize = 8,
.ivsize = 8,
.minkey = 5,
.maxkey = 16,
};
const struct enc_xform enc_xform_skipjack = {
.type = CRYPTO_SKIPJACK_CBC,
.name = "Skipjack",
.blocksize = 8,
.ivsize = 8,
.minkey = 10,
.maxkey = 10,
};
const struct enc_xform enc_xform_aes = {
.type = CRYPTO_AES_CBC,
.name = "AES",
.blocksize = 16,
.ivsize = 16,
.minkey = 16,
.maxkey = 32,
};
const struct enc_xform enc_xform_arc4 = {
.type = CRYPTO_ARC4,
.name = "ARC4",
.blocksize = 1,
.ivsize = 0,
.minkey = 1,
.maxkey = 32,
};
const struct enc_xform enc_xform_camellia = {
.type = CRYPTO_CAMELLIA_CBC,
.name = "Camellia",
.blocksize = 16,
.ivsize = 16,
.minkey = 8,
.maxkey = 32,
};
const struct enc_xform enc_xform_aes_ctr = {
.type = CRYPTO_AES_CTR,
.name = "AES-CTR",
.blocksize = 16,
.ivsize = 8,
.minkey = 16 + 4,
.maxkey = 32 + 4,
};
const struct enc_xform enc_xform_aes_gcm = {
.type = CRYPTO_AES_GCM_16,
.name = "AES-GCM",
.blocksize = 4, /* ??? */
.ivsize = 8,
.minkey = 16 + 4,
.maxkey = 32 + 4,
};
const struct enc_xform enc_xform_aes_gmac = {
.type = CRYPTO_AES_GMAC,
.name = "AES-GMAC",
.blocksize = 4, /* ??? */
.ivsize = 8,
.minkey = 16 + 4,
.maxkey = 32 + 4,
};
/* Authentication instances */
const struct auth_hash auth_hash_null = {
.type = CRYPTO_NULL_HMAC,
.name = "NULL-HMAC",
.keysize = 0,
.hashsize = 0,
.authsize = 12,
.blocksize = 64,
};
const struct auth_hash auth_hash_hmac_md5 = {
.type = CRYPTO_MD5_HMAC,
.name = "HMAC-MD5",
.keysize = 16,
.hashsize = 16,
.authsize = 16,
.blocksize = 64,
};
const struct auth_hash auth_hash_hmac_sha1 = {
.type = CRYPTO_SHA1_HMAC,
.name = "HMAC-SHA1",
.keysize = 20,
.hashsize = 20,
.authsize = 20,
.blocksize = 64,
};
const struct auth_hash auth_hash_hmac_ripemd_160 = {
.type = CRYPTO_RIPEMD160_HMAC,
.name = "HMAC-RIPEMD-160",
.keysize = 20,
.hashsize = 20,
.authsize = 20,
.blocksize = 64,
};
const struct auth_hash auth_hash_hmac_md5_96 = {
.type = CRYPTO_MD5_HMAC_96,
.name = "HMAC-MD5-96",
.keysize = 16,
.hashsize = 16,
.authsize = 12,
.blocksize = 64,
};
const struct auth_hash auth_hash_hmac_sha1_96 = {
.type = CRYPTO_SHA1_HMAC_96,
.name = "HMAC-SHA1-96",
.keysize = 20,
.hashsize = 20,
.authsize = 12,
.blocksize = 64,
};
const struct auth_hash auth_hash_hmac_ripemd_160_96 = {
.type = CRYPTO_RIPEMD160_HMAC_96,
.name = "HMAC-RIPEMD-160",
.keysize = 20,
.hashsize = 20,
.authsize = 12,
.blocksize = 64,
};
const struct auth_hash auth_hash_key_md5 = {
.type = CRYPTO_MD5_KPDK,
.name = "Keyed MD5",
.keysize = 0,
.hashsize = 16,
.authsize = 16,
.blocksize = 0,
};
const struct auth_hash auth_hash_key_sha1 = {
.type = CRYPTO_SHA1_KPDK,
.name = "Keyed SHA1",
.keysize = 0,
.hashsize = 20,
.authsize = 20,
.blocksize = 0,
};
const struct auth_hash auth_hash_md5 = {
.type = CRYPTO_MD5,
.name = "MD5",
.keysize = 0,
.hashsize = 16,
.authsize = 16,
.blocksize = 0,
};
const struct auth_hash auth_hash_sha1 = {
.type = CRYPTO_SHA1,
.name = "SHA1",
.keysize = 0,
.hashsize = 20,
.authsize = 20,
.blocksize = 0,
};
const struct auth_hash auth_hash_hmac_sha2_256 = {
.type = CRYPTO_SHA2_256_HMAC,
.name = "HMAC-SHA2",
.keysize = 32,
.hashsize = 32,
.authsize = 16,
.blocksize = 64,
};
const struct auth_hash auth_hash_hmac_sha2_384 = {
.type = CRYPTO_SHA2_384_HMAC,
.name = "HMAC-SHA2-384",
.keysize = 48,
.hashsize = 48,
.authsize = 24,
.blocksize = 128,
};
const struct auth_hash auth_hash_hmac_sha2_512 = {
.type = CRYPTO_SHA2_512_HMAC,
.name = "HMAC-SHA2-512",
.keysize = 64,
.hashsize = 64,
.authsize = 32,
.blocksize = 128,
};
const struct auth_hash auth_hash_aes_xcbc_mac_96 = {
.type = CRYPTO_AES_XCBC_MAC_96,
.name = "AES-XCBC-MAC-96",
.keysize = 16,
.hashsize = 16,
.authsize = 12,
.blocksize = 0,
};
const struct auth_hash auth_hash_gmac_aes_128 = {
.type = CRYPTO_AES_128_GMAC,
.name = "GMAC-AES-128",
.keysize = 16 + 4,
.hashsize = 16,
.authsize = 16,
.blocksize = 16, /* ??? */
};
const struct auth_hash auth_hash_gmac_aes_192 = {
.type = CRYPTO_AES_192_GMAC,
.name = "GMAC-AES-192",
.keysize = 24 + 4,
.hashsize = 16,
.authsize = 16,
.blocksize = 16, /* ??? */
};
const struct auth_hash auth_hash_gmac_aes_256 = {
.type = CRYPTO_AES_256_GMAC,
.name = "GMAC-AES-256",
.keysize = 32 + 4,
.hashsize = 16,
.authsize = 16,
.blocksize = 16, /* ??? */
};
/* Compression instance */
const struct comp_algo comp_algo_deflate = {
.type = CRYPTO_DEFLATE_COMP,
.name = "Deflate",
.minlen = 90,
};
const struct comp_algo comp_algo_deflate_nogrow = {
.type = CRYPTO_DEFLATE_COMP_NOGROW,
.name = "Deflate",
.minlen = 90,
};
const struct comp_algo comp_algo_gzip = {
.type = CRYPTO_GZIP_COMP,
.name = "GZIP",
.minlen = 90,
};
|