lkml.org 
[lkml]   [2021]   [May]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [RFC PATCH] crypto: arc4: Implement a version optimized for memory usage
From
Date
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

>
> - Eric
>

\
 
 \ /
  Last update: 2021-05-04 21:39    [W:0.388 / U:2.704 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site