Skip to content

Commit 5adffca

Browse files
committed
merge #78
2 parents fb1d36b + ac58988 commit 5adffca

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ exports.pbkdf2Sync = p.pbkdf2Sync
3939
require('browserify-aes/inject')(exports, module.exports);
4040
require('browserify-sign/inject')(module.exports, exports);
4141
require('diffie-hellman/inject')(exports, module.exports);
42+
require('create-ecdh/inject')(module.exports, exports);
4243

4344
// the least I can do is make error messages for the rest of the node.js/crypto api.
4445
each([
45-
'createCredentials',
46+
'createCredentials', 'publicEncrypt', 'privateDecrypt'
4647
], function (name) {
4748
exports[name] = function () {
4849
error('sorry,', name, 'is not implemented yet')

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"dependencies": {
1919
"browserify-aes": "0.6.0",
2020
"browserify-sign": "2.4.0",
21+
"create-ecdh": "1.0.0",
22+
"diffie-hellman": "2.2.0",
2123
"pbkdf2-compat": "2.0.1",
2224
"ripemd160": "0.2.0",
2325
"diffie-hellman": "2.2.0",

readme.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ Here is the subset that is currently implemented:
2121
* createDiffieHellman
2222
* createSign (rsa, ecdsa)
2323
* createVerify (rsa, ecdsa)
24-
24+
* createECDH (secp256k1)
2525

2626
## todo
2727

2828
these features from node's `crypto` are still unimplemented.
2929

3030
* createCredentials
31+
* publicEncrypt/privateDecrypt
3132

3233
## contributions
3334

test/ecdh.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
var mods = [
2+
'secp256k1'
3+
];
4+
var test = require('tape');
5+
var crypto = require('../');
6+
test('createECDH', function (t) {
7+
mods.forEach(function (mod) {
8+
t.test(mod + ' uncompressed', function (t){
9+
t.plan(2);
10+
var dh1 = crypto.createECDH(mod);
11+
dh1.generateKeys();
12+
var dh2 = crypto.createECDH(mod);
13+
dh2.generateKeys();
14+
var pubk1 = dh1.getPublicKey();
15+
var pubk2 = dh2.getPublicKey();
16+
t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys');
17+
var pub1 = dh1.computeSecret(pubk2).toString('hex');
18+
var pub2 = dh2.computeSecret(pubk1).toString('hex');
19+
t.equals(pub1, pub2, 'equal secrets');
20+
});
21+
t.test(mod + ' compressed', function (t){
22+
t.plan(2);
23+
var dh1 = crypto.createECDH(mod);
24+
dh1.generateKeys();
25+
var dh2 = crypto.createECDH(mod);
26+
dh2.generateKeys();
27+
var pubk1 = dh1.getPublicKey(null, 'compressed');
28+
var pubk2 = dh2.getPublicKey(null, 'compressed');
29+
t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys');
30+
var pub1 = dh1.computeSecret(pubk2).toString('hex');
31+
var pub2 = dh2.computeSecret(pubk1).toString('hex');
32+
t.equals(pub1, pub2, 'equal secrets');
33+
});
34+
t.test(mod + ' set stuff', function (t){
35+
t.plan(5);
36+
var dh1 = crypto.createECDH(mod);
37+
var dh2 = crypto.createECDH(mod);
38+
dh1.generateKeys();
39+
dh2.generateKeys();
40+
dh1.setPrivateKey(dh2.getPrivateKey());
41+
dh1.setPublicKey(dh2.getPublicKey());
42+
var priv1 = dh1.getPrivateKey('hex');
43+
var priv2 = dh2.getPrivateKey('hex');
44+
t.equals(priv1, priv2, 'same private key');
45+
var pubk1 = dh1.getPublicKey();
46+
var pubk2 = dh2.getPublicKey();
47+
t.equals(pubk1.toString('hex'), pubk2.toString('hex'), 'same public keys, uncompressed');
48+
t.equals(dh1.getPublicKey('hex', 'compressed'), dh2.getPublicKey('hex', 'compressed'), 'same public keys compressed');
49+
t.equals(dh1.getPublicKey('hex', 'hybrid'), dh2.getPublicKey('hex', 'hybrid'), 'same public keys hybrid');
50+
var pub1 = dh1.computeSecret(pubk2).toString('hex');
51+
var pub2 = dh2.computeSecret(pubk1).toString('hex');
52+
t.equals(pub1, pub2, 'equal secrets');
53+
});
54+
});
55+
});

0 commit comments

Comments
 (0)