aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-08-21 07:08:13 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2006-09-20 21:16:30 -0400
commitcce9e06d100df19a327b19f23adad76e7bf63edd (patch)
treece10f50679db9ed8db92912c104eef1f05efc3c5 /crypto
parent9409f38a0c8773c04bff8dda8c552d7ea013d956 (diff)
[CRYPTO] api: Split out low-level API
The crypto API is made up of the part facing users such as IPsec and the low-level part which is used by cryptographic entities such as algorithms. This patch splits out the latter so that the two APIs are more clearly delineated. As a bonus the low-level API can now be modularised if all algorithms are built as modules. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/Kconfig84
-rw-r--r--crypto/Makefile7
-rw-r--r--crypto/algapi.c118
-rw-r--r--crypto/api.c97
-rw-r--r--crypto/internal.h6
-rw-r--r--crypto/proc.c5
6 files changed, 184 insertions, 133 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig
index fa927a287a1d..aabc63195222 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -9,47 +9,54 @@ config CRYPTO
9 help 9 help
10 This option provides the core Cryptographic API. 10 This option provides the core Cryptographic API.
11 11
12if CRYPTO
13
14config CRYPTO_ALGAPI
15 tristate
16 help
17 This option provides the API for cryptographic algorithms.
18
12config CRYPTO_HMAC 19config CRYPTO_HMAC
13 bool "HMAC support" 20 bool "HMAC support"
14 depends on CRYPTO
15 help 21 help
16 HMAC: Keyed-Hashing for Message Authentication (RFC2104). 22 HMAC: Keyed-Hashing for Message Authentication (RFC2104).
17 This is required for IPSec. 23 This is required for IPSec.
18 24
19config CRYPTO_NULL 25config CRYPTO_NULL
20 tristate "Null algorithms" 26 tristate "Null algorithms"
21 depends on CRYPTO 27 select CRYPTO_ALGAPI
22 help 28 help
23 These are 'Null' algorithms, used by IPsec, which do nothing. 29 These are 'Null' algorithms, used by IPsec, which do nothing.
24 30
25config CRYPTO_MD4 31config CRYPTO_MD4
26 tristate "MD4 digest algorithm" 32 tristate "MD4 digest algorithm"
27 depends on CRYPTO 33 select CRYPTO_ALGAPI
28 help 34 help
29 MD4 message digest algorithm (RFC1320). 35 MD4 message digest algorithm (RFC1320).
30 36
31config CRYPTO_MD5 37config CRYPTO_MD5
32 tristate "MD5 digest algorithm" 38 tristate "MD5 digest algorithm"
33 depends on CRYPTO 39 select CRYPTO_ALGAPI
34 help 40 help
35 MD5 message digest algorithm (RFC1321). 41 MD5 message digest algorithm (RFC1321).
36 42
37config CRYPTO_SHA1 43config CRYPTO_SHA1
38 tristate "SHA1 digest algorithm" 44 tristate "SHA1 digest algorithm"
39 depends on CRYPTO 45 select CRYPTO_ALGAPI
40 help 46 help
41 SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2). 47 SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2).
42 48
43config CRYPTO_SHA1_S390 49config CRYPTO_SHA1_S390
44 tristate "SHA1 digest algorithm (s390)" 50 tristate "SHA1 digest algorithm (s390)"
45 depends on CRYPTO && S390 51 depends on S390
52 select CRYPTO_ALGAPI
46 help 53 help
47 This is the s390 hardware accelerated implementation of the 54 This is the s390 hardware accelerated implementation of the
48 SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2). 55 SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2).
49 56
50config CRYPTO_SHA256 57config CRYPTO_SHA256
51 tristate "SHA256 digest algorithm" 58 tristate "SHA256 digest algorithm"
52 depends on CRYPTO 59 select CRYPTO_ALGAPI
53 help 60 help
54 SHA256 secure hash standard (DFIPS 180-2). 61 SHA256 secure hash standard (DFIPS 180-2).
55 62
@@ -58,7 +65,8 @@ config CRYPTO_SHA256
58 65
59config CRYPTO_SHA256_S390 66config CRYPTO_SHA256_S390
60 tristate "SHA256 digest algorithm (s390)" 67 tristate "SHA256 digest algorithm (s390)"
61 depends on CRYPTO && S390 68 depends on S390
69 select CRYPTO_ALGAPI
62 help 70 help
63 This is the s390 hardware accelerated implementation of the 71 This is the s390 hardware accelerated implementation of the
64 SHA256 secure hash standard (DFIPS 180-2). 72 SHA256 secure hash standard (DFIPS 180-2).
@@ -68,7 +76,7 @@ config CRYPTO_SHA256_S390
68 76
69config CRYPTO_SHA512 77config CRYPTO_SHA512
70 tristate "SHA384 and SHA512 digest algorithms" 78 tristate "SHA384 and SHA512 digest algorithms"
71 depends on CRYPTO 79 select CRYPTO_ALGAPI
72 help 80 help
73 SHA512 secure hash standard (DFIPS 180-2). 81 SHA512 secure hash standard (DFIPS 180-2).
74 82
@@ -80,7 +88,7 @@ config CRYPTO_SHA512
80 88
81config CRYPTO_WP512 89config CRYPTO_WP512
82 tristate "Whirlpool digest algorithms" 90 tristate "Whirlpool digest algorithms"
83 depends on CRYPTO 91 select CRYPTO_ALGAPI
84 help 92 help
85 Whirlpool hash algorithm 512, 384 and 256-bit hashes 93 Whirlpool hash algorithm 512, 384 and 256-bit hashes
86 94
@@ -92,7 +100,7 @@ config CRYPTO_WP512
92 100
93config CRYPTO_TGR192 101config CRYPTO_TGR192
94 tristate "Tiger digest algorithms" 102 tristate "Tiger digest algorithms"
95 depends on CRYPTO 103 select CRYPTO_ALGAPI
96 help 104 help
97 Tiger hash algorithm 192, 160 and 128-bit hashes 105 Tiger hash algorithm 192, 160 and 128-bit hashes
98 106
@@ -105,19 +113,20 @@ config CRYPTO_TGR192
105 113
106config CRYPTO_DES 114config CRYPTO_DES
107 tristate "DES and Triple DES EDE cipher algorithms" 115 tristate "DES and Triple DES EDE cipher algorithms"
108 depends on CRYPTO 116 select CRYPTO_ALGAPI
109 help 117 help
110 DES cipher algorithm (FIPS 46-2), and Triple DES EDE (FIPS 46-3). 118 DES cipher algorithm (FIPS 46-2), and Triple DES EDE (FIPS 46-3).
111 119
112config CRYPTO_DES_S390 120config CRYPTO_DES_S390
113 tristate "DES and Triple DES cipher algorithms (s390)" 121 tristate "DES and Triple DES cipher algorithms (s390)"
114 depends on CRYPTO && S390 122 depends on S390
123 select CRYPTO_ALGAPI
115 help 124 help
116 DES cipher algorithm (FIPS 46-2), and Triple DES EDE (FIPS 46-3). 125 DES cipher algorithm (FIPS 46-2), and Triple DES EDE (FIPS 46-3).
117 126
118config CRYPTO_BLOWFISH 127config CRYPTO_BLOWFISH
119 tristate "Blowfish cipher algorithm" 128 tristate "Blowfish cipher algorithm"
120 depends on CRYPTO 129 select CRYPTO_ALGAPI
121 help 130 help
122 Blowfish cipher algorithm, by Bruce Schneier. 131 Blowfish cipher algorithm, by Bruce Schneier.
123 132
@@ -130,7 +139,7 @@ config CRYPTO_BLOWFISH
130 139
131config CRYPTO_TWOFISH 140config CRYPTO_TWOFISH
132 tristate "Twofish cipher algorithm" 141 tristate "Twofish cipher algorithm"
133 depends on CRYPTO 142 select CRYPTO_ALGAPI
134 select CRYPTO_TWOFISH_COMMON 143 select CRYPTO_TWOFISH_COMMON
135 help 144 help
136 Twofish cipher algorithm. 145 Twofish cipher algorithm.
@@ -145,14 +154,14 @@ config CRYPTO_TWOFISH
145 154
146config CRYPTO_TWOFISH_COMMON 155config CRYPTO_TWOFISH_COMMON
147 tristate 156 tristate
148 depends on CRYPTO
149 help 157 help
150 Common parts of the Twofish cipher algorithm shared by the 158 Common parts of the Twofish cipher algorithm shared by the
151 generic c and the assembler implementations. 159 generic c and the assembler implementations.
152 160
153config CRYPTO_TWOFISH_586 161config CRYPTO_TWOFISH_586
154 tristate "Twofish cipher algorithms (i586)" 162 tristate "Twofish cipher algorithms (i586)"
155 depends on CRYPTO && ((X86 || UML_X86) && !64BIT) 163 depends on (X86 || UML_X86) && !64BIT
164 select CRYPTO_ALGAPI
156 select CRYPTO_TWOFISH_COMMON 165 select CRYPTO_TWOFISH_COMMON
157 help 166 help
158 Twofish cipher algorithm. 167 Twofish cipher algorithm.
@@ -167,7 +176,8 @@ config CRYPTO_TWOFISH_586
167 176
168config CRYPTO_TWOFISH_X86_64 177config CRYPTO_TWOFISH_X86_64
169 tristate "Twofish cipher algorithm (x86_64)" 178 tristate "Twofish cipher algorithm (x86_64)"
170 depends on CRYPTO && ((X86 || UML_X86) && 64BIT) 179 depends on (X86 || UML_X86) && 64BIT
180 select CRYPTO_ALGAPI
171 select CRYPTO_TWOFISH_COMMON 181 select CRYPTO_TWOFISH_COMMON
172 help 182 help
173 Twofish cipher algorithm (x86_64). 183 Twofish cipher algorithm (x86_64).
@@ -182,7 +192,7 @@ config CRYPTO_TWOFISH_X86_64
182 192
183config CRYPTO_SERPENT 193config CRYPTO_SERPENT
184 tristate "Serpent cipher algorithm" 194 tristate "Serpent cipher algorithm"
185 depends on CRYPTO 195 select CRYPTO_ALGAPI
186 help 196 help
187 Serpent cipher algorithm, by Anderson, Biham & Knudsen. 197 Serpent cipher algorithm, by Anderson, Biham & Knudsen.
188 198
@@ -195,7 +205,7 @@ config CRYPTO_SERPENT
195 205
196config CRYPTO_AES 206config CRYPTO_AES
197 tristate "AES cipher algorithms" 207 tristate "AES cipher algorithms"
198 depends on CRYPTO 208 select CRYPTO_ALGAPI
199 help 209 help
200 AES cipher algorithms (FIPS-197). AES uses the Rijndael 210 AES cipher algorithms (FIPS-197). AES uses the Rijndael
201 algorithm. 211 algorithm.
@@ -215,7 +225,8 @@ config CRYPTO_AES
215 225
216config CRYPTO_AES_586 226config CRYPTO_AES_586
217 tristate "AES cipher algorithms (i586)" 227 tristate "AES cipher algorithms (i586)"
218 depends on CRYPTO && ((X86 || UML_X86) && !64BIT) 228 depends on (X86 || UML_X86) && !64BIT
229 select CRYPTO_ALGAPI
219 help 230 help
220 AES cipher algorithms (FIPS-197). AES uses the Rijndael 231 AES cipher algorithms (FIPS-197). AES uses the Rijndael
221 algorithm. 232 algorithm.
@@ -235,7 +246,8 @@ config CRYPTO_AES_586
235 246
236config CRYPTO_AES_X86_64 247config CRYPTO_AES_X86_64
237 tristate "AES cipher algorithms (x86_64)" 248 tristate "AES cipher algorithms (x86_64)"
238 depends on CRYPTO && ((X86 || UML_X86) && 64BIT) 249 depends on (X86 || UML_X86) && 64BIT
250 select CRYPTO_ALGAPI
239 help 251 help
240 AES cipher algorithms (FIPS-197). AES uses the Rijndael 252 AES cipher algorithms (FIPS-197). AES uses the Rijndael
241 algorithm. 253 algorithm.
@@ -255,7 +267,8 @@ config CRYPTO_AES_X86_64
255 267
256config CRYPTO_AES_S390 268config CRYPTO_AES_S390
257 tristate "AES cipher algorithms (s390)" 269 tristate "AES cipher algorithms (s390)"
258 depends on CRYPTO && S390 270 depends on S390
271 select CRYPTO_ALGAPI
259 help 272 help
260 This is the s390 hardware accelerated implementation of the 273 This is the s390 hardware accelerated implementation of the
261 AES cipher algorithms (FIPS-197). AES uses the Rijndael 274 AES cipher algorithms (FIPS-197). AES uses the Rijndael
@@ -275,21 +288,21 @@ config CRYPTO_AES_S390
275 288
276config CRYPTO_CAST5 289config CRYPTO_CAST5
277 tristate "CAST5 (CAST-128) cipher algorithm" 290 tristate "CAST5 (CAST-128) cipher algorithm"
278 depends on CRYPTO 291 select CRYPTO_ALGAPI
279 help 292 help
280 The CAST5 encryption algorithm (synonymous with CAST-128) is 293 The CAST5 encryption algorithm (synonymous with CAST-128) is
281 described in RFC2144. 294 described in RFC2144.
282 295
283config CRYPTO_CAST6 296config CRYPTO_CAST6
284 tristate "CAST6 (CAST-256) cipher algorithm" 297 tristate "CAST6 (CAST-256) cipher algorithm"
285 depends on CRYPTO 298 select CRYPTO_ALGAPI
286 help 299 help
287 The CAST6 encryption algorithm (synonymous with CAST-256) is 300 The CAST6 encryption algorithm (synonymous with CAST-256) is
288 described in RFC2612. 301 described in RFC2612.
289 302
290config CRYPTO_TEA 303config CRYPTO_TEA
291 tristate "TEA, XTEA and XETA cipher algorithms" 304 tristate "TEA, XTEA and XETA cipher algorithms"
292 depends on CRYPTO 305 select CRYPTO_ALGAPI
293 help 306 help
294 TEA cipher algorithm. 307 TEA cipher algorithm.
295 308
@@ -306,7 +319,7 @@ config CRYPTO_TEA
306 319
307config CRYPTO_ARC4 320config CRYPTO_ARC4
308 tristate "ARC4 cipher algorithm" 321 tristate "ARC4 cipher algorithm"
309 depends on CRYPTO 322 select CRYPTO_ALGAPI
310 help 323 help
311 ARC4 cipher algorithm. 324 ARC4 cipher algorithm.
312 325
@@ -317,7 +330,7 @@ config CRYPTO_ARC4
317 330
318config CRYPTO_KHAZAD 331config CRYPTO_KHAZAD
319 tristate "Khazad cipher algorithm" 332 tristate "Khazad cipher algorithm"
320 depends on CRYPTO 333 select CRYPTO_ALGAPI
321 help 334 help
322 Khazad cipher algorithm. 335 Khazad cipher algorithm.
323 336
@@ -330,7 +343,7 @@ config CRYPTO_KHAZAD
330 343
331config CRYPTO_ANUBIS 344config CRYPTO_ANUBIS
332 tristate "Anubis cipher algorithm" 345 tristate "Anubis cipher algorithm"
333 depends on CRYPTO 346 select CRYPTO_ALGAPI
334 help 347 help
335 Anubis cipher algorithm. 348 Anubis cipher algorithm.
336 349
@@ -345,7 +358,7 @@ config CRYPTO_ANUBIS
345 358
346config CRYPTO_DEFLATE 359config CRYPTO_DEFLATE
347 tristate "Deflate compression algorithm" 360 tristate "Deflate compression algorithm"
348 depends on CRYPTO 361 select CRYPTO_ALGAPI
349 select ZLIB_INFLATE 362 select ZLIB_INFLATE
350 select ZLIB_DEFLATE 363 select ZLIB_DEFLATE
351 help 364 help
@@ -356,7 +369,7 @@ config CRYPTO_DEFLATE
356 369
357config CRYPTO_MICHAEL_MIC 370config CRYPTO_MICHAEL_MIC
358 tristate "Michael MIC keyed digest algorithm" 371 tristate "Michael MIC keyed digest algorithm"
359 depends on CRYPTO 372 select CRYPTO_ALGAPI
360 help 373 help
361 Michael MIC is used for message integrity protection in TKIP 374 Michael MIC is used for message integrity protection in TKIP
362 (IEEE 802.11i). This algorithm is required for TKIP, but it 375 (IEEE 802.11i). This algorithm is required for TKIP, but it
@@ -365,7 +378,7 @@ config CRYPTO_MICHAEL_MIC
365 378
366config CRYPTO_CRC32C 379config CRYPTO_CRC32C
367 tristate "CRC32c CRC algorithm" 380 tristate "CRC32c CRC algorithm"
368 depends on CRYPTO 381 select CRYPTO_ALGAPI
369 select LIBCRC32C 382 select LIBCRC32C
370 help 383 help
371 Castagnoli, et al Cyclic Redundancy-Check Algorithm. Used 384 Castagnoli, et al Cyclic Redundancy-Check Algorithm. Used
@@ -375,10 +388,13 @@ config CRYPTO_CRC32C
375 388
376config CRYPTO_TEST 389config CRYPTO_TEST
377 tristate "Testing module" 390 tristate "Testing module"
378 depends on CRYPTO && m 391 depends on m
392 select CRYPTO_ALGAPI
379 help 393 help
380 Quick & dirty crypto test module. 394 Quick & dirty crypto test module.
381 395
382source "drivers/crypto/Kconfig" 396source "drivers/crypto/Kconfig"
383endmenu
384 397
398endif # if CRYPTO
399
400endmenu
diff --git a/crypto/Makefile b/crypto/Makefile
index fe934f1001c6..6d51f80753a1 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -2,10 +2,11 @@
2# Cryptographic API 2# Cryptographic API
3# 3#
4 4
5proc-crypto-$(CONFIG_PROC_FS) = proc.o 5obj-$(CONFIG_CRYPTO) += api.o scatterwalk.o cipher.o digest.o compress.o
6 6
7obj-$(CONFIG_CRYPTO) += api.o scatterwalk.o cipher.o digest.o compress.o \ 7crypto_algapi-$(CONFIG_PROC_FS) += proc.o
8 $(proc-crypto-y) 8crypto_algapi-objs := algapi.o $(crypto_algapi-y)
9obj-$(CONFIG_CRYPTO_ALGAPI) += crypto_algapi.o
9 10
10obj-$(CONFIG_CRYPTO_HMAC) += hmac.o 11obj-$(CONFIG_CRYPTO_HMAC) += hmac.o
11obj-$(CONFIG_CRYPTO_NULL) += crypto_null.o 12obj-$(CONFIG_CRYPTO_NULL) += crypto_null.o
diff --git a/crypto/algapi.c b/crypto/algapi.c
new file mode 100644
index 000000000000..a65c6ccfbe17
--- /dev/null
+++ b/crypto/algapi.c
@@ -0,0 +1,118 @@
1/*
2 * Cryptographic API for algorithms (i.e., low-level API).
3 *
4 * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#include <linux/errno.h>
14#include <linux/init.h>
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/string.h>
18
19#include "internal.h"
20
21static inline int crypto_set_driver_name(struct crypto_alg *alg)
22{
23 static const char suffix[] = "-generic";
24 char *driver_name = alg->cra_driver_name;
25 int len;
26
27 if (*driver_name)
28 return 0;
29
30 len = strlcpy(driver_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
31 if (len + sizeof(suffix) > CRYPTO_MAX_ALG_NAME)
32 return -ENAMETOOLONG;
33
34 memcpy(driver_name + len, suffix, sizeof(suffix));
35 return 0;
36}
37
38int crypto_register_alg(struct crypto_alg *alg)
39{
40 int ret;
41 struct crypto_alg *q;
42
43 if (alg->cra_alignmask & (alg->cra_alignmask + 1))
44 return -EINVAL;
45
46 if (alg->cra_alignmask & alg->cra_blocksize)
47 return -EINVAL;
48
49 if (alg->cra_blocksize > PAGE_SIZE / 8)
50 return -EINVAL;
51
52 if (alg->cra_priority < 0)
53 return -EINVAL;
54
55 ret = crypto_set_driver_name(alg);
56 if (unlikely(ret))
57 return ret;
58
59 down_write(&crypto_alg_sem);
60
61 list_for_each_entry(q, &crypto_alg_list, cra_list) {
62 if (q == alg) {
63 ret = -EEXIST;
64 goto out;
65 }
66 }
67
68 list_add(&alg->cra_list, &crypto_alg_list);
69 atomic_set(&alg->cra_refcnt, 1);
70out:
71 up_write(&crypto_alg_sem);
72 return ret;
73}
74EXPORT_SYMBOL_GPL(crypto_register_alg);
75
76int crypto_unregister_alg(struct crypto_alg *alg)
77{
78 int ret = -ENOENT;
79 struct crypto_alg *q;
80
81 down_write(&crypto_alg_sem);
82 list_for_each_entry(q, &crypto_alg_list, cra_list) {
83 if (alg == q) {
84 list_del(&alg->cra_list);
85 ret = 0;
86 goto out;
87 }
88 }
89out:
90 up_write(&crypto_alg_sem);
91
92 if (ret)
93 return ret;
94
95 BUG_ON(atomic_read(&alg->cra_refcnt) != 1);
96 if (alg->cra_destroy)
97 alg->cra_destroy(alg);
98
99 return 0;
100}
101EXPORT_SYMBOL_GPL(crypto_unregister_alg);
102
103static int __init crypto_algapi_init(void)
104{
105 crypto_init_proc();
106 return 0;
107}
108
109static void __exit crypto_algapi_exit(void)
110{
111 crypto_exit_proc();
112}
113
114module_init(crypto_algapi_init);
115module_exit(crypto_algapi_exit);
116
117MODULE_LICENSE("GPL");
118MODULE_DESCRIPTION("Cryptographic algorithms API");
diff --git a/crypto/api.c b/crypto/api.c
index 5994a58ef954..c922090b4842 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -15,19 +15,17 @@
15 * 15 *
16 */ 16 */
17 17
18#include <linux/compiler.h>
19#include <linux/init.h>
20#include <linux/crypto.h>
21#include <linux/errno.h> 18#include <linux/errno.h>
22#include <linux/kernel.h> 19#include <linux/kernel.h>
23#include <linux/kmod.h> 20#include <linux/kmod.h>
24#include <linux/rwsem.h>
25#include <linux/slab.h> 21#include <linux/slab.h>
26#include <linux/string.h> 22#include <linux/string.h>
27#include "internal.h" 23#include "internal.h"
28 24
29LIST_HEAD(crypto_alg_list); 25LIST_HEAD(crypto_alg_list);
26EXPORT_SYMBOL_GPL(crypto_alg_list);
30DECLARE_RWSEM(crypto_alg_sem); 27DECLARE_RWSEM(crypto_alg_sem);
28EXPORT_SYMBOL_GPL(crypto_alg_sem);
31 29
32static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg) 30static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)
33{ 31{
@@ -239,86 +237,6 @@ void crypto_free_tfm(struct crypto_tfm *tfm)
239 kfree(tfm); 237 kfree(tfm);
240} 238}
241 239
242static inline int crypto_set_driver_name(struct crypto_alg *alg)
243{
244 static const char suffix[] = "-generic";
245 char *driver_name = alg->cra_driver_name;
246 int len;
247
248 if (*driver_name)
249 return 0;
250
251 len = strlcpy(driver_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
252 if (len + sizeof(suffix) > CRYPTO_MAX_ALG_NAME)
253 return -ENAMETOOLONG;
254
255 memcpy(driver_name + len, suffix, sizeof(suffix));
256 return 0;
257}
258
259int crypto_register_alg(struct crypto_alg *alg)
260{
261 int ret;
262 struct crypto_alg *q;
263
264 if (alg->cra_alignmask & (alg->cra_alignmask + 1))
265 return -EINVAL;
266
267 if (alg->cra_alignmask & alg->cra_blocksize)
268 return -EINVAL;
269
270 if (alg->cra_blocksize > PAGE_SIZE / 8)
271 return -EINVAL;
272
273 if (alg->cra_priority < 0)
274 return -EINVAL;
275
276 ret = crypto_set_driver_name(alg);
277 if (unlikely(ret))
278 return ret;
279
280 down_write(&crypto_alg_sem);
281
282 list_for_each_entry(q, &crypto_alg_list, cra_list) {
283 if (q == alg) {
284 ret = -EEXIST;
285 goto out;
286 }
287 }
288
289 list_add(&alg->cra_list, &crypto_alg_list);
290 atomic_set(&alg->cra_refcnt, 1);
291out:
292 up_write(&crypto_alg_sem);
293 return ret;
294}
295
296int crypto_unregister_alg(struct crypto_alg *alg)
297{
298 int ret = -ENOENT;
299 struct crypto_alg *q;
300
301 down_write(&crypto_alg_sem);
302 list_for_each_entry(q, &crypto_alg_list, cra_list) {
303 if (alg == q) {
304 list_del(&alg->cra_list);
305 ret = 0;
306 goto out;
307 }
308 }
309out:
310 up_write(&crypto_alg_sem);
311
312 if (ret)
313 return ret;
314
315 BUG_ON(atomic_read(&alg->cra_refcnt) != 1);
316 if (alg->cra_destroy)
317 alg->cra_destroy(alg);
318
319 return 0;
320}
321
322int crypto_alg_available(const char *name, u32 flags) 240int crypto_alg_available(const char *name, u32 flags)
323{ 241{
324 int ret = 0; 242 int ret = 0;
@@ -332,17 +250,6 @@ int crypto_alg_available(const char *name, u32 flags)
332 return ret; 250 return ret;
333} 251}
334 252
335static int __init init_crypto(void)
336{
337 printk(KERN_INFO "Initializing Cryptographic API\n");
338 crypto_init_proc();
339 return 0;
340}
341
342__initcall(init_crypto);
343
344EXPORT_SYMBOL_GPL(crypto_register_alg);
345EXPORT_SYMBOL_GPL(crypto_unregister_alg);
346EXPORT_SYMBOL_GPL(crypto_alloc_tfm); 253EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
347EXPORT_SYMBOL_GPL(crypto_free_tfm); 254EXPORT_SYMBOL_GPL(crypto_free_tfm);
348EXPORT_SYMBOL_GPL(crypto_alg_available); 255EXPORT_SYMBOL_GPL(crypto_alg_available);
diff --git a/crypto/internal.h b/crypto/internal.h
index 959e602909a6..26f47d331551 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -12,7 +12,8 @@
12 */ 12 */
13#ifndef _CRYPTO_INTERNAL_H 13#ifndef _CRYPTO_INTERNAL_H
14#define _CRYPTO_INTERNAL_H 14#define _CRYPTO_INTERNAL_H
15#include <linux/crypto.h> 15
16#include <crypto/algapi.h>
16#include <linux/mm.h> 17#include <linux/mm.h>
17#include <linux/highmem.h> 18#include <linux/highmem.h>
18#include <linux/interrupt.h> 19#include <linux/interrupt.h>
@@ -64,9 +65,12 @@ static inline void crypto_free_hmac_block(struct crypto_tfm *tfm)
64 65
65#ifdef CONFIG_PROC_FS 66#ifdef CONFIG_PROC_FS
66void __init crypto_init_proc(void); 67void __init crypto_init_proc(void);
68void __exit crypto_exit_proc(void);
67#else 69#else
68static inline void crypto_init_proc(void) 70static inline void crypto_init_proc(void)
69{ } 71{ }
72static inline void crypto_exit_proc(void)
73{ }
70#endif 74#endif
71 75
72static inline unsigned int crypto_digest_ctxsize(struct crypto_alg *alg, 76static inline unsigned int crypto_digest_ctxsize(struct crypto_alg *alg,
diff --git a/crypto/proc.c b/crypto/proc.c
index 8543b7a157d6..9e573b17e887 100644
--- a/crypto/proc.c
+++ b/crypto/proc.c
@@ -113,3 +113,8 @@ void __init crypto_init_proc(void)
113 if (proc) 113 if (proc)
114 proc->proc_fops = &proc_crypto_ops; 114 proc->proc_fops = &proc_crypto_ops;
115} 115}
116
117void __exit crypto_exit_proc(void)
118{
119 remove_proc_entry("crypto", NULL);
120}