Skip to contentSkip to conversation

AES i586-asm optimized

PATCH In review Fruhwirth Clemens 4 participants 5 messages Sep 10, 2003 – Sep 11, 2003 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 AES i586-asm optimized

This patch[1] adds an i586 assembler optimized version of the Rijndael (AES) cipher. Please have a look, try, and criticise.

Before starting the old "do we need assembler" thread again:
As tested by hvr[2] this implemention is significantly faster than the C version. Guys, the linux kernel doesn't even compile with icc (Intel C compiler) so don't start arguing with "a decent compiler one could blahbla.." These are the raw numbers. Assembler is faster.

And before we start to discuss a sophisticated framework for assembler implemention or automatic selection of implementions or preferences by application for a particular implemention and so one: This is the first assembler implemention and most likely the last for a long time. So I think with this perspective it's not worth delaying this feature, especially because after this module disk encryption becomes reasonable.

Regards, Clemens

[1] http://clemens.endorphin.org/patches/aes-i586-asm-2.6.0-test5.diff
[2] http://www.kerneli.org/pipermail/cryptoapi-devel/2003-August/000607.html

crypto/Kconfig +20 -0
diff -u -r --new-file linux-2.6.0-test5.orig/crypto/Kconfig linux-2.6.0-test5/crypto/Kconfig
@@ -126,6 +126,26 @@
 
 	  See http://csrc.nist.gov/encryption/aes/ for more information.
 
+config CRYPTO_AES_586
+	tristate "AES cipher algorithms (586)"
+	depends on CRYPTO && X86 && !X86_64 
+	help
+	  AES cipher algorithms (FIPS-197). AES uses the Rijndael 
+	  algorithm.
+
+	  Rijndael appears to be consistently a very good performer in
+	  both hardware and software across a wide range of computing 
+	  environments regardless of its use in feedback or non-feedback 
+	  modes. Its key setup time is excellent, and its key agility is 
+	  good. Rijndael's very low memory requirements make it very well 
+	  suited for restricted-space environments, in which it also 
+	  demonstrates excellent performance. Rijndael's operations are 
+	  among the easiest to defend against power and timing attacks.	
+
+	  The AES specifies three key sizes: 128, 192 and 256 bits	  
+
+	  See http://csrc.nist.gov/encryption/aes/ for more information.
+
 config CRYPTO_CAST5
 	tristate "CAST5 (CAST-128) cipher algorithm"
 	depends on CRYPTO
crypto/Makefile +3 -0
diff -u -r --new-file linux-2.6.0-test5.orig/crypto/Makefile linux-2.6.0-test5/crypto/Makefile
@@ -19,8 +19,11 @@
 obj-$(CONFIG_CRYPTO_TWOFISH) += twofish.o
 obj-$(CONFIG_CRYPTO_SERPENT) += serpent.o
 obj-$(CONFIG_CRYPTO_AES) += aes.o
+obj-$(CONFIG_CRYPTO_AES_586) += aes-i586.o
 obj-$(CONFIG_CRYPTO_CAST5) += cast5.o
 obj-$(CONFIG_CRYPTO_CAST6) += cast6.o
 obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
 
 obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o
+
+aes-i586-y := aes-i586-asm.o aes-i586-glue.o
crypto/aes-i586-asm.S +925 -0

925 lines not on this page · raw message

crypto/aes-i586-glue.c +89 -0

89 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · Fruhwirth Clemens

This patch[1] adds an i586 assembler optimized version of the Rijndael (AES) cipher. Please have a look, try, and criticise.

Before starting the old "do we need assembler" thread again:
As tested by hvr[2] this implemention is significantly faster than the C version.

Tested on what processors? With what kernel config?

I would be surprised if a 586-optimized asm was useful on P4.

Quoted 2 lines

Guys, the linux kernel doesn't even compile with icc (Intel C compiler)

Wrong. As Intel pointed out on linux-kernel less than 24 hours ago, even.

Quoted 1 line

These are the raw numbers. Assembler is faster.

gcc generates assembler, so this is nonsensical ;-)

Quoted 4 lines

And before we start to discuss a sophisticated framework for assembler implemention or automatic selection of implementions or preferences by application for a particular implemention and so one: This is the first assembler implemention and most likely the last for a long time.

Nope, S/390 folks beat ya to it.

And I'm working on something as well.

Quoted 3 lines

So I think
with this perspective it's not worth delaying this feature, especially because after this module disk encryption becomes reasonable.

In your opinion.

Jeff

#2 lore raw
Quoted 7 lines · Jeff Garzik
Quoted 2 lines · Fruhwirth Clemens

As tested by hvr[2] this implemention is significantly faster than the C version.

Tested on what processors? With what kernel config?

I would be surprised if a 586-optimized asm was useful on P4.

It uses classic Pentium instruction set. Speed optimized for my 300 MHz Pentium-2 test box. Original Gladman version that I started with was pretty fast but I was able to improve performance about 7% over original version.

On my same 300 MHz P2 test box, assembler implementation is about twice as fast as the mainline kernel C implementation.

Regards,
Jari Ruusu <[email protected]>

#3 lore raw
Quoted 12 lines · Jari Ruusu
Quoted 8 lines · Jeff Garzik
Quoted 2 lines · Fruhwirth Clemens

As tested by hvr[2] this implemention is significantly faster than the C version.

Tested on what processors? With what kernel config?

I would be surprised if a 586-optimized asm was useful on P4.

Quoted 6 lines

It uses classic Pentium instruction set. Speed optimized for my 300 MHz Pentium-2 test box. Original Gladman version that I started with was pretty fast but I was able to improve performance about 7% over original version.

On my same 300 MHz P2 test box, assembler implementation is about twice as fast as the mainline kernel C implementation.

Neat. Consider me surprised, then ;-)

Don't take my message as objection to the merge. I dunno what DaveM or JamesM thinks, but I definitely support merging patches like this. It provides a great example, if nothing else.

Eventually I bet there will be issues about automatic algorithm selection: like the RAID5 code, which benchmarks all available algorithms, and selects the fastest one.

Jeff

#4 lore raw

In article <[email protected]>,
Jeff Garzik <[email protected]> wrote:
| Jari Ruusu wrote:

| > It uses classic Pentium instruction set. Speed optimized for my 300 MHz
| > Pentium-2 test box. Original Gladman version that I started with was pretty
| > fast but I was able to improve performance about 7% over original version.
| > 
| > On my same 300 MHz P2 test box, assembler implementation is about twice as
| > fast as the mainline kernel C implementation.
| 
| 
| Neat.  Consider me surprised, then  ;-)
| 
| Don't take my message as objection to the merge.  I dunno what DaveM or 
| JamesM thinks, but I definitely support merging patches like this.  It 
| provides a great example, if nothing else.
| 
| Eventually I bet there will be issues about automatic algorithm 
| selection:  like the RAID5 code, which benchmarks all available 
| algorithms, and selects the fastest one.

Didn't we just have this discussion? ;-) RAID5 benchmarks all available code and then uses SSE2 or whatever because it doesn't plunk the registers or cache or something... sorry, the details escape me, or the sorry details escape me, or whatever.

BTW: I do agree with your point here, I'm using cryptoloop for some stuff I'm doing, and while I never do enough disk i/o to care, this is a good thing for the future. I'm using a PII-350, but next month I have to add a P55C SMP machine, and will be doing much more crypto.

Thanks for asking for clarification, the patch looks better for it.

Signature · 3 lines
bill davidsen <[email protected]>
  CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.