linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Van Leeuwen, Pascal" <pvanleeuwen@rambus.com>
To: "Van Leeuwen, Pascal" <pvanleeuwen@rambus.com>,
	Stephan Mueller <smueller@chronox.de>
Cc: Eric Biggers <ebiggers@kernel.org>,
	Gilad Ben-Yossef <gilad@benyossef.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	David Miller <davem@davemloft.net>,
	Ofir Drang <Ofir.Drang@arm.com>
Subject: RE: Possible issue with new inauthentic AEAD in extended crypto tests
Date: Fri, 7 Feb 2020 15:50:07 +0000	[thread overview]
Message-ID: <SN4PR0401MB3663AF7E5A50BC4126D2713EC31C0@SN4PR0401MB3663.namprd04.prod.outlook.com> (raw)
In-Reply-To: <0795c353d60547539d23cd6db805f579@MN2PR20MB2973.namprd20.prod.outlook.com>

> -----Original Message-----
> From: linux-crypto-owner@vger.kernel.org <linux-crypto-owner@vger.kernel.org> On Behalf Of RBRpvanleeuwen
> Sent: Friday, February 7, 2020 4:37 PM
> To: Stephan Mueller <smueller@chronox.de>
> Cc: Eric Biggers <ebiggers@kernel.org>; Gilad Ben-Yossef <gilad@benyossef.com>; Herbert Xu <herbert@gondor.apana.org.au>;
> Linux Crypto Mailing List <linux-crypto@vger.kernel.org>; Geert Uytterhoeven <geert@linux-m68k.org>; David Miller
> <davem@davemloft.net>; Ofir Drang <Ofir.Drang@arm.com>
> Subject: RE: Possible issue with new inauthentic AEAD in extended crypto tests
>
> <<< External Email >>>
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the
> sender/sender address and know the content is safe.
>
>
> > -----Original Message-----
> > From: Stephan Mueller <smueller@chronox.de>
> > Sent: Friday, February 7, 2020 3:29 PM
> > To: Van Leeuwen, Pascal <pvanleeuwen@rambus.com>
> > Cc: Eric Biggers <ebiggers@kernel.org>; Gilad Ben-Yossef <gilad@benyossef.com>; Herbert Xu <herbert@gondor.apana.org.au>;
> > Linux Crypto Mailing List <linux-crypto@vger.kernel.org>; Geert Uytterhoeven <geert@linux-m68k.org>; David Miller
> > <davem@davemloft.net>; Ofir Drang <Ofir.Drang@arm.com>
> > Subject: Re: Possible issue with new inauthentic AEAD in extended crypto tests
> >
> > <<< External Email >>>
> > Am Freitag, 7. Februar 2020, 15:07:49 CET schrieb Van Leeuwen, Pascal:
> >
> > Hi Pascal,
> >
> > > Hi Stephan,
> > >
> > >
> > > > -----Original Message-----
> > > > From: linux-crypto-owner@vger.kernel.org
> > > > <linux-crypto-owner@vger.kernel.org> On Behalf Of Stephan Mueller
> >  Sent:
> > > > Friday, February 7, 2020 8:56 AM
> > > > To: Eric Biggers <ebiggers@kernel.org>
> > > > Cc: Gilad Ben-Yossef <gilad@benyossef.com>; Herbert Xu
> > > > <herbert@gondor.apana.org.au>; Linux Crypto Mailing List <linux-
> > > > crypto@vger.kernel.org>; Geert Uytterhoeven <geert@linux-m68k.org>; David
> > > > Miller <davem@davemloft.net>; Ofir Drang <Ofir.Drang@arm.com>
> > > > Subject: Re: Possible issue with new inauthentic AEAD in extended crypto
> > > > tests
> > >
> > > >
> > > >
> > > > <<< External Email >>>
> > > > CAUTION: This email originated from outside of the organization. Do not
> > > > click links or open attachments unless you recognize the
> >  sender/sender
> > > > address and know the content is safe.
> > > >
> > > >
> > > >
> > > >
> > > > Am Freitag, 7. Februar 2020, 08:27:09 CET schrieb Eric Biggers:
> > > >
> > > >
> > > >
> > > > Hi Eric,
> > > >
> > > >
> > > >
> > > > > On Wed, Feb 05, 2020 at 04:48:16PM +0200, Gilad Ben-Yossef wrote:
> > > > >
> > > > > > Probably another issue with my driver, but just in case -
> > > > > >
> > > > > >
> > > > > >
> > > > > > include/crypot/aead.h says:
> > > > > >
> > > > > >  * The scatter list pointing to the input data must contain:
> > > > > >  *
> > > > > >  * * for RFC4106 ciphers, the concatenation of
> > > > > >  *   associated authentication data || IV || plaintext or ciphertext.
> > > > > >  Note, the *   same IV (buffer) is also set with the
> > > > > >  aead_request_set_crypt call. Note, *   the API call of
> > > > > >  aead_request_set_ad must provide the length of the AAD and *   the
> > > > > >  IV.
> > > > > >  The API call of aead_request_set_crypt only points to the size of *
> > > > > >  the input plaintext or ciphertext.
> > > > > >
> > > > > >
> > > > > >
> > > > > > I seem to be missing the place where this is handled in
> > > > > > generate_random_aead_testvec()
> > > > > > and generate_aead_message()
> > > > > >
> > > > > >
> > > > > >
> > > > > > We seem to be generating a random IV for providing as the parameter
> > > > > > to
> > > > > > aead_request_set_crypt()
> > > > > > but than have other random bytes set in aead_request_set_ad() - or am
> > > > > > I'm missing something again?
> > > > >
> > > > >
> > > > >
> > > > > Yes, for rfc4106 the tests don't pass the same IV in both places.  This
> > > > > is
> > > > > because I wrote the tests from the perspective of a generic AEAD that
> > > > > doesn't have this weird IV quirk, and then I added the minimum quirks
> > > > > to
> > > > > get the weird algorithms like rfc4106 passing.
> > > > >
> > > > >
> > > > >
> > > > > Since the actual behavior of the generic implementation of rfc4106 is
> > > > > that
> > > > > the last 8 bytes of the AAD are ignored, that means that currently the
> > > > > tests just avoid mutating these bytes when generating inauthentic input
> > > > > tests.  They don't know that they're (apparently) meant to be another
> > > > > copy
> > > > > of the IV.
> > > > >
> > > > >
> > > > >
> > > > > So it seems we need to clearly define the behavior when the two IV
> > > > > copies
> > > > > don't match.  Should one or the other be used, should an error be
> > > > > returned,
> >  or should the behavior be unspecified (in which case the
> > > > > tests would need to be updated)?
> > > > >
> > > > >
> > > > >
> > > > > Unspecified behavior is bad, but it would be easiest for software to
> > > > > use
> > > > > req->iv, while hardware might want to use the IV in the scatterlist...
> > > > >
> > > > >
> > > > >
> > > > > Herbert and Stephan, any idea what was intended here?
> > > > >
> > > > >
> > > > >
> > > > > - Eric
> > > >
> > > >
> > > >
> > > > The full structure of RFC4106 is the following:
> > > >
> > > >
> > > >
> > > > - the key to be set is always 4 bytes larger than required for the
> > > > respective
> >  AES operation (i.e. the key is 20, 28 or 36 bytes
> > > > respectively). The key value contains the following information: key ||
> > > > first 4 bytes of the IV (note, the first 4 bytes of the IV are the bytes
> > > > derived from the KDF invoked by IKE - i.e. they come from user space and
> > > > are fixed)
> > > >
> > > >
> > > >
> > > > - data block contains AAD || trailing 8 bytes of IV || plaintext or
> > > > ciphertext
> >  - the trailing 8 bytes of the IV are the SPI which is updated
> > > > for each new IPSec package
> > > >
> > > >
> > >
> > > By SPI you must mean sequence number?
> > > (The SPI is actually the SA index which certainly doesn't change per
> > > packet!)
> > > That would be one possible way of generating the explicit IV, but
> > > you certainly cannot count on that. Anything unique under the key would be
> > > fine for GCM.
> >
> > The IV actually is generated with an IV generator (I think it is the SEQIV
> > generator from crypto/seqiv.c - it is set in the XFRM framework). It is a
> > deterministic construction XORed with a random number from the SP800-90A DRBG.
> >
> That would be a good way of generating IV's for CBC mode (which requires
> unpredictability and sufficient Hamming distance precluding a counter), but I would not
> recommend that for CTR based modes like GCM, where all you need is a nonce because:
>
> a) randomness does not guarantee uniqueness perse
> b) it is far too heavy on the CPU for this purpose
>
> So I would certainly hope it doesn't do it like that? The name seqiv alone would imply
> something based on a sequence numberand not a DRBG  ... IIRC it was doing sequence
> number XOR some key material?
>
> > >
> > > > aead_request_set_ad points to the AAD plus the 8 bytes of IV in the use
> > > > case
> >  of rfc4106(gcm(aes)) as part of IPSec.
> > > >
> > > >
> > > >
> > > > Considering your question about the aead_request_set_ad vs
> > > > aead_request_set_crypt I think the RFC4106 gives the answer: the IV is
> > > > used in
> >  two locations considering that the IV is also the SPI in our
> > > > case. If you see RFC 4106 chapter 3 you see the trailing 8 bytes of the
> > > > IV as, well, the GCM IV (which is extended by the 4 byte salt as defined
> > > > in chapter 4 that we provide with the trailing 4 bytes of the key). The
> > > > kernel uses the SPI for this.>
> > > >
> > >
> > > Again, by  SPI you must mean sequence number. The SPI itself is entirely
> > > seperate.
> >
> > See above, it is actually not the SPI, or sequence number, it is what the IV
> > generator provides.
> >
> Yes. But what you were describing sounded like the sequence number.
> Which would be perfectly legal to use _directly_ for this (unlike the SPI).
> Thats what our hardware does in case of full protocol offload.
>
> > > So the IV is not "used in two places", it is only used as IV for
> > > the AEAD operation, with the explicit part (8 bytes) inserted into the
> > > packet.
> > > [For GCM the IV, despite being in the AAD buffer,  is _not_ authenticated]
> > > The sequence number _may_ be used in two places (AAD and explicit part of
> > > the IV),
> > > but that is not a given and out of the scope of the crypto API. I
> > > would not make any assumptions there.
> > >
> > > The "problem" Gilad was referring to is that the _explicit_ part of the  IV
> > > appears to be
> > > available  from both req->iv and from the AAD scatterbuffer.
> > > Which one should you use? API wise I would assume req->iv but from a (our)
> > > hardware perspective, it would be more efficient to extract it from the
> > > datastream. But is it allowed to assume there is a valid IV stored there?
> > > (which implies that it has to match req->iv, otherwise behaviour would
> > > deviate from implementations using that)
> >
> > req->iv is your IV.
> >
> But the IV is also in the last bytes of the AAD buffer. Which would be _way_ more
> convenient to use _directly_ compared to req->iv.
> Saves a lot of effort in both the driver and the HW to get the IV to where it
> is actually needed. For _our_ driver and hardware, anyway.
>
> So that's the point: if it's already where you want it to be, then why insisting
> on getting it from a different location (i.e. req->iv) just for the sake of entertaining
> some generic API? These rfcxxxx ciphersuites appear to be for a very specific use
> case  (IPsec) and are already deviating from the normal AEAD implementations.
>
> > The use of the IV as part of the AAD is just a use case for rfc4106.
> >
> No, it is most definitely not. The IV is _not_ part of the AAD for rfc4106.
> Just take another long look at chapter 5 and tell me where it says "IV".
> It's just SPI and (full extended) sequence number, no more.
>
> So actually, the implementation needs to be aware of this and stop
> authenticating IV size bytes before the end of the AAD buffer. Which is
> rather strange if you think about it ... but I guess it is what is is now.
>
Then again, this was probably done to provide a common AEAD API from the
kernel IPsec stack, such that that doesn't need to worry about these ciphersuite
specific details ... and that had to be shoe-horned into the existing kernel crypto
API also making sure it doesn't get inefficient on that side ...

> > Although
> > I doubt that the rfc4106 structure will change any time soon, I would not use
> > the IV from the AAD but only look at the req->iv.
> >
> That is what I did mostly because I didn't know if I could rely on the IV in the
> AAD buffer being correct.
> BUT if you're not allowed to use it from the AAD buffer, then why is it even there?
>
> Let's put it differently: if I _would_ take it from the AAD buffer instead of req->iv,
> the current test vectors from testmgr.h would pass just fine(!)
>
> And how about GMAC (rfc4543), where IV _does_ need to be authenticated. If
> it doesn't match req->iv there, it would certainly not result in output complying
> with rfc4543. (though you could argue this to be useful for _other_ purposes)
>
> I think, especially considering the only user being the kernel IPsec stack here,
> it would make some sense to _require_ req->iv to match the AAD buffer IV and
> allow taking the IV from there instead of from req->iv, if that is more convenient.
>
> > >
> > > > In chapter 5 RFC4106 you see that the SP is however used as part of the
> > > > AAD as
> >  well.
> > > >
> > > >
> > > >
> > > > Bottom line: if you do not set the same IV value for both, the AAD and the
> > > > GCM
> >  IV, you deviate from the use case of rfc4106(gcm(aes)) in IPSec.
> > > > Yet, from a pure mathematical point of view and also from a cipher
> > > > implementation point of view, it does not matter whether the AAD and the
> > > > IV point to the same value - the implementation must always process that
> > > > data. The result however will not be identical to the IPSec use case.
> > > >
> > > >
> > >
> > > For the IPsec use case, it's perfectly legal to have IV != sequence number
> > > as long
> > > as it is unique under the key.
> >
> > Right, it is a perfectly legal way of doing it, but it is currently not done
> > that way in the kernel.
> >
> I guess my main point was there is no "IV for AAD" (if not the sequence number)
> so it can't possibly mismatch the "IV for GCM", ergo it's not possible to deviate from
> any IPsec use case. (for GCM anyway, for GMAC you could)
>
> > Thus, I would reiterate my suggestion from above to always use req->iv as your IV.
> >
> Which is what I do, BUT is rather silly _if_ req->iv in practice will always point to
> the IV stored in the AAD scatter buffer.
>
> > > So you should not assume the sequence number part of the AAD buffer to
> > > match
> > > the IV part (or req->iv), but it _would_ make sense if the IV part
> > > of the AAD matches req->iv. (then again, if this is not _required_ by the
> > > API the application might not bother providing it, which is my reason not
> > > to use in in the inside_secure driver)
> >
> > Precisely.
> >
> > Ciao
> > Stephan
>
> Regards,
> Pascal van Leeuwen
> Silicon IP Architect Multi-Protocol Engines, Rambus Security
> Rambus ROTW Holding BV
> +31-73 6581953
>
> Note: The Inside Secure/Verimatrix Silicon IP team was recently acquired by Rambus.
> Please be so kind to update your e-mail address book with my new e-mail address.
>
> ** This message and any attachments are for the sole use of the intended recipient(s). It may contain information that is confidential
> and privileged. If you are not the intended recipient of this message, you are prohibited from printing, copying, forwarding or saving it.
> Please delete the message and attachments and notify the sender immediately. **
>
> Rambus
> Inc.<https://nam12.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.rambus.com&amp;data=01%7C01%7Cpvanleeuwe
> n%40verimatrix.com%7C5c74040eea5748c69aee08d7abe388cb%7Cdcb260f9022d44958602eae51035a0d0%7C0&amp;sdata=Wlq96le14
> BiueepIAtGY6MykFRcKKcR7JGnYNAYVqPM%3D&amp;reserved=0>

Regards,
Pascal van Leeuwen
Silicon IP Architect Multi-Protocol Engines, Rambus Security
Rambus ROTW Holding BV
+31-73 6581953

Note: The Inside Secure/Verimatrix Silicon IP team was recently acquired by Rambus.
Please be so kind to update your e-mail address book with my new e-mail address.


** This message and any attachments are for the sole use of the intended recipient(s). It may contain information that is confidential and privileged. If you are not the intended recipient of this message, you are prohibited from printing, copying, forwarding or saving it. Please delete the message and attachments and notify the sender immediately. **

Rambus Inc.<http://www.rambus.com>

  parent reply	other threads:[~2020-02-07 15:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-27  8:04 Possible issue with new inauthentic AEAD in extended crypto tests Gilad Ben-Yossef
2020-01-28  2:34 ` Eric Biggers
2020-01-28  3:15   ` Stephan Mueller
2020-01-28  3:38   ` Herbert Xu
2020-01-28  7:24     ` Gilad Ben-Yossef
2020-01-28 21:12       ` Eric Biggers
2020-01-29 11:28         ` Gilad Ben-Yossef
     [not found]         ` <2f3e874fae2242d99f4e4095ae42eb75@MN2PR20MB2973.namprd20.prod.outlook.com>
2020-01-29 13:28           ` Van Leeuwen, Pascal
2020-02-05 14:48         ` Gilad Ben-Yossef
2020-02-07  7:27           ` Eric Biggers
2020-02-07  7:56             ` Stephan Mueller
2020-02-07 11:50               ` Gilad Ben-Yossef
2020-02-07 12:29                 ` Stephan Mueller
2020-02-09  8:04                   ` Gilad Ben-Yossef
     [not found]                   ` <7f68982502574b03931e7caad965e76f@MN2PR20MB2973.namprd20.prod.outlook.com>
2020-02-10  8:03                     ` Van Leeuwen, Pascal
     [not found]               ` <3b65754206a049e596efeb76619eef5c@MN2PR20MB2973.namprd20.prod.outlook.com>
2020-02-07 14:30                 ` Van Leeuwen, Pascal
     [not found]             ` <70156395ce424f41949feb13fd9f978b@MN2PR20MB2973.namprd20.prod.outlook.com>
2020-02-07 14:07               ` Van Leeuwen, Pascal
2020-02-07 14:29                 ` Stephan Mueller
2020-02-07 15:36                   ` Van Leeuwen, Pascal
     [not found]                   ` <0795c353d60547539d23cd6db805f579@MN2PR20MB2973.namprd20.prod.outlook.com>
2020-02-07 15:50                     ` Van Leeuwen, Pascal [this message]
2020-02-09  8:09                 ` Gilad Ben-Yossef
2020-02-10  8:05                   ` Van Leeuwen, Pascal
2020-02-10 11:04             ` Herbert Xu
     [not found]       ` <b5a529fd1abd46ea881b18c387fcd4dc@MN2PR20MB2973.namprd20.prod.outlook.com>
2020-01-29  0:18         ` Van Leeuwen, Pascal
2020-01-29  1:26           ` Stephan Mueller
     [not found]           ` <11489dad16d64075939db69181b5ecbb@MN2PR20MB2973.namprd20.prod.outlook.com>
2020-01-29  8:40             ` Van Leeuwen, Pascal
2020-01-29 12:54               ` Stephan Mueller
2020-01-29 13:42                 ` Van Leeuwen, Pascal

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=SN4PR0401MB3663AF7E5A50BC4126D2713EC31C0@SN4PR0401MB3663.namprd04.prod.outlook.com \
    --to=pvanleeuwen@rambus.com \
    --cc=Ofir.Drang@arm.com \
    --cc=davem@davemloft.net \
    --cc=ebiggers@kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=gilad@benyossef.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=smueller@chronox.de \
    /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).