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

Cleanup #24

Merged
merged 1 commit into from
Aug 27, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions lib/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ Point.prototype.multiply = function(k) {
var R = this

for (var i = h.bitLength() - 2; i > 0; --i) {
R = R.twice()

var hBit = h.testBit(i)
var eBit = e.testBit(i)

if (hBit != eBit) {
R = R.twice()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Putting the R calculation here gives clearer visibility that the testBit operations done above are separate, and non-reliant on it.


if (hBit !== eBit) {
R = R.add(hBit ? this : neg)
}
}
Expand All @@ -157,22 +157,16 @@ Point.prototype.multiply = function(k) {

// Compute this*j + x*k (simultaneous multiplication)
Point.prototype.multiplyTwo = function(j, x, k) {
var i

if (j.bitLength() > k.bitLength())
i = j.bitLength() - 1
else
i = k.bitLength() - 1

var i = Math.max(j.bitLength(), k.bitLength()) - 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO, way clearer what the purpose of this is

var R = this.curve.infinity
var both = this.add(x)

while (i >= 0) {
R = R.twice()

var jBit = j.testBit(i)
var kBit = k.testBit(i)

R = R.twice()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here


if (jBit) {
if (kBit) {
R = R.add(both)
Expand All @@ -181,10 +175,8 @@ Point.prototype.multiplyTwo = function(j, x, k) {
R = R.add(this)
}

} else {
if (kBit) {
R = R.add(x)
}
} else if (kBit) {
R = R.add(x)
}
--i
}
Expand Down