[Pkg-javascript-commits] [node-diffie-hellman] 36/88: fix small primes
Bastien Roucariès
rouca at moszumanska.debian.org
Thu May 4 10:19:14 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 18b6066820027339bc01ec7785153ce09ff46455
Author: Calvin Metcalf <cmetcalf at appgeo.com>
Date: Wed Dec 3 12:51:31 2014 -0500
fix small primes
---
dh.js | 2 +-
generatePrime.js | 15 ++++++++-------
test.js | 3 +--
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/dh.js b/dh.js
index ec93aed..4b9c35b 100644
--- a/dh.js
+++ b/dh.js
@@ -102,7 +102,7 @@ function DH(prime, generator,crypto, malleable) {
defineError(this, 8);
}
this._makeNum = function makeNum() {
- return crypto.randomBytes(192);
+ return crypto.randomBytes(prime.length);
};
}
DH.prototype.generateKeys = function () {
diff --git a/generatePrime.js b/generatePrime.js
index 00d55af..8395f7d 100644
--- a/generatePrime.js
+++ b/generatePrime.js
@@ -44,8 +44,13 @@ function simpleSieve(p) {
var primes = _getPrimes();
for (var i = 0; i < primes.length; i++)
- if (p.modn(primes[i]) === 0)
- return false;
+ if (p.modn(primes[i]) === 0) {
+ if (p.cmpn(primes[i]) === 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
return true;
}
@@ -62,10 +67,6 @@ function findPrime(bits, gen ,crypto) {
return new BN([0x8c, 0x27]);
}
}
- var rebits = bits;
- if (bits < 22) {
- rebits = 22;
- }
gen = new BN(gen);
var runs, comp;
function generateRandom(bits) {
@@ -113,7 +114,7 @@ function findPrime(bits, gen ,crypto) {
var n2 = num.shrn(1);
while (true) {
- if (num.bitLength() > rebits) {
+ while (num.bitLength() > bits) {
num = generateRandom(bits);
n2 = num.shrn(1);
}
diff --git a/test.js b/test.js
index 009d398..59d9b01 100644
--- a/test.js
+++ b/test.js
@@ -12,7 +12,7 @@ function isNode10() {
2, 8, 16, 17, 18, 20, 21, 22, 64, 65, 128, 384, 512, 1024,
192, 224, 256];
var lens2 = [
- 64, 65, 128];
+ 16, 17, 18, 20, 21, 22,64, 65, 128];
function run(i) {
mods.forEach(function (mod) {
test(mod + ' run ' + i, function (t){
@@ -45,7 +45,6 @@ function bylen(t, generator) {
var prime2 = dh2.getPrime();
var p2 = prime2.toString('hex');
var dh1 = nodeCrypto.createDiffieHellman(prime2, generator);
- //console.log('error', dh1.verifyError)
var p1 = dh1.getPrime().toString('hex');
t.equals(typeof dh1.setPublicKey, typeof dh2.setPublicKey, 'same methods');
t.equals(typeof dh1.setPrivateKey, typeof dh2.setPrivateKey, 'same methods');
--
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