Skip to content

Commit

Permalink
crypto: aead - Add chunk size
Browse files Browse the repository at this point in the history
This patch adds a chunk size parameter to aead algorithms, just
like the chunk size for skcipher algorithms.

However, unlike skcipher we do not currently export this to AEAD
users.  It is only meant to be used by AEAD implementors for now.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
herbertx committed Jul 18, 2016
1 parent a012973 commit 7a530aa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
6 changes: 5 additions & 1 deletion crypto/aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,13 @@ static int aead_prepare_alg(struct aead_alg *alg)
{
struct crypto_alg *base = &alg->base;

if (max(alg->maxauthsize, alg->ivsize) > PAGE_SIZE / 8)
if (max3(alg->maxauthsize, alg->ivsize, alg->chunksize) >
PAGE_SIZE / 8)
return -EINVAL;

if (!alg->chunksize)
alg->chunksize = base->cra_blocksize;

base->cra_type = &crypto_aead_type;
base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
base->cra_flags |= CRYPTO_ALG_TYPE_AEAD;
Expand Down
12 changes: 7 additions & 5 deletions include/crypto/aead.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ struct aead_request {
* supplied during the decryption operation. This function is also
* responsible for checking the authentication tag size for
* validity.
* @setkey: see struct ablkcipher_alg
* @encrypt: see struct ablkcipher_alg
* @decrypt: see struct ablkcipher_alg
* @geniv: see struct ablkcipher_alg
* @ivsize: see struct ablkcipher_alg
* @setkey: see struct skcipher_alg
* @encrypt: see struct skcipher_alg
* @decrypt: see struct skcipher_alg
* @geniv: see struct skcipher_alg
* @ivsize: see struct skcipher_alg
* @chunksize: see struct skcipher_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
Expand Down Expand Up @@ -145,6 +146,7 @@ struct aead_alg {

unsigned int ivsize;
unsigned int maxauthsize;
unsigned int chunksize;

struct crypto_alg base;
};
Expand Down
21 changes: 21 additions & 0 deletions include/crypto/internal/aead.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,27 @@ static inline struct aead_request *aead_get_backlog(struct aead_queue *queue)
return req ? container_of(req, struct aead_request, base) : NULL;
}

static inline unsigned int crypto_aead_alg_chunksize(struct aead_alg *alg)
{
return alg->chunksize;
}

/**
* crypto_aead_chunksize() - obtain chunk size
* @tfm: cipher handle
*
* The block size is set to one for ciphers such as CCM. However,
* you still need to provide incremental updates in multiples of
* the underlying block size as the IV does not have sub-block
* granularity. This is known in this API as the chunk size.
*
* Return: chunk size in bytes
*/
static inline unsigned int crypto_aead_chunksize(struct crypto_aead *tfm)
{
return crypto_aead_alg_chunksize(crypto_aead_alg(tfm));
}

int crypto_register_aead(struct aead_alg *alg);
void crypto_unregister_aead(struct aead_alg *alg);
int crypto_register_aeads(struct aead_alg *algs, int count);
Expand Down

0 comments on commit 7a530aa

Please sign in to comment.