NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #1218 most downloaded on PyPI
Cryptographic modules for Python.
Last release 12 years ago
no release in 18 months
Release timing varies
gaps range from 2 weeks to 1.2 years
Nearly every release is documented
notes for 10 of 10 stable releases
Nothing withdrawn
no release was ever pulled
16 years old
13 releases · first in 2010
[CVE-2013-1445] Fix PRNG not correctly reseeded in some situations.
[CVE-2013-1445] Fix PRNG not correctly reseeded in some situations.
In previous versions of PyCrypto, the Crypto.Random PRNG exhibits a
race condition that may cause forked processes to generate identical
sequences of 'random' numbers.
This is a fairly obscure bug that will (hopefully) not affect many
applications, but the failure scenario is pretty bad. Here is some
sample code that illustrates the problem:
from binascii import hexlify
import multiprocessing, pprint, time
import Crypto.Random
def task_main(arg):
a = Crypto.Random.get_random_bytes(8)
time.sleep(0.1)
b = Crypto.Random.get_random_bytes(8)
rdy, ack = arg
rdy.set()
ack.wait()
return "%s,%s" % (hexlify(a).decode(),
hexlify(b).decode())
n_procs = 4
manager = multiprocessing.Manager()
rdys = [manager.Event() for i in range(n_procs)]
acks = [manager.Event() for i in range(n_procs)]
Crypto.Random.get_random_bytes(1)
pool = multiprocessing.Pool(processes=n_procs,
initializer=Crypto.Random.atfork)
res_async = pool.map_async(task_main, zip(rdys, acks))
pool.close()
[rdy.wait() for rdy in rdys]
[ack.set() for ack in acks]
res = res_async.get()
pprint.pprint(sorted(res))
pool.join()
The output should be random, but it looked like this:
['c607803ae01aa8c0,2e4de6457a304b34',
'c607803ae01aa8c0,af80d08942b4c987',
'c607803ae01aa8c0,b0e4c0853de927c4',
'c607803ae01aa8c0,f0362585b3fceba4']
This release fixes the problem by resetting the rate-limiter when
Crypto.Random.atfork() is invoked. It also adds some tests and a
few related comments.
One column per quarter.
[CVE-2012-2417] Fix LP#985164: insecure ElGamal key generation. (thanks: Legrandin)
[CVE-2012-2417] Fix LP#985164: insecure ElGamal key generation. (thanks: Legrandin)
In the ElGamal schemes (for both encryption and signatures), g is
supposed to be the generator of the entire Z^*_p group. However, in
PyCrypto 2.5 and earlier, g is more simply the generator of a random
sub-group of Z^*_p.
The result is that the signature space (when the key is used for
signing) or the public key space (when the key is used for encryption)
may be greatly reduced from its expected size of log(p) bits, possibly
down to 1 bit (the worst case if the order of g is 2).
While it has not been confirmed, it has also been suggested that an
attacker might be able to use this fact to determine the private key.
Anyone using ElGamal keys should generate new keys as soon as practical.
Any additional information about this bug will be tracked at
https://bugs.launchpad.net/pycrypto/+bug/985164
Huge documentation cleanup (thanks: Legrandin).
Added more tests, including test vectors from NIST 800-38A (thanks: Legrandin)
Remove broken MODE_PGP, which never actually worked properly. A new mode, MODE_OPENPGP, has been added for people wishing to write OpenPGP implementations. Note that this does not implement the full OpenPGP specification, only the "OpenPGP CFB mode" part of that specification. https://bugs.launchpad.net/pycrypto/+bug/996814
Fix: getPrime with invalid input causes Python to abort with fatal error https://bugs.launchpad.net/pycrypto/+bug/988431
Fix: Segfaults within error-handling paths (thanks: Paul Howarth & Dave Malcolm) https://bugs.launchpad.net/pycrypto/+bug/934294
Fix: Block ciphers allow empty string as IV https://bugs.launchpad.net/pycrypto/+bug/997464
Fix DevURandomRNG to work with Python3's new I/O stack. (thanks: Sebastian Ramacher)
Remove automagic dependencies on libgmp and libmpir, let the caller disable them using args.
Many other minor bug fixes and improvements (mostly thanks to Legrandin)
Added PKCS#1 encryption schemes (v1.5 and OAEP). We now have a decent, easy-to-use non-textbook RSA implementation. Yay!
Added PKCS#1 encryption schemes (v1.5 and OAEP). We now have a decent, easy-to-use non-textbook RSA implementation. Yay!
Added PKCS#1 signature schemes (v1.5 and PSS). v1.5 required some extensive changes to Hash modules to contain the algorithm specific ASN.1 OID. To that end, we now always have a (thin) Python module to hide the one in pure C.
Added 2 standard Key Derivation Functions (PBKDF1 and PBKDF2).
Added export/import of RSA keys in OpenSSH and PKCS#8 formats.
Added password-protected export/import of RSA keys (one old method for PKCS#8 PEM only).
Added ability to generate RSA key pairs with configurable public exponent e.
Added ability to construct an RSA key pair even if only the private exponent d is known, and not p and q.
Added SHA-2 C source code (fully from Lorenz Quack).
Unit tests for all the above.
Updates to documentation (both inline and in Doc/pycrypt.rst)
All of the above changes were put together by Legrandin (Thanks!)
Minor bug fixes (setup.py and tests).
Fix "error: Setup script exited with error: src/config.h: No such file or directory" when installing via easy_install. (Sebastian Ramacher)
Python 3 support! (Thorsten E. Behrens, Anders Sundman) PyCrypto now supports every version of Python from 2.1 through 3.2.
Python 3 support! (Thorsten E. Behrens, Anders Sundman) PyCrypto now supports every version of Python from 2.1 through 3.2.
Timing-attack countermeasures in _fastmath: When built against libgmp version 5 or later, we use mpz_powm_sec instead of mpz_powm. This should prevent the timing attack described by Geremy Condra at PyCon 2011: http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2011-through-the-side-channel-timing-and-implementation-attacks-in-python-4897955
New hash modules (for Python >= 2.5 only): SHA224, SHA384, and SHA512 (Frédéric Bertolus)
Configuration using GNU autoconf. This should help fix a bunch of build issues.
Support using MPIR as an alternative to GMP.
Improve the test command in setup.py, by allowing tests to be performed on a single sub-package or module only. (Legrandin)
You can now do something like this:
python setup.py test -m Hash.SHA256 --skip-slow-tests
Fix double-decref of "counter" when Cipher object initialisation fails (Ryan Kelly)
Apply patches from Debian's python-crypto 2.3-3 package (Jan Dittberner, Sebastian Ramacher):
Fix launchpad bug #702835: "Import key code is not compatible with GMP library" (Legrandin)
More tests, better documentation, various bugfixes.
Fix NameError when attempting to use deprecated getRandomNumber() function.
Fix NameError when attempting to use deprecated getRandomNumber() function.
_slowmath: Compute RSA u parameter when it's not given to RSA.construct. This makes _slowmath behave the same as _fastmath in this regard.
Make RSA.generate raise a more user-friendly exception message when the user tries to generate a bogus-length key.
Deprecated Crypto.Util.number.getRandomNumber(), which had confusing semantics. It's been replaced by getRandomNBitInteger and getRandomInteger. (Than…
Deprecated Crypto.Util.number.getRandomNumber(), which had confusing semantics. It's been replaced by getRandomNBitInteger and getRandomInteger. (Thanks: Lorenz Quack)
Better isPrime() and getPrime() implementations that do a real Rabin-Miller probabilistic primality test (not the phony test we did before with fixed bases). (Thanks: Lorenz Quack)
getStrongPrime() implementation for generating RSA primes. (Thanks: Lorenz Quack)
Support for importing and exporting RSA keys in DER and PEM format. (Thanks: Legrandin)
Fix PyCrypto when floor division (python -Qnew) is enabled.
When building using gcc, use -std=c99 for compilation. This should fix building on FreeBSD and NetBSD.
Fix building PyCrypto on Win64 using MS Visual Studio 9. (Thanks: Nevins Bartolomeo.)
Fix SHA256 and RIPEMD on AMD64 platform.
Added SHA256 module contributed by Jeethu Rao, with test data from Taylor Boon.
Added SHA256 module contributed by Jeethu Rao, with test data from Taylor Boon.
Fixed AES.c compilation problems with Borland C.
(Contributed by Jeethu Rao.)
Fix ZeroDivisionErrors on Windows, caused by the system clock not having enough resolution.
Fix FutureWarning in Crypto.Util.randpool, noted by James P Rutledge.
Util.number.getPrime() would inadvertently round off the bit size; if you asked for a 129-bit prime or 135-bit prime, you got a 128-bit prime.
Util.number.getPrime() would inadvertently round off the bit size; if you asked for a 129-bit prime or 135-bit prime, you got a 128-bit prime.
Added Util/test/prime_speed.py to measure the speed of prime generation, and PublicKey/test/rsa_speed.py to measure the speed of RSA operations.
Merged the _rsa.c and _dsa.c files into a single accelerator module, _fastmath.c.
Speed improvements: Added fast isPrime() function to _fastmath, cutting the time to generate a 1024-bit prime by a factor of 10. Optimized the C version of RSA decryption to use a longer series of operations that's roughly 3x faster than a single exponentiation. (Contributed by Joris Bontje.)
Added support to RSA key objects for blinding and unblinding data. (Contributed by Joris Bontje.)
Simplified RSA key generation: hard-wired the encryption exponent to 65537 instead of generating a random prime; generate prime factors in a loop until the product is large enough.
Renamed cansign(), canencrypt(), hasprivate(), to can_sign, can_encrypt, has_private. If people shriek about this change very loudly, I'll add aliases for the old method names that log a warning and call the new method.
Many randpool changes. RandomPool now has a randomize(N:int) method that can be called to get N bytes of entropy for the pool (N defaults to 0, which
Many randpool changes. RandomPool now has a randomize(N:int) method that can be called to get N bytes of entropy for the pool (N defaults to 0, which 'fills up' the pool's entropy) KeyboardRandom overloads this method.
* Added src/winrand.c for Crypto.Util.winrandom and
now use winrandom for _randomize if possible.
(Calls Windows CryptoAPI CryptGenRandom)
* Several additional places for stirring the pool,
capturing inter-event entropy when reading/writing,
stirring before and after saves.
* RandomPool.add_event now returns the number of
estimated bits of added entropy, rather than the
pool entropy itself (since the pool entropy is
capped at the number of bits in the pool)
* Moved termios code from KeyboardRandomPool into a
KeyboardEntry class, provided a version for Windows
using msvcrt.
* Fix randpool.py crash on machines with poor timer resolution.
(Reported by Mark Moraes and others.)
* If the GNU GMP library is available, two C extensions will be
compiled to speed up RSA and DSA operations. (Contributed by
Paul Swartz.)
* DES3 with a 24-byte key was broken; now fixed.
(Patch by Philippe Frycia.)
(Backwards incompatible) The old Crypto.Hash.HMAC module is gone, replaced by a copy of hmac.py from Python 2.2's standard library. It will display a…
(Backwards incompatible) The old Crypto.Hash.HMAC module is gone, replaced by a copy of hmac.py from Python 2.2's standard library. It will display a warning on interpreter versions older than 2.2.
* (Backwards incompatible) Restored the Crypto.Protocol package,
and modernized and tidied up the two modules in it,
AllOrNothing.py and Chaffing.py, renaming various methods
and changing the interface.
* (Backwards incompatible) Changed the function names in
Crypto.Util.RFC1751.
* Restored the Crypto.PublicKey package at user request. I
think I'll leave it in the package and warn about it in the
documentation. I hope that eventually I can point to
someone else's better public-key code, and at that point I
may insert warnings and begin the process of deprecating
this code.
* Fix use of a Python 2.2 C function, replacing it with a
2.1-compatible equivalent. (Bug report and patch by Andrew
Eland.)
* Fix endianness bugs that caused test case failures on Sparc,
PPC, and doubtless other platforms.
* Fixed compilation problem on FreeBSD and MacOS X.
* Expanded the test suite (requires Sancho, from
http://www.mems-exchange.org/software/sancho/)
* Added lots of docstrings, so 'pydoc Crypto' now produces
helpful output. (Open question: maybe *all* of the documentation
should be moved into docstrings?)
* Make test.py automatically add the build/* directory to sys.path.
* Removed 'inline' declaration from C functions. Some compilers
don't support it, and Python's pyconfig.h no longer tells you whether
it's supported or not. After this change, some ciphers got slower,
but others got faster.
* The C-level API has been changed to reduce the amount of
memory-to-memory copying. This makes the code neater, but
had ambiguous performance effects; again, some ciphers got slower
and others became faster. Probably this is due to my compiler
optimizing slightly worse or better as a result.
* Moved C source implementations into src/ from block/, hash/,
and stream/. Having Hash/ and hash/ directories causes problems
on case-insensitive filesystems such as Mac OS.
* Cleaned up the C code for the extensions.
Your coding agent can read these notes before it upgrades. Set up the MCP server →