All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hellermann <stefan@the2masters.de>
To: Sebastian Siewior <sebastian@breakpoint.cc>
Cc: Herbert Xu <herbert@gondor.apana.org.au>, linux-crypto@vger.kernel.org
Subject: Re: [PATCH] [PATCH] [crypto] LRW: use proper alignment.
Date: Sun, 02 Mar 2008 15:01:34 +0100	[thread overview]
Message-ID: <47CAB33E.2050207@the2masters.de> (raw)
In-Reply-To: <1b5471b654eea02f82ccf0aad032fbbb951cbbc5.1204465942.git.sebastian@breakpoint.cc>

Sebastian Siewior schrieb:
> The LRW blockmode uses a copy of the IV which is saved on the stack
> and may or may not be properly aligned. If it is not, it will break
> hardware cipher like the geode or padlock.
> This patch moves the copy of IV to the private structre which has the
> same aligment as the underlying cipher.
> Signed-off-by: Sebastian Siewior <sebastian@breakpoint.cc>

Tested-by: Stefan Hellermann <stefan@the2masters.de>

> ---
>  crypto/lrw.c |   32 ++++++++++++++++++--------------
>  1 files changed, 18 insertions(+), 14 deletions(-)
> 
> diff --git a/crypto/lrw.c b/crypto/lrw.c
> index 9d52e58..0c3ce3e 100644
> --- a/crypto/lrw.c
> +++ b/crypto/lrw.c
> @@ -27,7 +27,17 @@
>  #include <crypto/b128ops.h>
>  #include <crypto/gf128mul.h>
>  
> +struct sinfo {
> +	be128 t;
> +	struct crypto_tfm *tfm;
> +	void (*fn)(struct crypto_tfm *, u8 *, const u8 *);
> +};
> +
>  struct priv {
> +	/* s.t being the first member in this struct enforces proper alignment
> +	 * required by the underlying cipher without explicit knowing the it.
> +	 */
> +	struct sinfo s;
>  	struct crypto_cipher *child;
>  	/* optimizes multiplying a random (non incrementing, as at the
>  	 * start of a new sector) value with key2, we could also have
> @@ -83,12 +93,6 @@ static int setkey(struct crypto_tfm *parent, const u8 *key,
>  	return 0;
>  }
>  
> -struct sinfo {
> -	be128 t;
> -	struct crypto_tfm *tfm;
> -	void (*fn)(struct crypto_tfm *, u8 *, const u8 *);
> -};
> -
>  static inline void inc(be128 *iv)
>  {
>  	if (!(iv->b = cpu_to_be64(be64_to_cpu(iv->b) + 1)))
> @@ -128,14 +132,14 @@ static int crypt(struct blkcipher_desc *d,
>  	int err;
>  	unsigned int avail;
>  	const int bs = crypto_cipher_blocksize(ctx->child);
> -	struct sinfo s = {
> -		.tfm = crypto_cipher_tfm(ctx->child),
> -		.fn = fn
> -	};
> +	struct sinfo *s = &ctx->s;
>  	be128 *iv;
>  	u8 *wsrc;
>  	u8 *wdst;
>  
> +	s->tfm = crypto_cipher_tfm(ctx->child);
> +	s->fn = fn;
> +
>  	err = blkcipher_walk_virt(d, w);
>  	if (!(avail = w->nbytes))
>  		return err;
> @@ -145,10 +149,10 @@ static int crypt(struct blkcipher_desc *d,
>  
>  	/* calculate first value of T */
>  	iv = (be128 *)w->iv;
> -	s.t = *iv;
> +	s->t = *iv;
>  
>  	/* T <- I*Key2 */
> -	gf128mul_64k_bbe(&s.t, ctx->table);
> +	gf128mul_64k_bbe(&s->t, ctx->table);
>  
>  	goto first;
>  
> @@ -156,11 +160,11 @@ static int crypt(struct blkcipher_desc *d,
>  		do {
>  			/* T <- I*Key2, using the optimization
>  			 * discussed in the specification */
> -			be128_xor(&s.t, &s.t, &ctx->mulinc[get_index128(iv)]);
> +			be128_xor(&s->t, &s->t, &ctx->mulinc[get_index128(iv)]);
>  			inc(iv);
>  
>  first:
> -			lrw_round(&s, wdst, wsrc);
> +			lrw_round(s, wdst, wsrc);
>  
>  			wsrc += bs;
>  			wdst += bs;

  reply	other threads:[~2008-03-02 14:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-02 13:51 [PATCH] fix alignment problem in XTS and LRW blockmode Sebastian Siewior
2008-03-02 11:09 ` [PATCH] [crypto] XTS: use proper alignment Sebastian Siewior
2008-03-02 13:35   ` [PATCH] [PATCH] [crypto] LRW: " Sebastian Siewior
2008-03-02 14:01     ` Stefan Hellermann [this message]
2008-03-02 16:23       ` Herbert Xu
2008-03-05 11:17     ` Herbert Xu
2008-03-05 11:16   ` [PATCH] [crypto] XTS: " Herbert Xu
2008-03-05 11:46     ` Sebastian Siewior
2008-03-05 11:52       ` Herbert Xu
2008-03-05 12:01         ` Sebastian Siewior
2008-03-05 14:02           ` Stefan Hellermann
2008-03-05 16:37             ` Sebastian Siewior
2008-03-05 22:17               ` [PATCH] [crypto] XTS: use proper alignment v2 Sebastian Siewior
2008-03-05 22:48                 ` Stefan Hellermann
2008-03-06  8:52                   ` Sebastian Siewior
2008-03-06 10:53                     ` Stefan Hellermann
2008-03-06 10:57                   ` Herbert Xu

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=47CAB33E.2050207@the2masters.de \
    --to=stefan@the2masters.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=sebastian@breakpoint.cc \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.