From patchwork Thu Mar 30 19:25:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?T25kcmVqIE1vc27DocSNZWs=?= X-Patchwork-Id: 9654945 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CCD0E60349 for ; Thu, 30 Mar 2017 19:25:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF452285C3 for ; Thu, 30 Mar 2017 19:25:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2C86285D2; Thu, 30 Mar 2017 19:25:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51F1C285C3 for ; Thu, 30 Mar 2017 19:25:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934420AbdC3TZw (ORCPT ); Thu, 30 Mar 2017 15:25:52 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:36437 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934067AbdC3TZw (ORCPT ); Thu, 30 Mar 2017 15:25:52 -0400 Received: by mail-wr0-f193.google.com with SMTP id k6so13536847wre.3 for ; Thu, 30 Mar 2017 12:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=P6vH3TjCynxBqKpP7Ov8FhumqOUsoCPEwXkG7N1+ra0=; b=q1S51Uq/aPUqba1Iz8VWZvC8aKLkwHnmA0961pogNFkTFTjXn86jOVdcQplIGX7jNB f2GXwek7lYXKCwml92L0ca3Doi36E53kKA4EKWUvT3HsboBZotXoqmlKkXiovrbXhtVH dGGqVAgzkRFzz60fsXUC/C9DB2wLOuAOP3ap/KK5Yj59tJGmGo6jwE0WC9lHKBApqBq7 jqfgmZnYqUBlcimN1VnE5DpCtRomVTHoj4eR94X6OZq1zayg8New9yeRtXzc0vpnbGva 4knUx0JAJjFd+mq9TD7tgkPx1hUP0H114ZARjxFPfyjDp3VuNwNiLv2RpeBDU659y3Zd tUhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=P6vH3TjCynxBqKpP7Ov8FhumqOUsoCPEwXkG7N1+ra0=; b=emh/UuMP0aBKv5z05mqzLCMm90x2m4HHWF5krtEl7vnjGYcFbYgkcslNHDg+Hij2PP Ncl36j22KsNJk5Ty3/PkqZFOAfNpWdva77p0X/iOQQU3M7UFMks9OZMA+5PSDSfg+PWr Zy5GiZKZb7EDCHyY8ZOonCtUfAgIu9L4VPMvSTwZtBGyQxH20eeKKDQbYbjTYFqMMR5g GeqEAvDh1h8cLWjrbdXp64LCYROHep2pEggpVV1J+o78++y5f/9U4Ea424GUiUV+JLYh niU0AGy1ERS7BzvZNqwQ7lQzPmj7linlo0Q/XRYW7o9Y7hvSr66YdBK7IYbJ/H77udRV DApg== X-Gm-Message-State: AFeK/H0Irq0AcF8FZOsI5If1GuYPjDWNiC8dH7E2qRUMpa/XmHtVbr5h0osTzNekj8ZpOw== X-Received: by 10.28.30.19 with SMTP id e19mr1896469wme.52.1490901950142; Thu, 30 Mar 2017 12:25:50 -0700 (PDT) Received: from localhost.localdomain (bband-dyn32.178-41-80.t-com.sk. [178.41.80.32]) by smtp.gmail.com with ESMTPSA id 75sm3091108wmp.2.2017.03.30.12.25.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 12:25:48 -0700 (PDT) From: Ondrej Mosnacek To: Herbert Xu Cc: "David S. Miller" , linux-crypto@vger.kernel.org, Milan Broz , Ondrej Mosnacek Subject: [PATCH] crypto: gf128mul - define gf128mul_x_ble in gf128mul.h Date: Thu, 30 Mar 2017 21:25:35 +0200 Message-Id: <20170330192535.23123-1-omosnacek@gmail.com> X-Mailer: git-send-email 2.9.3 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The gf128mul_x_ble function is currently defined in gf128mul.c, because it depends on the gf128mul_table_be multiplication table. However, since the function is very small and only uses two values from the table, it is better for it to be defined as inline function in gf128mul.h. That way, the function can be inlined by the compiler for better performance. After this change, the speed of the generic 'xts(aes)' implementation increased from ~225 MiB/s to ~235 MiB/s (measured using 'cryptsetup benchmark' on an Intel system with CRYPTO_AES_X86_64 and CRYPTO_AES_NI_INTEL disabled). Signed-off-by: Ondrej Mosnacek --- crypto/gf128mul.c | 11 ----------- include/crypto/gf128mul.h | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crypto/gf128mul.c b/crypto/gf128mul.c index 04facc0..2eab1a1 100644 --- a/crypto/gf128mul.c +++ b/crypto/gf128mul.c @@ -156,17 +156,6 @@ static void gf128mul_x_bbe(be128 *r, const be128 *x) r->b = cpu_to_be64((b << 1) ^ _tt); } -void gf128mul_x_ble(be128 *r, const be128 *x) -{ - u64 a = le64_to_cpu(x->a); - u64 b = le64_to_cpu(x->b); - u64 _tt = gf128mul_table_be[b >> 63]; - - r->a = cpu_to_le64((a << 1) ^ _tt); - r->b = cpu_to_le64((b << 1) | (a >> 63)); -} -EXPORT_SYMBOL(gf128mul_x_ble); - static void gf128mul_x8_lle(be128 *x) { u64 a = be64_to_cpu(x->a); diff --git a/include/crypto/gf128mul.h b/include/crypto/gf128mul.h index 0bc9b5f..46a01a2 100644 --- a/include/crypto/gf128mul.h +++ b/include/crypto/gf128mul.h @@ -49,6 +49,7 @@ #ifndef _CRYPTO_GF128MUL_H #define _CRYPTO_GF128MUL_H +#include #include #include @@ -163,8 +164,18 @@ void gf128mul_lle(be128 *a, const be128 *b); void gf128mul_bbe(be128 *a, const be128 *b); -/* multiply by x in ble format, needed by XTS */ -void gf128mul_x_ble(be128 *a, const be128 *b); +/* Multiply by x in ble format, needed by XTS. + * Defined here for performance. */ +static inline void gf128mul_x_ble(be128 *r, const be128 *x) +{ + u64 a = le64_to_cpu(x->a); + u64 b = le64_to_cpu(x->b); + /* equivalent to gf128mul_table_be[b >> 63] (see crypto/gf128mul.c): */ + u64 _tt = (b & ((u64)1 << 63)) ? 0x87 : 0x00; + + r->a = cpu_to_le64((a << 1) ^ _tt); + r->b = cpu_to_le64((b << 1) | (a >> 63)); +} /* 4k table optimization */