From be5542c05e46b500e47b94bc8a6254cae8335a8b Mon Sep 17 00:00:00 2001 From: "Jeremy T. Bouse" Date: Sun, 29 May 2011 08:16:54 -0400 Subject: Imported Upstream version 1.7.7.1 --- docs/paramiko.primes-pysrc.html | 174 ++++++++++++++++++++++------------------ 1 file changed, 98 insertions(+), 76 deletions(-) (limited to 'docs/paramiko.primes-pysrc.html') diff --git a/docs/paramiko.primes-pysrc.html b/docs/paramiko.primes-pysrc.html index dee92dc..eabf841 100644 --- a/docs/paramiko.primes-pysrc.html +++ b/docs/paramiko.primes-pysrc.html @@ -82,33 +82,34 @@ 26 from paramiko.ssh_exception import SSHException 27 28 -
29 -def _generate_prime(bits, randpool): +
29 -def _generate_prime(bits, rng):
30 "primtive attempt at prime generation" 31 hbyte_mask = pow(2, bits % 8) - 1 32 while True: 33 # loop catches the case where we increment n into a higher bit-range - 34 x = randpool.get_bytes((bits+7) // 8) + 34 x = rng.read((bits+7) // 8) 35 if hbyte_mask > 0: 36 x = chr(ord(x[0]) & hbyte_mask) + x[1:] 37 n = util.inflate_long(x, 1) @@ -120,7 +121,7 @@ paramiko.rng.StrongLockingRandomPool.get_bytes" class="py-name" href="#" onclick 43 break 44 return n
45 -
46 -def _roll_random(rpool, n): +
46 -def _roll_random(rng, n):
47 "returns a random # from 0 to N-1" 48 bits = util.bit_length(n-1) 49 bytes = (bits + 7) // 8 @@ -133,11 +134,32 @@ paramiko.rng.StrongLockingRandomPool.get_bytes" class="py-name" href="#" onclick 56 # fits, so i can't guarantee that this loop will ever finish, but the odds 57 # of it looping forever should be infinitesimal. 58 while True: - 59 x = rpool.get_bytes(bytes) + 59 x = rng.read(bytes) 60 if hbyte_mask > 0: 61 x = chr(ord(x[0]) & hbyte_mask) + x[1:] - 62 num = util.inflate_long(x, 1) + 62 num = util.inflate_long(x, 1) 63 if num < n: 64 break 65 return num @@ -153,27 +175,27 @@ paramiko.rng.StrongLockingRandomPool.get_bytes" class="py-name" href="#" onclick
75 # pack is a hash of: bits -> [ (generator, modulus) ... ] 76 self.pack = {} 77 self.discarded = [] - 78 self.randpool = rpool + 78 self.rng = rpool
79
80 - def _parse_modulus(self, line):
81 timestamp, mod_type, tests, tries, size, generator, modulus = line.split() @@ -197,7 +219,7 @@ paramiko.util.randpool" class="py-name" href="#" onclick="return doclink('link-1 99 # there's a bug in the ssh "moduli" file (yeah, i know: shock! dismay! 100 # call cnn!) where it understates the bit lengths of these primes by 1. 101 # this is okay. -102 bl = util.bit_length(modulus) +102 bl = util.bit_length(modulus) 103 if (bl != size) and (bl != size + 1): 104 self.discarded.append((modulus, 'incorrectly reported bit length %d' % size)) 105 return @@ -210,7 +232,7 @@ paramiko.util.randpool" class="py-name" href="#" onclick="return doclink('link-1 112 @raise IOError: passed from any file operations that fail. 113 """ 114 self.pack = {} -115 f = open(filename, 'r') +115 f = open(filename, 'r') 116 for line in f: 117 line = line.strip() 118 if (len(line) == 0) or (line[0] == '#'): @@ -219,7 +241,7 @@ paramiko.util.randpool" class="py-name" href="#" onclick="return doclink('link-1 121 self._parse_modulus(line) 122 except: 123 continue -124 f.124 f.close() +paramiko.win_pageant.PageantConnection.close" class="py-name" href="#" onclick="return doclink('link-21', 'close', 'link-21');">close()
125
126 - def get_modulus(self, min, prefer, max): -
127 bitsizes = self.pack.keys() +
127 bitsizes = self.pack.keys() 128 bitsizes.sort() 129 if len(bitsizes) == 0: -130 raise SSHException('no moduli available') +130 raise SSHException('no moduli available') 131 good = -1 132 # find nearest bitsize >= preferred 133 for b in bitsizes: @@ -256,27 +278,27 @@ paramiko.win_pageant.PageantConnection.close" class="py-name" href="#" onclick=" 147 if min > good: 148 good = bitsizes[-1] 149 # now pick a random modulus of this bitsize -150 n = _roll_random(self.randpool, len(self.pack[good])) +150 n = _roll_random(self.rng, len(self.pack[good])) 151 return self.pack[good][n]
152