linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephan Mueller <smueller@chronox.de>
To: herbert@gondor.apana.org.au
Cc: linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org,
	Harsh Jain <harshjain.prof@gmail.com>
Subject: [PATCH v2 7/8] crypto: doc - clarify AEAD memory structure
Date: Fri, 21 Oct 2016 04:59:24 +0200	[thread overview]
Message-ID: <3596198.suv0AJ2MEx@positron.chronox.de> (raw)
In-Reply-To: <2053893.WjF01BJSDF@positron.chronox.de>

The previous description have been misleading and partially incorrect.

Reported-by: Harsh Jain <harshjain.prof@gmail.com>
Signed-off-by: Stephan Mueller <smueller@chronox.de>
---
 crypto/algif_aead.c   | 14 ++------------
 include/crypto/aead.h | 36 ++++++++++++------------------------
 2 files changed, 14 insertions(+), 36 deletions(-)

diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c
index 80a0f1a..a0d8377 100644
--- a/crypto/algif_aead.c
+++ b/crypto/algif_aead.c
@@ -551,18 +551,8 @@ static int aead_recvmsg_sync(struct socket *sock, struct msghdr *msg, int flags)
 	lock_sock(sk);
 
 	/*
-	 * AEAD memory structure: For encryption, the tag is appended to the
-	 * ciphertext which implies that the memory allocated for the ciphertext
-	 * must be increased by the tag length. For decryption, the tag
-	 * is expected to be concatenated to the ciphertext. The plaintext
-	 * therefore has a memory size of the ciphertext minus the tag length.
-	 *
-	 * The memory structure for cipher operation has the following
-	 * structure:
-	 *	AEAD encryption input:  assoc data || plaintext
-	 *	AEAD encryption output: cipherntext || auth tag
-	 *	AEAD decryption input:  assoc data || ciphertext || auth tag
-	 *	AEAD decryption output: plaintext
+	 * Please see documentation of aead_request_set_crypt for the
+	 * description of the AEAD memory structure expected from the caller.
 	 */
 
 	if (ctx->more) {
diff --git a/include/crypto/aead.h b/include/crypto/aead.h
index e725155..03b9762 100644
--- a/include/crypto/aead.h
+++ b/include/crypto/aead.h
@@ -483,30 +483,18 @@ 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, plain/cipher text,
- * authentication tag.
- *
- * The content of the AD in the destination buffer after processing
- * will either be untouched, or it will contain a copy of the AD
- * from the source buffer.  In order to ensure that it always has
- * a copy of the AD, the user must copy the AD over either before
- * or after processing.  Of course this is not relevant if the user
- * is doing in-place processing where src == dst.
- *
- * 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);
+ * The memory structure for cipher operation has the following structure:
+ *
+ * - AEAD encryption input:  assoc data || plaintext
+ * - AEAD encryption output: assoc data || cipherntext || auth tag
+ * - AEAD decryption input:  assoc data || ciphertext || auth tag
+ * - AEAD decryption output: assoc data || plaintext
+ *
+ * Albeit the kernel requires the presence of the AAD buffer, however,
+ * the kernel does not fill the AAD buffer in the output case. If the
+ * caller wants to have that data buffer filled, the caller must either
+ * use an in-place cipher operation (i.e. same memory location for
+ * input/output memory location).
  */
 static inline void aead_request_set_crypt(struct aead_request *req,
 					  struct scatterlist *src,
-- 
2.7.4



  parent reply	other threads:[~2016-10-21  2:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-21  2:53 [PATCH v2 0/8] Conversion crypto API documentation to Sphinx Stephan Mueller
2016-10-21  2:54 ` [PATCH v2 1/8] crypto: doc - convert " Stephan Mueller
2016-10-21  2:57 ` [PATCH v2 2/8] crypto: doc - remove crypto API DocBook Stephan Mueller
2016-10-21  2:57 ` [PATCH v2 3/8] crypto: doc - fix source comments for Sphinx Stephan Mueller
2016-10-21  2:57 ` [PATCH v2 4/8] crypto: doc - fix separation of cipher / req API Stephan Mueller
2016-10-21  2:58 ` [PATCH v2 5/8] crypto: doc - add KPP documentation Stephan Mueller
2016-10-21  2:58 ` [PATCH v2 6/8] crypto: doc - remove crypto_alloc_ablkcipher Stephan Mueller
2016-10-21  2:59 ` Stephan Mueller [this message]
2016-10-21  3:00 ` [PATCH v2 8/8] crypto: doc - optimize compilation Stephan Mueller
2016-10-23 16:32 ` [PATCH v2 0/8] Conversion crypto API documentation to Sphinx Jonathan Corbet
2016-10-23 16:46   ` Stephan Mueller
2016-10-25  2:35     ` Herbert Xu
2016-12-13 21:25       ` Stephan Müller
2016-12-13 21:50         ` Jonathan Corbet
2016-12-13 22:06           ` Stephan Müller
2016-12-13 23:40             ` Jonathan Corbet
2016-12-14  7:01               ` Stephan Müller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3596198.suv0AJ2MEx@positron.chronox.de \
    --to=smueller@chronox.de \
    --cc=harshjain.prof@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).