mirror of
https://github.com/hanzoai/elliptic.git
synced 2026-09-23 23:51:03 +00:00
eddsa: cleanup
This commit is contained in:
@@ -61,9 +61,8 @@ EDDSA.prototype.verify = function verify(message, sig, pub) {
|
||||
|
||||
EDDSA.prototype.hashInt = function hashInt() {
|
||||
var hash = this.hash();
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
for (var i = 0; i < arguments.length; i++)
|
||||
hash.update(arguments[i]);
|
||||
}
|
||||
return utils.intFromLE(hash.digest()).mod(this.curve.n);
|
||||
};
|
||||
|
||||
@@ -90,11 +89,20 @@ EDDSA.prototype.makeSignature = function makeSignature(sig) {
|
||||
*
|
||||
*/
|
||||
EDDSA.prototype.encodePoint = function encodePoint(point) {
|
||||
return utils.pointToLEYoddX(point, this.encodingLength);
|
||||
var enc = utils.intToLE(point.getY(), this.encodingLength);
|
||||
enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0;
|
||||
return enc;
|
||||
};
|
||||
|
||||
EDDSA.prototype.decodePoint = function decodePoint(bytes) {
|
||||
return utils.pointFromLEYoddX(this.curve, bytes, bytes.length);
|
||||
bytes = utils.parseBytes(bytes);
|
||||
|
||||
var lastIx = bytes.length - 1;
|
||||
var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80);
|
||||
var xIsOdd = (bytes[lastIx] & 0x80) !== 0;
|
||||
|
||||
var y = utils.intFromLE(normed);
|
||||
return this.curve.pointFromY(y, xIsOdd);
|
||||
};
|
||||
|
||||
EDDSA.prototype.encodeInt = function encodeInt(num) {
|
||||
|
||||
@@ -26,7 +26,7 @@ function KeyPair(eddsa, params) {
|
||||
|
||||
KeyPair.fromPublic = function fromPublic(eddsa, pub) {
|
||||
if (pub instanceof KeyPair)
|
||||
return pub;
|
||||
return pub;
|
||||
return new KeyPair(eddsa, { pub: pub });
|
||||
};
|
||||
|
||||
|
||||
@@ -177,25 +177,3 @@ function intToLE(num, padTo) {
|
||||
return bytes;
|
||||
}
|
||||
utils.intToLE = intToLE;
|
||||
|
||||
function pointToLEYoddX(point, length) {
|
||||
var enc = intToLE(point.getY(), length);
|
||||
enc[length - 1] |= point.getX().isOdd() ? 0x80 : 0;
|
||||
return enc;
|
||||
}
|
||||
utils.pointToLEYoddX = pointToLEYoddX;
|
||||
|
||||
function pointFromLEYoddX(curve, bytes, expectedLength) {
|
||||
bytes = parseBytes(bytes);
|
||||
|
||||
if (expectedLength !== undefined)
|
||||
utils.assert(bytes.length === expectedLength);
|
||||
|
||||
var lastIx = bytes.length - 1;
|
||||
var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80);
|
||||
var xIsOdd = Boolean(bytes[lastIx] & 0x80);
|
||||
|
||||
var y = intFromLE(normed);
|
||||
return curve.pointFromY(y, xIsOdd);
|
||||
}
|
||||
utils.pointFromLEYoddX = pointFromLEYoddX;
|
||||
|
||||
Reference in New Issue
Block a user