diff options
| author | Jeremy T. Bouse <jbouse@debian.org> | 2009-11-27 16:20:12 -0500 | 
|---|---|---|
| committer | Jeremy T. Bouse <jbouse@debian.org> | 2009-11-27 16:20:12 -0500 | 
| commit | ed280d5ac360e2af796e9bd973d7b4df89f0c449 (patch) | |
| tree | ce892d6ce9dad8c0ecbc9cbe73f8095195bef0b4 /paramiko/primes.py | |
| parent | 176c6caf4ea7918e1698438634b237fab8456471 (diff) | |
| download | python-paramiko-ed280d5ac360e2af796e9bd973d7b4df89f0c449.tar python-paramiko-ed280d5ac360e2af796e9bd973d7b4df89f0c449.tar.gz | |
Imported Upstream version 1.7.4upstream/1.7.4
Diffstat (limited to 'paramiko/primes.py')
| -rw-r--r-- | paramiko/primes.py | 17 | 
1 files changed, 10 insertions, 7 deletions
| diff --git a/paramiko/primes.py b/paramiko/primes.py index 3677394..7b35736 100644 --- a/paramiko/primes.py +++ b/paramiko/primes.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003-2005 Robey Pointer <robey@lag.net> +# Copyright (C) 2003-2007  Robey Pointer <robey@lag.net>  #  # This file is part of paramiko.  # @@ -23,6 +23,7 @@ Utility functions for dealing with primes.  from Crypto.Util import number  from paramiko import util +from paramiko.ssh_exception import SSHException  def _generate_prime(bits, randpool): @@ -39,7 +40,8 @@ def _generate_prime(bits, randpool):          while not number.isPrime(n):              n += 2          if util.bit_length(n) == bits: -            return n +            break +    return n  def _roll_random(rpool, n):      "returns a random # from 0 to N-1" @@ -59,7 +61,8 @@ def _roll_random(rpool, n):              x = chr(ord(x[0]) & hbyte_mask) + x[1:]          num = util.inflate_long(x, 1)          if num < n: -            return num +            break +    return num  class ModulusPack (object): @@ -75,8 +78,8 @@ class ModulusPack (object):          self.randpool = rpool      def _parse_modulus(self, line): -        timestamp, type, tests, tries, size, generator, modulus = line.split() -        type = int(type) +        timestamp, mod_type, tests, tries, size, generator, modulus = line.split() +        mod_type = int(mod_type)          tests = int(tests)          tries = int(tries)          size = int(size) @@ -87,7 +90,7 @@ class ModulusPack (object):          # type 2 (meets basic structural requirements)          # test 4 (more than just a small-prime sieve)          # tries < 100 if test & 4 (at least 100 tries of miller-rabin) -        if (type < 2) or (tests < 4) or ((tests & 4) and (tests < 8) and (tries < 100)): +        if (mod_type < 2) or (tests < 4) or ((tests & 4) and (tests < 8) and (tries < 100)):              self.discarded.append((modulus, 'does not meet basic requirements'))              return          if generator == 0: @@ -100,7 +103,7 @@ class ModulusPack (object):          if (bl != size) and (bl != size + 1):              self.discarded.append((modulus, 'incorrectly reported bit length %d' % size))              return -        if not self.pack.has_key(bl): +        if bl not in self.pack:              self.pack[bl] = []          self.pack[bl].append((generator, modulus)) |