From patchwork Sat Apr 25 14:33:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6274661 Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4812BBF4A6 for ; Sat, 25 Apr 2015 14:34:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 57B102022A for ; Sat, 25 Apr 2015 14:34:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 54A9F201CD for ; Sat, 25 Apr 2015 14:34:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759498AbbDYOd7 (ORCPT ); Sat, 25 Apr 2015 10:33:59 -0400 Received: from mail-pd0-f181.google.com ([209.85.192.181]:34984 "EHLO mail-pd0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754794AbbDYOd7 (ORCPT ); Sat, 25 Apr 2015 10:33:59 -0400 Received: by pdbqd1 with SMTP id qd1so77762757pdb.2; Sat, 25 Apr 2015 07:33:58 -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=5BcX3thdDpCRlUuu/SYejQXU/DZd1Dsz7FgMsiKsz/w=; b=Ig2bF3sXN3anz4XfebF6eGO2L/m3UZaHfrMrNGEbAuWTXVHDD1LwCJkKPN7/XFGSfg nwBUmbSopFOiMLwKI45Vyw3MEh5DX+367iVFMVTeEoYDo230/V/ROmi6La9JiPVdTwHm 9CopmJIpuaxchQdhfon2YIS1aHrgevljZ4ISgjcFKiKt7ChlZQmQQlN/4C3yLnyXOz9Z 1+YD1Ekg36kRTElw+lef2bCdTQRZ2GCng+3xnUonlnsPmLhLfs2frZh9nLqEE97kxT+4 b/Dp+bGgWAXmodjiJ/F3Rkv6ANfRBGa8Defis9xETrP2GoWxLVecJTDZh8LY70danf6b bTTQ== X-Received: by 10.68.112.195 with SMTP id is3mr6685673pbb.92.1429972438578; Sat, 25 Apr 2015 07:33:58 -0700 (PDT) Received: from localhost.localdomain (KD106168100169.ppp-bb.dion.ne.jp. [106.168.100.169]) by mx.google.com with ESMTPSA id ts4sm14156224pbc.41.2015.04.25.07.33.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Apr 2015 07:33:57 -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 v3 2/5] lib: introduce crc_t10dif_update() Date: Sat, 25 Apr 2015 23:33:27 +0900 Message-Id: <1429972410-7146-3-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429972410-7146-1-git-send-email-akinobu.mita@gmail.com> References: <1429972410-7146-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. Signed-off-by: Akinobu Mita 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 Acked-by: Martin K. Petersen --- * New patch from v3 include/linux/crc-t10dif.h | 1 + lib/crc-t10dif.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) 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..7cdbe2e 100644 --- a/lib/crc-t10dif.c +++ b/lib/crc-t10dif.c @@ -19,6 +19,29 @@ static struct crypto_shash *crct10dif_tfm; static struct static_key crct10dif_fallback __read_mostly; +__u16 crc_t10dif_update(__u16 crc, const unsigned char *buffer, size_t len) +{ + struct { + struct shash_desc shash; + char ctx[2]; + } desc; + int err; + + if (static_key_false(&crct10dif_fallback)) + return crc_t10dif_generic(crc, buffer, len); + + desc.shash.tfm = crct10dif_tfm; + desc.shash.flags = 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) { struct {