linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian-Ken Rueegsegger <ken@codelabs.ch>
To: herbert@gondor.apana.org.au
Cc: linux-crypto@vger.kernel.org, steffen.klassert@secunet.com,
	Adrian-Ken Rueegsegger <ken@codelabs.ch>
Subject: [PATCH 4/4 v2] crypto: michael_mic - Switch to shash
Date: Thu,  4 Dec 2008 10:32:10 +0100	[thread overview]
Message-ID: <12283831332300-git-send-email-ken@codelabs.ch> (raw)
In-Reply-To: <122838313275-git-send-email-ken@codelabs.ch>

This patch changes michael_mic to the new shash interface.

Signed-off-by: Adrian-Ken Rueegsegger <ken@codelabs.ch>
---
 crypto/Kconfig       |    2 +-
 crypto/michael_mic.c |   72 ++++++++++++++++++++++++++++---------------------
 2 files changed, 42 insertions(+), 32 deletions(-)

diff --git a/crypto/Kconfig b/crypto/Kconfig
index e2b903d..9003f11 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -259,7 +259,7 @@ config CRYPTO_MD5
 
 config CRYPTO_MICHAEL_MIC
 	tristate "Michael MIC keyed digest algorithm"
-	select CRYPTO_ALGAPI
+	select CRYPTO_HASH
 	help
 	  Michael MIC is used for message integrity protection in TKIP
 	  (IEEE 802.11i). This algorithm is required for TKIP, but it
diff --git a/crypto/michael_mic.c b/crypto/michael_mic.c
index 9e917b8..079b761 100644
--- a/crypto/michael_mic.c
+++ b/crypto/michael_mic.c
@@ -9,23 +9,25 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
-
+#include <crypto/internal/hash.h>
 #include <asm/byteorder.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/string.h>
-#include <linux/crypto.h>
 #include <linux/types.h>
 
 
 struct michael_mic_ctx {
+	u32 l, r;
+};
+
+struct michael_mic_desc_ctx {
 	u8 pending[4];
 	size_t pending_len;
 
 	u32 l, r;
 };
 
-
 static inline u32 xswap(u32 val)
 {
 	return ((val & 0x00ff00ff) << 8) | ((val & 0xff00ff00) >> 8);
@@ -45,17 +47,22 @@ do {				\
 } while (0)
 
 
-static void michael_init(struct crypto_tfm *tfm)
+static int michael_init(struct shash_desc *desc)
 {
-	struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
+	struct michael_mic_desc_ctx *mctx = shash_desc_ctx(desc);
+	struct michael_mic_ctx *ctx = crypto_shash_ctx(desc->tfm);
 	mctx->pending_len = 0;
+	mctx->l = ctx->l;
+	mctx->r = ctx->r;
+
+	return 0;
 }
 
 
-static void michael_update(struct crypto_tfm *tfm, const u8 *data,
+static int michael_update(struct shash_desc *desc, const u8 *data,
 			   unsigned int len)
 {
-	struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
+	struct michael_mic_desc_ctx *mctx = shash_desc_ctx(desc);
 	const __le32 *src;
 
 	if (mctx->pending_len) {
@@ -68,7 +75,7 @@ static void michael_update(struct crypto_tfm *tfm, const u8 *data,
 		len -= flen;
 
 		if (mctx->pending_len < 4)
-			return;
+			return 0;
 
 		src = (const __le32 *)mctx->pending;
 		mctx->l ^= le32_to_cpup(src);
@@ -88,12 +95,14 @@ static void michael_update(struct crypto_tfm *tfm, const u8 *data,
 		mctx->pending_len = len;
 		memcpy(mctx->pending, src, len);
 	}
+
+	return 0;
 }
 
 
-static void michael_final(struct crypto_tfm *tfm, u8 *out)
+static int michael_final(struct shash_desc *desc, u8 *out)
 {
-	struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
+	struct michael_mic_desc_ctx *mctx = shash_desc_ctx(desc);
 	u8 *data = mctx->pending;
 	__le32 *dst = (__le32 *)out;
 
@@ -119,17 +128,20 @@ static void michael_final(struct crypto_tfm *tfm, u8 *out)
 
 	dst[0] = cpu_to_le32(mctx->l);
 	dst[1] = cpu_to_le32(mctx->r);
+
+	return 0;
 }
 
 
-static int michael_setkey(struct crypto_tfm *tfm, const u8 *key,
+static int michael_setkey(struct crypto_shash *tfm, const u8 *key,
 			  unsigned int keylen)
 {
-	struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
+	struct michael_mic_ctx *mctx = crypto_shash_ctx(tfm);
+
 	const __le32 *data = (const __le32 *)key;
 
 	if (keylen != 8) {
-		tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
+		crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
 		return -EINVAL;
 	}
 
@@ -138,33 +150,31 @@ static int michael_setkey(struct crypto_tfm *tfm, const u8 *key,
 	return 0;
 }
 
-
-static struct crypto_alg michael_mic_alg = {
-	.cra_name	= "michael_mic",
-	.cra_flags	= CRYPTO_ALG_TYPE_DIGEST,
-	.cra_blocksize	= 8,
-	.cra_ctxsize	= sizeof(struct michael_mic_ctx),
-	.cra_module	= THIS_MODULE,
-	.cra_alignmask	= 3,
-	.cra_list	= LIST_HEAD_INIT(michael_mic_alg.cra_list),
-	.cra_u		= { .digest = {
-	.dia_digestsize	= 8,
-	.dia_init	= michael_init,
-	.dia_update	= michael_update,
-	.dia_final	= michael_final,
-	.dia_setkey	= michael_setkey } }
+static struct shash_alg alg = {
+	.digestsize		=	8,
+	.setkey			=	michael_setkey,
+	.init			=	michael_init,
+	.update			=	michael_update,
+	.final			=	michael_final,
+	.descsize		=	sizeof(struct michael_mic_desc_ctx),
+	.base			=	{
+		.cra_name		=	"michael_mic",
+		.cra_blocksize		=	8,
+		.cra_alignmask		=	3,
+		.cra_ctxsize		=	sizeof(struct michael_mic_ctx),
+		.cra_module		=	THIS_MODULE,
+	}
 };
 

  reply	other threads:[~2008-12-04  9:32 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-04  9:32 [PATCH 0/4 v2] Switch remaining algorithms to shash Adrian-Ken Rueegsegger
2008-12-04  9:32 ` [PATCH 1/4 v2] crypto: sha512 - Remove W (message schedule) from struct sha512_ctx Adrian-Ken Rueegsegger
2008-12-04  9:32   ` [PATCH 2/4 v2] crypto: sha512 - Switch to shash Adrian-Ken Rueegsegger
2008-12-04  9:32     ` [PATCH 3/4 v2] crypto: wp512 " Adrian-Ken Rueegsegger
2008-12-04  9:32       ` Adrian-Ken Rueegsegger [this message]
2008-12-04 10:05   ` [PATCH 1/4 v2] crypto: sha512 - Remove W (message schedule) from struct sha512_ctx Herbert Xu
2008-12-04 10:51     ` Adrian-Ken Rueegsegger
2008-12-04 22:43     ` [PATCH 0/4 v3] Switch remaining algorithms to shash Adrian-Ken Rueegsegger
2008-12-04 22:43       ` [PATCH 1/4 v3] crypto: sha512 - Move message schedule W[80] to static percpu area Adrian-Ken Rueegsegger
2008-12-04 22:43         ` [PATCH 2/4 v3] crypto: sha512 - Switch to shash Adrian-Ken Rueegsegger
2008-12-04 22:43           ` [PATCH 3/4 v3] crypto: wp512 " Adrian-Ken Rueegsegger
2008-12-04 22:43             ` [PATCH 4/4 v3] crypto: michael_mic " Adrian-Ken Rueegsegger
2008-12-05  0:29           ` [PATCH 0/1] Resend correct sha512 shash patch Adrian-Ken Rueegsegger
2008-12-05  0:29             ` [PATCH] crypto: sha512 - Switch to shash Adrian-Ken Rueegsegger
2008-12-07 11:33         ` [PATCH 1/4 v3] crypto: sha512 - Move message schedule W[80] to static percpu area Herbert Xu
2008-12-07 22:17           ` [PATCH 0/2 v4] Switch remaining algorithms to shash Adrian-Ken Rueegsegger
2008-12-07 22:17             ` [PATCH 1/2 v4] crypto: sha512 - Move message schedule W[80] to static percpu area Adrian-Ken Rueegsegger
2008-12-07 22:17               ` [PATCH 2/2 v4] crypto: sha512 - Switch to shash Adrian-Ken Rueegsegger
2008-12-08  0:09               ` [PATCH 1/2 v4] crypto: sha512 - Move message schedule W[80] to static percpu area Evgeniy Polyakov
2008-12-08  0:24                 ` Herbert Xu
2008-12-08  0:33                   ` Evgeniy Polyakov
2008-12-17  5:49             ` [PATCH 0/2 v4] Switch remaining algorithms to shash Herbert Xu
2008-12-07 11:36       ` [PATCH 0/4 v3] " 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=12283831332300-git-send-email-ken@codelabs.ch \
    --to=ken@codelabs.ch \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    /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).