Commit graph

19 commits

Author SHA1 Message Date
Legrandin
7b1e1699a4 Remove leftover references to fastmath 2015-01-05 23:06:22 +01:00
Legrandin
d83380a048 Removed support for Python<2.4 2014-06-16 20:36:35 +02:00
Legrandin
3755ff63fe Merge branch 'scrypt' of https://github.com/Legrandin/pycrypto
Conflicts:
	lib/Crypto/Protocol/KDF.py
	lib/Crypto/SelfTest/Cipher/common.py
	lib/Crypto/SelfTest/Hash/test_HMAC.py
	lib/Crypto/SelfTest/Protocol/test_KDF.py
	src/hash_template.c
2014-05-11 15:42:33 +02:00
Marc Abramowitz
eb51036c9b Refactor 3 places handling fastmath ImportError
so that they call `Crypto.SelfTest.st_common.handle_fastmath_import_error`,
thereby eliminiating duplicate code.
2014-02-22 12:40:25 -08:00
Marc Abramowitz
5dc0db2009 Use different method for getting ext_suffix
```
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.
2014-02-22 12:40:25 -08:00
Legrandin
aa32e3d662 Optimize scrypt (~50%) and support for Python 2.1 2013-12-24 23:00:35 +01:00
Legrandin
102cd21c8d Add support for scrypt
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.
2013-12-24 22:56:21 +01:00
Dwayne C. Litzenberger
48aeb9472d Add tests for error propagation in _fastmath
Affects isPrime and getStrongPrime.

See https://github.com/dlitz/pycrypto/pull/23 ("Store result of
rabinMillerTest in an int.") for the bug report.
2012-07-03 11:47:55 -04:00
Sebastian Ramacher
d31f7df39a Run test_negative_number_roundtrip_mpzToLongObj_longObjToMPZ only if _fastmath
is available.
2012-06-28 16:16:26 +02:00
Dwayne C. Litzenberger
61420abf2e _fastmath: Convert negative numbers properly 2012-04-25 17:06:48 -04:00
Dwayne C. Litzenberger
88b4a886cc _fastmath: missing Py_BLOCK_THREADS on isPrime(1)
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
2012-04-25 16:08:02 -04:00
Legrandin
c22fa18c0d Merged from upstream (py3k support) and modified so that all unit tests pass. 2011-10-18 23:20:26 +02:00
Legrandin
71df2e2eea Added test case for size() 2011-02-06 23:42:57 +01:00
Thorsten Behrens
cb48387f66 PY3K _fastmath support
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
2010-12-29 13:21:05 -05:00
Thorsten Behrens
295ce314d9 Changes to allow pycrpyto to work on Python 3.x as well as 2.1 through 2.7 2010-12-28 16:26:52 -05:00
Dwayne C. Litzenberger
a4cdab130e Fix backward compatibility with PyCrypto 2.1 through 2.5:
- 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)".
2010-06-10 23:47:16 -04:00
Lorenz Quack
c575de4f18 getStrongPrime() implementation
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 ===
2010-06-10 21:02:07 -04:00
Dwayne C. Litzenberger
386de1947b Legal: Dedicate my files to the public domain.
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)
2009-03-01 10:22:51 -05:00
Dwayne C. Litzenberger
ff8a657a8d cleanup: Move modules to "lib/Crypto" subdirectory.
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)