Skip to content

Commit 1ab53a7

Browse files
gcabidduherbertx
authored andcommitted
crypto: acomp - add driver-side scomp interface
Add a synchronous back-end (scomp) to acomp. This allows to easily expose the already present compression algorithms in LKCF via acomp. Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 2ebda74 commit 1ab53a7

File tree

7 files changed

+578
-29
lines changed

7 files changed

+578
-29
lines changed

crypto/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ rsa_generic-y += rsa-pkcs1pad.o
5151
obj-$(CONFIG_CRYPTO_RSA) += rsa_generic.o
5252

5353
obj-$(CONFIG_CRYPTO_ACOMP2) += acompress.o
54+
obj-$(CONFIG_CRYPTO_ACOMP2) += scompress.o
5455

5556
cryptomgr-y := algboss.o testmgr.o
5657

crypto/acompress.c

+53-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
#include <linux/cryptouser.h>
2323
#include <net/netlink.h>
2424
#include <crypto/internal/acompress.h>
25+
#include <crypto/internal/scompress.h>
2526
#include "internal.h"
2627

28+
static const struct crypto_type crypto_acomp_type;
29+
2730
#ifdef CONFIG_NET
2831
static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
2932
{
@@ -67,6 +70,14 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm)
6770
struct crypto_acomp *acomp = __crypto_acomp_tfm(tfm);
6871
struct acomp_alg *alg = crypto_acomp_alg(acomp);
6972

73+
if (tfm->__crt_alg->cra_type != &crypto_acomp_type)
74+
return crypto_init_scomp_ops_async(tfm);
75+
76+
acomp->compress = alg->compress;
77+
acomp->decompress = alg->decompress;
78+
acomp->dst_free = alg->dst_free;
79+
acomp->reqsize = alg->reqsize;
80+
7081
if (alg->exit)
7182
acomp->base.exit = crypto_acomp_exit_tfm;
7283

@@ -76,15 +87,25 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm)
7687
return 0;
7788
}
7889

90+
static unsigned int crypto_acomp_extsize(struct crypto_alg *alg)
91+
{
92+
int extsize = crypto_alg_extsize(alg);
93+
94+
if (alg->cra_type != &crypto_acomp_type)
95+
extsize += sizeof(struct crypto_scomp *);
96+
97+
return extsize;
98+
}
99+
79100
static const struct crypto_type crypto_acomp_type = {
80-
.extsize = crypto_alg_extsize,
101+
.extsize = crypto_acomp_extsize,
81102
.init_tfm = crypto_acomp_init_tfm,
82103
#ifdef CONFIG_PROC_FS
83104
.show = crypto_acomp_show,
84105
#endif
85106
.report = crypto_acomp_report,
86107
.maskclear = ~CRYPTO_ALG_TYPE_MASK,
87-
.maskset = CRYPTO_ALG_TYPE_MASK,
108+
.maskset = CRYPTO_ALG_TYPE_ACOMPRESS_MASK,
88109
.type = CRYPTO_ALG_TYPE_ACOMPRESS,
89110
.tfmsize = offsetof(struct crypto_acomp, base),
90111
};
@@ -96,6 +117,36 @@ struct crypto_acomp *crypto_alloc_acomp(const char *alg_name, u32 type,
96117
}
97118
EXPORT_SYMBOL_GPL(crypto_alloc_acomp);
98119

120+
struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp)
121+
{
122+
struct crypto_tfm *tfm = crypto_acomp_tfm(acomp);
123+
struct acomp_req *req;
124+
125+
req = __acomp_request_alloc(acomp);
126+
if (req && (tfm->__crt_alg->cra_type != &crypto_acomp_type))
127+
return crypto_acomp_scomp_alloc_ctx(req);
128+
129+
return req;
130+
}
131+
EXPORT_SYMBOL_GPL(acomp_request_alloc);
132+
133+
void acomp_request_free(struct acomp_req *req)
134+
{
135+
struct crypto_acomp *acomp = crypto_acomp_reqtfm(req);
136+
struct crypto_tfm *tfm = crypto_acomp_tfm(acomp);
137+
138+
if (tfm->__crt_alg->cra_type != &crypto_acomp_type)
139+
crypto_acomp_scomp_free_ctx(req);
140+
141+
if (req->flags & CRYPTO_ACOMP_ALLOC_OUTPUT) {
142+
acomp->dst_free(req->dst);
143+
req->dst = NULL;
144+
}
145+
146+
__acomp_request_free(req);
147+
}
148+
EXPORT_SYMBOL_GPL(acomp_request_free);
149+
99150
int crypto_register_acomp(struct acomp_alg *alg)
100151
{
101152
struct crypto_alg *base = &alg->base;

0 commit comments

Comments
 (0)