From patchwork Thu Sep 1 00:33:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 112739 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 1FA09B6F7F for ; Thu, 1 Sep 2011 10:34:09 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757337Ab1IAAdg (ORCPT ); Wed, 31 Aug 2011 20:33:36 -0400 Received: from e5.ny.us.ibm.com ([32.97.182.145]:58594 "EHLO e5.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757330Ab1IAAde (ORCPT ); Wed, 31 Aug 2011 20:33:34 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e5.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p8103LMw030129; Wed, 31 Aug 2011 20:03:21 -0400 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p810XW58273692; Wed, 31 Aug 2011 20:33:33 -0400 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p810XVEB030816; Wed, 31 Aug 2011 18:33:32 -0600 Received: from elm3c44.beaverton.ibm.com ([9.47.69.44]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p810XUZp030795; Wed, 31 Aug 2011 18:33:30 -0600 Subject: [PATCH 2/3] libcrc32c: Expose big-endian version of crc32c To: Andreas Dilger , Herbert Xu , Theodore Tso , David Miller , "Darrick J. Wong" From: "Darrick J. Wong" Cc: Bob Pearson , linux-kernel , Mingming Cao , linux-crypto , linux-fsdevel , linux-ext4@vger.kernel.org Date: Wed, 31 Aug 2011 17:33:30 -0700 Message-ID: <20110901003330.32645.32586.stgit@elm3c44.beaverton.ibm.com> In-Reply-To: <20110901003317.32645.16843.stgit@elm3c44.beaverton.ibm.com> References: <20110901003317.32645.16843.stgit@elm3c44.beaverton.ibm.com> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Provide a big-endian version of crc32c for modules that want it. Signed-off-by: Darrick J. Wong --- 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 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 -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 #include -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);