aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-12-13 09:28:59 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2008-01-10 16:16:53 -0500
commit3631c650c495d61b1dabf32eb26b46873636e918 (patch)
treeb46244dc1062fbede37bff4955e205ab7d5310c3 /crypto
parent93cc74e078eed8735585e5687903727bcfbcc8b4 (diff)
[CRYPTO] null: Add null blkcipher algorithm
This patch adds a null blkcipher algorithm called ecb(cipher_null) for backwards compatibility. Previously the null algorithm when used by IPsec copied the data byte by byte. This new algorithm optimises that to a straight memcpy which lets us better measure inherent overheads in our IPsec code. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/crypto_null.c69
1 files changed, 59 insertions, 10 deletions
diff --git a/crypto/crypto_null.c b/crypto/crypto_null.c
index 29f77477d701..fc2d2a4d7789 100644
--- a/crypto/crypto_null.c
+++ b/crypto/crypto_null.c
@@ -16,15 +16,17 @@
16 * (at your option) any later version. 16 * (at your option) any later version.
17 * 17 *
18 */ 18 */
19
20#include <crypto/internal/skcipher.h>
19#include <linux/init.h> 21#include <linux/init.h>
20#include <linux/module.h> 22#include <linux/module.h>
21#include <linux/mm.h> 23#include <linux/mm.h>
22#include <linux/crypto.h>
23#include <linux/string.h> 24#include <linux/string.h>
24 25
25#define NULL_KEY_SIZE 0 26#define NULL_KEY_SIZE 0
26#define NULL_BLOCK_SIZE 1 27#define NULL_BLOCK_SIZE 1
27#define NULL_DIGEST_SIZE 0 28#define NULL_DIGEST_SIZE 0
29#define NULL_IV_SIZE 0
28 30
29static int null_compress(struct crypto_tfm *tfm, const u8 *src, 31static int null_compress(struct crypto_tfm *tfm, const u8 *src,
30 unsigned int slen, u8 *dst, unsigned int *dlen) 32 unsigned int slen, u8 *dst, unsigned int *dlen)
@@ -55,6 +57,26 @@ static void null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
55 memcpy(dst, src, NULL_BLOCK_SIZE); 57 memcpy(dst, src, NULL_BLOCK_SIZE);
56} 58}
57 59
60static int skcipher_null_crypt(struct blkcipher_desc *desc,
61 struct scatterlist *dst,
62 struct scatterlist *src, unsigned int nbytes)
63{
64 struct blkcipher_walk walk;
65 int err;
66
67 blkcipher_walk_init(&walk, dst, src, nbytes);
68 err = blkcipher_walk_virt(desc, &walk);
69
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);
75 }
76
77 return err;
78}
79
58static struct crypto_alg compress_null = { 80static struct crypto_alg compress_null = {
59 .cra_name = "compress_null", 81 .cra_name = "compress_null",
60 .cra_flags = CRYPTO_ALG_TYPE_COMPRESS, 82 .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
@@ -96,6 +118,25 @@ static struct crypto_alg cipher_null = {
96 .cia_decrypt = null_crypt } } 118 .cia_decrypt = null_crypt } }
97}; 119};
98 120
121static struct crypto_alg skcipher_null = {
122 .cra_name = "ecb(cipher_null)",
123 .cra_driver_name = "ecb-cipher_null",
124 .cra_priority = 100,
125 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
126 .cra_blocksize = NULL_BLOCK_SIZE,
127 .cra_type = &crypto_blkcipher_type,
128 .cra_ctxsize = 0,
129 .cra_module = THIS_MODULE,
130 .cra_list = LIST_HEAD_INIT(skcipher_null.cra_list),
131 .cra_u = { .blkcipher = {
132 .min_keysize = NULL_KEY_SIZE,
133 .max_keysize = NULL_KEY_SIZE,
134 .ivsize = NULL_IV_SIZE,
135 .setkey = null_setkey,
136 .encrypt = skcipher_null_crypt,
137 .decrypt = skcipher_null_crypt } }
138};
139
99MODULE_ALIAS("compress_null"); 140MODULE_ALIAS("compress_null");
100MODULE_ALIAS("digest_null"); 141MODULE_ALIAS("digest_null");
101MODULE_ALIAS("cipher_null"); 142MODULE_ALIAS("cipher_null");
@@ -108,27 +149,35 @@ static int __init init(void)
108 if (ret < 0) 149 if (ret < 0)
109 goto out; 150 goto out;
110 151
152 ret = crypto_register_alg(&skcipher_null);
153 if (ret < 0)
154 goto out_unregister_cipher;
155
111 ret = crypto_register_alg(&digest_null); 156 ret = crypto_register_alg(&digest_null);
112 if (ret < 0) { 157 if (ret < 0)
113 crypto_unregister_alg(&cipher_null); 158 goto out_unregister_skcipher;
114 goto out;
115 }
116 159
117 ret = crypto_register_alg(&compress_null); 160 ret = crypto_register_alg(&compress_null);
118 if (ret < 0) { 161 if (ret < 0)
119 crypto_unregister_alg(&digest_null); 162 goto out_unregister_digest;
120 crypto_unregister_alg(&cipher_null);
121 goto out;
122 }
123 163
124out: 164out:
125 return ret; 165 return ret;
166
167out_unregister_digest:
168 crypto_unregister_alg(&digest_null);
169out_unregister_skcipher:
170 crypto_unregister_alg(&skcipher_null);
171out_unregister_cipher:
172 crypto_unregister_alg(&cipher_null);
173 goto out;
126} 174}
127 175
128static void __exit fini(void) 176static void __exit fini(void)
129{ 177{
130 crypto_unregister_alg(&compress_null); 178 crypto_unregister_alg(&compress_null);
131 crypto_unregister_alg(&digest_null); 179 crypto_unregister_alg(&digest_null);
180 crypto_unregister_alg(&skcipher_null);
132 crypto_unregister_alg(&cipher_null); 181 crypto_unregister_alg(&cipher_null);
133} 182}
134 183