[PATCH 8/9] crypto, lz4hc: Implement zbufsize()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This implements the worst-case compression size querying interface for
lz4hc, based on the logic originally used by pstore.

Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
---
 crypto/lz4hc.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/crypto/lz4hc.c b/crypto/lz4hc.c
index 2be14f054daf..cf6f38a1c35b 100644
--- a/crypto/lz4hc.c
+++ b/crypto/lz4hc.c
@@ -118,6 +118,24 @@ static int lz4hc_decompress_crypto(struct crypto_tfm *tfm, const u8 *src,
 	return __lz4hc_decompress_crypto(src, slen, dst, dlen, NULL);
 }
 
+static int __lz4hc_zbufsize_crypto(unsigned int slen, unsigned int *dlen)
+{
+	*dlen = LZ4_compressBound(slen);
+	return 0;
+}
+
+static int lz4hc_szbufsize(struct crypto_scomp *tfm, unsigned int slen,
+			   unsigned int *dlen, void *ctx)
+{
+	return __lz4hc_zbufsize_crypto(slen, dlen);
+}
+
+static int lz4hc_zbufsize_crypto(struct crypto_tfm *tfm, unsigned int slen,
+				 unsigned int *dlen)
+{
+	return __lz4hc_zbufsize_crypto(slen, dlen);
+}
+
 static struct crypto_alg alg_lz4hc = {
 	.cra_name		= "lz4hc",
 	.cra_flags		= CRYPTO_ALG_TYPE_COMPRESS,
@@ -128,7 +146,8 @@ static struct crypto_alg alg_lz4hc = {
 	.cra_exit		= lz4hc_exit,
 	.cra_u			= { .compress = {
 	.coa_compress		= lz4hc_compress_crypto,
-	.coa_decompress		= lz4hc_decompress_crypto } }
+	.coa_decompress		= lz4hc_decompress_crypto,
+	.coa_zbufsize		= lz4hc_zbufsize_crypto } }
 };
 
 static struct scomp_alg scomp = {
@@ -136,6 +155,7 @@ static struct scomp_alg scomp = {
 	.free_ctx		= lz4hc_free_ctx,
 	.compress		= lz4hc_scompress,
 	.decompress		= lz4hc_sdecompress,
+	.zbufsize		= lz4hc_szbufsize,
 	.base			= {
 		.cra_name	= "lz4hc",
 		.cra_driver_name = "lz4hc-scomp",
-- 
2.17.1




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux