-
Notifications
You must be signed in to change notification settings - Fork 2
/
browser.js
40 lines (30 loc) · 1.1 KB
/
browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var generatePrime = require('./lib/generatePrime');
var primes = require('./lib/primes');
var DH = require('./lib/dh');
function getDiffieHellman(mod) {
var prime = new Buffer(primes[mod].prime, 'hex');
var gen = new Buffer(primes[mod].gen, 'hex');
return new DH(prime, gen);
}
function createDiffieHellman(prime, enc, generator, genc) {
if (Buffer.isBuffer(enc) || (typeof enc === 'string' && ['hex', 'binary', 'base64'].indexOf(enc) === -1)) {
genc = generator;
generator = enc;
enc = undefined;
}
enc = enc || 'binary';
genc = genc || 'binary';
generator = generator || new Buffer([2]);
if (!Buffer.isBuffer(generator)) {
generator = new Buffer(generator, genc);
}
if (typeof prime === 'number') {
return new DH(generatePrime(prime, generator), generator, true);
}
if (!Buffer.isBuffer(prime)) {
prime = new Buffer(prime, enc);
}
return new DH(prime, generator, true);
}
exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman;
exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman;