public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto/sha256.c crypto/sha512.c
@ 2004-01-27 19:39 Jean-Luc Cooke
  2004-01-27 20:14 ` James Morris
  0 siblings, 1 reply; 8+ messages in thread
From: Jean-Luc Cooke @ 2004-01-27 19:39 UTC (permalink / raw)
  To: linux-kernel

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] crypto/sha256.c crypto/sha512.c
  2004-01-27 19:39 [PATCH] crypto/sha256.c crypto/sha512.c Jean-Luc Cooke
@ 2004-01-27 20:14 ` James Morris
  2004-01-27 20:22   ` Jean-Luc Cooke
  0 siblings, 1 reply; 8+ messages in thread
From: James Morris @ 2004-01-27 20:14 UTC (permalink / raw)
  To: Jean-Luc Cooke; +Cc: linux-kernel

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
<jmorris@redhat.com>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] crypto/sha256.c crypto/sha512.c
  2004-01-27 20:14 ` James Morris
@ 2004-01-27 20:22   ` Jean-Luc Cooke
  2004-01-27 21:05     ` David S. Miller
  0 siblings, 1 reply; 8+ messages in thread
From: Jean-Luc Cooke @ 2004-01-27 20:22 UTC (permalink / raw)
  To: linux-kernel

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] crypto/sha256.c crypto/sha512.c
  2004-01-27 20:22   ` Jean-Luc Cooke
@ 2004-01-27 21:05     ` David S. Miller
  2004-01-27 22:12       ` Jean-Luc Cooke
  0 siblings, 1 reply; 8+ messages in thread
From: David S. Miller @ 2004-01-27 21:05 UTC (permalink / raw)
  To: Jean-Luc Cooke; +Cc: linux-kernel

On Tue, 27 Jan 2004 15:22:25 -0500
Jean-Luc Cooke <jlcooke@certainkey.com> wrote:

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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] crypto/sha256.c crypto/sha512.c
  2004-01-27 21:05     ` David S. Miller
@ 2004-01-27 22:12       ` Jean-Luc Cooke
  2004-01-28 21:30         ` Jean-Luc Cooke
  0 siblings, 1 reply; 8+ messages in thread
From: Jean-Luc Cooke @ 2004-01-27 22:12 UTC (permalink / raw)
  To: linux-kernel

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 <jlcooke@certainkey.com> 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 majordomo@vger.kernel.org
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] crypto/sha256.c crypto/sha512.c
  2004-01-27 22:12       ` Jean-Luc Cooke
@ 2004-01-28 21:30         ` Jean-Luc Cooke
  2004-01-28 22:08           ` James Morris
  0 siblings, 1 reply; 8+ messages in thread
From: Jean-Luc Cooke @ 2004-01-28 21:30 UTC (permalink / raw)
  To: linux-kernel

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 <jlcooke@certainkey.com> 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 majordomo@vger.kernel.org
> > 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 majordomo@vger.kernel.org
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] crypto/sha256.c crypto/sha512.c
  2004-01-28 21:30         ` Jean-Luc Cooke
@ 2004-01-28 22:08           ` James Morris
  2004-01-28 23:03             ` David S. Miller
  0 siblings, 1 reply; 8+ messages in thread
From: James Morris @ 2004-01-28 22:08 UTC (permalink / raw)
  To: Jean-Luc Cooke; +Cc: linux-kernel, David S. Miller

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
<jmorris@redhat.com>

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)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] crypto/sha256.c crypto/sha512.c
  2004-01-28 22:08           ` James Morris
@ 2004-01-28 23:03             ` David S. Miller
  0 siblings, 0 replies; 8+ messages in thread
From: David S. Miller @ 2004-01-28 23:03 UTC (permalink / raw)
  To: James Morris; +Cc: jlcooke, linux-kernel

On Wed, 28 Jan 2004 17:08:58 -0500 (EST)
James Morris <jmorris@redhat.com> 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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-01-28 23:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-27 19:39 [PATCH] crypto/sha256.c crypto/sha512.c Jean-Luc Cooke
2004-01-27 20:14 ` James Morris
2004-01-27 20:22   ` Jean-Luc Cooke
2004-01-27 21:05     ` David S. Miller
2004-01-27 22:12       ` Jean-Luc Cooke
2004-01-28 21:30         ` Jean-Luc Cooke
2004-01-28 22:08           ` James Morris
2004-01-28 23:03             ` David S. Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox