]> git.karo-electronics.de Git - linux-beck.git/commitdiff
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 9b18a1e40d6af896be358c72113cbddb78c7acaa..b155cbc3a0dd91e344f0cce0b0ca2ee7ee487704 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 75174f80a1063d67ef4db86ec2d22634ed2da583..12f84327ca366f35c393ba7ee519a3c38ef224a9 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 da3864991d4c50b33a4145c57444d8a70a0db14a..6ad8e31d38682e4408f669dc0b08ec153bb8b36b 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);