| OLD | NEW |
| 1 """cryptomath module | 1 """cryptomath module |
| 2 | 2 |
| 3 This module has basic math/crypto code.""" | 3 This module has basic math/crypto code.""" |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import math | 6 import math |
| 7 import base64 | 7 import base64 |
| 8 import binascii | 8 import binascii |
| 9 import sha | 9 |
| 10 # The sha module is deprecated in Python 2.6 |
| 11 try: |
| 12 import sha |
| 13 except ImportError: |
| 14 from hashlib import sha1 as sha |
| 15 |
| 16 # The md5 module is deprecated in Python 2.6 |
| 17 try: |
| 18 import md5 |
| 19 except ImportError: |
| 20 from hashlib import md5 |
| 10 | 21 |
| 11 from compat import * | 22 from compat import * |
| 12 | 23 |
| 13 | 24 |
| 14 # ************************************************************************** | 25 # ************************************************************************** |
| 15 # Load Optional Modules | 26 # Load Optional Modules |
| 16 # ************************************************************************** | 27 # ************************************************************************** |
| 17 | 28 |
| 18 # Try to load M2Crypto/OpenSSL | 29 # Try to load M2Crypto/OpenSSL |
| 19 try: | 30 try: |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 if (q >= high): | 402 if (q >= high): |
| 392 q = getRandomNumber(low, high) | 403 q = getRandomNumber(low, high) |
| 393 q += 29 - (q % 30) | 404 q += 29 - (q % 30) |
| 394 #Ideas from Tom Wu's SRP code | 405 #Ideas from Tom Wu's SRP code |
| 395 #Do trial division on p and q before Rabin-Miller | 406 #Do trial division on p and q before Rabin-Miller |
| 396 if isPrime(q, 0, display=display): | 407 if isPrime(q, 0, display=display): |
| 397 p = (2 * q) + 1 | 408 p = (2 * q) + 1 |
| 398 if isPrime(p, display=display): | 409 if isPrime(p, display=display): |
| 399 if isPrime(q, display=display): | 410 if isPrime(q, display=display): |
| 400 return p | 411 return p |
| OLD | NEW |