From patchwork Fri Jan 12 13:15:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 124341 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2049017qgn; Fri, 12 Jan 2018 05:15:40 -0800 (PST) X-Google-Smtp-Source: ACJfBov8r4bsWs5mFgSz8ZPDleUVrgbBjZgd+T5xEsvFEVYByJG/aZgbXSBF9nwqWdoec661BT5T X-Received: by 10.84.238.197 with SMTP id l5mr19427216pln.443.1515762940705; Fri, 12 Jan 2018 05:15:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515762940; cv=none; d=google.com; s=arc-20160816; b=aB0N0wJrBMHbvJhxF6o3ztJTAoeIW+maO01S45efvplQNUkLkUS12vSHM3N6SoxleB LGANYk7lajGMLWOSYSPO8hsOuSevR2iIoE44ZCnA+slP8mRzCZUL8SwH2nRNF8zOHygj N9B8H+6VlvbyvPRKgATCWlxpLz72+r+wXB+wNTxyBZ+XY17XP34ZQtu+eHlebqsu3oLL 5Tyo89wu1pUw5LzmO+pYp0QxWt67Ye9AIOuMh1wX2xzCyj55U1+tSX6L7lUXNyoJ6mRU Mud2zUYbD0QkIhxocC+/lArBRaBMmbK7GcITG+qOLx9dgXgMPkFrLlQKACDOUWX75e7N X9EQ== 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=mTQl3u17/xJbHEh1O6fNQ1UIvhljDtL76EQsnUId8nI=; b=z2pgIUbVoseqXGXH3Rl3lsx+OTR5eAZQKvr4uPJ4N8ATwGaJ2ykpSyC9SoKuMFtdnw gc7Fg6+DkeSKvfRkw1VwbL+HfHz+Tsail1c5j171My1IydwInfvB75ox5+8rvY0pVN3B dKvXpW6ts5mOrbEUn+3c6LdR7kCEzasvYHZdTP6enQ3O/kEkg3GE7bryogP3R8B5UIgp WBpwPqpsOfV3CX+iiGVGabMruhzl9HAQdgt2V/not9tVKNWhwE9fjdZXM0OIOJTn3qMo BChajqavoisQIRzCdQW8wG4aiDpKmH1cFpq6rmzZWBQ8UNt0BTkhuZ/YFheFpzGsFRrg 4cRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RKvsf1fv; 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 c29si3834030pgn.727.2018.01.12.05.15.40; Fri, 12 Jan 2018 05:15:40 -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=RKvsf1fv; 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 S933514AbeALNPj (ORCPT + 1 other); Fri, 12 Jan 2018 08:15:39 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:36244 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933357AbeALNPj (ORCPT ); Fri, 12 Jan 2018 08:15:39 -0500 Received: by mail-wr0-f195.google.com with SMTP id d9so5290187wre.3 for ; Fri, 12 Jan 2018 05:15:38 -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=mTQl3u17/xJbHEh1O6fNQ1UIvhljDtL76EQsnUId8nI=; b=RKvsf1fvy1yfjMyuNbo2CJPLXgtjeWC8nhaKwD+Sj/bfFt/bqP0Te6wJJLiOge7V0O USR8n9c4ExP2slkARW3pKH2iQELjcTKNMBof/dT0PfOUsGmI+dijkwE0aaXNU+rPjXi8 F7oflO3Df509qtpVzRkwqLpanHqdi4z+I9kSo= 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=mTQl3u17/xJbHEh1O6fNQ1UIvhljDtL76EQsnUId8nI=; b=glvCn5C3YaPGL8cfkJSTKpws7vU7lkR2wq7mP6M41MX8IfyBRW4DxKjamB8w6e8bdD /HE+vlPJJ4mA4F42/wz6T+ddNH34XNTzpv4lJtWqSAEXnpUbISwVJ6cqdAX0K4PjIf2y 3neQkHV9bHKzzgciZ+BmSVnPvSbSwVtg7VBjY8aTrbpKLQslNT6VzMlWU1ejp4Jy1PBu XapTo3wMkbGiDIqV+J3ZcBP5iJrwlXo8VdLsBYE0g2G5FR+BaRRIeNm8xF+RlHY09aRQ W8DoVJ+mbkm6XIscPLFN7y7FwFKeoR9vg4C22CcpzbPo1+uDtqf3ZR+mORPx9ma/HwAa wmyw== X-Gm-Message-State: AKGB3mJM62QPZ616IQJEh8xGujsO0v7p8CS1UPXVhceiqXPeE8q6BDP7 SK0xWRBgaRT+AFGrAFrAWihLkQ== X-Received: by 10.223.129.66 with SMTP id 60mr25031071wrm.88.1515762937895; Fri, 12 Jan 2018 05:15:37 -0800 (PST) Received: from localhost.localdomain ([105.141.218.128]) by smtp.gmail.com with ESMTPSA id o98sm16081395wrb.19.2018.01.12.05.15.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 05:15:36 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, will.deacon@arm.com, catalin.marinas@arm.com, steve.capper@linaro.org, jgarzik@redhat.com, Ard Biesheuvel Subject: [PATCH 1/5] crypto/generic: sha3 - fixes for alignment and big endian operation Date: Fri, 12 Jan 2018 13:15:18 +0000 Message-Id: <20180112131522.25663-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180112131522.25663-1-ard.biesheuvel@linaro.org> References: <20180112131522.25663-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. 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);