aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/crypto_null.c
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2005-05-17 00:53:41 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-17 10:59:18 -0400
commitd0856009dbaf8eca2269d4129bb83940c0d95054 (patch)
treee6c10d133f04ece55250f2fd84fc2b376624b8cd /crypto/crypto_null.c
parentba32311eb73f624a85a5fc2e043cda8e076f86ef (diff)
[PATCH] crypto: fix null encryption/compression
null_encrypt() needs to copy the data in case src and dst are disjunct, null_compress() needs to copy the data in any case as far as I can tell. I joined compress/decompress and encrypt/decrypt to avoid duplicating code. Without this patch ESP null_enc packets look like this: IP (tos 0x0, ttl 64, id 23130, offset 0, flags [DF], length: 128) 10.0.0.1 > 10.0.0.2: ESP(spi=0x0f9ca149,seq=0x4) 0x0000: 4500 0080 5a5a 4000 4032 cbef 0a00 0001 E...ZZ@.@2...... 0x0010: 0a00 0002 0f9c a149 0000 0004 0000 0000 .......I........ 0x0020: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0030: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0040: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0050: 0000 .. IP (tos 0x0, ttl 64, id 256, offset 0, flags [DF], length: 128) 10.0.0.2 > 10.0.0.1: ESP(spi=0x0e4f7b51,seq=0x2) 0x0000: 4500 0080 0100 4000 4032 254a 0a00 0002 E.....@.@2%J.... 0x0010: 0a00 0001 0e4f 7b51 0000 0002 a8a8 a8a8 .....O{Q........ 0x0020: a8a8 a8a8 a8a8 a8a8 a8a8 a8a8 a8a8 a8a8 ................ 0x0030: a8a8 a8a8 a8a8 a8a8 a8a8 a8a8 a8a8 a8a8 ................ 0x0040: a8a8 a8a8 a8a8 a8a8 a8a8 a8a8 a8a8 a8a8 ................ 0x0050: a8a8 .. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'crypto/crypto_null.c')
-rw-r--r--crypto/crypto_null.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/crypto/crypto_null.c b/crypto/crypto_null.c
index f691d31fa9ee..3fcf6e887e87 100644
--- a/crypto/crypto_null.c
+++ b/crypto/crypto_null.c
@@ -21,6 +21,7 @@
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <asm/scatterlist.h> 22#include <asm/scatterlist.h>
23#include <linux/crypto.h> 23#include <linux/crypto.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
@@ -28,11 +29,13 @@
28 29
29static int null_compress(void *ctx, const u8 *src, unsigned int slen, 30static int null_compress(void *ctx, const u8 *src, unsigned int slen,
30 u8 *dst, unsigned int *dlen) 31 u8 *dst, unsigned int *dlen)
31{ return 0; } 32{
32 33 if (slen > *dlen)
33static int null_decompress(void *ctx, const u8 *src, unsigned int slen, 34 return -EINVAL;
34 u8 *dst, unsigned int *dlen) 35 memcpy(dst, src, slen);
35{ return 0; } 36 *dlen = slen;
37 return 0;
38}
36 39
37static void null_init(void *ctx) 40static void null_init(void *ctx)
38{ } 41{ }
@@ -47,11 +50,10 @@ static int null_setkey(void *ctx, const u8 *key,
47 unsigned int keylen, u32 *flags) 50 unsigned int keylen, u32 *flags)
48{ return 0; } 51{ return 0; }
49 52
50static void null_encrypt(void *ctx, u8 *dst, const u8 *src) 53static void null_crypt(void *ctx, u8 *dst, const u8 *src)
51{ } 54{
52 55 memcpy(dst, src, NULL_BLOCK_SIZE);
53static void null_decrypt(void *ctx, u8 *dst, const u8 *src) 56}
54{ }
55 57
56static struct crypto_alg compress_null = { 58static struct crypto_alg compress_null = {
57 .cra_name = "compress_null", 59 .cra_name = "compress_null",
@@ -62,7 +64,7 @@ static struct crypto_alg compress_null = {
62 .cra_list = LIST_HEAD_INIT(compress_null.cra_list), 64 .cra_list = LIST_HEAD_INIT(compress_null.cra_list),
63 .cra_u = { .compress = { 65 .cra_u = { .compress = {
64 .coa_compress = null_compress, 66 .coa_compress = null_compress,
65 .coa_decompress = null_decompress } } 67 .coa_decompress = null_compress } }
66}; 68};
67 69
68static struct crypto_alg digest_null = { 70static struct crypto_alg digest_null = {
@@ -90,8 +92,8 @@ static struct crypto_alg cipher_null = {
90 .cia_min_keysize = NULL_KEY_SIZE, 92 .cia_min_keysize = NULL_KEY_SIZE,
91 .cia_max_keysize = NULL_KEY_SIZE, 93 .cia_max_keysize = NULL_KEY_SIZE,
92 .cia_setkey = null_setkey, 94 .cia_setkey = null_setkey,
93 .cia_encrypt = null_encrypt, 95 .cia_encrypt = null_crypt,
94 .cia_decrypt = null_decrypt } } 96 .cia_decrypt = null_crypt } }
95}; 97};
96 98
97MODULE_ALIAS("compress_null"); 99MODULE_ALIAS("compress_null");