This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+1
View File
@@ -0,0 +1 @@
test.js
+7
View File
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "0.10"
- "0.11"
- "0.12"
- "iojs"
+122
View File
@@ -0,0 +1,122 @@
var elliptic = require('elliptic');
var BN = require('bn.js');
module.exports = function createECDH(curve) {
return new ECDH(curve);
};
var aliases = {
secp256k1: {
name: 'secp256k1',
byteLength: 32
},
secp224r1: {
name: 'p224',
byteLength: 28
},
prime256v1: {
name: 'p256',
byteLength: 32
},
prime192v1: {
name: 'p192',
byteLength: 24
},
ed25519: {
name: 'ed25519',
byteLength: 32
},
secp384r1: {
name: 'p384',
byteLength: 48
},
secp521r1: {
name: 'p521',
byteLength: 66
}
};
aliases.p224 = aliases.secp224r1;
aliases.p256 = aliases.secp256r1 = aliases.prime256v1;
aliases.p192 = aliases.secp192r1 = aliases.prime192v1;
aliases.p384 = aliases.secp384r1;
aliases.p521 = aliases.secp521r1;
function ECDH(curve) {
this.curveType = aliases[curve];
if (!this.curveType ) {
this.curveType = {
name: curve
};
}
this.curve = new elliptic.ec(this.curveType.name);
this.keys = void 0;
}
ECDH.prototype.generateKeys = function (enc, format) {
this.keys = this.curve.genKeyPair();
return this.getPublicKey(enc, format);
};
ECDH.prototype.computeSecret = function (other, inenc, enc) {
inenc = inenc || 'utf8';
if (!Buffer.isBuffer(other)) {
other = new Buffer(other, inenc);
}
var otherPub = this.curve.keyFromPublic(other).getPublic();
var out = otherPub.mul(this.keys.getPrivate()).getX();
return formatReturnValue(out, enc, this.curveType.byteLength);
};
ECDH.prototype.getPublicKey = function (enc, format) {
var key = this.keys.getPublic(format === 'compressed', true);
if (format === 'hybrid') {
if (key[key.length - 1] % 2) {
key[0] = 7;
} else {
key [0] = 6;
}
}
return formatReturnValue(key, enc);
};
ECDH.prototype.getPrivateKey = function (enc) {
return formatReturnValue(this.keys.getPrivate(), enc);
};
ECDH.prototype.setPublicKey = function (pub, enc) {
enc = enc || 'utf8';
if (!Buffer.isBuffer(pub)) {
pub = new Buffer(pub, enc);
}
this.keys._importPublic(pub);
return this;
};
ECDH.prototype.setPrivateKey = function (priv, enc) {
enc = enc || 'utf8';
if (!Buffer.isBuffer(priv)) {
priv = new Buffer(priv, enc);
}
var _priv = new BN(priv);
_priv = _priv.toString(16);
this.keys._importPrivate(_priv);
return this;
};
function formatReturnValue(bn, enc, len) {
if (!Array.isArray(bn)) {
bn = bn.toArray();
}
var buf = new Buffer(bn);
if (len && buf.length < len) {
var zeros = new Buffer(len - buf.length);
zeros.fill(0);
buf = Buffer.concat([zeros, buf]);
}
if (!enc) {
return buf;
} else {
return buf.toString(enc);
}
}
+3
View File
@@ -0,0 +1,3 @@
var createECDH = require('crypto').createECDH;
module.exports = createECDH || require('./browser');
+108
View File
@@ -0,0 +1,108 @@
{
"_args": [
[
{
"raw": "create-ecdh@^4.0.0",
"scope": null,
"escapedName": "create-ecdh",
"name": "create-ecdh",
"rawSpec": "^4.0.0",
"spec": ">=4.0.0 <5.0.0",
"type": "range"
},
"c:\\xampp\\htdocs\\laravel\\node_modules\\crypto-browserify"
]
],
"_from": "create-ecdh@>=4.0.0 <5.0.0",
"_id": "create-ecdh@4.0.0",
"_inCache": true,
"_location": "/create-ecdh",
"_nodeVersion": "4.2.1",
"_npmUser": {
"name": "cwmma",
"email": "calvin.metcalf@gmail.com"
},
"_npmVersion": "2.9.0",
"_phantomChildren": {},
"_requested": {
"raw": "create-ecdh@^4.0.0",
"scope": null,
"escapedName": "create-ecdh",
"name": "create-ecdh",
"rawSpec": "^4.0.0",
"spec": ">=4.0.0 <5.0.0",
"type": "range"
},
"_requiredBy": [
"/crypto-browserify"
],
"_resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.0.tgz",
"_shasum": "888c723596cdf7612f6498233eebd7a35301737d",
"_shrinkwrap": null,
"_spec": "create-ecdh@^4.0.0",
"_where": "c:\\xampp\\htdocs\\laravel\\node_modules\\crypto-browserify",
"author": {
"name": "Calvin Metcalf"
},
"browser": "browser.js",
"bugs": {
"url": "https://github.com/crypto-browserify/createECDH/issues"
},
"dependencies": {
"bn.js": "^4.1.0",
"elliptic": "^6.0.0"
},
"description": "createECDH but browserifiable",
"devDependencies": {
"tap-spec": "^1.0.1",
"tape": "^3.0.1"
},
"directories": {},
"dist": {
"shasum": "888c723596cdf7612f6498233eebd7a35301737d",
"tarball": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.0.tgz"
},
"gitHead": "115f7b6bad56934285b9015575e1b43f23148a8a",
"homepage": "https://github.com/crypto-browserify/createECDH",
"keywords": [
"diffie",
"hellman",
"diffiehellman",
"ECDH"
],
"license": "MIT",
"main": "index.js",
"maintainers": [
{
"name": "cwmma",
"email": "calvin.metcalf@gmail.com"
},
{
"name": "dcousens",
"email": "email@dcousens.com"
},
{
"name": "dominictarr",
"email": "dominic.tarr@gmail.com"
},
{
"name": "jprichardson",
"email": "jprichardson@gmail.com"
},
{
"name": "indutny",
"email": "fedor@indutny.com"
}
],
"name": "create-ecdh",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/crypto-browserify/createECDH.git"
},
"scripts": {
"test": "node test.js | tspec"
},
"version": "4.0.0"
}
+4
View File
@@ -0,0 +1,4 @@
createECDH [![Build Status](https://travis-ci.org/crypto-browserify/createECDH.svg)](https://travis-ci.org/crypto-browserify/createECDH)
====
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).