ed25519 icon indicating copy to clipboard operation
ed25519 copied to clipboard

Speed up by fast unpacking

Open Ivoz opened this issue 12 years ago • 4 comments

I added a simple profiling script to show call profiles of the main functions.

This allowed me to see that the manual bit unpacking performed by the likes of

return sum(2 ** i * bit(h, i) for i in range(2 * b))

Was causing a major slowdown, I thought it seemed to be 1/5th of the time for a signature validation.

With the help of a cool dude called ssbr in #python, I've managed to replace generators like the one above with C-speed unpacking using the struct module.

This resulted in 30% faster in signature validation and 50% faster signature generation.

There are two functions which still use by-the-bit packing, encodeint and encodepoint; only encodepoint is still contributing a small noticeable amount of time to runtime. It's now otherwise purely taken up by the edwards/scalarmult functions. You still might get a noticeable speed increase by optimizing these two encoding functions.

Lastly, bit twiddling is hard.

pyca

(ed25519)ivo@ivosung ed25519$ python science.py 
Time generate
0.168344974518

Time create signature
0.423187017441

Time verify signature
0.906836032867

Ivoz

(ed25519)ivo@ivosung ed25519$ python science.py 
Time generate
0.118165969849

Time create signature
0.175889015198

Time verify signature
0.677781820297

Ivoz avatar Oct 06 '13 15:10 Ivoz

rebased onto xrange commit

Ivoz avatar Oct 06 '13 16:10 Ivoz

Strange, tests didn't seem to run on this?

dstufft avatar Oct 06 '13 17:10 dstufft

https://travis-ci.org/pyca/ed25519/builds/12200146

Ivoz avatar Oct 06 '13 18:10 Ivoz

Is there any wont to merge this?

Ivoz avatar Nov 06 '13 07:11 Ivoz