Skip to content

Commit e73d340

Browse files
committed
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>
1 parent 6779d0e commit e73d340

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎crypto/ahash.c‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,14 @@ static int ahash_def_finup(struct ahash_request *req)
444444
return ahash_def_finup_finish1(req, err);
445445
}
446446

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+
447455
static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
448456
{
449457
struct crypto_ahash *hash = __crypto_ahash_cast(tfm);
@@ -467,7 +475,10 @@ static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
467475
ahash_set_needkey(hash);
468476
}
469477

470-
return 0;
478+
if (alg->exit_tfm)
479+
tfm->exit = crypto_ahash_exit_tfm;
480+
481+
return alg->init_tfm ? alg->init_tfm(hash) : 0;
471482
}
472483

473484
static unsigned int crypto_ahash_extsize(struct crypto_alg *alg)

‎include/crypto/hash.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ struct ahash_request {
123123
* data so the transformation can continue from this point onward. No
124124
* data processing happens at this point. Driver must not use
125125
* 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.
126137
* @halg: see struct hash_alg_common
127138
*/
128139
struct ahash_alg {
@@ -135,6 +146,8 @@ struct ahash_alg {
135146
int (*import)(struct ahash_request *req, const void *in);
136147
int (*setkey)(struct crypto_ahash *tfm, const u8 *key,
137148
unsigned int keylen);
149+
int (*init_tfm)(struct crypto_ahash *tfm);
150+
void (*exit_tfm)(struct crypto_ahash *tfm);
138151

139152
struct hash_alg_common halg;
140153
};

0 commit comments

Comments
 (0)