Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Montgomery Reduction #208

Merged
merged 7 commits into from
Mar 6, 2015
Merged

Montgomery Reduction #208

merged 7 commits into from
Mar 6, 2015

Conversation

Bren2010
Copy link
Contributor

  1. (Same as before, with cleaner commit history) sjcl.bn.power will no longer freeze if it's not in a field and sjcl.bn.powermod is slightly faster.
  2. Modular exponentiation with Montgomery reduction was implemented at bn.montpowermod(x, N), and bn.powermod(x, N) defers to it when possible (when the modulus is odd).
  3. The rest of the standard SRP group choices have been implemented because using them is somewhat practical now.

Here are some very rough benchmarks I took from my iMac and Ubuntu laptop: (All using 32 byte secret keys, running the code sample from the top of issue #172)

Group Size iMac Time (s) Laptop Time (s)
1024 0.03 0.08
1536 0.07 0.16
2048 0.11 0.26
3072 0.22 0.55
4096 0.40 0.95
6144 0.80 2.00
8192 1.30 3.50

Chrome is usually a tick faster than Firefox. It'd be great if someone else can vouch for similar speeds.

Supersedes pull request #203 and hopefully resolves issue #172.

Questions:

  • Should this be re-implemented similar to the way pseudo-Mersenne primes are (which would get rid of all of the bn.*mod(..., N) methods)? How should the modulus be passed in?
  • If the modulus is even, we could use the smallest viable pseudo-Mersenne prime--that would get fast modulo, but is there a way to divide by a pseudo-Mersenne prime efficiently?

@Nilos
Copy link
Collaborator

Nilos commented Feb 25, 2015

Awesome! I hope I will be able to review this one in the weekend!

}

// Calculate window size as a function of the exponent's size.
if (bitsize == 0) { return this;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a code style like

if (cond) {
  do;
}

Nilos added a commit that referenced this pull request Mar 6, 2015
@Nilos Nilos merged commit 2f591b4 into bitwiseshiftleft:master Mar 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants