diff options
-rw-r--r-- | crypto/Kconfig | 16 | ||||
-rw-r--r-- | crypto/Makefile | 2 | ||||
-rw-r--r-- | crypto/lz4.c | 106 | ||||
-rw-r--r-- | crypto/lz4hc.c | 106 |
4 files changed, 230 insertions, 0 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig index 904ffe838567..69ce573f1224 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
@@ -1336,6 +1336,22 @@ config CRYPTO_842 | |||
1336 | help | 1336 | help |
1337 | This is the 842 algorithm. | 1337 | This is the 842 algorithm. |
1338 | 1338 | ||
1339 | config CRYPTO_LZ4 | ||
1340 | tristate "LZ4 compression algorithm" | ||
1341 | select CRYPTO_ALGAPI | ||
1342 | select LZ4_COMPRESS | ||
1343 | select LZ4_DECOMPRESS | ||
1344 | help | ||
1345 | This is the LZ4 algorithm. | ||
1346 | |||
1347 | config CRYPTO_LZ4HC | ||
1348 | tristate "LZ4HC compression algorithm" | ||
1349 | select CRYPTO_ALGAPI | ||
1350 | select LZ4HC_COMPRESS | ||
1351 | select LZ4_DECOMPRESS | ||
1352 | help | ||
1353 | This is the LZ4 high compression mode algorithm. | ||
1354 | |||
1339 | comment "Random Number Generation" | 1355 | comment "Random Number Generation" |
1340 | 1356 | ||
1341 | config CRYPTO_ANSI_CPRNG | 1357 | config CRYPTO_ANSI_CPRNG |
diff --git a/crypto/Makefile b/crypto/Makefile index 62af87df8729..2d5ed08a239f 100644 --- a/crypto/Makefile +++ b/crypto/Makefile | |||
@@ -86,6 +86,8 @@ obj-$(CONFIG_CRYPTO_CRC32) += crc32.o | |||
86 | obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif.o | 86 | obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif.o |
87 | obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o | 87 | obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o |
88 | obj-$(CONFIG_CRYPTO_LZO) += lzo.o | 88 | obj-$(CONFIG_CRYPTO_LZO) += lzo.o |
89 | obj-$(CONFIG_CRYPTO_LZ4) += lz4.o | ||
90 | obj-$(CONFIG_CRYPTO_LZ4HC) += lz4hc.o | ||
89 | obj-$(CONFIG_CRYPTO_842) += 842.o | 91 | obj-$(CONFIG_CRYPTO_842) += 842.o |
90 | obj-$(CONFIG_CRYPTO_RNG2) += rng.o | 92 | obj-$(CONFIG_CRYPTO_RNG2) += rng.o |
91 | obj-$(CONFIG_CRYPTO_RNG2) += krng.o | 93 | obj-$(CONFIG_CRYPTO_RNG2) += krng.o |
diff --git a/crypto/lz4.c b/crypto/lz4.c new file mode 100644 index 000000000000..4586dd15b0d8 --- /dev/null +++ b/crypto/lz4.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /* | ||
2 | * Cryptographic API. | ||
3 | * | ||
4 | * Copyright (c) 2013 Chanho Min <chanho.min@lge.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License version 2 as published by | ||
8 | * the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License along with | ||
16 | * this program; if not, write to the Free Software Foundation, Inc., 51 | ||
17 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include <linux/init.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/crypto.h> | ||
24 | #include <linux/vmalloc.h> | ||
25 | #include <linux/lz4.h> | ||
26 | |||
27 | struct lz4_ctx { | ||
28 | void *lz4_comp_mem; | ||
29 | }; | ||
30 | |||
31 | static int lz4_init(struct crypto_tfm *tfm) | ||
32 | { | ||
33 | struct lz4_ctx *ctx = crypto_tfm_ctx(tfm); | ||
34 | |||
35 | ctx->lz4_comp_mem = vmalloc(LZ4_MEM_COMPRESS); | ||
36 | if (!ctx->lz4_comp_mem) | ||
37 | return -ENOMEM; | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | static void lz4_exit(struct crypto_tfm *tfm) | ||
43 | { | ||
44 | struct lz4_ctx *ctx = crypto_tfm_ctx(tfm); | ||
45 | vfree(ctx->lz4_comp_mem); | ||
46 | } | ||
47 | |||
48 | static int lz4_compress_crypto(struct crypto_tfm *tfm, const u8 *src, | ||
49 | unsigned int slen, u8 *dst, unsigned int *dlen) | ||
50 | { | ||
51 | struct lz4_ctx *ctx = crypto_tfm_ctx(tfm); | ||
52 | size_t tmp_len = *dlen; | ||
53 | int err; | ||
54 | |||
55 | err = lz4_compress(src, slen, dst, &tmp_len, ctx->lz4_comp_mem); | ||
56 | |||
57 | if (err < 0) | ||
58 | return -EINVAL; | ||
59 | |||
60 | *dlen = tmp_len; | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | static int lz4_decompress_crypto(struct crypto_tfm *tfm, const u8 *src, | ||
65 | unsigned int slen, u8 *dst, unsigned int *dlen) | ||
66 | { | ||
67 | int err; | ||
68 | size_t tmp_len = *dlen; | ||
69 | size_t __slen = slen; | ||
70 | |||
71 | err = lz4_decompress(src, &__slen, dst, tmp_len); | ||
72 | if (err < 0) | ||
73 | return -EINVAL; | ||
74 | |||
75 | *dlen = tmp_len; | ||
76 | return err; | ||
77 | } | ||
78 | |||
79 | static struct crypto_alg alg_lz4 = { | ||
80 | .cra_name = "lz4", | ||
81 | .cra_flags = CRYPTO_ALG_TYPE_COMPRESS, | ||
82 | .cra_ctxsize = sizeof(struct lz4_ctx), | ||
83 | .cra_module = THIS_MODULE, | ||
84 | .cra_list = LIST_HEAD_INIT(alg_lz4.cra_list), | ||
85 | .cra_init = lz4_init, | ||
86 | .cra_exit = lz4_exit, | ||
87 | .cra_u = { .compress = { | ||
88 | .coa_compress = lz4_compress_crypto, | ||
89 | .coa_decompress = lz4_decompress_crypto } } | ||
90 | }; | ||
91 | |||
92 | static int __init lz4_mod_init(void) | ||
93 | { | ||
94 | return crypto_register_alg(&alg_lz4); | ||
95 | } | ||
96 | |||
97 | static void __exit lz4_mod_fini(void) | ||
98 | { | ||
99 | crypto_unregister_alg(&alg_lz4); | ||
100 | } | ||
101 | |||
102 | module_init(lz4_mod_init); | ||
103 | module_exit(lz4_mod_fini); | ||
104 | |||
105 | MODULE_LICENSE("GPL"); | ||
106 | MODULE_DESCRIPTION("LZ4 Compression Algorithm"); | ||
diff --git a/crypto/lz4hc.c b/crypto/lz4hc.c new file mode 100644 index 000000000000..151ba31d34e3 --- /dev/null +++ b/crypto/lz4hc.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /* | ||
2 | * Cryptographic API. | ||
3 | * | ||
4 | * Copyright (c) 2013 Chanho Min <chanho.min@lge.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License version 2 as published by | ||
8 | * the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License along with | ||
16 | * this program; if not, write to the Free Software Foundation, Inc., 51 | ||
17 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | * | ||
19 | */ | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/crypto.h> | ||
23 | #include <linux/vmalloc.h> | ||
24 | #include <linux/lz4.h> | ||
25 | |||
26 | struct lz4hc_ctx { | ||
27 | void *lz4hc_comp_mem; | ||
28 | }; | ||
29 | |||
30 | static int lz4hc_init(struct crypto_tfm *tfm) | ||
31 | { | ||
32 | struct lz4hc_ctx *ctx = crypto_tfm_ctx(tfm); | ||
33 | |||
34 | ctx->lz4hc_comp_mem = vmalloc(LZ4HC_MEM_COMPRESS); | ||
35 | if (!ctx->lz4hc_comp_mem) | ||
36 | return -ENOMEM; | ||
37 | |||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | static void lz4hc_exit(struct crypto_tfm *tfm) | ||
42 | { | ||
43 | struct lz4hc_ctx *ctx = crypto_tfm_ctx(tfm); | ||
44 | |||
45 | vfree(ctx->lz4hc_comp_mem); | ||
46 | } | ||
47 | |||
48 | static int lz4hc_compress_crypto(struct crypto_tfm *tfm, const u8 *src, | ||
49 | unsigned int slen, u8 *dst, unsigned int *dlen) | ||
50 | { | ||
51 | struct lz4hc_ctx *ctx = crypto_tfm_ctx(tfm); | ||
52 | size_t tmp_len = *dlen; | ||
53 | int err; | ||
54 | |||
55 | err = lz4hc_compress(src, slen, dst, &tmp_len, ctx->lz4hc_comp_mem); | ||
56 | |||
57 | if (err < 0) | ||
58 | return -EINVAL; | ||
59 | |||
60 | *dlen = tmp_len; | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | static int lz4hc_decompress_crypto(struct crypto_tfm *tfm, const u8 *src, | ||
65 | unsigned int slen, u8 *dst, unsigned int *dlen) | ||
66 | { | ||
67 | int err; | ||
68 | size_t tmp_len = *dlen; | ||
69 | size_t __slen = slen; | ||
70 | |||
71 | err = lz4_decompress(src, &__slen, dst, tmp_len); | ||
72 | if (err < 0) | ||
73 | return -EINVAL; | ||
74 | |||
75 | *dlen = tmp_len; | ||
76 | return err; | ||
77 | } | ||
78 | |||
79 | static struct crypto_alg alg_lz4hc = { | ||
80 | .cra_name = "lz4hc", | ||
81 | .cra_flags = CRYPTO_ALG_TYPE_COMPRESS, | ||
82 | .cra_ctxsize = sizeof(struct lz4hc_ctx), | ||
83 | .cra_module = THIS_MODULE, | ||
84 | .cra_list = LIST_HEAD_INIT(alg_lz4hc.cra_list), | ||
85 | .cra_init = lz4hc_init, | ||
86 | .cra_exit = lz4hc_exit, | ||
87 | .cra_u = { .compress = { | ||
88 | .coa_compress = lz4hc_compress_crypto, | ||
89 | .coa_decompress = lz4hc_decompress_crypto } } | ||
90 | }; | ||
91 | |||
92 | static int __init lz4hc_mod_init(void) | ||
93 | { | ||
94 | return crypto_register_alg(&alg_lz4hc); | ||
95 | } | ||
96 | |||
97 | static void __exit lz4hc_mod_fini(void) | ||
98 | { | ||
99 | crypto_unregister_alg(&alg_lz4hc); | ||
100 | } | ||
101 | |||
102 | module_init(lz4hc_mod_init); | ||
103 | module_exit(lz4hc_mod_fini); | ||
104 | |||
105 | MODULE_LICENSE("GPL"); | ||
106 | MODULE_DESCRIPTION("LZ4HC Compression Algorithm"); | ||