Newer eccrypto

This commit is contained in:
Kagami Hiiragi 2015-01-14 02:36:07 +03:00
parent ab01647440
commit 5bb1257adf
4 changed files with 15 additions and 15 deletions

View File

@ -14,17 +14,17 @@ API documentation is available [here](https://bitchan.github.io/bitmessage/docs/
## Feature matrix (both Browser and Node)
- [ ] crypto
- [x] crypto
- [x] SHA-512
- [x] SHA-256
- [x] RIPEMD-160
- [x] PRNG
- [x] ECC keys manipulation
- [x] ECDSA
- [ ] ECDH
- [ ] ECIES
- [ ] AES-256-CBC
- [ ] HMAC-SHA-256
- [x] ECDH
- [x] ECIES
- [x] AES-256-CBC
- [x] HMAC-SHA-256
- [x] Common structures
- [x] message
- [x] var_int

View File

@ -442,14 +442,14 @@ exports.encrypted = {
buf.copy(ephemPublicKey, 33, 54, 86);
// NOTE(Kagami): We do copy instead of slice to protect against
// possible source buffer modification by user.
var cipherText = new Buffer(buf.length - 118);
buf.copy(cipherText, 0, 86, buf.length - 32);
var ciphertext = new Buffer(buf.length - 118);
buf.copy(ciphertext, 0, 86, buf.length - 32);
var mac = new Buffer(32);
buf.copy(mac, 0, buf.length - 32);
return {
iv: iv,
ephemPublicKey: ephemPublicKey,
cipherText: cipherText,
ciphertext: ciphertext,
mac: mac,
};
},
@ -464,15 +464,15 @@ exports.encrypted = {
assert(opts.ephemPublicKey.length === 65, "Bad public key");
assert(opts.mac.length === 32, "Bad MAC");
// 16 + 2 + 2 + 32 + 2 + 32 + ? + 32
var buf = new Buffer(118 + opts.cipherText.length);
var buf = new Buffer(118 + opts.ciphertext.length);
opts.iv.copy(buf);
buf.writeUInt16BE(SECP256K1_TYPE, 16, true); // Curve type
buf.writeUInt16BE(32, 18, true); // Rx length
opts.ephemPublicKey.copy(buf, 20, 1, 33); // Rx
buf.writeUInt16BE(32, 52, true); // Ry length
opts.ephemPublicKey.copy(buf, 54, 33); // Ry
opts.cipherText.copy(buf, 86);
opts.mac.copy(buf, 86 + opts.cipherText.length);
opts.ciphertext.copy(buf, 86);
opts.mac.copy(buf, 86 + opts.ciphertext.length);
return buf;
},
};

View File

@ -50,7 +50,7 @@
"bn.js": "^1.0.0",
"bs58": "^2.0.0",
"buffer-equal": "~0.0.1",
"eccrypto": "^0.1.2",
"eccrypto": "^0.9.0",
"es6-promise": "^2.0.1",
"hash.js": "^1.0.2",
"nan": "^1.4.1",

View File

@ -223,12 +223,12 @@ describe("Common structures", function() {
var iv = Buffer(16);
var ephemPublicKey = Buffer(65);
ephemPublicKey[0] = 0x04;
var cipherText = Buffer("test");
var ciphertext = Buffer("test");
var mac = Buffer(32);
var inopts = {
iv: iv,
ephemPublicKey: ephemPublicKey,
cipherText: cipherText,
ciphertext: ciphertext,
mac: mac,
};
@ -237,7 +237,7 @@ describe("Common structures", function() {
var outopts = encrypted.decode(encoded);
expect(bufferEqual(iv, outopts.iv)).to.be.true;
expect(bufferEqual(ephemPublicKey, outopts.ephemPublicKey)).to.be.true;
expect(cipherText.toString()).to.equal("test");
expect(ciphertext.toString()).to.equal("test");
expect(bufferEqual(mac, outopts.mac)).to.be.true;
});
});