Commit cbdcf80d8b9486ddb699a044c6f87f25821708cb
Committed by
Herbert Xu
1 parent
ab30046567
Exists in
master
and in
20 other branches
crypto: authenc - Convert to ahash
This patch converts authenc to the new ahash interface. Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Showing 1 changed file with 285 additions and 69 deletions Side-by-side Diff
crypto/authenc.c
... | ... | @@ -23,24 +23,36 @@ |
23 | 23 | #include <linux/slab.h> |
24 | 24 | #include <linux/spinlock.h> |
25 | 25 | |
26 | +typedef u8 *(*authenc_ahash_t)(struct aead_request *req, unsigned int flags); | |
27 | + | |
26 | 28 | struct authenc_instance_ctx { |
27 | - struct crypto_spawn auth; | |
29 | + struct crypto_ahash_spawn auth; | |
28 | 30 | struct crypto_skcipher_spawn enc; |
29 | 31 | }; |
30 | 32 | |
31 | 33 | struct crypto_authenc_ctx { |
32 | - spinlock_t auth_lock; | |
33 | - struct crypto_hash *auth; | |
34 | + unsigned int reqoff; | |
35 | + struct crypto_ahash *auth; | |
34 | 36 | struct crypto_ablkcipher *enc; |
35 | 37 | }; |
36 | 38 | |
39 | +struct authenc_request_ctx { | |
40 | + unsigned int cryptlen; | |
41 | + struct scatterlist *sg; | |
42 | + struct scatterlist asg[2]; | |
43 | + struct scatterlist cipher[2]; | |
44 | + crypto_completion_t complete; | |
45 | + crypto_completion_t update_complete; | |
46 | + char tail[]; | |
47 | +}; | |
48 | + | |
37 | 49 | static int crypto_authenc_setkey(struct crypto_aead *authenc, const u8 *key, |
38 | 50 | unsigned int keylen) |
39 | 51 | { |
40 | 52 | unsigned int authkeylen; |
41 | 53 | unsigned int enckeylen; |
42 | 54 | struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); |
43 | - struct crypto_hash *auth = ctx->auth; | |
55 | + struct crypto_ahash *auth = ctx->auth; | |
44 | 56 | struct crypto_ablkcipher *enc = ctx->enc; |
45 | 57 | struct rtattr *rta = (void *)key; |
46 | 58 | struct crypto_authenc_key_param *param; |
47 | 59 | |
... | ... | @@ -64,11 +76,11 @@ |
64 | 76 | |
65 | 77 | authkeylen = keylen - enckeylen; |
66 | 78 | |
67 | - crypto_hash_clear_flags(auth, CRYPTO_TFM_REQ_MASK); | |
68 | - crypto_hash_set_flags(auth, crypto_aead_get_flags(authenc) & | |
79 | + crypto_ahash_clear_flags(auth, CRYPTO_TFM_REQ_MASK); | |
80 | + crypto_ahash_set_flags(auth, crypto_aead_get_flags(authenc) & | |
69 | 81 | CRYPTO_TFM_REQ_MASK); |
70 | - err = crypto_hash_setkey(auth, key, authkeylen); | |
71 | - crypto_aead_set_flags(authenc, crypto_hash_get_flags(auth) & | |
82 | + err = crypto_ahash_setkey(auth, key, authkeylen); | |
83 | + crypto_aead_set_flags(authenc, crypto_ahash_get_flags(auth) & | |
72 | 84 | CRYPTO_TFM_RES_MASK); |
73 | 85 | |
74 | 86 | if (err) |
75 | 87 | |
76 | 88 | |
77 | 89 | |
78 | 90 | |
79 | 91 | |
80 | 92 | |
81 | 93 | |
82 | 94 | |
83 | 95 | |
84 | 96 | |
85 | 97 | |
... | ... | @@ -103,40 +115,198 @@ |
103 | 115 | sg_mark_end(head); |
104 | 116 | } |
105 | 117 | |
106 | -static u8 *crypto_authenc_hash(struct aead_request *req, unsigned int flags, | |
107 | - struct scatterlist *cipher, | |
108 | - unsigned int cryptlen) | |
118 | +static void authenc_geniv_ahash_update_done(struct crypto_async_request *areq, | |
119 | + int err) | |
109 | 120 | { |
121 | + struct aead_request *req = areq->data; | |
110 | 122 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
111 | 123 | struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); |
112 | - struct crypto_hash *auth = ctx->auth; | |
113 | - struct hash_desc desc = { | |
114 | - .tfm = auth, | |
115 | - .flags = aead_request_flags(req) & flags, | |
116 | - }; | |
117 | - u8 *hash = aead_request_ctx(req); | |
124 | + struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); | |
125 | + struct ahash_request *ahreq = (void *)(areq_ctx->tail + ctx->reqoff); | |
126 | + | |
127 | + if (err) | |
128 | + goto out; | |
129 | + | |
130 | + ahash_request_set_crypt(ahreq, areq_ctx->sg, ahreq->result, | |
131 | + areq_ctx->cryptlen); | |
132 | + ahash_request_set_callback(ahreq, aead_request_flags(req) & | |
133 | + CRYPTO_TFM_REQ_MAY_SLEEP, | |
134 | + areq_ctx->complete, req); | |
135 | + | |
136 | + err = crypto_ahash_finup(ahreq); | |
137 | + if (err) | |
138 | + goto out; | |
139 | + | |
140 | + scatterwalk_map_and_copy(ahreq->result, areq_ctx->sg, | |
141 | + areq_ctx->cryptlen, | |
142 | + crypto_aead_authsize(authenc), 1); | |
143 | + | |
144 | +out: | |
145 | + aead_request_complete(req, err); | |
146 | +} | |
147 | + | |
148 | +static void authenc_geniv_ahash_done(struct crypto_async_request *areq, int err) | |
149 | +{ | |
150 | + struct aead_request *req = areq->data; | |
151 | + struct crypto_aead *authenc = crypto_aead_reqtfm(req); | |
152 | + struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); | |
153 | + struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); | |
154 | + struct ahash_request *ahreq = (void *)(areq_ctx->tail + ctx->reqoff); | |
155 | + | |
156 | + if (err) | |
157 | + goto out; | |
158 | + | |
159 | + scatterwalk_map_and_copy(ahreq->result, areq_ctx->sg, | |
160 | + areq_ctx->cryptlen, | |
161 | + crypto_aead_authsize(authenc), 1); | |
162 | + | |
163 | +out: | |
164 | + aead_request_complete(req, err); | |
165 | +} | |
166 | + | |
167 | +static void authenc_verify_ahash_update_done(struct crypto_async_request *areq, | |
168 | + int err) | |
169 | +{ | |
170 | + u8 *ihash; | |
171 | + unsigned int authsize; | |
172 | + struct ablkcipher_request *abreq; | |
173 | + struct aead_request *req = areq->data; | |
174 | + struct crypto_aead *authenc = crypto_aead_reqtfm(req); | |
175 | + struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); | |
176 | + struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); | |
177 | + struct ahash_request *ahreq = (void *)(areq_ctx->tail + ctx->reqoff); | |
178 | + | |
179 | + if (err) | |
180 | + goto out; | |
181 | + | |
182 | + ahash_request_set_crypt(ahreq, areq_ctx->sg, ahreq->result, | |
183 | + areq_ctx->cryptlen); | |
184 | + ahash_request_set_callback(ahreq, aead_request_flags(req) & | |
185 | + CRYPTO_TFM_REQ_MAY_SLEEP, | |
186 | + areq_ctx->complete, req); | |
187 | + | |
188 | + err = crypto_ahash_finup(ahreq); | |
189 | + if (err) | |
190 | + goto out; | |
191 | + | |
192 | + authsize = crypto_aead_authsize(authenc); | |
193 | + ihash = ahreq->result + authsize; | |
194 | + scatterwalk_map_and_copy(ihash, areq_ctx->sg, areq_ctx->cryptlen, | |
195 | + authsize, 0); | |
196 | + | |
197 | + err = memcmp(ihash, ahreq->result, authsize) ? -EBADMSG: 0; | |
198 | + if (err) | |
199 | + goto out; | |
200 | + | |
201 | + abreq = aead_request_ctx(req); | |
202 | + ablkcipher_request_set_tfm(abreq, ctx->enc); | |
203 | + ablkcipher_request_set_callback(abreq, aead_request_flags(req), | |
204 | + req->base.complete, req->base.data); | |
205 | + ablkcipher_request_set_crypt(abreq, req->src, req->dst, | |
206 | + req->cryptlen, req->iv); | |
207 | + | |
208 | + err = crypto_ablkcipher_decrypt(abreq); | |
209 | + | |
210 | +out: | |
211 | + aead_request_complete(req, err); | |
212 | +} | |
213 | + | |
214 | +static void authenc_verify_ahash_done(struct crypto_async_request *areq, | |
215 | + int err) | |
216 | +{ | |
217 | + u8 *ihash; | |
218 | + unsigned int authsize; | |
219 | + struct ablkcipher_request *abreq; | |
220 | + struct aead_request *req = areq->data; | |
221 | + struct crypto_aead *authenc = crypto_aead_reqtfm(req); | |
222 | + struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); | |
223 | + struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); | |
224 | + struct ahash_request *ahreq = (void *)(areq_ctx->tail + ctx->reqoff); | |
225 | + | |
226 | + if (err) | |
227 | + goto out; | |
228 | + | |
229 | + authsize = crypto_aead_authsize(authenc); | |
230 | + ihash = ahreq->result + authsize; | |
231 | + scatterwalk_map_and_copy(ihash, areq_ctx->sg, areq_ctx->cryptlen, | |
232 | + authsize, 0); | |
233 | + | |
234 | + err = memcmp(ihash, ahreq->result, authsize) ? -EBADMSG: 0; | |
235 | + if (err) | |
236 | + goto out; | |
237 | + | |
238 | + abreq = aead_request_ctx(req); | |
239 | + ablkcipher_request_set_tfm(abreq, ctx->enc); | |
240 | + ablkcipher_request_set_callback(abreq, aead_request_flags(req), | |
241 | + req->base.complete, req->base.data); | |
242 | + ablkcipher_request_set_crypt(abreq, req->src, req->dst, | |
243 | + req->cryptlen, req->iv); | |
244 | + | |
245 | + err = crypto_ablkcipher_decrypt(abreq); | |
246 | + | |
247 | +out: | |
248 | + aead_request_complete(req, err); | |
249 | +} | |
250 | + | |
251 | +static u8 *crypto_authenc_ahash_fb(struct aead_request *req, unsigned int flags) | |
252 | +{ | |
253 | + struct crypto_aead *authenc = crypto_aead_reqtfm(req); | |
254 | + struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); | |
255 | + struct crypto_ahash *auth = ctx->auth; | |
256 | + struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); | |
257 | + struct ahash_request *ahreq = (void *)(areq_ctx->tail + ctx->reqoff); | |
258 | + u8 *hash = areq_ctx->tail; | |
118 | 259 | int err; |
119 | 260 | |
120 | - hash = (u8 *)ALIGN((unsigned long)hash + crypto_hash_alignmask(auth), | |
121 | - crypto_hash_alignmask(auth) + 1); | |
261 | + hash = (u8 *)ALIGN((unsigned long)hash + crypto_ahash_alignmask(auth), | |
262 | + crypto_ahash_alignmask(auth) + 1); | |
122 | 263 | |
123 | - spin_lock_bh(&ctx->auth_lock); | |
124 | - err = crypto_hash_init(&desc); | |
264 | + ahash_request_set_tfm(ahreq, auth); | |
265 | + | |
266 | + err = crypto_ahash_init(ahreq); | |
125 | 267 | if (err) |
126 | - goto auth_unlock; | |
268 | + return ERR_PTR(err); | |
127 | 269 | |
128 | - err = crypto_hash_update(&desc, req->assoc, req->assoclen); | |
270 | + ahash_request_set_crypt(ahreq, req->assoc, hash, req->assoclen); | |
271 | + ahash_request_set_callback(ahreq, aead_request_flags(req) & flags, | |
272 | + areq_ctx->update_complete, req); | |
273 | + | |
274 | + err = crypto_ahash_update(ahreq); | |
129 | 275 | if (err) |
130 | - goto auth_unlock; | |
276 | + return ERR_PTR(err); | |
131 | 277 | |
132 | - err = crypto_hash_update(&desc, cipher, cryptlen); | |
278 | + ahash_request_set_crypt(ahreq, areq_ctx->sg, hash, | |
279 | + areq_ctx->cryptlen); | |
280 | + ahash_request_set_callback(ahreq, aead_request_flags(req) & flags, | |
281 | + areq_ctx->complete, req); | |
282 | + | |
283 | + err = crypto_ahash_finup(ahreq); | |
133 | 284 | if (err) |
134 | - goto auth_unlock; | |
285 | + return ERR_PTR(err); | |
135 | 286 | |
136 | - err = crypto_hash_final(&desc, hash); | |
137 | -auth_unlock: | |
138 | - spin_unlock_bh(&ctx->auth_lock); | |
287 | + return hash; | |
288 | +} | |
139 | 289 | |
290 | +static u8 *crypto_authenc_ahash(struct aead_request *req, unsigned int flags) | |
291 | +{ | |
292 | + struct crypto_aead *authenc = crypto_aead_reqtfm(req); | |
293 | + struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); | |
294 | + struct crypto_ahash *auth = ctx->auth; | |
295 | + struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); | |
296 | + struct ahash_request *ahreq = (void *)(areq_ctx->tail + ctx->reqoff); | |
297 | + u8 *hash = areq_ctx->tail; | |
298 | + int err; | |
299 | + | |
300 | + hash = (u8 *)ALIGN((unsigned long)hash + crypto_ahash_alignmask(auth), | |
301 | + crypto_ahash_alignmask(auth) + 1); | |
302 | + | |
303 | + ahash_request_set_tfm(ahreq, auth); | |
304 | + ahash_request_set_crypt(ahreq, areq_ctx->sg, hash, | |
305 | + areq_ctx->cryptlen); | |
306 | + ahash_request_set_callback(ahreq, aead_request_flags(req) & flags, | |
307 | + areq_ctx->complete, req); | |
308 | + | |
309 | + err = crypto_ahash_digest(ahreq); | |
140 | 310 | if (err) |
141 | 311 | return ERR_PTR(err); |
142 | 312 | |
143 | 313 | |
144 | 314 | |
... | ... | @@ -147,11 +317,15 @@ |
147 | 317 | unsigned int flags) |
148 | 318 | { |
149 | 319 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
320 | + struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); | |
150 | 321 | struct scatterlist *dst = req->dst; |
151 | - struct scatterlist cipher[2]; | |
152 | - struct page *dstp; | |
322 | + struct scatterlist *assoc = req->assoc; | |
323 | + struct scatterlist *cipher = areq_ctx->cipher; | |
324 | + struct scatterlist *asg = areq_ctx->asg; | |
153 | 325 | unsigned int ivsize = crypto_aead_ivsize(authenc); |
154 | - unsigned int cryptlen; | |
326 | + unsigned int cryptlen = req->cryptlen; | |
327 | + authenc_ahash_t authenc_ahash_fn = crypto_authenc_ahash_fb; | |
328 | + struct page *dstp; | |
155 | 329 | u8 *vdst; |
156 | 330 | u8 *hash; |
157 | 331 | |
158 | 332 | |
... | ... | @@ -163,10 +337,25 @@ |
163 | 337 | sg_set_buf(cipher, iv, ivsize); |
164 | 338 | authenc_chain(cipher, dst, vdst == iv + ivsize); |
165 | 339 | dst = cipher; |
340 | + cryptlen += ivsize; | |
166 | 341 | } |
167 | 342 | |
168 | - cryptlen = req->cryptlen + ivsize; | |
169 | - hash = crypto_authenc_hash(req, flags, dst, cryptlen); | |
343 | + if (sg_is_last(assoc)) { | |
344 | + authenc_ahash_fn = crypto_authenc_ahash; | |
345 | + sg_init_table(asg, 2); | |
346 | + sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset); | |
347 | + authenc_chain(asg, dst, 0); | |
348 | + dst = asg; | |
349 | + cryptlen += req->assoclen; | |
350 | + } | |
351 | + | |
352 | + areq_ctx->cryptlen = cryptlen; | |
353 | + areq_ctx->sg = dst; | |
354 | + | |
355 | + areq_ctx->complete = authenc_geniv_ahash_done; | |
356 | + areq_ctx->update_complete = authenc_geniv_ahash_update_done; | |
357 | + | |
358 | + hash = authenc_ahash_fn(req, flags); | |
170 | 359 | if (IS_ERR(hash)) |
171 | 360 | return PTR_ERR(hash); |
172 | 361 | |
173 | 362 | |
174 | 363 | |
175 | 364 | |
... | ... | @@ -256,22 +445,25 @@ |
256 | 445 | } |
257 | 446 | |
258 | 447 | static int crypto_authenc_verify(struct aead_request *req, |
259 | - struct scatterlist *cipher, | |
260 | - unsigned int cryptlen) | |
448 | + authenc_ahash_t authenc_ahash_fn) | |
261 | 449 | { |
262 | 450 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
451 | + struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); | |
263 | 452 | u8 *ohash; |
264 | 453 | u8 *ihash; |
265 | 454 | unsigned int authsize; |
266 | 455 | |
267 | - ohash = crypto_authenc_hash(req, CRYPTO_TFM_REQ_MAY_SLEEP, cipher, | |
268 | - cryptlen); | |
456 | + areq_ctx->complete = authenc_verify_ahash_done; | |
457 | + areq_ctx->complete = authenc_verify_ahash_update_done; | |
458 | + | |
459 | + ohash = authenc_ahash_fn(req, CRYPTO_TFM_REQ_MAY_SLEEP); | |
269 | 460 | if (IS_ERR(ohash)) |
270 | 461 | return PTR_ERR(ohash); |
271 | 462 | |
272 | 463 | authsize = crypto_aead_authsize(authenc); |
273 | 464 | ihash = ohash + authsize; |
274 | - scatterwalk_map_and_copy(ihash, cipher, cryptlen, authsize, 0); | |
465 | + scatterwalk_map_and_copy(ihash, areq_ctx->sg, areq_ctx->cryptlen, | |
466 | + authsize, 0); | |
275 | 467 | return memcmp(ihash, ohash, authsize) ? -EBADMSG: 0; |
276 | 468 | } |
277 | 469 | |
278 | 470 | |
279 | 471 | |
... | ... | @@ -279,10 +471,14 @@ |
279 | 471 | unsigned int cryptlen) |
280 | 472 | { |
281 | 473 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
474 | + struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); | |
282 | 475 | struct scatterlist *src = req->src; |
283 | - struct scatterlist cipher[2]; | |
284 | - struct page *srcp; | |
476 | + struct scatterlist *assoc = req->assoc; | |
477 | + struct scatterlist *cipher = areq_ctx->cipher; | |
478 | + struct scatterlist *asg = areq_ctx->asg; | |
285 | 479 | unsigned int ivsize = crypto_aead_ivsize(authenc); |
480 | + authenc_ahash_t authenc_ahash_fn = crypto_authenc_ahash_fb; | |
481 | + struct page *srcp; | |
286 | 482 | u8 *vsrc; |
287 | 483 | |
288 | 484 | srcp = sg_page(src); |
289 | 485 | |
... | ... | @@ -293,9 +489,22 @@ |
293 | 489 | sg_set_buf(cipher, iv, ivsize); |
294 | 490 | authenc_chain(cipher, src, vsrc == iv + ivsize); |
295 | 491 | src = cipher; |
492 | + cryptlen += ivsize; | |
296 | 493 | } |
297 | 494 | |
298 | - return crypto_authenc_verify(req, src, cryptlen + ivsize); | |
495 | + if (sg_is_last(assoc)) { | |
496 | + authenc_ahash_fn = crypto_authenc_ahash; | |
497 | + sg_init_table(asg, 2); | |
498 | + sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset); | |
499 | + authenc_chain(asg, src, 0); | |
500 | + src = asg; | |
501 | + cryptlen += req->assoclen; | |
502 | + } | |
503 | + | |
504 | + areq_ctx->cryptlen = cryptlen; | |
505 | + areq_ctx->sg = src; | |
506 | + | |
507 | + return crypto_authenc_verify(req, authenc_ahash_fn); | |
299 | 508 | } |
300 | 509 | |
301 | 510 | static int crypto_authenc_decrypt(struct aead_request *req) |
302 | 511 | |
303 | 512 | |
304 | 513 | |
305 | 514 | |
306 | 515 | |
307 | 516 | |
308 | 517 | |
309 | 518 | |
... | ... | @@ -326,38 +535,41 @@ |
326 | 535 | |
327 | 536 | static int crypto_authenc_init_tfm(struct crypto_tfm *tfm) |
328 | 537 | { |
329 | - struct crypto_instance *inst = (void *)tfm->__crt_alg; | |
538 | + struct crypto_instance *inst = crypto_tfm_alg_instance(tfm); | |
330 | 539 | struct authenc_instance_ctx *ictx = crypto_instance_ctx(inst); |
331 | 540 | struct crypto_authenc_ctx *ctx = crypto_tfm_ctx(tfm); |
332 | - struct crypto_hash *auth; | |
541 | + struct crypto_ahash *auth; | |
333 | 542 | struct crypto_ablkcipher *enc; |
334 | 543 | int err; |
335 | 544 | |
336 | - auth = crypto_spawn_hash(&ictx->auth); | |
545 | + auth = crypto_spawn_ahash(&ictx->auth); | |
337 | 546 | if (IS_ERR(auth)) |
338 | 547 | return PTR_ERR(auth); |
339 | 548 | |
549 | + ctx->reqoff = ALIGN(2 * crypto_ahash_digestsize(auth) + | |
550 | + crypto_ahash_alignmask(auth), | |
551 | + crypto_ahash_alignmask(auth) + 1); | |
552 | + | |
340 | 553 | enc = crypto_spawn_skcipher(&ictx->enc); |
341 | 554 | err = PTR_ERR(enc); |
342 | 555 | if (IS_ERR(enc)) |
343 | - goto err_free_hash; | |
556 | + goto err_free_ahash; | |
344 | 557 | |
345 | 558 | ctx->auth = auth; |
346 | 559 | ctx->enc = enc; |
560 | + | |
347 | 561 | tfm->crt_aead.reqsize = max_t(unsigned int, |
348 | - (crypto_hash_alignmask(auth) & | |
349 | - ~(crypto_tfm_ctx_alignment() - 1)) + | |
350 | - crypto_hash_digestsize(auth) * 2, | |
351 | - sizeof(struct skcipher_givcrypt_request) + | |
352 | - crypto_ablkcipher_reqsize(enc) + | |
353 | - crypto_ablkcipher_ivsize(enc)); | |
562 | + crypto_ahash_reqsize(auth) + ctx->reqoff + | |
563 | + sizeof(struct authenc_request_ctx) + | |
564 | + sizeof(struct ahash_request), | |
565 | + sizeof(struct skcipher_givcrypt_request) + | |
566 | + crypto_ablkcipher_reqsize(enc) + | |
567 | + crypto_ablkcipher_ivsize(enc)); | |
354 | 568 | |
355 | - spin_lock_init(&ctx->auth_lock); | |
356 | - | |
357 | 569 | return 0; |
358 | 570 | |
359 | -err_free_hash: | |
360 | - crypto_free_hash(auth); | |
571 | +err_free_ahash: | |
572 | + crypto_free_ahash(auth); | |
361 | 573 | return err; |
362 | 574 | } |
363 | 575 | |
... | ... | @@ -365,7 +577,7 @@ |
365 | 577 | { |
366 | 578 | struct crypto_authenc_ctx *ctx = crypto_tfm_ctx(tfm); |
367 | 579 | |
368 | - crypto_free_hash(ctx->auth); | |
580 | + crypto_free_ahash(ctx->auth); | |
369 | 581 | crypto_free_ablkcipher(ctx->enc); |
370 | 582 | } |
371 | 583 | |
... | ... | @@ -373,7 +585,8 @@ |
373 | 585 | { |
374 | 586 | struct crypto_attr_type *algt; |
375 | 587 | struct crypto_instance *inst; |
376 | - struct crypto_alg *auth; | |
588 | + struct hash_alg_common *auth; | |
589 | + struct crypto_alg *auth_base; | |
377 | 590 | struct crypto_alg *enc; |
378 | 591 | struct authenc_instance_ctx *ctx; |
379 | 592 | const char *enc_name; |
380 | 593 | |
... | ... | @@ -387,11 +600,13 @@ |
387 | 600 | if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) |
388 | 601 | return ERR_PTR(-EINVAL); |
389 | 602 | |
390 | - auth = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH, | |
391 | - CRYPTO_ALG_TYPE_HASH_MASK); | |
603 | + auth = ahash_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH, | |
604 | + CRYPTO_ALG_TYPE_AHASH_MASK); | |
392 | 605 | if (IS_ERR(auth)) |
393 | 606 | return ERR_PTR(PTR_ERR(auth)); |
394 | 607 | |
608 | + auth_base = &auth->base; | |
609 | + | |
395 | 610 | enc_name = crypto_attr_alg_name(tb[2]); |
396 | 611 | err = PTR_ERR(enc_name); |
397 | 612 | if (IS_ERR(enc_name)) |
... | ... | @@ -404,7 +619,7 @@ |
404 | 619 | |
405 | 620 | ctx = crypto_instance_ctx(inst); |
406 | 621 | |
407 | - err = crypto_init_spawn(&ctx->auth, auth, inst, CRYPTO_ALG_TYPE_MASK); | |
622 | + err = crypto_init_ahash_spawn(&ctx->auth, auth, inst); | |
408 | 623 | if (err) |
409 | 624 | goto err_free_inst; |
410 | 625 | |
411 | 626 | |
412 | 627 | |
413 | 628 | |
414 | 629 | |
... | ... | @@ -419,24 +634,25 @@ |
419 | 634 | |
420 | 635 | err = -ENAMETOOLONG; |
421 | 636 | if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, |
422 | - "authenc(%s,%s)", auth->cra_name, enc->cra_name) >= | |
637 | + "authenc(%s,%s)", auth_base->cra_name, enc->cra_name) >= | |
423 | 638 | CRYPTO_MAX_ALG_NAME) |
424 | 639 | goto err_drop_enc; |
425 | 640 | |
426 | 641 | if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
427 | - "authenc(%s,%s)", auth->cra_driver_name, | |
642 | + "authenc(%s,%s)", auth_base->cra_driver_name, | |
428 | 643 | enc->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) |
429 | 644 | goto err_drop_enc; |
430 | 645 | |
431 | 646 | inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD; |
432 | 647 | inst->alg.cra_flags |= enc->cra_flags & CRYPTO_ALG_ASYNC; |
433 | - inst->alg.cra_priority = enc->cra_priority * 10 + auth->cra_priority; | |
648 | + inst->alg.cra_priority = enc->cra_priority * | |
649 | + 10 + auth_base->cra_priority; | |
434 | 650 | inst->alg.cra_blocksize = enc->cra_blocksize; |
435 | - inst->alg.cra_alignmask = auth->cra_alignmask | enc->cra_alignmask; | |
651 | + inst->alg.cra_alignmask = auth_base->cra_alignmask | enc->cra_alignmask; | |
436 | 652 | inst->alg.cra_type = &crypto_aead_type; |
437 | 653 | |
438 | 654 | inst->alg.cra_aead.ivsize = enc->cra_ablkcipher.ivsize; |
439 | - inst->alg.cra_aead.maxauthsize = __crypto_shash_alg(auth)->digestsize; | |
655 | + inst->alg.cra_aead.maxauthsize = auth->digestsize; | |
440 | 656 | |
441 | 657 | inst->alg.cra_ctxsize = sizeof(struct crypto_authenc_ctx); |
442 | 658 | |
443 | 659 | |
... | ... | @@ -449,13 +665,13 @@ |
449 | 665 | inst->alg.cra_aead.givencrypt = crypto_authenc_givencrypt; |
450 | 666 | |
451 | 667 | out: |
452 | - crypto_mod_put(auth); | |
668 | + crypto_mod_put(auth_base); | |
453 | 669 | return inst; |
454 | 670 | |
455 | 671 | err_drop_enc: |
456 | 672 | crypto_drop_skcipher(&ctx->enc); |
457 | 673 | err_drop_auth: |
458 | - crypto_drop_spawn(&ctx->auth); | |
674 | + crypto_drop_ahash(&ctx->auth); | |
459 | 675 | err_free_inst: |
460 | 676 | kfree(inst); |
461 | 677 | out_put_auth: |
... | ... | @@ -468,7 +684,7 @@ |
468 | 684 | struct authenc_instance_ctx *ctx = crypto_instance_ctx(inst); |
469 | 685 | |
470 | 686 | crypto_drop_skcipher(&ctx->enc); |
471 | - crypto_drop_spawn(&ctx->auth); | |
687 | + crypto_drop_ahash(&ctx->auth); | |
472 | 688 | kfree(inst); |
473 | 689 | } |
474 | 690 |