kernel: the cryptosoft module of ocf needs cryptoapi manager support (for blkcipher...
[openwrt.git] / target / linux / generic / 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@mcafee.com>
8 * Copyright (C) 2006-2010 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 #include <linux/version.h>
37 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33))
38 #include <generated/autoconf.h>
39 #else
40 #include <linux/autoconf.h>
41 #endif
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>
50
51 #include <cryptodev.h>
52 #include <uio.h>
53
54 static int32_t null_id = -1;
55 static u_int32_t null_sesnum = 0;
56
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);
60
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");
65
66 /*
67 * dummy device structure
68 */
69
70 static struct {
71 softc_device_decl sc_dev;
72 } nulldev;
73
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),
79 };
80
81 /*
82 * Generate a new software session.
83 */
84 static int
85 null_newsession(device_t arg, u_int32_t *sid, struct cryptoini *cri)
86 {
87 dprintk("%s()\n", __FUNCTION__);
88 if (sid == NULL || cri == NULL) {
89 dprintk("%s,%d - EINVAL\n", __FILE__, __LINE__);
90 return EINVAL;
91 }
92
93 if (null_sesnum == 0)
94 null_sesnum++;
95 *sid = null_sesnum++;
96 return 0;
97 }
98
99
100 /*
101 * Free a session.
102 */
103 static int
104 null_freesession(device_t arg, u_int64_t tid)
105 {
106 u_int32_t sid = CRYPTO_SESID2LID(tid);
107
108 dprintk("%s()\n", __FUNCTION__);
109 if (sid > null_sesnum) {
110 dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
111 return EINVAL;
112 }
113
114 /* Silently accept and return */
115 if (sid == 0)
116 return 0;
117 return 0;
118 }
119
120
121 /*
122 * Process a request.
123 */
124 static int
125 null_process(device_t arg, struct cryptop *crp, int hint)
126 {
127 unsigned int lid;
128
129 dprintk("%s()\n", __FUNCTION__);
130
131 /* Sanity check */
132 if (crp == NULL) {
133 dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
134 return EINVAL;
135 }
136
137 crp->crp_etype = 0;
138
139 if (crp->crp_desc == NULL || crp->crp_buf == NULL) {
140 dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
141 crp->crp_etype = EINVAL;
142 goto done;
143 }
144
145 /*
146 * find the session we are using
147 */
148
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__);
153 goto done;
154 }
155
156 done:
157 crypto_done(crp);
158 return 0;
159 }
160
161
162 /*
163 * our driver startup and shutdown routines
164 */
165
166 static int
167 null_init(void)
168 {
169 dprintk("%s(%p)\n", __FUNCTION__, null_init);
170
171 memset(&nulldev, 0, sizeof(nulldev));
172 softc_device_init(&nulldev, "ocfnull", 0, null_methods);
173
174 null_id = crypto_get_driverid(softc_get_device(&nulldev),
175 CRYPTOCAP_F_HARDWARE);
176 if (null_id < 0)
177 panic("ocfnull: crypto device cannot initialize!");
178
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);
188 #undef REGISTER
189
190 return 0;
191 }
192
193 static void
194 null_exit(void)
195 {
196 dprintk("%s()\n", __FUNCTION__);
197 crypto_unregister_all(null_id);
198 null_id = -1;
199 }
200
201 module_init(null_init);
202 module_exit(null_exit);
203
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");
This page took 0.065292 seconds and 5 git commands to generate.