[Pkg-javascript-commits] [node-diffie-hellman] 08/88: finish up
Bastien Roucariès
rouca at moszumanska.debian.org
Thu May 4 10:19:12 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-diffie-hellman.
commit de5c8132359dbf07182576e2dcdc771ae412e41f
Author: Calvin Metcalf <cmetcalf at appgeo.com>
Date: Tue Nov 4 10:22:18 2014 -0500
finish up
---
dh.js | 4 ++--
inject.js | 9 ++++++---
test.js | 9 ++++++---
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/dh.js b/dh.js
index 7cafdcd..69bff59 100644
--- a/dh.js
+++ b/dh.js
@@ -23,7 +23,7 @@ DH.prototype.computeSecret = function (other) {
other = other.toRed(this._prime);
var secret = other.redPow(this._priv).fromRed();
return new Buffer(secret.toArray());
-}
+};
DH.prototype.getPublicKey = function (enc) {
return returnValue(this._pub, enc);
};
@@ -43,7 +43,7 @@ DH.prototype.setGenerator = function (gen, enc) {
gen = new Buffer(gen, enc);
}
this._gen = new BN(gen);
-}
+};
DH.prototype.setPublicKey = function (pub, enc) {
enc = enc || 'utf8';
if (!Buffer.isBuffer(pub)) {
diff --git a/inject.js b/inject.js
index 536fadd..149c285 100644
--- a/inject.js
+++ b/inject.js
@@ -2,8 +2,11 @@ var primes = require('./primes.json');
var DH = require('./dh');
module.exports = function (crypto, exports) {
exports.getDiffieHellman = function (mod) {
+ if (mod === 'modp17' || mod === 'modp18') {
+ throw new Error(mod + ' is not implimented');
+ }
return new DH(new Buffer(primes[mod].prime, 'hex'), crypto);
- }
+ };
exports.createDiffieHellman = function (prime, enc) {
if (typeof prime === 'number') {
throw new Error('generating primes not implimented');
@@ -13,5 +16,5 @@ module.exports = function (crypto, exports) {
prime = new Buffer(prime, enc);
}
return new DH(prime, crypto);
- }
-}
\ No newline at end of file
+ };
+};
\ No newline at end of file
diff --git a/test.js b/test.js
index f072fc0..62e482a 100644
--- a/test.js
+++ b/test.js
@@ -9,15 +9,18 @@ var mods = [
function run(i) {
mods.forEach(function (mod) {
test(mod + ' run ' + i, function (t){
- t.plan(2);
+ t.plan(3);
var dh1 = nodeCrypto.getDiffieHellman(mod);
var p1 = dh1.getPrime().toString('hex');
dh1.generateKeys();
var dh2 = myCrypto.getDiffieHellman(mod);
var p2 = dh2.getPrime().toString('hex');
dh2.generateKeys();
- t.equals(p1, p2, 'equal primes')
- var pub1 = dh1.computeSecret(dh2.getPublicKey()).toString('hex');
+ t.equals(p1, p2, 'equal primes');
+ var pubk1 = dh1.getPublicKey();
+ var pubk2 = dh2.getPublicKey();
+ t.notEquals(pubk1, pubk2, 'diff public keys');
+ var pub1 = dh1.computeSecret(pubk2).toString('hex');
var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex');
t.equals(pub1, pub2, 'equal secrets');
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-diffie-hellman.git
More information about the Pkg-javascript-commits
mailing list