diff options
-rw-r--r-- | crypto/Kconfig | 8 | ||||
-rw-r--r-- | crypto/Makefile | 1 | ||||
-rw-r--r-- | crypto/lzo.c | 106 | ||||
-rw-r--r-- | crypto/tcrypt.c | 9 | ||||
-rw-r--r-- | crypto/tcrypt.h | 82 |
5 files changed, 205 insertions, 1 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig index 40ae92caa4f6..4fd14e4efed2 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
@@ -536,6 +536,14 @@ config CRYPTO_AUTHENC | |||
536 | Authenc: Combined mode wrapper for IPsec. | 536 | Authenc: Combined mode wrapper for IPsec. |
537 | This is required for IPSec. | 537 | This is required for IPSec. |
538 | 538 | ||
539 | config CRYPTO_LZO | ||
540 | tristate "LZO compression algorithm" | ||
541 | select CRYPTO_ALGAPI | ||
542 | select LZO_COMPRESS | ||
543 | select LZO_DECOMPRESS | ||
544 | help | ||
545 | This is the LZO algorithm. | ||
546 | |||
539 | source "drivers/crypto/Kconfig" | 547 | source "drivers/crypto/Kconfig" |
540 | 548 | ||
541 | endif # if CRYPTO | 549 | endif # if CRYPTO |
diff --git a/crypto/Makefile b/crypto/Makefile index 957343cbc0e2..83532ac8466d 100644 --- a/crypto/Makefile +++ b/crypto/Makefile | |||
@@ -55,6 +55,7 @@ obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o | |||
55 | obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o | 55 | obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o |
56 | obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o | 56 | obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o |
57 | obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o | 57 | obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o |
58 | obj-$(CONFIG_CRYPTO_LZO) += lzo.o | ||
58 | 59 | ||
59 | obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o | 60 | obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o |
60 | 61 | ||
diff --git a/crypto/lzo.c b/crypto/lzo.c new file mode 100644 index 000000000000..48c32883f024 --- /dev/null +++ b/crypto/lzo.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /* | ||
2 | * Cryptographic API. | ||
3 | * | ||
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. | ||
7 | * | ||
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 | ||
11 | * more details. | ||
12 | * | ||
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 | ||
16 | * | ||
17 | */ | ||
18 | |||
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 | |||
25 | struct lzo_ctx { | ||
26 | void *lzo_comp_mem; | ||
27 | }; | ||
28 | |||
29 | static int lzo_init(struct crypto_tfm *tfm) | ||
30 | { | ||
31 | struct lzo_ctx *ctx = crypto_tfm_ctx(tfm); | ||
32 | |||
33 | ctx->lzo_comp_mem = vmalloc(LZO1X_MEM_COMPRESS); | ||
34 | if (!ctx->lzo_comp_mem) | ||
35 | return -ENOMEM; | ||
36 | |||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | static void lzo_exit(struct crypto_tfm *tfm) | ||
41 | { | ||
42 | struct lzo_ctx *ctx = crypto_tfm_ctx(tfm); | ||
43 | |||
44 | vfree(ctx->lzo_comp_mem); | ||
45 | } | ||
46 | |||
47 | static int lzo_compress(struct crypto_tfm *tfm, const u8 *src, | ||
48 | unsigned int slen, u8 *dst, unsigned int *dlen) | ||
49 | { | ||
50 | struct lzo_ctx *ctx = crypto_tfm_ctx(tfm); | ||
51 | size_t tmp_len = *dlen; /* size_t(ulong) <-> uint on 64 bit */ | ||
52 | int err; | ||
53 | |||
54 | err = lzo1x_1_compress(src, slen, dst, &tmp_len, ctx->lzo_comp_mem); | ||
55 | |||
56 | if (err != LZO_E_OK) | ||
57 | return -EINVAL; | ||
58 | |||
59 | *dlen = tmp_len; | ||
60 | return 0; | ||
61 | } | ||
62 | |||
63 | static int lzo_decompress(struct crypto_tfm *tfm, const u8 *src, | ||
64 | unsigned int slen, u8 *dst, unsigned int *dlen) | ||
65 | { | ||
66 | int err; | ||
67 | size_t tmp_len = *dlen; /* size_t(ulong) <-> uint on 64 bit */ | ||
68 | |||
69 | err = lzo1x_decompress_safe(src, slen, dst, &tmp_len); | ||
70 | |||
71 | if (err != LZO_E_OK) | ||
72 | return -EINVAL; | ||
73 | |||
74 | *dlen = tmp_len; | ||
75 | return 0; | ||
76 | |||
77 | } | ||
78 | |||
79 | static struct crypto_alg alg = { | ||
80 | .cra_name = "lzo", | ||
81 | .cra_flags = CRYPTO_ALG_TYPE_COMPRESS, | ||
82 | .cra_ctxsize = sizeof(struct lzo_ctx), | ||
83 | .cra_module = THIS_MODULE, | ||
84 | .cra_list = LIST_HEAD_INIT(alg.cra_list), | ||
85 | .cra_init = lzo_init, | ||
86 | .cra_exit = lzo_exit, | ||
87 | .cra_u = { .compress = { | ||
88 | .coa_compress = lzo_compress, | ||
89 | .coa_decompress = lzo_decompress } } | ||
90 | }; | ||
91 | |||
92 | static int __init init(void) | ||
93 | { | ||
94 | return crypto_register_alg(&alg); | ||
95 | } | ||
96 | |||
97 | static void __exit fini(void) | ||
98 | { | ||
99 | crypto_unregister_alg(&alg); | ||
100 | } | ||
101 | |||
102 | module_init(init); | ||
103 | module_exit(fini); | ||
104 | |||
105 | MODULE_LICENSE("GPL"); | ||
106 | MODULE_DESCRIPTION("LZO Compression Algorithm"); | ||
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index c8d3e600c541..943a514478bd 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -84,7 +84,7 @@ static char *check[] = { | |||
84 | "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | 84 | "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
85 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | 85 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
86 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", | 86 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", |
87 | "camellia", "seed", "salsa20", NULL | 87 | "camellia", "seed", "salsa20", "lzo", NULL |
88 | }; | 88 | }; |
89 | 89 | ||
90 | static void hexdump(unsigned char *buf, unsigned int len) | 90 | static void hexdump(unsigned char *buf, unsigned int len) |
@@ -1292,6 +1292,8 @@ static void do_test(void) | |||
1292 | test_comp("deflate", deflate_comp_tv_template, | 1292 | test_comp("deflate", deflate_comp_tv_template, |
1293 | deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS, | 1293 | deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS, |
1294 | DEFLATE_DECOMP_TEST_VECTORS); | 1294 | DEFLATE_DECOMP_TEST_VECTORS); |
1295 | test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template, | ||
1296 | LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS); | ||
1295 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); | 1297 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
1296 | test_hash("hmac(md5)", hmac_md5_tv_template, | 1298 | test_hash("hmac(md5)", hmac_md5_tv_template, |
1297 | HMAC_MD5_TEST_VECTORS); | 1299 | HMAC_MD5_TEST_VECTORS); |
@@ -1550,6 +1552,11 @@ static void do_test(void) | |||
1550 | AES_GCM_DEC_TEST_VECTORS); | 1552 | AES_GCM_DEC_TEST_VECTORS); |
1551 | break; | 1553 | break; |
1552 | 1554 | ||
1555 | case 36: | ||
1556 | test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template, | ||
1557 | LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS); | ||
1558 | break; | ||
1559 | |||
1553 | case 100: | 1560 | case 100: |
1554 | test_hash("hmac(md5)", hmac_md5_tv_template, | 1561 | test_hash("hmac(md5)", hmac_md5_tv_template, |
1555 | HMAC_MD5_TEST_VECTORS); | 1562 | HMAC_MD5_TEST_VECTORS); |
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h index d3c380f5fe83..175f26a58e2d 100644 --- a/crypto/tcrypt.h +++ b/crypto/tcrypt.h | |||
@@ -7461,6 +7461,88 @@ static struct comp_testvec deflate_decomp_tv_template[] = { | |||
7461 | }; | 7461 | }; |
7462 | 7462 | ||
7463 | /* | 7463 | /* |
7464 | * LZO test vectors (null-terminated strings). | ||
7465 | */ | ||
7466 | #define LZO_COMP_TEST_VECTORS 2 | ||
7467 | #define LZO_DECOMP_TEST_VECTORS 2 | ||
7468 | |||
7469 | static struct comp_testvec lzo_comp_tv_template[] = { | ||
7470 | { | ||
7471 | .inlen = 70, | ||
7472 | .outlen = 46, | ||
7473 | .input = "Join us now and share the software " | ||
7474 | "Join us now and share the software ", | ||
7475 | .output = { 0x00, 0x0d, 0x4a, 0x6f, 0x69, 0x6e, 0x20, 0x75, | ||
7476 | 0x73, 0x20, 0x6e, 0x6f, 0x77, 0x20, 0x61, 0x6e, | ||
7477 | 0x64, 0x20, 0x73, 0x68, 0x61, 0x72, 0x65, 0x20, | ||
7478 | 0x74, 0x68, 0x65, 0x20, 0x73, 0x6f, 0x66, 0x74, | ||
7479 | 0x77, 0x70, 0x01, 0x01, 0x4a, 0x6f, 0x69, 0x6e, | ||
7480 | 0x3d, 0x88, 0x00, 0x11, 0x00, 0x00 }, | ||
7481 | }, { | ||
7482 | .inlen = 159, | ||
7483 | .outlen = 133, | ||
7484 | .input = "This document describes a compression method based on the LZO " | ||
7485 | "compression algorithm. This document defines the application of " | ||
7486 | "the LZO algorithm used in UBIFS.", | ||
7487 | .output = { 0x00, 0x2b, 0x54, 0x68, 0x69, 0x73, 0x20, 0x64, | ||
7488 | 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x20, | ||
7489 | 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, | ||
7490 | 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x70, | ||
7491 | 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x20, | ||
7492 | 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x20, 0x62, | ||
7493 | 0x61, 0x73, 0x65, 0x64, 0x20, 0x6f, 0x6e, 0x20, | ||
7494 | 0x74, 0x68, 0x65, 0x20, 0x4c, 0x5a, 0x4f, 0x2b, | ||
7495 | 0x8c, 0x00, 0x0d, 0x61, 0x6c, 0x67, 0x6f, 0x72, | ||
7496 | 0x69, 0x74, 0x68, 0x6d, 0x2e, 0x20, 0x20, 0x54, | ||
7497 | 0x68, 0x69, 0x73, 0x2a, 0x54, 0x01, 0x02, 0x66, | ||
7498 | 0x69, 0x6e, 0x65, 0x73, 0x94, 0x06, 0x05, 0x61, | ||
7499 | 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x76, | ||
7500 | 0x0a, 0x6f, 0x66, 0x88, 0x02, 0x60, 0x09, 0x27, | ||
7501 | 0xf0, 0x00, 0x0c, 0x20, 0x75, 0x73, 0x65, 0x64, | ||
7502 | 0x20, 0x69, 0x6e, 0x20, 0x55, 0x42, 0x49, 0x46, | ||
7503 | 0x53, 0x2e, 0x11, 0x00, 0x00 }, | ||
7504 | }, | ||
7505 | }; | ||
7506 | |||
7507 | static struct comp_testvec lzo_decomp_tv_template[] = { | ||
7508 | { | ||
7509 | .inlen = 133, | ||
7510 | .outlen = 159, | ||
7511 | .input = { 0x00, 0x2b, 0x54, 0x68, 0x69, 0x73, 0x20, 0x64, | ||
7512 | 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x20, | ||
7513 | 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, | ||
7514 | 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x70, | ||
7515 | 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x20, | ||
7516 | 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x20, 0x62, | ||
7517 | 0x61, 0x73, 0x65, 0x64, 0x20, 0x6f, 0x6e, 0x20, | ||
7518 | 0x74, 0x68, 0x65, 0x20, 0x4c, 0x5a, 0x4f, 0x2b, | ||
7519 | 0x8c, 0x00, 0x0d, 0x61, 0x6c, 0x67, 0x6f, 0x72, | ||
7520 | 0x69, 0x74, 0x68, 0x6d, 0x2e, 0x20, 0x20, 0x54, | ||
7521 | 0x68, 0x69, 0x73, 0x2a, 0x54, 0x01, 0x02, 0x66, | ||
7522 | 0x69, 0x6e, 0x65, 0x73, 0x94, 0x06, 0x05, 0x61, | ||
7523 | 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x76, | ||
7524 | 0x0a, 0x6f, 0x66, 0x88, 0x02, 0x60, 0x09, 0x27, | ||
7525 | 0xf0, 0x00, 0x0c, 0x20, 0x75, 0x73, 0x65, 0x64, | ||
7526 | 0x20, 0x69, 0x6e, 0x20, 0x55, 0x42, 0x49, 0x46, | ||
7527 | 0x53, 0x2e, 0x11, 0x00, 0x00 }, | ||
7528 | .output = "This document describes a compression method based on the LZO " | ||
7529 | "compression algorithm. This document defines the application of " | ||
7530 | "the LZO algorithm used in UBIFS.", | ||
7531 | }, { | ||
7532 | .inlen = 46, | ||
7533 | .outlen = 70, | ||
7534 | .input = { 0x00, 0x0d, 0x4a, 0x6f, 0x69, 0x6e, 0x20, 0x75, | ||
7535 | 0x73, 0x20, 0x6e, 0x6f, 0x77, 0x20, 0x61, 0x6e, | ||
7536 | 0x64, 0x20, 0x73, 0x68, 0x61, 0x72, 0x65, 0x20, | ||
7537 | 0x74, 0x68, 0x65, 0x20, 0x73, 0x6f, 0x66, 0x74, | ||
7538 | 0x77, 0x70, 0x01, 0x01, 0x4a, 0x6f, 0x69, 0x6e, | ||
7539 | 0x3d, 0x88, 0x00, 0x11, 0x00, 0x00 }, | ||
7540 | .output = "Join us now and share the software " | ||
7541 | "Join us now and share the software ", | ||
7542 | }, | ||
7543 | }; | ||
7544 | |||
7545 | /* | ||
7464 | * Michael MIC test vectors from IEEE 802.11i | 7546 | * Michael MIC test vectors from IEEE 802.11i |
7465 | */ | 7547 | */ |
7466 | #define MICHAEL_MIC_TEST_VECTORS 6 | 7548 | #define MICHAEL_MIC_TEST_VECTORS 6 |