aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2009-07-12 09:38:59 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2009-07-14 00:58:10 -0400
commit46309d8938122dff2fe59bf163307989cd22ea4a (patch)
tree7a2987245bd2a0c90ea234663c2488cfa9e0be4d
parent7eddf95ec5440d60f10963f453e27f82f394044e (diff)
crypto: cryptd - Use shash algorithms
This patch changes cryptd to use shash algorithms instead of the legacy hash interface. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/cryptd.c164
1 files changed, 84 insertions, 80 deletions
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index ae5fa99d5d36..ef5720cf1216 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -39,6 +39,11 @@ struct cryptd_instance_ctx {
39 struct cryptd_queue *queue; 39 struct cryptd_queue *queue;
40}; 40};
41 41
42struct hashd_instance_ctx {
43 struct crypto_shash_spawn spawn;
44 struct cryptd_queue *queue;
45};
46
42struct cryptd_blkcipher_ctx { 47struct cryptd_blkcipher_ctx {
43 struct crypto_blkcipher *child; 48 struct crypto_blkcipher *child;
44}; 49};
@@ -48,11 +53,12 @@ struct cryptd_blkcipher_request_ctx {
48}; 53};
49 54
50struct cryptd_hash_ctx { 55struct cryptd_hash_ctx {
51 struct crypto_hash *child; 56 struct crypto_shash *child;
52}; 57};
53 58
54struct cryptd_hash_request_ctx { 59struct cryptd_hash_request_ctx {
55 crypto_completion_t complete; 60 crypto_completion_t complete;
61 struct shash_desc desc;
56}; 62};
57 63
58static void cryptd_queue_worker(struct work_struct *work); 64static void cryptd_queue_worker(struct work_struct *work);
@@ -250,13 +256,12 @@ static void cryptd_blkcipher_exit_tfm(struct crypto_tfm *tfm)
250} 256}
251 257
252static struct crypto_instance *cryptd_alloc_instance(struct crypto_alg *alg, 258static struct crypto_instance *cryptd_alloc_instance(struct crypto_alg *alg,
253 struct cryptd_queue *queue) 259 unsigned int tail)
254{ 260{
255 struct crypto_instance *inst; 261 struct crypto_instance *inst;
256 struct cryptd_instance_ctx *ctx;
257 int err; 262 int err;
258 263
259 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); 264 inst = kzalloc(sizeof(*inst) + tail, GFP_KERNEL);
260 if (!inst) { 265 if (!inst) {
261 inst = ERR_PTR(-ENOMEM); 266 inst = ERR_PTR(-ENOMEM);
262 goto out; 267 goto out;
@@ -267,14 +272,6 @@ static struct crypto_instance *cryptd_alloc_instance(struct crypto_alg *alg,
267 "cryptd(%s)", alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) 272 "cryptd(%s)", alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
268 goto out_free_inst; 273 goto out_free_inst;
269 274
270 ctx = crypto_instance_ctx(inst);
271 err = crypto_init_spawn(&ctx->spawn, alg, inst,
272 CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
273 if (err)
274 goto out_free_inst;
275
276 ctx->queue = queue;
277
278 memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME); 275 memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
279 276
280 inst->alg.cra_priority = alg->cra_priority + 50; 277 inst->alg.cra_priority = alg->cra_priority + 50;
@@ -293,18 +290,28 @@ out_free_inst:
293static struct crypto_instance *cryptd_alloc_blkcipher( 290static struct crypto_instance *cryptd_alloc_blkcipher(
294 struct rtattr **tb, struct cryptd_queue *queue) 291 struct rtattr **tb, struct cryptd_queue *queue)
295{ 292{
293 struct cryptd_instance_ctx *ctx;
296 struct crypto_instance *inst; 294 struct crypto_instance *inst;
297 struct crypto_alg *alg; 295 struct crypto_alg *alg;
296 int err;
298 297
299 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER, 298 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER,
300 CRYPTO_ALG_TYPE_MASK); 299 CRYPTO_ALG_TYPE_MASK);
301 if (IS_ERR(alg)) 300 if (IS_ERR(alg))
302 return ERR_CAST(alg); 301 return ERR_CAST(alg);
303 302
304 inst = cryptd_alloc_instance(alg, queue); 303 inst = cryptd_alloc_instance(alg, sizeof(*ctx));
305 if (IS_ERR(inst)) 304 if (IS_ERR(inst))
306 goto out_put_alg; 305 goto out_put_alg;
307 306
307 ctx = crypto_instance_ctx(inst);
308 ctx->queue = queue;
309
310 err = crypto_init_spawn(&ctx->spawn, alg, inst,
311 CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
312 if (err)
313 goto out_free_inst;
314
308 inst->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC; 315 inst->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC;
309 inst->alg.cra_type = &crypto_ablkcipher_type; 316 inst->alg.cra_type = &crypto_ablkcipher_type;
310 317
@@ -326,23 +333,28 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
326out_put_alg: 333out_put_alg:
327 crypto_mod_put(alg); 334 crypto_mod_put(alg);
328 return inst; 335 return inst;
336
337out_free_inst:
338 kfree(inst);
339 inst = ERR_PTR(err);
340 goto out_put_alg;
329} 341}
330 342
331static int cryptd_hash_init_tfm(struct crypto_tfm *tfm) 343static int cryptd_hash_init_tfm(struct crypto_tfm *tfm)
332{ 344{
333 struct crypto_instance *inst = crypto_tfm_alg_instance(tfm); 345 struct crypto_instance *inst = crypto_tfm_alg_instance(tfm);
334 struct cryptd_instance_ctx *ictx = crypto_instance_ctx(inst); 346 struct hashd_instance_ctx *ictx = crypto_instance_ctx(inst);
335 struct crypto_spawn *spawn = &ictx->spawn; 347 struct crypto_shash_spawn *spawn = &ictx->spawn;
336 struct cryptd_hash_ctx *ctx = crypto_tfm_ctx(tfm); 348 struct cryptd_hash_ctx *ctx = crypto_tfm_ctx(tfm);
337 struct crypto_hash *cipher; 349 struct crypto_shash *hash;
338 350
339 cipher = crypto_spawn_hash(spawn); 351 hash = crypto_spawn_shash(spawn);
340 if (IS_ERR(cipher)) 352 if (IS_ERR(hash))
341 return PTR_ERR(cipher); 353 return PTR_ERR(hash);
342 354
343 ctx->child = cipher; 355 ctx->child = hash;
344 tfm->crt_ahash.reqsize = 356 tfm->crt_ahash.reqsize = sizeof(struct cryptd_hash_request_ctx) +
345 sizeof(struct cryptd_hash_request_ctx); 357 crypto_shash_descsize(hash);
346 return 0; 358 return 0;
347} 359}
348 360
@@ -350,22 +362,22 @@ static void cryptd_hash_exit_tfm(struct crypto_tfm *tfm)
350{ 362{
351 struct cryptd_hash_ctx *ctx = crypto_tfm_ctx(tfm); 363 struct cryptd_hash_ctx *ctx = crypto_tfm_ctx(tfm);
352 364
353 crypto_free_hash(ctx->child); 365 crypto_free_shash(ctx->child);
354} 366}
355 367
356static int cryptd_hash_setkey(struct crypto_ahash *parent, 368static int cryptd_hash_setkey(struct crypto_ahash *parent,
357 const u8 *key, unsigned int keylen) 369 const u8 *key, unsigned int keylen)
358{ 370{
359 struct cryptd_hash_ctx *ctx = crypto_ahash_ctx(parent); 371 struct cryptd_hash_ctx *ctx = crypto_ahash_ctx(parent);
360 struct crypto_hash *child = ctx->child; 372 struct crypto_shash *child = ctx->child;
361 int err; 373 int err;
362 374
363 crypto_hash_clear_flags(child, CRYPTO_TFM_REQ_MASK); 375 crypto_shash_clear_flags(child, CRYPTO_TFM_REQ_MASK);
364 crypto_hash_set_flags(child, crypto_ahash_get_flags(parent) & 376 crypto_shash_set_flags(child, crypto_ahash_get_flags(parent) &
365 CRYPTO_TFM_REQ_MASK); 377 CRYPTO_TFM_REQ_MASK);
366 err = crypto_hash_setkey(child, key, keylen); 378 err = crypto_shash_setkey(child, key, keylen);
367 crypto_ahash_set_flags(parent, crypto_hash_get_flags(child) & 379 crypto_ahash_set_flags(parent, crypto_shash_get_flags(child) &
368 CRYPTO_TFM_RES_MASK); 380 CRYPTO_TFM_RES_MASK);
369 return err; 381 return err;
370} 382}
371 383
@@ -385,21 +397,19 @@ static int cryptd_hash_enqueue(struct ahash_request *req,
385 397
386static void cryptd_hash_init(struct crypto_async_request *req_async, int err) 398static void cryptd_hash_init(struct crypto_async_request *req_async, int err)
387{ 399{
388 struct cryptd_hash_ctx *ctx = crypto_tfm_ctx(req_async->tfm); 400 struct cryptd_hash_ctx *ctx = crypto_tfm_ctx(req_async->tfm);
389 struct crypto_hash *child = ctx->child; 401 struct crypto_shash *child = ctx->child;
390 struct ahash_request *req = ahash_request_cast(req_async); 402 struct ahash_request *req = ahash_request_cast(req_async);
391 struct cryptd_hash_request_ctx *rctx; 403 struct cryptd_hash_request_ctx *rctx = ahash_request_ctx(req);
392 struct hash_desc desc; 404 struct shash_desc *desc = &rctx->desc;
393
394 rctx = ahash_request_ctx(req);
395 405</