Skip to content

Commit

Permalink
crypto: aead - Add type-safe init/exit functions
Browse files Browse the repository at this point in the history
As it stands the only non-type safe functions left in the new
AEAD interface are the cra_init/cra_exit functions.  It means
exposing the ugly __crypto_aead_cast to every AEAD implementor.

This patch adds type-safe init/exit functions to AEAD.  Existing
algorithms are unaffected while new implementations can simply
fill in these two instead of cra_init/cra_exit.

Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
herbertx committed Jun 3, 2015
1 parent addfda2 commit 5eb8ec6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crypto/aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ static int crypto_old_aead_init_tfm(struct crypto_tfm *tfm)
return 0;
}

static void crypto_aead_exit_tfm(struct crypto_tfm *tfm)
{
struct crypto_aead *aead = __crypto_aead_cast(tfm);
struct aead_alg *alg = crypto_aead_alg(aead);

alg->exit(aead);
}

static int crypto_aead_init_tfm(struct crypto_tfm *tfm)
{
struct crypto_aead *aead = __crypto_aead_cast(tfm);
Expand All @@ -189,6 +197,12 @@ static int crypto_aead_init_tfm(struct crypto_tfm *tfm)
aead->child = __crypto_aead_cast(tfm);
aead->authsize = alg->maxauthsize;

if (alg->exit)
aead->base.exit = crypto_aead_exit_tfm;

if (alg->init)
return alg->init(aead);

return 0;
}

Expand Down
13 changes: 13 additions & 0 deletions include/crypto/aead.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ struct aead_givcrypt_request {
* @decrypt: see struct ablkcipher_alg
* @geniv: see struct ablkcipher_alg
* @ivsize: see struct ablkcipher_alg
* @init: Initialize the cryptographic transformation object. This function
* is used to initialize the cryptographic transformation object.
* This function is called only once at the instantiation time, right
* after the transformation context was allocated. In case the
* cryptographic hardware has some special requirements which need to
* be handled by software, this function shall check for the precise
* requirement of the transformation and put any software fallbacks
* in place.
* @exit: Deinitialize the cryptographic transformation object. This is a
* counterpart to @init, used to remove various changes set in
* @init.
*
* All fields except @ivsize is mandatory and must be filled.
*/
Expand All @@ -118,6 +129,8 @@ struct aead_alg {
int (*setauthsize)(struct crypto_aead *tfm, unsigned int authsize);
int (*encrypt)(struct aead_request *req);
int (*decrypt)(struct aead_request *req);
int (*init)(struct crypto_aead *tfm);
void (*exit)(struct crypto_aead *tfm);

const char *geniv;

Expand Down

0 comments on commit 5eb8ec6

Please sign in to comment.