bip151: 32 bit sequence and 64 bit iv.
This commit is contained in:
parent
db0552874b
commit
6a2615d3cc
@ -70,9 +70,8 @@ function BIP151Stream(cipher, key) {
|
||||
this.chacha = new chachapoly.ChaCha20();
|
||||
this.aead = new chachapoly.AEAD();
|
||||
this.tag = null;
|
||||
this.seqHi = 0;
|
||||
this.seqLo = 0;
|
||||
this.iv = new Buffer(12);
|
||||
this.seq = 0;
|
||||
this.iv = new Buffer(8);
|
||||
this.iv.fill(0);
|
||||
|
||||
this.highWaterMark = 1024 * (1 << 20);
|
||||
@ -106,8 +105,7 @@ BIP151Stream.prototype.init = function init(publicKey) {
|
||||
this.k2 = utils.hkdfExpand(this.prk, INFO_KEY2, 32, 'sha256');
|
||||
this.sid = utils.hkdfExpand(this.prk, INFO_SID, 32, 'sha256');
|
||||
|
||||
this.seqHi = 0;
|
||||
this.seqLo = 0;
|
||||
this.seq = 0;
|
||||
|
||||
this.update();
|
||||
|
||||
@ -163,11 +161,8 @@ BIP151Stream.prototype.rekey = function rekey() {
|
||||
|
||||
BIP151Stream.prototype.sequence = function sequence() {
|
||||
// Wrap sequence number a la openssh.
|
||||
if (++this.seqLo === 0x100000000) {
|
||||
this.seqLo = 0;
|
||||
if (++this.seqHi === 0x100000000)
|
||||
this.seqHi = 0;
|
||||
}
|
||||
if (++this.seq === 0x100000000)
|
||||
this.seq = 0;
|
||||
|
||||
this.update();
|
||||
|
||||
@ -183,8 +178,7 @@ BIP151Stream.prototype.sequence = function sequence() {
|
||||
*/
|
||||
|
||||
BIP151Stream.prototype.update = function update() {
|
||||
this.iv.writeUInt32LE(this.seqLo, 0, true);
|
||||
this.iv.writeUInt32LE(this.seqHi, 4, true);
|
||||
this.iv.writeUInt32LE(this.seq, 4, true);
|
||||
return this.iv;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user