From patchwork Fri Jan 19 12:04:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 125153 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp259585ljf; Fri, 19 Jan 2018 04:05:17 -0800 (PST) X-Google-Smtp-Source: ACJfBounzbyXsI5isRllB36LyQcj6Zvz1d153BaXq3MOOeLXW/nyVTmnFg5QRrq9YiWWMK4bq9NN X-Received: by 10.99.127.24 with SMTP id a24mr37203198pgd.225.1516363517526; Fri, 19 Jan 2018 04:05:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516363517; cv=none; d=google.com; s=arc-20160816; b=ZEQ1S031ckUtYSF6XA/4L7bAp6DFkbZZiSYjLjhAfmXpnpr2Byx/O/dGtI/8fIo/kw Fr2/dJv99N+UP/089OkkeRTD7C3EP3aapmop97+l1zMAUjOtsvtpmuTldqxe8pNUZ+5D maf1hxNSWl4aHkOJ6+e3JRjRMr6sDAw4Hf6FY+hh8ZY5SxzWQHHc6qDLBhBeSCSdZHuP mYRBqHmUqa0xLTjfN1aozUfvmDWvVGb8e0Dq83eRwKZddDsyJIvyLEYk5R1cLzOSiU6W /ZJtVdVxSp21PlBiyXz3TnCK2ScURMHisgpa/OZaXJHORZ08ieFw36QIH3klVk/cDU46 TRbw== 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=W2hPYOGsu/1RRSryxdXrQon+v1tjRxHwSl6/6wpdnZo=; b=oeXEEZtx8lzuG6AmxUqjbFCWnXrCuFgB9w3K4WkDwpV2ppEdA+iqi1PPQcoV0DvH1S noHkjlZDRGOIgvxc687mKTAASbrPd1prZR9WgMPtMSjS4aKDjg3Dkh+X/CeeIayw3+uQ LKgnPS1Lzj3nivLtVjHJZBTSteIi5SygQuNViRsndmgy9wPnCO95jW/cOl6Gu8pilx4p x1MKD5kI2Nro/ZGL/rTg9qTNX3JHUCpaLXqaU5F0EXsmVWX3g207IlauWFbeUH/978tF CUpBXnOmsVGzg2TZTouMVGzDNVVQH3T3IvLEhmW1JERscsS37uYYfP611lNV1SyRC9l9 Jncw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M4kLBh19; 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 y2si5314051pgq.384.2018.01.19.04.05.17; Fri, 19 Jan 2018 04:05:17 -0800 (PST) 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.s=google header.b=M4kLBh19; 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 S1752368AbeASMFQ (ORCPT + 1 other); Fri, 19 Jan 2018 07:05:16 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:38046 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751212AbeASMFP (ORCPT ); Fri, 19 Jan 2018 07:05:15 -0500 Received: by mail-wr0-f196.google.com with SMTP id x1so1372877wrb.5 for ; Fri, 19 Jan 2018 04:05:15 -0800 (PST) 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=W2hPYOGsu/1RRSryxdXrQon+v1tjRxHwSl6/6wpdnZo=; b=M4kLBh19aYhF9K2iLzbcH4F0WHsNahqJrU7u+AQlo2U/wwBZxgCBqi80qvuNmYaLbn nkbhlugRemdiSeny2fGzwucsUefkkdxot2hAiU6NncGqjtsZfCcvtg5ixNgWYXFigkVN f3aE50eVNaj4dZKkM2cIGv+fWgtP6c2t/D5+U= 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=W2hPYOGsu/1RRSryxdXrQon+v1tjRxHwSl6/6wpdnZo=; b=UWxw6wi4lfvZN2gW3BjTj3gtt1YOqIR1dc49r7+wt6tv+mrchT43A30eBfhH+J0hWU MYRzX6c0WdU79VV8FiRllpmWqQLReih5OqpJoRgT9g9RUJLNHVESAsxxP1C4lSQqsdHN j3013Yjly+uk9j5FtPtduhm5y/X74564wfPK/UGX33qa0o0TfDyp6Xq+c7J3/1pzHqhm y8aunR8OjMHHKqK9Ke3NwgCqs/sTznw/e1Y1bFx7jp6CvH7c0pFeAsLIfXuhw46WhbLI xB2vANiUoNPQPrgD5DVtgtB7W5Xq97EQpnhbKP9FCMaGAIL2zDmbyg4rA0FuJ7je6HVm YcJA== X-Gm-Message-State: AKwxyteXzdMVBZt6sZg80K4o6Jy85fNEw9LYeord8ro2r8HX+koJvSs0 XmgBnaJtqlSvMdE5lH8mTbZHQYLpmcg= X-Received: by 10.223.196.211 with SMTP id o19mr8574637wrf.201.1516363514535; Fri, 19 Jan 2018 04:05:14 -0800 (PST) Received: from localhost.localdomain ([160.170.62.40]) by smtp.gmail.com with ESMTPSA id 127sm1039149wmk.14.2018.01.19.04.05.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 04:05:13 -0800 (PST) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH 1/8] crypto/generic: sha3 - fixes for alignment and big endian operation Date: Fri, 19 Jan 2018 12:04:33 +0000 Message-Id: <20180119120440.31556-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180119120440.31556-1-ard.biesheuvel@linaro.org> References: <20180119120440.31556-1-ard.biesheuvel@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Ensure that the input is byte swabbed before injecting it into the SHA3 transform. Use the get_unaligned() accessor for this so that we don't perform unaligned access inadvertently on architectures that do not support that. Cc: Fixes: 53964b9ee63b7075 ("crypto: sha3 - Add SHA-3 hash algorithm") Signed-off-by: Ard Biesheuvel --- crypto/sha3_generic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/crypto/sha3_generic.c b/crypto/sha3_generic.c index 7e8ed96236ce..a68be626017c 100644 --- a/crypto/sha3_generic.c +++ b/crypto/sha3_generic.c @@ -18,6 +18,7 @@ #include #include #include +#include #define KECCAK_ROUNDS 24 @@ -149,7 +150,7 @@ static int sha3_update(struct shash_desc *desc, const u8 *data, unsigned int i; for (i = 0; i < sctx->rsizw; i++) - sctx->st[i] ^= ((u64 *) src)[i]; + sctx->st[i] ^= get_unaligned_le64(src + 8 * i); keccakf(sctx->st); done += sctx->rsiz; @@ -174,7 +175,7 @@ static int sha3_final(struct shash_desc *desc, u8 *out) sctx->buf[sctx->rsiz - 1] |= 0x80; for (i = 0; i < sctx->rsizw; i++) - sctx->st[i] ^= ((u64 *) sctx->buf)[i]; + sctx->st[i] ^= get_unaligned_le64(sctx->buf + 8 * i); keccakf(sctx->st);