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 #ifndef AUTOCONF_INCLUDED
37 #include <linux/config.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/list.h>
42 #include <linux/slab.h>
43 #include <linux/sched.h>
44 #include <linux/wait.h>
45 #include <linux/crypto.h>
46 #include <linux/interrupt.h>
48 #include <cryptodev.h>
51 static int32_t null_id = -1;
52 static u_int32_t null_sesnum = 0;
54 static int null_process(device_t, struct cryptop *, int);
55 static int null_newsession(device_t, u_int32_t *, struct cryptoini *);
56 static int null_freesession(device_t, u_int64_t);
58 #define debug ocfnull_debug
59 int ocfnull_debug = 0;
60 module_param(ocfnull_debug, int, 0644);
61 MODULE_PARM_DESC(ocfnull_debug, "Enable debug");
64 * dummy device structure
68 softc_device_decl sc_dev;
71 static device_method_t null_methods = {
72 /* crypto device methods */
73 DEVMETHOD(cryptodev_newsession, null_newsession),
74 DEVMETHOD(cryptodev_freesession,null_freesession),
75 DEVMETHOD(cryptodev_process, null_process),
79 * Generate a new software session.
82 null_newsession(device_t arg, u_int32_t *sid, struct cryptoini *cri)
84 dprintk("%s()\n", __FUNCTION__);
85 if (sid == NULL || cri == NULL) {
86 dprintk("%s,%d - EINVAL\n", __FILE__, __LINE__);
101 null_freesession(device_t arg, u_int64_t tid)
103 u_int32_t sid = CRYPTO_SESID2LID(tid);
105 dprintk("%s()\n", __FUNCTION__);
106 if (sid > null_sesnum) {
107 dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
111 /* Silently accept and return */
122 null_process(device_t arg, struct cryptop *crp, int hint)
126 dprintk("%s()\n", __FUNCTION__);
130 dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
136 if (crp->crp_desc == NULL || crp->crp_buf == NULL) {
137 dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
138 crp->crp_etype = EINVAL;
143 * find the session we are using
146 lid = crp->crp_sid & 0xffffffff;
147 if (lid >= null_sesnum || lid == 0) {
148 crp->crp_etype = ENOENT;
149 dprintk("%s,%d: ENOENT\n", __FILE__, __LINE__);
160 * our driver startup and shutdown routines
166 dprintk("%s(%p)\n", __FUNCTION__, null_init);
168 memset(&nulldev, 0, sizeof(nulldev));
169 softc_device_init(&nulldev, "ocfnull", 0, null_methods);
171 null_id = crypto_get_driverid(softc_get_device(&nulldev),
172 CRYPTOCAP_F_HARDWARE);
174 panic("ocfnull: crypto device cannot initialize!");
176 #define REGISTER(alg) \
177 crypto_register(null_id,alg,0,0)
178 REGISTER(CRYPTO_DES_CBC);
179 REGISTER(CRYPTO_3DES_CBC);
180 REGISTER(CRYPTO_RIJNDAEL128_CBC);
181 REGISTER(CRYPTO_MD5);
182 REGISTER(CRYPTO_SHA1);
183 REGISTER(CRYPTO_MD5_HMAC);
184 REGISTER(CRYPTO_SHA1_HMAC);
193 dprintk("%s()\n", __FUNCTION__);
194 crypto_unregister_all(null_id);
198 module_init(null_init);
199 module_exit(null_exit);
201 MODULE_LICENSE("Dual BSD/GPL");
202 MODULE_AUTHOR("David McCullough <david_mccullough@mcafee.com>");
203 MODULE_DESCRIPTION("ocfnull - claims a lot but does nothing");