```
ext_suffix = get_config_var("EXT_SUFFIX") or get_config_var("SO")
```
because `get_config_var("SO")` returns None in Python 3.4.0a4 because the "SO"
variable is deprecated and "EXT_SUFFIX" is the new way to get this information
(see: http://bugs.python.org/issue19555)
This fixes `TypeError: Can't convert 'NoneType' object to str implicitly`
errors when running the tests on Python 3.4.0a4.
scrypt is a robust password-based key derivation function.
These set of changes implements it according to the RFC draft:
http://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01
scrypt is also added to the algorithms understood by PKCS#8
(so that one can protect private keys at rest with it).
Additionally, this patch adds tests cases for PBES functions.
When _fastmath is present, the following code caused the Python interpreter
to abort with a fatal error:
from Crypto.Util.number import isPrime
isPrime(1) # Fatal Python error: PyEval_SaveThread: NULL tstate
Bug report: https://bugs.launchpad.net/pycrypto/+bug/988431
o _fastmath now builds and runs on PY3K
o Changes to setup.py to allow /usr/include for gmp.h
o Changes to setup.py to allow linking fastmath w/ static mpir
on Windows without warning messages
o Changes to test_DSA/test_RSA to throw an exception if _fastmath
is present but cannot be imported (due to an issue building
_fastmath or the shared gmp/mpir libraries not being reachable)
o number.py has the code to flag a failing _fastmath, but that
code is commented out for a better runtime experience
o Clean up the if for py21compat import - should have been == not is
o Clean up some '== None' occurences, now 'is None' instead
- Replaced things like (1 << bits) with (1L << bits). See PEP 237:
- In Python < 2.4, (1<<31) evaluates as -2147483648
- In Python >= 2.4, it becomes 2147483648L
- Replaced things like (bits/2) with the equivalent (bits>>1). This makes
PyCrypto work when floating-point division is enabled (e.g. in Python 2.6
with -Qnew)
- In Python < 2.2, expressions like 2**1279, 1007119*2014237, and
3153640933 raise OverflowError. Replaced them with it with 2L**1279,
1007119L*2014237L, and 3153640933, respectively.
- The "//" and "//=" integer division operators are a syntax error in Python
2.1 and below. Replaced things like (m //= 2) with the equivalent
(m >>= 1).
- Where integer division can't be replaced by bit shifting, replace (a/b) with
(divmod(a, b)[0]).
- math.log takes exactly 1 argument in Python < 2.3, so replaced things like
"-math.log(false_positive_prob, 4)" with
"-math.log(false_positive_prob)/math.log(4)".
From http://lists.dlitz.net/pipermail/pycrypto/2009q4/000167.html, with the
following explanation included in the email:
=== snip ===
Hi there!
Here comes my monster patch.
It includes a python and C version of getStrongPrime, rabinMillerTest and isPrime.
there are also two small unit tests and some helper functions.
They all take a randfunc and propagate them (or so I hope).
The Rabin-Miller-Test uses random bases (non-deterministic).
getStrongPrime and isPrime take an optional parameter "false_positive_prob"
where one can specify the maximum probability that the prime is actually
composite. Internally the functions calculate the Rabin-Miller rounds from
this. It defaults to 1e-6 (1:1000000) which results in 10 rounds of Rabin-Miller
testing.
Please review this carefully. Even though I tried hard to get things right some
bugs always slip through.
maybe you could also review the way I acquire and release the GIL. It felt kind
of ugly the way I did it but I don't see a better way just now.
Concerning the public exponent e:
I now know why it needs to be coprime to p-1 and q-1. The private exponent d is
the inverse of e mod ((p-1)(q-1)).
If e is not coprime to ((p-1)(q-1)) then the inverse does not exist [1].
The getStrongPrime take an optional argument e. if provided the function will
make sure p-1 and e are coprime. if e is even (p-1)/2 will be coprime.
if e is even then there is a additional constraint: p =/= q mod 8.
I can't check for that in getStrongPrime of course but since we hardcoded e to
be odd in _RSA.py this should pose no problem.
The Baillie-PSW-Test is not included.
I tried hard not to use any functionality new than 2.1 but if you find anything
feel free to criticize. Also if I didn't get the coding style right either tell
me or feel free to correct it yourself.
have fun.
//Lorenz
[1] http://mathworld.wolfram.com/ModularInverse.html
=== snip ===
In an attempt to simplify the copyright status of PyCrypto, I'm placing my
code into the public domain, and encouraging other contributors to do the
same.
I have used a public domain dedication that was recommended in a book on FOSS legal
issues[1], followed by the warranty disclaimer boilerplate from the MIT license.
[1] _Intellectual Property and Open Source: A Practical Guide to Protecting
Code_, a book written by Van Lindberg and published by O'Reilly Media.
(ISBN 978-0-596-51796-0)
This will avoid the previous situation where scripts like the old "test.py"
get included accidentally in a release. It also frees us to put additional
build scripts in the top-level directory of the source tree.
2009-02-28 13:14:53 -05:00
Renamed from SelfTest/Util/test_number.py (Browse further)