From 97e40f9ac693364b47d5828a20f339e8ee87f03f Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Mon, 25 Aug 2014 16:38:53 -0700 Subject: [PATCH] rename keybuf -> cipherkeybuf ...since this use of "key" is very different than the public/private key pair that is key.js --- lib/expmt/cbc.js | 18 +++++++++--------- test/test.cbc.js | 32 ++++++++++++++++---------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/expmt/cbc.js b/lib/expmt/cbc.js index 2596e24..e507da4 100644 --- a/lib/expmt/cbc.js +++ b/lib/expmt/cbc.js @@ -1,12 +1,12 @@ var Random = require('../random'); // http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher-block_chaining_.28CBC.29 -var CBC = function CBC(blockcipher, keybuf, ivbuf) { +var CBC = function CBC(blockcipher, cipherkeybuf, ivbuf) { if (!(this instanceof CBC)) - return new CBC(blockcipher, keybuf, ivbuf); + return new CBC(blockcipher, cipherkeybuf, ivbuf); this.blockcipher = blockcipher; - this.keybuf = keybuf; + this.cipherkeybuf = cipherkeybuf; this.ivbuf = ivbuf; }; @@ -26,26 +26,26 @@ CBC.buf2blockbufs = function(buf, blocksize) { return blockbufs; }; -CBC.encrypt = function(messagebuf, ivbuf, blockcipher, keybuf) { +CBC.encrypt = function(messagebuf, ivbuf, blockcipher, cipherkeybuf) { var blocksize = ivbuf.length * 8; var blockbufs = CBC.buf2blockbufs(messagebuf, blocksize); - var encbufs = CBC.encryptblocks(blockbufs, ivbuf, blockcipher, keybuf); + var encbufs = CBC.encryptblocks(blockbufs, ivbuf, blockcipher, cipherkeybuf); var enc = Buffer.concat(encbufs); return enc; }; -CBC.encryptblock = function(blockbuf, ivbuf, blockcipher, keybuf) { +CBC.encryptblock = function(blockbuf, ivbuf, blockcipher, cipherkeybuf) { var xorbuf = CBC.xorbufs(blockbuf, ivbuf); - var encbuf = blockcipher.encrypt(xorbuf, keybuf); + var encbuf = blockcipher.encrypt(xorbuf, cipherkeybuf); return encbuf; }; -CBC.encryptblocks = function(blockbufs, ivbuf, blockcipher, keybuf) { +CBC.encryptblocks = function(blockbufs, ivbuf, blockcipher, cipherkeybuf) { var encbufs = []; for (var i = 0; i < blockbufs.length; i++) { var blockbuf = blockbufs[i]; - var encbuf = CBC.encryptblock(blockbuf, ivbuf, blockcipher, keybuf); + var encbuf = CBC.encryptblock(blockbuf, ivbuf, blockcipher, cipherkeybuf); encbufs.push(encbuf); diff --git a/test/test.cbc.js b/test/test.cbc.js index 7c54ce8..2c4bb41 100644 --- a/test/test.cbc.js +++ b/test/test.cbc.js @@ -44,13 +44,13 @@ describe('CBC', function() { var messagebuf = Buffer.concat([messagebuf1, messagebuf2]); var ivbuf = new Buffer(128 / 8); ivbuf.fill(0x10); - var keybuf = new Buffer(128 / 8); - keybuf.fill(0); + var cipherkeybuf = new Buffer(128 / 8); + cipherkeybuf.fill(0); var blockcipher = {}; - blockcipher.encrypt = function(messagebuf, keybuf) { + blockcipher.encrypt = function(messagebuf, cipherkeybuf) { return messagebuf; }; - var encbuf = CBC.encrypt(messagebuf, ivbuf, blockcipher, keybuf); + var encbuf = CBC.encrypt(messagebuf, ivbuf, blockcipher, cipherkeybuf); encbuf.toString('hex').should.equal('101010101010101010101010101010100000000000000000000000000000000010101010101010101010101010101010'); }); @@ -63,13 +63,13 @@ describe('CBC', function() { messagebuf.fill(0); var ivbuf = new Buffer(128 / 8); ivbuf.fill(0x10); - var keybuf = new Buffer(128 / 8); - keybuf.fill(0); + var cipherkeybuf = new Buffer(128 / 8); + cipherkeybuf.fill(0); var blockcipher = {}; - blockcipher.encrypt = function(messagebuf, keybuf) { + blockcipher.encrypt = function(messagebuf, cipherkeybuf) { return messagebuf; }; - var enc = CBC.encryptblock(messagebuf, ivbuf, blockcipher, keybuf); + var enc = CBC.encryptblock(messagebuf, ivbuf, blockcipher, cipherkeybuf); enc.toString('hex').should.equal(ivbuf.toString('hex')); }); @@ -78,13 +78,13 @@ describe('CBC', function() { messagebuf.fill(0x10); var ivbuf = new Buffer(128 / 8); ivbuf.fill(0x10); - var keybuf = new Buffer(128 / 8); - keybuf.fill(0); + var cipherkeybuf = new Buffer(128 / 8); + cipherkeybuf.fill(0); var blockcipher = {}; - blockcipher.encrypt = function(messagebuf, keybuf) { + blockcipher.encrypt = function(messagebuf, cipherkeybuf) { return messagebuf; }; - var enc = CBC.encryptblock(messagebuf, ivbuf, blockcipher, keybuf); + var enc = CBC.encryptblock(messagebuf, ivbuf, blockcipher, cipherkeybuf); enc.toString('hex').should.equal('00000000000000000000000000000000'); }); @@ -99,13 +99,13 @@ describe('CBC', function() { messagebuf2.fill(0x10); var ivbuf = new Buffer(128 / 8); ivbuf.fill(0x10); - var keybuf = new Buffer(128 / 8); - keybuf.fill(0); + var cipherkeybuf = new Buffer(128 / 8); + cipherkeybuf.fill(0); var blockcipher = {} - blockcipher.encrypt = function(messagebuf, keybuf) { + blockcipher.encrypt = function(messagebuf, cipherkeybuf) { return messagebuf; }; - var encbufs = CBC.encryptblocks([messagebuf1, messagebuf2], ivbuf, blockcipher, keybuf); + var encbufs = CBC.encryptblocks([messagebuf1, messagebuf2], ivbuf, blockcipher, cipherkeybuf); encbufs[0].toString('hex').should.equal('10101010101010101010101010101010'); encbufs[1].toString('hex').should.equal('00000000000000000000000000000000'); });