From patchwork Sun May 20 05:07:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10413081 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 D0BE06053B for ; Sun, 20 May 2018 05:07:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2EF5286FB for ; Sun, 20 May 2018 05:07:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6D4F2870C; Sun, 20 May 2018 05:07:01 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 A2900286FB for ; Sun, 20 May 2018 05:07:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750883AbeETFG4 (ORCPT ); Sun, 20 May 2018 01:06:56 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:39239 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750800AbeETFGz (ORCPT ); Sun, 20 May 2018 01:06:55 -0400 Received: by mail-pl0-f68.google.com with SMTP id c19-v6so6858502pls.6 for ; Sat, 19 May 2018 22:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ADmCcvnBR8LqQHTX+wLyztQN4DAE+2H8s4Tuj8/jC7E=; b=c3AdSdueEm0tgdBq67KEEFlJ7WhwFfgx/5vcd5CCZ2OeqrSBcTesfp0/Ug08cVQaJ6 9v/0DmGnysKad3aYmTtdc+225jO9hr7VFlHRRgvrxBHiSX9ccTERk0CZmpP4GvHSWCBH hfP3L8ci62zATlT16il/3BcO745iaNfi4XgmrAviEHZDDUjwTLSXwdzn95XR0420zdit vITR7CzxJ0HIE3ZfqpIGudsbj62QF/C0h5T4V8pxuTi05dF80ruizFUNSX0Avtn+nwhv fEiAb24NEbKLjAz+Gkzq7t5RSOWfncaluEn0ZDGWL7+MF20dYiT2CHC1+aavw7bQAbjP q2RQ== 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=ADmCcvnBR8LqQHTX+wLyztQN4DAE+2H8s4Tuj8/jC7E=; b=gFmRXzycr1/R/MLtZKqQkjH5r1QU/b8sZjUapWDiDCelvYp36YEg/nrYfEry//K6My jCudT8FgRROCx3Qn6EQmk17Pf3YqdfLn9RWr/7IHpjuF7pG1BDIU+N1l/f8YnnhE5jnf NQX1MZOL1f62JQPi8K0t8bVYCqk+SE274mwJPKbKL1wOmTIxUE/hl79x1sAFTZvKHkmD 97Oi5DvMPe/HMe6JjJ0OdxEI5ujGGlBKQLu/VmeWt9iWV6VK54o7Mxv61pfBqtSTG3Tu UjgkwTO/3eEPo5xm85DAb43YTc+OoWjTwtPgaC85b0vRfrvtSIkjAJPK0bL3iH4a+e3D qYDg== X-Gm-Message-State: ALKqPwcjuYQr6wQFc+5Za1h8Bf1GZ0GQVrtVHmQpw1yi0VSj43M++rOW 6B6E852xCrXATHsZWEe1wHqWMdQa X-Google-Smtp-Source: AB8JxZox874RTbznmvB+cKohhXKO2BKRGp9mllIeB+VcU3/FfSjCYGR6DhJAlaHpCafNFrSEfQIteQ== X-Received: by 2002:a17:902:3001:: with SMTP id u1-v6mr15725512plb.376.1526792814906; Sat, 19 May 2018 22:06:54 -0700 (PDT) Received: from sol.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id m9-v6sm19488322pff.41.2018.05.19.22.06.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 May 2018 22:06:54 -0700 (PDT) From: Eric Biggers To: linux-crypto@vger.kernel.org, Herbert Xu Cc: Eric Biggers Subject: [PATCH 1/6] crypto: crc32-generic - use unaligned access macros when needed Date: Sat, 19 May 2018 22:07:37 -0700 Message-Id: <20180520050742.5008-2-ebiggers3@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180520050742.5008-1-ebiggers3@gmail.com> References: <20180520050742.5008-1-ebiggers3@gmail.com> 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 From: Eric Biggers crc32-generic doesn't have a cra_alignmask set, which is desired as its ->update() works with any alignment. However, it incorrectly assumes 4-byte alignment in ->setkey() and when outputting the final digest. Fix this by using the unaligned access macros in those cases. Signed-off-by: Eric Biggers --- crypto/crc32_generic.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crypto/crc32_generic.c b/crypto/crc32_generic.c index 718cbce8d169..20b879881a2d 100644 --- a/crypto/crc32_generic.c +++ b/crypto/crc32_generic.c @@ -29,6 +29,7 @@ * This is crypto api shash wrappers to crc32_le. */ +#include #include #include #include @@ -69,7 +70,7 @@ static int crc32_setkey(struct crypto_shash *hash, const u8 *key, crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN); return -EINVAL; } - *mctx = le32_to_cpup((__le32 *)key); + *mctx = get_unaligned_le32(key); return 0; } @@ -96,7 +97,7 @@ static int crc32_update(struct shash_desc *desc, const u8 *data, static int __crc32_finup(u32 *crcp, const u8 *data, unsigned int len, u8 *out) { - *(__le32 *)out = cpu_to_le32(__crc32_le(*crcp, data, len)); + put_unaligned_le32(__crc32_le(*crcp, data, len), out); return 0; } @@ -110,7 +111,7 @@ static int crc32_final(struct shash_desc *desc, u8 *out) { u32 *crcp = shash_desc_ctx(desc); - *(__le32 *)out = cpu_to_le32p(crcp); + put_unaligned_le32(*crcp, out); return 0; }