Skip to content

Commit

Permalink
6.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Oct 26, 2024
1 parent 34c8534 commit b8a7edd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
38 changes: 30 additions & 8 deletions dist/elliptic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion dist/elliptic.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elliptic",
"version": "6.5.7",
"version": "6.6.0",
"description": "EC cryptography",
"main": "lib/elliptic.js",
"files": [
Expand Down

0 comments on commit b8a7edd

Please # to comment.