~spiv/ubuntu/lucid/paramiko/address-families-579530-lucid

« back to all changes in this revision

Viewing changes to paramiko/primes.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy T. Bouse
  • Date: 2006-12-26 15:48:42 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20061226154842-a4h9l1h59t0osb7y
Tags: 1.6.4-1
New upstream release (Closes: #344734, #382348).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2003-2005 Robey Pointer <robey@lag.net>
 
1
# Copyright (C) 2003-2006 Robey Pointer <robey@lag.net>
2
2
#
3
3
# This file is part of paramiko.
4
4
#
23
23
from Crypto.Util import number
24
24
 
25
25
from paramiko import util
 
26
from paramiko.ssh_exception import SSHException
26
27
 
27
28
 
28
29
def _generate_prime(bits, randpool):
39
40
        while not number.isPrime(n):
40
41
            n += 2
41
42
        if util.bit_length(n) == bits:
42
 
            return n
 
43
            break
 
44
    return n
43
45
 
44
46
def _roll_random(rpool, n):
45
47
    "returns a random # from 0 to N-1"
59
61
            x = chr(ord(x[0]) & hbyte_mask) + x[1:]
60
62
        num = util.inflate_long(x, 1)
61
63
        if num < n:
62
 
            return num
 
64
            break
 
65
    return num
63
66
 
64
67
 
65
68
class ModulusPack (object):
75
78
        self.randpool = rpool
76
79
 
77
80
    def _parse_modulus(self, line):
78
 
        timestamp, type, tests, tries, size, generator, modulus = line.split()
79
 
        type = int(type)
 
81
        timestamp, mod_type, tests, tries, size, generator, modulus = line.split()
 
82
        mod_type = int(mod_type)
80
83
        tests = int(tests)
81
84
        tries = int(tries)
82
85
        size = int(size)
87
90
        # type 2 (meets basic structural requirements)
88
91
        # test 4 (more than just a small-prime sieve)
89
92
        # tries < 100 if test & 4 (at least 100 tries of miller-rabin)
90
 
        if (type < 2) or (tests < 4) or ((tests & 4) and (tests < 8) and (tries < 100)):
 
93
        if (mod_type < 2) or (tests < 4) or ((tests & 4) and (tests < 8) and (tries < 100)):
91
94
            self.discarded.append((modulus, 'does not meet basic requirements'))
92
95
            return
93
96
        if generator == 0:
100
103
        if (bl != size) and (bl != size + 1):
101
104
            self.discarded.append((modulus, 'incorrectly reported bit length %d' % size))
102
105
            return
103
 
        if not self.pack.has_key(bl):
 
106
        if bl not in self.pack:
104
107
            self.pack[bl] = []
105
108
        self.pack[bl].append((generator, modulus))
106
109