linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Siewior <sebastian@breakpoint.cc>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: linux-crypto@vger.kernel.org, Stefan Hellermann <stefan@the2masters.de>
Subject: [PATCH] [crypto] XTS: use proper alignment.
Date: Sun, 2 Mar 2008 11:09:10 +0000	[thread overview]
Message-ID: <958c4032ba3b28931dea586d0338bf1ec1594659.1204465942.git.sebastian@breakpoint.cc> (raw)
In-Reply-To: <20080302135135.GC16659@Chamillionaire.breakpoint.cc>

The XTS 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.

Tested-by: Stefan Hellermann <stefan@the2masters.de>
Signed-off-by: Sebastian Siewior <sebastian@breakpoint.cc>
---
 crypto/xts.c |   32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/crypto/xts.c b/crypto/xts.c
index 8eb08bf..4457022 100644
--- a/crypto/xts.c
+++ b/crypto/xts.c
@@ -24,7 +24,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;
 	struct crypto_cipher *tweak;
 };
@@ -76,12 +86,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 xts_round(struct sinfo *s, void *dst, const void *src)
 {
 	be128_xor(dst, &s->t, src);		/* PP <- T xor P */
@@ -97,13 +101,12 @@ 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
-	};
-	be128 *iv;
 	u8 *wsrc;
 	u8 *wdst;
+	struct sinfo *s = &ctx->s;
+
+	s->tfm = crypto_cipher_tfm(ctx->child);
+	s->fn = fn;
 
 	err = blkcipher_walk_virt(d, w);
 	if (!w->nbytes)
@@ -115,17 +118,16 @@ static int crypt(struct blkcipher_desc *d,
 	wdst = w->dst.virt.addr;
 
 	/* calculate first value of T */
-	iv = (be128 *)w->iv;
-	tw(crypto_cipher_tfm(ctx->tweak), (void *)&s.t, w->iv);
+	tw(crypto_cipher_tfm(ctx->tweak), (void *)&s->t, w->iv);
 
 	goto first;
 
 	for (;;) {
 		do {
-			gf128mul_x_ble(&s.t, &s.t);
+			gf128mul_x_ble(&s->t, &s->t);
 
 first:
-			xts_round(&s, wdst, wsrc);
+			xts_round(s, wdst, wsrc);
 
 			wsrc += bs;
 			wdst += bs;
-- 
1.5.3.4


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

Thread overview: 22+ 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 ` Sebastian Siewior [this message]
2008-03-02 13:35   ` [PATCH] [PATCH] [crypto] LRW: use proper alignment Sebastian Siewior
2008-03-02 14:01     ` Stefan Hellermann
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
  -- strict thread matches above, loose matches on Subject: below --
2008-02-24 11:01 [RFC] padlock aes, unification of setkey() Sebastian Siewior
2008-02-24 11:54 ` Stefan Hellermann
2008-02-24 12:51   ` Sebastian Siewior
2008-02-24 20:07     ` Via Padlock Bug with LRW/XTS Stefan Hellermann
2008-03-02 11:20       ` [PATCH] [crypto] XTS: use proper alignment Sebastian Siewior
2008-03-02 12:04         ` Stefan Hellermann
2008-03-02 13:22           ` Sebastian Siewior
2008-03-02 13:49             ` Stefan Hellermann
2008-03-02 14:04               ` Stefan Hellermann

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=958c4032ba3b28931dea586d0338bf1ec1594659.1204465942.git.sebastian@breakpoint.cc \
    --to=sebastian@breakpoint.cc \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=stefan@the2masters.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).