create-ecdh 4.0.1 → 4.0.2
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/.travis.yml +5 -5
- package/browser.js +104 -102
- package/index.js +2 -2
- package/package.json +4 -3
package/.travis.yml
CHANGED
package/browser.js
CHANGED
|
@@ -1,122 +1,124 @@
|
|
|
1
|
-
var elliptic = require('elliptic')
|
|
2
|
-
var BN = require('bn.js')
|
|
1
|
+
var elliptic = require('elliptic')
|
|
2
|
+
var BN = require('bn.js')
|
|
3
3
|
|
|
4
|
-
module.exports = function createECDH(curve) {
|
|
5
|
-
|
|
6
|
-
}
|
|
4
|
+
module.exports = function createECDH (curve) {
|
|
5
|
+
return new ECDH(curve)
|
|
6
|
+
}
|
|
7
7
|
|
|
8
8
|
var aliases = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
9
|
+
secp256k1: {
|
|
10
|
+
name: 'secp256k1',
|
|
11
|
+
byteLength: 32
|
|
12
|
+
},
|
|
13
|
+
secp224r1: {
|
|
14
|
+
name: 'p224',
|
|
15
|
+
byteLength: 28
|
|
16
|
+
},
|
|
17
|
+
prime256v1: {
|
|
18
|
+
name: 'p256',
|
|
19
|
+
byteLength: 32
|
|
20
|
+
},
|
|
21
|
+
prime192v1: {
|
|
22
|
+
name: 'p192',
|
|
23
|
+
byteLength: 24
|
|
24
|
+
},
|
|
25
|
+
ed25519: {
|
|
26
|
+
name: 'ed25519',
|
|
27
|
+
byteLength: 32
|
|
28
|
+
},
|
|
29
|
+
secp384r1: {
|
|
30
|
+
name: 'p384',
|
|
31
|
+
byteLength: 48
|
|
32
|
+
},
|
|
33
|
+
secp521r1: {
|
|
34
|
+
name: 'p521',
|
|
35
|
+
byteLength: 66
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
38
|
|
|
39
|
-
aliases.p224 = aliases.secp224r1
|
|
40
|
-
aliases.p256 = aliases.secp256r1 = aliases.prime256v1
|
|
41
|
-
aliases.p192 = aliases.secp192r1 = aliases.prime192v1
|
|
42
|
-
aliases.p384 = aliases.secp384r1
|
|
43
|
-
aliases.p521 = aliases.secp521r1
|
|
39
|
+
aliases.p224 = aliases.secp224r1
|
|
40
|
+
aliases.p256 = aliases.secp256r1 = aliases.prime256v1
|
|
41
|
+
aliases.p192 = aliases.secp192r1 = aliases.prime192v1
|
|
42
|
+
aliases.p384 = aliases.secp384r1
|
|
43
|
+
aliases.p521 = aliases.secp521r1
|
|
44
44
|
|
|
45
|
-
function ECDH(curve) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
function ECDH (curve) {
|
|
46
|
+
this.curveType = aliases[curve]
|
|
47
|
+
if (!this.curveType) {
|
|
48
|
+
this.curveType = {
|
|
49
|
+
name: curve
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
this.curve = new elliptic.ec(this.curveType.name) // eslint-disable-line new-cap
|
|
53
|
+
this.keys = void 0
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
ECDH.prototype.generateKeys = function (enc, format) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
57
|
+
this.keys = this.curve.genKeyPair()
|
|
58
|
+
return this.getPublicKey(enc, format)
|
|
59
|
+
}
|
|
60
60
|
|
|
61
61
|
ECDH.prototype.computeSecret = function (other, inenc, enc) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
62
|
+
inenc = inenc || 'utf8'
|
|
63
|
+
if (!Buffer.isBuffer(other)) {
|
|
64
|
+
other = new Buffer(other, inenc)
|
|
65
|
+
}
|
|
66
|
+
var otherPub = this.curve.keyFromPublic(other).getPublic()
|
|
67
|
+
var out = otherPub.mul(this.keys.getPrivate()).getX()
|
|
68
|
+
return formatReturnValue(out, enc, this.curveType.byteLength)
|
|
69
|
+
}
|
|
70
70
|
|
|
71
71
|
ECDH.prototype.getPublicKey = function (enc, format) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
72
|
+
var key = this.keys.getPublic(format === 'compressed', true)
|
|
73
|
+
if (format === 'hybrid') {
|
|
74
|
+
if (key[key.length - 1] % 2) {
|
|
75
|
+
key[0] = 7
|
|
76
|
+
} else {
|
|
77
|
+
key[0] = 6
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return formatReturnValue(key, enc)
|
|
81
|
+
}
|
|
82
82
|
|
|
83
83
|
ECDH.prototype.getPrivateKey = function (enc) {
|
|
84
|
-
|
|
85
|
-
}
|
|
84
|
+
return formatReturnValue(this.keys.getPrivate(), enc)
|
|
85
|
+
}
|
|
86
86
|
|
|
87
87
|
ECDH.prototype.setPublicKey = function (pub, enc) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
88
|
+
enc = enc || 'utf8'
|
|
89
|
+
if (!Buffer.isBuffer(pub)) {
|
|
90
|
+
pub = new Buffer(pub, enc)
|
|
91
|
+
}
|
|
92
|
+
this.keys._importPublic(pub)
|
|
93
|
+
return this
|
|
94
|
+
}
|
|
95
95
|
|
|
96
96
|
ECDH.prototype.setPrivateKey = function (priv, enc) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
enc = enc || 'utf8'
|
|
98
|
+
if (!Buffer.isBuffer(priv)) {
|
|
99
|
+
priv = new Buffer(priv, enc)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var _priv = new BN(priv)
|
|
103
|
+
_priv = _priv.toString(16)
|
|
104
|
+
this.keys = this.curve.genKeyPair()
|
|
105
|
+
this.keys._importPrivate(_priv)
|
|
106
|
+
return this
|
|
107
|
+
}
|
|
106
108
|
|
|
107
|
-
function formatReturnValue(bn, enc, len) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
109
|
+
function formatReturnValue (bn, enc, len) {
|
|
110
|
+
if (!Array.isArray(bn)) {
|
|
111
|
+
bn = bn.toArray()
|
|
112
|
+
}
|
|
113
|
+
var buf = new Buffer(bn)
|
|
114
|
+
if (len && buf.length < len) {
|
|
115
|
+
var zeros = new Buffer(len - buf.length)
|
|
116
|
+
zeros.fill(0)
|
|
117
|
+
buf = Buffer.concat([zeros, buf])
|
|
118
|
+
}
|
|
119
|
+
if (!enc) {
|
|
120
|
+
return buf
|
|
121
|
+
} else {
|
|
122
|
+
return buf.toString(enc)
|
|
123
|
+
}
|
|
122
124
|
}
|
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var createECDH = require('crypto').createECDH
|
|
1
|
+
var createECDH = require('crypto').createECDH
|
|
2
2
|
|
|
3
|
-
module.exports = createECDH || require('./browser')
|
|
3
|
+
module.exports = createECDH || require('./browser')
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-ecdh",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "createECDH but browserifiable",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"browser": "browser.js",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "node test.js | tspec"
|
|
8
|
+
"test": "standard && node test.js | tspec"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"homepage": "https://github.com/crypto-browserify/createECDH",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"bn.js": "^4.1.0",
|
|
28
|
-
"elliptic": "^6.0.0"
|
|
28
|
+
"elliptic": "^6.0.0",
|
|
29
|
+
"standard": "^5.4.1"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"tap-spec": "^1.0.1",
|