decrypt blocks

This commit is contained in:
Ryan X. Charles 2014-08-25 20:38:39 -07:00
parent eddeb60d7d
commit a6e74666c8
2 changed files with 27 additions and 1 deletions

View File

@ -74,7 +74,7 @@ CBC.decryptblocks = function(encbufs, ivbuf, blockcipher, cipherkeybuf) {
ivbuf = encbuf;
}
return encbufs;
return blockbufs;
};
CBC.pkcs7pad = function(buf, blocksize) {

View File

@ -135,6 +135,32 @@ describe('CBC', function() {
});
describe('@decryptblocks', function() {
it('should decrypt encrypted blocks', function() {
var messagebuf1 = new Buffer(128 / 8);
messagebuf1.fill(0);
var messagebuf2 = new Buffer(128 / 8);
messagebuf2.fill(0x10);
var ivbuf = new Buffer(128 / 8);
ivbuf.fill(0x10);
var cipherkeybuf = new Buffer(128 / 8);
cipherkeybuf.fill(0);
var blockcipher = {}
blockcipher.encrypt = function(messagebuf, cipherkeybuf) {
return messagebuf;
};
blockcipher.decrypt = function(messagebuf, cipherkeybuf) {
return messagebuf;
};
var encbufs = CBC.encryptblocks([messagebuf1, messagebuf2], ivbuf, blockcipher, cipherkeybuf);
var bufs = CBC.decryptblocks(encbufs, ivbuf, blockcipher, cipherkeybuf);
bufs[0].toString('hex').should.equal(messagebuf1.toString('hex'));
bufs[1].toString('hex').should.equal(messagebuf2.toString('hex'));
});
});
describe('@pkcs7pad', function() {
it('should pad this 32 bit buffer to 128 bits with the number 128/8 - 32/8', function() {