crypto: aead - Add chunk size
authorHerbert Xu <herbert@gondor.apana.org.au>
Tue, 12 Jul 2016 05:17:33 +0000 (13:17 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 18 Jul 2016 09:35:38 +0000 (17:35 +0800)
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>
crypto/aead.c
include/crypto/aead.h
include/crypto/internal/aead.h

index 9b18a1e..b155cbc 100644 (file)
@@ -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;
index 75174f8..12f8432 100644 (file)
@@ -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
@@ -145,6 +146,7 @@ struct aead_alg {
 
        unsigned int ivsize;
        unsigned int maxauthsize;
+       unsigned int chunksize;
 
        struct crypto_alg base;
 };
index da38649..6ad8e31 100644 (file)
@@ -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);