confusingly named SymEnc -> accurately named AESCBC
This will also further discourage use amongst anyone who doesn't understand what this is.
This commit is contained in:
parent
bdb8daaf07
commit
40a2007e18
2
index.js
2
index.js
|
@ -23,9 +23,9 @@ bitcore.Signature = require('./lib/signature');
|
|||
//experimental, nonstandard, or unstable features
|
||||
bitcore.expmt = {};
|
||||
bitcore.expmt.AES = require('./lib/expmt/aes');
|
||||
bitcore.expmt.AESCBC = require('./lib/expmt/aescbc');
|
||||
bitcore.expmt.CBC = require('./lib/expmt/cbc');
|
||||
bitcore.expmt.ECIES = require('./lib/expmt/ecies');
|
||||
bitcore.expmt.SymEnc = require('./lib/expmt/symenc');
|
||||
bitcore.expmt.Stealth = require('./lib/expmt/stealth');
|
||||
|
||||
//dependencies, subject to change
|
||||
|
|
|
@ -3,31 +3,32 @@ var CBC = require('./cbc');
|
|||
var Random = require('../random');
|
||||
var Hash = require('../hash');
|
||||
|
||||
var SymEnc = function SymEnc() {
|
||||
// Symmetric encryption with AES and CBC convenience class
|
||||
var AESCBC = function AESCBC() {
|
||||
};
|
||||
|
||||
SymEnc.encrypt = function(messagebuf, passwordstr) {
|
||||
AESCBC.encrypt = function(messagebuf, passwordstr) {
|
||||
var cipherkeybuf = Hash.sha256(new Buffer(passwordstr));
|
||||
return SymEnc.encryptCipherkey(messagebuf, cipherkeybuf);
|
||||
return AESCBC.encryptCipherkey(messagebuf, cipherkeybuf);
|
||||
};
|
||||
|
||||
SymEnc.decrypt = function(encbuf, passwordstr) {
|
||||
AESCBC.decrypt = function(encbuf, passwordstr) {
|
||||
var cipherkeybuf = Hash.sha256(new Buffer(passwordstr));
|
||||
return SymEnc.decryptCipherkey(encbuf, cipherkeybuf);
|
||||
return AESCBC.decryptCipherkey(encbuf, cipherkeybuf);
|
||||
};
|
||||
|
||||
SymEnc.encryptCipherkey = function(messagebuf, cipherkeybuf, ivbuf) {
|
||||
AESCBC.encryptCipherkey = function(messagebuf, cipherkeybuf, ivbuf) {
|
||||
ivbuf = ivbuf || Random.getRandomBuffer(128 / 8);
|
||||
var ctbuf = CBC.encrypt(messagebuf, ivbuf, AES, cipherkeybuf);
|
||||
var encbuf = Buffer.concat([ivbuf, ctbuf]);
|
||||
return encbuf;
|
||||
};
|
||||
|
||||
SymEnc.decryptCipherkey = function(encbuf, cipherkeybuf) {
|
||||
AESCBC.decryptCipherkey = function(encbuf, cipherkeybuf) {
|
||||
var ivbuf = encbuf.slice(0, 128 / 8);
|
||||
var ctbuf = encbuf.slice(128 / 8);
|
||||
var messagebuf = CBC.decrypt(ctbuf, ivbuf, AES, cipherkeybuf);
|
||||
return messagebuf;
|
||||
};
|
||||
|
||||
module.exports = SymEnc;
|
||||
module.exports = AESCBC;
|
|
@ -1,4 +1,4 @@
|
|||
var SymEnc = require('./symenc');
|
||||
var AESCBC = require('./aescbc');
|
||||
var Key = require('../key');
|
||||
var Point = require('../point');
|
||||
var Hash = require('../hash');
|
||||
|
@ -22,7 +22,7 @@ ECIES.encrypt = function(messagebuf, tokey, fromkey, ivbuf) {
|
|||
var kEkM = Hash.sha512(Sbuf);
|
||||
var kE = kEkM.slice(0, 32);
|
||||
var kM = kEkM.slice(32, 64);
|
||||
var c = SymEnc.encryptCipherkey(messagebuf, kE, ivbuf);
|
||||
var c = AESCBC.encryptCipherkey(messagebuf, kE, ivbuf);
|
||||
var d = Hash.sha256hmac(c, kM);
|
||||
var encbuf = Buffer.concat([Rbuf, c, d]);
|
||||
return encbuf;
|
||||
|
@ -45,7 +45,7 @@ ECIES.decrypt = function(encbuf, tokey) {
|
|||
var d2 = Hash.sha256hmac(c, kM);
|
||||
if (d.toString('hex') !== d2.toString('hex'))
|
||||
throw new Error('Invalid checksum');
|
||||
var messagebuf = SymEnc.decryptCipherkey(c, kE);
|
||||
var messagebuf = AESCBC.decryptCipherkey(c, kE);
|
||||
return messagebuf;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var should = require('chai').should();
|
||||
var SymEnc = require('../lib/expmt/symenc');
|
||||
var AESCBC = require('../lib/expmt/aescbc');
|
||||
|
||||
describe('SymEnc', function() {
|
||||
describe('AESCBC', function() {
|
||||
|
||||
describe('@encrypt', function() {
|
||||
|
||||
|
@ -9,7 +9,7 @@ describe('SymEnc', function() {
|
|||
var password = "password";
|
||||
var messagebuf = new Buffer(128 / 8 - 1);
|
||||
messagebuf.fill(0);
|
||||
var encbuf = SymEnc.encrypt(messagebuf, password);
|
||||
var encbuf = AESCBC.encrypt(messagebuf, password);
|
||||
encbuf.length.should.equal(128 / 8 + 128 / 8);
|
||||
});
|
||||
|
||||
|
@ -21,8 +21,8 @@ describe('SymEnc', function() {
|
|||
var password = "password";
|
||||
var messagebuf = new Buffer(128 / 8 - 1);
|
||||
messagebuf.fill(0);
|
||||
var encbuf = SymEnc.encrypt(messagebuf, password);
|
||||
var messagebuf2 = SymEnc.decrypt(encbuf, password);
|
||||
var encbuf = AESCBC.encrypt(messagebuf, password);
|
||||
var messagebuf2 = AESCBC.decrypt(encbuf, password);
|
||||
messagebuf2.toString('hex').should.equal(messagebuf.toString('hex'));
|
||||
});
|
||||
|
||||
|
@ -37,7 +37,7 @@ describe('SymEnc', function() {
|
|||
ivbuf.fill(0);
|
||||
var messagebuf = new Buffer(128 / 8 - 1);
|
||||
messagebuf.fill(0);
|
||||
var encbuf = SymEnc.encryptCipherkey(messagebuf, cipherkeybuf, ivbuf);
|
||||
var encbuf = AESCBC.encryptCipherkey(messagebuf, cipherkeybuf, ivbuf);
|
||||
encbuf.length.should.equal(128 / 8 + 128 / 8);
|
||||
});
|
||||
|
||||
|
@ -48,7 +48,7 @@ describe('SymEnc', function() {
|
|||
ivbuf.fill(0);
|
||||
var messagebuf = new Buffer(128 / 8);
|
||||
messagebuf.fill(0);
|
||||
var encbuf = SymEnc.encryptCipherkey(messagebuf, cipherkeybuf, ivbuf);
|
||||
var encbuf = AESCBC.encryptCipherkey(messagebuf, cipherkeybuf, ivbuf);
|
||||
encbuf.length.should.equal(128 / 8 + 128 / 8 + 128 / 8);
|
||||
});
|
||||
|
||||
|
@ -63,8 +63,8 @@ describe('SymEnc', function() {
|
|||
ivbuf.fill(0);
|
||||
var messagebuf = new Buffer(128 / 8);
|
||||
messagebuf.fill(0);
|
||||
var encbuf = SymEnc.encryptCipherkey(messagebuf, cipherkeybuf, ivbuf);
|
||||
var messagebuf2 = SymEnc.decryptCipherkey(encbuf, cipherkeybuf);
|
||||
var encbuf = AESCBC.encryptCipherkey(messagebuf, cipherkeybuf, ivbuf);
|
||||
var messagebuf2 = AESCBC.decryptCipherkey(encbuf, cipherkeybuf);
|
||||
messagebuf2.toString('hex').should.equal(messagebuf.toString('hex'));
|
||||
});
|
||||
|
Loading…
Reference in New Issue