Skip to content

Commit

Permalink
Merge commit from fork
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR authored Nov 13, 2024
1 parent b8a7edd commit 04cb6f5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/elliptic/ec/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,29 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
if (!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);
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
var bytes = this.n.byteLength();
var bkey = key.getPrivate().toArray('be', bytes);

// Zero-extend nonce to have the same byte size as N
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
var drbg = new HmacDRBG({
hash: this.hash,
Expand Down

0 comments on commit 04cb6f5

Please sign in to comment.