diff options
-rw-r--r-- | crypto/Kconfig | 4 | ||||
-rw-r--r-- | crypto/Makefile | 2 | ||||
-rw-r--r-- | crypto/pcompress.c | 97 | ||||
-rw-r--r-- | include/crypto/compress.h | 125 | ||||
-rw-r--r-- | include/crypto/internal/compress.h | 28 | ||||
-rw-r--r-- | include/linux/crypto.h | 1 |
6 files changed, 257 insertions, 0 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig index 4a3e6b225189..1676f171c54b 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
@@ -76,6 +76,10 @@ config CRYPTO_RNG2 | |||
76 | tristate | 76 | tristate |
77 | select CRYPTO_ALGAPI2 | 77 | select CRYPTO_ALGAPI2 |
78 | 78 | ||
79 | config CRYPTO_PCOMP | ||
80 | tristate | ||
81 | select CRYPTO_ALGAPI2 | ||
82 | |||
79 | config CRYPTO_MANAGER | 83 | config CRYPTO_MANAGER |
80 | tristate "Cryptographic algorithm manager" | 84 | tristate "Cryptographic algorithm manager" |
81 | select CRYPTO_MANAGER2 | 85 | select CRYPTO_MANAGER2 |
diff --git a/crypto/Makefile b/crypto/Makefile index e05a844e08d5..1132a678b253 100644 --- a/crypto/Makefile +++ b/crypto/Makefile | |||
@@ -27,6 +27,8 @@ crypto_hash-objs += ahash.o | |||
27 | crypto_hash-objs += shash.o | 27 | crypto_hash-objs += shash.o |
28 | obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o | 28 | obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o |
29 | 29 | ||
30 | obj-$(CONFIG_CRYPTO_PCOMP) += pcompress.o | ||
31 | |||
30 | cryptomgr-objs := algboss.o testmgr.o | 32 | cryptomgr-objs := algboss.o testmgr.o |
31 | 33 | ||
32 | obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o | 34 | obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o |
diff --git a/crypto/pcompress.c b/crypto/pcompress.c new file mode 100644 index 000000000000..ca9a4af91efe --- /dev/null +++ b/crypto/pcompress.c | |||
@@ -0,0 +1,97 @@ | |||
1 | /* | ||
2 | * Cryptographic API. | ||
3 | * | ||
4 | * Partial (de)compression operations. | ||
5 | * | ||
6 | * Copyright 2008 Sony Corporation | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; version 2 of the License. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program. | ||
19 | * If not, see <http://www.gnu.org/licenses/>. | ||
20 | */ | ||
21 | |||
22 | #include <linux/crypto.h> | ||
23 | #include <linux/errno.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/seq_file.h> | ||
26 | #include <linux/string.h> | ||
27 | |||
28 | #include <crypto/compress.h> | ||
29 | |||
30 | #include "internal.h" | ||
31 | |||
32 | |||
33 | static int crypto_pcomp_init(struct crypto_tfm *tfm, u32 type, u32 mask) | ||
34 | { | ||
35 | return 0; | ||
36 | } | ||
37 | |||
38 | static unsigned int crypto_pcomp_extsize(struct crypto_alg *alg, | ||
39 | const struct crypto_type *frontend) | ||
40 | { | ||
41 | return alg->cra_ctxsize; | ||
42 | } | ||
43 | |||
44 | static int crypto_pcomp_init_tfm(struct crypto_tfm *tfm, | ||
45 | const struct crypto_type *frontend) | ||
46 | { | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg) | ||
51 | __attribute__ ((unused)); | ||
52 | static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg) | ||
53 | { | ||
54 | seq_printf(m, "type : pcomp\n"); | ||
55 | } | ||
56 | |||
57 | static const struct crypto_type crypto_pcomp_type = { | ||
58 | .extsize = crypto_pcomp_extsize, | ||
59 | .init = crypto_pcomp_init, | ||
60 | .init_tfm = crypto_pcomp_init_tfm, | ||
61 | #ifdef CONFIG_PROC_FS | ||
62 | .show = crypto_pcomp_show, | ||
63 | #endif | ||
64 | .maskclear = ~CRYPTO_ALG_TYPE_MASK, | ||
65 | .maskset = CRYPTO_ALG_TYPE_MASK, | ||
66 | .type = CRYPTO_ALG_TYPE_PCOMPRESS, | ||
67 | .tfmsize = offsetof(struct crypto_pcomp, base), | ||
68 | }; | ||
69 | |||
70 | struct crypto_pcomp *crypto_alloc_pcomp(const char *alg_name, u32 type, | ||
71 | u32 mask) | ||
72 | { | ||
73 | return crypto_alloc_tfm(alg_name, &crypto_pcomp_type, type, mask); | ||
74 | } | ||
75 | EXPORT_SYMBOL_GPL(crypto_alloc_pcomp); | ||
76 | |||
77 | int crypto_register_pcomp(struct pcomp_alg *alg) | ||
78 | { | ||
79 | struct crypto_alg *base = &alg->base; | ||
80 | |||
81 | base->cra_type = &crypto_pcomp_type; | ||
82 | base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK; | ||
83 | base->cra_flags |= CRYPTO_ALG_TYPE_PCOMPRESS; | ||
84 | |||
85 | return crypto_register_alg(base); | ||
86 | } | ||
87 | EXPORT_SYMBOL_GPL(crypto_register_pcomp); | ||
88 | |||
89 | int crypto_unregister_pcomp(struct pcomp_alg *alg) | ||
90 | { | ||
91 | return crypto_unregister_alg(&alg->base); | ||
92 | } | ||
93 | EXPORT_SYMBOL_GPL(crypto_unregister_pcomp); | ||
94 | |||
95 | MODULE_LICENSE("GPL"); | ||
96 | MODULE_DESCRIPTION("Partial (de)compression type"); | ||
97 | MODULE_AUTHOR("Sony Corporation"); | ||
diff --git a/include/crypto/compress.h b/include/crypto/compress.h new file mode 100644 index 000000000000..b7d228708d6b --- /dev/null +++ b/include/crypto/compress.h | |||
@@ -0,0 +1,125 @@ | |||
1 | /* | ||
2 | * Compress: Compression algorithms under the cryptographic API. | ||
3 | * | ||
4 | * Copyright 2008 Sony Corporation | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; version 2 of the License. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. | ||
17 | * If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | #ifndef _CRYPTO_COMPRESS_H | ||
21 | #define _CRYPTO_COMPRESS_H | ||
22 | |||
23 | #include <linux/crypto.h> | ||
24 | |||
25 | |||
26 | struct comp_request { | ||
27 | const void *next_in; /* next input byte */ | ||
28 | void *next_out; /* next output byte */ | ||
29 | unsigned int avail_in; /* bytes available at next_in */ | ||
30 | unsigned int avail_out; /* bytes available at next_out */ | ||
31 | }; | ||
32 | |||
33 | struct crypto_pcomp { | ||
34 | struct crypto_tfm base; | ||
35 | }; | ||
36 | |||
37 | struct pcomp_alg { | ||
38 | int (*compress_setup)(struct crypto_pcomp *tfm, void *params, | ||
39 | unsigned int len); | ||
40 | int (*compress_init)(struct crypto_pcomp *tfm); | ||
41 | int (*compress_update)(struct crypto_pcomp *tfm, | ||
42 | struct comp_request *req); | ||
43 | int (*compress_final)(struct crypto_pcomp *tfm, | ||
44 | struct comp_request *req); | ||
45 | int (*decompress_setup)(struct crypto_pcomp *tfm, void *params, | ||
46 | unsigned int len); | ||
47 | int (*decompress_init)(struct crypto_pcomp *tfm); | ||
48 | int (*decompress_update)(struct crypto_pcomp *tfm, | ||
49 | struct comp_request *req); | ||
50 | int (*decompress_final)(struct crypto_pcomp *tfm, | ||
51 | struct comp_request *req); | ||
52 | |||
53 | struct crypto_alg base; | ||
54 | }; | ||
55 | |||
56 | extern struct crypto_pcomp *crypto_alloc_pcomp(const char *alg_name, u32 type, | ||
57 | u32 mask); | ||
58 | |||
59 | static inline struct crypto_tfm *crypto_pcomp_tfm(struct crypto_pcomp *tfm) | ||
60 | { | ||
61 | return &tfm->base; | ||
62 | } | ||
63 | |||
64 | static inline void crypto_free_pcomp(struct crypto_pcomp *tfm) | ||
65 | { | ||
66 | crypto_destroy_tfm(tfm, crypto_pcomp_tfm(tfm)); | ||
67 | } | ||
68 | |||
69 | static inline struct pcomp_alg *__crypto_pcomp_alg(struct crypto_alg *alg) | ||
70 | { | ||
71 | return container_of(alg, struct pcomp_alg, base); | ||
72 | } | ||
73 | |||
74 | static inline struct pcomp_alg *crypto_pcomp_alg(struct crypto_pcomp *tfm) | ||
75 | { | ||
76 | return __crypto_pcomp_alg(crypto_pcomp_tfm(tfm)->__crt_alg); | ||
77 | } | ||
78 | |||
79 | static inline int crypto_compress_setup(struct crypto_pcomp *tfm, | ||
80 | void *params, unsigned int len) | ||
81 | { | ||
82 | return crypto_pcomp_alg(tfm)->compress_setup(tfm, params, len); | ||
83 | } | ||
84 | |||
85 | static inline int crypto_compress_init(struct crypto_pcomp *tfm) | ||
86 | { | ||
87 | return crypto_pcomp_alg(tfm)->compress_init(tfm); | ||
88 | } | ||
89 | |||
90 | static inline int crypto_compress_update(struct crypto_pcomp *tfm, | ||
91 | struct comp_request *req) | ||
92 | { | ||
93 | return crypto_pcomp_alg(tfm)->compress_update(tfm, req); | ||
94 | } | ||
95 | |||
96 | static inline int crypto_compress_final(struct crypto_pcomp *tfm, | ||
97 | struct comp_request *req) | ||
98 | { | ||
99 | return crypto_pcomp_alg(tfm)->compress_final(tfm, req); | ||
100 | } | ||
101 | |||
102 | static inline int crypto_decompress_setup(struct crypto_pcomp *tfm, | ||
103 | void *params, unsigned int len) | ||
104 | { | ||
105 | return crypto_pcomp_alg(tfm)->decompress_setup(tfm, params, len); | ||
106 | } | ||
107 | |||
108 | static inline int crypto_decompress_init(struct crypto_pcomp *tfm) | ||
109 | { | ||
110 | return crypto_pcomp_alg(tfm)->decompress_init(tfm); | ||
111 | } | ||
112 | |||
113 | static inline int crypto_decompress_update(struct crypto_pcomp *tfm, | ||
114 | struct comp_request *req) | ||
115 | { | ||
116 | return crypto_pcomp_alg(tfm)->decompress_update(tfm, req); | ||
117 | } | ||
118 | |||
119 | static inline int crypto_decompress_final(struct crypto_pcomp *tfm, | ||
120 | struct comp_request *req) | ||
121 | { | ||
122 | return crypto_pcomp_alg(tfm)->decompress_final(tfm, req); | ||
123 | } | ||
124 | |||
125 | #endif /* _CRYPTO_COMPRESS_H */ | ||
diff --git a/include/crypto/internal/compress.h b/include/crypto/internal/compress.h new file mode 100644 index 000000000000..178a888d1d93 --- /dev/null +++ b/include/crypto/internal/compress.h | |||
@@ -0,0 +1,28 @@ | |||
1 | /* | ||
2 | * Compress: Compression algorithms under the cryptographic API. | ||
3 | * | ||
4 | * Copyright 2008 Sony Corporation | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; version 2 of the License. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. | ||
17 | * If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | #ifndef _CRYPTO_INTERNAL_COMPRESS_H | ||
21 | #define _CRYPTO_INTERNAL_COMPRESS_H | ||
22 | |||
23 | #include <crypto/compress.h> | ||
24 | |||
25 | extern int crypto_register_pcomp(struct pcomp_alg *alg); | ||
26 | extern int crypto_unregister_pcomp(struct pcomp_alg *alg); | ||
27 | |||
28 | #endif /* _CRYPTO_INTERNAL_COMPRESS_H */ | ||
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 29729b834380..ec29fa268b94 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -40,6 +40,7 @@ | |||
40 | #define CRYPTO_ALG_TYPE_SHASH 0x00000009 | 40 | #define CRYPTO_ALG_TYPE_SHASH 0x00000009 |
41 | #define CRYPTO_ALG_TYPE_AHASH 0x0000000a | 41 | #define CRYPTO_ALG_TYPE_AHASH 0x0000000a |
42 | #define CRYPTO_ALG_TYPE_RNG 0x0000000c | 42 | #define CRYPTO_ALG_TYPE_RNG 0x0000000c |
43 | #define CRYPTO_ALG_TYPE_PCOMPRESS 0x0000000f | ||
43 | 44 | ||
44 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e | 45 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e |
45 | #define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000c | 46 | #define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000c |