linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@us.ibm.com>
To: Andreas Dilger <adilger.kernel@dilger.ca>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Theodore Tso <tytso@mit.edu>, David Miller <davem@davemloft.net>,
	"Darrick J. Wong" <djwong@us.ibm.com>
Cc: Bob Pearson <rpearson@systemfabricworks.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Mingming Cao <cmm@us.ibm.com>,
	linux-crypto <linux-crypto@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	linux-ext4@vger.kernel.org
Subject: [PATCH 2/3] libcrc32c: Expose big-endian version of crc32c
Date: Wed, 31 Aug 2011 17:33:30 -0700	[thread overview]
Message-ID: <20110901003330.32645.32586.stgit@elm3c44.beaverton.ibm.com> (raw)
In-Reply-To: <20110901003317.32645.16843.stgit@elm3c44.beaverton.ibm.com>

Provide a big-endian version of crc32c for modules that want it.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
---
 include/linux/crc32c.h |    5 +++--
 lib/libcrc32c.c        |   43 ++++++++++++++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 11 deletions(-)


diff --git a/include/linux/crc32c.h b/include/linux/crc32c.h
index bd8b44d..33320e1 100644
--- a/include/linux/crc32c.h
+++ b/include/linux/crc32c.h
@@ -3,9 +3,10 @@
 
 #include <linux/types.h>
 
-extern u32 crc32c(u32 crc, const void *address, unsigned int length);
+extern u32 crc32c_le(u32 crc, const void *address, unsigned int length);
+extern u32 crc32c_be(u32 crc, const void *address, unsigned int length);
 
 /* This macro exists for backwards-compatibility. */
-#define crc32c_le crc32c
+#define crc32c crc32c_le
 
 #endif	/* _LINUX_CRC32C_H */
diff --git a/lib/libcrc32c.c b/lib/libcrc32c.c
index 244f548..e421ff5 100644
--- a/lib/libcrc32c.c
+++ b/lib/libcrc32c.c
@@ -37,17 +37,17 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 
-static struct crypto_shash *tfm;
+static struct crypto_shash *tfm_le, *tfm_be;
 
-u32 crc32c(u32 crc, const void *address, unsigned int length)
+u32 crc32c_le(u32 crc, const void *address, unsigned int length)
 {
 	struct {
 		struct shash_desc shash;
-		char ctx[crypto_shash_descsize(tfm)];
+		char ctx[crypto_shash_descsize(tfm_le)];
 	} desc;
 	int err;
 
-	desc.shash.tfm = tfm;
+	desc.shash.tfm = tfm_le;
 	desc.shash.flags = 0;
 	*(u32 *)desc.ctx = crc;
 
@@ -56,21 +56,46 @@ u32 crc32c(u32 crc, const void *address, unsigned int length)
 
 	return *(u32 *)desc.ctx;
 }
+EXPORT_SYMBOL(crc32c_le);
 
-EXPORT_SYMBOL(crc32c);
+u32 crc32c_be(u32 crc, const void *address, unsigned int length)
+{
+	struct {
+		struct shash_desc shash;
+		char ctx[crypto_shash_descsize(tfm_be)];
+	} desc;
+	int err;
+
+	desc.shash.tfm = tfm_be;
+	desc.shash.flags = 0;
+	*(u32 *)desc.ctx = crc;
+
+	err = crypto_shash_update(&desc.shash, address, length);
+	BUG_ON(err);
+
+	return *(u32 *)desc.ctx;
+}
+EXPORT_SYMBOL(crc32c_be);
 
 static int __init libcrc32c_mod_init(void)
 {
-	tfm = crypto_alloc_shash("crc32c", 0, 0);
-	if (IS_ERR(tfm))
-		return PTR_ERR(tfm);
+	tfm_le = crypto_alloc_shash("crc32c", 0, 0);
+	if (IS_ERR(tfm_le))
+		return PTR_ERR(tfm_le);
+
+	tfm_be = crypto_alloc_shash("crc32c-be", 0, 0);
+	if (IS_ERR(tfm_be)) {
+		crypto_free_shash(tfm_le);
+		return PTR_ERR(tfm_be);
+	}
 
 	return 0;
 }
 
 static void __exit libcrc32c_mod_fini(void)
 {
-	crypto_free_shash(tfm);
+	crypto_free_shash(tfm_be);
+	crypto_free_shash(tfm_le);
 }
 
 module_init(libcrc32c_mod_init);

  parent reply	other threads:[~2011-09-01  0:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-01  0:33 [PATCH v1 0/3] crc32c: Add faster algorithm and self-test code Darrick J. Wong
2011-09-01  0:33 ` [PATCH 1/3] crc32c: Implement CRC32c with slicing-by-8 algorithm Darrick J. Wong
2011-09-01  0:33 ` Darrick J. Wong [this message]
2011-09-01  0:33 ` [PATCH 3/3] crc32c: Implement a self-test for CRC32c Darrick J. Wong
2011-09-01  1:07   ` Herbert Xu
2011-09-01  1:20     ` Bob Pearson
2011-09-01  1:51       ` Herbert Xu
2011-09-01  5:40   ` Bob Pearson
2011-09-01  6:41     ` Herbert Xu
2011-09-01 22:18     ` Darrick J. Wong
2011-09-01 22:24       ` Christoph Hellwig
2011-09-01 22:28         ` Darrick J. Wong
  -- strict thread matches above, loose matches on Subject: below --
2011-09-27 22:12 [PATCH v2 0/3] crc32c: Add faster algorithm and self-test code Darrick J. Wong
2011-09-27 22:12 ` [PATCH 2/3] libcrc32c: Expose big-endian version of crc32c Darrick J. Wong
2011-09-28  3:53   ` Herbert Xu
2011-09-28 16:51     ` Darrick J. Wong
2011-09-29  0:02       ` Darrick J. Wong

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=20110901003330.32645.32586.stgit@elm3c44.beaverton.ibm.com \
    --to=djwong@us.ibm.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=cmm@us.ibm.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rpearson@systemfabricworks.com \
    --cc=tytso@mit.edu \
    /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).