1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
6
"""Common functions for the SSH classes.
8
This module is unstable.
10
Maintainer: U{Paul Swartz<mailto:z3p@twistedmatrix.com>}
15
from Crypto import Util
16
from Crypto.Util import randpool
19
warnings.warn("PyCrypto not installed, but continuing anyways!",
22
entropy = randpool.RandomPool()
30
return struct.pack('!L',len(t)) + t
32
def getNS(s, count=1):
38
for i in range(count):
39
l, = struct.unpack('!L',s[c:c+4])
40
ns.append(s[c+4:4+l+c])
42
return tuple(ns) + (s[c:],)
45
if number==0: return '\000'*4
47
bn = Util.number.long_to_bytes(number)
50
return struct.pack('>L',len(bn)) + bn
54
get multiple precision integer
56
length=struct.unpack('>L',data[:4])[0]
57
return Util.number.bytes_to_long(data[4:4+length]),data[4+length:]
60
"""return the MP version of (x**y)%z
67
goes through the first list, looking for items in the second, returns the first one
78
l = struct.unpack('!L', i[:4])[0]
80
return long(gmpy.mpz(n+'\x00', 256)), i[4+l:]
83
i2 = gmpy.mpz(i).binary()[::-1]
84
return struct.pack('!L', len(i2)) + i2
86
def _fastMPpow(x, y, z=None):
87
r = pyPow(gmpy.mpz(x),y,z).binary()[::-1]
88
return struct.pack('!L', len(r)) + r
90
def _fastpow(x, y, z=None):
91
return pyPow(gmpy.mpz(x), y, z)
94
global getMP, MP, _MPpow
98
__builtins__['pow'] = _fastpow # evil evil