]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
Revert "crypto: aead - Convert top level interface to new style"
authorEthan Zhao <ethan.zhao@oracle.com>
Wed, 15 Feb 2017 03:54:18 +0000 (12:54 +0900)
committerChuck Anderson <chuck.anderson@oracle.com>
Sun, 26 Feb 2017 05:34:40 +0000 (21:34 -0800)
Orabug: 25243093

Revert this commit because old_crypt()/old_encrypt() are buggy
temporary interface.

This reverts commit 21579deee39629f2a68a37c42e89bdad53d88ebf.

Signed-off-by: Ethan Zhao <ethan.zhao@oracle.com>
crypto/aead.c
drivers/net/macsec.c
include/crypto/aead.h
include/crypto/algapi.h
include/crypto/internal/aead.h
include/linux/crypto.h

index 717b2f6ec9bb3b835e498f3d3c423426b9bffb2f..d6ad0c66ee835eeec289be4a68d9bb864847c57b 100644 (file)
@@ -26,9 +26,6 @@
 
 #include "internal.h"
 
-static int aead_null_givencrypt(struct aead_givcrypt_request *req);
-static int aead_null_givdecrypt(struct aead_givcrypt_request *req);
-
 static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
                            unsigned int keylen)
 {
@@ -51,63 +48,63 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
        return ret;
 }
 
-int crypto_aead_setkey(struct crypto_aead *tfm,
-                      const u8 *key, unsigned int keylen)
+static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
 {
        struct aead_alg *aead = crypto_aead_alg(tfm);
        unsigned long alignmask = crypto_aead_alignmask(tfm);
 
-       tfm = tfm->child;
-
        if ((unsigned long)key & alignmask)
                return setkey_unaligned(tfm, key, keylen);
 
        return aead->setkey(tfm, key, keylen);
 }
-EXPORT_SYMBOL_GPL(crypto_aead_setkey);
 
 int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
 {
+       struct aead_tfm *crt = crypto_aead_crt(tfm);
        int err;
 
        if (authsize > crypto_aead_alg(tfm)->maxauthsize)
                return -EINVAL;
 
        if (crypto_aead_alg(tfm)->setauthsize) {
-               err = crypto_aead_alg(tfm)->setauthsize(tfm->child, authsize);
+               err = crypto_aead_alg(tfm)->setauthsize(crt->base, authsize);
                if (err)
                        return err;
        }
 
-       tfm->child->authsize = authsize;
-       tfm->authsize = authsize;
+       crypto_aead_crt(crt->base)->authsize = authsize;
+       crt->authsize = authsize;
        return 0;
 }
 EXPORT_SYMBOL_GPL(crypto_aead_setauthsize);
 
+static unsigned int crypto_aead_ctxsize(struct crypto_alg *alg, u32 type,
+                                       u32 mask)
+{
+       return alg->cra_ctxsize;
+}
+
 static int no_givcrypt(struct aead_givcrypt_request *req)
 {
        return -ENOSYS;
 }
 
-static int crypto_aead_init_tfm(struct crypto_tfm *tfm)
+static int crypto_init_aead_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
 {
        struct aead_alg *alg = &tfm->__crt_alg->cra_aead;
-       struct crypto_aead *crt = __crypto_aead_cast(tfm);
+       struct aead_tfm *crt = &tfm->crt_aead;
 
        if (max(alg->maxauthsize, alg->ivsize) > PAGE_SIZE / 8)
                return -EINVAL;
 
+       crt->setkey = tfm->__crt_alg->cra_flags & CRYPTO_ALG_GENIV ?
+                     alg->setkey : setkey;
        crt->encrypt = alg->encrypt;
        crt->decrypt = alg->decrypt;
-       if (alg->ivsize) {
-               crt->givencrypt = alg->givencrypt ?: no_givcrypt;
-               crt->givdecrypt = alg->givdecrypt ?: no_givcrypt;
-       } else {
-               crt->givencrypt = aead_null_givencrypt;
-               crt->givdecrypt = aead_null_givdecrypt;
-       }
-       crt->child = __crypto_aead_cast(tfm);
+       crt->givencrypt = alg->givencrypt ?: no_givcrypt;
+       crt->givdecrypt = alg->givdecrypt ?: no_givcrypt;
+       crt->base = __crypto_aead_cast(tfm);
        crt->ivsize = alg->ivsize;
        crt->authsize = alg->maxauthsize;
 
@@ -158,17 +155,12 @@ static void crypto_aead_show(struct seq_file *m, struct crypto_alg *alg)
 }
 
 const struct crypto_type crypto_aead_type = {
-       .extsize = crypto_alg_extsize,
-       .init_tfm = crypto_aead_init_tfm,
+       .ctxsize = crypto_aead_ctxsize,
+       .init = crypto_init_aead_ops,
 #ifdef CONFIG_PROC_FS
        .show = crypto_aead_show,
 #endif
        .report = crypto_aead_report,
-       .lookup = crypto_lookup_aead,
-       .maskclear = ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV),
-       .maskset = CRYPTO_ALG_TYPE_MASK,
-       .type = CRYPTO_ALG_TYPE_AEAD,
-       .tfmsize = offsetof(struct crypto_aead, base),
 };
 EXPORT_SYMBOL_GPL(crypto_aead_type);
 
@@ -182,6 +174,28 @@ static int aead_null_givdecrypt(struct aead_givcrypt_request *req)
        return crypto_aead_decrypt(&req->areq);
 }
 
+static int crypto_init_nivaead_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
+{
+       struct aead_alg *alg = &tfm->__crt_alg->cra_aead;
+       struct aead_tfm *crt = &tfm->crt_aead;
+
+       if (max(alg->maxauthsize, alg->ivsize) > PAGE_SIZE / 8)
+               return -EINVAL;
+
+       crt->setkey = setkey;
+       crt->encrypt = alg->encrypt;
+       crt->decrypt = alg->decrypt;
+       if (!alg->ivsize) {
+               crt->givencrypt = aead_null_givencrypt;
+               crt->givdecrypt = aead_null_givdecrypt;
+       }
+       crt->base = __crypto_aead_cast(tfm);
+       crt->ivsize = alg->ivsize;
+       crt->authsize = alg->maxauthsize;
+
+       return 0;
+}
+
 #ifdef CONFIG_NET
 static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
 {
@@ -227,24 +241,32 @@ static void crypto_nivaead_show(struct seq_file *m, struct crypto_alg *alg)
 }
 
 const struct crypto_type crypto_nivaead_type = {
-       .extsize = crypto_alg_extsize,
-       .init_tfm = crypto_aead_init_tfm,
+       .ctxsize = crypto_aead_ctxsize,
+       .init = crypto_init_nivaead_ops,
 #ifdef CONFIG_PROC_FS
        .show = crypto_nivaead_show,
 #endif
        .report = crypto_nivaead_report,
-       .maskclear = ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV),
-       .maskset = CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV,
-       .type = CRYPTO_ALG_TYPE_AEAD,
-       .tfmsize = offsetof(struct crypto_aead, base),
 };
 EXPORT_SYMBOL_GPL(crypto_nivaead_type);
 
 static int crypto_grab_nivaead(struct crypto_aead_spawn *spawn,
                               const char *name, u32 type, u32 mask)
 {
-       spawn->base.frontend = &crypto_nivaead_type;
-       return crypto_grab_spawn(&spawn->base, name, type, mask);
+       struct crypto_alg *alg;
+       int err;
+
+       type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
+       type |= CRYPTO_ALG_TYPE_AEAD;
+       mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV;
+
+       alg = crypto_alg_mod_lookup(name, type, mask);
+       if (IS_ERR(alg))
+               return PTR_ERR(alg);
+
+       err = crypto_init_spawn(&spawn->base, alg, spawn->base.inst, mask);
+       crypto_mod_put(alg);
+       return err;
 }
 
 struct crypto_instance *aead_geniv_alloc(struct crypto_template *tmpl,
@@ -352,17 +374,14 @@ EXPORT_SYMBOL_GPL(aead_geniv_free);
 int aead_geniv_init(struct crypto_tfm *tfm)
 {
        struct crypto_instance *inst = (void *)tfm->__crt_alg;
-       struct crypto_aead *child;
        struct crypto_aead *aead;
 
-       aead = __crypto_aead_cast(tfm);
+       aead = crypto_spawn_aead(crypto_instance_ctx(inst));
+       if (IS_ERR(aead))
+               return PTR_ERR(aead);
 
-       child = crypto_spawn_aead(crypto_instance_ctx(inst));
-       if (IS_ERR(child))
-               return PTR_ERR(child);
-
-       aead->child = child;
-       aead->reqsize += crypto_aead_reqsize(child);
+       tfm->crt_aead.base = aead;
+       tfm->crt_aead.reqsize += crypto_aead_reqsize(aead);
 
        return 0;
 }
@@ -370,7 +389,7 @@ EXPORT_SYMBOL_GPL(aead_geniv_init);
 
 void aead_geniv_exit(struct crypto_tfm *tfm)
 {
-       crypto_free_aead(__crypto_aead_cast(tfm)->child);
+       crypto_free_aead(tfm->crt_aead.base);
 }
 EXPORT_SYMBOL_GPL(aead_geniv_exit);
 
@@ -486,14 +505,60 @@ EXPORT_SYMBOL_GPL(crypto_lookup_aead);
 int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
                     u32 type, u32 mask)
 {
-       spawn->base.frontend = &crypto_aead_type;
-       return crypto_grab_spawn(&spawn->base, name, type, mask);
+       struct crypto_alg *alg;
+       int err;
+
+       type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
+       type |= CRYPTO_ALG_TYPE_AEAD;
+       mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
+       mask |= CRYPTO_ALG_TYPE_MASK;
+
+       alg = crypto_lookup_aead(name, type, mask);
+       if (IS_ERR(alg))
+               return PTR_ERR(alg);
+
+       err = crypto_init_spawn(&spawn->base, alg, spawn->base.inst, mask);
+       crypto_mod_put(alg);
+       return err;
 }
 EXPORT_SYMBOL_GPL(crypto_grab_aead);
 
 struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask)
 {
-       return crypto_alloc_tfm(alg_name, &crypto_aead_type, type, mask);
+       struct crypto_tfm *tfm;
+       int err;
+
+       type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
+       type |= CRYPTO_ALG_TYPE_AEAD;
+       mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
+       mask |= CRYPTO_ALG_TYPE_MASK;
+
+       for (;;) {
+               struct crypto_alg *alg;
+
+               alg = crypto_lookup_aead(alg_name, type, mask);
+               if (IS_ERR(alg)) {
+                       err = PTR_ERR(alg);
+                       goto err;
+               }
+
+               tfm = __crypto_alloc_tfm(alg, type, mask);
+               if (!IS_ERR(tfm))
+                       return __crypto_aead_cast(tfm);
+
+               crypto_mod_put(alg);
+               err = PTR_ERR(tfm);
+
+err:
+               if (err != -EAGAIN)
+                       break;
+               if (signal_pending(current)) {
+                       err = -EINTR;
+                       break;
+               }
+       }
+
+       return ERR_PTR(err);
 }
 EXPORT_SYMBOL_GPL(crypto_alloc_aead);
 
index 727c131a0b831adda36ba06f405d322fdc638499..11933e5c57a127e0dbac2744347ceff5f58cffac 100644 (file)
@@ -59,6 +59,7 @@ struct macsec_eth_header {
 
 #define GCM_AES_IV_LEN 12
 #define DEFAULT_ICV_LEN 16
+#define IV_EXTRA_ROOM sizeof(u32)
 
 #define MACSEC_NUM_AN 4 /* 2 bits for the association number */
 
@@ -606,26 +607,32 @@ static void macsec_encrypt_done(struct crypto_async_request *base, int err)
 
 static struct aead_request *macsec_alloc_req(struct crypto_aead *tfm,
                                             unsigned char **iv,
-                                            struct scatterlist **sg)
+                                             struct scatterlist **sg,
+                                             struct scatterlist **sg_ad)
 {
-       size_t size, iv_offset, sg_offset;
+       size_t size, iv_offset, sg_offset, sg_ad_offset;
        struct aead_request *req;
        void *tmp;
 
        size = sizeof(struct aead_request) + crypto_aead_reqsize(tfm);
        iv_offset = size;
-       size += GCM_AES_IV_LEN;
+       size += GCM_AES_IV_LEN + IV_EXTRA_ROOM;
 
        size = ALIGN(size, __alignof__(struct scatterlist));
        sg_offset = size;
        size += sizeof(struct scatterlist) * (MAX_SKB_FRAGS + 1);
 
+       size = ALIGN(size, __alignof__(struct scatterlist));
+       sg_ad_offset = size;
+       size += sizeof(struct scatterlist) * (MAX_SKB_FRAGS + 1);
+
        tmp = kmalloc(size, GFP_ATOMIC);
        if (!tmp)
                return NULL;
 
        *iv = (unsigned char *)(tmp + iv_offset);
        *sg = (struct scatterlist *)(tmp + sg_offset);
+       *sg_ad = (struct scatterlist *)(tmp + sg_ad_offset);
        req = tmp;
 
        aead_request_set_tfm(req, tfm);
@@ -638,6 +645,7 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
 {
        int ret;
        struct scatterlist *sg;
+       struct scatterlist *sg_ad;
        unsigned char *iv;
        struct ethhdr *eth;
        struct macsec_eth_header *hh;
@@ -710,7 +718,7 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
                return ERR_PTR(-EINVAL);
        }
 
-       req = macsec_alloc_req(tx_sa->key.tfm, &iv, &sg);
+       req = macsec_alloc_req(tx_sa->key.tfm, &iv, &sg, &sg_ad);
        if (!req) {
                macsec_txsa_put(tx_sa);
                kfree_skb(skb);
@@ -719,17 +727,28 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
 
        macsec_fill_iv(iv, secy->sci, pn);
 
-       sg_init_table(sg, MAX_SKB_FRAGS + 1);
-       skb_to_sgvec(skb, sg, 0, skb->len);
-
        if (tx_sc->encrypt) {
-               int len = skb->len - macsec_hdr_len(tx_sc->send_sci) -
-                         secy->icv_len;
-               aead_request_set_crypt(req, sg, sg, len, iv);
-               aead_request_set_ad(req, macsec_hdr_len(tx_sc->send_sci), 0);
+               int assoc_len = macsec_hdr_len(tx_sc->send_sci);
+                int data_len = skb->len - secy->icv_len - assoc_len;
+
+                sg_init_table(sg_ad, MAX_SKB_FRAGS + 1);
+                skb_to_sgvec(skb, sg_ad, 0, assoc_len);
+                sg_init_table(sg, MAX_SKB_FRAGS + 1);
+                skb_to_sgvec(skb, sg, assoc_len, data_len + secy->icv_len);
+       
+               aead_request_set_crypt(req, sg, sg, data_len, iv);
+               aead_request_set_assoc(req, sg_ad, assoc_len);
        } else {
+               int assoc_len = skb->len - secy->icv_len;
+                int data_len = secy->icv_len;
+
+                sg_init_table(sg_ad, MAX_SKB_FRAGS + 1);
+                skb_to_sgvec(skb, sg_ad, 0, assoc_len);
+                sg_init_table(sg, MAX_SKB_FRAGS + 1);
+                skb_to_sgvec(skb, sg, assoc_len, data_len);
+
                aead_request_set_crypt(req, sg, sg, 0, iv);
-               aead_request_set_ad(req, skb->len - secy->icv_len, 0);
+               aead_request_set_assoc(req, sg_ad, assoc_len);
        }
 
        macsec_skb_cb(skb)->req = req;
@@ -901,6 +920,7 @@ static struct sk_buff *macsec_decrypt(struct sk_buff *skb,
 {
        int ret;
        struct scatterlist *sg;
+       struct scatterlist *sg_ad;
        unsigned char *iv;
        struct aead_request *req;
        struct macsec_eth_header *hdr;
@@ -911,7 +931,7 @@ static struct sk_buff *macsec_decrypt(struct sk_buff *skb,
        if (!skb)
                return ERR_PTR(-ENOMEM);
 
-       req = macsec_alloc_req(rx_sa->key.tfm, &iv, &sg);
+       req = macsec_alloc_req(rx_sa->key.tfm, &iv, &sg, &sg_ad);
        if (!req) {
                kfree_skb(skb);
                return ERR_PTR(-ENOMEM);
@@ -927,20 +947,36 @@ static struct sk_buff *macsec_decrypt(struct sk_buff *skb,
                /* confidentiality: ethernet + macsec header
                 * authenticated, encrypted payload
                 */
-               int len = skb->len - macsec_hdr_len(macsec_skb_cb(skb)->has_sci);
 
-               aead_request_set_crypt(req, sg, sg, len, iv);
-               aead_request_set_ad(req, macsec_hdr_len(macsec_skb_cb(skb)->has_sci), 0);
-               skb = skb_unshare(skb, GFP_ATOMIC);
-               if (!skb) {
-                       aead_request_free(req);
-                       return ERR_PTR(-ENOMEM);
-               }
-       } else {
-               /* integrity only: all headers + data authenticated */
-               aead_request_set_crypt(req, sg, sg, icv_len, iv);
-               aead_request_set_ad(req, skb->len - icv_len, 0);
-       }
+                int assoc_len = macsec_hdr_len(macsec_skb_cb(skb)->has_sci);
+                int data_len = skb->len - assoc_len;
+
+                sg_init_table(sg_ad, MAX_SKB_FRAGS + 1);
+                skb_to_sgvec(skb, sg_ad, 0, assoc_len);
+                sg_init_table(sg, MAX_SKB_FRAGS + 1);
+                skb_to_sgvec(skb, sg, assoc_len, data_len);
+
+                aead_request_set_crypt(req, sg, sg, data_len, iv);
+                aead_request_set_assoc(req, sg_ad, assoc_len);
+
+                skb = skb_unshare(skb, GFP_ATOMIC);
+                if (!skb) {
+                        aead_request_free(req);
+                        return ERR_PTR(-ENOMEM);
+                }
+        } else {
+                /* integrity only: all headers + data authenticated */
+                int assoc_len = skb->len - icv_len;
+                int data_len = icv_len;
+
+                sg_init_table(sg_ad, MAX_SKB_FRAGS + 1);
+                skb_to_sgvec(skb, sg_ad, 0, assoc_len);
+                sg_init_table(sg, MAX_SKB_FRAGS + 1);
+                skb_to_sgvec(skb, sg, assoc_len, data_len);
+
+                aead_request_set_crypt(req, sg, sg, data_len, iv);
+                aead_request_set_assoc(req, sg_ad, assoc_len);
+        }
 
        macsec_skb_cb(skb)->req = req;
        skb->dev = dev;
index dbcad08f4891d193464ec509c46ddf6398efde17..1b806de8ff16a9d100a3f0f2c6a9e5f4b0e21a23 100644 (file)
 #include <linux/kernel.h>
 #include <linux/slab.h>
 
-/**
- * DOC: Authenticated Encryption With Associated Data (AEAD) Cipher API
- *
- * The AEAD cipher API is used with the ciphers of type CRYPTO_ALG_TYPE_AEAD
- * (listed as type "aead" in /proc/crypto)
- *
- * The most prominent examples for this type of encryption is GCM and CCM.
- * However, the kernel supports other types of AEAD ciphers which are defined
- * with the following cipher string:
- *
- *     authenc(keyed message digest, block cipher)
- *
- * For example: authenc(hmac(sha256), cbc(aes))
- *
- * The example code provided for the asynchronous block cipher operation
- * applies here as well. Naturally all *ablkcipher* symbols must be exchanged
- * the *aead* pendants discussed in the following. In addtion, for the AEAD
- * operation, the aead_request_set_assoc function must be used to set the
- * pointer to the associated data memory location before performing the
- * encryption or decryption operation. In case of an encryption, the associated
- * data memory is filled during the encryption operation. For decryption, the
- * associated data memory must contain data that is used to verify the integrity
- * of the decrypted data. Another deviation from the asynchronous block cipher
- * operation is that the caller should explicitly check for -EBADMSG of the
- * crypto_aead_decrypt. That error indicates an authentication error, i.e.
- * a breach in the integrity of the message. In essence, that -EBADMSG error
- * code is the key bonus an AEAD cipher has over "standard" block chaining
- * modes.
- */
-
-/**
- *     struct aead_request - AEAD request
- *     @base: Common attributes for async crypto requests
- *     @assoclen: Length in bytes of associated data for authentication
- *     @cryptlen: Length of data to be encrypted or decrypted
- *     @iv: Initialisation vector
- *     @assoc: Associated data
- *     @src: Source data
- *     @dst: Destination data
- *     @__ctx: Start of private context data
- */
-struct aead_request {
-       struct crypto_async_request base;
-
-       unsigned int assoclen;
-       unsigned int cryptlen;
-
-       u8 *iv;
-
-       struct scatterlist *assoc;
-       struct scatterlist *src;
-       struct scatterlist *dst;
-
-       void *__ctx[] CRYPTO_MINALIGN_ATTR;
-};
-
 /**
  *     struct aead_givcrypt_request - AEAD request with IV generation
  *     @seq: Sequence number for IV generation
@@ -86,380 +30,6 @@ struct aead_givcrypt_request {
        struct aead_request areq;
 };
 
-struct crypto_aead {
-       int (*encrypt)(struct aead_request *req);
-       int (*decrypt)(struct aead_request *req);
-       int (*givencrypt)(struct aead_givcrypt_request *req);
-       int (*givdecrypt)(struct aead_givcrypt_request *req);
-
-       struct crypto_aead *child;
-
-       unsigned int ivsize;
-       unsigned int authsize;
-       unsigned int reqsize;
-
-       struct crypto_tfm base;
-};
-
-static inline struct crypto_aead *__crypto_aead_cast(struct crypto_tfm *tfm)
-{
-       return container_of(tfm, struct crypto_aead, base);
-}
-
-/**
- * crypto_alloc_aead() - allocate AEAD cipher handle
- * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
- *          AEAD cipher
- * @type: specifies the type of the cipher
- * @mask: specifies the mask for the cipher
- *
- * Allocate a cipher handle for an AEAD. The returned struct
- * crypto_aead is the cipher handle that is required for any subsequent
- * API invocation for that AEAD.
- *
- * Return: allocated cipher handle in case of success; IS_ERR() is true in case
- *        of an error, PTR_ERR() returns the error code.
- */
-struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask);
-
-static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm)
-{
-       return &tfm->base;
-}
-
-/**
- * crypto_free_aead() - zeroize and free aead handle
- * @tfm: cipher handle to be freed
- */
-static inline void crypto_free_aead(struct crypto_aead *tfm)
-{
-       crypto_destroy_tfm(tfm, crypto_aead_tfm(tfm));
-}
-
-static inline struct crypto_aead *crypto_aead_crt(struct crypto_aead *tfm)
-{
-       return tfm;
-}
-
-/**
- * crypto_aead_ivsize() - obtain IV size
- * @tfm: cipher handle
- *
- * The size of the IV for the aead referenced by the cipher handle is
- * returned. This IV size may be zero if the cipher does not need an IV.
- *
- * Return: IV size in bytes
- */
-static inline unsigned int crypto_aead_ivsize(struct crypto_aead *tfm)
-{
-       return tfm->ivsize;
-}
-
-/**
- * crypto_aead_authsize() - obtain maximum authentication data size
- * @tfm: cipher handle
- *
- * The maximum size of the authentication data for the AEAD cipher referenced
- * by the AEAD cipher handle is returned. The authentication data size may be
- * zero if the cipher implements a hard-coded maximum.
- *
- * The authentication data may also be known as "tag value".
- *
- * Return: authentication data size / tag size in bytes
- */
-static inline unsigned int crypto_aead_authsize(struct crypto_aead *tfm)
-{
-       return tfm->authsize;
-}
-
-/**
- * crypto_aead_blocksize() - obtain block size of cipher
- * @tfm: cipher handle
- *
- * The block size for the AEAD referenced with the cipher handle is returned.
- * The caller may use that information to allocate appropriate memory for the
- * data returned by the encryption or decryption operation
- *
- * Return: block size of cipher
- */
-static inline unsigned int crypto_aead_blocksize(struct crypto_aead *tfm)
-{
-       return crypto_tfm_alg_blocksize(crypto_aead_tfm(tfm));
-}
-
-static inline unsigned int crypto_aead_alignmask(struct crypto_aead *tfm)
-{
-       return crypto_tfm_alg_alignmask(crypto_aead_tfm(tfm));
-}
-
-static inline u32 crypto_aead_get_flags(struct crypto_aead *tfm)
-{
-       return crypto_tfm_get_flags(crypto_aead_tfm(tfm));
-}
-
-static inline void crypto_aead_set_flags(struct crypto_aead *tfm, u32 flags)
-{
-       crypto_tfm_set_flags(crypto_aead_tfm(tfm), flags);
-}
-
-static inline void crypto_aead_clear_flags(struct crypto_aead *tfm, u32 flags)
-{
-       crypto_tfm_clear_flags(crypto_aead_tfm(tfm), flags);
-}
-
-/**
- * crypto_aead_setkey() - set key for cipher
- * @tfm: cipher handle
- * @key: buffer holding the key
- * @keylen: length of the key in bytes
- *
- * The caller provided key is set for the AEAD referenced by the cipher
- * handle.
- *
- * Note, the key length determines the cipher type. Many block ciphers implement
- * different cipher modes depending on the key size, such as AES-128 vs AES-192
- * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128
- * is performed.
- *
- * Return: 0 if the setting of the key was successful; < 0 if an error occurred
- */
-int crypto_aead_setkey(struct crypto_aead *tfm,
-                      const u8 *key, unsigned int keylen);
-
-/**
- * crypto_aead_setauthsize() - set authentication data size
- * @tfm: cipher handle
- * @authsize: size of the authentication data / tag in bytes
- *
- * Set the authentication data size / tag size. AEAD requires an authentication
- * tag (or MAC) in addition to the associated data.
- *
- * Return: 0 if the setting of the key was successful; < 0 if an error occurred
- */
-int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize);
-
-static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req)
-{
-       return __crypto_aead_cast(req->base.tfm);
-}
-
-/**
- * crypto_aead_encrypt() - encrypt plaintext
- * @req: reference to the aead_request handle that holds all information
- *      needed to perform the cipher operation
- *
- * Encrypt plaintext data using the aead_request handle. That data structure
- * and how it is filled with data is discussed with the aead_request_*
- * functions.
- *
- * IMPORTANT NOTE The encryption operation creates the authentication data /
- *               tag. That data is concatenated with the created ciphertext.
- *               The ciphertext memory size is therefore the given number of
- *               block cipher blocks + the size defined by the
- *               crypto_aead_setauthsize invocation. The caller must ensure
- *               that sufficient memory is available for the ciphertext and
- *               the authentication tag.
- *
- * Return: 0 if the cipher operation was successful; < 0 if an error occurred
- */
-static inline int crypto_aead_encrypt(struct aead_request *req)
-{
-       return crypto_aead_reqtfm(req)->encrypt(req);
-}
-
-/**
- * crypto_aead_decrypt() - decrypt ciphertext
- * @req: reference to the ablkcipher_request handle that holds all information
- *      needed to perform the cipher operation
- *
- * Decrypt ciphertext data using the aead_request handle. That data structure
- * and how it is filled with data is discussed with the aead_request_*
- * functions.
- *
- * IMPORTANT NOTE The caller must concatenate the ciphertext followed by the
- *               authentication data / tag. That authentication data / tag
- *               must have the size defined by the crypto_aead_setauthsize
- *               invocation.
- *
- *
- * Return: 0 if the cipher operation was successful; -EBADMSG: The AEAD
- *        cipher operation performs the authentication of the data during the
- *        decryption operation. Therefore, the function returns this error if
- *        the authentication of the ciphertext was unsuccessful (i.e. the
- *        integrity of the ciphertext or the associated data was violated);
- *        < 0 if an error occurred.
- */
-static inline int crypto_aead_decrypt(struct aead_request *req)
-{
-       if (req->cryptlen < crypto_aead_authsize(crypto_aead_reqtfm(req)))
-               return -EINVAL;
-
-       return crypto_aead_reqtfm(req)->decrypt(req);
-}
-
-/**
- * DOC: Asynchronous AEAD Request Handle
- *
- * The aead_request data structure contains all pointers to data required for
- * the AEAD cipher operation. This includes the cipher handle (which can be
- * used by multiple aead_request instances), pointer to plaintext and
- * ciphertext, asynchronous callback function, etc. It acts as a handle to the
- * aead_request_* API calls in a similar way as AEAD handle to the
- * crypto_aead_* API calls.
- */
-
-/**
- * crypto_aead_reqsize() - obtain size of the request data structure
- * @tfm: cipher handle
- *
- * Return: number of bytes
- */
-static inline unsigned int crypto_aead_reqsize(struct crypto_aead *tfm)
-{
-       return tfm->reqsize;
-}
-
-/**
- * aead_request_set_tfm() - update cipher handle reference in request
- * @req: request handle to be modified
- * @tfm: cipher handle that shall be added to the request handle
- *
- * Allow the caller to replace the existing aead handle in the request
- * data structure with a different one.
- */
-static inline void aead_request_set_tfm(struct aead_request *req,
-                                       struct crypto_aead *tfm)
-{
-       req->base.tfm = crypto_aead_tfm(tfm->child);
-}
-
-/**
- * aead_request_alloc() - allocate request data structure
- * @tfm: cipher handle to be registered with the request
- * @gfp: memory allocation flag that is handed to kmalloc by the API call.
- *
- * Allocate the request data structure that must be used with the AEAD
- * encrypt and decrypt API calls. During the allocation, the provided aead
- * handle is registered in the request data structure.
- *
- * Return: allocated request handle in case of success; IS_ERR() is true in case
- *        of an error, PTR_ERR() returns the error code.
- */
-static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm,
-                                                     gfp_t gfp)
-{
-       struct aead_request *req;
-
-       req = kmalloc(sizeof(*req) + crypto_aead_reqsize(tfm), gfp);
-
-       if (likely(req))
-               aead_request_set_tfm(req, tfm);
-
-       return req;
-}
-
-/**
- * aead_request_free() - zeroize and free request data structure
- * @req: request data structure cipher handle to be freed
- */
-static inline void aead_request_free(struct aead_request *req)
-{
-       kzfree(req);
-}
-
-/**
- * aead_request_set_callback() - set asynchronous callback function
- * @req: request handle
- * @flags: specify zero or an ORing of the flags
- *        CRYPTO_TFM_REQ_MAY_BACKLOG the request queue may back log and
- *        increase the wait queue beyond the initial maximum size;
- *        CRYPTO_TFM_REQ_MAY_SLEEP the request processing may sleep
- * @compl: callback function pointer to be registered with the request handle
- * @data: The data pointer refers to memory that is not used by the kernel
- *       crypto API, but provided to the callback function for it to use. Here,
- *       the caller can provide a reference to memory the callback function can
- *       operate on. As the callback function is invoked asynchronously to the
- *       related functionality, it may need to access data structures of the
- *       related functionality which can be referenced using this pointer. The
- *       callback function can access the memory via the "data" field in the
- *       crypto_async_request data structure provided to the callback function.
- *
- * Setting the callback function that is triggered once the cipher operation
- * completes
- *
- * The callback function is registered with the aead_request handle and
- * must comply with the following template
- *
- *     void callback_function(struct crypto_async_request *req, int error)
- */
-static inline void aead_request_set_callback(struct aead_request *req,
-                                            u32 flags,
-                                            crypto_completion_t compl,
-                                            void *data)
-{
-       req->base.complete = compl;
-       req->base.data = data;
-       req->base.flags = flags;
-}
-
-/**
- * aead_request_set_crypt - set data buffers
- * @req: request handle
- * @src: source scatter / gather list
- * @dst: destination scatter / gather list
- * @cryptlen: number of bytes to process from @src
- * @iv: IV for the cipher operation which must comply with the IV size defined
- *      by crypto_aead_ivsize()
- *
- * Setting the source data and destination data scatter / gather lists.
- *
- * For encryption, the source is treated as the plaintext and the
- * destination is the ciphertext. For a decryption operation, the use is
- * reversed - the source is the ciphertext and the destination is the plaintext.
- *
- * IMPORTANT NOTE AEAD requires an authentication tag (MAC). For decryption,
- *               the caller must concatenate the ciphertext followed by the
- *               authentication tag and provide the entire data stream to the
- *               decryption operation (i.e. the data length used for the
- *               initialization of the scatterlist and the data length for the
- *               decryption operation is identical). For encryption, however,
- *               the authentication tag is created while encrypting the data.
- *               The destination buffer must hold sufficient space for the
- *               ciphertext and the authentication tag while the encryption
- *               invocation must only point to the plaintext data size. The
- *               following code snippet illustrates the memory usage
- *               buffer = kmalloc(ptbuflen + (enc ? authsize : 0));
- *               sg_init_one(&sg, buffer, ptbuflen + (enc ? authsize : 0));
- *               aead_request_set_crypt(req, &sg, &sg, ptbuflen, iv);
- */
-static inline void aead_request_set_crypt(struct aead_request *req,
-                                         struct scatterlist *src,
-                                         struct scatterlist *dst,
-                                         unsigned int cryptlen, u8 *iv)
-{
-       req->src = src;
-       req->dst = dst;
-       req->cryptlen = cryptlen;
-       req->iv = iv;
-}
-
-/**
- * aead_request_set_assoc() - set the associated data scatter / gather list
- * @req: request handle
- * @assoc: associated data scatter / gather list
- * @assoclen: number of bytes to process from @assoc
- *
- * For encryption, the memory is filled with the associated data. For
- * decryption, the memory must point to the associated data.
- */
-static inline void aead_request_set_assoc(struct aead_request *req,
-                                         struct scatterlist *assoc,
-                                         unsigned int assoclen)
-{
-       req->assoc = assoc;
-       req->assoclen = assoclen;
-}
-
 static inline struct crypto_aead *aead_givcrypt_reqtfm(
        struct aead_givcrypt_request *req)
 {
@@ -468,12 +38,14 @@ static inline struct crypto_aead *aead_givcrypt_reqtfm(
 
 static inline int crypto_aead_givencrypt(struct aead_givcrypt_request *req)
 {
-       return aead_givcrypt_reqtfm(req)->givencrypt(req);
+       struct aead_tfm *crt = crypto_aead_crt(aead_givcrypt_reqtfm(req));
+       return crt->givencrypt(req);
 };
 
 static inline int crypto_aead_givdecrypt(struct aead_givcrypt_request *req)
 {
-       return aead_givcrypt_reqtfm(req)->givdecrypt(req);
+       struct aead_tfm *crt = crypto_aead_crt(aead_givcrypt_reqtfm(req));
+       return crt->givdecrypt(req);
 };
 
 static inline void aead_givcrypt_set_tfm(struct aead_givcrypt_request *req,
@@ -529,5 +101,4 @@ static inline void aead_givcrypt_set_giv(struct aead_givcrypt_request *req,
        req->giv = giv;
        req->seq = seq;
 }
-
 #endif /* _CRYPTO_AEAD_H */
index d4ebf6e9af6a536c589d55c914e56f1c6000f910..a949bf70983b8a7234091415495a92e1ed03163c 100644 (file)
@@ -17,7 +17,6 @@
 #include <linux/kernel.h>
 #include <linux/skbuff.h>
 
-struct crypto_aead;
 struct module;
 struct rtattr;
 struct seq_file;
@@ -127,6 +126,7 @@ struct ablkcipher_walk {
 };
 
 extern const struct crypto_type crypto_ablkcipher_type;
+extern const struct crypto_type crypto_aead_type;
 extern const struct crypto_type crypto_blkcipher_type;
 
 void crypto_mod_put(struct crypto_alg *alg);
@@ -241,6 +241,22 @@ static inline void *crypto_ablkcipher_ctx_aligned(struct crypto_ablkcipher *tfm)
        return crypto_tfm_ctx_aligned(&tfm->base);
 }
 
+static inline struct aead_alg *crypto_aead_alg(struct crypto_aead *tfm)
+{
+       return &crypto_aead_tfm(tfm)->__crt_alg->cra_aead;
+}
+
+static inline void *crypto_aead_ctx(struct crypto_aead *tfm)
+{
+       return crypto_tfm_ctx(&tfm->base);
+}
+
+static inline struct crypto_instance *crypto_aead_alg_instance(
+       struct crypto_aead *aead)
+{
+       return crypto_tfm_alg_instance(&aead->base);
+}
+
 static inline struct crypto_blkcipher *crypto_spawn_blkcipher(
        struct crypto_spawn *spawn)
 {
@@ -349,6 +365,21 @@ static inline int ablkcipher_tfm_in_queue(struct crypto_queue *queue,
        return crypto_tfm_in_queue(queue, crypto_ablkcipher_tfm(tfm));
 }
 
+static inline void *aead_request_ctx(struct aead_request *req)
+{
+       return req->__ctx;
+}
+
+static inline void aead_request_complete(struct aead_request *req, int err)
+{
+       req->base.complete(&req->base, err);
+}
+
+static inline u32 aead_request_flags(struct aead_request *req)
+{
+       return req->base.flags;
+}
+
 static inline struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb,
                                                     u32 type, u32 mask)
 {
index a2d104aa343060d930893856a4a1e108f22a1784..750948cf46211c68c6e6a60f2d16793d129176c5 100644 (file)
@@ -23,40 +23,8 @@ struct crypto_aead_spawn {
        struct crypto_spawn base;
 };
 
-extern const struct crypto_type crypto_aead_type;
 extern const struct crypto_type crypto_nivaead_type;
 
-static inline struct aead_alg *crypto_aead_alg(struct crypto_aead *tfm)
-{
-       return &crypto_aead_tfm(tfm)->__crt_alg->cra_aead;
-}
-
-static inline void *crypto_aead_ctx(struct crypto_aead *tfm)
-{
-       return crypto_tfm_ctx(&tfm->base);
-}
-
-static inline struct crypto_instance *crypto_aead_alg_instance(
-       struct crypto_aead *aead)
-{
-       return crypto_tfm_alg_instance(&aead->base);
-}
-
-static inline void *aead_request_ctx(struct aead_request *req)
-{
-       return req->__ctx;
-}
-
-static inline void aead_request_complete(struct aead_request *req, int err)
-{
-       req->base.complete(&req->base, err);
-}
-
-static inline u32 aead_request_flags(struct aead_request *req)
-{
-       return req->base.flags;
-}
-
 static inline void crypto_set_aead_spawn(
        struct crypto_aead_spawn *spawn, struct crypto_instance *inst)
 {
@@ -82,7 +50,9 @@ static inline struct crypto_alg *crypto_aead_spawn_alg(
 static inline struct crypto_aead *crypto_spawn_aead(
        struct crypto_aead_spawn *spawn)
 {
-       return crypto_spawn_tfm2(&spawn->base);
+       return __crypto_aead_cast(
+               crypto_spawn_tfm(&spawn->base, CRYPTO_ALG_TYPE_AEAD,
+                                CRYPTO_ALG_TYPE_MASK));
 }
 
 struct crypto_instance *aead_geniv_alloc(struct crypto_template *tmpl,
@@ -94,7 +64,7 @@ void aead_geniv_exit(struct crypto_tfm *tfm);
 
 static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv)
 {
-       return geniv->child;
+       return crypto_aead_crt(geniv)->base;
 }
 
 static inline void *aead_givcrypt_reqctx(struct aead_givcrypt_request *req)
index b75ec14bbaf2c865100cdb899255a31b10664b19..10df5d2d093a7ffa14fd02fec144a5073562e194 100644 (file)
@@ -141,7 +141,6 @@ struct crypto_hash;
 struct crypto_rng;
 struct crypto_tfm;
 struct crypto_type;
-struct aead_request;
 struct aead_givcrypt_request;
 struct skcipher_givcrypt_request;
 
@@ -176,6 +175,32 @@ struct ablkcipher_request {
        void *__ctx[] CRYPTO_MINALIGN_ATTR;
 };
 
+/**
+ *     struct aead_request - AEAD request
+ *     @base: Common attributes for async crypto requests
+ *     @assoclen: Length in bytes of associated data for authentication
+ *     @cryptlen: Length of data to be encrypted or decrypted
+ *     @iv: Initialisation vector
+ *     @assoc: Associated data
+ *     @src: Source data
+ *     @dst: Destination data
+ *     @__ctx: Start of private context data
+ */
+struct aead_request {
+       struct crypto_async_request base;
+
+       unsigned int assoclen;
+       unsigned int cryptlen;
+
+       u8 *iv;
+
+       struct scatterlist *assoc;
+       struct scatterlist *src;
+       struct scatterlist *dst;
+
+       void *__ctx[] CRYPTO_MINALIGN_ATTR;
+};
+
 struct blkcipher_desc {
        struct crypto_blkcipher *tfm;
        void *info;
@@ -577,6 +602,21 @@ struct ablkcipher_tfm {
        unsigned int reqsize;
 };
 
+struct aead_tfm {
+       int (*setkey)(struct crypto_aead *tfm, const u8 *key,
+                     unsigned int keylen);
+       int (*encrypt)(struct aead_request *req);
+       int (*decrypt)(struct aead_request *req);
+       int (*givencrypt)(struct aead_givcrypt_request *req);
+       int (*givdecrypt)(struct aead_givcrypt_request *req);
+
+       struct crypto_aead *base;
+
+       unsigned int ivsize;
+       unsigned int authsize;
+       unsigned int reqsize;
+};
+
 struct blkcipher_tfm {
        void *iv;
        int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
@@ -622,6 +662,7 @@ struct rng_tfm {
 };
 
 #define crt_ablkcipher crt_u.ablkcipher
+#define crt_aead       crt_u.aead
 #define crt_blkcipher  crt_u.blkcipher
 #define crt_cipher     crt_u.cipher
 #define crt_hash       crt_u.hash
@@ -634,6 +675,7 @@ struct crypto_tfm {
        
        union {
                struct ablkcipher_tfm ablkcipher;
+               struct aead_tfm aead;
                struct blkcipher_tfm blkcipher;
                struct cipher_tfm cipher;
                struct hash_tfm hash;
@@ -652,6 +694,10 @@ struct crypto_ablkcipher {
        struct crypto_tfm base;
 };
 
+struct crypto_aead {
+       struct crypto_tfm base;
+};
+
 struct crypto_blkcipher {
        struct crypto_tfm base;
 };
@@ -1147,6 +1193,400 @@ static inline void ablkcipher_request_set_crypt(
        req->info = iv;
 }
 
+/**
+ * DOC: Authenticated Encryption With Associated Data (AEAD) Cipher API
+ *
+ * The AEAD cipher API is used with the ciphers of type CRYPTO_ALG_TYPE_AEAD
+ * (listed as type "aead" in /proc/crypto)
+ *
+ * The most prominent examples for this type of encryption is GCM and CCM.
+ * However, the kernel supports other types of AEAD ciphers which are defined
+ * with the following cipher string:
+ *
+ *     authenc(keyed message digest, block cipher)
+ *
+ * For example: authenc(hmac(sha256), cbc(aes))
+ *
+ * The example code provided for the asynchronous block cipher operation
+ * applies here as well. Naturally all *ablkcipher* symbols must be exchanged
+ * the *aead* pendants discussed in the following. In addtion, for the AEAD
+ * operation, the aead_request_set_assoc function must be used to set the
+ * pointer to the associated data memory location before performing the
+ * encryption or decryption operation. In case of an encryption, the associated
+ * data memory is filled during the encryption operation. For decryption, the
+ * associated data memory must contain data that is used to verify the integrity
+ * of the decrypted data. Another deviation from the asynchronous block cipher
+ * operation is that the caller should explicitly check for -EBADMSG of the
+ * crypto_aead_decrypt. That error indicates an authentication error, i.e.
+ * a breach in the integrity of the message. In essence, that -EBADMSG error
+ * code is the key bonus an AEAD cipher has over "standard" block chaining
+ * modes.
+ */
+
+static inline struct crypto_aead *__crypto_aead_cast(struct crypto_tfm *tfm)
+{
+       return (struct crypto_aead *)tfm;
+}
+
+/**
+ * crypto_alloc_aead() - allocate AEAD cipher handle
+ * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
+ *          AEAD cipher
+ * @type: specifies the type of the cipher
+ * @mask: specifies the mask for the cipher
+ *
+ * Allocate a cipher handle for an AEAD. The returned struct
+ * crypto_aead is the cipher handle that is required for any subsequent
+ * API invocation for that AEAD.
+ *
+ * Return: allocated cipher handle in case of success; IS_ERR() is true in case
+ *        of an error, PTR_ERR() returns the error code.
+ */
+struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask);
+
+static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm)
+{
+       return &tfm->base;
+}
+
+/**
+ * crypto_free_aead() - zeroize and free aead handle
+ * @tfm: cipher handle to be freed
+ */
+static inline void crypto_free_aead(struct crypto_aead *tfm)
+{
+       crypto_free_tfm(crypto_aead_tfm(tfm));
+}
+
+static inline struct aead_tfm *crypto_aead_crt(struct crypto_aead *tfm)
+{
+       return &crypto_aead_tfm(tfm)->crt_aead;
+}
+
+/**
+ * crypto_aead_ivsize() - obtain IV size
+ * @tfm: cipher handle
+ *
+ * The size of the IV for the aead referenced by the cipher handle is
+ * returned. This IV size may be zero if the cipher does not need an IV.
+ *
+ * Return: IV size in bytes
+ */
+static inline unsigned int crypto_aead_ivsize(struct crypto_aead *tfm)
+{
+       return crypto_aead_crt(tfm)->ivsize;
+}
+
+/**
+ * crypto_aead_authsize() - obtain maximum authentication data size
+ * @tfm: cipher handle
+ *
+ * The maximum size of the authentication data for the AEAD cipher referenced
+ * by the AEAD cipher handle is returned. The authentication data size may be
+ * zero if the cipher implements a hard-coded maximum.
+ *
+ * The authentication data may also be known as "tag value".
+ *
+ * Return: authentication data size / tag size in bytes
+ */
+static inline unsigned int crypto_aead_authsize(struct crypto_aead *tfm)
+{
+       return crypto_aead_crt(tfm)->authsize;
+}
+
+/**
+ * crypto_aead_blocksize() - obtain block size of cipher
+ * @tfm: cipher handle
+ *
+ * The block size for the AEAD referenced with the cipher handle is returned.
+ * The caller may use that information to allocate appropriate memory for the
+ * data returned by the encryption or decryption operation
+ *
+ * Return: block size of cipher
+ */
+static inline unsigned int crypto_aead_blocksize(struct crypto_aead *tfm)
+{
+       return crypto_tfm_alg_blocksize(crypto_aead_tfm(tfm));
+}
+
+static inline unsigned int crypto_aead_alignmask(struct crypto_aead *tfm)
+{
+       return crypto_tfm_alg_alignmask(crypto_aead_tfm(tfm));
+}
+
+static inline u32 crypto_aead_get_flags(struct crypto_aead *tfm)
+{
+       return crypto_tfm_get_flags(crypto_aead_tfm(tfm));
+}
+
+static inline void crypto_aead_set_flags(struct crypto_aead *tfm, u32 flags)
+{
+       crypto_tfm_set_flags(crypto_aead_tfm(tfm), flags);
+}
+
+static inline void crypto_aead_clear_flags(struct crypto_aead *tfm, u32 flags)
+{
+       crypto_tfm_clear_flags(crypto_aead_tfm(tfm), flags);
+}
+
+/**
+ * crypto_aead_setkey() - set key for cipher
+ * @tfm: cipher handle
+ * @key: buffer holding the key
+ * @keylen: length of the key in bytes
+ *
+ * The caller provided key is set for the AEAD referenced by the cipher
+ * handle.
+ *
+ * Note, the key length determines the cipher type. Many block ciphers implement
+ * different cipher modes depending on the key size, such as AES-128 vs AES-192
+ * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128
+ * is performed.
+ *
+ * Return: 0 if the setting of the key was successful; < 0 if an error occurred
+ */
+static inline int crypto_aead_setkey(struct crypto_aead *tfm, const u8 *key,
+                                    unsigned int keylen)
+{
+       struct aead_tfm *crt = crypto_aead_crt(tfm);
+
+       return crt->setkey(crt->base, key, keylen);
+}
+
+/**
+ * crypto_aead_setauthsize() - set authentication data size
+ * @tfm: cipher handle
+ * @authsize: size of the authentication data / tag in bytes
+ *
+ * Set the authentication data size / tag size. AEAD requires an authentication
+ * tag (or MAC) in addition to the associated data.
+ *
+ * Return: 0 if the setting of the key was successful; < 0 if an error occurred
+ */
+int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize);
+
+static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req)
+{
+       return __crypto_aead_cast(req->base.tfm);
+}
+
+/**
+ * crypto_aead_encrypt() - encrypt plaintext
+ * @req: reference to the aead_request handle that holds all information
+ *      needed to perform the cipher operation
+ *
+ * Encrypt plaintext data using the aead_request handle. That data structure
+ * and how it is filled with data is discussed with the aead_request_*
+ * functions.
+ *
+ * IMPORTANT NOTE The encryption operation creates the authentication data /
+ *               tag. That data is concatenated with the created ciphertext.
+ *               The ciphertext memory size is therefore the given number of
+ *               block cipher blocks + the size defined by the
+ *               crypto_aead_setauthsize invocation. The caller must ensure
+ *               that sufficient memory is available for the ciphertext and
+ *               the authentication tag.
+ *
+ * Return: 0 if the cipher operation was successful; < 0 if an error occurred
+ */
+static inline int crypto_aead_encrypt(struct aead_request *req)
+{
+       return crypto_aead_crt(crypto_aead_reqtfm(req))->encrypt(req);
+}
+
+/**
+ * crypto_aead_decrypt() - decrypt ciphertext
+ * @req: reference to the ablkcipher_request handle that holds all information
+ *      needed to perform the cipher operation
+ *
+ * Decrypt ciphertext data using the aead_request handle. That data structure
+ * and how it is filled with data is discussed with the aead_request_*
+ * functions.
+ *
+ * IMPORTANT NOTE The caller must concatenate the ciphertext followed by the
+ *               authentication data / tag. That authentication data / tag
+ *               must have the size defined by the crypto_aead_setauthsize
+ *               invocation.
+ *
+ *
+ * Return: 0 if the cipher operation was successful; -EBADMSG: The AEAD
+ *        cipher operation performs the authentication of the data during the
+ *        decryption operation. Therefore, the function returns this error if
+ *        the authentication of the ciphertext was unsuccessful (i.e. the
+ *        integrity of the ciphertext or the associated data was violated);
+ *        < 0 if an error occurred.
+ */
+static inline int crypto_aead_decrypt(struct aead_request *req)
+{
+       if (req->cryptlen < crypto_aead_authsize(crypto_aead_reqtfm(req)))
+               return -EINVAL;
+
+       return crypto_aead_crt(crypto_aead_reqtfm(req))->decrypt(req);
+}
+
+/**
+ * DOC: Asynchronous AEAD Request Handle
+ *
+ * The aead_request data structure contains all pointers to data required for
+ * the AEAD cipher operation. This includes the cipher handle (which can be
+ * used by multiple aead_request instances), pointer to plaintext and
+ * ciphertext, asynchronous callback function, etc. It acts as a handle to the
+ * aead_request_* API calls in a similar way as AEAD handle to the
+ * crypto_aead_* API calls.
+ */
+
+/**
+ * crypto_aead_reqsize() - obtain size of the request data structure
+ * @tfm: cipher handle
+ *
+ * Return: number of bytes
+ */
+static inline unsigned int crypto_aead_reqsize(struct crypto_aead *tfm)
+{
+       return crypto_aead_crt(tfm)->reqsize;
+}
+
+/**
+ * aead_request_set_tfm() - update cipher handle reference in request
+ * @req: request handle to be modified
+ * @tfm: cipher handle that shall be added to the request handle
+ *
+ * Allow the caller to replace the existing aead handle in the request
+ * data structure with a different one.
+ */
+static inline void aead_request_set_tfm(struct aead_request *req,
+                                       struct crypto_aead *tfm)
+{
+       req->base.tfm = crypto_aead_tfm(crypto_aead_crt(tfm)->base);
+}
+
+/**
+ * aead_request_alloc() - allocate request data structure
+ * @tfm: cipher handle to be registered with the request
+ * @gfp: memory allocation flag that is handed to kmalloc by the API call.
+ *
+ * Allocate the request data structure that must be used with the AEAD
+ * encrypt and decrypt API calls. During the allocation, the provided aead
+ * handle is registered in the request data structure.
+ *
+ * Return: allocated request handle in case of success; IS_ERR() is true in case
+ *        of an error, PTR_ERR() returns the error code.
+ */
+static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm,
+                                                     gfp_t gfp)
+{
+       struct aead_request *req;
+
+       req = kmalloc(sizeof(*req) + crypto_aead_reqsize(tfm), gfp);
+
+       if (likely(req))
+               aead_request_set_tfm(req, tfm);
+
+       return req;
+}
+
+/**
+ * aead_request_free() - zeroize and free request data structure
+ * @req: request data structure cipher handle to be freed
+ */
+static inline void aead_request_free(struct aead_request *req)
+{
+       kzfree(req);
+}
+
+/**
+ * aead_request_set_callback() - set asynchronous callback function
+ * @req: request handle
+ * @flags: specify zero or an ORing of the flags
+ *        CRYPTO_TFM_REQ_MAY_BACKLOG the request queue may back log and
+ *        increase the wait queue beyond the initial maximum size;
+ *        CRYPTO_TFM_REQ_MAY_SLEEP the request processing may sleep
+ * @compl: callback function pointer to be registered with the request handle
+ * @data: The data pointer refers to memory that is not used by the kernel
+ *       crypto API, but provided to the callback function for it to use. Here,
+ *       the caller can provide a reference to memory the callback function can
+ *       operate on. As the callback function is invoked asynchronously to the
+ *       related functionality, it may need to access data structures of the
+ *       related functionality which can be referenced using this pointer. The
+ *       callback function can access the memory via the "data" field in the
+ *       crypto_async_request data structure provided to the callback function.
+ *
+ * Setting the callback function that is triggered once the cipher operation
+ * completes
+ *
+ * The callback function is registered with the aead_request handle and
+ * must comply with the following template
+ *
+ *     void callback_function(struct crypto_async_request *req, int error)
+ */
+static inline void aead_request_set_callback(struct aead_request *req,
+                                            u32 flags,
+                                            crypto_completion_t compl,
+                                            void *data)
+{
+       req->base.complete = compl;
+       req->base.data = data;
+       req->base.flags = flags;
+}
+
+/**
+ * aead_request_set_crypt - set data buffers
+ * @req: request handle
+ * @src: source scatter / gather list
+ * @dst: destination scatter / gather list
+ * @cryptlen: number of bytes to process from @src
+ * @iv: IV for the cipher operation which must comply with the IV size defined
+ *      by crypto_aead_ivsize()
+ *
+ * Setting the source data and destination data scatter / gather lists.
+ *
+ * For encryption, the source is treated as the plaintext and the
+ * destination is the ciphertext. For a decryption operation, the use is
+ * reversed - the source is the ciphertext and the destination is the plaintext.
+ *
+ * IMPORTANT NOTE AEAD requires an authentication tag (MAC). For decryption,
+ *               the caller must concatenate the ciphertext followed by the
+ *               authentication tag and provide the entire data stream to the
+ *               decryption operation (i.e. the data length used for the
+ *               initialization of the scatterlist and the data length for the
+ *               decryption operation is identical). For encryption, however,
+ *               the authentication tag is created while encrypting the data.
+ *               The destination buffer must hold sufficient space for the
+ *               ciphertext and the authentication tag while the encryption
+ *               invocation must only point to the plaintext data size. The
+ *               following code snippet illustrates the memory usage
+ *               buffer = kmalloc(ptbuflen + (enc ? authsize : 0));
+ *               sg_init_one(&sg, buffer, ptbuflen + (enc ? authsize : 0));
+ *               aead_request_set_crypt(req, &sg, &sg, ptbuflen, iv);
+ */
+static inline void aead_request_set_crypt(struct aead_request *req,
+                                         struct scatterlist *src,
+                                         struct scatterlist *dst,
+                                         unsigned int cryptlen, u8 *iv)
+{
+       req->src = src;
+       req->dst = dst;
+       req->cryptlen = cryptlen;
+       req->iv = iv;
+}
+
+/**
+ * aead_request_set_assoc() - set the associated data scatter / gather list
+ * @req: request handle
+ * @assoc: associated data scatter / gather list
+ * @assoclen: number of bytes to process from @assoc
+ *
+ * For encryption, the memory is filled with the associated data. For
+ * decryption, the memory must point to the associated data.
+ */
+static inline void aead_request_set_assoc(struct aead_request *req,
+                                         struct scatterlist *assoc,
+                                         unsigned int assoclen)
+{
+       req->assoc = assoc;
+       req->assoclen = assoclen;
+}
+
 /**
  * DOC: Synchronous Block Cipher API
  *