ecurve: upgrade to 0.9.0

This commit is contained in:
Daniel Cousens 2014-06-16 01:36:05 +10:00
parent cfe5436394
commit f42993297c
6 changed files with 19 additions and 19 deletions

View file

@ -23,7 +23,7 @@ function deterministicGenerateK(curve, hash, d) {
v = crypto.HmacSHA256(v, k)
v = crypto.HmacSHA256(v, k)
var n = curve.params.n
var n = curve.n
var kB = BigInteger.fromBuffer(v).mod(n)
assert(kB.compareTo(BigInteger.ONE) > 0, 'Invalid k value')
assert(kB.compareTo(n) < 0, 'Invalid k value')
@ -34,8 +34,8 @@ function deterministicGenerateK(curve, hash, d) {
function sign(curve, hash, d) {
var k = deterministicGenerateK(curve, hash, d)
var n = curve.params.n
var G = curve.params.G
var n = curve.n
var G = curve.G
var Q = G.multiply(k)
var e = BigInteger.fromBuffer(hash)
@ -62,8 +62,8 @@ function verify(curve, hash, signature, Q) {
}
function verifyRaw(curve, e, signature, Q) {
var n = curve.params.n
var G = curve.params.G
var n = curve.n
var G = curve.G
var r = signature.r
var s = signature.s
@ -104,8 +104,8 @@ function recoverPubKey(curve, e, signature, i) {
// first or second candidate key.
var isSecondKey = i >> 1
var n = curve.params.n
var G = curve.params.G
var n = curve.n
var G = curve.G
var p = curve.p
var a = curve.a
var b = curve.b

View file

@ -12,9 +12,9 @@ var curve = ecurve.getCurveByName('secp256k1')
function ECKey(d, compressed) {
assert(d.signum() > 0, 'Private key must be greater than 0')
assert(d.compareTo(curve.params.n) < 0, 'Private key must be less than the curve order')
assert(d.compareTo(curve.n) < 0, 'Private key must be less than the curve order')
var Q = curve.params.G.multiply(d)
var Q = curve.G.multiply(d)
this.d = d
this.pub = new ECPubKey(Q, compressed)
@ -47,7 +47,7 @@ ECKey.makeRandom = function(compressed, rng) {
var buffer = new Buffer(rng(32))
var d = BigInteger.fromBuffer(buffer)
d = d.mod(curve.params.n)
d = d.mod(curve.n)
return new ECKey(d, compressed)
}

View file

@ -222,7 +222,7 @@ HDNode.prototype.derive = function(index) {
var pIL = BigInteger.fromBuffer(IL)
// In case parse256(IL) >= n, proceed with the next value for i
if (pIL.compareTo(curve.params.n) >= 0) {
if (pIL.compareTo(curve.n) >= 0) {
return this.derive(index + 1)
}
@ -230,7 +230,7 @@ HDNode.prototype.derive = function(index) {
var hd
if (this.privKey) {
// ki = parse256(IL) + kpar (mod n)
var ki = pIL.add(this.privKey.d).mod(curve.params.n)
var ki = pIL.add(this.privKey.d).mod(curve.n)
// In case ki == 0, proceed with the next value for i
if (ki.signum() === 0) {
@ -243,7 +243,7 @@ HDNode.prototype.derive = function(index) {
} else {
// Ki = point(parse256(IL)) + Kpar
// = G*IL + Kpar
var Ki = curve.params.G.multiply(pIL).add(this.pubKey.Q)
var Ki = curve.G.multiply(pIL).add(this.pubKey.Q)
// In case Ki is the point at infinity, proceed with the next value for i
if (curve.isInfinity(Ki)) {