Newer eccrypto
This commit is contained in:
parent
ab01647440
commit
5bb1257adf
10
README.md
10
README.md
|
@ -14,17 +14,17 @@ API documentation is available [here](https://bitchan.github.io/bitmessage/docs/
|
||||||
|
|
||||||
## Feature matrix (both Browser and Node)
|
## Feature matrix (both Browser and Node)
|
||||||
|
|
||||||
- [ ] crypto
|
- [x] crypto
|
||||||
- [x] SHA-512
|
- [x] SHA-512
|
||||||
- [x] SHA-256
|
- [x] SHA-256
|
||||||
- [x] RIPEMD-160
|
- [x] RIPEMD-160
|
||||||
- [x] PRNG
|
- [x] PRNG
|
||||||
- [x] ECC keys manipulation
|
- [x] ECC keys manipulation
|
||||||
- [x] ECDSA
|
- [x] ECDSA
|
||||||
- [ ] ECDH
|
- [x] ECDH
|
||||||
- [ ] ECIES
|
- [x] ECIES
|
||||||
- [ ] AES-256-CBC
|
- [x] AES-256-CBC
|
||||||
- [ ] HMAC-SHA-256
|
- [x] HMAC-SHA-256
|
||||||
- [x] Common structures
|
- [x] Common structures
|
||||||
- [x] message
|
- [x] message
|
||||||
- [x] var_int
|
- [x] var_int
|
||||||
|
|
|
@ -442,14 +442,14 @@ exports.encrypted = {
|
||||||
buf.copy(ephemPublicKey, 33, 54, 86);
|
buf.copy(ephemPublicKey, 33, 54, 86);
|
||||||
// NOTE(Kagami): We do copy instead of slice to protect against
|
// NOTE(Kagami): We do copy instead of slice to protect against
|
||||||
// possible source buffer modification by user.
|
// possible source buffer modification by user.
|
||||||
var cipherText = new Buffer(buf.length - 118);
|
var ciphertext = new Buffer(buf.length - 118);
|
||||||
buf.copy(cipherText, 0, 86, buf.length - 32);
|
buf.copy(ciphertext, 0, 86, buf.length - 32);
|
||||||
var mac = new Buffer(32);
|
var mac = new Buffer(32);
|
||||||
buf.copy(mac, 0, buf.length - 32);
|
buf.copy(mac, 0, buf.length - 32);
|
||||||
return {
|
return {
|
||||||
iv: iv,
|
iv: iv,
|
||||||
ephemPublicKey: ephemPublicKey,
|
ephemPublicKey: ephemPublicKey,
|
||||||
cipherText: cipherText,
|
ciphertext: ciphertext,
|
||||||
mac: mac,
|
mac: mac,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -464,15 +464,15 @@ exports.encrypted = {
|
||||||
assert(opts.ephemPublicKey.length === 65, "Bad public key");
|
assert(opts.ephemPublicKey.length === 65, "Bad public key");
|
||||||
assert(opts.mac.length === 32, "Bad MAC");
|
assert(opts.mac.length === 32, "Bad MAC");
|
||||||
// 16 + 2 + 2 + 32 + 2 + 32 + ? + 32
|
// 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);
|
opts.iv.copy(buf);
|
||||||
buf.writeUInt16BE(SECP256K1_TYPE, 16, true); // Curve type
|
buf.writeUInt16BE(SECP256K1_TYPE, 16, true); // Curve type
|
||||||
buf.writeUInt16BE(32, 18, true); // Rx length
|
buf.writeUInt16BE(32, 18, true); // Rx length
|
||||||
opts.ephemPublicKey.copy(buf, 20, 1, 33); // Rx
|
opts.ephemPublicKey.copy(buf, 20, 1, 33); // Rx
|
||||||
buf.writeUInt16BE(32, 52, true); // Ry length
|
buf.writeUInt16BE(32, 52, true); // Ry length
|
||||||
opts.ephemPublicKey.copy(buf, 54, 33); // Ry
|
opts.ephemPublicKey.copy(buf, 54, 33); // Ry
|
||||||
opts.cipherText.copy(buf, 86);
|
opts.ciphertext.copy(buf, 86);
|
||||||
opts.mac.copy(buf, 86 + opts.cipherText.length);
|
opts.mac.copy(buf, 86 + opts.ciphertext.length);
|
||||||
return buf;
|
return buf;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
"bn.js": "^1.0.0",
|
"bn.js": "^1.0.0",
|
||||||
"bs58": "^2.0.0",
|
"bs58": "^2.0.0",
|
||||||
"buffer-equal": "~0.0.1",
|
"buffer-equal": "~0.0.1",
|
||||||
"eccrypto": "^0.1.2",
|
"eccrypto": "^0.9.0",
|
||||||
"es6-promise": "^2.0.1",
|
"es6-promise": "^2.0.1",
|
||||||
"hash.js": "^1.0.2",
|
"hash.js": "^1.0.2",
|
||||||
"nan": "^1.4.1",
|
"nan": "^1.4.1",
|
||||||
|
|
6
test.js
6
test.js
|
@ -223,12 +223,12 @@ describe("Common structures", function() {
|
||||||
var iv = Buffer(16);
|
var iv = Buffer(16);
|
||||||
var ephemPublicKey = Buffer(65);
|
var ephemPublicKey = Buffer(65);
|
||||||
ephemPublicKey[0] = 0x04;
|
ephemPublicKey[0] = 0x04;
|
||||||
var cipherText = Buffer("test");
|
var ciphertext = Buffer("test");
|
||||||
var mac = Buffer(32);
|
var mac = Buffer(32);
|
||||||
var inopts = {
|
var inopts = {
|
||||||
iv: iv,
|
iv: iv,
|
||||||
ephemPublicKey: ephemPublicKey,
|
ephemPublicKey: ephemPublicKey,
|
||||||
cipherText: cipherText,
|
ciphertext: ciphertext,
|
||||||
mac: mac,
|
mac: mac,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ describe("Common structures", function() {
|
||||||
var outopts = encrypted.decode(encoded);
|
var outopts = encrypted.decode(encoded);
|
||||||
expect(bufferEqual(iv, outopts.iv)).to.be.true;
|
expect(bufferEqual(iv, outopts.iv)).to.be.true;
|
||||||
expect(bufferEqual(ephemPublicKey, outopts.ephemPublicKey)).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;
|
expect(bufferEqual(mac, outopts.mac)).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user