[Pkg-javascript-commits] [node-diffie-hellman] 07/88: Revert "bench"

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 54dc2a28b5ff73a61c261b721b0665a349b2c67d
Author: Calvin Metcalf <cmetcalf at appgeo.com>
Date:   Tue Nov 4 10:05:56 2014 -0500

    Revert "bench"
    
    This reverts commit 3a4f943ef0070a8146c0aa8b75e20747acc24040.
---
 dh.js     | 11 ++++-------
 inject.js |  7 ++++---
 test.js   | 39 +++++++++++++++++----------------------
 3 files changed, 25 insertions(+), 32 deletions(-)

diff --git a/dh.js b/dh.js
index c5ff7a6..7cafdcd 100644
--- a/dh.js
+++ b/dh.js
@@ -1,14 +1,11 @@
 var BN = require('bn.js');
-var primes = require('./primes.json');
-Object.keys(primes).forEach(function (mod){
-	BN.primes[mod] = new BN.MPrime(mod, new BN(new Buffer(primes[mod].prime, 'hex')));
-});
+
 module.exports = DH;
 
 function DH(prime, crypto) {
 	this.setGenerator(new Buffer([2]));
-	this.__prime = BN._prime(prime);
-	this._prime = BN.red(this.__prime);
+	this.__prime = new BN(prime);
+	this._prime = BN.mont(this.__prime);
 	this._pub = void 0;
 	this._priv = void 0;
 	this._makeNum = function makeNum() {
@@ -35,7 +32,7 @@ DH.prototype.getPrivateKey = function (enc) {
 };
 
 DH.prototype.getPrime = function (enc) {
-	return returnValue(this.__prime.p, enc);
+	return returnValue(this.__prime, enc);
 };
 DH.prototype.getGenerator = function (enc) {
 	return returnValue(this._gen, enc);
diff --git a/inject.js b/inject.js
index 7c72332..536fadd 100644
--- a/inject.js
+++ b/inject.js
@@ -1,8 +1,9 @@
+var primes = require('./primes.json');
 var DH = require('./dh');
 module.exports = function (crypto, exports) {
 	exports.getDiffieHellman = function (mod) {
-		return new DH(mod, crypto);
-	};
+		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');
@@ -12,5 +13,5 @@ module.exports = function (crypto, exports) {
 			prime = new Buffer(prime, enc);
 		}
 		return new DH(prime, crypto);
-	};
+	}
 }
\ No newline at end of file
diff --git a/test.js b/test.js
index 617d876..f072fc0 100644
--- a/test.js
+++ b/test.js
@@ -7,28 +7,23 @@ var mods = [
 ];
 
 function run(i) {
-	test('run ' + i, function (t) {
-		console.time('test' + i);
-		mods.forEach(function (mod) {
-			t.test(mod + ' run ' + i, function (t){
-				t.plan(2);
-				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');
-				var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex');
-				t.equals(pub1, pub2, 'equal secrets');
-			});
+	mods.forEach(function (mod) {
+		test(mod + ' run ' + i, function (t){
+			t.plan(2);
+			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');
+			var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex');
+			t.equals(pub1, pub2, 'equal secrets');
 		});
-		t.test('end', function (t){
-			console.timeEnd('test' + i);
-	 	t.end();
-	 });
 	});
 }
-run(1);
-run(2);
+var i = 0;
+while (++i < 3) {
+	run(i);
+}
\ No newline at end of file

-- 
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