mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-28 16:15:49 +00:00
[CHORE] Modified functions not to overwrite entire prototype
This commit is contained in:
@@ -1,30 +1,26 @@
|
|||||||
sjcl.ecc.ecdsa.secretKey.prototype = {
|
sjcl.ecc.ecdsa.secretKey.prototype.sign = function(hash, paranoia) {
|
||||||
sign: function(hash, paranoia) {
|
var R = this._curve.r,
|
||||||
var R = this._curve.r,
|
l = R.bitLength(),
|
||||||
l = R.bitLength(),
|
k = sjcl.bn.random(R.sub(1), paranoia).add(1),
|
||||||
k = sjcl.bn.random(R.sub(1), paranoia).add(1),
|
r = this._curve.G.mult(k).x.mod(R),
|
||||||
r = this._curve.G.mult(k).x.mod(R),
|
s = sjcl.bn.fromBits(hash).add(r.mul(this._exponent)).mul(k.inverseMod(R)).mod(R);
|
||||||
s = sjcl.bn.fromBits(hash).add(r.mul(this._exponent)).mul(k.inverseMod(R)).mod(R);
|
|
||||||
|
|
||||||
return sjcl.bitArray.concat(r.toBits(l), s.toBits(l));
|
return sjcl.bitArray.concat(r.toBits(l), s.toBits(l));
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
sjcl.ecc.ecdsa.publicKey.prototype = {
|
sjcl.ecc.ecdsa.publicKey.prototype.verify = function(hash, rs) {
|
||||||
verify: function(hash, rs) {
|
var w = sjcl.bitArray,
|
||||||
var w = sjcl.bitArray,
|
R = this._curve.r,
|
||||||
R = this._curve.r,
|
l = R.bitLength(),
|
||||||
l = R.bitLength(),
|
r = sjcl.bn.fromBits(w.bitSlice(rs,0,l)),
|
||||||
r = sjcl.bn.fromBits(w.bitSlice(rs,0,l)),
|
s = sjcl.bn.fromBits(w.bitSlice(rs,l,2*l)),
|
||||||
s = sjcl.bn.fromBits(w.bitSlice(rs,l,2*l)),
|
sInv = s.inverseMod(R),
|
||||||
sInv = s.inverseMod(R),
|
hG = sjcl.bn.fromBits(hash).mul(sInv).mod(R),
|
||||||
hG = sjcl.bn.fromBits(hash).mul(sInv).mod(R),
|
hA = r.mul(sInv).mod(R),
|
||||||
hA = r.mul(sInv).mod(R),
|
r2 = this._curve.G.mult2(hG, hA, this._point).x;
|
||||||
r2 = this._curve.G.mult2(hG, hA, this._point).x;
|
|
||||||
|
|
||||||
if (r.equals(0) || s.equals(0) || r.greaterEquals(R) || s.greaterEquals(R) || !r2.equals(r)) {
|
if (r.equals(0) || s.equals(0) || r.greaterEquals(R) || s.greaterEquals(R) || !r2.equals(r)) {
|
||||||
throw (new sjcl.exception.corrupt("signature didn't check out"));
|
throw (new sjcl.exception.corrupt("signature didn't check out"));
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user