This commit is contained in:
Fedor Indutny
2024-11-12 19:39:30 -08:00
parent 33e82b60d4
commit 7b86a52e65
4 changed files with 18 additions and 5 deletions
+14 -1
View File
@@ -2289,9 +2289,19 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
if (!options) if (!options)
options = {}; options = {};
if (typeof msg !== 'string' && typeof msg !== 'number' && !BN.isBN(msg)) {
assert(typeof msg === 'object' && msg && typeof msg.length === 'number',
'Expected message to be an array-like, a hex string, or a BN instance');
assert((msg.length >>> 0) === msg.length); // non-negative 32-bit integer
for (var i = 0; i < msg.length; i++) assert((msg[i] & 255) === msg[i]);
}
key = this.keyFromPrivate(key, enc); key = this.keyFromPrivate(key, enc);
msg = this._truncateToN(msg, false, options.msgBitLength); msg = this._truncateToN(msg, false, options.msgBitLength);
// Would fail further checks, but let's make the error message clear
assert(!msg.isNeg(), 'Can not sign a negative message');
// Zero-extend key to provide enough entropy // Zero-extend key to provide enough entropy
var bytes = this.n.byteLength(); var bytes = this.n.byteLength();
var bkey = key.getPrivate().toArray('be', bytes); var bkey = key.getPrivate().toArray('be', bytes);
@@ -2299,6 +2309,9 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
// Zero-extend nonce to have the same byte size as N // Zero-extend nonce to have the same byte size as N
var nonce = msg.toArray('be', bytes); var nonce = msg.toArray('be', bytes);
// Recheck nonce to be bijective to msg
assert((new BN(nonce)).eq(msg), 'Can not sign message');
// Instantiate Hmac_DRBG // Instantiate Hmac_DRBG
var drbg = new HmacDRBG({ var drbg = new HmacDRBG({
hash: this.hash, hash: this.hash,
@@ -8889,7 +8902,7 @@ utils.encode = function encode(arr, enc) {
},{}],35:[function(require,module,exports){ },{}],35:[function(require,module,exports){
module.exports={ module.exports={
"name": "elliptic", "name": "elliptic",
"version": "6.6.0", "version": "6.6.1",
"description": "EC cryptography", "description": "EC cryptography",
"main": "lib/elliptic.js", "main": "lib/elliptic.js",
"files": [ "files": [
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,11 +1,11 @@
{ {
"name": "elliptic", "name": "elliptic",
"version": "6.6.0", "version": "6.6.1",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"version": "6.6.0", "version": "6.6.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"bn.js": "^4.11.9", "bn.js": "^4.11.9",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "elliptic", "name": "elliptic",
"version": "6.6.0", "version": "6.6.1",
"description": "EC cryptography", "description": "EC cryptography",
"main": "lib/elliptic.js", "main": "lib/elliptic.js",
"files": [ "files": [