Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Basic Javascript Elliptic Curve implementation
// Ported loosely from BouncyCastle's Java EC code
// Only Fp curves implemented for now
// Requires jsbn.js and jsbn2.js
var BigInteger = require('jsbn').BigInteger
var Barrett = BigInteger.prototype.Barrett
// ----------------
// ECFieldElementFp
// constructor
function ECFieldElementFp(q,x) {
this.x = x;
// TODO if(x.compareTo(q) >= 0) error
this.q = q;
}
function feFpEquals(other) {
if(other == this) return true;
return (this.q.equals(other.q) && this.x.equals(other.x));
}
}
}
function _bi2bytes(n, cnt) {
if (cnt === undefined) {
cnt = (n.bitLength() + 7) >>> 3;
}
var bytes = new Array(cnt);
for (var i = cnt - 1; i >= 0; i--) {
bytes[i] = n[0] & 255; // n.and(0xff);
n = n.shiftRight(8);
}
return bytes;
}
BigInteger.prototype.bytes = function(n) {
return _bi2bytes(this, n);
};
// /////////////////////////////////////////////////////////
function _bytehash(s) {
var sha = crypto.createHash('sha512').update(s).digest();
return _bi2bytes(_bi(sha), 64).reverse();
}
function _stringhash(s) {
var sha = crypto.createHash('sha512').update(s).digest();
return _map(_chr, _bi2bytes(_bi(sha), 64)).join('');
}
function _inthash(s) {
// Basic Javascript Elliptic Curve implementation
// Ported loosely from BouncyCastle's Java EC code
// Only Fp curves implemented for now
// Requires jsbn.js and jsbn2.js
var BigInteger = require('jsbn').BigInteger
var Barrett = BigInteger.prototype.Barrett
// ----------------
// ECFieldElementFp
// constructor
function ECFieldElementFp(q,x) {
this.x = x;
// TODO if(x.compareTo(q) >= 0) error
this.q = q;
}
function feFpEquals(other) {
if(other == this) return true;
return (this.q.equals(other.q) && this.x.equals(other.x));
}