This source file includes following definitions.
- crypto_acomp_tfm
- __crypto_acomp_alg
- __crypto_acomp_tfm
- crypto_acomp_alg
- crypto_acomp_reqsize
- acomp_request_set_tfm
- crypto_acomp_reqtfm
- crypto_free_acomp
- crypto_has_acomp
- acomp_request_set_callback
- acomp_request_set_params
- crypto_acomp_compress
- crypto_acomp_decompress
1
2
3
4
5
6
7
8
9 #ifndef _CRYPTO_ACOMP_H
10 #define _CRYPTO_ACOMP_H
11 #include <linux/crypto.h>
12
13 #define CRYPTO_ACOMP_ALLOC_OUTPUT 0x00000001
14
15
16
17
18
19
20
21
22
23
24
25
26 struct acomp_req {
27 struct crypto_async_request base;
28 struct scatterlist *src;
29 struct scatterlist *dst;
30 unsigned int slen;
31 unsigned int dlen;
32 u32 flags;
33 void *__ctx[] CRYPTO_MINALIGN_ATTR;
34 };
35
36
37
38
39
40
41
42
43
44
45
46
47 struct crypto_acomp {
48 int (*compress)(struct acomp_req *req);
49 int (*decompress)(struct acomp_req *req);
50 void (*dst_free)(struct scatterlist *dst);
51 unsigned int reqsize;
52 struct crypto_tfm base;
53 };
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 struct acomp_alg {
77 int (*compress)(struct acomp_req *req);
78 int (*decompress)(struct acomp_req *req);
79 void (*dst_free)(struct scatterlist *dst);
80 int (*init)(struct crypto_acomp *tfm);
81 void (*exit)(struct crypto_acomp *tfm);
82 unsigned int reqsize;
83 struct crypto_alg base;
84 };
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 struct crypto_acomp *crypto_alloc_acomp(const char *alg_name, u32 type,
108 u32 mask);
109
110 static inline struct crypto_tfm *crypto_acomp_tfm(struct crypto_acomp *tfm)
111 {
112 return &tfm->base;
113 }
114
115 static inline struct acomp_alg *__crypto_acomp_alg(struct crypto_alg *alg)
116 {
117 return container_of(alg, struct acomp_alg, base);
118 }
119
120 static inline struct crypto_acomp *__crypto_acomp_tfm(struct crypto_tfm *tfm)
121 {
122 return container_of(tfm, struct crypto_acomp, base);
123 }
124
125 static inline struct acomp_alg *crypto_acomp_alg(struct crypto_acomp *tfm)
126 {
127 return __crypto_acomp_alg(crypto_acomp_tfm(tfm)->__crt_alg);
128 }
129
130 static inline unsigned int crypto_acomp_reqsize(struct crypto_acomp *tfm)
131 {
132 return tfm->reqsize;
133 }
134
135 static inline void acomp_request_set_tfm(struct acomp_req *req,
136 struct crypto_acomp *tfm)
137 {
138 req->base.tfm = crypto_acomp_tfm(tfm);
139 }
140
141 static inline struct crypto_acomp *crypto_acomp_reqtfm(struct acomp_req *req)
142 {
143 return __crypto_acomp_tfm(req->base.tfm);
144 }
145
146
147
148
149
150
151 static inline void crypto_free_acomp(struct crypto_acomp *tfm)
152 {
153 crypto_destroy_tfm(tfm, crypto_acomp_tfm(tfm));
154 }
155
156 static inline int crypto_has_acomp(const char *alg_name, u32 type, u32 mask)
157 {
158 type &= ~CRYPTO_ALG_TYPE_MASK;
159 type |= CRYPTO_ALG_TYPE_ACOMPRESS;
160 mask |= CRYPTO_ALG_TYPE_MASK;
161
162 return crypto_has_alg(alg_name, type, mask);
163 }
164
165
166
167
168
169
170
171
172 struct acomp_req *acomp_request_alloc(struct crypto_acomp *tfm);
173
174
175
176
177
178
179
180
181 void acomp_request_free(struct acomp_req *req);
182
183
184
185
186
187
188
189
190
191
192
193
194 static inline void acomp_request_set_callback(struct acomp_req *req,
195 u32 flgs,
196 crypto_completion_t cmpl,
197 void *data)
198 {
199 req->base.complete = cmpl;
200 req->base.data = data;
201 req->base.flags = flgs;
202 }
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217 static inline void acomp_request_set_params(struct acomp_req *req,
218 struct scatterlist *src,
219 struct scatterlist *dst,
220 unsigned int slen,
221 unsigned int dlen)
222 {
223 req->src = src;
224 req->dst = dst;
225 req->slen = slen;
226 req->dlen = dlen;
227
228 if (!req->dst)
229 req->flags |= CRYPTO_ACOMP_ALLOC_OUTPUT;
230 }
231
232
233
234
235
236
237
238
239
240
241 static inline int crypto_acomp_compress(struct acomp_req *req)
242 {
243 struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
244 struct crypto_alg *alg = tfm->base.__crt_alg;
245 unsigned int slen = req->slen;
246 int ret;
247
248 crypto_stats_get(alg);
249 ret = tfm->compress(req);
250 crypto_stats_compress(slen, ret, alg);
251 return ret;
252 }
253
254
255
256
257
258
259
260
261
262
263 static inline int crypto_acomp_decompress(struct acomp_req *req)
264 {
265 struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
266 struct crypto_alg *alg = tfm->base.__crt_alg;
267 unsigned int slen = req->slen;
268 int ret;
269
270 crypto_stats_get(alg);
271 ret = tfm->decompress(req);
272 crypto_stats_decompress(slen, ret, alg);
273 return ret;
274 }
275
276 #endif