CVS: crypto/Util number.py,1.9,1.10
"A.M. Kuchling" <[email protected]> Thu, 03 Apr 2003 10:41:08 -0800
| Newsgroups | gmane.comp.python.cryptography.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/pycrypto/crypto/Util
In directory sc8-pr-cvs1:/tmp/cvs-serv15126a
Modified Files:
number.py
Log Message:
Use _fastmath.isPrime()
Index: number.py
===================================================================
RCS file: /cvsroot/pycrypto/crypto/Util/number.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- number.py 21 Mar 2003 15:12:54 -0000 1.9
+++ number.py 3 Apr 2003 18:41:06 -0000 1.10
@@ -14,14 +14,9 @@
bignum = long
try:
- import gmp
+ from Crypto.PublicKey import _fastmath
except ImportError:
- try:
- import mpz
- #bignum=mpz.mpz # Temporarily disabled; the 'outrageous exponent'
- # error messes things up.
- except ImportError:
- pass
+ _fastmath = None
# Commented out and replaced with faster versions below
## def long2str(n):
@@ -93,6 +88,9 @@
for i in sieve:
if (N % i)==0: return 0
+ # Use the accelerator if available
+ if _fastmath is not None:
+ return _fastmath.isPrime(N)
# Compute the highest bit that's set in N
N1=N - 1L ; n=1L
@@ -104,11 +102,15 @@
a=long(c) ; d=1L ; t=n
while (t): # Iterate over the bits in N1
x=(d*d) % N
- if x==1L and d!=1L and d!=N1: return 0 # Square root of 1 found
- if N1 & t: d=(x*a) % N
- else: d=x
+ if x==1L and d!=1L and d!=N1:
+ return 0 # Square root of 1 found
+ if N1 & t:
+ d=(x*a) % N
+ else:
+ d=x
t = t >> 1L
- if d!=1L: return 0
+ if d!=1L:
+ return 0
return 1
# Small primes used for checking primality; these are all the primes
-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb:
Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/