Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Feb 2017 07:15:07 -0800
From:      Allan Jude <allanjude@FreeBSD.org>
To:        Ed Schouten <ed@nuxi.nl>, Andriy Gapon <avg@freebsd.org>, cperciva@freebsd.org
Cc:        src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   Re: svn commit: r314335 - stable/10/sys/crypto/sha2
Message-ID:  <DDDAE4B2-18CA-46E8-B268-C4BB700E158B@FreeBSD.org>
In-Reply-To: <CABh_MK==nm1rpy0STaECBVF-fT%2B5C5BapDWjkOOqAEeszOBknw@mail.gmail.com>
References:  <201702271305.v1RD5HOi077424@repo.freebsd.org> <CABh_MK==nm1rpy0STaECBVF-fT%2B5C5BapDWjkOOqAEeszOBknw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On February 27, 2017 6:01:41 AM PST, Ed Schouten <ed@nuxi=2Enl> wrote:
>Hi Andriy,
>
>2017-02-27 14:05 GMT+01:00 Andriy Gapon <avg@freebsd=2Eorg>:
>> +/* Message schedule computation */
>> +#define MSCH(W, ii, i)                         \
>> +       W[i + ii + 16] =3D s1(W[i + ii + 14]) + W[i + ii + 9] + s0(W[i
>+ ii + 1]) + W[i + ii]
>
>[snip]
>
>>         uint32_t W[64];
>
>[snip]
>
>> +       for (i =3D 0; i < 64; i +=3D 16) {
>> +               RNDr(S, W, 1, i);
>> +               RNDr(S, W, 2, i);
>> +               RNDr(S, W, 3, i);
>> +               RNDr(S, W, 4, i);
>> +               RNDr(S, W, 5, i);
>> +               RNDr(S, W, 6, i);
>> +               RNDr(S, W, 7, i);
>> +               RNDr(S, W, 8, i);
>> +               RNDr(S, W, 9, i);
>> +               RNDr(S, W, 10, i);
>> +               RNDr(S, W, 11, i);
>> +               RNDr(S, W, 12, i);
>> +               RNDr(S, W, 13, i);
>> +               RNDr(S, W, 14, i);
>> +               RNDr(S, W, 15, i);
>> +
>> +               if (i =3D=3D 48)
>> +                       break;
>> +               MSCH(W, 0, i);
>> +               MSCH(W, 1, i);
>> +               MSCH(W, 2, i);
>> +               MSCH(W, 3, i);
>> +               MSCH(W, 4, i);
>> +               MSCH(W, 5, i);
>> +               MSCH(W, 6, i);
>> +               MSCH(W, 7, i);
>> +               MSCH(W, 8, i);
>> +               MSCH(W, 9, i);
>> +               MSCH(W, 10, i);
>> +               MSCH(W, 11, i);
>> +               MSCH(W, 12, i);
>> +               MSCH(W, 13, i);
>> +               MSCH(W, 14, i);
>> +               MSCH(W, 15, i);
>> +       }
>
>Something interesting that I noticed some time ago when comparing the
>various SHA-{256,512} implementations: there is no need to store the
>entire extended message in W=2E During every iteration of this loop,
>RNDr() and MSCH() never go more than 16 elements back=2E
>
>Say, if you were to modify MSCH() to something like this:
>
>> +#define MSCH(W, ii)                         \
>> +       W[ii] +=3D s1(W[(ii + 14) % 16]) + W[(ii + 9) % 16] + s0(W[(ii
>+ 1)) % 16])
>
>Then it will compute the next chunk of the extended message in-place=2E
>RNDr() must then be adjusted to use W[i] instead of W[i + ii], of
>course=2E W then only needs to hold 16 elements instead of 64 or 80=2E

Add Colin, author of the original code
--=20
Allan Jude



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?DDDAE4B2-18CA-46E8-B268-C4BB700E158B>