diff mbox

[2/3] libcrc32c: Expose big-endian version of crc32c

Message ID 20110927221253.21653.28062.stgit@elm3c44.beaverton.ibm.com
State Not Applicable, archived
Headers show

Commit Message

Darrick J. Wong Sept. 27, 2011, 10:12 p.m. UTC
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(-)



--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Herbert Xu Sept. 28, 2011, 3:53 a.m. UTC | #1
On Tue, Sep 27, 2011 at 03:12:53PM -0700, Darrick J. Wong wrote:
> Provide a big-endian version of crc32c for modules that want it.

Who is going to use this?

Thanks,
Darrick J. Wong Sept. 28, 2011, 4:51 p.m. UTC | #2
On Wed, Sep 28, 2011 at 01:53:59PM +1000, Herbert Xu wrote:
> On Tue, Sep 27, 2011 at 03:12:53PM -0700, Darrick J. Wong wrote:
> > Provide a big-endian version of crc32c for modules that want it.
> 
> Who is going to use this?

Well, I was using it for jbd2 ... but since you ask, it seems to work just as
well with crc32c-le, so I think I'll just drop the -be version.

--D
> 
> Thanks,
> -- 
> Email: Herbert Xu <herbert@gondor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Darrick J. Wong Sept. 29, 2011, 12:02 a.m. UTC | #3
On Wed, Sep 28, 2011 at 09:51:45AM -0700, Darrick J. Wong wrote:
> On Wed, Sep 28, 2011 at 01:53:59PM +1000, Herbert Xu wrote:
> > On Tue, Sep 27, 2011 at 03:12:53PM -0700, Darrick J. Wong wrote:
> > > Provide a big-endian version of crc32c for modules that want it.
> > 
> > Who is going to use this?
> 
> Well, I was using it for jbd2 ... but since you ask, it seems to work just as
> well with crc32c-le, so I think I'll just drop the -be version.

Drat, it's also missing the gen_crc32ctable program.  Sorry for the noise; I'll
resend it.  With the -be parts stripped out I can remove all but the first
patch, which cuts down the code changes considerably.

--D
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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);