Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1317610 > unrolled thread
| Started by | Joonsoo Kim <js1304@gmail.com> |
|---|---|
| First post | 2016-01-26 09:20 +0100 |
| Last post | 2016-01-26 09:20 +0100 |
| Articles | 10 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH v2 00/10] Introduce new async/sync compression APIs Joonsoo Kim <js1304@gmail.com> - 2016-01-26 09:20 +0100
[PATCH v2 02/10] crypto: add algorithm type specific flag, CRYPTO_ALG_PRIVATE Joonsoo Kim <js1304@gmail.com> - 2016-01-26 09:20 +0100
[PATCH v2 06/10] crypto/lz4: support new compression APIs Joonsoo Kim <js1304@gmail.com> - 2016-01-26 09:20 +0100
[PATCH v2 04/10] crypto/compress: add asynchronous compression support Joonsoo Kim <js1304@gmail.com> - 2016-01-26 09:20 +0100
Re: [PATCH v2 04/10] crypto/compress: add asynchronous compression support Herbert Xu <herbert@gondor.apana.org.au> - 2016-01-27 08:50 +0100
Re: [PATCH v2 04/10] crypto/compress: add asynchronous compression support "Li, Weigang" <weigang.li@intel.com> - 2016-01-27 09:00 +0100
Re: [PATCH v2 04/10] crypto/compress: add asynchronous compression support Herbert Xu <herbert@gondor.apana.org.au> - 2016-01-27 09:10 +0100
Re: [PATCH v2 04/10] crypto/compress: add asynchronous compression support Herbert Xu <herbert@gondor.apana.org.au> - 2016-01-27 09:10 +0100
Re: [PATCH v2 04/10] crypto/compress: add asynchronous compression support "Li, Weigang" <weigang.li@intel.com> - 2016-01-27 09:30 +0100
[PATCH v2 03/10] crypto/compress: introduce sychronuous compression API Joonsoo Kim <js1304@gmail.com> - 2016-01-26 09:20 +0100
| From | Joonsoo Kim <js1304@gmail.com> |
|---|---|
| Date | 2016-01-26 09:20 +0100 |
| Subject | [PATCH v2 00/10] Introduce new async/sync compression APIs |
| Message-ID | <qV710-1ma-3@gated-at.bofh.it> |
This patchset introduces new compression APIs. This work is started to support crypto compression in zram [1]. I will restart that work after this patchset is mereged. Major point of new APIs is that it is now stateless. Instead of legacy compression API, tfm objects doesn't embedded any context so we can de/compress concurrently with one tfm object. Instead, this de/compression context is coupled with the request. This architecture change will make APIs more flexible and we can naturally use asynchronous APIs as front-end of synchronous compression algorithm. Moreover, thanks to this change, we can decompress without context buffer if algorithm supports it. In this case, we can achieve maximum parallelism without memory overhead caused by context buffer. Please let know if there is a problem. Thanks. [1]: https://lkml.org/lkml/2015/10/14/83 Joonsoo Kim (9): crypto/compress: remove unused pcomp interface crypto: add algorithm type specific flag, CRYPTO_ALG_PRIVATE crypto/compress: introduce sychronuous compression API crypto/lzo: support new compression APIs crypto/lz4: support new compression APIs crypto/lz4hc: support new compression APIs crypto/842: support new compression APIs crypto/deflate: support new compression APIs crypto/testmgr: add new compression APIs test Weigang Li (1): crypto/compress: add asynchronous compression support crypto/842.c | 85 +++++++- crypto/Kconfig | 23 +- crypto/Makefile | 4 +- crypto/acompress.c | 164 ++++++++++++++ crypto/deflate.c | 110 +++++++++- crypto/lz4.c | 91 +++++++- crypto/lz4hc.c | 91 +++++++- crypto/lzo.c | 95 ++++++-- crypto/pcompress.c | 115 ---------- crypto/scompress.c | 284 ++++++++++++++++++++++++ crypto/testmgr.c | 428 ++++++++++++++++++------------------- crypto/testmgr.h | 144 ------------- crypto/zlib.c | 381 --------------------------------- include/crypto/compress.h | 375 ++++++++++++++++++++++++-------- include/crypto/internal/compress.h | 32 +-- include/linux/crypto.h | 9 +- 16 files changed, 1387 insertions(+), 1044 deletions(-) create mode 100644 crypto/acompress.c delete mode 100644 crypto/pcompress.c create mode 100644 crypto/scompress.c delete mode 100644 crypto/zlib.c -- 1.9.1
[toc] | [next] | [standalone]
| From | Joonsoo Kim <js1304@gmail.com> |
|---|---|
| Date | 2016-01-26 09:20 +0100 |
| Subject | [PATCH v2 02/10] crypto: add algorithm type specific flag, CRYPTO_ALG_PRIVATE |
| Message-ID | <qV710-1ma-19@gated-at.bofh.it> |
| In reply to | #1317610 |
In following patch, new synchronous compression APIs will be introduced and it needs one flags to determine whether context buffer is needed or not for decompression. It can be implemented by flag in it's own algorithm structure definition but because there is a room in general crypto_alg flag, this patch reuses it to reduce complexity. It possibly can be used for other algorithm type. Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> --- include/linux/crypto.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/crypto.h b/include/linux/crypto.h index ab2a745..96530a1 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -101,6 +101,11 @@ #define CRYPTO_ALG_INTERNAL 0x00002000 /* + * Use this flag as algorithm type specific one. + */ +#define CRYPTO_ALG_PRIVATE 0x00004000 + +/* * Transform masks and values (for crt_flags). */ #define CRYPTO_TFM_REQ_MASK 0x000fff00 -- 1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Joonsoo Kim <js1304@gmail.com> |
|---|---|
| Date | 2016-01-26 09:20 +0100 |
| Subject | [PATCH v2 06/10] crypto/lz4: support new compression APIs |
| Message-ID | <qV711-1ma-25@gated-at.bofh.it> |
| In reply to | #1317610 |
Now, new compression APIs are introduced and it has some benefits.
Let's support it.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
crypto/Kconfig | 1 +
crypto/lz4.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 82 insertions(+), 10 deletions(-)
diff --git a/crypto/Kconfig b/crypto/Kconfig
index b4b485c..72ab0d7 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -1520,6 +1520,7 @@ config CRYPTO_LZ4
select CRYPTO_ALGAPI
select LZ4_COMPRESS
select LZ4_DECOMPRESS
+ select CRYPTO_COMPRESS2
help
This is the LZ4 algorithm.
diff --git a/crypto/lz4.c b/crypto/lz4.c
index aefbcea..728c6c4 100644
--- a/crypto/lz4.c
+++ b/crypto/lz4.c
@@ -24,35 +24,53 @@
#include <linux/vmalloc.h>
#include <linux/lz4.h>
+#include <crypto/compress.h>
+
struct lz4_ctx {
void *lz4_comp_mem;
};
+static void *lz4_alloc_ctx(struct crypto_scomp *tfm)
+{
+ void *ctx;
+
+ ctx = vmalloc(LZ4_MEM_COMPRESS);
+ if (!ctx)
+ return ERR_PTR(-ENOMEM);
+
+ return ctx;
+}
+
static int lz4_init(struct crypto_tfm *tfm)
{
struct lz4_ctx *ctx = crypto_tfm_ctx(tfm);
- ctx->lz4_comp_mem = vmalloc(LZ4_MEM_COMPRESS);
- if (!ctx->lz4_comp_mem)
+ ctx->lz4_comp_mem = lz4_alloc_ctx(NULL);
+ if (IS_ERR(ctx->lz4_comp_mem))
return -ENOMEM;
return 0;
}
+static void lz4_free_ctx(struct crypto_scomp *tfm, void *ctx)
+{
+ vfree(ctx);
+}
+
static void lz4_exit(struct crypto_tfm *tfm)
{
struct lz4_ctx *ctx = crypto_tfm_ctx(tfm);
- vfree(ctx->lz4_comp_mem);
+
+ lz4_free_ctx(NULL, ctx->lz4_comp_mem);
}
-static int lz4_compress_crypto(struct crypto_tfm *tfm, const u8 *src,
- unsigned int slen, u8 *dst, unsigned int *dlen)
+static int __lz4_compress_crypto(const u8 *src, unsigned int slen,
+ u8 *dst, unsigned int *dlen, void *ctx)
{
- struct lz4_ctx *ctx = crypto_tfm_ctx(tfm);
size_t tmp_len = *dlen;
int err;
- err = lz4_compress(src, slen, dst, &tmp_len, ctx->lz4_comp_mem);
+ err = lz4_compress(src, slen, dst, &tmp_len, ctx);
if (err < 0)
return -EINVAL;
@@ -61,8 +79,22 @@ static int lz4_compress_crypto(struct crypto_tfm *tfm, const u8 *src,
return 0;
}
-static int lz4_decompress_crypto(struct crypto_tfm *tfm, const u8 *src,
- unsigned int slen, u8 *dst, unsigned int *dlen)
+static int lz4_scompress(struct crypto_scomp *tfm, const u8 *src,
+ unsigned int slen, u8 *dst, unsigned int *dlen, void *ctx)
+{
+ return __lz4_compress_crypto(src, slen, dst, dlen, ctx);
+}
+
+static int lz4_compress_crypto(struct crypto_tfm *tfm, const u8 *src,
+ unsigned int slen, u8 *dst, unsigned int *dlen)
+{
+ struct lz4_ctx *ctx = crypto_tfm_ctx(tfm);
+
+ return __lz4_compress_crypto(src, slen, dst, dlen, ctx->lz4_comp_mem);
+}
+
+static int __lz4_decompress_crypto(const u8 *src, unsigned int slen,
+ u8 *dst, unsigned int *dlen, void *ctx)
{
int err;
size_t tmp_len = *dlen;
@@ -76,6 +108,18 @@ static int lz4_decompress_crypto(struct crypto_tfm *tfm, const u8 *src,
return err;
}
+static int lz4_sdecompress(struct crypto_scomp *tfm, const u8 *src,
+ unsigned int slen, u8 *dst, unsigned int *dlen, void *ctx)
+{
+ return __lz4_decompress_crypto(src, slen, dst, dlen, NULL);
+}
+
+static int lz4_decompress_crypto(struct crypto_tfm *tfm, const u8 *src,
+ unsigned int slen, u8 *dst, unsigned int *dlen)
+{
+ return __lz4_decompress_crypto(src, slen, dst, dlen, NULL);
+}
+
static struct crypto_alg alg_lz4 = {
.cra_name = "lz4",
.cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
@@ -89,14 +133,41 @@ static struct crypto_alg alg_lz4 = {
.coa_decompress = lz4_decompress_crypto } }
};
+static struct scomp_alg scomp = {
+ .alloc_ctx = lz4_alloc_ctx,
+ .free_ctx = lz4_free_ctx,
+ .compress = lz4_scompress,
+ .decompress = lz4_sdecompress,
+ .base = {
+ .cra_name = "lz4",
+ .cra_driver_name= "lz4-scomp",
+ .cra_flags = CRYPTO_ALG_TYPE_SCOMPRESS |
+ CRYPTO_SCOMP_DECOMP_NOCTX,
+ .cra_module = THIS_MODULE,
+ }
+};
+
static int __init lz4_mod_init(void)
{
- return crypto_register_alg(&alg_lz4);
+ int ret;
+
+ ret = crypto_register_alg(&alg_lz4);
+ if (ret)
+ return ret;
+
+ ret = crypto_register_scomp(&scomp);
+ if (ret) {
+ crypto_unregister_alg(&alg_lz4);
+ return ret;
+ }
+
+ return ret;
}
static void __exit lz4_mod_fini(void)
{
crypto_unregister_alg(&alg_lz4);
+ crypto_unregister_scomp(&scomp);
}
module_init(lz4_mod_init);
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Joonsoo Kim <js1304@gmail.com> |
|---|---|
| Date | 2016-01-26 09:20 +0100 |
| Subject | [PATCH v2 04/10] crypto/compress: add asynchronous compression support |
| Message-ID | <qV711-1ma-27@gated-at.bofh.it> |
| In reply to | #1317610 |
From: Weigang Li <weigang.li@intel.com>
Now, asynchronous compression APIs are supported. There is no asynchronous
compression driver now but this APIs can be used as front-end to
synchronous compression algorithm. In this case, scatterlist would be
linearlized when needed so it would cause some overhead.
Signed-off-by: Weigang Li <weigang.li@intel.com>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
crypto/Kconfig | 3 +-
crypto/Makefile | 3 +-
crypto/acompress.c | 164 ++++++++++++++++++++++++
crypto/scompress.c | 170 +++++++++++++++++++++++++
include/crypto/compress.h | 253 +++++++++++++++++++++++++++++++++++++
include/crypto/internal/compress.h | 4 +
include/linux/crypto.h | 2 +
7 files changed, 596 insertions(+), 3 deletions(-)
create mode 100644 crypto/acompress.c
create mode 100644 include/crypto/internal/compress.h
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 7159520..f22f4e9 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -84,7 +84,7 @@ config CRYPTO_RNG_DEFAULT
tristate
select CRYPTO_DRBG_MENU
-config CRYPTO_SCOMPRESS
+config CRYPTO_COMPRESS2
tristate
select CRYPTO_ALGAPI2
@@ -1503,7 +1503,6 @@ config CRYPTO_LZO
select CRYPTO_ALGAPI
select LZO_COMPRESS
select LZO_DECOMPRESS
- select SCOMPRESS
help
This is the LZO algorithm.
diff --git a/crypto/Makefile b/crypto/Makefile
index 16ef796..9157d69 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -28,7 +28,8 @@ crypto_hash-y += ahash.o
crypto_hash-y += shash.o
obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o
-obj-$(CONFIG_CRYPTO_SCOMPRESS) += scompress.o
+crypto_compress-y += scompress.o acompress.o
+obj-$(CONFIG_CRYPTO_COMPRESS2) += crypto_compress.o
obj-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o
$(obj)/rsapubkey-asn1.o: $(obj)/rsapubkey-asn1.c $(obj)/rsapubkey-asn1.h
diff --git a/crypto/acompress.c b/crypto/acompress.c
new file mode 100644
index 0000000..ddaa5a0
--- /dev/null
+++ b/crypto/acompress.c
@@ -0,0 +1,164 @@
+/*
+ * Asynchronous compression operations
+ *
+ * Copyright (c) 2015, Intel Corporation
+ * Authors: Weigang Li <weigang.li@intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/seq_file.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/crypto.h>
+
+#include <crypto/algapi.h>
+#include <linux/cryptouser.h>
+#include <net/netlink.h>
+#include <crypto/compress.h>
+#include <crypto/internal/compress.h>
+#include "internal.h"
+
+const struct crypto_type crypto_acomp_type;
+
+#ifdef CONFIG_NET
+static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+ struct crypto_report_comp racomp;
+
+ strncpy(racomp.type, "acomp", sizeof(racomp.type));
+
+ if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
+ sizeof(struct crypto_report_comp), &racomp))
+ goto nla_put_failure;
+ return 0;
+
+nla_put_failure:
+ return -EMSGSIZE;
+}
+#else
+static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+ return -ENOSYS;
+}
+#endif
+
+static void crypto_acomp_show(struct seq_file *m, struct crypto_alg *alg)
+ __attribute__ ((unused));
+
+static void crypto_acomp_show(struct seq_file *m, struct crypto_alg *alg)
+{
+ seq_puts(m, "type : acomp\n");
+}
+
+static void crypto_acomp_exit_tfm(struct crypto_tfm *tfm)
+{
+ struct crypto_acomp *acomp = __crypto_acomp_tfm(tfm);
+ struct acomp_alg *alg = crypto_acomp_alg(acomp);
+
+ alg->exit(acomp);
+}
+
+static int crypto_acomp_init_tfm(struct crypto_tfm *tfm)
+{
+ struct crypto_acomp *acomp = __crypto_acomp_tfm(tfm);
+ struct acomp_alg *alg = crypto_acomp_alg(acomp);
+
+ if (tfm->__crt_alg->cra_type != &crypto_acomp_type)
+ return crypto_init_scomp_ops_async(tfm);
+
+ acomp->compress = alg->compress;
+ acomp->decompress = alg->decompress;
+
+ if (alg->exit)
+ acomp->base.exit = crypto_acomp_exit_tfm;
+
+ if (alg->init)
+ return alg->init(acomp);
+
+ return 0;
+}
+
+static unsigned int crypto_acomp_extsize(struct crypto_alg *alg)
+{
+ if (alg->cra_type == &crypto_acomp_type)
+ return alg->cra_ctxsize;
+
+ return sizeof(void *);
+}
+
+const struct crypto_type crypto_acomp_type = {
+ .extsize = crypto_acomp_extsize,
+ .init_tfm = crypto_acomp_init_tfm,
+#ifdef CONFIG_PROC_FS
+ .show = crypto_acomp_show,
+#endif
+ .report = crypto_acomp_report,
+ .maskclear = ~CRYPTO_ALG_TYPE_MASK,
+ .maskset = CRYPTO_ALG_TYPE_ACOMPRESS_MASK,
+ .type = CRYPTO_ALG_TYPE_ACOMPRESS,
+ .tfmsize = offsetof(struct crypto_acomp, base),
+};
+EXPORT_SYMBOL_GPL(crypto_acomp_type);
+
+struct crypto_acomp *crypto_alloc_acomp(const char *alg_name, u32 type,
+ u32 mask)
+{
+ return crypto_alloc_tfm(alg_name, &crypto_acomp_type, type, mask);
+}
+EXPORT_SYMBOL_GPL(crypto_alloc_acomp);
+
+struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp,
+ gfp_t gfp)
+{
+ struct crypto_tfm *tfm = crypto_acomp_tfm(acomp);
+ struct acomp_req *req;
+
+ if (tfm->__crt_alg->cra_type != &crypto_acomp_type)
+ return crypto_scomp_acomp_request_alloc(acomp, gfp);
+
+ req = kzalloc(sizeof(*req) + crypto_acomp_reqsize(acomp), gfp);
+ if (likely(req))
+ acomp_request_set_tfm(req, acomp);
+
+ return req;
+}
+EXPORT_SYMBOL_GPL(acomp_request_alloc);
+
+void acomp_request_free(struct acomp_req *req)
+{
+ struct crypto_acomp *acomp = crypto_acomp_reqtfm(req);
+ struct crypto_tfm *tfm = crypto_acomp_tfm(acomp);
+
+ if (tfm->__crt_alg->cra_type != &crypto_acomp_type)
+ return crypto_scomp_acomp_request_free(req);
+
+ kfree(req);
+}
+EXPORT_SYMBOL_GPL(acomp_request_free);
+
+int crypto_register_acomp(struct acomp_alg *alg)
+{
+ struct crypto_alg *base = &alg->base;
+
+ base->cra_type = &crypto_acomp_type;
+ base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
+ base->cra_flags |= CRYPTO_ALG_TYPE_ACOMPRESS;
+ return crypto_register_alg(base);
+}
+EXPORT_SYMBOL_GPL(crypto_register_acomp);
+
+int crypto_unregister_acomp(struct acomp_alg *alg)
+{
+ return crypto_unregister_alg(&alg->base);
+}
+EXPORT_SYMBOL_GPL(crypto_unregister_acomp);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Asynchronous compression type");
diff --git a/crypto/scompress.c b/crypto/scompress.c
index 7c9955b..e5ebf24 100644
--- a/crypto/scompress.c
+++ b/crypto/scompress.c
@@ -24,8 +24,12 @@
#include <linux/module.h>
#include <linux/seq_file.h>
#include <linux/cryptouser.h>
+#include <linux/vmalloc.h>
+#include <linux/highmem.h>
+#include <linux/gfp.h>
#include <crypto/compress.h>
+#include <crypto/scatterwalk.h>
#include <net/netlink.h>
#include "internal.h"
@@ -90,6 +94,172 @@ struct crypto_scomp *crypto_alloc_scomp(const char *alg_name, u32 type,
}
EXPORT_SYMBOL_GPL(crypto_alloc_scomp);
+static void *scomp_map(struct scatterlist *sg, unsigned int len)
+{
+ gfp_t gfp_flags;
+ void *buf;
+
+ if (sg_is_last(sg))
+ return kmap_atomic(sg_page(sg)) + sg->offset;
+
+ if (in_atomic() || irqs_disabled())
+ gfp_flags = GFP_ATOMIC;
+ else
+ gfp_flags = GFP_KERNEL;
+
+ buf = kmalloc(len, gfp_flags);
+ if (!buf)
+ return NULL;
+
+ scatterwalk_map_and_copy(buf, sg, 0, len, 0);
+
+ return buf;
+}
+
+static void scomp_unmap(struct scatterlist *sg, void *buf, unsigned int len)
+{
+ if (!buf)
+ return;
+
+ if (sg_is_last(sg)) {
+ kunmap_atomic(buf);
+ return;
+ }
+
+ scatterwalk_map_and_copy(buf, sg, 0, len, 1);
+ kfree(buf);
+}
+
+static int scomp_acomp_compress(struct acomp_req *req,
+ struct crypto_acomp *tfm)
+{
+ int ret;
+ void **tfm_ctx = crypto_acomp_ctx(tfm);
+ struct crypto_scomp *scomp = (struct crypto_scomp *)*tfm_ctx;
+ void *ctx = *(req->__ctx);
+ char *src = scomp_map(req->src, req->src_len);
+ char *dst = scomp_map(req->dst, req->dst_len);
+
+ if (!src || !dst) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ req->out_len = req->dst_len;
+ ret = crypto_scomp_compress(scomp, src, req->src_len,
+ dst, &req->out_len, ctx);
+
+out:
+ scomp_unmap(req->src, src, 0);
+ scomp_unmap(req->dst, dst, ret ? 0 : req->out_len);
+
+ return ret;
+}
+
+static int scomp_async_compress(struct acomp_req *req)
+{
+ return scomp_acomp_compress(req, crypto_acomp_reqtfm(req));
+}
+
+static int scomp_acomp_decompress(struct acomp_req *req,
+ struct crypto_acomp *tfm)
+{
+ int ret;
+ void **tfm_ctx = crypto_acomp_ctx(tfm);
+ struct crypto_scomp *scomp = (struct crypto_scomp *)*tfm_ctx;
+ void *ctx = *(req->__ctx);
+ char *src = scomp_map(req->src, req->src_len);
+ char *dst = scomp_map(req->dst, req->dst_len);
+
+ if (!src || !dst) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ req->out_len = req->dst_len;
+ ret = crypto_scomp_decompress(scomp, src, req->src_len,
+ dst, &req->out_len, ctx);
+
+out:
+ scomp_unmap(req->src, src, 0);
+ scomp_unmap(req->dst, dst, ret ? 0 : req->out_len);
+
+ return ret;
+}
+
+static int scomp_async_decompress(struct acomp_req *req)
+{
+ return scomp_acomp_decompress(req, crypto_acomp_reqtfm(req));
+}
+
+static void crypto_exit_scomp_ops_async(struct crypto_tfm *tfm)
+{
+ struct crypto_scomp **ctx = crypto_tfm_ctx(tfm);
+
+ crypto_free_scomp(*ctx);
+}
+
+int crypto_init_scomp_ops_async(struct crypto_tfm *tfm)
+{
+ struct crypto_alg *calg = tfm->__crt_alg;
+ struct crypto_acomp *acomp = __crypto_acomp_tfm(tfm);
+ struct crypto_scomp *scomp;
+ void **ctx = crypto_tfm_ctx(tfm);
+
+ if (!crypto_mod_get(calg))
+ return -EAGAIN;
+
+ scomp = crypto_create_tfm(calg, &crypto_scomp_type);
+ if (IS_ERR(scomp)) {
+ crypto_mod_put(calg);
+ return PTR_ERR(scomp);
+ }
+
+ *ctx = scomp;
+ tfm->exit = crypto_exit_scomp_ops_async;
+
+ acomp->compress = scomp_async_compress;
+ acomp->decompress = scomp_async_decompress;
+ acomp->reqsize = sizeof(void *);
+
+ return 0;
+}
+
+struct acomp_req *crypto_scomp_acomp_request_alloc(struct crypto_acomp *tfm,
+ gfp_t gfp)
+{
+ void **tfm_ctx = crypto_acomp_ctx(tfm);
+ struct crypto_scomp *scomp = (struct crypto_scomp *)*tfm_ctx;
+ struct acomp_req *req;
+ void *ctx;
+
+ req = kzalloc(sizeof(*req) + crypto_acomp_reqsize(tfm), gfp);
+ if (!req)
+ return NULL;
+
+ ctx = crypto_scomp_alloc_ctx(scomp);
+ if (IS_ERR(ctx)) {
+ kfree(req);
+ return NULL;
+ }
+
+ *(req->__ctx) = ctx;
+ acomp_request_set_tfm(req, tfm);
+
+ return req;
+}
+
+void crypto_scomp_acomp_request_free(struct acomp_req *req)
+{
+ struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
+ void **tfm_ctx = crypto_acomp_ctx(tfm);
+ struct crypto_scomp *scomp = (struct crypto_scomp *)*tfm_ctx;
+ void *ctx = *(req->__ctx);
+
+ crypto_scomp_free_ctx(scomp, ctx);
+ kfree(req);
+}
+
int crypto_register_scomp(struct scomp_alg *alg)
{
struct crypto_alg *base = &alg->base;
diff --git a/include/crypto/compress.h b/include/crypto/compress.h
index e4053fc..5b6332d 100644
--- a/include/crypto/compress.h
+++ b/include/crypto/compress.h
@@ -90,4 +90,257 @@ static inline bool crypto_scomp_decomp_noctx(struct crypto_scomp *tfm)
extern int crypto_register_scomp(struct scomp_alg *alg);
extern int crypto_unregister_scomp(struct scomp_alg *alg);
+
+/**
+ * struct acomp_req - asynchronous compression request
+ *
+ * @base: Common attributes for async crypto requests
+ * @src: Pointer to memory containing the input scatterlist buffer
+ * @dst: Pointer to memory containing the output scatterlist buffer
+ * @src_len: Length of input buffer
+ * @dst_len: Length of output buffer
+ * @out_len: Number of bytes produced by (de)compressor
+ * @__ctx: Start of private context data
+ */
+struct acomp_req {
+ struct crypto_async_request base;
+ struct scatterlist *src;
+ struct scatterlist *dst;
+ unsigned int src_len;
+ unsigned int dst_len;
+ unsigned int out_len;
+ void *__ctx[] CRYPTO_MINALIGN_ATTR;
+};
+
+/**
+ * struct crypto_acomp - user-instantiated objects which encapsulate
+ * algorithms and core processing logic
+ *
+ * @compress: Function performs a compress operation
+ * @decompress: Function performs a de-compress operation
+ * @reqsize: Request size required by algorithm implementation
+ * @base: Common crypto API algorithm data structure
+ */
+struct crypto_acomp {
+ int (*compress)(struct acomp_req *req);
+ int (*decompress)(struct acomp_req *req);
+ unsigned int reqsize;
+ struct crypto_tfm base;
+};
+
+/**
+ * struct acomp_alg - async compression algorithm
+ *
+ * @compress: Function performs a compress operation
+ * @decompress: Function performs a de-compress operation
+ * @init: Initialize the cryptographic transformation object.
+ * This function is used to initialize the cryptographic
+ * transformation object. This function is called only once at
+ * the instantiation time, right after the transformation context
+ * was allocated. In case the cryptographic hardware has some
+ * special requirements which need to be handled by software, this
+ * function shall check for the precise requirement of the
+ * transformation and put any software fallbacks in place.
+ * @exit: Deinitialize the cryptographic transformation object. This is a
+ * counterpart to @init, used to remove various changes set in
+ * @init.
+ *
+ * @base: Common crypto API algorithm data structure
+ */
+struct acomp_alg {
+ int (*compress)(struct acomp_req *req);
+ int (*decompress)(struct acomp_req *req);
+ int (*init)(struct crypto_acomp *tfm);
+ void (*exit)(struct crypto_acomp *tfm);
+ struct crypto_alg base;
+};
+
+/**
+ * DOC: Asynchronous Compression API
+ *
+ * The Asynchronous Compression API is used with the algorithms of type
+ * CRYPTO_ALG_TYPE_ACOMPRESS (listed as type "acomp" in /proc/crypto)
+ */
+
+/**
+ * crypto_alloc_acompress() -- allocate ACOMPRESS tfm handle
+ * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
+ * compression algorithm e.g. "deflate"
+ * @type: specifies the type of the algorithm
+ * @mask: specifies the mask for the algorithm
+ *
+ * Allocate a handle for compression algorithm. The returned struct
+ * crypto_acomp is the handle that is required for any subsequent
+ * API invocation for the compression operations.
+ *
+ * Return: allocated handle in case of success; IS_ERR() is true in case
+ * of an error, PTR_ERR() returns the error code.
+ */
+struct crypto_acomp *crypto_alloc_acomp(const char *alg_name, u32 type,
+ u32 mask);
+
+static inline struct crypto_tfm *crypto_acomp_tfm(struct crypto_acomp *tfm)
+{
+ return &tfm->base;
+}
+
+static inline struct crypto_acomp *crypto_acomp_cast(struct crypto_tfm *tfm)
+{
+ return (struct crypto_acomp *)tfm;
+}
+
+static inline void *crypto_acomp_ctx(struct crypto_acomp *tfm)
+{
+ return crypto_tfm_ctx(crypto_acomp_tfm(tfm));
+}
+
+static inline struct acomp_alg *__crypto_acomp_alg(struct crypto_alg *alg)
+{
+ return container_of(alg, struct acomp_alg, base);
+}
+
+static inline struct crypto_acomp *__crypto_acomp_tfm(
+ struct crypto_tfm *tfm)
+{
+ return container_of(tfm, struct crypto_acomp, base);
+}
+
+static inline struct acomp_alg *crypto_acomp_alg(
+ struct crypto_acomp *tfm)
+{
+ return __crypto_acomp_alg(crypto_acomp_tfm(tfm)->__crt_alg);
+}
+
+static inline unsigned int crypto_acomp_reqsize(struct crypto_acomp *tfm)
+{
+ return tfm->reqsize;
+}
+
+static inline void acomp_request_set_tfm(struct acomp_req *req,
+ struct crypto_acomp *tfm)
+{
+ req->base.tfm = crypto_acomp_tfm(tfm);
+}
+
+static inline struct crypto_acomp *crypto_acomp_reqtfm(
+ struct acomp_req *req)
+{
+ return __crypto_acomp_tfm(req->base.tfm);
+}
+
+/**
+ * crypto_free_acomp() -- free ACOMPRESS tfm handle
+ *
+ * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acompr()
+ */
+static inline void crypto_free_acomp(struct crypto_acomp *tfm)
+{
+ crypto_destroy_tfm(tfm, crypto_acomp_tfm(tfm));
+}
+
+static inline int crypto_has_acomp(const char *alg_name, u32 type, u32 mask)
+{
+ type &= ~CRYPTO_ALG_TYPE_MASK;
+ type |= CRYPTO_ALG_TYPE_ACOMPRESS;
+ mask |= CRYPTO_ALG_TYPE_MASK;
+
+ return crypto_has_alg(alg_name, type, mask);
+}
+
+/**
+ * acomp_request_alloc() -- allocates async compress request
+ *
+ * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acomp()
+ * @gfp: allocation flags
+ *
+ * Return: allocated handle in case of success or NULL in case of an error.
+ */
+struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp,
+ gfp_t gfp);
+
+/**
+ * acomp_request_free() -- zeroize and free async compress request
+ *
+ * @req: request to free
+ */
+void acomp_request_free(struct acomp_req *acomp);
+
+/**
+ * acomp_request_set_callback() -- Sets an asynchronous callback.
+ *
+ * Callback will be called when an asynchronous operation on a given
+ * request is finished.
+ *
+ * @req: request that the callback will be set for
+ * @flgs: specify for instance if the operation may backlog
+ * @cmlp: callback which will be called
+ * @data: private data used by the caller
+ */
+static inline void acomp_request_set_callback(struct acomp_req *req, u32 flgs,
+ crypto_completion_t cmpl, void *data)
+{
+ req->base.complete = cmpl;
+ req->base.data = data;
+ req->base.flags = flgs;
+}
+
+/**
+ * acomp_request_set_comp() -- Sets reqest parameters
+ *
+ * Sets parameters required by acomp operation
+ *
+ * @req: async compress request
+ * @src: ptr to input buffer list
+ * @dst: ptr to output buffer list
+ * @src_len: size of the input buffer
+ * @dst_len: size of the output buffer
+ * @result: (de)compression result returned by compressor
+ */
+static inline void acomp_request_set_comp(struct acomp_req *req,
+ struct scatterlist *src,
+ struct scatterlist *dst,
+ unsigned int src_len,
+ unsigned int dst_len)
+{
+ req->src = src;
+ req->dst = dst;
+ req->src_len = src_len;
+ req->dst_len = dst_len;
+ req->out_len = 0;
+}
+
+/**
+ * crypto_acomp_compress() -- Invoke async compress operation
+ *
+ * Function invokes the async compress operation
+ *
+ * @req: async compress request
+ *
+ * Return: zero on success; error code in case of error
+ */
+static inline int crypto_acomp_compress(struct acomp_req *req)
+{
+ struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
+
+ return tfm->compress(req);
+}
+
+/**
+ * crypto_acomp_decompress() -- Invoke async decompress operation
+ *
+ * Function invokes the async decompress operation
+ *
+ * @req: async compress request
+ *
+ * Return: zero on success; error code in case of error
+ */
+static inline int crypto_acomp_decompress(struct acomp_req *req)
+{
+ struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
+
+ return tfm->decompress(req);
+}
+
+extern int crypto_register_acomp(struct acomp_alg *alg);
+extern int crypto_unregister_acomp(struct acomp_alg *alg);
#endif
diff --git a/include/crypto/internal/compress.h b/include/crypto/internal/compress.h
new file mode 100644
index 0000000..088bc5b
--- /dev/null
+++ b/include/crypto/internal/compress.h
@@ -0,0 +1,4 @@
+extern int crypto_init_scomp_ops_async(struct crypto_tfm *tfm);
+extern struct acomp_req *
+crypto_scomp_acomp_request_alloc(struct crypto_acomp *tfm, gfp_t gfp);
+extern void crypto_scomp_acomp_request_free(struct acomp_req *req);
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index ba73c18..ccd1d32 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -55,9 +55,11 @@
#define CRYPTO_ALG_TYPE_RNG 0x0000000c
#define CRYPTO_ALG_TYPE_AKCIPHER 0x0000000d
#define CRYPTO_ALG_TYPE_SCOMPRESS 0x0000000e
+#define CRYPTO_ALG_TYPE_ACOMPRESS 0x0000000f
#define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
#define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000c
+#define CRYPTO_ALG_TYPE_ACOMPRESS_MASK 0x0000000e
#define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c
#define CRYPTO_ALG_LARVAL 0x00000010
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Herbert Xu <herbert@gondor.apana.org.au> |
|---|---|
| Date | 2016-01-27 08:50 +0100 |
| Subject | Re: [PATCH v2 04/10] crypto/compress: add asynchronous compression support |
| Message-ID | <qVt1w-7Z-13@gated-at.bofh.it> |
| In reply to | #1317614 |
On Tue, Jan 26, 2016 at 05:15:06PM +0900, Joonsoo Kim wrote: > From: Weigang Li <weigang.li@intel.com> > > Now, asynchronous compression APIs are supported. There is no asynchronous > compression driver now but this APIs can be used as front-end to > synchronous compression algorithm. In this case, scatterlist would be > linearlized when needed so it would cause some overhead. > > Signed-off-by: Weigang Li <weigang.li@intel.com> > Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> I think we should be able to use this for the synchronous case too, like we do with skcipher and ahash. The main difference that I can see right now is that acomp always allocates a context through the request object while scomp does not. This difference is entirely artificial as we could also make the context conditional for acomp. The reason we had the shash/ahash division is because the shash interface offers a direct pointer interface while ahash is SG-based. Otherwise ahash is just as able as shash to handle synchronous requests. At this point in time I don't see such a fundamental distinction between acomp and scomp. Cheers, -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
[toc] | [prev] | [next] | [standalone]
| From | "Li, Weigang" <weigang.li@intel.com> |
|---|---|
| Date | 2016-01-27 09:00 +0100 |
| Subject | Re: [PATCH v2 04/10] crypto/compress: add asynchronous compression support |
| Message-ID | <qVtbd-cl-13@gated-at.bofh.it> |
| In reply to | #1318732 |
On 1/27/2016 3:41 PM, Herbert Xu wrote: > On Tue, Jan 26, 2016 at 05:15:06PM +0900, Joonsoo Kim wrote: >> From: Weigang Li <weigang.li@intel.com> >> >> Now, asynchronous compression APIs are supported. There is no asynchronous >> compression driver now but this APIs can be used as front-end to >> synchronous compression algorithm. In this case, scatterlist would be >> linearlized when needed so it would cause some overhead. >> >> Signed-off-by: Weigang Li <weigang.li@intel.com> >> Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> > > I think we should be able to use this for the synchronous case > too, like we do with skcipher and ahash. > > The main difference that I can see right now is that acomp always > allocates a context through the request object while scomp does not. > > This difference is entirely artificial as we could also make the > context conditional for acomp. > > The reason we had the shash/ahash division is because the shash > interface offers a direct pointer interface while ahash is SG-based. > Otherwise ahash is just as able as shash to handle synchronous > requests. > > At this point in time I don't see such a fundamental distinction > between acomp and scomp. > > Cheers, > The acomp is also SG-based, while scomp only accepts flat buffer.
[toc] | [prev] | [next] | [standalone]
| From | Herbert Xu <herbert@gondor.apana.org.au> |
|---|---|
| Date | 2016-01-27 09:10 +0100 |
| Subject | Re: [PATCH v2 04/10] crypto/compress: add asynchronous compression support |
| Message-ID | <qVtkR-wF-9@gated-at.bofh.it> |
| In reply to | #1318737 |
On Wed, Jan 27, 2016 at 03:59:05PM +0800, Li, Weigang wrote: > > The acomp is also SG-based, while scomp only accepts flat buffer. Right, but do we need a pointer-based scomp at all? IPComp would certainly be better off with an SG-based interface. Any other users of compression are presumably dealing with large amounts of data where an SG interface would make more sense. A pointer interface makes sense for shash because you may be hashing 16 bytes at a time. Nobody sane is going to be compressing 16 bytes, or are they? Cheers, -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
[toc] | [prev] | [next] | [standalone]
| From | Herbert Xu <herbert@gondor.apana.org.au> |
|---|---|
| Date | 2016-01-27 09:10 +0100 |
| Subject | Re: [PATCH v2 04/10] crypto/compress: add asynchronous compression support |
| Message-ID | <qVtkS-wF-17@gated-at.bofh.it> |
| In reply to | #1318740 |
On Wed, Jan 27, 2016 at 04:03:55PM +0800, Herbert Xu wrote: > On Wed, Jan 27, 2016 at 03:59:05PM +0800, Li, Weigang wrote: > > > > The acomp is also SG-based, while scomp only accepts flat buffer. > > Right, but do we need a pointer-based scomp at all? IPComp would > certainly be better off with an SG-based interface. Any other > users of compression are presumably dealing with large amounts > of data where an SG interface would make more sense. > > A pointer interface makes sense for shash because you may be hashing > 16 bytes at a time. Nobody sane is going to be compressing 16 bytes, > or are they? Note that I'm fine with keeping an scomp interface underneath for those algorithms where the best way to handle SG input is to linearise things. But I would prefer that this interface is not exposed to kernel users unless it is absolutely required. Cheers, -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
[toc] | [prev] | [next] | [standalone]
| From | "Li, Weigang" <weigang.li@intel.com> |
|---|---|
| Date | 2016-01-27 09:30 +0100 |
| Subject | Re: [PATCH v2 04/10] crypto/compress: add asynchronous compression support |
| Message-ID | <qVtEd-DF-1@gated-at.bofh.it> |
| In reply to | #1318741 |
On 1/27/2016 4:09 PM, Herbert Xu wrote: > On Wed, Jan 27, 2016 at 04:03:55PM +0800, Herbert Xu wrote: >> On Wed, Jan 27, 2016 at 03:59:05PM +0800, Li, Weigang wrote: >>> >>> The acomp is also SG-based, while scomp only accepts flat buffer. >> >> Right, but do we need a pointer-based scomp at all? IPComp would >> certainly be better off with an SG-based interface. Any other >> users of compression are presumably dealing with large amounts >> of data where an SG interface would make more sense. >> >> A pointer interface makes sense for shash because you may be hashing >> 16 bytes at a time. Nobody sane is going to be compressing 16 bytes, >> or are they? > > Note that I'm fine with keeping an scomp interface underneath > for those algorithms where the best way to handle SG input is > to linearise things. But I would prefer that this interface is > not exposed to kernel users unless it is absolutely required. > > Cheers, > Thanks for your comments, Herbert. I Agree, SG-list based compression API makes more sense. Maybe Joonsoo can comment on this.
[toc] | [prev] | [next] | [standalone]
| From | Joonsoo Kim <js1304@gmail.com> |
|---|---|
| Date | 2016-01-26 09:20 +0100 |
| Subject | [PATCH v2 03/10] crypto/compress: introduce sychronuous compression API |
| Message-ID | <qV711-1ma-29@gated-at.bofh.it> |
| In reply to | #1317610 |
This introduces new compression APIs. Major change is that APIs are
stateless. Instead of previous implementation, tfm objects doesn't
embedded any context so we can de/compress concurrently with one tfm
object. Instead, this de/compression context is coupled with the request.
This architecture change will make APIs more flexible and we can naturally
use asynchronous APIs as front-end of synchronous compression algorithm.
Moreover, thanks to this change, we can decompress without context buffer
if algorithm supports it. You can check it by crypto_scomp_decomp_noctx()
and in this case we can achieve maximum parallelism without
memory overhead caused by context buffer.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
crypto/Kconfig | 5 ++
crypto/Makefile | 1 +
crypto/scompress.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++
include/crypto/compress.h | 93 +++++++++++++++++++++++++++++++++++++
include/linux/crypto.h | 1 +
5 files changed, 214 insertions(+)
create mode 100644 crypto/scompress.c
create mode 100644 include/crypto/compress.h
diff --git a/crypto/Kconfig b/crypto/Kconfig
index c80d34f..7159520 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -84,6 +84,10 @@ config CRYPTO_RNG_DEFAULT
tristate
select CRYPTO_DRBG_MENU
+config CRYPTO_SCOMPRESS
+ tristate
+ select CRYPTO_ALGAPI2
+
config CRYPTO_AKCIPHER2
tristate
select CRYPTO_ALGAPI2
@@ -1499,6 +1503,7 @@ config CRYPTO_LZO
select CRYPTO_ALGAPI
select LZO_COMPRESS
select LZO_DECOMPRESS
+ select SCOMPRESS
help
This is the LZO algorithm.
diff --git a/crypto/Makefile b/crypto/Makefile
index ffe18c9..16ef796 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -28,6 +28,7 @@ crypto_hash-y += ahash.o
crypto_hash-y += shash.o
obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o
+obj-$(CONFIG_CRYPTO_SCOMPRESS) += scompress.o
obj-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o
$(obj)/rsapubkey-asn1.o: $(obj)/rsapubkey-asn1.c $(obj)/rsapubkey-asn1.h
diff --git a/crypto/scompress.c b/crypto/scompress.c
new file mode 100644
index 0000000..7c9955b
--- /dev/null
+++ b/crypto/scompress.c
@@ -0,0 +1,114 @@
+/*
+ * Cryptographic API.
+ *
+ * Synchronous compression operations.
+ *
+ * Copyright 2015 LG Electronics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/crypto.h>
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/seq_file.h>
+#include <linux/cryptouser.h>
+
+#include <crypto/compress.h>
+#include <net/netlink.h>
+
+#include "internal.h"
+
+
+static int crypto_scomp_init(struct crypto_tfm *tfm, u32 type, u32 mask)
+{
+ return 0;
+}
+
+static int crypto_scomp_init_tfm(struct crypto_tfm *tfm)
+{
+ return 0;
+}
+
+#ifdef CONFIG_NET
+static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+ struct crypto_report_comp rcomp;
+
+ strncpy(rcomp.type, "scomp", sizeof(rcomp.type));
+ if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
+ sizeof(struct crypto_report_comp), &rcomp))
+ goto nla_put_failure;
+ return 0;
+
+nla_put_failure:
+ return -EMSGSIZE;
+}
+#else
+static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+ return -ENOSYS;
+}
+#endif
+
+static void crypto_scomp_show(struct seq_file *m, struct crypto_alg *alg)
+ __attribute__ ((unused));
+static void crypto_scomp_show(struct seq_file *m, struct crypto_alg *alg)
+{
+ seq_puts(m, "type : scomp\n");
+}
+
+static const struct crypto_type crypto_scomp_type = {
+ .extsize = crypto_alg_extsize,
+ .init = crypto_scomp_init,
+ .init_tfm = crypto_scomp_init_tfm,
+#ifdef CONFIG_PROC_FS
+ .show = crypto_scomp_show,
+#endif
+ .report = crypto_scomp_report,
+ .maskclear = ~CRYPTO_ALG_TYPE_MASK,
+ .maskset = CRYPTO_ALG_TYPE_MASK,
+ .type = CRYPTO_ALG_TYPE_SCOMPRESS,
+ .tfmsize = offsetof(struct crypto_scomp, base),
+};
+
+struct crypto_scomp *crypto_alloc_scomp(const char *alg_name, u32 type,
+ u32 mask)
+{
+ return crypto_alloc_tfm(alg_name, &crypto_scomp_type, type, mask);
+}
+EXPORT_SYMBOL_GPL(crypto_alloc_scomp);
+
+int crypto_register_scomp(struct scomp_alg *alg)
+{
+ struct crypto_alg *base = &alg->base;
+
+ base->cra_type = &crypto_scomp_type;
+ base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
+ base->cra_flags |= CRYPTO_ALG_TYPE_SCOMPRESS;
+
+ return crypto_register_alg(base);
+}
+EXPORT_SYMBOL_GPL(crypto_register_scomp);
+
+int crypto_unregister_scomp(struct scomp_alg *alg)
+{
+ return crypto_unregister_alg(&alg->base);
+}
+EXPORT_SYMBOL_GPL(crypto_unregister_scomp);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Synchronous compression operations");
+MODULE_AUTHOR("LG Electronics Inc.");
+
diff --git a/include/crypto/compress.h b/include/crypto/compress.h
new file mode 100644
index 0000000..e4053fc
--- /dev/null
+++ b/include/crypto/compress.h
@@ -0,0 +1,93 @@
+#ifndef _CRYPTO_COMPRESS_H
+#define _CRYPTO_COMPRESS_H
+#include <linux/crypto.h>
+
+#define CRYPTO_SCOMP_DECOMP_NOCTX CRYPTO_ALG_PRIVATE
+
+struct crypto_scomp {
+ struct crypto_tfm base;
+};
+
+struct scomp_alg {
+ void *(*alloc_ctx)(struct crypto_scomp *tfm);
+ void (*free_ctx)(struct crypto_scomp *tfm, void *ctx);
+ int (*compress)(struct crypto_scomp *tfm, const u8 *src,
+ unsigned int slen, u8 *dst, unsigned int *dlen, void *ctx);
+ int (*decompress)(struct crypto_scomp *tfm, const u8 *src,
+ unsigned int slen, u8 *dst, unsigned int *dlen, void *ctx);
+
+ struct crypto_alg base;
+};
+
+extern struct crypto_scomp *crypto_alloc_scomp(const char *alg_name, u32 type,
+ u32 mask);
+
+static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm)
+{
+ return &tfm->base;
+}
+
+static inline struct crypto_scomp *crypto_scomp_cast(struct crypto_tfm *tfm)
+{
+ return (struct crypto_scomp *)tfm;
+}
+
+static inline void crypto_free_scomp(struct crypto_scomp *tfm)
+{
+ crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm));
+}
+
+static inline int crypto_has_scomp(const char *alg_name, u32 type, u32 mask)
+{
+ type &= ~CRYPTO_ALG_TYPE_MASK;
+ type |= CRYPTO_ALG_TYPE_SCOMPRESS;
+ mask |= CRYPTO_ALG_TYPE_MASK;
+
+ return crypto_has_alg(alg_name, type, mask);
+}
+
+static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg)
+{
+ return container_of(alg, struct scomp_alg, base);
+}
+
+static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm)
+{
+ return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg);
+}
+
+static inline void *crypto_scomp_alloc_ctx(struct crypto_scomp *tfm)
+{
+ return crypto_scomp_alg(tfm)->alloc_ctx(tfm);
+}
+
+static inline void crypto_scomp_free_ctx(struct crypto_scomp *tfm,
+ void *ctx)
+{
+ return crypto_scomp_alg(tfm)->free_ctx(tfm, ctx);
+}
+
+static inline int crypto_scomp_compress(struct crypto_scomp *tfm,
+ const u8 *src, unsigned int slen,
+ u8 *dst, unsigned int *dlen, void *ctx)
+{
+ return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx);
+}
+
+static inline int crypto_scomp_decompress(struct crypto_scomp *tfm,
+ const u8 *src, unsigned int slen,
+ u8 *dst, unsigned int *dlen, void *ctx)
+{
+ return crypto_scomp_alg(tfm)->decompress(tfm, src, slen,
+ dst, dlen, ctx);
+}
+
+static inline bool crypto_scomp_decomp_noctx(struct crypto_scomp *tfm)
+{
+ return crypto_scomp_tfm(tfm)->__crt_alg->cra_flags &
+ CRYPTO_SCOMP_DECOMP_NOCTX;
+}
+
+extern int crypto_register_scomp(struct scomp_alg *alg);
+extern int crypto_unregister_scomp(struct scomp_alg *alg);
+#endif
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 96530a1..ba73c18 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -54,6 +54,7 @@
#define CRYPTO_ALG_TYPE_AHASH 0x0000000a
#define CRYPTO_ALG_TYPE_RNG 0x0000000c
#define CRYPTO_ALG_TYPE_AKCIPHER 0x0000000d
+#define CRYPTO_ALG_TYPE_SCOMPRESS 0x0000000e
#define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
#define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000c
--
1.9.1
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web