4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <linux/init.h>
20 #include <linux/module.h>
21 #include <linux/crypto.h>
22 #include <linux/vmalloc.h>
23 #include <linux/lzo.h>
24 #include <linux/lz4k.h>
26 #define malloc(a) kmalloc(a, GFP_KERNEL)
27 #define free(a) kfree(a)
31 extern int lz4k_compress_ubifs(const unsigned char *in
, size_t in_len
, unsigned char *out
,
32 size_t *out_len
, void *wrkmem
);
34 extern int lz4k_decompress_ubifs(const unsigned char *in
, size_t in_len
,
35 unsigned char *out
, size_t *out_len
);
37 extern int lz4k_compress(const unsigned char *in
, size_t in_len
, unsigned char *out
,
38 size_t *out_len
, void *wrkmem
);
44 static int lz4kc_init(struct crypto_tfm
*tfm
)
46 struct lz4k_ctx
*ctx
= crypto_tfm_ctx(tfm
);
48 ctx
->lz4k_comp_mem
= vmalloc(LZO1X_MEM_COMPRESS
);
49 if (!ctx
->lz4k_comp_mem
)
55 static void lz4kc_exit(struct crypto_tfm
*tfm
)
57 struct lz4k_ctx
*ctx
= crypto_tfm_ctx(tfm
);
59 vfree(ctx
->lz4k_comp_mem
);
62 static int lz4kc_compress(struct crypto_tfm
*tfm
, const u8
*src
,
63 unsigned int slen
, u8
*dst
, unsigned int *dlen
)
66 struct lz4k_ctx
*ctx
= crypto_tfm_ctx(tfm
);
67 //static size_t in_size = 0, out_size = 0;
68 size_t tmp_len
= *dlen
; /* size_t(ulong) <-> uint on 64 bit */
73 //printk("lz4k_compress 2 count = %d\r\n", count);
78 err
= lz4k_compress(src
, slen
, dst
, &tmp_len
, ctx
->lz4k_comp_mem
);
79 //err = lzo1x_1_compress(src, slen, dst, &tmp_len, ctx->lz4k_comp_mem);
89 printk("lz4k_compress_ubifs result in_size = %d, out_size = %d \n", in_size
,out_size
);
92 //printk("lz4k_compress result in_size = %d, out_size = %d \n", in_size,out_size);
93 //printk("lz4k_compress result slen = %d, tmp_len = %d \n", slen,tmp_len);
100 static int lz4kc_decompress(struct crypto_tfm
*tfm
, const u8
*src
,
101 unsigned int slen
, u8
*dst
, unsigned int *dlen
)
103 static int count
= 0;
105 size_t tmp_len
= *dlen
; /* size_t(ulong) <-> uint on 64 bit */
108 //printk("lz4k_decompress 2count = %d, *dlen = %d", count,*dlen);
110 err
= lz4k_decompress_ubifs(src
, slen
, dst
, &tmp_len
);
111 //err = lzo1x_decompress_safe(src, slen, dst, &tmp_len);
124 static struct crypto_alg alg
= {
126 .cra_flags
= CRYPTO_ALG_TYPE_COMPRESS
,
127 .cra_ctxsize
= sizeof(struct lz4k_ctx
),
128 .cra_module
= THIS_MODULE
,
129 .cra_list
= LIST_HEAD_INIT(alg
.cra_list
),
130 .cra_init
= lz4kc_init
,
131 .cra_exit
= lz4kc_exit
,
132 .cra_u
= { .compress
= {
133 .coa_compress
= lz4kc_compress
,
134 .coa_decompress
= lz4kc_decompress
} }
137 static int __init
lz4k_mod_init(void)
139 return crypto_register_alg(&alg
);
142 static void __exit
lz4k_mod_fini(void)
144 crypto_unregister_alg(&alg
);
147 module_init(lz4k_mod_init
);
148 module_exit(lz4k_mod_fini
);
150 MODULE_LICENSE("GPL");
151 MODULE_DESCRIPTION("LZ77 with 4K Compression Algorithm");