[Pkg-javascript-commits] [node-diffie-hellman] 06/88: 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 3a4f943ef0070a8146c0aa8b75e20747acc24040
Author: Calvin Metcalf <cmetcalf at appgeo.com>
Date: Mon Nov 3 10:06:33 2014 -0500
bench
---
dh.js | 11 +++++++----
inject.js | 7 +++----
test.js | 39 ++++++++++++++++++++++-----------------
3 files changed, 32 insertions(+), 25 deletions(-)
diff --git a/dh.js b/dh.js
index 7cafdcd..c5ff7a6 100644
--- a/dh.js
+++ b/dh.js
@@ -1,11 +1,14 @@
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 = new BN(prime);
- this._prime = BN.mont(this.__prime);
+ this.__prime = BN._prime(prime);
+ this._prime = BN.red(this.__prime);
this._pub = void 0;
this._priv = void 0;
this._makeNum = function makeNum() {
@@ -32,7 +35,7 @@ DH.prototype.getPrivateKey = function (enc) {
};
DH.prototype.getPrime = function (enc) {
- return returnValue(this.__prime, enc);
+ return returnValue(this.__prime.p, enc);
};
DH.prototype.getGenerator = function (enc) {
return returnValue(this._gen, enc);
diff --git a/inject.js b/inject.js
index 536fadd..7c72332 100644
--- a/inject.js
+++ b/inject.js
@@ -1,9 +1,8 @@
-var primes = require('./primes.json');
var DH = require('./dh');
module.exports = function (crypto, exports) {
exports.getDiffieHellman = function (mod) {
- return new DH(new Buffer(primes[mod].prime, 'hex'), crypto);
- }
+ return new DH(mod, crypto);
+ };
exports.createDiffieHellman = function (prime, enc) {
if (typeof prime === 'number') {
throw new Error('generating primes not implimented');
@@ -13,5 +12,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 f072fc0..617d876 100644
--- a/test.js
+++ b/test.js
@@ -7,23 +7,28 @@ var mods = [
];
function run(i) {
- 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');
+ 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');
+ });
});
+ t.test('end', function (t){
+ console.timeEnd('test' + i);
+ t.end();
+ });
});
}
-var i = 0;
-while (++i < 3) {
- run(i);
-}
\ No newline at end of file
+run(1);
+run(2);
--
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