primes.py 682 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. #
  4. """
  5. Parsing for the moduli file, which contains Diffie-Hellman prime groups.
  6. Maintainer: Paul Swartz
  7. """
  8. from twisted.python.compat import long
  9. def parseModuliFile(filename):
  10. with open(filename) as f:
  11. lines = f.readlines()
  12. primes = {}
  13. for l in lines:
  14. l = l.strip()
  15. if not l or l[0]=='#':
  16. continue
  17. tim, typ, tst, tri, size, gen, mod = l.split()
  18. size = int(size) + 1
  19. gen = long(gen)
  20. mod = long(mod, 16)
  21. if size not in primes:
  22. primes[size] = []
  23. primes[size].append((gen, mod))
  24. return primes