# Only in pycrypto/files: pycrypto-2.3-gmp.patch diff -ur pycrypto.orig/pycrypto-2.3.ebuild pycrypto/pycrypto-2.3.ebuild --- pycrypto.orig/pycrypto-2.3.ebuild 2011-12-02 17:26:35.756048870 +0800 +++ pycrypto/pycrypto-2.3.ebuild 2011-12-02 18:32:01.631050510 +0800 @@ -33,6 +33,7 @@ src_prepare() { distutils_src_prepare epatch "${FILESDIR}/${PN}-2.1.0-gmp.patch" + epatch "${FILESDIR}"/pycrypto-2.3-gmp.patch } src_configure() { diff -ur pycrypto-2.3.orig/lib/Crypto/PublicKey/RSA.py pycrypto-2.3/lib/Crypto/PublicKey/RSA.py --- lib/Crypto/PublicKey/RSA.py 2010-08-27 12:41:55.000000000 +0800 +++ lib/Crypto/PublicKey/RSA.py 2011-12-02 18:13:49.552050054 +0800 @@ -36,6 +36,7 @@ from Crypto.Util.asn1 import DerObject, DerSequence import binascii +from Crypto.Util.number import inverse try: from Crypto.PublicKey import _fastmath except ImportError: @@ -143,7 +144,7 @@ keyType = "RSA PRIVATE" der[:] = [ 0, self.n, self.e, self.d, self.p, self.q, self.d % (self.p-1), self.d % (self.q-1), - self.u ] + inverse(self.q, self.p) ] else: keyType = "PUBLIC" der.append('\x30\x0D\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x01\x01\x05\x00') @@ -162,7 +163,7 @@ pem += ''.join(chunks) pem += "-----END %s KEY-----" % keyType return pem - return ValueError("") + return ValueError("Unknown key format '%s'. Cannot export the RSA key." % format) class RSAImplementation(object): def __init__(self, **kwargs): @@ -204,7 +205,7 @@ def generate(self, bits, randfunc=None, progress_func=None): if bits < 1024 or (bits & 0xff) != 0: # pubkey.getStrongPrime doesn't like anything that's not a multiple of 128 and > 512 - raise ValueError("RSA modulus length must be a multiple of 256 and > 1024") + raise ValueError("RSA modulus length must be a multiple of 256 and >= 1024") rf = self._get_randfunc(randfunc) obj = _RSA.generate_py(bits, rf, progress_func) # TODO: Don't use legacy _RSA module key = self._math.rsa_construct(obj.n, obj.e, obj.d, obj.p, obj.q, obj.u) @@ -219,11 +220,23 @@ der.decode(externKey, True) if len(der)==9 and der.hasOnlyInts() and der[0]==0: # ASN.1 RSAPrivateKey element - del der[6:8] # Remove d mod (p-1) and d mod (q-1) + del der[6:] # Remove d mod (p-1), d mod (q-1), and q^{-1} mod p + der.append(inverse(der[4],der[5])) # Add p^{-1} mod q del der[0] # Remove version return self.construct(der[:]) if len(der)==2: # ASN.1 SubjectPublicKeyInfo element + # The DER object is a SEQUENCE with two elements: + # The DER object is a SEQUENCE with two elements: + # + # The first element is always the same: + # 0x30 0x0D SEQUENCE, 12 bytes of payload + # 0x06 0x09 OBJECT IDENTIFIER, 9 bytes of payload + # 0x2A 0x86 0x48 0x86 0xF7 0x0D 0x01 0x01 0x01 + # 0x2A 0x86 0x48 0x86 0xF7 0x0D 0x01 0x01 0x01 + # 0x2A 0x86 0x48 0x86 0xF7 0x0D 0x01 0x01 0x01 + # + # 0x2A 0x86 0x48 0x86 0xF7 0x0D 0x01 0x01 0x01 if der[0]=='\x30\x0D\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x01\x01\x05\x00': bitmap = DerObject() bitmap.decode(der[1], True) @@ -239,6 +252,8 @@ externKey: the RSA key to import, encoded as a string. The key can be in DER (PKCS#1) or in unencrypted PEM format (RFC1421). + + Raises a ValueError/IndexError if the given key cannot be parsed. """ if externKey.startswith('-----'): # This is probably a PEM encoded key