pyca/ed25519 — pull request #16 by Ivoz (2013-10-06 15:17:52+00:00)
Title: Manual bit unpacking is slow

I have 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
```