Menu

#2 calling "getRandomPrime(bits/2, False)" breaks in future

open
nobody
None
5
2008-07-25
2008-07-25
Christophe
No

The generate function in the PythonRSAKey class uses the getRandomBits function ( p = getRandomPrime(bits/2, False). By dividing with "/" (true division) this will give a float in future version of python (tested with from __future__ import division) instead of an int and the getRandomPrime will throw an error. Using "//" (floor division) will work.

I found this bug while using TLS Lite in Sage (www.sagemath.org). There I got a Sage Rational type after the bits/2 division. getRandomPrime won't work then either. But using "//" it will stay a Sage integer type and the everything executes correctly in Sage.

The diff:

--- tlslite-0.3.8/tlslite/utils/Python_RSAKey.py 2008-07-25 14:08:32.000000000 +0200
+++ tlslite-0.3.8/tlslite/utils/Python_RSAKey.py 2008-07-25 14:00:50.000000000 +0200
@@ -95,8 +95,8 @@

def generate(bits):
key = Python_RSAKey()
- p = getRandomPrime(bits/2, False)
- q = getRandomPrime(bits/2, False)
+ p = getRandomPrime(bits//2, False)
+ q = getRandomPrime(bits//2, False)
t = lcm(p-1, q-1)
key.n = p * q
key.e = 3L #Needed to be long, for Java

Discussion


Log in to post a comment.