Skip to content
This repository has been archived by the owner on Nov 16, 2021. It is now read-only.

Commit

Permalink
Optimized the bn_inverse method.
Browse files Browse the repository at this point in the history
The new method needs about 30 % less time for prime256k1 and is about
twice as fast for other moduli.  The base algorithm is the same.
The code is also a bit smaller and doesn't need the 8 kb precomputed
table.

Important canges:
1. even/odd distinction so that we need to test only one of the numbers
   for being even.  This also leads to less duplicated code.
2. Allow for shifting by 32 bits at a time in the even test.
3. Pack u,s and v,r into the same array, which saves a bit of stack memory.
4. Don't divide by two after subtraction; this simplifies code.
5. Abort as soon as u,v are equal, instead of subtracting them.
6. Use s instead of r after the loop; no negation needed.
7. New code that divides by 2^k fast without any precomputed values.
  • Loading branch information
jhoenicke committed Mar 17, 2015
1 parent e37ba82 commit 7d4cf5c
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 515 deletions.

0 comments on commit 7d4cf5c

Please sign in to comment.