From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752018AbdKVV35 (ORCPT ); Wed, 22 Nov 2017 16:29:57 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:45014 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751626AbdKVV3y (ORCPT ); Wed, 22 Nov 2017 16:29:54 -0500 X-Google-Smtp-Source: AGs4zMY2NWC8WyGMahxnG//RL3zpMtHL+AZPoEJ7uRAdYNf2Xypq+yoQk3vWwS21EF/QVrM61PskEQ== Date: Wed, 22 Nov 2017 13:29:50 -0800 From: Eric Biggers To: Ard Biesheuvel Cc: "linux-crypto@vger.kernel.org" , Herbert Xu , "Theodore Ts'o" , "Jason A . Donenfeld" , Martin Willi , "linux-kernel@vger.kernel.org" , Eric Biggers Subject: Re: [PATCH 5/5] crypto: chacha20 - Fix keystream alignment for chacha20_block() Message-ID: <20171122212950.GA74584@gmail.com> References: <20171122195139.121269-1-ebiggers3@gmail.com> <20171122195139.121269-6-ebiggers3@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 22, 2017 at 08:51:57PM +0000, Ard Biesheuvel wrote: > On 22 November 2017 at 19:51, Eric Biggers wrote: > > From: Eric Biggers > > > > When chacha20_block() outputs the keystream block, it uses 'u32' stores > > directly. However, the callers (crypto/chacha20_generic.c and > > drivers/char/random.c) declare the keystream buffer as a 'u8' array, > > which is not guaranteed to have the needed alignment. > > > > Fix it by having both callers declare the keystream as a 'u32' array. > > For now this is preferable to switching over to the unaligned access > > macros because chacha20_block() is only being used in cases where we can > > easily control the alignment (stack buffers). > > > > Given this paragraph, I think we agree the correct way to fix this > would be to make chacha20_block() adhere to its prototype, so if we > deviate from that, there should be a good reason. On which > architecture that cares about alignment is this expected to result in > a measurable performance benefit? > Well, variables on the stack tend to be 4 or even 8-byte aligned anyway, so this change probably doesn't make a difference in practice currently. But it still should be fixed, in case it does become a problem. We could certainly leave the type as u8 array and use put_unaligned_le32() instead; that would be a simpler change. But that would be slower on architectures where a potentially-unaligned access requires multiple instructions. Eric