LZF Cryptoapi support.
Hi again.
Here's another resend, this time adding an lzf cryptoapi module.
LZF is a very fast compressor which typically achieves approximately 50% compression on a suspend image. The original author (Marc Alexander Lehmann) donated it to Suspend2. I have converted it to cryptoapi with a recent switch of Suspend2 to use cryptoapi.
Regards,
Nigel
Kconfig | 7 + Makefile | 1 lzf.c | 425 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 433 insertions(+)
crypto/Kconfig +7 -0
@@ -262,6 +262,13 @@ config CRYPTO_DEFLATE You will most probably want this if using IPSec. +config CRYPTO_LZF + tristate "LZF compression algorithm" + depends on CRYPTO + help + This is the LZF algorithm. It is especially useful for Suspend2, + because it achieves good compression quickly. + config CRYPTO_MICHAEL_MIC tristate "Michael MIC keyed digest algorithm" depends on CRYPTO
crypto/lzf.c +425 -0
425 lines not on this page · raw message
crypto/Makefile +1 -0
@@ -30,5 +30,6 @@ obj-$(CONFIG_CRYPTO_ANUBIS) += anubis.o obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o +obj-$(CONFIG_CRYPTO_LZF) += lzf.o obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o
Signature · 5 lines
Evolution. Enumerate the requirements. Consider the interdependencies. Calculate the probabilities. Be amazed that people believe it happened.
Hi!
Quoted 6 lines
Here's another resend, this time adding an lzf cryptoapi module.
LZF is a very fast compressor which typically achieves approximately 50% compression on a suspend image. The original author (Marc Alexander Lehmann) donated it to Suspend2. I have converted it to cryptoapi with a recent switch of Suspend2 to use cryptoapi.
And it is still that old, ugly code.
crypto/lzf.c line 91
Quoted 11 lines
crypto/lzf.c +11
-0+/* +* sacrifice some compression quality in favour of compression speed. +* (roughly 1-2% worse compression for large blocks and +* 9-10% for small, redundant, blocks and >>20% better speed in both cases) +* In short: enable this for binary data, disable this for text data. +*/ +#define ULTRA_FAST 1 + +#define STRICT_ALIGN 0 +#define USE_MEMCPY 1 +#define INIT_HTAB 0
We do not want these options. It also allows you to kill ifdefs down in the code.
Quoted 14 lines
crypto/lzf.c +14
-0+#define HSIZE (1 << (HLOG)) + +/* +* don't play with this unless you benchmark! +* decompression is not dependent on the hash function +* the hashing function might seem strange, just believe me +* it works ;) +*/ +#define FRST (p) (((p[0]) << 8) + p[1]) +#define NEXT (v,p) (((v) << 8) + p[2]) +#define IDX (h) ((((h ^ (h << 5)) >> (3*8 - HLOG)) + h*3) & (HSIZE - 1)) +/* +* IDX works because it is very similar to a multiplicative hash, e.g. +* (h * 57321 >> (3*8 - HLOG))
crypto/lzf.c line 116
Quoted 10 lines
crypto/lzf.c +10
-0+* the next one is also quite good, albeit slow ;) +* (int)(cos(h & 0xffffff) * 1e6) +*/ + +#if 0 +/* original lzv-like hash function */ +# define FRST (p) (p[0] << 5) ^ p[1] +# define NEXT (v,p) ((v) << 5) ^ p[2] +# define IDX (h) ((h) & (HSIZE - 1)) +#endif
And we do not want #if 0-ed code.
Pavel
Signature · 1 line
teflon -- maybe it is a trademark, but it should not be.
Howdy.
New revision. Anything left to fix up?
Regards,
Nigel
Kconfig | 7 + Makefile | 1 lzf.c | 377 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 385 insertions(+)
crypto/Kconfig +7 -0
@@ -282,6 +282,13 @@ config CRYPTO_DEFLATE You will most probably want this if using IPSec. +config CRYPTO_LZF + tristate "LZF compression algorithm" + depends on CRYPTO + help + This is the LZF algorithm. It is especially useful for Suspend2, + because it achieves good compression quickly. + config CRYPTO_MICHAEL_MIC tristate "Michael MIC keyed digest algorithm" depends on CRYPTO
crypto/lzf.c +377 -0
377 lines not on this page · raw message
crypto/Makefile +1 -0
@@ -30,5 +30,6 @@ obj-$(CONFIG_CRYPTO_ANUBIS) += anubis.o obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o +obj-$(CONFIG_CRYPTO_LZF) += lzf.o obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o
Signature · 4 lines
Evolution. Enumerate the requirements. Consider the interdependencies. Calculate the probabilities.
Hi!
Quoted 1 line
New revision. Anything left to fix up?
It certainly looks better now.
Quoted 13 lines
crypto/lzf.c +13
-0+static int lzf_compress_init (void *context) +{ +struct lzf_ctx *ctx = (struct lzf_ctx *)context; + +/* Get LZF ready to go */ + ctx->hbuf =vmalloc_32 ((1 << hlog) *sizeof (char *)); +if (!ctx->hbuf) { +printk (KERN_WARNING +"Failed to allocate %d bytes for lzf workspace\n" , + (1 << hlog) *sizeof (char *)); +return -ENOMEM ; + } +
crypto/lzf.c line 166
Quoted 10 lines
crypto/lzf.c +10
-0+/* Allocate local buffer */ + ctx->local_buffer = (char *)get_zeroed_page (GFP_ATOMIC ); + +if (!ctx->local_buffer) { +lzf_compress_exit (ctx); +return -ENOMEM ; + } + +/* Allocate page buffer */ + ctx->page_buffer = (char *)get_zeroed_page (GFP_ATOMIC );
Why GFP_ATOMIC in last two?
crypto/lzf.c line 179
Quoted 12 lines
crypto/lzf.c +12
-0+if (!ctx->page_buffer) { +free_page ((unsigned long )ctx->local_buffer); +lzf_compress_exit (ctx); +return -ENOMEM ; + } + + ctx->first_call =1 ; + +return 0 ; +} + +static int lzf_compress(void *context, const u8 * in_data, unsigned int in_len,
~ extra space; it
is inconsistent all over the file.
Pavel
Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.
Herbert Xu
maintainercrypto/lzf.c line 149
Quoted 7 lines · Nigel Cunningham
crypto/lzf.c +6
-0+static int lzf_compress_init (void *context) +{ +struct lzf_ctx *ctx = (struct lzf_ctx *)context; + +/* Get LZF ready to go */ + ctx->hbuf =vmalloc_32 ((1 << hlog) *sizeof (char *));
Any reason why vmalloc can't be used?
crypto/lzf.c line 166
Quoted 5 lines
crypto/lzf.c +4
-0+/* Allocate local buffer */ + ctx->local_buffer = (char *)get_zeroed_page (GFP_ATOMIC ); +/* Allocate page buffer */ + ctx->page_buffer = (char *)get_zeroed_page (GFP_ATOMIC );
Where are these two buffers used anyway?
crypto/lzf.c line 170
Quoted 3 lines
crypto/lzf.c +3
-0+if (!ctx->page_buffer) { +free_page ((unsigned long )ctx->local_buffer); +lzf_compress_exit (ctx);
This is a double-free of local_buffer.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt