Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

+38 -27
+38 -27
crypto/authenc.c
··· 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 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 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; ··· 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); 285 + 286 + if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) 287 + return ERR_PTR(-EINVAL); 282 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; 298 - 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; 302 + goto out_put_auth; 309 303 310 304 ctx = crypto_instance_ctx(inst); 311 305 ··· 307 313 if (err) 308 314 goto err_free_inst; 309 315 310 - err = crypto_init_spawn(&ctx->enc, enc, inst, CRYPTO_ALG_TYPE_MASK); 316 + crypto_set_skcipher_spawn(&ctx->enc, inst); 317 + err = crypto_grab_skcipher(&ctx->enc, enc_name, 0, 318 + crypto_requires_sync(algt->type, 319 + algt->mask)); 311 320 if (err) 312 321 goto err_drop_auth; 313 322 314 - inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC; 323 + enc = crypto_skcipher_spawn_alg(&ctx->enc); 324 + 325 + err = -ENAMETOOLONG; 326 + if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, 327 + "authenc(%s,%s)", auth->cra_name, enc->cra_name) >= 328 + CRYPTO_MAX_ALG_NAME) 329 + goto err_drop_enc; 330 + 331 + if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, 332 + "authenc(%s,%s)", auth->cra_driver_name, 333 + enc->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) 334 + goto err_drop_enc; 335 + 336 + inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD; 337 + inst->alg.cra_flags |= enc->cra_flags & CRYPTO_ALG_ASYNC; 315 338 inst->alg.cra_priority = enc->cra_priority * 10 + auth->cra_priority; 316 339 inst->alg.cra_blocksize = enc->cra_blocksize; 317 340 inst->alg.cra_alignmask = auth->cra_alignmask | enc->cra_alignmask; ··· 349 338 inst->alg.cra_aead.decrypt = crypto_authenc_decrypt; 350 339 351 340 out: 352 - crypto_mod_put(enc); 353 - out_put_auth: 354 341 crypto_mod_put(auth); 355 342 return inst; 356 343 344 + err_drop_enc: 345 + crypto_drop_skcipher(&ctx->enc); 357 346 err_drop_auth: 358 347 crypto_drop_spawn(&ctx->auth); 359 348 err_free_inst: 360 349 kfree(inst); 361 - out_put_enc: 350 + out_put_auth: 362 351 inst = ERR_PTR(err); 363 352 goto out; 364 353 } ··· 367 356 { 368 357 struct authenc_instance_ctx *ctx = crypto_instance_ctx(inst); 369 358 370 - crypto_drop_spawn(&ctx->enc); 359 + crypto_drop_skcipher(&ctx->enc); 371 360 crypto_drop_spawn(&ctx->auth); 372 361 kfree(inst); 373 362 }