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: 107295 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp3443049qge; Mon, 10 Jul 2017 06:46:15 -0700 (PDT) X-Received: by 10.99.140.79 with SMTP id q15mr14732401pgn.140.1499694375784; Mon, 10 Jul 2017 06:46:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499694375; cv=none; d=google.com; s=arc-20160816; b=RWg4MNLFbF6mEcws1k2mNfGPO5pMsg3D86PAjpANedh2O3Q3R+xn+rWXFEzElPotRV fo5RgE7BDfea6sZDBNCzPrxQb6T6ePxJJagWfQ8ueCw9GpWum5ZjazBJqkAtqpiI2n02 iz1lmn7L3B2Pxttoo9P6lp5DisfEXlCChYrWXfCIaV7Z1k4kHXEffFdo2nQoVPIbBLN6 mxR2OEcGlnrtdm4FEdYCk7FVb7u52CPGZjCJXvkb3knkc2ct5GOBosoNsNWUdKGyq91u wVtaCLcEdqkJOGp1LQWp46N1KB2dn7dzD4FcEZbO20TgJEDDjfIyrNoH0Vo17eirqTgq up9A== 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=zZZKsMVKkLr3FYgcnvfptyUIogCVp/jBa2OcQMjWFwg=; b=EvvnkC6kefEnuhfgud6vr5tdWEJjLYdwfyCZ2b+4yY8XrzTU5ryP2b/ZA8cUcA2sj5 hK0lBy9+DQjoJjT7TY1wvetaU6kpec6nKII3AexhL+jjWtE16dDqJm8JlfPEZtDIFC66 VWIk24Ih8W5NjTN8wkPsJ0kmzcBGjMtGztcIgrYh7F1ZkQ8IT8n8VeeyGuRWZcdi9Kkd sAlDJenqPNLaCdVHJ+8Fup6Xw1ArlvIh5P1hIjyVq7sYr1Ei7loNBCU0o4BRO6xpEWuj tinD545P+Adh+Tvuy9WP0Er32A3Xp7gi1YtsrAmmiQglY8EdV5snEKZpFExmCOC0lYAr XTdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=b7u1oA1U; 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 t25si6389806pge.237.2017.07.10.06.46.15; Mon, 10 Jul 2017 06:46:15 -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=b7u1oA1U; 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 S932155AbdGJNqO (ORCPT + 1 other); Mon, 10 Jul 2017 09:46:14 -0400 Received: from mail-wr0-f173.google.com ([209.85.128.173]:36522 "EHLO mail-wr0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932150AbdGJNqN (ORCPT ); Mon, 10 Jul 2017 09:46:13 -0400 Received: by mail-wr0-f173.google.com with SMTP id c11so139622244wrc.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=PPz4bumzogGp/eI0tynRuZjd2oOk9jfNcWX3iAMRyh0yaLrOUdbtZVeTyt+DzC2Er4 O1PWdZtIQchrP1Jw7WoNjggnaPNFdXH4+A6uDVBdW+AturKQyUirRaoZxZ68hJVjisfS 65AbJhCz/fm435MKnzK4GkHNhaeKfCBt2+1dV5kg5i3xxagCHi0JAR54a7cLIBymtCUj vshn/zb/N1CnbsdZoiWpCkr0FzrPIjV2iE/56tvV6opFlwQDcsJPongsIwd+mKp65L7F IatAOcQ1srInNQIEMd7V7daEq0LJcQ9gT3WpznT1f5HualieMVbNyEPn/okY6CCNuecw sgNg== X-Gm-Message-State: AIVw1102Hn6GxPv+r2IS2bTr3aUf/4OH0q5qv3UgRzmN7oM5cmMaA2Xf FVNX1Tcm5xNQZfucOImmyg== 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 Cc: 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 1/2] crypto/algapi - use separate dst and src operands for __crypto_xor() Date: Mon, 10 Jul 2017 14:45:47 +0100 Message-Id: <20170710134548.20234-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170710134548.20234-1-ard.biesheuvel@linaro.org> References: <20170710134548.20234-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 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(-) -- 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); } }