2004-01-27 19:43:17

by Jean-Luc Cooke

[permalink] [raw]
Subject: [PATCH] crypto/sha256.c crypto/sha512.c

Optimized the choice and majority fuctions a bit.

Patch:
http://jlcooke.ca/lkml/faster_sha2.patch

Test suite:
http://jlcooke.ca/lkml/faster_sha2.c
build with:
gcc -O3 -s faster_sha2.c -o faster_sha2

JLC

--
http://www.certainkey.com
Suite 4560 CTTC
1125 Colonel By Dr.
Ottawa ON, K1S 5B6


2004-01-27 20:14:57

by James Morris

[permalink] [raw]
Subject: Re: [PATCH] crypto/sha256.c crypto/sha512.c

On Tue, 27 Jan 2004, Jean-Luc Cooke wrote:

> Optimized the choice and majority fuctions a bit.
>
> Patch:
> http://jlcooke.ca/lkml/faster_sha2.patch
>
> Test suite:
> http://jlcooke.ca/lkml/faster_sha2.c
> build with:
> gcc -O3 -s faster_sha2.c -o faster_sha2
>

What kind of performance improvement does this provide?


- James
--
James Morris
<[email protected]>


2004-01-27 20:26:18

by Jean-Luc Cooke

[permalink] [raw]
Subject: Re: [PATCH] crypto/sha256.c crypto/sha512.c

If you take a peek in your/Plumb's crypto/md5.c you've reduced the F1() macro
to the identical operation as the new Ch() inline function.

It reduces gcc's tenancy to re-load values in functions such like:
(x & y) ^ (~x & z)
(x & y) ^ (x & z) ^ (y & z)

This works out much nicer:
z ^ (x & (y ^ z))
(x & y) | (z & (x | y))

I've seen this in a few .c files (gcc -S blah.c; vim blah.s)

The Ch() and Maj() operations are used a lot in sha256/512.

JLC

On Tue, Jan 27, 2004 at 03:14:53PM -0500, James Morris wrote:
> On Tue, 27 Jan 2004, Jean-Luc Cooke wrote:
>
> > Optimized the choice and majority fuctions a bit.
> >
> > Patch:
> > http://jlcooke.ca/lkml/faster_sha2.patch
> >
> > Test suite:
> > http://jlcooke.ca/lkml/faster_sha2.c
> > build with:
> > gcc -O3 -s faster_sha2.c -o faster_sha2
> >
>
> What kind of performance improvement does this provide?

--
http://www.certainkey.com
Suite 4560 CTTC
1125 Colonel By Dr.
Ottawa ON, K1S 5B6

2004-01-27 21:12:46

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] crypto/sha256.c crypto/sha512.c

On Tue, 27 Jan 2004 15:22:25 -0500
Jean-Luc Cooke <[email protected]> wrote:

> The Ch() and Maj() operations are used a lot in sha256/512.

Your analysis is great, but James was really asking for numbers :-)

2004-01-27 22:15:58

by Jean-Luc Cooke

[permalink] [raw]
Subject: Re: [PATCH] crypto/sha256.c crypto/sha512.c

I updated the faster_sha2.c to include a quick performance test, same URL.

The Ch/sec and Maj/sec can't be easily compared, however instruction
count can to some extent.

http://jlcooke.ca/lkml/faster_sha2_x86.s
http://jlcooke.ca/lkml/faster_sha2_ppc.s
http://jlcooke.ca/lkml/faster_sha2_alpha.s
http://jlcooke.ca/lkml/faster_sha2_sparc.s

Hope this helps, I'll know better next time I ask for patch-blessing. :)

JLC


On Tue, Jan 27, 2004 at 01:05:04PM -0800, David S. Miller wrote:
> On Tue, 27 Jan 2004 15:22:25 -0500
> Jean-Luc Cooke <[email protected]> wrote:
>
> > The Ch() and Maj() operations are used a lot in sha256/512.
>
> Your analysis is great, but James was really asking for numbers :-)
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

--
http://www.certainkey.com
Suite 4560 CTTC
1125 Colonel By Dr.
Ottawa ON, K1S 5B6

2004-01-28 21:34:51

by Jean-Luc Cooke

[permalink] [raw]
Subject: Re: [PATCH] crypto/sha256.c crypto/sha512.c

Humm,

Pardon my ignorance, but does silence mean "yes"?

Didn't see any changes to http://samba.org/~jamesm/crypto/

JLC

On Tue, Jan 27, 2004 at 05:12:29PM -0500, Jean-Luc Cooke wrote:
> I updated the faster_sha2.c to include a quick performance test, same URL.
>
> The Ch/sec and Maj/sec can't be easily compared, however instruction
> count can to some extent.
>
> http://jlcooke.ca/lkml/faster_sha2_x86.s
> http://jlcooke.ca/lkml/faster_sha2_ppc.s
> http://jlcooke.ca/lkml/faster_sha2_alpha.s
> http://jlcooke.ca/lkml/faster_sha2_sparc.s
>
> Hope this helps, I'll know better next time I ask for patch-blessing. :)
>
> JLC
>
>
> On Tue, Jan 27, 2004 at 01:05:04PM -0800, David S. Miller wrote:
> > On Tue, 27 Jan 2004 15:22:25 -0500
> > Jean-Luc Cooke <[email protected]> wrote:
> >
> > > The Ch() and Maj() operations are used a lot in sha256/512.
> >
> > Your analysis is great, but James was really asking for numbers :-)
> > -
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to [email protected]
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at http://www.tux.org/lkml/
>
> --
> http://www.certainkey.com
> Suite 4560 CTTC
> 1125 Colonel By Dr.
> Ottawa ON, K1S 5B6
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

--
http://www.certainkey.com
Suite 4560 CTTC
1125 Colonel By Dr.
Ottawa ON, K1S 5B6

2004-01-28 22:09:21

by James Morris

[permalink] [raw]
Subject: Re: [PATCH] crypto/sha256.c crypto/sha512.c

On Wed, 28 Jan 2004, Jean-Luc Cooke wrote:

> Pardon my ignorance, but does silence mean "yes"?

No, but the patch looks fine to me and passes the test vectors.

Dave, I've included it below.


- James
--
James Morris
<[email protected]>

diff -Naur linux-2.6.1/crypto/sha256.c linux-2.6.1-patched/crypto/sha256.c
--- linux-2.6.1/crypto/sha256.c 2004-01-09 01:59:26.000000000 -0500
+++ linux-2.6.1-patched/crypto/sha256.c 2004-01-27 14:22:00.000000000 -0500
@@ -34,12 +34,12 @@

static inline u32 Ch(u32 x, u32 y, u32 z)
{
- return ((x & y) ^ (~x & z));
+ return z ^ (x & (y ^ z));
}

static inline u32 Maj(u32 x, u32 y, u32 z)
{
- return ((x & y) ^ (x & z) ^ (y & z));
+ return (x & y) | (z & (x | y));
}

static inline u32 RORu32(u32 x, u32 y)
diff -Naur linux-2.6.1/crypto/sha512.c linux-2.6.1-patched/crypto/sha512.c
--- linux-2.6.1/crypto/sha512.c 2004-01-09 02:00:03.000000000 -0500
+++ linux-2.6.1-patched/crypto/sha512.c 2004-01-27 14:22:26.000000000 -0500
@@ -34,12 +34,12 @@

static inline u64 Ch(u64 x, u64 y, u64 z)
{
- return ((x & y) ^ (~x & z));
+ return z ^ (x & (y ^ z));
}

static inline u64 Maj(u64 x, u64 y, u64 z)
{
- return ((x & y) ^ (x & z) ^ (y & z));
+ return (x & y) | (z & (x | y));
}

static inline u64 RORu64(u64 x, u64 y)

2004-01-28 23:03:51

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] crypto/sha256.c crypto/sha512.c

On Wed, 28 Jan 2004 17:08:58 -0500 (EST)
James Morris <[email protected]> wrote:

> On Wed, 28 Jan 2004, Jean-Luc Cooke wrote:
>
> > Pardon my ignorance, but does silence mean "yes"?
>
> No, but the patch looks fine to me and passes the test vectors.
>
> Dave, I've included it below.

Applied, thanks guys.