Browse Source
This is a standard algorithm for the purposes of padding a block for a block cipher. It will be used in CBC, which in turned will be used with AES for ECIES.patch-2
2 changed files with 35 additions and 0 deletions
@ -0,0 +1,14 @@ |
|||
var Random = require('../random'); |
|||
|
|||
var CBC = function CBC() { |
|||
}; |
|||
|
|||
CBC.pkcs7pad = function(buf, blocksize) { |
|||
var bytesize = blocksize / 8; |
|||
var padbytesize = bytesize - buf.length; |
|||
var pad = new Buffer(padbytesize); |
|||
pad.fill(padbytesize); |
|||
return Buffer.concat([buf, pad]); |
|||
}; |
|||
|
|||
module.exports = CBC; |
@ -0,0 +1,21 @@ |
|||
var should = require('chai').should(); |
|||
var CBC = require('../lib/expmt/cbc'); |
|||
|
|||
describe('CBC', function() { |
|||
|
|||
describe('@pkcs7pad', function() { |
|||
|
|||
it('should pad this 32 bit buffer to 128 bits with the number 128/8 - 32/8', function() { |
|||
var buf = new Buffer(32 / 8); |
|||
buf.fill(0); |
|||
var padbuf = CBC.pkcs7pad(buf, 128); |
|||
padbuf.length.should.equal(128 / 8); |
|||
padbuf[32 / 8].should.equal(128 / 8 - 32 / 8); |
|||
padbuf[32 / 8 + 1].should.equal(128 / 8 - 32 / 8); |
|||
// ...
|
|||
padbuf[32 / 8 + 128 / 8 - 32 / 8 - 1].should.equal(128 / 8 - 32 / 8); |
|||
}); |
|||
|
|||
}); |
|||
|
|||
}); |
Loading…
Reference in new issue