From patchwork Mon Jul 24 10:28:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 108548 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp3887335qge; Mon, 24 Jul 2017 03:28:33 -0700 (PDT) X-Received: by 10.98.112.137 with SMTP id l131mr15750581pfc.194.1500892113513; Mon, 24 Jul 2017 03:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500892113; cv=none; d=google.com; s=arc-20160816; b=goeK13s+hTHJWHnwkGiSnEHwte9kvYpwvSUBfaVd3EGc2DH68AvB7mMFZlngfQYyXX qThnjw8dGTiC0TxQqS/mXc8b+mZkV6vmWGEGZhqqCgjhfnX0852s6yNej+cz/yniIw5r j1sMwPSOqKr718tZ6OyTJ9TQNolp/NepUadqf1NKer3CNUZC4+QqkfJ1+QSS15hRnRgv NV4lmqO/aH7xZ5+fra/FFxEPafYsGxNn3tkzA9ZvbZNFEJ5hjXetPCc8Ykx8AL2vNxyX 0hMfbt51WV1oiMJE6Ty/4ps2JWLeVvdd8jBRXXk5RcR6Bs+KA4kKWqOZpP58ZbbCl6ZS gQWA== 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=jB9AOEKw/c7rTJZ4qPof3rnl4NyNez7JWOre16VgUTgvPUZrfuMCHJY/3xG/Krou21 ru6SBiaGRwmBdgAiJ6VwYU6Ptaf257KXiSF8uzuvw0l/+qEHVBe0mDi+qJFGH5odvE28 T4aZ1l33buWtaLOPDjqYWIBCpKgCXjiI/QsUhwNKLNr3CTHNVepKsGxBCR+nIlge9Z+1 g5F9pqTAojoPzSDVtabVDMsCcpsSgOzGr7oRk3sQ8o8klWQG1At30EuelF0X5DRJiyi5 fynNsmTnc6HJWUauXxlMwJhbJzgKtvuuv+NjgmenxGPIx8hEgEG0RibCWrjVXACRLfxP sajw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=hiuXFMe4; 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 38si3348411pld.76.2017.07.24.03.28.33; Mon, 24 Jul 2017 03:28:33 -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=hiuXFMe4; 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 S1751543AbdGXK2c (ORCPT + 1 other); Mon, 24 Jul 2017 06:28:32 -0400 Received: from mail-wm0-f43.google.com ([74.125.82.43]:36236 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751482AbdGXK2b (ORCPT ); Mon, 24 Jul 2017 06:28:31 -0400 Received: by mail-wm0-f43.google.com with SMTP id t201so14634211wmt.1 for ; Mon, 24 Jul 2017 03:28:30 -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=hiuXFMe4DYpKpvoHNX740qBijRVB75HV6oiQ2y4AHMFSJbnzFYcl517sSrorXgz8AS +tioPclqkGtOXpqAbBLWOJ2qGlMNDqlZTg0HTlVOh0mrRlVEwQgrOqn7Y+SjOLk92Uu8 vFWqn1R0smTOxSjl8lQ/LEwiG4SpdXAniglbM= 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=WFf0svAgm/7MsBJdvTBvrMIv1VyaEhaMIOMLFOnCvqKS+zfwi/IBn1Q+1ZEraKrSQv FZ1C+/zLl16ozbuFJCRzzqR80lL+QUSl8F544tHCjHz+8TnJzVUTLHvOC7dSqvbVqg7G 0df6h0KRApbQcvqXmHcQ1hHVIS8T4QgGsiH/ghdqX9ST9TTb5yaJ2JvD+z10T+EfK/xR ejOQKPLANkRS5J/FtFbeWixPckfIrWlmEFiD3nHnghhE3KX9nC1yaK+u2Gt1y4821DUx 686EMX5FaQYh0PfPTds6GlE1XQIlc3xdlZWlv60UCQm7r52ezDuWxFJYryePwYVttWqc I8ZQ== X-Gm-Message-State: AIVw113wEs+snFAvBrQfKYijGYP/nMChVnhOSPrdVW/lkj+Jo8fqkSAg 4F7U+tgbGyXd/L9wAxY30g== X-Received: by 10.28.9.9 with SMTP id 9mr1148553wmj.93.1500892109822; Mon, 24 Jul 2017 03:28:29 -0700 (PDT) Received: from localhost.localdomain ([105.148.195.69]) by smtp.gmail.com with ESMTPSA id v44sm13205400wrb.53.2017.07.24.03.28.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jul 2017 03:28:29 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: herbert@gondor.apana.org.au, dave.martin@arm.com, Ard Biesheuvel Subject: [PATCH resend 01/18] crypto/algapi - use separate dst and src operands for __crypto_xor() Date: Mon, 24 Jul 2017 11:28:03 +0100 Message-Id: <20170724102820.16534-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170724102820.16534-1-ard.biesheuvel@linaro.org> References: <20170724102820.16534-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); } }