From patchwork Tue May 31 13:55:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 9144881 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5126F60761 for ; Tue, 31 May 2016 13:55:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4256F2793B for ; Tue, 31 May 2016 13:55:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3705B27BF0; Tue, 31 May 2016 13:55:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB0A62796F for ; Tue, 31 May 2016 13:55:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753676AbcEaNzu (ORCPT ); Tue, 31 May 2016 09:55:50 -0400 Received: from mga04.intel.com ([192.55.52.120]:2582 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753893AbcEaNzs (ORCPT ); Tue, 31 May 2016 09:55:48 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP; 31 May 2016 06:55:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,395,1459839600"; d="scan'208";a="113436198" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga004.fm.intel.com with ESMTP; 31 May 2016 06:55:47 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id u4VDtjri021984; Tue, 31 May 2016 14:55:45 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id u4VDtj7v028196; Tue, 31 May 2016 14:55:45 +0100 Received: (from gcabiddu@localhost) by sivswdev01.ir.intel.com with id u4VDtikv028192; Tue, 31 May 2016 14:55:44 +0100 From: Giovanni Cabiddu To: herbert@gondor.apana.org.au Cc: linux-crypto@vger.kernel.org, Giovanni Cabiddu Subject: [PATCH v4 04/10] crypto: add quick decompression api Date: Tue, 31 May 2016 14:55:30 +0100 Message-Id: <1464702936-27627-5-git-send-email-giovanni.cabiddu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1464702936-27627-1-git-send-email-giovanni.cabiddu@intel.com> References: <1464702936-27627-1-git-send-email-giovanni.cabiddu@intel.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces qdecomp, an asynchronous decompression api. qdecomp is a front-end for acomp and scomp algorithms which do not not need additional vmalloc work space for decompression. Signed-off-by: Giovanni Cabiddu --- crypto/Makefile | 1 + crypto/acompress.c | 50 ++++++++- crypto/qdecompress.c | 93 +++++++++++++++ crypto/scompress.c | 92 +++++++++++++++- include/crypto/internal/acompress.h | 15 +++ include/crypto/internal/qdecompress.h | 22 ++++ include/crypto/internal/scompress.h | 14 +++ include/crypto/qdecompress.h | 204 +++++++++++++++++++++++++++++++++ include/linux/crypto.h | 4 + 9 files changed, 491 insertions(+), 4 deletions(-) create mode 100644 crypto/qdecompress.c create mode 100644 include/crypto/internal/qdecompress.h create mode 100644 include/crypto/qdecompress.h diff --git a/crypto/Makefile b/crypto/Makefile index fc8fcfe..2621451 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o obj-$(CONFIG_CRYPTO_ACOMP2) += acompress.o obj-$(CONFIG_CRYPTO_ACOMP2) += scompress.o +obj-$(CONFIG_CRYPTO_ACOMP2) += qdecompress.o $(obj)/rsapubkey-asn1.o: $(obj)/rsapubkey-asn1.c $(obj)/rsapubkey-asn1.h $(obj)/rsaprivkey-asn1.o: $(obj)/rsaprivkey-asn1.c $(obj)/rsaprivkey-asn1.h diff --git a/crypto/acompress.c b/crypto/acompress.c index 885d15d..dcc9ddc 100644 --- a/crypto/acompress.c +++ b/crypto/acompress.c @@ -23,9 +23,10 @@ #include #include #include +#include #include "internal.h" -static const struct crypto_type crypto_acomp_type; +const struct crypto_type crypto_acomp_type; #ifdef CONFIG_NET static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg) @@ -96,7 +97,39 @@ unsigned int crypto_acomp_extsize(struct crypto_alg *alg) return extsize; } -static const struct crypto_type crypto_acomp_type = { +static void crypto_exit_acomp_ops_nospace(struct crypto_tfm *tfm) +{ + struct crypto_tfm **ctx = crypto_tfm_ctx(tfm); + struct crypto_acomp *acomp = __crypto_acomp_tfm(*ctx); + + crypto_free_acomp(acomp); + *ctx = NULL; +} + +int crypto_init_acomp_ops_nospace(struct crypto_tfm *tfm) +{ + struct crypto_alg *calg = tfm->__crt_alg; + struct crypto_qdecomp *crt = __crypto_qdecomp_tfm(tfm); + struct crypto_tfm **ctx = crypto_tfm_ctx(tfm); + struct crypto_acomp *acomp; + + if (!crypto_mod_get(calg)) + return -EAGAIN; + + acomp = crypto_create_tfm(calg, &crypto_acomp_type); + if (IS_ERR(acomp)) { + crypto_mod_put(calg); + return PTR_ERR(acomp); + } + + *ctx = &acomp->base; + tfm->exit = crypto_exit_acomp_ops_nospace; + crt->decompress = (int (*)(struct qdecomp_req *req))acomp->decompress; + + return 0; +} + +const struct crypto_type crypto_acomp_type = { .extsize = crypto_acomp_extsize, .init_tfm = crypto_acomp_init_tfm, #ifdef CONFIG_PROC_FS @@ -108,6 +141,7 @@ static const struct crypto_type crypto_acomp_type = { .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) @@ -153,6 +187,18 @@ int crypto_register_acomp(struct acomp_alg *alg) } EXPORT_SYMBOL_GPL(crypto_register_acomp); +int crypto_register_acomp_qdecomp(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_QDCMP; + + return crypto_register_alg(base); +} +EXPORT_SYMBOL_GPL(crypto_register_acomp_qdecomp); + int crypto_unregister_acomp(struct acomp_alg *alg) { return crypto_unregister_alg(&alg->base); diff --git a/crypto/qdecompress.c b/crypto/qdecompress.c new file mode 100644 index 0000000..f229016 --- /dev/null +++ b/crypto/qdecompress.c @@ -0,0 +1,93 @@ +/* + * Quick Decompression operations + * + * Copyright (c) 2016, Intel Corporation + * Authors: Giovanni Cabiddu + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "internal.h" + +#ifdef CONFIG_NET +static int crypto_qdecomp_report(struct sk_buff *skb, struct crypto_alg *alg) +{ + struct crypto_report_comp rqdecomp; + + strncpy(rqdecomp.type, "qdecomp", sizeof(rqdecomp.type)); + + if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS, + sizeof(struct crypto_report_comp), &rqdecomp)) + goto nla_put_failure; + return 0; + +nla_put_failure: + return -EMSGSIZE; +} +#else +static int crypto_qdecomp_report(struct sk_buff *skb, struct crypto_alg *alg) +{ + return -ENOSYS; +} +#endif + +static void crypto_qdecomp_show(struct seq_file *m, struct crypto_alg *alg) + __attribute__ ((unused)); + +static void crypto_qdecomp_show(struct seq_file *m, struct crypto_alg *alg) +{ + seq_puts(m, "type : qdecomp\n"); +} + +static int crypto_qdecomp_init_tfm(struct crypto_tfm *tfm) +{ + if (tfm->__crt_alg->cra_type == &crypto_scomp_type) + return crypto_init_scomp_ops_nospace(tfm); + else if (tfm->__crt_alg->cra_type == &crypto_acomp_type) + return crypto_init_acomp_ops_nospace(tfm); + else + return -EINVAL; +} + +unsigned int crypto_qdecomp_extsize(struct crypto_alg *alg) +{ + if (alg->cra_type == &crypto_acomp_type) + return crypto_alg_extsize(alg); + return sizeof(struct crypto_scomp *); +} + +static const struct crypto_type crypto_qdecomp_type = { + .extsize = crypto_qdecomp_extsize, + .init_tfm = crypto_qdecomp_init_tfm, +#ifdef CONFIG_PROC_FS + .show = crypto_qdecomp_show, +#endif + .report = crypto_qdecomp_report, + .maskclear = ~CRYPTO_ALG_TYPE_MASK, + .maskset = CRYPTO_ALG_TYPE_QDECOMP_MASK, + .type = CRYPTO_ALG_TYPE_QDECOMPRESS, + .tfmsize = offsetof(struct crypto_qdecomp, base), +}; + +struct crypto_qdecomp *crypto_alloc_qdecomp(const char *alg_name, u32 type, + u32 mask) +{ + return crypto_alloc_tfm(alg_name, &crypto_qdecomp_type, type, mask); +} +EXPORT_SYMBOL_GPL(crypto_alloc_qdecomp); diff --git a/crypto/scompress.c b/crypto/scompress.c index 5a25e17..faecab8 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -24,9 +24,10 @@ #include #include #include +#include #include "internal.h" -static const struct crypto_type crypto_scomp_type; +const struct crypto_type crypto_scomp_type; #ifdef CONFIG_NET static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg) @@ -184,6 +185,80 @@ int crypto_init_scomp_ops_async(struct crypto_tfm *tfm) return 0; } +static int scomp_qdecomp_decompress(struct qdecomp_req *req) +{ + struct crypto_qdecomp *qdecomp = crypto_qdecomp_reqtfm(req); + struct crypto_tfm *tfm = crypto_qdecomp_tfm(qdecomp); + struct crypto_tfm **ctx = crypto_tfm_ctx(tfm); + struct crypto_scomp *scomp = __crypto_scomp_tfm(*ctx); + gfp_t gfp_flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? + GFP_KERNEL : GFP_ATOMIC; + unsigned int slen = req->slen; + unsigned int dlen = req->dlen; + u8 *src; + u8 *dst; + int ret; + + src = scomp_map(req->src, slen, gfp_flags); + if (!src) { + ret = -ENOMEM; + goto out; + } + + dst = scomp_map(req->dst, dlen, gfp_flags); + if (!dst) { + ret = -ENOMEM; + goto out; + } + + ret = crypto_scomp_decompress(scomp, src, slen, dst, &dlen, NULL); + +out: + if (ret < 0) { + req->consumed = 0; + req->produced = 0; + } else { + req->consumed = slen; + req->produced = dlen; + } + scomp_unmap(req->src, src, 0); + scomp_unmap(req->dst, dst, (ret < 0) ? 0 : dlen); + + return ret; +} + +static void crypto_exit_scomp_ops_nospace(struct crypto_tfm *tfm) +{ + struct crypto_tfm **ctx = crypto_tfm_ctx(tfm); + struct crypto_scomp *scomp = __crypto_scomp_tfm(*ctx); + + crypto_free_scomp(scomp); + *ctx = NULL; +} + +int crypto_init_scomp_ops_nospace(struct crypto_tfm *tfm) +{ + struct crypto_alg *calg = tfm->__crt_alg; + struct crypto_qdecomp *crt = __crypto_qdecomp_tfm(tfm); + struct crypto_tfm **ctx = crypto_tfm_ctx(tfm); + struct crypto_scomp *scomp; + + 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->base; + tfm->exit = crypto_exit_scomp_ops_nospace; + crt->decompress = scomp_qdecomp_decompress; + + return 0; +} + struct acomp_req *crypto_acomp_scomp_alloc_ctx(struct acomp_req *req) { struct crypto_acomp *acomp = crypto_acomp_reqtfm(req); @@ -215,7 +290,7 @@ void crypto_acomp_scomp_free_ctx(struct acomp_req *req) crypto_scomp_free_ctx(scomp, ctx); } -static const struct crypto_type crypto_scomp_type = { +const struct crypto_type crypto_scomp_type = { .extsize = crypto_alg_extsize, .init_tfm = crypto_scomp_init_tfm, #ifdef CONFIG_PROC_FS @@ -227,6 +302,7 @@ static const struct crypto_type crypto_scomp_type = { .type = CRYPTO_ALG_TYPE_SCOMPRESS, .tfmsize = offsetof(struct crypto_scomp, base), }; +EXPORT_SYMBOL_GPL(crypto_scomp_type); struct crypto_scomp *crypto_alloc_scomp(const char *alg_name, u32 type, u32 mask) @@ -247,6 +323,18 @@ int crypto_register_scomp(struct scomp_alg *alg) } EXPORT_SYMBOL_GPL(crypto_register_scomp); +int crypto_register_scomp_qdecomp(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_QDCMP; + + return crypto_register_alg(base); +} +EXPORT_SYMBOL_GPL(crypto_register_scomp_qdecomp); + int crypto_unregister_scomp(struct scomp_alg *alg) { return crypto_unregister_alg(&alg->base); diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h index e42ce28..238856e 100644 --- a/include/crypto/internal/acompress.h +++ b/include/crypto/internal/acompress.h @@ -55,6 +55,8 @@ static inline void __acomp_request_free(struct acomp_req *req) kzfree(req); } +int crypto_init_acomp_ops_nospace(struct crypto_tfm *tfm); + /** * crypto_register_acomp() -- Register asynchronous compression algorithm * @@ -68,6 +70,19 @@ static inline void __acomp_request_free(struct acomp_req *req) int crypto_register_acomp(struct acomp_alg *alg); /** + * crypto_register_acomp_qdecomp() -- Register asynchronous compression + * algorithm with support for qdecomp + * + * Function registers an implementation of an asynchronous + * compression algorithm that supports qdecomp + * + * @alg: algorithm definition + * + * Return: zero on success; error code in case of error + */ +int crypto_register_acomp_qdecomp(struct acomp_alg *alg); + +/** * crypto_unregister_acomp() -- Unregister asynchronous compression algorithm * * Function unregisters an implementation of an asynchronous diff --git a/include/crypto/internal/qdecompress.h b/include/crypto/internal/qdecompress.h new file mode 100644 index 0000000..ed3c2d8 --- /dev/null +++ b/include/crypto/internal/qdecompress.h @@ -0,0 +1,22 @@ +/* + * Quick Decompression operations + * + * Copyright (c) 2016, Intel Corporation + * Authors: Giovanni Cabiddu + * + * 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. + * + */ +#ifndef _CRYPTO_QDECOMP_INT_H +#define _CRYPTO_QDECOMP_INT_H + +#include +#include + +extern const struct crypto_type crypto_acomp_type; +extern const struct crypto_type crypto_scomp_type; + +#endif diff --git a/include/crypto/internal/scompress.h b/include/crypto/internal/scompress.h index a88fc8d..07f3162 100644 --- a/include/crypto/internal/scompress.h +++ b/include/crypto/internal/scompress.h @@ -104,6 +104,7 @@ static inline int crypto_scomp_decompress(struct crypto_scomp *tfm, } int crypto_init_scomp_ops_async(struct crypto_tfm *tfm); +int crypto_init_scomp_ops_nospace(struct crypto_tfm *tfm); struct acomp_req *crypto_acomp_scomp_alloc_ctx(struct acomp_req *req); void crypto_acomp_scomp_free_ctx(struct acomp_req *req); @@ -120,6 +121,19 @@ void crypto_acomp_scomp_free_ctx(struct acomp_req *req); int crypto_register_scomp(struct scomp_alg *alg); /** + * crypto_register_scomp_qdecomp() -- Register synchronous compression + * algorithm with support for qdecomp + * + * Function registers an implementation of a synchronous + * compression algorithm that supports qdecomp + * + * @alg: algorithm definition + * + * Return: zero on success; error code in case of error + */ +int crypto_register_scomp_qdecomp(struct scomp_alg *alg); + +/** * crypto_unregister_scomp() -- Unregister synchronous compression algorithm * * Function unregisters an implementation of a synchronous diff --git a/include/crypto/qdecompress.h b/include/crypto/qdecompress.h new file mode 100644 index 0000000..6dad3b2 --- /dev/null +++ b/include/crypto/qdecompress.h @@ -0,0 +1,204 @@ +/* + * Quick Decompression operations + * + * Copyright (c) 2016, Intel Corporation + * Authors: Giovanni Cabiddu + * + * 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. + * + */ +#ifndef _CRYPTO_QDECOMP_H +#define _CRYPTO_QDECOMP_H +#include + +/** + * struct qdecomp_req - decompression request without work space + * + * @base: Common attributes for asynchronous crypto requests + * @src: Source Data + * @dst: Destination data + * @slen: Size of the input buffer + * @dlen: Size of the output buffer + * @consumed: Number of bytes consumed by the decompressor + * @produced: Number of bytes produced by the decompressor + */ +struct qdecomp_req { + struct crypto_async_request base; + struct scatterlist *src; + struct scatterlist *dst; + unsigned int slen; + unsigned int dlen; + unsigned int consumed; + unsigned int produced; +}; + +/** + * struct crypto_qdecomp - user-instantiated objects which encapsulate + * algorithms and core processing logic + * + * @decompress: Function performs a decompression operation + * @reqsize: Context size for decompression requests + * @base: Common crypto API algorithm data structure + */ +struct crypto_qdecomp { + int (*decompress)(struct qdecomp_req *req); + struct crypto_tfm base; +}; + +/** + * DOC: Quick Decompression API + * + * The Quick Decompression API is used with the algorithms of type + * CRYPTO_ALG_TYPE_ACOMPRESS (listed as type "acomp" in /proc/crypto) and + * CRYPTO_ALG_TYPE_SCOMPRESS (listed as type "scomp" in /proc/crypto) which + * support decompression without work space + */ + +/** + * crypto_alloc_qdecomp() -- allocate QDECOMPRESS tfm handle + * @alg_name: is the cra_name / name or cra_driver_name / driver name of the + * decompression algorithm e.g. "deflate" + * @type: specifies the type of the algorithm + * @mask: specifies the mask for the algorithm + * + * Allocate a handle for a decompression algorithm. The returned struct + * crypto_qdecomp is the handle that is required for any subsequent + * API invocation for the decompression operation. + * + * Return: allocated handle in case of success; IS_ERR() is true in case + * of an error, PTR_ERR() returns the error code. + */ +struct crypto_qdecomp *crypto_alloc_qdecomp(const char *alg_name, u32 type, + u32 mask); + +static inline struct crypto_tfm *crypto_qdecomp_tfm(struct crypto_qdecomp *tfm) +{ + return &tfm->base; +} + +static inline struct crypto_qdecomp *__crypto_qdecomp_tfm( + struct crypto_tfm *tfm) +{ + return container_of(tfm, struct crypto_qdecomp, base); +} + +static inline void qdecomp_request_set_tfm(struct qdecomp_req *req, + struct crypto_qdecomp *tfm) +{ + req->base.tfm = crypto_qdecomp_tfm(tfm); +} + +static inline struct crypto_qdecomp *crypto_qdecomp_reqtfm( + struct qdecomp_req *req) +{ + return __crypto_qdecomp_tfm(req->base.tfm); +} + +/** + * crypto_free_qdecomp() -- free QDECOMPRESS tfm handle + * + * @tfm: QDECOMPRESS tfm handle allocated with crypto_alloc_qdecomp() + */ +static inline void crypto_free_qdecomp(struct crypto_qdecomp *tfm) +{ + crypto_destroy_tfm(tfm, crypto_qdecomp_tfm(tfm)); +} + +/** + * qdecomp_request_alloc() -- allocates quick decompression request + * + * @tfm: QDECOMPRESS tfm handle allocated with crypto_alloc_qdecomp() + * @gfp: allocation flags + * + * Return: allocated handle in case of success or NULL in case of an error. + */ +static inline struct qdecomp_req *qdecomp_request_alloc( + struct crypto_qdecomp *tfm, + gfp_t gfp) +{ + struct qdecomp_req *req; + + req = kzalloc(sizeof(*req), gfp); + if (likely(req)) + qdecomp_request_set_tfm(req, tfm); + + return req; +} + +/** + * qdecomp_request_free() -- zeroize and free quick decompress request + * + * @req: request to free + */ + +static inline void qdecomp_request_free(struct qdecomp_req *req) +{ + kzfree(req); +} + +/** + * qdecomp_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 qdecomp_request_set_callback(struct qdecomp_req *req, + u32 flgs, + crypto_completion_t cmpl, + void *data) +{ + req->base.complete = cmpl; + req->base.data = data; + req->base.flags = flgs; +} + +/** + * qdecomp_request_set_params() -- Sets request parameters + * + * Sets parameters required by a qdecomp operation + * + * @req: asynchronous decompression request + * @src: pointer to input buffer scatterlist + * @dst: pointer to output buffer scatterlist + * @slen: size of the input buffer + * @dlen: size of the output buffer + */ +static inline void qdecomp_request_set_params(struct qdecomp_req *req, + struct scatterlist *src, + struct scatterlist *dst, + unsigned int slen, + unsigned int dlen) +{ + req->src = src; + req->dst = dst; + req->slen = slen; + req->dlen = dlen; + req->consumed = 0; + req->produced = 0; +} + +/** + * crypto_qdecomp_decompress() -- Invoke asynchronous decompression operation + * + * Function invokes the asynchronous decompression operation + * + * @req: asynchronous decompression request + * + * Return: zero on success; error code in case of error + */ +static inline int crypto_qdecomp_decompress(struct qdecomp_req *req) +{ + struct crypto_qdecomp *tfm = crypto_qdecomp_reqtfm(req); + + return tfm->decompress(req); +} + +#endif diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 23ceb0b..916e4f7 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -49,7 +49,10 @@ #define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005 #define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006 #define CRYPTO_ALG_TYPE_ACOMPRESS 0x00000008 +#define CRYPTO_ALG_TYPE_ACOMPRESS_QDCMP 0x00000009 +#define CRYPTO_ALG_TYPE_QDECOMPRESS 0x00000009 #define CRYPTO_ALG_TYPE_SCOMPRESS 0x0000000a +#define CRYPTO_ALG_TYPE_SCOMPRESS_QDCMP 0x0000000b #define CRYPTO_ALG_TYPE_RNG 0x0000000c #define CRYPTO_ALG_TYPE_AKCIPHER 0x0000000d #define CRYPTO_ALG_TYPE_DIGEST 0x0000000e @@ -61,6 +64,7 @@ #define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000e #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c #define CRYPTO_ALG_TYPE_ACOMPRESS_MASK 0x0000000c +#define CRYPTO_ALG_TYPE_QDECOMP_MASK 0x0000000d #define CRYPTO_ALG_LARVAL 0x00000010 #define CRYPTO_ALG_DEAD 0x00000020