lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1299745272-25477-3-git-send-email-nab@linux-iscsi.org>
Date:	Thu, 10 Mar 2011 00:21:12 -0800
From:	"Nicholas A. Bellinger" <nab@...ux-iscsi.org>
To:	linux-kernel <linux-kernel@...r.kernel.org>,
	linux-crypto <linux-crypto@...r.kernel.org>,
	Herbert Xu <herbert@...dor.apana.org.au>
Cc:	James Bottomley <James.Bottomley@...e.de>,
	Christoph Hellwig <hch@....de>,
	Randy Dunlap <rdunlap@...otime.net>,
	linux-scsi <linux-scsi@...r.kernel.org>,
	Nicholas Bellinger <nab@...ux-iscsi.org>,
	Herbert Xu <herbert@...dor.apana.org.au>
Subject: [PATCH 2/2] crypto/crc32c: Add crc32c_cra_check_optimized for crc32c_intel

From: Nicholas Bellinger <nab@...ux-iscsi.org>

This patch adds crc32c_cra_check_optimized() for use by the new
struct crypto_alg->cra_check_optimized() API caller in order to
call request_module() to load crc32c_intel.ko for CRC32C instruction
offload when available on CONFIG_X86 w/ SSE v4.2 compatiable hardware.

Signed-off-by: Nicholas A. Bellinger <nab@...ux-iscsi.org>
Cc: Herbert Xu <herbert@...dor.apana.org.au>
---
 crypto/crc32c.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/crypto/crc32c.c b/crypto/crc32c.c
index de9e55c..3f1d3a3 100644
--- a/crypto/crc32c.c
+++ b/crypto/crc32c.c
@@ -44,6 +44,8 @@
 #define CHKSUM_BLOCK_SIZE	1
 #define CHKSUM_DIGEST_SIZE	4
 
+static int crc32c_offload_enabled;
+
 struct chksum_ctx {
 	u32 key;
 };
@@ -221,6 +223,24 @@ static int crc32c_cra_init(struct crypto_tfm *tfm)
 	return 0;
 }
 
+static void crc32c_cra_check_optimized(struct crypto_alg *alg)
+{
+	if (crc32c_offload_enabled)
+		return;
+#ifdef CONFIG_X86
+	/*
+	 * For cpu_has_xmm4_2 go ahead and load crc32c_intel.ko in order so
+	 * crypto_alloc_hash("crc32c", ...) will automatically use SSE v4.2
+	 * CRC32C instruction offload.
+	 */
+	if (cpu_has_xmm4_2) {
+		int rc = request_module("crc32c_intel");
+		if (rc == 0)
+			crc32c_offload_enabled = 1;
+	}
+#endif
+}
+
 static struct shash_alg alg = {
 	.digestsize		=	CHKSUM_DIGEST_SIZE,
 	.setkey			=	chksum_setkey,
@@ -239,11 +259,14 @@ static struct shash_alg alg = {
 		.cra_ctxsize		=	sizeof(struct chksum_ctx),
 		.cra_module		=	THIS_MODULE,
 		.cra_init		=	crc32c_cra_init,
+		.cra_check_optimized	=	crc32c_cra_check_optimized,
 	}
 };
 
 static int __init crc32c_mod_init(void)
 {
+	crc32c_offload_enabled = 0;
+
 	return crypto_register_shash(&alg);
 }
 
-- 
1.5.6.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ