Commit graph

29 commits

Author SHA1 Message Date
Legrandin
95c9b5be4e Check primality of Q in any DSA domain parameter 2015-10-12 09:17:28 -04:00
Legrandin
d97b240d56 Removed parameter verify_x509_cert from importKey (RSA/DSA) 2015-06-30 20:52:22 +00:00
Legrandin
12b75141c4 Minor simplification to DER decoding code 2015-03-18 08:42:04 +01:00
Legrandin
0701df338c Remove ambiguous method size() from RSA, DSA and ElGamal keys 2015-03-13 20:35:38 +01:00
Legrandin
8e4d6f3518 Update to API documentation. 2015-03-13 20:35:37 +01:00
Legrandin
eaf771e1b9 Remove Crypto.PublicKey.DSA.DSAImplementation
In the process, Crypto.PublicKey.DSA.exportKey()
accepts a "randfunc" parameter to convey the PRNG
to rely on when doing PEM encryption.
2015-03-11 13:56:19 -04:00
Legrandin
72aff29a65 Update to API documentation. 2015-03-11 11:30:16 -04:00
Legrandin
54f786bbf3 Refactor DSA generation to follow FIPS186 more closely 2015-03-08 20:51:23 +01:00
Legrandin
2cb82bb2a6 Remove progress_func from PublicKey objects 2015-02-25 21:42:49 +01:00
Legrandin
7205b0b719 Base DSA on Math.Integer 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
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
c37fbf2d0f Merge branch 'side_channel_dsa' of https://github.com/Legrandin/pycrypto
Conflicts:
	lib/Crypto/PublicKey/DSA.py
2014-05-11 15:48:14 +02:00
Legrandin
fdad7e6166 Merge branch 'rsa_dsa_sanity_checks' of https://github.com/Legrandin/pycrypto 2014-05-11 15:28:23 +02:00
Legrandin
a67cdf4de8 Generate DSA key given the domain parameters.
This patch makes it possible to generate a new DSA key so that it uses
a set of pre-defined domain parameters.

For instance, it is possible to generate 2 distinct DSA keys that
share the same domain parameters:

    >> key_one = DSA.generate(2048)
    >> key_two = DSA.generate(2048, domain=key_one.domain())
2014-03-04 22:34:30 +01:00
Legrandin
727780b7da Implement a robust DSA API.
This patch introduces a new module (Crypto.Signature.DSS)
with a less error prone API for performing DSA signatures.

Similarly to Crypto.Signature.PKCS1_PSS, the module
creates a signer object that only works with hash objects,
not directly with messages.

Additionally, the caller does not need to provide any RNG.
The module will use the default one and will correctly pick
the critical nonce K.

Example of API usage:

>>> from Crypto.Signature.DSS
>>> from Crypto.Hash import SHA256
>>> from Crypto.PublicKey import DSA
>>>
>>> message = b'I give my permission to order #4355'
>>> key = DSA.importKey(open('privkey.der').read())
>>> h = SHA256.new(message)
>>> signer = DSS.new(key)
>>> signature = signer.sign(h)
2014-03-04 22:34:29 +01:00
Legrandin
08faf34764 Add side-channel countermeasures to DSA.
This patch strenghten the DSA signing code against
side-channel attacks.

The DSA signing formulae:

r = (g^{k} mod p) mod q
s = k^{-1} * (H(m) + r*x) mod q

becomes:

b = random in [1..q)
r = (g^{k} mod p) mod q
s = (b * k)^{-1} * (b*H(m) + r*(b*x)) mod q

In this way we avoid that the secret (x) gets multiplied
by a random factor (r) which is immediately disclosed
to an attacker (which we assume can both collect (r) and
also monitor the side-channel produced by the multiplication).

See also attack DSA_2 in:

"Minimum Requirements for Evaluating Side-Channel Attack Resistance
of RSA, DSA and Diffie-Hellman Key Exchange Implementations", BSI
2014-03-04 22:32:54 +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
791cfaa255 Add support for import/export of DSA keys
This patch adds methods importKey() to DSA module
and exportKey() to _DSAobj object.

Public and private keys can be imported/exported
in a variety of formats:

* DER vs PEM
* PKCS#8 vs OpenSSL vs OpenSSH/OpenSSL
* Encrypted vs clear
2013-07-14 21:16:46 -07:00
Legrandin
ed29118387 Domain parameters for ElGamal and DSA can be freely shared. The message M to sign must really be hash. 2012-04-26 00:10:05 +02:00
Legrandin
c8e21380a6 Refreshed documentation for ElGamal. Small corrections to DSA and RSA. 2012-04-18 20:45:38 +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
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
133fbaddb8 Crypto.PublicKey: Raise ValueError/TypeError/RuntimeError instead of the various custom "error" exceptions
At some point, it might be a good idea to remove the custom error classes themselves.
2009-04-25 13:57:58 -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/DSA.py (Browse further)