summaryrefslogtreecommitdiff
path: root/lib/crypto.js
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2014-08-27 18:01:01 +0400
committerFedor Indutny <fedor@indutny.com>2014-08-29 00:27:09 +0400
commit6e453fad87c51dc15327628aa75886d3fbb3fa1c (patch)
treea750ea46af04a3107132a3e21eb6047675a15178 /lib/crypto.js
parentf7d6147e43b8a80a0d627f2034271239db500d9f (diff)
downloadandroid-node-v8-6e453fad87c51dc15327628aa75886d3fbb3fa1c.tar.gz
android-node-v8-6e453fad87c51dc15327628aa75886d3fbb3fa1c.tar.bz2
android-node-v8-6e453fad87c51dc15327628aa75886d3fbb3fa1c.zip
crypto: introduce ECDH
Diffstat (limited to 'lib/crypto.js')
-rw-r--r--lib/crypto.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/crypto.js b/lib/crypto.js
index 828c0f4310..a38ccb77c1 100644
--- a/lib/crypto.js
+++ b/lib/crypto.js
@@ -514,6 +514,53 @@ DiffieHellman.prototype.setPrivateKey = function(key, encoding) {
};
+function ECDH(curve) {
+ if (!util.isString(curve))
+ throw new TypeError('curve should be a string');
+
+ this._handle = new binding.ECDH(curve);
+}
+
+exports.createECDH = function createECDH(curve) {
+ return new ECDH(curve);
+};
+
+ECDH.prototype.computeSecret = DiffieHellman.prototype.computeSecret;
+ECDH.prototype.setPrivateKey = DiffieHellman.prototype.setPrivateKey;
+ECDH.prototype.setPublicKey = DiffieHellman.prototype.setPublicKey;
+ECDH.prototype.getPrivateKey = DiffieHellman.prototype.getPrivateKey;
+
+ECDH.prototype.generateKeys = function generateKeys(encoding, format) {
+ this._handle.generateKeys();
+
+ return this.getPublicKey(encoding, format);
+};
+
+ECDH.prototype.getPublicKey = function getPublicKey(encoding, format) {
+ var f;
+ if (format) {
+ if (typeof format === 'number')
+ f = format;
+ if (format === 'compressed')
+ f = constants.POINT_CONVERSION_COMPRESSED;
+ else if (format === 'hybrid')
+ f = constants.POINT_CONVERSION_HYBRID;
+ // Default
+ else if (format === 'uncompressed')
+ f = constants.POINT_CONVERSION_UNCOMPRESSED;
+ else
+ throw TypeError('Bad format: ' + format);
+ } else {
+ f = constants.POINT_CONVERSION_UNCOMPRESSED;
+ }
+ var key = this._handle.getPublicKey(f);
+ encoding = encoding || exports.DEFAULT_ENCODING;
+ if (encoding && encoding !== 'buffer')
+ key = key.toString(encoding);
+ return key;
+};
+
+
exports.pbkdf2 = function(password,
salt,