aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorGeert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>2009-03-04 02:05:33 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2009-03-04 02:05:33 -0500
commita1d2f09544065b60598b8167d94a6371bff3e892 (patch)
treecd8b88e7ea0cd44e7e369f670f9fdfcba78f4326 /crypto
parente9cc8bddaea3944fabfebb968bc88d603239beed (diff)
crypto: compress - Add pcomp interface
The current "comp" crypto interface supports one-shot (de)compression only, i.e. the whole data buffer to be (de)compressed must be passed at once, and the whole (de)compressed data buffer will be received at once. In several use-cases (e.g. compressed file systems that store files in big compressed blocks), this workflow is not suitable. Furthermore, the "comp" type doesn't provide for the configuration of (de)compression parameters, and always allocates workspace memory for both compression and decompression, which may waste memory. To solve this, add a "pcomp" partial (de)compression interface that provides the following operations: - crypto_compress_{init,update,final}() for compression, - crypto_decompress_{init,update,final}() for decompression, - crypto_{,de}compress_setup(), to configure (de)compression parameters (incl. allocating workspace memory). The (de)compression methods take a struct comp_request, which was mimicked after the z_stream object in zlib, and contains buffer pointer and length pairs for input and output. The setup methods take an opaque parameter pointer and length pair. Parameters are supposed to be encoded using netlink attributes, whose meanings depend on the actual (name of the) (de)compression algorithm. Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/Kconfig4
-rw-r--r--crypto/Makefile2
-rw-r--r--crypto/pcompress.c97
3 files changed, 103 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
79config CRYPTO_PCOMP
80 tristate
81 select CRYPTO_ALGAPI2
82
79config CRYPTO_MANAGER 83config 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
27crypto_hash-objs += shash.o 27crypto_hash-objs += shash.o
28obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o 28obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o
29 29
30obj-$(CONFIG_CRYPTO_PCOMP) += pcompress.o
31
30cryptomgr-objs := algboss.o testmgr.o 32cryptomgr-objs := algboss.o testmgr.o
31 33
32obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o 34obj-$(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
33static int crypto_pcomp_init(struct crypto_tfm *tfm, u32 type, u32 mask)
34{
35 return 0;
36}
37
38static unsigned int crypto_pcomp_extsize(struct crypto_alg *alg,
39 const struct crypto_type *frontend)
40{
41 return alg->cra_ctxsize;
42}
43
44static int crypto_pcomp_init_tfm(struct crypto_tfm *tfm,
45 const struct crypto_type *frontend)
46{
47 return 0;
48}
49
50static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg)
51 __attribute__ ((unused));
52static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg)
53{
54 seq_printf(m, "type : pcomp\n");
55}
56
57static 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
70struct 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}
75EXPORT_SYMBOL_GPL(crypto_alloc_pcomp);
76
77int 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}
87EXPORT_SYMBOL_GPL(crypto_register_pcomp);
88
89int crypto_unregister_pcomp(struct pcomp_alg *alg)
90{
91 return crypto_unregister_alg(&alg->base);
92}
93EXPORT_SYMBOL_GPL(crypto_unregister_pcomp);
94
95MODULE_LICENSE("GPL");
96MODULE_DESCRIPTION("Partial (de)compression type");
97MODULE_AUTHOR("Sony Corporation");