Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3904746pxy; Tue, 4 May 2021 12:37:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/vT3e3aJ6J7Ktrs8EP6Fbj63dpQLZQfHE/Y9zSFZ86K8TwxD8FCHVGY7HDE2hnOjB3SgD X-Received: by 2002:a05:6402:26ce:: with SMTP id x14mr21922129edd.216.1620157076422; Tue, 04 May 2021 12:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620157076; cv=none; d=google.com; s=arc-20160816; b=V8rEJjg6TVyz4suvW7Bq0Mc+3X4/1CGc3xefhWBVBewP3nIwXEOa4YCFRozgmRaCBZ raEtRitQHZ21IO4d43/aHzM7vM8w6PSr7Y6gFJsAv8m+WYkXeUdQ6hbCm1l7dZRUE1He lyoC17O17vQ3nL1x+nDmDYT5MJxdthspvBEYauoeYllOKdL06EGlr4fnlLNLduFbE5uM 4B+O4Jnc+ZN07dtOdyZx1W6tbJX+bx0f4JGxpxgQFrvUW/5jzuzCYyq/1TQXQ+5h0efx sU/zPiGwnquxIBUsr8YaSiXv7Cpi04aAxtriu+PKP2jNuAtHHudRitNOAI2jy7eDkAGf IeFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=2cYn5vqS73S57qXZKVANS0C8bBykwVcgTbQPjaVzXjU=; b=FDiauw4dOiNvBQ67RmiDVxR2HElPtz/dIKOMJ+PtyJEG3dsiwWjN1K/G79wV0jX6AD NEqQq2wD0NX2u8Js6d+TU4hbBh7o1RrffWGfvKDpFQCKqyraN2nEfSfTd23+LK7NAXDH FStCGwUiyJR125jc8MI9vO0YlMNVuZKfU84gVMASxRSrDpB6LI/pIbaikf0W8EvfsY+I lkt2LVrpVl+jvm4pPdt9Li3BA+nbW3/QhD4DfudV2bSiV6cqG4aKX0N3pbf+yYAJntSR cFgf61h0YLLyC4Pxfng0+p6Yqh1MMwnYDYPMn1Fi1FQz6yfm9UG2nT9ZW4FFMKUdbt/l GKcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="i2/tEJKG"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn3si3948662ejc.68.2021.05.04.12.37.22; Tue, 04 May 2021 12:37:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="i2/tEJKG"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232254AbhEDThT (ORCPT + 99 others); Tue, 4 May 2021 15:37:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:53732 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232153AbhEDThS (ORCPT ); Tue, 4 May 2021 15:37:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 29962611AB; Tue, 4 May 2021 19:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620156983; bh=i6ahxh9OSb47tZNJ3wX/lTlF8AtbCiuqhyjEP+7mDXw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=i2/tEJKGx/t7vVYrKQXdzpcUOf9xN1dWL0X+F8tLc4izoqKStv4C9sq+i/QfErnSX 6538DCyAJ704el1BQZSThgpzVfqbvhzmjGwnO0J3Zq6aiRTYYL+39b9FrOrHB5iUdn 4xtnB7KEFxe1H0K3mjYRfdVQsaHI5mvnERa6ePQdCOjjLa0acBnVliBzBS48UTGItM yYef3jXv+1LSdcYMswe/ztk3tf2UyDcFWitVGZEMnnvElDZBt0ZaI5TgGCon5i1r9u CtVHLr7gjzWypJF+uCB7JHcNDQu42bVaEJk5OgtOUxsHtE43NkvSgKC0GWzwqXCWvc wdjpHbt94vwsQ== Date: Tue, 4 May 2021 12:36:21 -0700 From: Eric Biggers To: Christophe JAILLET Cc: herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [RFC PATCH] crypto: arc4: Implement a version optimized for memory usage Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Tue, May 04, 2021 at 07:59:38PM +0200, Christophe JAILLET wrote: > Le 04/05/2021 ? 18:57, Eric Biggers a ?crit?: > > On Sun, May 02, 2021 at 09:29:46PM +0200, Christophe JAILLET wrote: > > > +#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) > > > +#define S_type u8 > > > +#else > > > +#define S_type u32 > > > +#endif > > > + > > > struct arc4_ctx { > > > - u32 S[256]; > > > + S_type S[256]; > > > u32 x, y; > > > }; > > > > Is it actually useful to keep both versions? It seems we could just use the u8 > > version everywhere. Note that there aren't actually any unaligned memory > > accesses, so choosing the version conditionally on > > CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS seems odd. What are you trying to > > determine by checking that? > > Hi, this is a bad interpretation from me. > > I thought that S[1] would likely use an odd address and would trigger an > unaligned access. But as we would read only 1 byte, this is not the case. > > Looking at [1], we have : "At this point, it should be clear that accessing > a single byte (u8 or char) will never cause an unaligned access, because all > memory addresses are evenly divisible by one." > > > I wanted to avoid potential performance cost related to using char (i.e u8) > instead of int (i.e. u32). > On some architecture this could require some shift or masking or whatever to > "unpack" the values of S. > > > [1]: > https://www.kernel.org/doc/html/latest/core-api/unaligned-memory-access.html > > CJ > arc4 is an insecure cipher which is only supported for use in legacy protocols. So we don't really need to worry about optimizing performance on every architecture. If the byte-based version is *usually* faster as well as uses less memory, we probably should just use it everywhere. - Eric