* [PATCH] crypto: AEAD: add check for presence of auth tag
@ 2014-12-30 21:16 Stephan Mueller
2015-01-05 10:19 ` Herbert Xu
0 siblings, 1 reply; 7+ messages in thread
From: Stephan Mueller @ 2014-12-30 21:16 UTC (permalink / raw)
To: 'Herbert Xu'; +Cc: 'LKML', linux-crypto
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] crypto: AEAD: add check for presence of auth tag
2014-12-30 21:16 [PATCH] crypto: AEAD: add check for presence of auth tag Stephan Mueller
@ 2015-01-05 10:19 ` Herbert Xu
2015-01-05 10:26 ` Stephan Mueller
0 siblings, 1 reply; 7+ messages in thread
From: Herbert Xu @ 2015-01-05 10:19 UTC (permalink / raw)
To: Stephan Mueller; +Cc: 'LKML', linux-crypto
On Tue, Dec 30, 2014 at 10:16:03PM +0100, Stephan Mueller wrote:
> 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.
There is no need to vet the scatterlist. For kernel users it's
up to them to ensure that the length is valid with respect to the
sg list.
For the user-space interface obviously you should ensure that a
valid length is supplied.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] crypto: AEAD: add check for presence of auth tag
2015-01-05 10:19 ` Herbert Xu
@ 2015-01-05 10:26 ` Stephan Mueller
2015-01-05 10:39 ` Herbert Xu
0 siblings, 1 reply; 7+ messages in thread
From: Stephan Mueller @ 2015-01-05 10:26 UTC (permalink / raw)
To: Herbert Xu; +Cc: 'LKML', linux-crypto
Am Montag, 5. Januar 2015, 21:19:01 schrieb Herbert Xu:
Hi Herbert,
> On Tue, Dec 30, 2014 at 10:16:03PM +0100, Stephan Mueller wrote:
> > 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.
>
> There is no need to vet the scatterlist. For kernel users it's
> up to them to ensure that the length is valid with respect to the
> sg list.
>
> For the user-space interface obviously you should ensure that a
> valid length is supplied.
Then it seems I misunderstood you in your last comments. I thought the check
that the authentication tag is present should be moved to the crypto API so
that all users benefit from it.
As the authentication tag is "inline" in the ciphertext data stream, the only
way I see to check for its presence is to verify that sufficient ciphertext is
provided.
If the AEAD user space interface should perform the check, then the code drop
provided with patch v6 would already cover that.
Could you please help me understand where that check should be and what should
be done at the crypto API level?
Thanks
--
Ciao
Stephan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] crypto: AEAD: add check for presence of auth tag
2015-01-05 10:26 ` Stephan Mueller
@ 2015-01-05 10:39 ` Herbert Xu
2015-01-05 10:53 ` Stephan Mueller
0 siblings, 1 reply; 7+ messages in thread
From: Herbert Xu @ 2015-01-05 10:39 UTC (permalink / raw)
To: Stephan Mueller; +Cc: 'LKML', linux-crypto
On Mon, Jan 05, 2015 at 11:26:48AM +0100, Stephan Mueller wrote:
>
> Could you please help me understand where that check should be and what should
> be done at the crypto API level?
All I was asking for is a length check like the one at the top
of crypto_authenc_decypt.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] crypto: AEAD: add check for presence of auth tag
2015-01-05 10:39 ` Herbert Xu
@ 2015-01-05 10:53 ` Stephan Mueller
2015-01-05 10:55 ` Herbert Xu
0 siblings, 1 reply; 7+ messages in thread
From: Stephan Mueller @ 2015-01-05 10:53 UTC (permalink / raw)
To: Herbert Xu; +Cc: 'LKML', linux-crypto
Am Montag, 5. Januar 2015, 21:39:57 schrieb Herbert Xu:
Hi Herbert,
> On Mon, Jan 05, 2015 at 11:26:48AM +0100, Stephan Mueller wrote:
> > Could you please help me understand where that check should be and what
> > should be done at the crypto API level?
>
> All I was asking for is a length check like the one at the top
> of crypto_authenc_decypt.
Could you please check: I am unable to find the function.
Note, there is no size parameter provided in crypto_aead_decrypt. To obtain
the size, I would need to walk the scatterlists, no?
>
> Cheers,
--
Ciao
Stephan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] crypto: AEAD: add check for presence of auth tag
2015-01-05 10:53 ` Stephan Mueller
@ 2015-01-05 10:55 ` Herbert Xu
2015-01-05 11:00 ` Stephan Mueller
0 siblings, 1 reply; 7+ messages in thread
From: Herbert Xu @ 2015-01-05 10:55 UTC (permalink / raw)
To: Stephan Mueller; +Cc: 'LKML', linux-crypto
On Mon, Jan 05, 2015 at 11:53:38AM +0100, Stephan Mueller wrote:
>
> Could you please check: I am unable to find the function.
It's in crypto/authenc.c.
> Note, there is no size parameter provided in crypto_aead_decrypt. To obtain
> the size, I would need to walk the scatterlists, no?
The cryptlen is supposed to contain the entire input apart from the
AD, including the authentication tag if one is present.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] crypto: AEAD: add check for presence of auth tag
2015-01-05 10:55 ` Herbert Xu
@ 2015-01-05 11:00 ` Stephan Mueller
0 siblings, 0 replies; 7+ messages in thread
From: Stephan Mueller @ 2015-01-05 11:00 UTC (permalink / raw)
To: Herbert Xu; +Cc: 'LKML', linux-crypto
Am Montag, 5. Januar 2015, 21:55:40 schrieb Herbert Xu:
Hi Herbert,
> On Mon, Jan 05, 2015 at 11:53:38AM +0100, Stephan Mueller wrote:
> > Could you please check: I am unable to find the function.
>
> It's in crypto/authenc.c.
>
> > Note, there is no size parameter provided in crypto_aead_decrypt. To
> > obtain
> > the size, I would need to walk the scatterlists, no?
>
> The cryptlen is supposed to contain the entire input apart from the
> AD, including the authentication tag if one is present.
Thanks a lot for the pointer, I overlooked the cryptlen member variable. I
will update the patch to replace the scatterlist walk with such small check.
--
Ciao
Stephan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-01-05 11:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-30 21:16 [PATCH] crypto: AEAD: add check for presence of auth tag Stephan Mueller
2015-01-05 10:19 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox