linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ondrej Mosnáček" <omosnacek@gmail.com>
To: Milan Broz <gmazyland@gmail.com>
Cc: Pascal Van Leeuwen <pvanleeuwen@verimatrix.com>,
	Pascal van Leeuwen <pascalvanl@gmail.com>,
	"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
	"rsnel@cube.dyndns.org" <rsnel@cube.dyndns.org>,
	"herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
	"davem@davemloft.net" <davem@davemloft.net>
Subject: Re: [PATCH] crypto: xts - Add support for Cipher Text Stealing
Date: Wed, 7 Aug 2019 22:32:35 +0200	[thread overview]
Message-ID: <CAAUqJDuMUHqd4J7TNRbMiEDNeb_GCJPhJUQJoOJo5zXKmL72nQ@mail.gmail.com> (raw)
In-Reply-To: <46f76b06-004e-c08a-3ef3-4ba9fdc61d91@gmail.com>

st 7. 8. 2019 o 19:44 Milan Broz <gmazyland@gmail.com> napísal(a):
> On 07/08/2019 17:13, Pascal Van Leeuwen wrote:
> >>>> Seems there is no mistake in your code, it is some bug in aesni_intel implementation.
> >>>> If I disable this module, it works as expected (with aes generic and aes_i586).
> >>>>
> >>> That's odd though, considering there is a dedicated xts-aes-ni implementation,
> >>> i.e. I would not expect that to end up at the generic xts wrapper at all?
> >>
> >> Note it is 32bit system, AESNI XTS is under #ifdef CONFIG_X86_64 so it is not used.
> >>
> > Ok, so I guess no one bothered to make an optimized XTS version for i386.
> > I quickly browsed through the code - took me a while to realise the assembly is
> > "backwards" compared to the original Intel definition :-) - but I did not spot
> > anything obvious :-(
> >
> >> I guess it only ECB part ...
>
> Mystery solved, the skcipher subreq must be te last member in the struct.
> (Some comments in Adiantum code mentions it too, so I do not think it
> just hides the corruption after the struct. Seems like another magic requirement
> in crypto API :-)

Oh, yes, this makes sense! I would have noticed this immediately if I
had looked carefully at the struct definition :) The reason is that
the skcipher_request struct is followed by a variable-length request
context. So when you want to nest requests, you need to make the
subrequest the last member and declare your request context size as:
size of your request context struct + size of the sub-algorithm's
request context.

It is a bit confusing, but it is the only reasonable way to support
variably sized context and at the same time keep the whole request in
a single allocation.

>
> This chunk is enough to fix it for me:
>
> --- a/crypto/xts.c
> +++ b/crypto/xts.c
> @@ -33,8 +33,8 @@ struct xts_instance_ctx {
>
>  struct rctx {
>         le128 t, tcur;
> -       struct skcipher_request subreq;
>         int rem_bytes, is_encrypt;
> +       struct skcipher_request subreq;
>  };
>
> While at it, shouldn't be is_encrypt bool?
>
> Thanks,
> Milan

  parent reply	other threads:[~2019-08-07 20:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06  6:55 [PATCH] crypto: xts - Add support for Cipher Text Stealing Pascal van Leeuwen
2019-08-06 18:34 ` Milan Broz
2019-08-06 19:36   ` Pascal Van Leeuwen
2019-08-07  8:15     ` Pascal Van Leeuwen
2019-08-07 11:19       ` Milan Broz
2019-08-07 11:27         ` Pascal Van Leeuwen
2019-08-07 11:41           ` Milan Broz
2019-08-07 15:13             ` Pascal Van Leeuwen
2019-08-07 17:24               ` Milan Broz
2019-08-07 20:26                 ` Pascal Van Leeuwen
2019-08-07 20:32                 ` Ondrej Mosnáček [this message]
2019-08-07 21:13                   ` Pascal Van Leeuwen
2019-08-08  4:35                     ` Milan Broz

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=CAAUqJDuMUHqd4J7TNRbMiEDNeb_GCJPhJUQJoOJo5zXKmL72nQ@mail.gmail.com \
    --to=omosnacek@gmail.com \
    --cc=davem@davemloft.net \
    --cc=gmazyland@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=pascalvanl@gmail.com \
    --cc=pvanleeuwen@verimatrix.com \
    --cc=rsnel@cube.dyndns.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).