summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-05-21 15:11:01 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2015-05-22 11:25:51 +0800
commit996d98d85ccc27d9c592ad7dc1371c60cd6585cc (patch)
treea7f9c96dc0ec10e5761495fc2116d4d3364705bd /include
parentfc42bcba97bae738f905b83741134a63af7e6c02 (diff)
crypto: aead - Add new interface with single SG list
The primary user of AEAD, IPsec includes the IV in the AD in most cases, except where it is implicitly authenticated by the underlying algorithm. The way it is currently implemented is a hack because we pass the data in piecemeal and the underlying algorithms try to stitch them back up into one piece. This is why this patch is adding a new interface that allows a single SG list to be passed in that contains everything so the algorithm implementors do not have to stitch. The new interface accepts a single source SG list and a single destination SG list. Both must be laid out as follows: AD, skipped data, plain/cipher text, ICV The ICV is not present from the source during encryption and from the destination during decryption. For the top-level IPsec AEAD algorithm the plain/cipher text will contain the generated (or received) IV. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include')
-rw-r--r--include/crypto/aead.h35
1 files changed, 29 insertions, 6 deletions
diff --git a/include/crypto/aead.h b/include/crypto/aead.h
index dbcad08f4891..e2d2c3c62e68 100644
--- a/include/crypto/aead.h
+++ b/include/crypto/aead.h
@@ -52,6 +52,7 @@
* @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
+ * @cryptoff: Bytes to skip after AD before plain/cipher text
* @iv: Initialisation vector
* @assoc: Associated data
* @src: Source data
@@ -61,8 +62,11 @@
struct aead_request {
struct crypto_async_request base;
+ bool old;
+
unsigned int assoclen;
unsigned int cryptlen;
+ unsigned int cryptoff;
u8 *iv;
@@ -314,10 +318,7 @@ static inline int crypto_aead_decrypt(struct aead_request *req)
*
* Return: number of bytes
*/
-static inline unsigned int crypto_aead_reqsize(struct crypto_aead *tfm)
-{
- return tfm->reqsize;
-}
+unsigned int crypto_aead_reqsize(struct crypto_aead *tfm);
/**
* aead_request_set_tfm() - update cipher handle reference in request
@@ -417,6 +418,9 @@ static inline void aead_request_set_callback(struct aead_request *req,
* destination is the ciphertext. For a decryption operation, the use is
* reversed - the source is the ciphertext and the destination is the plaintext.
*
+ * For both src/dst the layout is associated data, skipped data,
+ * plain/cipher text, authentication tag.
+ *
* 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
@@ -449,8 +453,7 @@ static inline void aead_request_set_crypt(struct aead_request *req,
* @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.
+ * Obsolete, do not use.
*/
static inline void aead_request_set_assoc(struct aead_request *req,
struct scatterlist *assoc,
@@ -458,6 +461,26 @@ static inline void aead_request_set_assoc(struct aead_request *req,
{
req->assoc = assoc;
req->assoclen = assoclen;
+ req->old = true;
+}
+
+/**
+ * aead_request_set_ad - set associated data information
+ * @req: request handle
+ * @assoclen: number of bytes in associated data
+ * @cryptoff: Number of bytes to skip after AD before plain/cipher text
+ *
+ * Setting the AD information. This function sets the length of
+ * the associated data and the number of bytes to skip after it to
+ * access the plain/cipher text.
+ */
+static inline void aead_request_set_ad(struct aead_request *req,
+ unsigned int assoclen,
+ unsigned int cryptoff)
+{
+ req->assoclen = assoclen;
+ req->cryptoff = cryptoff;
+ req->old = false;
}
static inline struct crypto_aead *aead_givcrypt_reqtfm(