@@ -14,6 +14,7 @@
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/rtnetlink.h>
#include <linux/scatterlist.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
@@ -377,5 +378,53 @@ void crypto_unregister_scomps(struct scomp_alg *algs, int count)
}
EXPORT_SYMBOL_GPL(crypto_unregister_scomps);
+int crypto_comp_getparams(struct crypto_comp_params *params, const u8 *raw,
+ unsigned int len)
+{
+ struct rtattr *rta = (struct rtattr *)raw;
+ void *dict;
+
+ crypto_comp_putparams(params);
+ params->level = CRYPTO_COMP_NO_LEVEL;
+
+ for (;; rta = RTA_NEXT(rta, len)) {
+ if (!RTA_OK(rta, len))
+ return -EINVAL;
+
+ if (rta->rta_type == CRYPTO_COMP_PARAM_LAST)
+ break;
+
+ switch (rta->rta_type) {
+ case CRYPTO_COMP_PARAM_LEVEL:
+ if (RTA_PAYLOAD(rta) != 4)
+ return -EINVAL;
+ memcpy(¶ms->level, RTA_DATA(rta), 4);
+ break;
+ default:
+ return -EINVAL;
+ }
+ }
+
+ dict = RTA_NEXT(rta, len);
+ if (!len)
+ return 0;
+
+ params->dict = kvmemdup(dict, len, GFP_KERNEL);
+ if (!params->dict)
+ return -ENOMEM;
+ params->dict_sz = len;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(crypto_comp_getparams);
+
+void crypto_comp_putparams(struct crypto_comp_params *params)
+{
+ kfree(params->dict);
+ params->dict = NULL;
+ params->dict_sz = 0;
+}
+EXPORT_SYMBOL_GPL(crypto_comp_putparams);
+
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Synchronous compression type");
@@ -12,10 +12,19 @@
#include <linux/atomic.h>
#include <linux/container_of.h>
#include <linux/crypto.h>
+#include <linux/limits.h>
#define CRYPTO_ACOMP_ALLOC_OUTPUT 0x00000001
#define CRYPTO_ACOMP_DST_MAX 131072
+#define CRYPTO_COMP_NO_LEVEL INT_MIN
+
+enum {
+ CRYPTO_COMP_PARAM_UNSPEC,
+ CRYPTO_COMP_PARAM_LEVEL,
+ CRYPTO_COMP_PARAM_LAST,
+};
+
/**
* struct acomp_req - asynchronous (de)compression request
*
@@ -49,6 +49,12 @@ struct scomp_alg {
};
};
+struct crypto_comp_params {
+ int level;
+ unsigned dict_sz;
+ void *dict;
+};
+
static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg)
{
return container_of(alg, struct scomp_alg, base);
@@ -150,4 +156,8 @@ void crypto_unregister_scomp(struct scomp_alg *alg);
int crypto_register_scomps(struct scomp_alg *algs, int count);
void crypto_unregister_scomps(struct scomp_alg *algs, int count);
+int crypto_comp_getparams(struct crypto_comp_params *params, const u8 *raw,
+ unsigned int len);
+void crypto_comp_putparams(struct crypto_comp_params *params);
+
#endif
Add helpers to get compression parameters, including the level and an optional dictionary. Note that algorithms do not have to use these helpers and could come up with its own set of parameters. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> --- crypto/scompress.c | 49 +++++++++++++++++++++++++++++ include/crypto/acompress.h | 9 ++++++ include/crypto/internal/scompress.h | 10 ++++++ 3 files changed, 68 insertions(+)