2 * An OCF module for determining the cost of crypto versus the cost of
3 * IPSec processing outside of OCF. This modules gives us the effect of
4 * zero cost encryption, of course you will need to run it at both ends
5 * since it does no crypto at all.
7 * Written by David McCullough <david_mccullough@mcafee.com>
8 * Copyright (C) 2006-2010 David McCullough
12 * The free distribution and use of this software in both source and binary
13 * form is allowed (with or without changes) provided that:
15 * 1. distributions of this source code include the above copyright
16 * notice, this list of conditions and the following disclaimer;
18 * 2. distributions in binary form include the above copyright
19 * notice, this list of conditions and the following disclaimer
20 * in the documentation and/or other associated materials;
22 * 3. the copyright holder's name is not used to endorse products
23 * built using this software without specific written permission.
25 * ALTERNATIVELY, provided that this notice is retained in full, this product
26 * may be distributed under the terms of the GNU General Public License (GPL),
27 * in which case the provisions of the GPL apply INSTEAD OF those given above.
31 * This software is provided 'as is' with no explicit or implied warranties
32 * in respect of its properties, including, but not limited to, correctness
33 * and/or fitness for purpose.
36 #include <linux/version.h>
37 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33))
38 #include <generated/autoconf.h>
40 #include <linux/autoconf.h>
42 #include <linux/module.h>
43 #include <linux/init.h>
44 #include <linux/list.h>
45 #include <linux/slab.h>
46 #include <linux/sched.h>
47 #include <linux/wait.h>
48 #include <linux/crypto.h>
49 #include <linux/interrupt.h>
51 #include <cryptodev.h>
54 static int32_t null_id
= -1;
55 static u_int32_t null_sesnum
= 0;
57 static int null_process(device_t
, struct cryptop
*, int);
58 static int null_newsession(device_t
, u_int32_t
*, struct cryptoini
*);
59 static int null_freesession(device_t
, u_int64_t
);
61 #define debug ocfnull_debug
62 int ocfnull_debug
= 0;
63 module_param(ocfnull_debug
, int, 0644);
64 MODULE_PARM_DESC(ocfnull_debug
, "Enable debug");
67 * dummy device structure
71 softc_device_decl sc_dev
;
74 static device_method_t null_methods
= {
75 /* crypto device methods */
76 DEVMETHOD(cryptodev_newsession
, null_newsession
),
77 DEVMETHOD(cryptodev_freesession
,null_freesession
),
78 DEVMETHOD(cryptodev_process
, null_process
),
82 * Generate a new software session.
85 null_newsession(device_t arg
, u_int32_t
*sid
, struct cryptoini
*cri
)
87 dprintk("%s()\n", __FUNCTION__
);
88 if (sid
== NULL
|| cri
== NULL
) {
89 dprintk("%s,%d - EINVAL\n", __FILE__
, __LINE__
);
104 null_freesession(device_t arg
, u_int64_t tid
)
106 u_int32_t sid
= CRYPTO_SESID2LID(tid
);
108 dprintk("%s()\n", __FUNCTION__
);
109 if (sid
> null_sesnum
) {
110 dprintk("%s,%d: EINVAL\n", __FILE__
, __LINE__
);
114 /* Silently accept and return */
125 null_process(device_t arg
, struct cryptop
*crp
, int hint
)
129 dprintk("%s()\n", __FUNCTION__
);
133 dprintk("%s,%d: EINVAL\n", __FILE__
, __LINE__
);
139 if (crp
->crp_desc
== NULL
|| crp
->crp_buf
== NULL
) {
140 dprintk("%s,%d: EINVAL\n", __FILE__
, __LINE__
);
141 crp
->crp_etype
= EINVAL
;
146 * find the session we are using
149 lid
= crp
->crp_sid
& 0xffffffff;
150 if (lid
>= null_sesnum
|| lid
== 0) {
151 crp
->crp_etype
= ENOENT
;
152 dprintk("%s,%d: ENOENT\n", __FILE__
, __LINE__
);
163 * our driver startup and shutdown routines
169 dprintk("%s(%p)\n", __FUNCTION__
, null_init
);
171 memset(&nulldev
, 0, sizeof(nulldev
));
172 softc_device_init(&nulldev
, "ocfnull", 0, null_methods
);
174 null_id
= crypto_get_driverid(softc_get_device(&nulldev
),
175 CRYPTOCAP_F_HARDWARE
);
177 panic("ocfnull: crypto device cannot initialize!");
179 #define REGISTER(alg) \
180 crypto_register(null_id,alg,0,0)
181 REGISTER(CRYPTO_DES_CBC
);
182 REGISTER(CRYPTO_3DES_CBC
);
183 REGISTER(CRYPTO_RIJNDAEL128_CBC
);
184 REGISTER(CRYPTO_MD5
);
185 REGISTER(CRYPTO_SHA1
);
186 REGISTER(CRYPTO_MD5_HMAC
);
187 REGISTER(CRYPTO_SHA1_HMAC
);
196 dprintk("%s()\n", __FUNCTION__
);
197 crypto_unregister_all(null_id
);
201 module_init(null_init
);
202 module_exit(null_exit
);
204 MODULE_LICENSE("Dual BSD/GPL");
205 MODULE_AUTHOR("David McCullough <david_mccullough@mcafee.com>");
206 MODULE_DESCRIPTION("ocfnull - claims a lot but does nothing");