From: Kees Cook <keescook@chromium.org>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Kees Cook <keescook@chromium.org>,
Geliang Tang <geliangtang@gmail.com>,
Arnd Bergmann <arnd@arndb.de>, Haren Myneni <haren@us.ibm.com>,
Anton Vorontsov <anton@enomsg.org>,
Colin Cross <ccross@android.com>, Tony Luck <tony.luck@intel.com>,
Zhou Wang <wangzhou1@hisilicon.com>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/9] crypto: add zbufsize() interface
Date: Thu, 2 Aug 2018 14:51:10 -0700 [thread overview]
Message-ID: <20180802215118.17752-2-keescook@chromium.org> (raw)
In-Reply-To: <20180802215118.17752-1-keescook@chromium.org>
When pstore was refactored to use the crypto compress API in:
commit cb3bee0369bc ("pstore: Use crypto compress API")
nearly all the pstore-specific compression routines were replaced with
the existing crypto compression API. One case remained: calculating the
"worst case" compression sizes ahead of time so it could have a buffer
preallocated for doing compression (which was called "zbufsize").
To make pstore fully algorithm-agnostic, the compression API needs to
grow this functionality. This adds the interface to support querying the
"worst case" estimate, with a new "zbufsize" routine that each compressor
can implement. The per-compressor implementations come in later commits.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
crypto/compress.c | 9 +++++++++
include/crypto/internal/scompress.h | 11 +++++++++++
include/linux/crypto.h | 12 ++++++++++++
3 files changed, 32 insertions(+)
diff --git a/crypto/compress.c b/crypto/compress.c
index f2d522924a07..29a80bb3b9d3 100644
--- a/crypto/compress.c
+++ b/crypto/compress.c
@@ -33,12 +33,21 @@ static int crypto_decompress(struct crypto_tfm *tfm,
dlen);
}
+static int crypto_zbufsize(struct crypto_tfm *tfm,
+ unsigned int slen, unsigned int *dlen)
+{
+ if (!tfm->__crt_alg->cra_compress.coa_zbufsize)
+ return -ENOTSUPP;
+ return tfm->__crt_alg->cra_compress.coa_zbufsize(tfm, slen, dlen);
+}
+
int crypto_init_compress_ops(struct crypto_tfm *tfm)
{
struct compress_tfm *ops = &tfm->crt_compress;
ops->cot_compress = crypto_compress;
ops->cot_decompress = crypto_decompress;
+ ops->cot_zbufsize = crypto_zbufsize;
return 0;
}
diff --git a/include/crypto/internal/scompress.h b/include/crypto/internal/scompress.h
index 0f6ddac1acfc..a4a2a55080ad 100644
--- a/include/crypto/internal/scompress.h
+++ b/include/crypto/internal/scompress.h
@@ -39,6 +39,8 @@ struct scomp_alg {
int (*decompress)(struct crypto_scomp *tfm, const u8 *src,
unsigned int slen, u8 *dst, unsigned int *dlen,
void *ctx);
+ int (*zbufsize)(struct crypto_scomp *tfm, unsigned int slen,
+ unsigned int *dlen, void *ctx);
struct crypto_alg base;
};
@@ -94,6 +96,15 @@ static inline int crypto_scomp_decompress(struct crypto_scomp *tfm,
ctx);
}
+static inline int crypto_scomp_zbufsize(struct crypto_scomp *tfm,
+ unsigned int slen,
+ unsigned int *dlen, void *ctx)
+{
+ if (!crypto_scomp_alg(tfm)->zbufsize)
+ return -ENOTSUPP;
+ return crypto_scomp_alg(tfm)->zbufsize(tfm, slen, dlen, ctx);
+}
+
int crypto_init_scomp_ops_async(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);
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 6eb06101089f..376c056447e7 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -362,6 +362,8 @@ struct compress_alg {
unsigned int slen, u8 *dst, unsigned int *dlen);
int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
unsigned int slen, u8 *dst, unsigned int *dlen);
+ int (*coa_zbufsize)(struct crypto_tfm *tfm, unsigned int slen,
+ unsigned int *dlen);
};
@@ -578,6 +580,8 @@ struct compress_tfm {
int (*cot_decompress)(struct crypto_tfm *tfm,
const u8 *src, unsigned int slen,
u8 *dst, unsigned int *dlen);
+ int (*cot_zbufsize)(struct crypto_tfm *tfm,
+ unsigned int slen, unsigned int *dlen);
};
#define crt_ablkcipher crt_u.ablkcipher
@@ -1660,5 +1664,13 @@ static inline int crypto_comp_decompress(struct crypto_comp *tfm,
src, slen, dst, dlen);
}
+static inline int crypto_comp_zbufsize(struct crypto_comp *tfm,
+ unsigned int slen,
+ unsigned int *dlen)
+{
+ return crypto_comp_crt(tfm)->cot_zbufsize(crypto_comp_tfm(tfm),
+ slen, dlen);
+}
+
#endif /* _LINUX_CRYPTO_H */
--
2.17.1
next prev parent reply other threads:[~2018-08-02 21:52 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-02 21:51 [PATCH 0/9] " Kees Cook
2018-08-02 21:51 ` Kees Cook [this message]
2018-08-07 9:45 ` [PATCH 1/9] " Herbert Xu
2018-08-07 18:10 ` Kees Cook
2018-08-08 2:53 ` Herbert Xu
2021-12-01 23:39 ` Kees Cook
2021-12-02 1:58 ` Herbert Xu
2021-12-02 3:51 ` Kees Cook
2021-12-02 3:57 ` Herbert Xu
2021-12-02 8:10 ` Kees Cook
2021-12-03 2:28 ` Herbert Xu
2021-12-03 20:49 ` Dmitry Torokhov
2021-12-07 5:20 ` Herbert Xu
2021-12-07 6:24 ` Dmitry Torokhov
2021-12-07 6:27 ` Herbert Xu
2018-08-02 21:51 ` [PATCH 2/9] crypto, 842: implement zbufsize() Kees Cook
2018-08-02 21:51 ` [PATCH 3/9] crypto, null: Implement zbufsize() Kees Cook
2018-08-02 21:51 ` [PATCH 4/9] crypto, lzo: " Kees Cook
2018-08-02 21:51 ` [PATCH 5/9] crypto, deflate: " Kees Cook
2018-08-02 21:51 ` [PATCH 6/9] crypto, zstd: " Kees Cook
2018-08-02 21:51 ` [PATCH 7/9] crypto, lz4: " Kees Cook
2018-08-02 21:51 ` [PATCH 8/9] crypto, lz4hc: " Kees Cook
2018-08-02 21:51 ` [PATCH 9/9] pstore: Use crypto_comp_zbufsize() Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180802215118.17752-2-keescook@chromium.org \
--to=keescook@chromium.org \
--cc=anton@enomsg.org \
--cc=arnd@arndb.de \
--cc=ccross@android.com \
--cc=geliangtang@gmail.com \
--cc=haren@us.ibm.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@intel.com \
--cc=wangzhou1@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®