From patchwork Mon Jul 10 13:45:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9833037 X-Patchwork-Delegate: snitzer@redhat.com 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 0FD7860363 for ; Mon, 10 Jul 2017 13:46:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F15F226E97 for ; Mon, 10 Jul 2017 13:46:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E54E3274B4; Mon, 10 Jul 2017 13:46:21 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D488F27480 for ; Mon, 10 Jul 2017 13:46:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B50E180477; Mon, 10 Jul 2017 13:46:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B50E180477 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B50E180477 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (1024-bit key) header.d=linaro.org header.i=@linaro.org header.b="b7u1oA1U" Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F19B5C6A1; Mon, 10 Jul 2017 13:46:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2CAE31853E30; Mon, 10 Jul 2017 13:46:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6ADkHiq003749 for ; Mon, 10 Jul 2017 09:46:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D78F7EBED; Mon, 10 Jul 2017 13:46:17 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 768A67F80D for ; Mon, 10 Jul 2017 13:46:14 +0000 (UTC) Received: from mail-wr0-f180.google.com (mail-wr0-f180.google.com [209.85.128.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56115C0587FD for ; Mon, 10 Jul 2017 13:46:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 56115C0587FD Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ard.biesheuvel@linaro.org DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 56115C0587FD Received: by mail-wr0-f180.google.com with SMTP id c11so139622007wrc.3 for ; Mon, 10 Jul 2017 06:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zZZKsMVKkLr3FYgcnvfptyUIogCVp/jBa2OcQMjWFwg=; b=b7u1oA1U3HG6umAuz5ydDl6gO4RkszPjxB/XqFWDnUDTzQEh7ciLeNDHITsLW/uaz0 0ETzd5rS2NEGyCTG/n5fzgj/58ail9I3NZ9T2HaeEXCe9NtxPlIxLFbAU+raa2HFKvTA GGh6+47iIZ30y2O6xJrT6Q3Fy7iO2HBvaZauA= 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=zZZKsMVKkLr3FYgcnvfptyUIogCVp/jBa2OcQMjWFwg=; b=MK7Qj1XRWfkOlAlClryWfp9Hmy0TIZJB5mGOluEJYZ4eHcYP1dvIYR5i6NIaAypM4X Ey3rLKxUI9BjTiGa2SgHVB5MWkw1ORdu8NbtQHmtKq+5r9FLGU95pTUSxD3a0sPFcCBX /sJI/+qjtitVAYTuSCWQAMEFqo7hzGOdmV0ethGiKgkWovz/L+f/pWi+h7AYjP0c9agX 2EBtNVjnFsnxP4XJMrHAttrhMAKDbQRjdpclWIQ3FCz+MNfepst/SO3OeIMyCO3j4wWu HyHqfOtOg2FDBOX52eI7VMK7B0gMSj06O2SjsEJ0las3G6/U4OHb8GrMIZ2RLVxQgK8u OyCg== X-Gm-Message-State: AIVw112tdRU15BAFU/Ce/U3qItcD/m/3ol499ZQ25zjzsCCHIHgiFdYm TtScU5RrFhkkfqOh X-Received: by 10.223.165.86 with SMTP id j22mr7227759wrb.147.1499694372035; Mon, 10 Jul 2017 06:46:12 -0700 (PDT) Received: from localhost.localdomain ([154.149.70.241]) by smtp.gmail.com with ESMTPSA id g63sm12139915wrd.11.2017.07.10.06.46.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Jul 2017 06:46:11 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, ebiggers@google.com Date: Mon, 10 Jul 2017 14:45:47 +0100 Message-Id: <20170710134548.20234-2-ard.biesheuvel@linaro.org> In-Reply-To: <20170710134548.20234-1-ard.biesheuvel@linaro.org> References: <20170710134548.20234-1-ard.biesheuvel@linaro.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 10 Jul 2017 13:46:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 10 Jul 2017 13:46:13 +0000 (UTC) for IP:'209.85.128.180' DOMAIN:'mail-wr0-f180.google.com' HELO:'mail-wr0-f180.google.com' FROM:'ard.biesheuvel@linaro.org' RCPT:'' X-RedHat-Spam-Score: -2.511 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.128.180 mail-wr0-f180.google.com 209.85.128.180 mail-wr0-f180.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: dm-devel@redhat.com Cc: snitzer@redhat.com, Ard Biesheuvel , linux-wireless@vger.kernel.org, dm-devel@redhat.com, johannes@sipsolutions.net, davem@davemloft.net, agk@redhat.com Subject: [dm-devel] [PATCH 1/2] crypto/algapi - use separate dst and src operands for __crypto_xor() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 10 Jul 2017 13:46:20 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP In preparation of updating crypto_xor() [which is what the crypto API exposes to other subsystems] to use separate operands for input and output, first modify the __crypto_xor() implementation that provides the actual functionality when not using the inline version. Signed-off-by: Ard Biesheuvel --- crypto/algapi.c | 25 ++++++++++++-------- include/crypto/algapi.h | 4 ++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/crypto/algapi.c b/crypto/algapi.c index e4cc7615a139..aa699ff6c876 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -975,13 +975,15 @@ void crypto_inc(u8 *a, unsigned int size) } EXPORT_SYMBOL_GPL(crypto_inc); -void __crypto_xor(u8 *dst, const u8 *src, unsigned int len) +void __crypto_xor(u8 *dst, const u8 *src1, const u8 *src2, unsigned int len) { int relalign = 0; if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) { int size = sizeof(unsigned long); - int d = ((unsigned long)dst ^ (unsigned long)src) & (size - 1); + int d = (((unsigned long)dst ^ (unsigned long)src1) | + ((unsigned long)dst ^ (unsigned long)src2)) & + (size - 1); relalign = d ? 1 << __ffs(d) : size; @@ -992,34 +994,37 @@ void __crypto_xor(u8 *dst, const u8 *src, unsigned int len) * process the remainder of the input using optimal strides. */ while (((unsigned long)dst & (relalign - 1)) && len > 0) { - *dst++ ^= *src++; + *dst++ = *src1++ ^ *src2++; len--; } } while (IS_ENABLED(CONFIG_64BIT) && len >= 8 && !(relalign & 7)) { - *(u64 *)dst ^= *(u64 *)src; + *(u64 *)dst = *(u64 *)src1 ^ *(u64 *)src2; dst += 8; - src += 8; + src1 += 8; + src2 += 8; len -= 8; } while (len >= 4 && !(relalign & 3)) { - *(u32 *)dst ^= *(u32 *)src; + *(u32 *)dst = *(u32 *)src1 ^ *(u32 *)src2; dst += 4; - src += 4; + src1 += 4; + src2 += 4; len -= 4; } while (len >= 2 && !(relalign & 1)) { - *(u16 *)dst ^= *(u16 *)src; + *(u16 *)dst = *(u16 *)src1 ^ *(u16 *)src2; dst += 2; - src += 2; + src1 += 2; + src2 += 2; len -= 2; } while (len--) - *dst++ ^= *src++; + *dst++ = *src1++ ^ *src2++; } EXPORT_SYMBOL_GPL(__crypto_xor); diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 436c4c2683c7..fd547f946bf8 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -192,7 +192,7 @@ static inline unsigned int crypto_queue_len(struct crypto_queue *queue) } void crypto_inc(u8 *a, unsigned int size); -void __crypto_xor(u8 *dst, const u8 *src, unsigned int size); +void __crypto_xor(u8 *dst, const u8 *src1, const u8 *src2, unsigned int size); static inline void crypto_xor(u8 *dst, const u8 *src, unsigned int size) { @@ -207,7 +207,7 @@ static inline void crypto_xor(u8 *dst, const u8 *src, unsigned int size) size -= sizeof(unsigned long); } } else { - __crypto_xor(dst, src, size); + __crypto_xor(dst, dst, src, size); } }