Commit graph

50 commits

Author SHA1 Message Date
Legrandin
06501ae142 RSA modulus size is not required to be a multiple of 256 bits anymore.
RSA key method ``size`` returns the same value as
in PyCrypto.

Use LCM for RSA private exponent.
2015-03-05 21:55:03 +01:00
Legrandin
2cb82bb2a6 Remove progress_func from PublicKey objects 2015-02-25 21:42:49 +01:00
Legrandin
00ab349550 Generic filter for prime number generation 2015-02-25 07:40:29 +01:00
Legrandin
ec7f3c8662 Remove _fastmath and _slowmath from code base 2014-12-06 12:04:12 +01:00
Legrandin
eb03c331b3 Base RSA on Math module (WIP) 2014-12-06 12:04:12 +01:00
Legrandin
b7fba1d134 DSA keys can be loaded from X.509 certificates 2014-07-15 23:01:35 +02:00
Legrandin
bd88e52e32 Add validation flag for import from X.509 cert
This patch forces the user to explicitly assert
that no validation of the X.509 certificate will be
done when importing an RSA key.

In other words, public keys can only be imported in the following way:

    >>> cert_data = open("cert.pem", "rb").read()
    >>> key = RSA.importKey(cert_data, verify_x509_cert=False)

Not passing the parameter "verify_x509_cert" will raise an exception.
2014-07-15 23:01:35 +02:00
Legrandin
11651f3b34 Add ability to read in RSA keys from X.509 certs 2014-07-15 23:01:34 +02:00
Legrandin
1c3c049a4c Clean up Crypto.PublicKey module
This patch does a few things to simplify the public key classes
(RSA, DSA and ElGamal):

* It removes the Crypto.PublicKey.pubkey module. The 3 classes
  do not have an ancestor anymore.
* Methods sign(), verify(), encrypt(), and decrypt() are removed.
* Methods blind() and unblind() are removed.
* Methods can_sign() and can_encrypt() are removed.
* The 3 classes cannot be pickled anymore.
2014-06-16 22:00:03 +02:00
Legrandin
d83380a048 Removed support for Python<2.4 2014-06-16 20:36:35 +02:00
Legrandin
5f8632c7ec Merge branch 'raw_rsa_boundary' of https://github.com/Legrandin/pycrypto 2014-05-11 15:58:28 +02:00
Legrandin
4019275161 Extended fix for the RSA boundary check 2014-05-07 12:22:03 +02:00
Legrandin
50cf75c103 FIX #1193521: mpz_powm_sec crashes when modulus is odd
When importing a key, we verify that all components
that will be used as modulus for mpz_powm_sec() are odd.
2013-12-22 13:42:37 +01:00
Legrandin
8acf0d7011 Add checks to verify correctness of RSA/DSA/ElGamal keys
When the various components are assembled into an RSA,
DSA or ElGamal key via the construct() method, we must verify
as much as possible if the result is indeed a valid key.
2013-12-22 13:42:37 +01:00
Legrandin
f9a0fc77e1 FIX #1191411: RSA export example
Closes: https://bugs.launchpad.net/pycrypto/+bug/1191411
2013-07-14 23:08:47 -07:00
Legrandin
90d6d3dbcf Added support for PKCS#8-encrypted private keys.
The patch contains the following changes:

- Private RSA keys can be imported/exported in encrypted form,
  protected according to PKCS#8 and:

  * PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC.
  * PBKDF2WithHMAC-SHA1AndAES128-CBC
  * PBKDF2WithHMAC-SHA1AndAES192-CBC
  * PBKDF2WithHMAC-SHA1AndAES256-CBC

  In addition to that, it is possible to import keys i the
  following weak formats:

  * pbeWithMD5AndDES-CBC
  * pbeWithSHA1AndRC2-CBC
  * pbeWithMD5AndRC2-CBC
  * pbeWithSHA1AndDES-CBC

- The following new module (and 1 new package) are added:

  * Crypto.Util.Padding for simple padding/unpadding logic
  * Crypto.IO._PBES for PBE-related PKCS#5 logic
  * Crypto.IO.PEM for PEM wrapping/unwrapping
  * Crypto.IO.PKCS8 for PKCS#8 wrapping/unwrapping

- All Object ID (OIDs) are now in dotted form to increase
  readability.

- Add AES support to PEM format (decode only).
  The PEM module can decrypt messages protected with AES-CBC.

- Update RSA import test cases.

- Updated to PKCS8 test cases
2013-07-14 21:16:46 -07:00
Frank Sievertsen
db52ac71e8 Fix RSA object serialization 2013-02-16 11:14:09 -08:00
Dwayne C. Litzenberger
125a4f93fa Merge remote-tracking branch 'sebastinas/reenable-tests' 2012-05-28 08:13:54 -04:00
Sebastian Ramacher
8c0572a871 Except shadows builtin IndexError.
Constructs like

 try:
   ...
 except ValueError, IndexError:
   ...

don't work as expected. This only catches a ValueError and replaces the builtin
IndexError with the catches ValueError object. See [1] for details.

[1] http://docs.python.org/whatsnew/2.6.html#pep-3110-exception-handling-changes
2012-05-28 13:32:13 +02:00
Sebastian Ramacher
0c2625df74 Raise a ValueError as documented.
Also add a test case for it.
2012-05-28 13:27:42 +02:00
Sebastian Ramacher
ab25c6fe95 Return a byte string if format is set to OpenSSH.
RSA.exportKey claims to return a byte string, so really return one.
2012-05-28 13:19:22 +02:00
Legrandin
cdcc48b064 Add ability to import RSAPublicKey objects (encoded in DER or PEM) 2012-05-18 22:54:57 +02:00
Legrandin
6a3b711a3a Clarification of how RSA keys can be imported/exported 2012-05-18 15:26:58 +02:00
Legrandin
c8e21380a6 Refreshed documentation for ElGamal. Small corrections to DSA and RSA. 2012-04-18 20:45:38 +02:00
Legrandin
e6ef5dee7b Polished the Crypto.PublicKey page.Added hyperlinks to RFCs. 2012-04-12 23:16:52 +02:00
Legrandin
35a748d482 Refreshed documentation for DSA. Minor fixes in RSA documentation. 2012-04-12 00:49:32 +02:00
Legrandin
a7123247de Refreshed documentation for RSA. epydoc does not generate documentation for private methods, and inherited ones are made more explicit. 2012-04-10 21:26:33 +02:00
Legrandin
3b5e3e152a Merge from upstream 2011-10-19 23:13:42 +02:00
Legrandin
8390495a9d Further fixed for python 3 2011-10-19 23:02:58 +02: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
c1ad8f08c9 FIX BUG 702835: "Import key code is not compatible with GMP library"
The bug is at: https://bugs.launchpad.net/pycrypto/+bug/702835

When importing an DER RSA private key, u (that is, p^{-1} mod q) must be
computed manually. RSA.importKey() also raises a more descriptive exception in
case of an unknown key format.

Conflicts:

	lib/Crypto/PublicKey/RSA.py
2011-10-17 22:09:04 -04:00
Legrandin
621d44a730 Added support for export and import of unencrypted PKCS#8 keys (with tests).
FIX: Certain public exponents were not correctly exported in OpenSSH keys.
2011-10-11 23:53:26 +02:00
Sebastian Ramacher
0f79b99483 fix exception message in Crypto.PublicKey.RSA.generate
Applied patch from Debian python-crypto 2.3-3:
    debian/patches/fix-RSA-generate-exception.patch
2011-10-10 16:22:44 -04:00
Legrandin
674b80db74 Added support for pass phrase and DES/3DES encrypted PEM keys, for both import and export. 2011-10-03 23:33:11 +02:00
Legrandin
51a760b185 Added support for export of public RSA keys in OpenSSH format 2011-09-21 20:54:17 +02:00
Legrandin
b8dc2d95ea Add support for import of OpenSSH public keys 2011-09-21 00:01:36 +02:00
Legrandin
01f280d0e2 Merged with upstream. 2011-09-20 19:41:33 +02:00
Anders Sundman
e226cd7f96 Merge from dlitz/master 2011-05-19 19:55:12 +02:00
Dwayne C. Litzenberger
4669b04c6f Avoid timing attacks: Do blinded RSA by default
Thanks to Geremy Condra (and others) for pointing out the timing
vulnerability.
2011-02-21 21:11:21 -05:00
Legrandin
09fb89e8e1 Added more documentation for the RSA module. 2011-01-21 18:54:53 +01:00
Legrandin
cdc8867904 Allow RSA to be generated with an arbitary public exponent e.
Small fix to importKey documentation (ASN.1 structure names were
incorrect for public keys).

Factors of an RSA private key are computed from private exponent d
(both slowmath and fastmath).
2011-01-18 23:39:32 +01:00
Legrandin
1221bebb3e Pure tab-to-space conversion with :retab in vim. 2011-01-16 22:05:54 +01:00
Legrandin
a2fdd4bada FIX BUG 702835. When importing an DER RSA private key, u (that is, p^{-1} mod q) must be computed manually. RSA.importKey() also raises a more descriptive exception in case of an unknown key format. 2011-01-16 21:44:10 +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
6833a7bf18 Make RSA.generate raise a more user-friendly exception message when the user tries to generate a bogus-length key.
Before this change, doing RSA.generate(128*5) would raise an exception saying:

    "bits must be multiple of 128 and > 512"

This was because getStrongPrime was raising the exception when trying to
generate 320-bit primes (which is correct behaviour).  Now, we raise a more
friendly error message:

    "RSA modulus length must be a multiple of 256 and > 1024"
2010-08-27 00:14:40 -04:00
Legrandin
902ea14fc2 Support for older versions of python
This patch add support for older python 2.1/2.2 to the previous one (DER/PEM).

Committer: Legrandin <gooksankoo@hoiptorrow.mailexpire.com>
2010-08-02 16:34:53 -04:00
Legrandin
0f45878cef Add ability to export and import RSA keys in DER and PEM format.
Typical usage for importing an RSA key:

f = file("ssl.pem")
key = RSA.importKey(f.read())
f.close()
key.verify(hash, signature)

Typical usage for exporting an RSA public key:

key = RSA.generate(512, randfunc)
f = file("ssl.der","w")
f.write(key.publickey.exportKey('DER'))
f.close()

I confirm I am eligible for submitting code to pycrypto according
to http://www.dlitz.net/software/pycrypto/submission-requirements/
fetched on 27 December 2009.

Committer: Legrandin <gooksankoo@hoiptorrow.mailexpire.com>
2010-08-02 16:34:13 -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 PublicKey/RSA.py (Browse further)