File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -113,13 +113,21 @@ def generate(bits, key_type="rsa"):
113113
114114 key_type can be "rsa" for a universal rsaEncryption key or
115115 "rsa-pss" for a key that can be used only for RSASSA-PSS."""
116+ # p, q, and t are standard names for the variables in RSA, so
117+ # ignore the fact those are one character long variable names
118+ # pylint: disable=invalid-name
116119 key = Python_RSAKey ()
117- p = getRandomPrime (bits // 2 , False )
118- q = getRandomPrime (bits // 2 , False )
119- if gmpyLoaded or GMPY2_LOADED :
120- p = mpz (p )
121- q = mpz (q )
122- t = lcm (p - 1 , q - 1 )
120+ while True :
121+ p = getRandomPrime (bits // 2 , False )
122+ q = getRandomPrime (bits // 2 , False )
123+ if gmpyLoaded or GMPY2_LOADED :
124+ p = mpz (p )
125+ q = mpz (q )
126+ t = lcm (p - 1 , q - 1 )
127+ # since we need to calculate inverse of 65537 mod t, they
128+ # must be relatively prime (coprime)
129+ if gcd (t , 65537 ) == 1 :
130+ break
123131 key .n = p * q
124132 if gmpyLoaded or GMPY2_LOADED :
125133 key .e = mpz (65537 )
@@ -132,6 +140,7 @@ def generate(bits, key_type="rsa"):
132140 key .dQ = key .d % (q - 1 )
133141 key .qInv = invMod (q , p )
134142 key .key_type = key_type
143+ # pylint: enable=invalid-name
135144 return key
136145
137146 @staticmethod
You can’t perform that action at this time.
0 commit comments