From 5bb1257adf780a4d7a8bdc80a6c2adf05ae1d57b Mon Sep 17 00:00:00 2001 From: Kagami Hiiragi Date: Wed, 14 Jan 2015 02:36:07 +0300 Subject: [PATCH] Newer eccrypto --- README.md | 10 +++++----- lib/structs.js | 12 ++++++------ package.json | 2 +- test.js | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c1bc748..673c324 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/structs.js b/lib/structs.js index 20ae40d..625c21d 100644 --- a/lib/structs.js +++ b/lib/structs.js @@ -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; }, }; diff --git a/package.json b/package.json index 25b95cb..1a3794e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test.js b/test.js index 29f8828..ffe4884 100644 --- a/test.js +++ b/test.js @@ -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; }); });