Projekt

Obecné

Profil

Stáhnout (1.11 KB) Statistiky
| Větev: | Revize:
1
var generatePrime = require('./lib/generatePrime')
2
var primes = require('./lib/primes.json')
3

    
4
var DH = require('./lib/dh')
5

    
6
function getDiffieHellman (mod) {
7
  var prime = new Buffer(primes[mod].prime, 'hex')
8
  var gen = new Buffer(primes[mod].gen, 'hex')
9

    
10
  return new DH(prime, gen)
11
}
12

    
13
var ENCODINGS = {
14
  'binary': true, 'hex': true, 'base64': true
15
}
16

    
17
function createDiffieHellman (prime, enc, generator, genc) {
18
  if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
19
    return createDiffieHellman(prime, 'binary', enc, generator)
20
  }
21

    
22
  enc = enc || 'binary'
23
  genc = genc || 'binary'
24
  generator = generator || new Buffer([2])
25

    
26
  if (!Buffer.isBuffer(generator)) {
27
    generator = new Buffer(generator, genc)
28
  }
29

    
30
  if (typeof prime === 'number') {
31
    return new DH(generatePrime(prime, generator), generator, true)
32
  }
33

    
34
  if (!Buffer.isBuffer(prime)) {
35
    prime = new Buffer(prime, enc)
36
  }
37

    
38
  return new DH(prime, generator, true)
39
}
40

    
41
exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman
42
exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman
(3-3/6)