From patchwork Wed Mar 15 12:37:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 9625501 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 402F5604A9 for ; Wed, 15 Mar 2017 12:39:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3698F28617 for ; Wed, 15 Mar 2017 12:39:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 227142861A; Wed, 15 Mar 2017 12:39:52 +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, 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 A0DC528617 for ; Wed, 15 Mar 2017 12:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751198AbdCOMit (ORCPT ); Wed, 15 Mar 2017 08:38:49 -0400 Received: from mail-it0-f67.google.com ([209.85.214.67]:32866 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751168AbdCOMiL (ORCPT ); Wed, 15 Mar 2017 08:38:11 -0400 Received: by mail-it0-f67.google.com with SMTP id g138so2923706itb.0 for ; Wed, 15 Mar 2017 05:38:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Yeby6jXiz+KJumixfB/V75zODAAjJgrYHULLRiKMLRw=; b=fhslq0HkQhbCs4l8C/ggq7RbsY4CYLua8x2Ok5VsUBuQxRyafmHVv/DGC65Vj22PLu HAdSzVfPehF24xQT4Vee9ZJC5F9bFkY+ndg04san50E0tFqE+91EkmwFe88HhC1YnE6t RNYsGUqAPs5sS7Ds5sYGOg83HBFjGIXPhqXQ4= 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:in-reply-to :references; bh=Yeby6jXiz+KJumixfB/V75zODAAjJgrYHULLRiKMLRw=; b=SE5sfByU7wQpMPrPcpEd63N0UWqv3hpwZrjKsyUSOrvGqrQsOFeCe4OngBHkWWOvw+ s1MsCzhIRiyPjej360Ro6pQ3F+6JQuLS8Zdd8K92i08LVgkOlM0hutINahx3gV5sLlM6 vf8/JX5fF/tSYwW1RYn9cRn4PNYzG1WloEZ1/TQsJ/r4HZ4YqlGa51+36oA5XidEy8UU n0vhYCjgPhEisPOAVoy4V1yuVdQDdRwVic/llO8+hfhoX5uUCsIJYXVUSw+WY09QSPS2 i0kHYl41UcB0Wxq9fCq4n+ncrEIMkjH5JHkfylMapbBCIe2Kzjg0u1lYL0/7XbHL05cC aH9g== X-Gm-Message-State: AFeK/H3fApMxLMoGB88jdW2IVQGtMBgsDlA56QUyyCg+D32GlQPI2urEGnApC7Onb9k6sw== X-Received: by 10.36.70.145 with SMTP id j139mr22064341itb.111.1489581489486; Wed, 15 Mar 2017 05:38:09 -0700 (PDT) Received: from connectitude.ibm.com (ppp121-45-212-55.lns20.cbr1.internode.on.net. [121.45.212.55]) by smtp.gmail.com with ESMTPSA id l5sm103945ita.13.2017.03.15.05.38.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Mar 2017 05:38:09 -0700 (PDT) From: Daniel Axtens To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org Cc: anton@samba.org, Daniel Axtens Subject: [PATCH 2/4] crypto: powerpc - Re-enable non-REFLECTed CRCs Date: Wed, 15 Mar 2017 23:37:35 +1100 Message-Id: <20170315123737.20234-2-dja@axtens.net> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170315123737.20234-1-dja@axtens.net> References: <20170315123737.20234-1-dja@axtens.net> 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 When CRC32c was included in the kernel, Anton ripped out the #ifdefs around reflected polynomials, because CRC32c is always reflected. However, not all CRCs use reflection so we'd like to make it optional. Restore the REFLECT parts from Anton's original CRC32 implementation (https://github.com/antonblanchard/crc32-vpmsum) That implementation is available under GPLv2+, so we're OK from a licensing point of view: https://github.com/antonblanchard/crc32-vpmsum/blob/master/LICENSE.TXT As CRC32c requires REFLECT, add that #define. Cc: Anton Blanchard Signed-off-by: Daniel Axtens --- I compared the disassembly of the CRC32c module on LE before and after the change, and verified that they were the same. I verified that the crypto self-tests still pass on LE and BE, and my tests in patch 4 still pass as well. --- arch/powerpc/crypto/crc32-vpmsum_core.S | 31 ++++++++++++++++++++++++++++++- arch/powerpc/crypto/crc32c-vpmsum_asm.S | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/crypto/crc32-vpmsum_core.S b/arch/powerpc/crypto/crc32-vpmsum_core.S index 629244ef170e..87fabf4d391a 100644 --- a/arch/powerpc/crypto/crc32-vpmsum_core.S +++ b/arch/powerpc/crypto/crc32-vpmsum_core.S @@ -35,7 +35,9 @@ .text -#if defined(__BIG_ENDIAN__) +#if defined(__BIG_ENDIAN__) && defined(REFLECT) +#define BYTESWAP_DATA +#elif defined(__LITTLE_ENDIAN__) && !defined(REFLECT) #define BYTESWAP_DATA #else #undef BYTESWAP_DATA @@ -108,7 +110,11 @@ FUNC_START(CRC_FUNCTION_NAME) /* Get the initial value into v8 */ vxor v8,v8,v8 MTVRD(v8, R3) +#ifdef REFLECT vsldoi v8,zeroes,v8,8 /* shift into bottom 32 bits */ +#else + vsldoi v8,v8,zeroes,4 /* shift into top 32 bits */ +#endif #ifdef BYTESWAP_DATA addis r3,r2,.byteswap_constant@toc@ha @@ -354,6 +360,7 @@ FUNC_START(CRC_FUNCTION_NAME) vxor v6,v6,v14 vxor v7,v7,v15 +#ifdef REFLECT /* * vpmsumd produces a 96 bit result in the least significant bits * of the register. Since we are bit reflected we have to shift it @@ -368,6 +375,7 @@ FUNC_START(CRC_FUNCTION_NAME) vsldoi v5,v5,zeroes,4 vsldoi v6,v6,zeroes,4 vsldoi v7,v7,zeroes,4 +#endif /* xor with last 1024 bits */ lvx v8,0,r4 @@ -511,13 +519,33 @@ FUNC_START(CRC_FUNCTION_NAME) vsldoi v1,v0,v0,8 vxor v0,v0,v1 /* xor two 64 bit results together */ +#ifdef REFLECT /* shift left one bit */ vspltisb v1,1 vsl v0,v0,v1 +#endif vand v0,v0,mask_64bit +#ifndef REFLECT + /* + * Now for the Barrett reduction algorithm. The idea is to calculate q, + * the multiple of our polynomial that we need to subtract. By + * doing the computation 2x bits higher (ie 64 bits) and shifting the + * result back down 2x bits, we round down to the nearest multiple. + */ + VPMSUMD(v1,v0,const1) /* ma */ + vsldoi v1,zeroes,v1,8 /* q = floor(ma/(2^64)) */ + VPMSUMD(v1,v1,const2) /* qn */ + vxor v0,v0,v1 /* a - qn, subtraction is xor in GF(2) */ /* + * Get the result into r3. We need to shift it left 8 bytes: + * V0 [ 0 1 2 X ] + * V0 [ 0 X 2 3 ] + */ + vsldoi v0,v0,zeroes,8 /* shift result into top 64 bits */ +#else + /* * The reflected version of Barrett reduction. Instead of bit * reflecting our data (which is expensive to do), we bit reflect our * constants and our algorithm, which means the intermediate data in @@ -537,6 +565,7 @@ FUNC_START(CRC_FUNCTION_NAME) * V0 [ 0 X 2 3 ] */ vsldoi v0,v0,zeroes,4 /* shift result into top 64 bits of */ +#endif /* Get it into r3 */ MFVRD(R3, v0) diff --git a/arch/powerpc/crypto/crc32c-vpmsum_asm.S b/arch/powerpc/crypto/crc32c-vpmsum_asm.S index c0d080caefc1..d2bea48051a0 100644 --- a/arch/powerpc/crypto/crc32c-vpmsum_asm.S +++ b/arch/powerpc/crypto/crc32c-vpmsum_asm.S @@ -842,4 +842,5 @@ .octa 0x00000000000000000000000105ec76f1 #define CRC_FUNCTION_NAME __crc32c_vpmsum +#define REFLECT #include "crc32-vpmsum_core.S"