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: 10160821 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E54B2602A7 for ; Fri, 12 Jan 2018 13:15:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D67EB28853 for ; Fri, 12 Jan 2018 13:15:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB107289E4; Fri, 12 Jan 2018 13:15:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A5E428853 for ; Fri, 12 Jan 2018 13:15:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933514AbeALNPj (ORCPT ); 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-Google-Smtp-Source: ACJfBouhHozOzvKkX5BpFvyEjB4/zDkYfcO5DlSb8nUADP2vxdslcA16hJOMlsOZeDuPidBFkwwDiA== 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 X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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);