You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.0 KiB
31 lines
1.0 KiB
import generatePrime from "./lib/generatePrime";
|
|
import * as primes from "./lib/primes.json";
|
|
import DH from "./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);
|
|
}
|
|
var ENCODINGS = {
|
|
'binary': true, 'hex': true, 'base64': true
|
|
};
|
|
function createDiffieHellman(prime, enc, generator, genc) {
|
|
if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
|
|
return createDiffieHellman(prime, 'binary', enc, generator);
|
|
}
|
|
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);
|
|
}
|
|
export { getDiffieHellman };
|
|
export { createDiffieHellman as DiffieHellman };
|
|
|