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

crypto: ahash - Add init_tfm/exit_tfm

This patch adds the type-safe init_tfm/exit_tfm functions to the
ahash interface. This is meant to replace the unsafe cra_init and
cra_exit interface.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+25 -1
+12 -1
crypto/ahash.c
··· 444 444 return ahash_def_finup_finish1(req, err); 445 445 } 446 446 447 + static void crypto_ahash_exit_tfm(struct crypto_tfm *tfm) 448 + { 449 + struct crypto_ahash *hash = __crypto_ahash_cast(tfm); 450 + struct ahash_alg *alg = crypto_ahash_alg(hash); 451 + 452 + alg->exit_tfm(hash); 453 + } 454 + 447 455 static int crypto_ahash_init_tfm(struct crypto_tfm *tfm) 448 456 { 449 457 struct crypto_ahash *hash = __crypto_ahash_cast(tfm); ··· 475 467 ahash_set_needkey(hash); 476 468 } 477 469 478 - return 0; 470 + if (alg->exit_tfm) 471 + tfm->exit = crypto_ahash_exit_tfm; 472 + 473 + return alg->init_tfm ? alg->init_tfm(hash) : 0; 479 474 } 480 475 481 476 static unsigned int crypto_ahash_extsize(struct crypto_alg *alg)
+13
include/crypto/hash.h
··· 123 123 * data so the transformation can continue from this point onward. No 124 124 * data processing happens at this point. Driver must not use 125 125 * req->result. 126 + * @init_tfm: Initialize the cryptographic transformation object. 127 + * This function is called only once at the instantiation 128 + * time, right after the transformation context was 129 + * allocated. In case the cryptographic hardware has 130 + * some special requirements which need to be handled 131 + * by software, this function shall check for the precise 132 + * requirement of the transformation and put any software 133 + * fallbacks in place. 134 + * @exit_tfm: Deinitialize the cryptographic transformation object. 135 + * This is a counterpart to @init_tfm, used to remove 136 + * various changes set in @init_tfm. 126 137 * @halg: see struct hash_alg_common 127 138 */ 128 139 struct ahash_alg { ··· 146 135 int (*import)(struct ahash_request *req, const void *in); 147 136 int (*setkey)(struct crypto_ahash *tfm, const u8 *key, 148 137 unsigned int keylen); 138 + int (*init_tfm)(struct crypto_ahash *tfm); 139 + void (*exit_tfm)(struct crypto_ahash *tfm); 149 140 150 141 struct hash_alg_common halg; 151 142 };