Merge commit from fork

This commit is contained in:
Nikita Skovoroda
2024-11-12 19:38:49 -08:00
committed by GitHub
parent 3613d015ae
commit 33e82b60d4
+13
View File
@@ -115,9 +115,19 @@ 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);
@@ -125,6 +135,9 @@ EC.prototype.sign = function sign(msg, key, enc, options) {
// 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,