Skip to content

Commit 3f692d5

Browse files
smuellerDDJonathan Corbet
authored andcommitted
crypto: doc - clarify AEAD memory structure
The previous description have been misleading and partially incorrect. Reported-by: Harsh Jain <[email protected]> Signed-off-by: Stephan Mueller <[email protected]> Signed-off-by: Jonathan Corbet <[email protected]>
1 parent 71f3f02 commit 3f692d5

File tree

2 files changed

+14
-36
lines changed

2 files changed

+14
-36
lines changed

crypto/algif_aead.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -551,18 +551,8 @@ static int aead_recvmsg_sync(struct socket *sock, struct msghdr *msg, int flags)
551551
lock_sock(sk);
552552

553553
/*
554-
* AEAD memory structure: For encryption, the tag is appended to the
555-
* ciphertext which implies that the memory allocated for the ciphertext
556-
* must be increased by the tag length. For decryption, the tag
557-
* is expected to be concatenated to the ciphertext. The plaintext
558-
* therefore has a memory size of the ciphertext minus the tag length.
559-
*
560-
* The memory structure for cipher operation has the following
561-
* structure:
562-
* AEAD encryption input: assoc data || plaintext
563-
* AEAD encryption output: cipherntext || auth tag
564-
* AEAD decryption input: assoc data || ciphertext || auth tag
565-
* AEAD decryption output: plaintext
554+
* Please see documentation of aead_request_set_crypt for the
555+
* description of the AEAD memory structure expected from the caller.
566556
*/
567557

568558
if (ctx->more) {

include/crypto/aead.h

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -483,30 +483,18 @@ static inline void aead_request_set_callback(struct aead_request *req,
483483
* destination is the ciphertext. For a decryption operation, the use is
484484
* reversed - the source is the ciphertext and the destination is the plaintext.
485485
*
486-
* For both src/dst the layout is associated data, plain/cipher text,
487-
* authentication tag.
488-
*
489-
* The content of the AD in the destination buffer after processing
490-
* will either be untouched, or it will contain a copy of the AD
491-
* from the source buffer. In order to ensure that it always has
492-
* a copy of the AD, the user must copy the AD over either before
493-
* or after processing. Of course this is not relevant if the user
494-
* is doing in-place processing where src == dst.
495-
*
496-
* IMPORTANT NOTE AEAD requires an authentication tag (MAC). For decryption,
497-
* the caller must concatenate the ciphertext followed by the
498-
* authentication tag and provide the entire data stream to the
499-
* decryption operation (i.e. the data length used for the
500-
* initialization of the scatterlist and the data length for the
501-
* decryption operation is identical). For encryption, however,
502-
* the authentication tag is created while encrypting the data.
503-
* The destination buffer must hold sufficient space for the
504-
* ciphertext and the authentication tag while the encryption
505-
* invocation must only point to the plaintext data size. The
506-
* following code snippet illustrates the memory usage
507-
* buffer = kmalloc(ptbuflen + (enc ? authsize : 0));
508-
* sg_init_one(&sg, buffer, ptbuflen + (enc ? authsize : 0));
509-
* aead_request_set_crypt(req, &sg, &sg, ptbuflen, iv);
486+
* The memory structure for cipher operation has the following structure:
487+
*
488+
* - AEAD encryption input: assoc data || plaintext
489+
* - AEAD encryption output: assoc data || cipherntext || auth tag
490+
* - AEAD decryption input: assoc data || ciphertext || auth tag
491+
* - AEAD decryption output: assoc data || plaintext
492+
*
493+
* Albeit the kernel requires the presence of the AAD buffer, however,
494+
* the kernel does not fill the AAD buffer in the output case. If the
495+
* caller wants to have that data buffer filled, the caller must either
496+
* use an in-place cipher operation (i.e. same memory location for
497+
* input/output memory location).
510498
*/
511499
static inline void aead_request_set_crypt(struct aead_request *req,
512500
struct scatterlist *src,

0 commit comments

Comments
 (0)