All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harvey Harrison <harvey.harrison@gmail.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Johannes Berg <johannes@sipsolutions.net>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] crypto: make michael_block a function
Date: Thu, 15 May 2008 23:17:17 -0700	[thread overview]
Message-ID: <1210918637.5915.24.camel@brick> (raw)

Make the michael_block macro a function and change the calling
function to take a struct michael_mic_ctx * and the value for
the initial xor with ctx->l.

Also open-code xswap in its one use in michael_block.

Some use of get_unaligned is probably needed as an add-on.

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
 crypto/michael_mic.c |   55 +++++++++++++++++++++----------------------------
 1 files changed, 24 insertions(+), 31 deletions(-)

diff --git a/crypto/michael_mic.c b/crypto/michael_mic.c
index 9e917b8..792dbf9 100644
--- a/crypto/michael_mic.c
+++ b/crypto/michael_mic.c
@@ -31,19 +31,18 @@ static inline u32 xswap(u32 val)
 	return ((val & 0x00ff00ff) << 8) | ((val & 0xff00ff00) >> 8);
 }
 
-
-#define michael_block(l, r)	\
-do {				\
-	r ^= rol32(l, 17);	\
-	l += r;			\
-	r ^= xswap(l);		\
-	l += r;			\
-	r ^= rol32(l, 3);	\
-	l += r;			\
-	r ^= ror32(l, 2);	\
-	l += r;			\
-} while (0)
-
+static void michael_block(struct michael_mic_ctx *ctx, u32 val)
+{
+	ctx->l ^= val;
+	ctx->r ^= rol32(ctx->l, 17);
+	ctx->l += ctx->r;
+	ctx->r ^= ((ctx->l & 0x00ff00ff) << 8) | ((ctx->l & 0xff00ff00) >> 8);
+	ctx->l += ctx->r;
+	ctx->r ^= rol32(ctx->l, 3);
+	ctx->l += ctx->r;
+	ctx->r ^= ror32(ctx->l, 2);
+	ctx->l += ctx->r;
+}
 
 static void michael_init(struct crypto_tfm *tfm)
 {
@@ -71,16 +70,14 @@ static void michael_update(struct crypto_tfm *tfm, const u8 *data,
 			return;
 
 		src = (const __le32 *)mctx->pending;
-		mctx->l ^= le32_to_cpup(src);
-		michael_block(mctx->l, mctx->r);
+		michael_block(mctx, le32_to_cpup(src));
 		mctx->pending_len = 0;
 	}
 
 	src = (const __le32 *)data;
 
 	while (len >= 4) {
-		mctx->l ^= le32_to_cpup(src++);
-		michael_block(mctx->l, mctx->r);
+		michael_block(mctx, le32_to_cpup(src++));
 		len -= 4;
 	}
 
@@ -96,26 +93,22 @@ static void michael_final(struct crypto_tfm *tfm, u8 *out)
 	struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
 	u8 *data = mctx->pending;
 	__le32 *dst = (__le32 *)out;
+	u32 tmp;
 
 	/* Last block and padding (0x5a, 4..7 x 0) */
+	tmp = 0x5a;
 	switch (mctx->pending_len) {
-	case 0:
-		mctx->l ^= 0x5a;
-		break;
-	case 1:
-		mctx->l ^= data[0] | 0x5a00;
-		break;
-	case 2:
-		mctx->l ^= data[0] | (data[1] << 8) | 0x5a0000;
-		break;
 	case 3:
-		mctx->l ^= data[0] | (data[1] << 8) | (data[2] << 16) |
-			0x5a000000;
+		tmp = (tmp << 8) | data[2];
+	case 2:
+		tmp = (tmp << 8) | data[1];
+	case 1:
+		tmp = (tmp << 8) | data[0];
+	case 0:
 		break;
 	}
-	michael_block(mctx->l, mctx->r);
-	/* l ^= 0; */
-	michael_block(mctx->l, mctx->r);
+	michael_block(mctx, tmp);
+	michael_block(mctx, 0);
 
 	dst[0] = cpu_to_le32(mctx->l);
 	dst[1] = cpu_to_le32(mctx->r);
-- 
1.5.5.1.570.g26b5e




             reply	other threads:[~2008-05-16  6:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-16  6:17 Harvey Harrison [this message]
2008-05-16  7:01 ` [PATCH] crypto: make michael_block a function Sebastian Siewior
2008-05-16  8:10   ` Johannes Berg
2008-05-16 15:52     ` Harvey Harrison
2008-05-18 21:57       ` Sebastian Siewior

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=1210918637.5915.24.camel@brick \
    --to=harvey.harrison@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.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 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.