ucc_geth: fix module removal
[linux-2.6/openmoko-kernel/knife-kernel.git] / crypto / crypto_null.c
blobff7b3de1bcfdb1bd81742367a5335a6717b0658e
1 /*
2 * Cryptographic API.
4 * Null algorithms, aka Much Ado About Nothing.
6 * These are needed for IPsec, and may be useful in general for
7 * testing & debugging.
8 *
9 * The null cipher is compliant with RFC2410.
11 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
20 #include <crypto/internal/skcipher.h>
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/mm.h>
24 #include <linux/string.h>
26 #define NULL_KEY_SIZE 0
27 #define NULL_BLOCK_SIZE 1
28 #define NULL_DIGEST_SIZE 0
29 #define NULL_IV_SIZE 0
31 static int null_compress(struct crypto_tfm *tfm, const u8 *src,
32 unsigned int slen, u8 *dst, unsigned int *dlen)
34 if (slen > *dlen)
35 return -EINVAL;
36 memcpy(dst, src, slen);
37 *dlen = slen;
38 return 0;
41 static void null_init(struct crypto_tfm *tfm)
42 { }
44 static void null_update(struct crypto_tfm *tfm, const u8 *data,
45 unsigned int len)
46 { }
48 static void null_final(struct crypto_tfm *tfm, u8 *out)
49 { }
51 static int null_setkey(struct crypto_tfm *tfm, const u8 *key,
52 unsigned int keylen)
53 { return 0; }
55 static void null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
57 memcpy(dst, src, NULL_BLOCK_SIZE);
60 static int skcipher_null_crypt(struct blkcipher_desc *desc,
61 struct scatterlist *dst,
62 struct scatterlist *src, unsigned int nbytes)
64 struct blkcipher_walk walk;
65 int err;
67 blkcipher_walk_init(&walk, dst, src, nbytes);
68 err = blkcipher_walk_virt(desc, &walk);
70 while (walk.nbytes) {
71 if (walk.src.virt.addr != walk.dst.virt.addr)
72 memcpy(walk.dst.virt.addr, walk.src.virt.addr,
73 walk.nbytes);
74 err = blkcipher_walk_done(desc, &walk, 0);
77 return err;
80 static struct crypto_alg compress_null = {
81 .cra_name = "compress_null",
82 .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
83 .cra_blocksize = NULL_BLOCK_SIZE,
84 .cra_ctxsize = 0,
85 .cra_module = THIS_MODULE,
86 .cra_list = LIST_HEAD_INIT(compress_null.cra_list),
87 .cra_u = { .compress = {
88 .coa_compress = null_compress,
89 .coa_decompress = null_compress } }
92 static struct crypto_alg digest_null = {
93 .cra_name = "digest_null",
94 .cra_flags = CRYPTO_ALG_TYPE_DIGEST,
95 .cra_blocksize = NULL_BLOCK_SIZE,
96 .cra_ctxsize = 0,
97 .cra_module = THIS_MODULE,
98 .cra_list = LIST_HEAD_INIT(digest_null.cra_list),
99 .cra_u = { .digest = {
100 .dia_digestsize = NULL_DIGEST_SIZE,
101 .dia_setkey = null_setkey,
102 .dia_init = null_init,
103 .dia_update = null_update,
104 .dia_final = null_final } }
107 static struct crypto_alg cipher_null = {
108 .cra_name = "cipher_null",
109 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
110 .cra_blocksize = NULL_BLOCK_SIZE,
111 .cra_ctxsize = 0,
112 .cra_module = THIS_MODULE,
113 .cra_list = LIST_HEAD_INIT(cipher_null.cra_list),
114 .cra_u = { .cipher = {
115 .cia_min_keysize = NULL_KEY_SIZE,
116 .cia_max_keysize = NULL_KEY_SIZE,
117 .cia_setkey = null_setkey,
118 .cia_encrypt = null_crypt,
119 .cia_decrypt = null_crypt } }
122 static struct crypto_alg skcipher_null = {
123 .cra_name = "ecb(cipher_null)",
124 .cra_driver_name = "ecb-cipher_null",
125 .cra_priority = 100,
126 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
127 .cra_blocksize = NULL_BLOCK_SIZE,
128 .cra_type = &crypto_blkcipher_type,
129 .cra_ctxsize = 0,
130 .cra_module = THIS_MODULE,
131 .cra_list = LIST_HEAD_INIT(skcipher_null.cra_list),
132 .cra_u = { .blkcipher = {
133 .min_keysize = NULL_KEY_SIZE,
134 .max_keysize = NULL_KEY_SIZE,
135 .ivsize = NULL_IV_SIZE,
136 .setkey = null_setkey,
137 .encrypt = skcipher_null_crypt,
138 .decrypt = skcipher_null_crypt } }
141 MODULE_ALIAS("compress_null");
142 MODULE_ALIAS("digest_null");
143 MODULE_ALIAS("cipher_null");
145 static int __init init(void)
147 int ret = 0;
149 ret = crypto_register_alg(&cipher_null);
150 if (ret < 0)
151 goto out;
153 ret = crypto_register_alg(&skcipher_null);
154 if (ret < 0)
155 goto out_unregister_cipher;
157 ret = crypto_register_alg(&digest_null);
158 if (ret < 0)
159 goto out_unregister_skcipher;
161 ret = crypto_register_alg(&compress_null);
162 if (ret < 0)
163 goto out_unregister_digest;
165 out:
166 return ret;
168 out_unregister_digest:
169 crypto_unregister_alg(&digest_null);
170 out_unregister_skcipher:
171 crypto_unregister_alg(&skcipher_null);
172 out_unregister_cipher:
173 crypto_unregister_alg(&cipher_null);
174 goto out;
177 static void __exit fini(void)
179 crypto_unregister_alg(&compress_null);
180 crypto_unregister_alg(&digest_null);
181 crypto_unregister_alg(&skcipher_null);
182 crypto_unregister_alg(&cipher_null);
185 module_init(init);
186 module_exit(fini);
188 MODULE_LICENSE("GPL");
189 MODULE_DESCRIPTION("Null Cryptographic Algorithms");