mirror of
https://github.com/hanzoai/elliptic.git
synced 2026-09-23 23:51:03 +00:00
6.6.0
This commit is contained in:
Vendored
+30
-8
@@ -2252,8 +2252,27 @@ EC.prototype.genKeyPair = function genKeyPair(options) {
|
||||
}
|
||||
};
|
||||
|
||||
EC.prototype._truncateToN = function _truncateToN(msg, truncOnly) {
|
||||
var delta = msg.byteLength() * 8 - this.n.bitLength();
|
||||
EC.prototype._truncateToN = function _truncateToN(msg, truncOnly, bitLength) {
|
||||
var byteLength;
|
||||
if (BN.isBN(msg) || typeof msg === 'number') {
|
||||
msg = new BN(msg, 16);
|
||||
byteLength = msg.byteLength();
|
||||
} else if (typeof msg === 'object') {
|
||||
// BN assumes an array-like input and asserts length
|
||||
byteLength = msg.length;
|
||||
msg = new BN(msg, 16);
|
||||
} else {
|
||||
// BN converts the value to string
|
||||
var str = msg.toString();
|
||||
// HEX encoding
|
||||
byteLength = (str.length + 1) >>> 1;
|
||||
msg = new BN(str, 16);
|
||||
}
|
||||
// Allow overriding
|
||||
if (typeof bitLength !== 'number') {
|
||||
bitLength = byteLength * 8;
|
||||
}
|
||||
var delta = bitLength - this.n.bitLength();
|
||||
if (delta > 0)
|
||||
msg = msg.ushrn(delta);
|
||||
if (!truncOnly && msg.cmp(this.n) >= 0)
|
||||
@@ -2271,7 +2290,7 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
|
||||
options = {};
|
||||
|
||||
key = this.keyFromPrivate(key, enc);
|
||||
msg = this._truncateToN(new BN(msg, 16));
|
||||
msg = this._truncateToN(msg, false, options.msgBitLength);
|
||||
|
||||
// Zero-extend key to provide enough entropy
|
||||
var bytes = this.n.byteLength();
|
||||
@@ -2327,8 +2346,11 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
|
||||
}
|
||||
};
|
||||
|
||||
EC.prototype.verify = function verify(msg, signature, key, enc) {
|
||||
msg = this._truncateToN(new BN(msg, 16));
|
||||
EC.prototype.verify = function verify(msg, signature, key, enc, options) {
|
||||
if (!options)
|
||||
options = {};
|
||||
|
||||
msg = this._truncateToN(msg, false, options.msgBitLength);
|
||||
key = this.keyFromPublic(key, enc);
|
||||
signature = new Signature(signature, 'hex');
|
||||
|
||||
@@ -2530,8 +2552,8 @@ KeyPair.prototype.sign = function sign(msg, enc, options) {
|
||||
return this.ec.sign(msg, this, enc, options);
|
||||
};
|
||||
|
||||
KeyPair.prototype.verify = function verify(msg, signature) {
|
||||
return this.ec.verify(msg, signature, this);
|
||||
KeyPair.prototype.verify = function verify(msg, signature, options) {
|
||||
return this.ec.verify(msg, signature, this, undefined, options);
|
||||
};
|
||||
|
||||
KeyPair.prototype.inspect = function inspect() {
|
||||
@@ -8867,7 +8889,7 @@ utils.encode = function encode(arr, enc) {
|
||||
},{}],35:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "elliptic",
|
||||
"version": "6.5.7",
|
||||
"version": "6.6.0",
|
||||
"description": "EC cryptography",
|
||||
"main": "lib/elliptic.js",
|
||||
"files": [
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Generated
+2
-2
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "elliptic",
|
||||
"version": "6.5.7",
|
||||
"version": "6.6.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"version": "6.5.7",
|
||||
"version": "6.6.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bn.js": "^4.11.9",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "elliptic",
|
||||
"version": "6.5.7",
|
||||
"version": "6.6.0",
|
||||
"description": "EC cryptography",
|
||||
"main": "lib/elliptic.js",
|
||||
"files": [
|
||||
|
||||
Reference in New Issue
Block a user