Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 362763
Collapse All | Expand All

(-)pycrypto.orig/pycrypto-2.3.ebuild (+1 lines)
Lines 33-38 Link Here
33
src_prepare() {
33
src_prepare() {
34
	distutils_src_prepare
34
	distutils_src_prepare
35
	epatch "${FILESDIR}/${PN}-2.1.0-gmp.patch"
35
	epatch "${FILESDIR}/${PN}-2.1.0-gmp.patch"
36
	epatch "${FILESDIR}"/pycrypto-2.3-gmp.patch
36
}
37
}
37
38
38
src_configure() {
39
src_configure() {
(-)lib/Crypto/PublicKey/RSA.py (-4 / +19 lines)
Lines 36-41 Link Here
36
from Crypto.Util.asn1 import DerObject, DerSequence
36
from Crypto.Util.asn1 import DerObject, DerSequence
37
import binascii
37
import binascii
38
38
39
from Crypto.Util.number import inverse
39
try:
40
try:
40
    from Crypto.PublicKey import _fastmath
41
    from Crypto.PublicKey import _fastmath
41
except ImportError:
42
except ImportError:
Lines 143-149 Link Here
143
		keyType = "RSA PRIVATE"
144
		keyType = "RSA PRIVATE"
144
		der[:] = [ 0, self.n, self.e, self.d, self.p, self.q,
145
		der[:] = [ 0, self.n, self.e, self.d, self.p, self.q,
145
			   self.d % (self.p-1), self.d % (self.q-1),
146
			   self.d % (self.p-1), self.d % (self.q-1),
146
			   self.u ]
147
			   inverse(self.q, self.p) ]
147
	else:
148
	else:
148
		keyType = "PUBLIC"
149
		keyType = "PUBLIC"
149
		der.append('\x30\x0D\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x01\x01\x05\x00')
150
		der.append('\x30\x0D\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x01\x01\x05\x00')
Lines 162-168 Link Here
162
		pem += ''.join(chunks)
163
		pem += ''.join(chunks)
163
		pem += "-----END %s KEY-----" % keyType
164
		pem += "-----END %s KEY-----" % keyType
164
		return pem
165
		return pem
165
	return ValueError("")
166
	return ValueError("Unknown key format '%s'. Cannot export the RSA key." % format)
166
167
167
class RSAImplementation(object):
168
class RSAImplementation(object):
168
    def __init__(self, **kwargs):
169
    def __init__(self, **kwargs):
Lines 204-210 Link Here
204
    def generate(self, bits, randfunc=None, progress_func=None):
205
    def generate(self, bits, randfunc=None, progress_func=None):
205
        if bits < 1024 or (bits & 0xff) != 0:
206
        if bits < 1024 or (bits & 0xff) != 0:
206
            # pubkey.getStrongPrime doesn't like anything that's not a multiple of 128 and > 512
207
            # pubkey.getStrongPrime doesn't like anything that's not a multiple of 128 and > 512
207
            raise ValueError("RSA modulus length must be a multiple of 256 and > 1024")
208
            raise ValueError("RSA modulus length must be a multiple of 256 and >= 1024")
208
        rf = self._get_randfunc(randfunc)
209
        rf = self._get_randfunc(randfunc)
209
        obj = _RSA.generate_py(bits, rf, progress_func)    # TODO: Don't use legacy _RSA module
210
        obj = _RSA.generate_py(bits, rf, progress_func)    # TODO: Don't use legacy _RSA module
210
        key = self._math.rsa_construct(obj.n, obj.e, obj.d, obj.p, obj.q, obj.u)
211
        key = self._math.rsa_construct(obj.n, obj.e, obj.d, obj.p, obj.q, obj.u)
Lines 219-229 Link Here
219
	der.decode(externKey, True)
220
	der.decode(externKey, True)
220
	if len(der)==9 and der.hasOnlyInts() and der[0]==0:
221
	if len(der)==9 and der.hasOnlyInts() and der[0]==0:
221
		# ASN.1 RSAPrivateKey element
222
		# ASN.1 RSAPrivateKey element
222
		del der[6:8]	# Remove d mod (p-1) and d mod (q-1)
223
		del der[6:]  # Remove d mod (p-1), d mod (q-1), and q^{-1} mod p
224
		der.append(inverse(der[4],der[5])) # Add p^{-1} mod q
223
		del der[0]	# Remove version
225
		del der[0]	# Remove version
224
		return self.construct(der[:])
226
		return self.construct(der[:])
225
	if len(der)==2:
227
	if len(der)==2:
226
		# ASN.1 SubjectPublicKeyInfo element
228
		# ASN.1 SubjectPublicKeyInfo element
229
		# The DER object is a SEQUENCE with two elements:
230
		# The DER object is a SEQUENCE with two elements:
231
		#
232
		# The first element is always the same:
233
		#  0x30 0x0D     SEQUENCE, 12 bytes of payload
234
		#   0x06 0x09   OBJECT IDENTIFIER, 9 bytes of payload
235
		#     0x2A 0x86 0x48 0x86 0xF7 0x0D 0x01 0x01 0x01
236
		#     0x2A 0x86 0x48 0x86 0xF7 0x0D 0x01 0x01 0x01
237
		#     0x2A 0x86 0x48 0x86 0xF7 0x0D 0x01 0x01 0x01
238
		#
239
		#     0x2A 0x86 0x48 0x86 0xF7 0x0D 0x01 0x01 0x01
227
		if der[0]=='\x30\x0D\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x01\x01\x05\x00':
240
		if der[0]=='\x30\x0D\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x01\x01\x05\x00':
228
			bitmap = DerObject()
241
			bitmap = DerObject()
229
			bitmap.decode(der[1], True)
242
			bitmap.decode(der[1], True)
Lines 239-244 Link Here
239
	externKey:	the RSA key to import, encoded as a string.
252
	externKey:	the RSA key to import, encoded as a string.
240
			The key can be in DER (PKCS#1) or in unencrypted
253
			The key can be in DER (PKCS#1) or in unencrypted
241
			PEM format (RFC1421).
254
			PEM format (RFC1421).
255
			
256
 	Raises a ValueError/IndexError if the given key cannot be parsed.			
242
	"""
257
	"""
243
	if externKey.startswith('-----'):
258
	if externKey.startswith('-----'):
244
		# This is probably a PEM encoded key
259
		# This is probably a PEM encoded key

Return to bug 362763