diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-14 00:50:12 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-14 00:58:00 -0400 |
commit | 113adefc73c291f93f875fe515a46d8f76252fff (patch) | |
tree | d8b71f64e7ed074ede921a1b2ba65d606367735e /crypto/shash.c | |
parent | aef73cfcb913eae3d0deeb60eb385f75039db40b (diff) |
crypto: shash - Make descsize a run-time attribute
This patch changes descsize to a run-time attribute so that
implementations can change it in their init functions.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/shash.c')
-rw-r--r-- | crypto/shash.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/crypto/shash.c b/crypto/shash.c index 131e14d2b572..d8e0f8f8d672 100644 --- a/crypto/shash.c +++ b/crypto/shash.c | |||
@@ -300,14 +300,16 @@ static int crypto_init_shash_ops_async(struct crypto_tfm *tfm) | |||
300 | static int shash_compat_setkey(struct crypto_hash *tfm, const u8 *key, | 300 | static int shash_compat_setkey(struct crypto_hash *tfm, const u8 *key, |
301 | unsigned int keylen) | 301 | unsigned int keylen) |
302 | { | 302 | { |
303 | struct shash_desc *desc = crypto_hash_ctx(tfm); | 303 | struct shash_desc **descp = crypto_hash_ctx(tfm); |
304 | struct shash_desc *desc = *descp; | ||
304 | 305 | ||
305 | return crypto_shash_setkey(desc->tfm, key, keylen); | 306 | return crypto_shash_setkey(desc->tfm, key, keylen); |
306 | } | 307 | } |
307 | 308 | ||
308 | static int shash_compat_init(struct hash_desc *hdesc) | 309 | static int shash_compat_init(struct hash_desc *hdesc) |
309 | { | 310 | { |
310 | struct shash_desc *desc = crypto_hash_ctx(hdesc->tfm); | 311 | struct shash_desc **descp = crypto_hash_ctx(hdesc->tfm); |
312 | struct shash_desc *desc = *descp; | ||
311 | 313 | ||
312 | desc->flags = hdesc->flags; | 314 | desc->flags = hdesc->flags; |
313 | 315 | ||
@@ -317,7 +319,8 @@ static int shash_compat_init(struct hash_desc *hdesc) | |||
317 | static int shash_compat_update(struct hash_desc *hdesc, struct scatterlist *sg, | 319 | static int shash_compat_update(struct hash_desc *hdesc, struct scatterlist *sg, |
318 | unsigned int len) | 320 | unsigned int len) |
319 | { | 321 | { |
320 | struct shash_desc *desc = crypto_hash_ctx(hdesc->tfm); | 322 | struct shash_desc **descp = crypto_hash_ctx(hdesc->tfm); |
323 | struct shash_desc *desc = *descp; | ||
321 | struct crypto_hash_walk walk; | 324 | struct crypto_hash_walk walk; |
322 | int nbytes; | 325 | int nbytes; |
323 | 326 | ||
@@ -330,7 +333,9 @@ static int shash_compat_update(struct hash_desc *hdesc, struct scatterlist *sg, | |||
330 | 333 | ||
331 | static int shash_compat_final(struct hash_desc *hdesc, u8 *out) | 334 | static int shash_compat_final(struct hash_desc *hdesc, u8 *out) |
332 | { | 335 | { |
333 | return crypto_shash_final(crypto_hash_ctx(hdesc->tfm), out); | 336 | struct shash_desc **descp = crypto_hash_ctx(hdesc->tfm); |
337 | |||
338 | return crypto_shash_final(*descp, out); | ||
334 | } | 339 | } |
335 | 340 | ||
336 | static int shash_compat_digest(struct hash_desc *hdesc, struct scatterlist *sg, | 341 | static int shash_compat_digest(struct hash_desc *hdesc, struct scatterlist *sg, |
@@ -340,7 +345,8 @@ static int shash_compat_digest(struct hash_desc *hdesc, struct scatterlist *sg, | |||
340 | int err; | 345 | int err; |
341 | 346 | ||
342 | if (nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset)) { | 347 | if (nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset)) { |
343 | struct shash_desc *desc = crypto_hash_ctx(hdesc->tfm); | 348 | struct shash_desc **descp = crypto_hash_ctx(hdesc->tfm); |
349 | struct shash_desc *desc = *descp; | ||
344 | void *data; | 350 | void *data; |
345 | 351 | ||
346 | desc->flags = hdesc->flags; | 352 | desc->flags = hdesc->flags; |
@@ -368,9 +374,11 @@ out: | |||
368 | 374 | ||
369 | static void crypto_exit_shash_ops_compat(struct crypto_tfm *tfm) | 375 | static void crypto_exit_shash_ops_compat(struct crypto_tfm *tfm) |
370 | { | 376 | { |
371 | struct shash_desc *desc= crypto_tfm_ctx(tfm); | 377 | struct shash_desc **descp = crypto_tfm_ctx(tfm); |
378 | struct shash_desc *desc = *descp; | ||
372 | 379 | ||
373 | crypto_free_shash(desc->tfm); | 380 | crypto_free_shash(desc->tfm); |
381 | kzfree(desc); | ||
374 | } | 382 | } |
375 | 383 | ||
376 | static int crypto_init_shash_ops_compat(struct crypto_tfm *tfm) | 384 | static int crypto_init_shash_ops_compat(struct crypto_tfm *tfm) |
@@ -378,8 +386,9 @@ static int crypto_init_shash_ops_compat(struct crypto_tfm *tfm) | |||
378 | struct hash_tfm *crt = &tfm->crt_hash; | 386 | struct hash_tfm *crt = &tfm->crt_hash; |
379 | struct crypto_alg *calg = tfm->__crt_alg; | 387 | struct crypto_alg *calg = tfm->__crt_alg; |
380 | struct shash_alg *alg = __crypto_shash_alg(calg); | 388 | struct shash_alg *alg = __crypto_shash_alg(calg); |
381 | struct shash_desc *desc = crypto_tfm_ctx(tfm); | 389 | struct shash_desc **descp = crypto_tfm_ctx(tfm); |
382 | struct crypto_shash *shash; | 390 | struct crypto_shash *shash; |
391 | struct shash_desc *desc; | ||
383 | 392 | ||
384 | if (!crypto_mod_get(calg)) | 393 | if (!crypto_mod_get(calg)) |
385 | return -EAGAIN; | 394 | return -EAGAIN; |
@@ -390,6 +399,14 @@ static int crypto_init_shash_ops_compat(struct crypto_tfm *tfm) | |||
390 | return PTR_ERR(shash); | 399 | return PTR_ERR(shash); |
391 | } | 400 | } |
392 | 401 | ||
402 | desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(shash), | ||
403 | GFP_KERNEL); | ||
404 | if (!desc) { | ||
405 | crypto_free_shash(shash); | ||
406 | return -ENOMEM; | ||
407 | } | ||
408 | |||
409 | *descp = desc; | ||
393 | desc->tfm = shash; | 410 | desc->tfm = shash; |
394 | tfm->exit = crypto_exit_shash_ops_compat; | 411 | tfm->exit = crypto_exit_shash_ops_compat; |
395 | 412 | ||
@@ -419,11 +436,9 @@ static int crypto_init_shash_ops(struct crypto_tfm *tfm, u32 type, u32 mask) | |||
419 | static unsigned int crypto_shash_ctxsize(struct crypto_alg *alg, u32 type, | 436 | static unsigned int crypto_shash_ctxsize(struct crypto_alg *alg, u32 type, |
420 | u32 mask) | 437 | u32 mask) |
421 | { | 438 | { |
422 | struct shash_alg *salg = __crypto_shash_alg(alg); | ||
423 | |||
424 | switch (mask & CRYPTO_ALG_TYPE_MASK) { | 439 | switch (mask & CRYPTO_ALG_TYPE_MASK) { |
425 | case CRYPTO_ALG_TYPE_HASH_MASK: | 440 | case CRYPTO_ALG_TYPE_HASH_MASK: |
426 | return sizeof(struct shash_desc) + salg->descsize; | 441 | return sizeof(struct shash_desc *); |
427 | case CRYPTO_ALG_TYPE_AHASH_MASK: | 442 | case CRYPTO_ALG_TYPE_AHASH_MASK: |
428 | return sizeof(struct crypto_shash *); | 443 | return sizeof(struct crypto_shash *); |
429 | } | 444 | } |
@@ -434,6 +449,9 @@ static unsigned int crypto_shash_ctxsize(struct crypto_alg *alg, u32 type, | |||
434 | static int crypto_shash_init_tfm(struct crypto_tfm *tfm, | 449 | static int crypto_shash_init_tfm(struct crypto_tfm *tfm, |
435 | const struct crypto_type *frontend) | 450 | const struct crypto_type *frontend) |
436 | { | 451 | { |
452 | struct crypto_shash *hash = __crypto_shash_cast(tfm); | ||
453 | |||
454 | hash->descsize = crypto_shash_alg(hash)->descsize; | ||
437 | return 0; | 455 | return 0; |
438 | } | 456 | } |
439 | 457 | ||
@@ -452,7 +470,6 @@ static void crypto_shash_show(struct seq_file *m, struct crypto_alg *alg) | |||
452 | seq_printf(m, "type : shash\n"); | 470 | seq_printf(m, "type : shash\n"); |
453 | seq_printf(m, "blocksize : %u\n", alg->cra_blocksize); | 471 | seq_printf(m, "blocksize : %u\n", alg->cra_blocksize); |
454 | seq_printf(m, "digestsize : %u\n", salg->digestsize); | 472 | seq_printf(m, "digestsize : %u\n", salg->digestsize); |
455 | seq_printf(m, "descsize : %u\n", salg->descsize); | ||
456 | } | 473 | } |
457 | 474 | ||
458 | static const struct crypto_type crypto_shash_type = { | 475 | static const struct crypto_type crypto_shash_type = { |