From patchwork Tue Jul 18 09:19:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 108073 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp5660467qge; Tue, 18 Jul 2017 02:19:27 -0700 (PDT) X-Received: by 10.84.167.74 with SMTP id j10mr644868plg.41.1500369567785; Tue, 18 Jul 2017 02:19:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500369567; cv=none; d=google.com; s=arc-20160816; b=VrCUsJMfoo6ypjN9fIrZEsxG1UzVSKuygowr7TafR2tGw4dpdpcysxXUdhFhoq6uFh wb8pGKq18dGd1svp7nB+k16hcnx0kSRD2RvC/0jEn5oR7fGvHle+DKleDUfiMv4U8Hse YlIZxSuNwITqBeLEN8fEW74tKNOou0oX3xFzbjvOY+ppkicpQNzGcwyJVwxULj9p4d6q BpeTcpCmyFYJ26txYR5b+of1Ec5ZdEmC7HQX75dcOD4tLXR2y4ItFGg9V/6ciL+cRskJ EqpllQxtkoRrihWfUST6rIS7Vr92WSf5pmXjwk9/NWIjj0MlH88XE2LcxPzm2/bWfHOX 7wQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=TTcJNC6kusyK3xBwuxZWQr4herCFHTJeaV8oPhIifTo=; b=IdWp1rqt0eJltJhl3Mq2ls3gBxgnT0EADoXaNpCrxvfNFQBAMnzXy6/OKVYIUo3Oc5 gwWYr/S2EH6miB4KADNbtcna7fF5tMB2YTuYUds2452njtt1fpRgwHbCElXw179OQmY8 4g0ZtL/C4hjunJ9JC/suzLf2+cTSjRwF3mWY8nDV61HY1H/jbL2uzxk9BPQobvAbSSYD PDI22Mt2I4+EE2VAmMdawtr4PHsJbG9aM+tHh0Y+DYuaQe0WASqUTCURHFbJH+RLjoiN wOhCBONudFHDvJOkxTIxZL79P/qpw4qRfEYu6NRqppCpBaOdxs2ZA5FKpSY7CUg+MzC0 8r8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=HCy2I3tw; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m23si1380689plk.369.2017.07.18.02.19.27; Tue, 18 Jul 2017 02:19:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=HCy2I3tw; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751418AbdGRJTZ (ORCPT + 1 other); Tue, 18 Jul 2017 05:19:25 -0400 Received: from mail-wr0-f180.google.com ([209.85.128.180]:36806 "EHLO mail-wr0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751334AbdGRJTX (ORCPT ); Tue, 18 Jul 2017 05:19:23 -0400 Received: by mail-wr0-f180.google.com with SMTP id y43so19869214wrd.3 for ; Tue, 18 Jul 2017 02:19:23 -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=TTcJNC6kusyK3xBwuxZWQr4herCFHTJeaV8oPhIifTo=; b=HCy2I3twwrERzOGsugyUagG905OCrqWpzi6PucFPlOFABSa4t8m9Vzb9AwRhHdkf7A Z9YLOi7LoYPcqNnxGBOZztpbM7m199VkWhLD9pvJxzCXjB6VBFNztg/4xBeYdqHmbijt tKhaTnI3ljOMPgYfaC2KdSidcNO8aSd3XZs+k= 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=TTcJNC6kusyK3xBwuxZWQr4herCFHTJeaV8oPhIifTo=; b=bpNiH6Cm17DZaOfdVkGyiXnDvBWpIUoy1QHSHrfS/ipAdVFaay3nEk5vPrhgWeLmAF 5jYL/efMfBQBYzbnjEX/JUhEbs3Hb4y+XYPIChFjhWljf9ESxMciAQrZE9r9y6l3T9Hu H9hKB4+qGfI9491iLcwHcV21WQN6u48LfRLratrbmUaTwRb3UmmO/SiSErNu82gKAh57 IP9neJzWcY8wQdcZhds7/f0ptuhZZXuL28DoBEKz9dkUb5Yh5ebReT6w+WIhpx/YviaI f/6GbBM4Ke5r3V3zbXDW6o+Y6ybLE1Z1By+/W6gpZW4LBR1T4tuPFHckEEvkFJyYxGk5 fhmA== X-Gm-Message-State: AIVw110HLQusn2tHpRoVHF92ZhKY5QgEzPYzVLg+EhXj7GLdOgVrTBkE dzDlTpEubhlhsTWWmDB/kg== X-Received: by 10.223.164.83 with SMTP id e19mr493685wra.101.1500369562310; Tue, 18 Jul 2017 02:19:22 -0700 (PDT) Received: from localhost.localdomain ([154.145.198.181]) by smtp.gmail.com with ESMTPSA id k45sm1133024wrk.45.2017.07.18.02.19.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jul 2017 02:19:21 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au Cc: ebiggers@google.com, davem@davemloft.net, dm-devel@redhat.com, johannes@sipsolutions.net, linux-wireless@vger.kernel.org, agk@redhat.com, snitzer@redhat.com, Ard Biesheuvel Subject: [PATCH v2 1/2] crypto/algapi - use separate dst and src operands for __crypto_xor() Date: Tue, 18 Jul 2017 10:19:11 +0100 Message-Id: <20170718091912.14104-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170718091912.14104-1-ard.biesheuvel@linaro.org> References: <20170718091912.14104-1-ard.biesheuvel@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org In preparation of introducing crypto_xor_cpy(), which will use separate operands for input and output, modify the __crypto_xor() implementation, which it will share with the existing crypto_xor(), which 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(-) -- 2.9.3 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); } }