b4ad84c044f52f01e6793162e8bc7b6235c94295
[openwrt.git] / target / linux / generic-2.6 / files / crypto / ocf / ocfnull / ocfnull.c
1 /*
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.
6 *
7 * Written by David McCullough <david_mccullough@securecomputing.com>
8 * Copyright (C) 2006-2007 David McCullough
9 *
10 * LICENSE TERMS
11 *
12 * The free distribution and use of this software in both source and binary
13 * form is allowed (with or without changes) provided that:
14 *
15 * 1. distributions of this source code include the above copyright
16 * notice, this list of conditions and the following disclaimer;
17 *
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;
21 *
22 * 3. the copyright holder's name is not used to endorse products
23 * built using this software without specific written permission.
24 *
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.
28 *
29 * DISCLAIMER
30 *
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.
34 */
35
36 #ifndef AUTOCONF_INCLUDED
37 #include <linux/config.h>
38 #endif
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>
47
48 #include <cryptodev.h>
49 #include <uio.h>
50
51 static int32_t null_id = -1;
52 static u_int32_t null_sesnum = 0;
53
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);
57
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");
62
63 /*
64 * dummy device structure
65 */
66
67 static struct {
68 softc_device_decl sc_dev;
69 } nulldev;
70
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),
76 };
77
78 /*
79 * Generate a new software session.
80 */
81 static int
82 null_newsession(device_t arg, u_int32_t *sid, struct cryptoini *cri)
83 {
84 dprintk("%s()\n", __FUNCTION__);
85 if (sid == NULL || cri == NULL) {
86 dprintk("%s,%d - EINVAL\n", __FILE__, __LINE__);
87 return EINVAL;
88 }
89
90 if (null_sesnum == 0)
91 null_sesnum++;
92 *sid = null_sesnum++;
93 return 0;
94 }
95
96
97 /*
98 * Free a session.
99 */
100 static int
101 null_freesession(device_t arg, u_int64_t tid)
102 {
103 u_int32_t sid = CRYPTO_SESID2LID(tid);
104
105 dprintk("%s()\n", __FUNCTION__);
106 if (sid > null_sesnum) {
107 dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
108 return EINVAL;
109 }
110
111 /* Silently accept and return */
112 if (sid == 0)
113 return 0;
114 return 0;
115 }
116
117
118 /*
119 * Process a request.
120 */
121 static int
122 null_process(device_t arg, struct cryptop *crp, int hint)
123 {
124 unsigned int lid;
125
126 dprintk("%s()\n", __FUNCTION__);
127
128 /* Sanity check */
129 if (crp == NULL) {
130 dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
131 return EINVAL;
132 }
133
134 crp->crp_etype = 0;
135
136 if (crp->crp_desc == NULL || crp->crp_buf == NULL) {
137 dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
138 crp->crp_etype = EINVAL;
139 goto done;
140 }
141
142 /*
143 * find the session we are using
144 */
145
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__);
150 goto done;
151 }
152
153 done:
154 crypto_done(crp);
155 return 0;
156 }
157
158
159 /*
160 * our driver startup and shutdown routines
161 */
162
163 static int
164 null_init(void)
165 {
166 dprintk("%s(%p)\n", __FUNCTION__, null_init);
167
168 memset(&nulldev, 0, sizeof(nulldev));
169 softc_device_init(&nulldev, "ocfnull", 0, null_methods);
170
171 null_id = crypto_get_driverid(softc_get_device(&nulldev),
172 CRYPTOCAP_F_HARDWARE);
173 if (null_id < 0)
174 panic("ocfnull: crypto device cannot initialize!");
175
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);
185 #undef REGISTER
186
187 return 0;
188 }
189
190 static void
191 null_exit(void)
192 {
193 dprintk("%s()\n", __FUNCTION__);
194 crypto_unregister_all(null_id);
195 null_id = -1;
196 }
197
198 module_init(null_init);
199 module_exit(null_exit);
200
201 MODULE_LICENSE("Dual BSD/GPL");
202 MODULE_AUTHOR("David McCullough <david_mccullough@securecomputing.com>");
203 MODULE_DESCRIPTION("ocfnull - claims a lot but does nothing");
This page took 0.048063 seconds and 3 git commands to generate.