aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-12-17 07:12:49 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2008-01-10 16:16:46 -0500
commit9ffde35a8edd3486cd7c80af931c15cec99a1a0d (patch)
treedd6d42e262349fda3bb907bfdbf76349685be485 /crypto
parentb9c55aa475599183d0eab6833ea23e70c52dd24b (diff)
[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>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/authenc.c65
1 files changed, 38 insertions, 27 deletions
diff --git a/crypto/authenc.c b/crypto/authenc.c
index 394e73308e31..2d609b72f5be 100644
--- a/crypto/authenc.c
+++ b/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#include <crypto/authenc.h> 14#include <crypto/authenc.h>
15#include <crypto/scatterwalk.h> 15#include <crypto/scatterwalk.h>
16#include <linux/err.h> 16#include <linux/err.h>
@@ -23,7 +23,7 @@
23 23
24struct authenc_instance_ctx { 24struct authenc_instance_ctx {
25 struct crypto_spawn auth; 25 struct crypto_spawn auth;
26 struct crypto_spawn enc; 26 struct crypto_skcipher_spawn enc;
27}; 27};
28 28
29struct crypto_authenc_ctx { 29struct crypto_authenc_ctx {
@@ -237,7 +237,7 @@ static int crypto_authenc_init_tfm(struct crypto_tfm *tfm)
237 if (IS_ERR(auth)) 237 if (IS_ERR(auth))
238 return PTR_ERR(auth); 238 return PTR_ERR(auth);
239 239
240 enc = crypto_spawn_ablkcipher(&ictx->enc); 240 enc = crypto_spawn_skcipher(&ictx->enc);
241 err = PTR_ERR(enc); 241 err = PTR_ERR(enc);
242 if (IS_ERR(enc)) 242 if (IS_ERR(enc))
243 goto err_free_hash; 243 goto err_free_hash;
@@ -270,42 +270,36 @@ static void crypto_authenc_exit_tfm(struct crypto_tfm *tfm)
270 270
271static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb) 271static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
272{ 272{
273 struct crypto_attr_type *algt;
273 struct crypto_instance *inst; 274 struct crypto_instance *inst;
274 struct crypto_alg *auth; 275 struct crypto_alg *auth;
275 struct crypto_alg *enc; 276 struct crypto_alg *enc;
276 struct authenc_instance_ctx *ctx; 277 struct authenc_instance_ctx *ctx;
278 const char *enc_name;
277 int err; 279 int err;
278 280
279 err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AEAD); 281 algt = crypto_get_attr_type(tb);
280 if (err) 282 err = PTR_ERR(algt);
283 if (IS_ERR(algt))
281 return ERR_PTR(err); 284 return ERR_PTR(err);
282 285
286 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
287 return ERR_PTR(-EINVAL);
288
283 auth = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH, 289 auth = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH,
284 CRYPTO_ALG_TYPE_HASH_MASK); 290 CRYPTO_ALG_TYPE_HASH_MASK);
285 if (IS_ERR(auth)) 291 if (IS_ERR(auth))
286 return ERR_PTR(PTR_ERR(auth)); 292 return ERR_PTR(PTR_ERR(auth));
287 293
288 enc = crypto_attr_alg(tb[2], CRYPTO_ALG_TYPE_BLKCIPHER, 294 enc_name = crypto_attr_alg_name(tb[2]);
289 CRYPTO_ALG_TYPE_BLKCIPHER_MASK); 295 err = PTR_ERR(enc_name);
290 inst = ERR_PTR(PTR_ERR(enc)); 296 if (IS_ERR(enc_name))
291 if (IS_ERR(enc))
292 goto out_put_auth; 297 goto out_put_auth;
293 298
294 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); 299 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
295 err = -ENOMEM; 300 err = -ENOMEM;
296 if (!inst) 301 if (!inst)
297 goto out_put_enc; 302 goto out_put_auth;
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;
309 303
310 ctx = crypto_instance_ctx(inst); 304 ctx = crypto_instance_ctx(inst);
311 305
@@ -313,11 +307,28 @@ static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
313 if (err) 307 if (err)
314 goto err_free_inst; 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 if (err) 314 if (err)
318 goto err_drop_auth; 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 inst->alg.cra_priority = enc->cra_priority * 10 + auth->cra_priority; 332 inst->alg.cra_priority = enc->cra_priority * 10 + auth->cra_priority;
322 inst->alg.cra_blocksize = enc->cra_blocksize; 333 inst->alg.cra_blocksize = enc->cra_blocksize;
323 inst->alg.cra_alignmask = auth->cra_alignmask | enc->cra_alignmask; 334 inst->alg.cra_alignmask = auth->cra_alignmask | enc->cra_alignmask;
@@ -338,16 +349,16 @@ static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
338 inst->alg.cra_aead.decrypt = crypto_authenc_decrypt; 349 inst->alg.cra_aead.decrypt = crypto_authenc_decrypt;
339 350
340out: 351out:
341 crypto_mod_put(enc);
342out_put_auth:
343 crypto_mod_put(auth); 352 crypto_mod_put(auth);
344 return inst; 353 return inst;
345 354
355err_drop_enc:
356 crypto_drop_skcipher(&ctx->enc);
346err_drop_auth: 357err_drop_auth:
347 crypto_drop_spawn(&ctx->auth); 358 crypto_drop_spawn(&ctx->auth);
348err_free_inst: 359err_free_inst:
349 kfree(inst); 360 kfree(inst);
350out_put_enc: 361out_put_auth:
351 inst = ERR_PTR(err); 362 inst = ERR_PTR(err);
352 goto out; 363 goto out;
353} 364}
@@ -356,7 +367,7 @@ static void crypto_authenc_free(struct crypto_instance *inst)
356{ 367{
357 struct authenc_instance_ctx *ctx = crypto_instance_ctx(inst); 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 crypto_drop_spawn(&ctx->auth); 371 crypto_drop_spawn(&ctx->auth);
361 kfree(inst); 372 kfree(inst);
362} 373}