create-ecdh 2.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.npmignore ADDED
@@ -0,0 +1 @@
1
+ test.js
package/browser.js CHANGED
@@ -25,12 +25,22 @@ var aliases = {
25
25
  ed25519: {
26
26
  name: 'ed25519',
27
27
  byteLength: 32
28
+ },
29
+ secp384r1: {
30
+ name: 'p384',
31
+ byteLength: 48
32
+ },
33
+ secp521r1: {
34
+ name: 'p521',
35
+ byteLength: 66
28
36
  }
29
37
  };
30
38
 
31
39
  aliases.p224 = aliases.secp224r1;
32
40
  aliases.p256 = aliases.secp256r1 = aliases.prime256v1;
33
41
  aliases.p192 = aliases.secp192r1 = aliases.prime192v1;
42
+ aliases.p384 = aliases.secp384r1;
43
+ aliases.p521 = aliases.secp521r1;
34
44
 
35
45
  function ECDH(curve) {
36
46
  this.curveType = aliases[curve];
@@ -53,9 +63,7 @@ ECDH.prototype.computeSecret = function (other, inenc, enc) {
53
63
  if (!Buffer.isBuffer(other)) {
54
64
  other = new Buffer(other, inenc);
55
65
  }
56
- other = new BN(other);
57
- other = other.toString(16);
58
- var otherPub = this.curve.keyPair(other, 'hex').getPublic();
66
+ var otherPub = this.curve.keyFromPublic(other).getPublic();
59
67
  var out = otherPub.mul(this.keys.getPrivate()).getX();
60
68
  return formatReturnValue(out, enc, this.curveType.byteLength);
61
69
  };
@@ -81,9 +89,7 @@ ECDH.prototype.setPublicKey = function (pub, enc) {
81
89
  if (!Buffer.isBuffer(pub)) {
82
90
  pub = new Buffer(pub, enc);
83
91
  }
84
- var pkey = new BN(pub);
85
- pkey = pkey.toArray();
86
- this.keys._importPublicHex(pkey);
92
+ this.keys._importPublic(pub);
87
93
  return this;
88
94
  };
89
95
 
@@ -113,4 +119,4 @@ function formatReturnValue(bn, enc, len) {
113
119
  } else {
114
120
  return buf.toString(enc);
115
121
  }
116
- }
122
+ }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "create-ecdh",
3
- "version": "2.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "createECDH but browserifiable",
5
5
  "main": "index.js",
6
+ "browser": "browser.js",
6
7
  "scripts": {
7
8
  "test": "node test.js | tspec"
8
9
  },
@@ -23,8 +24,8 @@
23
24
  },
24
25
  "homepage": "https://github.com/crypto-browserify/createECDH",
25
26
  "dependencies": {
26
- "bn.js": "^1.0.0",
27
- "elliptic": "^1.0.0"
27
+ "bn.js": "^4.1.0",
28
+ "elliptic": "^6.0.0"
28
29
  },
29
30
  "devDependencies": {
30
31
  "tap-spec": "^1.0.1",
package/readme.md CHANGED
@@ -1,4 +1,4 @@
1
1
  createECDH [![Build Status](https://travis-ci.org/crypto-browserify/createECDH.svg)](https://travis-ci.org/crypto-browserify/createECDH)
2
2
  ====
3
3
 
4
- In io.js or node >= 0.11 this module is just a shortcut to crypto.createECDH. In node <= 0.11 or the browser this is a pure JavaScript implimentation, more specifically a wrapper around [elliptic](https://github.com/indutny/elliptic), to give it the same API as node. `secp256k1`, `secp224r1` (aka p-224), `prime256v1` (aka p-256, secp256r1), `prime192v1` (aka p-192, secp192r1) curves all work in both this library and node (though only the highlighted name will work in node).
4
+ In io.js or node >= 0.11 this module is just a shortcut to crypto.createECDH. In node <= 0.11 or the browser this is a pure JavaScript implimentation, more specifically a wrapper around [elliptic](https://github.com/indutny/elliptic), to give it the same API as node. `secp256k1`, `secp224r1` (aka p224), `prime256v1` (aka p256, secp256r1), `prime192v1` (aka p192, secp192r1), `secp384r1` (aka p384), `secp521r1` (aka p521) curves all work in both this library and node (though only the highlighted name will work in node).
package/test.js DELETED
@@ -1,67 +0,0 @@
1
- var test = require('tape');
2
- var nodeCrypto = require('./browser');
3
- var myCrypto = require('./browser');
4
-
5
- var mods = [
6
- 'secp256k1',
7
- 'secp224r1',
8
- 'prime256v1',
9
- 'prime192v1'
10
- ];
11
-
12
- function run(i) {
13
- mods.forEach(function (mod) {
14
- test(mod + ' run ' + i + ' uncompressed', function (t){
15
- t.plan(2);
16
- var dh1 = nodeCrypto(mod);
17
- dh1.generateKeys();
18
- var dh2 = myCrypto(mod);
19
- dh2.generateKeys();
20
- var pubk1 = dh1.getPublicKey();
21
- var pubk2 = dh2.getPublicKey();
22
- t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys');
23
- var pub1 = dh1.computeSecret(pubk2).toString('hex');
24
- var pub2 = dh2.computeSecret(pubk1).toString('hex');
25
- t.equals(pub1, pub2, 'equal secrets');
26
- });
27
- test(mod + ' run ' + i + ' compressed', function (t){
28
- t.plan(2);
29
- var dh1 = nodeCrypto(mod);
30
- dh1.generateKeys();
31
- var dh2 = myCrypto(mod);
32
- dh2.generateKeys();
33
- var pubk1 = dh1.getPublicKey(null, 'compressed');
34
- var pubk2 = dh2.getPublicKey(null, 'compressed');
35
- t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys');
36
- var pub1 = dh1.computeSecret(pubk2).toString('hex');
37
- var pub2 = dh2.computeSecret(pubk1).toString('hex');
38
- t.equals(pub1, pub2, 'equal secrets');
39
- });
40
- test(mod + ' run ' + i + ' set stuff', function (t){
41
- t.plan(5);
42
- var dh1 = nodeCrypto(mod);
43
- var dh2 = myCrypto(mod);
44
- dh1.generateKeys();
45
- dh2.generateKeys();
46
- dh1.setPrivateKey(dh2.getPrivateKey());
47
- dh1.setPublicKey(dh2.getPublicKey());
48
- var priv1 = dh1.getPrivateKey('hex');
49
- var priv2 = dh2.getPrivateKey('hex');
50
- t.equals(priv1, priv2, 'same private key');
51
- var pubk1 = dh1.getPublicKey();
52
- var pubk2 = dh2.getPublicKey();
53
- t.equals(pubk1.toString('hex'), pubk2.toString('hex'), 'same public keys, uncompressed');
54
- t.equals(dh1.getPublicKey('hex', 'compressed'), dh2.getPublicKey('hex', 'compressed'), 'same public keys compressed');
55
- t.equals(dh1.getPublicKey('hex', 'hybrid'), dh2.getPublicKey('hex', 'hybrid'), 'same public keys hybrid');
56
- var pub1 = dh1.computeSecret(pubk2).toString('hex');
57
- var pub2 = dh2.computeSecret(pubk1).toString('hex');
58
- t.equals(pub1, pub2, 'equal secrets');
59
- });
60
- });
61
- }
62
-
63
-
64
- var i = 0;
65
- while (++i < 100) {
66
- run(i);
67
- }