This source file includes following definitions.
- crypto_kpp_tfm
- __crypto_kpp_alg
- __crypto_kpp_tfm
- crypto_kpp_alg
- crypto_kpp_reqsize
- kpp_request_set_tfm
- crypto_kpp_reqtfm
- crypto_kpp_get_flags
- crypto_kpp_set_flags
- crypto_free_kpp
- kpp_request_alloc
- kpp_request_free
- kpp_request_set_callback
- kpp_request_set_input
- kpp_request_set_output
- crypto_kpp_set_secret
- crypto_kpp_generate_public_key
- crypto_kpp_compute_shared_secret
- crypto_kpp_maxsize
1
2
3
4
5
6
7
8
9 #ifndef _CRYPTO_KPP_
10 #define _CRYPTO_KPP_
11 #include <linux/crypto.h>
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 struct kpp_request {
28 struct crypto_async_request base;
29 struct scatterlist *src;
30 struct scatterlist *dst;
31 unsigned int src_len;
32 unsigned int dst_len;
33 void *__ctx[] CRYPTO_MINALIGN_ATTR;
34 };
35
36
37
38
39
40
41
42 struct crypto_kpp {
43 struct crypto_tfm base;
44 };
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 struct kpp_alg {
72 int (*set_secret)(struct crypto_kpp *tfm, const void *buffer,
73 unsigned int len);
74 int (*generate_public_key)(struct kpp_request *req);
75 int (*compute_shared_secret)(struct kpp_request *req);
76
77 unsigned int (*max_size)(struct crypto_kpp *tfm);
78
79 int (*init)(struct crypto_kpp *tfm);
80 void (*exit)(struct crypto_kpp *tfm);
81
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 struct crypto_kpp *crypto_alloc_kpp(const char *alg_name, u32 type, u32 mask);
106
107 static inline struct crypto_tfm *crypto_kpp_tfm(struct crypto_kpp *tfm)
108 {
109 return &tfm->base;
110 }
111
112 static inline struct kpp_alg *__crypto_kpp_alg(struct crypto_alg *alg)
113 {
114 return container_of(alg, struct kpp_alg, base);
115 }
116
117 static inline struct crypto_kpp *__crypto_kpp_tfm(struct crypto_tfm *tfm)
118 {
119 return container_of(tfm, struct crypto_kpp, base);
120 }
121
122 static inline struct kpp_alg *crypto_kpp_alg(struct crypto_kpp *tfm)
123 {
124 return __crypto_kpp_alg(crypto_kpp_tfm(tfm)->__crt_alg);
125 }
126
127 static inline unsigned int crypto_kpp_reqsize(struct crypto_kpp *tfm)
128 {
129 return crypto_kpp_alg(tfm)->reqsize;
130 }
131
132 static inline void kpp_request_set_tfm(struct kpp_request *req,
133 struct crypto_kpp *tfm)
134 {
135 req->base.tfm = crypto_kpp_tfm(tfm);
136 }
137
138 static inline struct crypto_kpp *crypto_kpp_reqtfm(struct kpp_request *req)
139 {
140 return __crypto_kpp_tfm(req->base.tfm);
141 }
142
143 static inline u32 crypto_kpp_get_flags(struct crypto_kpp *tfm)
144 {
145 return crypto_tfm_get_flags(crypto_kpp_tfm(tfm));
146 }
147
148 static inline void crypto_kpp_set_flags(struct crypto_kpp *tfm, u32 flags)
149 {
150 crypto_tfm_set_flags(crypto_kpp_tfm(tfm), flags);
151 }
152
153
154
155
156
157
158 static inline void crypto_free_kpp(struct crypto_kpp *tfm)
159 {
160 crypto_destroy_tfm(tfm, crypto_kpp_tfm(tfm));
161 }
162
163
164
165
166
167
168
169
170
171 static inline struct kpp_request *kpp_request_alloc(struct crypto_kpp *tfm,
172 gfp_t gfp)
173 {
174 struct kpp_request *req;
175
176 req = kmalloc(sizeof(*req) + crypto_kpp_reqsize(tfm), gfp);
177 if (likely(req))
178 kpp_request_set_tfm(req, tfm);
179
180 return req;
181 }
182
183
184
185
186
187
188 static inline void kpp_request_free(struct kpp_request *req)
189 {
190 kzfree(req);
191 }
192
193
194
195
196
197
198
199
200
201
202
203
204 static inline void kpp_request_set_callback(struct kpp_request *req,
205 u32 flgs,
206 crypto_completion_t cmpl,
207 void *data)
208 {
209 req->base.complete = cmpl;
210 req->base.data = data;
211 req->base.flags = flgs;
212 }
213
214
215
216
217
218
219
220
221
222
223 static inline void kpp_request_set_input(struct kpp_request *req,
224 struct scatterlist *input,
225 unsigned int input_len)
226 {
227 req->src = input;
228 req->src_len = input_len;
229 }
230
231
232
233
234
235
236
237
238
239
240 static inline void kpp_request_set_output(struct kpp_request *req,
241 struct scatterlist *output,
242 unsigned int output_len)
243 {
244 req->dst = output;
245 req->dst_len = output_len;
246 }
247
248 enum {
249 CRYPTO_KPP_SECRET_TYPE_UNKNOWN,
250 CRYPTO_KPP_SECRET_TYPE_DH,
251 CRYPTO_KPP_SECRET_TYPE_ECDH,
252 };
253
254
255
256
257
258
259
260
261 struct kpp_secret {
262 unsigned short type;
263 unsigned short len;
264 };
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281 static inline int crypto_kpp_set_secret(struct crypto_kpp *tfm,
282 const void *buffer, unsigned int len)
283 {
284 struct kpp_alg *alg = crypto_kpp_alg(tfm);
285 struct crypto_alg *calg = tfm->base.__crt_alg;
286 int ret;
287
288 crypto_stats_get(calg);
289 ret = alg->set_secret(tfm, buffer, len);
290 crypto_stats_kpp_set_secret(calg, ret);
291 return ret;
292 }
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307 static inline int crypto_kpp_generate_public_key(struct kpp_request *req)
308 {
309 struct crypto_kpp *tfm = crypto_kpp_reqtfm(req);
310 struct kpp_alg *alg = crypto_kpp_alg(tfm);
311 struct crypto_alg *calg = tfm->base.__crt_alg;
312 int ret;
313
314 crypto_stats_get(calg);
315 ret = alg->generate_public_key(req);
316 crypto_stats_kpp_generate_public_key(calg, ret);
317 return ret;
318 }
319
320
321
322
323
324
325
326
327
328
329
330 static inline int crypto_kpp_compute_shared_secret(struct kpp_request *req)
331 {
332 struct crypto_kpp *tfm = crypto_kpp_reqtfm(req);
333 struct kpp_alg *alg = crypto_kpp_alg(tfm);
334 struct crypto_alg *calg = tfm->base.__crt_alg;
335 int ret;
336
337 crypto_stats_get(calg);
338 ret = alg->compute_shared_secret(req);
339 crypto_stats_kpp_compute_shared_secret(calg, ret);
340 return ret;
341 }
342
343
344
345
346
347
348
349
350
351
352
353 static inline unsigned int crypto_kpp_maxsize(struct crypto_kpp *tfm)
354 {
355 struct kpp_alg *alg = crypto_kpp_alg(tfm);
356
357 return alg->max_size(tfm);
358 }
359
360 #endif