bip151: update to conform to spec.

This commit is contained in:
Christopher Jeffrey 2016-08-22 22:36:33 -07:00
parent 8f8cf4fca6
commit 049be2086d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -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);
};