Skip to content

Commit b8a7edd

Browse files
committed
6.6.0
1 parent 34c8534 commit b8a7edd

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

dist/elliptic.js

+30-8
Original file line numberDiff line numberDiff line change
@@ -2252,8 +2252,27 @@ EC.prototype.genKeyPair = function genKeyPair(options) {
22522252
}
22532253
};
22542254

2255-
EC.prototype._truncateToN = function _truncateToN(msg, truncOnly) {
2256-
var delta = msg.byteLength() * 8 - this.n.bitLength();
2255+
EC.prototype._truncateToN = function _truncateToN(msg, truncOnly, bitLength) {
2256+
var byteLength;
2257+
if (BN.isBN(msg) || typeof msg === 'number') {
2258+
msg = new BN(msg, 16);
2259+
byteLength = msg.byteLength();
2260+
} else if (typeof msg === 'object') {
2261+
// BN assumes an array-like input and asserts length
2262+
byteLength = msg.length;
2263+
msg = new BN(msg, 16);
2264+
} else {
2265+
// BN converts the value to string
2266+
var str = msg.toString();
2267+
// HEX encoding
2268+
byteLength = (str.length + 1) >>> 1;
2269+
msg = new BN(str, 16);
2270+
}
2271+
// Allow overriding
2272+
if (typeof bitLength !== 'number') {
2273+
bitLength = byteLength * 8;
2274+
}
2275+
var delta = bitLength - this.n.bitLength();
22572276
if (delta > 0)
22582277
msg = msg.ushrn(delta);
22592278
if (!truncOnly && msg.cmp(this.n) >= 0)
@@ -2271,7 +2290,7 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
22712290
options = {};
22722291

22732292
key = this.keyFromPrivate(key, enc);
2274-
msg = this._truncateToN(new BN(msg, 16));
2293+
msg = this._truncateToN(msg, false, options.msgBitLength);
22752294

22762295
// Zero-extend key to provide enough entropy
22772296
var bytes = this.n.byteLength();
@@ -2327,8 +2346,11 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
23272346
}
23282347
};
23292348

2330-
EC.prototype.verify = function verify(msg, signature, key, enc) {
2331-
msg = this._truncateToN(new BN(msg, 16));
2349+
EC.prototype.verify = function verify(msg, signature, key, enc, options) {
2350+
if (!options)
2351+
options = {};
2352+
2353+
msg = this._truncateToN(msg, false, options.msgBitLength);
23322354
key = this.keyFromPublic(key, enc);
23332355
signature = new Signature(signature, 'hex');
23342356

@@ -2530,8 +2552,8 @@ KeyPair.prototype.sign = function sign(msg, enc, options) {
25302552
return this.ec.sign(msg, this, enc, options);
25312553
};
25322554

2533-
KeyPair.prototype.verify = function verify(msg, signature) {
2534-
return this.ec.verify(msg, signature, this);
2555+
KeyPair.prototype.verify = function verify(msg, signature, options) {
2556+
return this.ec.verify(msg, signature, this, undefined, options);
25352557
};
25362558

25372559
KeyPair.prototype.inspect = function inspect() {
@@ -8867,7 +8889,7 @@ utils.encode = function encode(arr, enc) {
88678889
},{}],35:[function(require,module,exports){
88688890
module.exports={
88698891
"name": "elliptic",
8870-
"version": "6.5.7",
8892+
"version": "6.6.0",
88718893
"description": "EC cryptography",
88728894
"main": "lib/elliptic.js",
88738895
"files": [

dist/elliptic.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "elliptic",
3-
"version": "6.5.7",
3+
"version": "6.6.0",
44
"description": "EC cryptography",
55
"main": "lib/elliptic.js",
66
"files": [

0 commit comments

Comments
 (0)