Commit d0856009 authored by Patrick McHardy's avatar Patrick McHardy Committed by Linus Torvalds

[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: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ba32311e
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <asm/scatterlist.h> #include <asm/scatterlist.h>
#include <linux/crypto.h> #include <linux/crypto.h>
#include <linux/string.h>
#define NULL_KEY_SIZE 0 #define NULL_KEY_SIZE 0
#define NULL_BLOCK_SIZE 1 #define NULL_BLOCK_SIZE 1
...@@ -28,11 +29,13 @@ ...@@ -28,11 +29,13 @@
static int null_compress(void *ctx, const u8 *src, unsigned int slen, static int null_compress(void *ctx, const u8 *src, unsigned int slen,
u8 *dst, unsigned int *dlen) u8 *dst, unsigned int *dlen)
{ return 0; } {
if (slen > *dlen)
static int null_decompress(void *ctx, const u8 *src, unsigned int slen, return -EINVAL;
u8 *dst, unsigned int *dlen) memcpy(dst, src, slen);
{ return 0; } *dlen = slen;
return 0;
}
static void null_init(void *ctx) static void null_init(void *ctx)
{ } { }
...@@ -47,11 +50,10 @@ static int null_setkey(void *ctx, const u8 *key, ...@@ -47,11 +50,10 @@ static int null_setkey(void *ctx, const u8 *key,
unsigned int keylen, u32 *flags) unsigned int keylen, u32 *flags)
{ return 0; } { return 0; }
static void null_encrypt(void *ctx, u8 *dst, const u8 *src) static void null_crypt(void *ctx, u8 *dst, const u8 *src)
{ } {
memcpy(dst, src, NULL_BLOCK_SIZE);
static void null_decrypt(void *ctx, u8 *dst, const u8 *src) }
{ }
static struct crypto_alg compress_null = { static struct crypto_alg compress_null = {
.cra_name = "compress_null", .cra_name = "compress_null",
...@@ -62,7 +64,7 @@ static struct crypto_alg compress_null = { ...@@ -62,7 +64,7 @@ static struct crypto_alg compress_null = {
.cra_list = LIST_HEAD_INIT(compress_null.cra_list), .cra_list = LIST_HEAD_INIT(compress_null.cra_list),
.cra_u = { .compress = { .cra_u = { .compress = {
.coa_compress = null_compress, .coa_compress = null_compress,
.coa_decompress = null_decompress } } .coa_decompress = null_compress } }
}; };
static struct crypto_alg digest_null = { static struct crypto_alg digest_null = {
...@@ -90,8 +92,8 @@ static struct crypto_alg cipher_null = { ...@@ -90,8 +92,8 @@ static struct crypto_alg cipher_null = {
.cia_min_keysize = NULL_KEY_SIZE, .cia_min_keysize = NULL_KEY_SIZE,
.cia_max_keysize = NULL_KEY_SIZE, .cia_max_keysize = NULL_KEY_SIZE,
.cia_setkey = null_setkey, .cia_setkey = null_setkey,
.cia_encrypt = null_encrypt, .cia_encrypt = null_crypt,
.cia_decrypt = null_decrypt } } .cia_decrypt = null_crypt } }
}; };
MODULE_ALIAS("compress_null"); MODULE_ALIAS("compress_null");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment