[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKv+Gu-6JCQ=f=Qy8DCLAN4V56HbXAG9Wr2Tb7Zm25HLKuG4Lg@mail.gmail.com>
Date: Mon, 22 Oct 2018 19:43:01 -0300
From: Ard Biesheuvel <ard.biesheuvel@...aro.org>
To: Eric Biggers <ebiggers@...nel.org>
Cc: "open list:HARDWARE RANDOM NUMBER GENERATOR CORE"
<linux-crypto@...r.kernel.org>, linux-fscrypt@...r.kernel.org,
linux-arm-kernel <linux-arm-kernel@...ts.infradead.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Herbert Xu <herbert@...dor.apana.org.au>,
Paul Crowley <paulcrowley@...gle.com>,
Greg Kaiser <gkaiser@...gle.com>,
Michael Halcrow <mhalcrow@...gle.com>,
"Jason A . Donenfeld" <Jason@...c4.com>,
Samuel Neves <samuel.c.p.neves@...il.com>,
Tomer Ashur <tomer.ashur@...t.kuleuven.be>
Subject: Re: [RFC PATCH v2 09/12] crypto: nhpoly1305 - add NHPoly1305 support
On 22 October 2018 at 19:40, Eric Biggers <ebiggers@...nel.org> wrote:
> Hi Ard,
>
> On Mon, Oct 22, 2018 at 07:25:27PM -0300, Ard Biesheuvel wrote:
>> >
>> > Hmm, I'm actually leaning towards the following instead. Unrolling multiple
>> > strides to try to reduce loads of the keys doesn't seem worthwhile in the C
>> > implementation; for one, it bloats the code size a lot
>> > (412 => 2332 bytes on arm32).
>> >
>> > static void nh_generic(const u32 *key, const u8 *message, size_t message_len,
>> > __le64 hash[NH_NUM_PASSES])
>> > {
>> > u64 sums[4] = { 0, 0, 0, 0 };
>> >
>> > BUILD_BUG_ON(NH_PAIR_STRIDE != 2);
>> > BUILD_BUG_ON(NH_NUM_PASSES != 4);
>> >
>> > while (message_len) {
>> > u32 m0 = get_unaligned_le32(message + 0);
>> > u32 m1 = get_unaligned_le32(message + 4);
>> > u32 m2 = get_unaligned_le32(message + 8);
>> > u32 m3 = get_unaligned_le32(message + 12);
>> >
>> > sums[0] += (u64)(u32)(m0 + key[ 0]) * (u32)(m2 + key[ 2]);
>> > sums[1] += (u64)(u32)(m0 + key[ 4]) * (u32)(m2 + key[ 6]);
>> > sums[2] += (u64)(u32)(m0 + key[ 8]) * (u32)(m2 + key[10]);
>> > sums[3] += (u64)(u32)(m0 + key[12]) * (u32)(m2 + key[14]);
>> > sums[0] += (u64)(u32)(m1 + key[ 1]) * (u32)(m3 + key[ 3]);
>> > sums[1] += (u64)(u32)(m1 + key[ 5]) * (u32)(m3 + key[ 7]);
>> > sums[2] += (u64)(u32)(m1 + key[ 9]) * (u32)(m3 + key[11]);
>> > sums[3] += (u64)(u32)(m1 + key[13]) * (u32)(m3 + key[15]);
>>
>> Are these (u32) casts really necessary? All the addends are u32 types,
>> so I'd expect each (x + y) subexpression to have a u32 type already as
>> well. Or am I missing something?
>>
>
> The (u32) casts are only necessary when sizeof(int) > sizeof(u32), as then the
> addends will be promoted to 'int'. Of course, that's never the case for the
> Linux kernel. But I prefer it to be as robust and well-defined as possible,
> since people might use this as a reference when coding other implementations,
> which could end up finding their way into unusual and/or future platforms.
>
Fair enough.
Powered by blists - more mailing lists