mirror of
https://github.com/hanzoai/elliptic.git
synced 2026-09-23 23:51:03 +00:00
Merge commit from fork
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user