mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-22 20:24:29 +07:00
a1d2f09544
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>
98 lines
2.5 KiB
C
98 lines
2.5 KiB
C
/*
|
|
* Cryptographic API.
|
|
*
|
|
* Partial (de)compression operations.
|
|
*
|
|
* Copyright 2008 Sony Corporation
|
|
*
|
|
* 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/string.h>
|
|
|
|
#include <crypto/compress.h>
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
static int crypto_pcomp_init(struct crypto_tfm *tfm, u32 type, u32 mask)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static unsigned int crypto_pcomp_extsize(struct crypto_alg *alg,
|
|
const struct crypto_type *frontend)
|
|
{
|
|
return alg->cra_ctxsize;
|
|
}
|
|
|
|
static int crypto_pcomp_init_tfm(struct crypto_tfm *tfm,
|
|
const struct crypto_type *frontend)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg)
|
|
__attribute__ ((unused));
|
|
static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg)
|
|
{
|
|
seq_printf(m, "type : pcomp\n");
|
|
}
|
|
|
|
static const struct crypto_type crypto_pcomp_type = {
|
|
.extsize = crypto_pcomp_extsize,
|
|
.init = crypto_pcomp_init,
|
|
.init_tfm = crypto_pcomp_init_tfm,
|
|
#ifdef CONFIG_PROC_FS
|
|
.show = crypto_pcomp_show,
|
|
#endif
|
|
.maskclear = ~CRYPTO_ALG_TYPE_MASK,
|
|
.maskset = CRYPTO_ALG_TYPE_MASK,
|
|
.type = CRYPTO_ALG_TYPE_PCOMPRESS,
|
|
.tfmsize = offsetof(struct crypto_pcomp, base),
|
|
};
|
|
|
|
struct crypto_pcomp *crypto_alloc_pcomp(const char *alg_name, u32 type,
|
|
u32 mask)
|
|
{
|
|
return crypto_alloc_tfm(alg_name, &crypto_pcomp_type, type, mask);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_alloc_pcomp);
|
|
|
|
int crypto_register_pcomp(struct pcomp_alg *alg)
|
|
{
|
|
struct crypto_alg *base = &alg->base;
|
|
|
|
base->cra_type = &crypto_pcomp_type;
|
|
base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
|
|
base->cra_flags |= CRYPTO_ALG_TYPE_PCOMPRESS;
|
|
|
|
return crypto_register_alg(base);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_register_pcomp);
|
|
|
|
int crypto_unregister_pcomp(struct pcomp_alg *alg)
|
|
{
|
|
return crypto_unregister_alg(&alg->base);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_unregister_pcomp);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("Partial (de)compression type");
|
|
MODULE_AUTHOR("Sony Corporation");
|