Commit 9ffde35a8edd3486cd7c80af931c15cec99a1a0d
1 parent
b9c55aa475
Exists in
master
and in
20 other branches
[CRYPTO] authenc: Use crypto_grab_skcipher
This patch converts the authenc algorithm over to crypto_grab_skcipher which is a prerequisite for IV generation. This patch also changes authenc to set its ASYNC status depending on the ASYNC status of the underlying skcipher. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Showing 1 changed file with 38 additions and 27 deletions Side-by-side Diff
crypto/authenc.c
... | ... | @@ -10,7 +10,7 @@ |
10 | 10 | * |
11 | 11 | */ |
12 | 12 | |
13 | -#include <crypto/algapi.h> | |
13 | +#include <crypto/internal/skcipher.h> | |
14 | 14 | #include <crypto/authenc.h> |
15 | 15 | #include <crypto/scatterwalk.h> |
16 | 16 | #include <linux/err.h> |
... | ... | @@ -23,7 +23,7 @@ |
23 | 23 | |
24 | 24 | struct authenc_instance_ctx { |
25 | 25 | struct crypto_spawn auth; |
26 | - struct crypto_spawn enc; | |
26 | + struct crypto_skcipher_spawn enc; | |
27 | 27 | }; |
28 | 28 | |
29 | 29 | struct crypto_authenc_ctx { |
... | ... | @@ -237,7 +237,7 @@ |
237 | 237 | if (IS_ERR(auth)) |
238 | 238 | return PTR_ERR(auth); |
239 | 239 | |
240 | - enc = crypto_spawn_ablkcipher(&ictx->enc); | |
240 | + enc = crypto_spawn_skcipher(&ictx->enc); | |
241 | 241 | err = PTR_ERR(enc); |
242 | 242 | if (IS_ERR(enc)) |
243 | 243 | goto err_free_hash; |
244 | 244 | |
245 | 245 | |
246 | 246 | |
247 | 247 | |
248 | 248 | |
249 | 249 | |
250 | 250 | |
251 | 251 | |
... | ... | @@ -270,54 +270,65 @@ |
270 | 270 | |
271 | 271 | static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb) |
272 | 272 | { |
273 | + struct crypto_attr_type *algt; | |
273 | 274 | struct crypto_instance *inst; |
274 | 275 | struct crypto_alg *auth; |
275 | 276 | struct crypto_alg *enc; |
276 | 277 | struct authenc_instance_ctx *ctx; |
278 | + const char *enc_name; | |
277 | 279 | int err; |
278 | 280 | |
279 | - err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AEAD); | |
280 | - if (err) | |
281 | + algt = crypto_get_attr_type(tb); | |
282 | + err = PTR_ERR(algt); | |
283 | + if (IS_ERR(algt)) | |
281 | 284 | return ERR_PTR(err); |
282 | 285 | |
286 | + if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) | |
287 | + return ERR_PTR(-EINVAL); | |
288 | + | |
283 | 289 | auth = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH, |
284 | 290 | CRYPTO_ALG_TYPE_HASH_MASK); |
285 | 291 | if (IS_ERR(auth)) |
286 | 292 | return ERR_PTR(PTR_ERR(auth)); |
287 | 293 | |
288 | - enc = crypto_attr_alg(tb[2], CRYPTO_ALG_TYPE_BLKCIPHER, | |
289 | - CRYPTO_ALG_TYPE_BLKCIPHER_MASK); | |
290 | - inst = ERR_PTR(PTR_ERR(enc)); | |
291 | - if (IS_ERR(enc)) | |
294 | + enc_name = crypto_attr_alg_name(tb[2]); | |
295 | + err = PTR_ERR(enc_name); | |
296 | + if (IS_ERR(enc_name)) | |
292 | 297 | goto out_put_auth; |
293 | 298 | |
294 | 299 | inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); |
295 | 300 | err = -ENOMEM; |
296 | 301 | if (!inst) |
297 | - goto out_put_enc; | |
302 | + goto out_put_auth; | |
298 | 303 | |
299 | - err = -ENAMETOOLONG; | |
300 | - if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, | |
301 | - "authenc(%s,%s)", auth->cra_name, enc->cra_name) >= | |
302 | - CRYPTO_MAX_ALG_NAME) | |
303 | - goto err_free_inst; | |
304 | - | |
305 | - if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, | |
306 | - "authenc(%s,%s)", auth->cra_driver_name, | |
307 | - enc->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) | |
308 | - goto err_free_inst; | |
309 | - | |
310 | 304 | ctx = crypto_instance_ctx(inst); |
311 | 305 | |
312 | 306 | err = crypto_init_spawn(&ctx->auth, auth, inst, CRYPTO_ALG_TYPE_MASK); |
313 | 307 | if (err) |
314 | 308 | goto err_free_inst; |
315 | 309 | |
316 | - err = crypto_init_spawn(&ctx->enc, enc, inst, CRYPTO_ALG_TYPE_MASK); | |
310 | + crypto_set_skcipher_spawn(&ctx->enc, inst); | |
311 | + err = crypto_grab_skcipher(&ctx->enc, enc_name, 0, | |
312 | + crypto_requires_sync(algt->type, | |
313 | + algt->mask)); | |
317 | 314 | if (err) |
318 | 315 | goto err_drop_auth; |
319 | 316 | |
320 | - inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC; | |
317 | + enc = crypto_skcipher_spawn_alg(&ctx->enc); | |
318 | + | |
319 | + err = -ENAMETOOLONG; | |
320 | + if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, | |
321 | + "authenc(%s,%s)", auth->cra_name, enc->cra_name) >= | |
322 | + CRYPTO_MAX_ALG_NAME) | |
323 | + goto err_drop_enc; | |
324 | + | |
325 | + if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, | |
326 | + "authenc(%s,%s)", auth->cra_driver_name, | |
327 | + enc->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) | |
328 | + goto err_drop_enc; | |
329 | + | |
330 | + inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD; | |
331 | + inst->alg.cra_flags |= enc->cra_flags & CRYPTO_ALG_ASYNC; | |
321 | 332 | inst->alg.cra_priority = enc->cra_priority * 10 + auth->cra_priority; |
322 | 333 | inst->alg.cra_blocksize = enc->cra_blocksize; |
323 | 334 | inst->alg.cra_alignmask = auth->cra_alignmask | enc->cra_alignmask; |
324 | 335 | |
325 | 336 | |
... | ... | @@ -338,16 +349,16 @@ |
338 | 349 | inst->alg.cra_aead.decrypt = crypto_authenc_decrypt; |
339 | 350 | |
340 | 351 | out: |
341 | - crypto_mod_put(enc); | |
342 | -out_put_auth: | |
343 | 352 | crypto_mod_put(auth); |
344 | 353 | return inst; |
345 | 354 | |
355 | +err_drop_enc: | |
356 | + crypto_drop_skcipher(&ctx->enc); | |
346 | 357 | err_drop_auth: |
347 | 358 | crypto_drop_spawn(&ctx->auth); |
348 | 359 | err_free_inst: |
349 | 360 | kfree(inst); |
350 | -out_put_enc: | |
361 | +out_put_auth: | |
351 | 362 | inst = ERR_PTR(err); |
352 | 363 | goto out; |
353 | 364 | } |
... | ... | @@ -356,7 +367,7 @@ |
356 | 367 | { |
357 | 368 | struct authenc_instance_ctx *ctx = crypto_instance_ctx(inst); |
358 | 369 | |
359 | - crypto_drop_spawn(&ctx->enc); | |
370 | + crypto_drop_skcipher(&ctx->enc); | |
360 | 371 | crypto_drop_spawn(&ctx->auth); |
361 | 372 | kfree(inst); |
362 | 373 | } |