Browse Source

fix Key tests

patch-2
Manuel Araoz 11 years ago
parent
commit
069f67e924
  1. 5
      Key.js
  2. 34
      browser/vendor.js
  3. 34
      browser/vendor/ecdsa.js

5
Key.js

@ -89,10 +89,11 @@ if (process.versions) {
} }
var eck = new ECKey(); var eck = new ECKey();
eck.setPub( bufferToArray(self.public)); eck.setPub(bufferToArray(self.public));
eck.setCompressed(self.compressed); eck.setCompressed(self.compressed);
var sigA = bufferToArray(sig); var sigA = bufferToArray(sig);
return eck.verify(hash,sigA); var ret = eck.verify(hash,sigA);
return ret;
}; };

34
browser/vendor.js

@ -2284,24 +2284,34 @@ ECPointFp.prototype.getEncoded = function (compressed) {
return enc; return enc;
}; };
ECPointFp.decodeFrom = function (curve, enc) { ECPointFp.decodeFrom = function (ecparams, enc) {
var type = enc[0]; var type = enc[0];
var dataLen = enc.length-1; var dataLen = enc.length-1;
// Extract x and y as byte arrays // Extract x and y as byte arrays
var xBa = enc.slice(1, 1 + dataLen/2); if (type === 4) {
var yBa = enc.slice(1 + dataLen/2, 1 + dataLen); var xBa = enc.slice(1, 1 + dataLen/2),
yBa = enc.slice(1 + dataLen/2, 1 + dataLen),
// Prepend zero byte to prevent interpretation as negative integer x = BigInteger.fromByteArrayUnsigned(xBa),
xBa.unshift(0); y = BigInteger.fromByteArrayUnsigned(yBa);
yBa.unshift(0); }
else {
// Convert to BigIntegers var xBa = enc.slice(1),
var x = new BigInteger(xBa); x = BigInteger.fromByteArrayUnsigned(xBa),
var y = new BigInteger(yBa); p = ecparams.getQ(),
xCubedPlus7 = x.multiply(x).multiply(x).add(new BigInteger('7')).mod(p),
pPlus1Over4 = p.add(new BigInteger('1'))
.divide(new BigInteger('4')),
y = xCubedPlus7.modPow(pPlus1Over4,p);
if (y.mod(new BigInteger('2')).toString() != ''+(type % 2)) {
y = p.subtract(y)
}
}
// Return point // Return point
return new ECPointFp(curve, curve.fromBigInteger(x), curve.fromBigInteger(y)); return new ECPointFp(ecparams,
ecparams.fromBigInteger(x),
ecparams.fromBigInteger(y));
}; };
ECPointFp.prototype.add2D = function (b) { ECPointFp.prototype.add2D = function (b) {

34
browser/vendor/ecdsa.js

@ -41,24 +41,34 @@ ECPointFp.prototype.getEncoded = function (compressed) {
return enc; return enc;
}; };
ECPointFp.decodeFrom = function (curve, enc) { ECPointFp.decodeFrom = function (ecparams, enc) {
var type = enc[0]; var type = enc[0];
var dataLen = enc.length-1; var dataLen = enc.length-1;
// Extract x and y as byte arrays // Extract x and y as byte arrays
var xBa = enc.slice(1, 1 + dataLen/2); if (type === 4) {
var yBa = enc.slice(1 + dataLen/2, 1 + dataLen); var xBa = enc.slice(1, 1 + dataLen/2),
yBa = enc.slice(1 + dataLen/2, 1 + dataLen),
// Prepend zero byte to prevent interpretation as negative integer x = BigInteger.fromByteArrayUnsigned(xBa),
xBa.unshift(0); y = BigInteger.fromByteArrayUnsigned(yBa);
yBa.unshift(0); }
else {
// Convert to BigIntegers var xBa = enc.slice(1),
var x = new BigInteger(xBa); x = BigInteger.fromByteArrayUnsigned(xBa),
var y = new BigInteger(yBa); p = ecparams.getQ(),
xCubedPlus7 = x.multiply(x).multiply(x).add(new BigInteger('7')).mod(p),
pPlus1Over4 = p.add(new BigInteger('1'))
.divide(new BigInteger('4')),
y = xCubedPlus7.modPow(pPlus1Over4,p);
if (y.mod(new BigInteger('2')).toString() != ''+(type % 2)) {
y = p.subtract(y)
}
}
// Return point // Return point
return new ECPointFp(curve, curve.fromBigInteger(x), curve.fromBigInteger(y)); return new ECPointFp(ecparams,
ecparams.fromBigInteger(x),
ecparams.fromBigInteger(y));
}; };
ECPointFp.prototype.add2D = function (b) { ECPointFp.prototype.add2D = function (b) {

Loading…
Cancel
Save