From patchwork Fri May 1 06:23:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6308541 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 12DE09F32E for ; Fri, 1 May 2015 06:24:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1C027203AB for ; Fri, 1 May 2015 06:24:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F082203A9 for ; Fri, 1 May 2015 06:24:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753254AbbEAGYW (ORCPT ); Fri, 1 May 2015 02:24:22 -0400 Received: from mail-pd0-f181.google.com ([209.85.192.181]:33646 "EHLO mail-pd0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750904AbbEAGYV (ORCPT ); Fri, 1 May 2015 02:24:21 -0400 Received: by pdbnk13 with SMTP id nk13so83982510pdb.0; Thu, 30 Apr 2015 23:24:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sxmlWOuUNxofx85EmD0OzcDfs1F1TZsQISPXHruhUmI=; b=nQ3FuiV0doCnSxdnS1a7BYZ3UnD5DEJZ66Rv5mbdineJ/4M6/TYk3VaJWB3OJfnstS Jzb7uDadp/jKAXsO7lUdA/eadQ9qSdjt+EfaAEIRWNea0+8siV+C2i+xTN4Ybq6kI0TS J1Qg5/BwDzcEMHLp6NriDzojudhT83o7JpXZAPq3ctblGOFbYgMJpDvfZ8RoVz1C1o0q 4ZLQR90UEfOJsuu27unZ98EjF+t03aF6M/LC67vw8eJm3Dsu+rCvQ0MOTznHdLR0jpJa ftNnSwZgFVb2uTHYrOHd75XP+wnU/bSvWc2lKb1n7KWIktc4L43/rv4B6esdcQE2s2m0 w4Tw== X-Received: by 10.68.65.66 with SMTP id v2mr15208024pbs.10.1430461460928; Thu, 30 Apr 2015 23:24:20 -0700 (PDT) Received: from localhost.localdomain (KD106168100169.ppp-bb.dion.ne.jp. [106.168.100.169]) by mx.google.com with ESMTPSA id bz11sm3889311pdb.34.2015.04.30.23.24.16 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Apr 2015 23:24:19 -0700 (PDT) From: Akinobu Mita To: target-devel@vger.kernel.org Cc: Akinobu Mita , Tim Chen , Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org, Nicholas Bellinger , Sagi Grimberg , "Martin K. Petersen" , Christoph Hellwig , "James E.J. Bottomley" Subject: [PATCH v4 3/4] lib: introduce crc_t10dif_update() Date: Fri, 1 May 2015 15:23:50 +0900 Message-Id: <1430461431-5936-4-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1430461431-5936-1-git-send-email-akinobu.mita@gmail.com> References: <1430461431-5936-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This introduces crc_t10dif_update() which enables to calculate CRC for a block which straddles multiple SG elements by calling multiple times. This also converts crc_t10dif() to use crc_t10dif_update() as they are almost same. Signed-off-by: Akinobu Mita Acked-by: Martin K. Petersen Cc: Tim Chen Cc: Herbert Xu Cc: "David S. Miller" Cc: linux-crypto@vger.kernel.org Cc: Nicholas Bellinger Cc: Sagi Grimberg Cc: "Martin K. Petersen" Cc: Christoph Hellwig Cc: "James E.J. Bottomley" Cc: target-devel@vger.kernel.org --- * Changes from v3: - Reduce duplicated code between crc_t10dif_update and crc_t10dif, suggested by Tim and Herbert include/linux/crc-t10dif.h | 1 + lib/crc-t10dif.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/linux/crc-t10dif.h b/include/linux/crc-t10dif.h index cf53d07..d81961e 100644 --- a/include/linux/crc-t10dif.h +++ b/include/linux/crc-t10dif.h @@ -9,5 +9,6 @@ extern __u16 crc_t10dif_generic(__u16 crc, const unsigned char *buffer, size_t len); extern __u16 crc_t10dif(unsigned char const *, size_t); +extern __u16 crc_t10dif_update(__u16 crc, unsigned char const *, size_t); #endif diff --git a/lib/crc-t10dif.c b/lib/crc-t10dif.c index dfe6ec1..d775737 100644 --- a/lib/crc-t10dif.c +++ b/lib/crc-t10dif.c @@ -19,7 +19,7 @@ static struct crypto_shash *crct10dif_tfm; static struct static_key crct10dif_fallback __read_mostly; -__u16 crc_t10dif(const unsigned char *buffer, size_t len) +__u16 crc_t10dif_update(__u16 crc, const unsigned char *buffer, size_t len) { struct { struct shash_desc shash; @@ -28,17 +28,24 @@ __u16 crc_t10dif(const unsigned char *buffer, size_t len) int err; if (static_key_false(&crct10dif_fallback)) - return crc_t10dif_generic(0, buffer, len); + return crc_t10dif_generic(crc, buffer, len); desc.shash.tfm = crct10dif_tfm; desc.shash.flags = 0; - *(__u16 *)desc.ctx = 0; + err = crypto_shash_import(&desc.shash, &crc); + BUG_ON(err); err = crypto_shash_update(&desc.shash, buffer, len); BUG_ON(err); return *(__u16 *)desc.ctx; } +EXPORT_SYMBOL(crc_t10dif_update); + +__u16 crc_t10dif(const unsigned char *buffer, size_t len) +{ + return crc_t10dif_update(0, buffer, len); +} EXPORT_SYMBOL(crc_t10dif); static int __init crc_t10dif_mod_init(void)