diff --git a/lib/bcoin/bip151.js b/lib/bcoin/bip151.js index 42ac49bb..3eab713e 100644 --- a/lib/bcoin/bip151.js +++ b/lib/bcoin/bip151.js @@ -23,7 +23,7 @@ var chachapoly = require('./chachapoly'); * Constants */ -var HKDF_SALT = new Buffer('bitcoinechd' /* ecHd (sic?) */, 'ascii'); +var HKDF_SALT = new Buffer('bitcoinecdh', 'ascii'); var INFO_KEY1 = new Buffer('BitcoinK1', 'ascii'); var INFO_KEY2 = new Buffer('BitcoinK2', 'ascii'); var INFO_SID = new Buffer('BitcoinSessionID', 'ascii'); @@ -142,13 +142,22 @@ BIP151Stream.prototype.maybeRekey = function maybeRekey(data) { */ BIP151Stream.prototype.rekey = function rekey() { + var seed; + assert(this.prk, 'Cannot rekey before initialization.'); + seed = new Buffer(64); + + this.sid.copy(seed, 0); + + this.k1.copy(seed, 32); + this.k1 = utils.hash256(seed); + + this.k2.copy(seed, 32); + this.k2 = utils.hash256(seed); + // All state is reinitialized // aside from the sequence number. - this.k1 = utils.hash256(this.k1); - this.k2 = utils.hash256(this.k2); - this.chacha.init(this.k1, this.iv); this.aead.init(this.k2, this.iv); };