From: Stephan Mueller <smueller@chronox.de>
To: 'Herbert Xu' <herbert@gondor.apana.org.au>
Cc: 'LKML' <linux-kernel@vger.kernel.org>, linux-crypto@vger.kernel.org
Subject: [PATCH] crypto: AEAD: add check for presence of auth tag
Date: Tue, 30 Dec 2014 22:16:03 +0100 [thread overview]
Message-ID: <15957213.Wu7Np8vQse@tachyon.chronox.de> (raw)
The AEAD decryption operation requires the authentication tag to be
present as part of the cipher text buffer. The added check verifies that
the caller provides a cipher text buffer with at least the
authentication tag.
As the cipher text is provided as a scatterlist, loop through the
scatterlist until we know we have sufficient cipher text bytes to invoke
the AEAD decryption operation.
As the authentication tag is typically smaller or equal to one block of
the cipher (except for authenc operations), it is expected that the
while loop iterating through the scatterlist is traversed not more than
once. Thus, the speed penalty should be marginal.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
---
include/linux/crypto.h | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 9c8776d..badc53b 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -24,6 +24,7 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/uaccess.h>
+#include <linux/scatterlist.h>
/*
* Autoloaded crypto modules should only use a prefixed name to avoid allowing
@@ -1412,7 +1413,18 @@ static inline int crypto_aead_encrypt(struct aead_request *req)
*/
static inline int crypto_aead_decrypt(struct aead_request *req)
{
- return crypto_aead_crt(crypto_aead_reqtfm(req))->decrypt(req);
+ struct scatterlist *sg = req->src;
+ unsigned int size = 0;
+
+ /* ensure that the ciphertext at least contains the auth tag */
+ while (sg) {
+ size += sg->length;
+ if (crypto_aead_authsize(crypto_aead_reqtfm(req)) <= size)
+ return crypto_aead_crt(
+ crypto_aead_reqtfm(req))->decrypt(req);
+ sg = sg_next(sg);
+ }
+ return -EINVAL;
}
/**
--
2.1.0
next reply other threads:[~2014-12-30 21:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-30 21:16 Stephan Mueller [this message]
2015-01-05 10:19 ` [PATCH] crypto: AEAD: add check for presence of auth tag Herbert Xu
2015-01-05 10:26 ` Stephan Mueller
2015-01-05 10:39 ` Herbert Xu
2015-01-05 10:53 ` Stephan Mueller
2015-01-05 10:55 ` Herbert Xu
2015-01-05 11:00 ` Stephan Mueller
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=15957213.Wu7Np8vQse@tachyon.chronox.de \
--to=smueller@chronox.de \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@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).