/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey
Edit: /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyc (14807B)
Bd\Rc @ s d Z d Z d d d d d g Z d d k Z e i d d
j o" e i d d j o d d k Tn d d
k l Z l Z l Z d d k
l Z y d d k l Z Wn e
j
o
d Z n Xd e i f d YZ d e f d YZ e Z e i Z e i Z e i Z d S( sx DSA public-key signature algorithm.
DSA_ is a widespread public-key signature algorithm. Its security is
based on the discrete logarithm problem (DLP_). Given a cyclic
group, a generator *g*, and an element *h*, it is hard
to find an integer *x* such that *g^x = h*. The problem is believed
to be difficult, and it has been proved such (and therefore secure) for
more than 30 years.
The group is actually a sub-group over the integers modulo *p*, with *p* prime.
The sub-group order is *q*, which is prime too; it always holds that *(p-1)* is a multiple of *q*.
The cryptographic strength is linked to the magnitude of *p* and *q*.
The signer holds a value *x* (*0
>> from Crypto.Random import random
>>> from Crypto.PublicKey import DSA
>>> from Crypto.Hash import SHA
>>>
>>> message = "Hello"
>>> key = DSA.generate(1024)
>>> h = SHA.new(message).digest()
>>> k = random.StrongRandom().randint(1,key.q-1)
>>> sig = key.sign(h,k)
>>> ...
>>> if key.verify(h,sig):
>>> print "OK"
>>> else:
>>> print "Incorrect signature"
.. _DSA: http://en.wikipedia.org/wiki/Digital_Signature_Algorithm
.. _DLP: http://www.cosic.esat.kuleuven.be/publications/talk-78.pdf
.. _ECRYPT: http://www.ecrypt.eu.org/documents/D.SPA.17.pdf
s $Id$t generatet constructt errort DSAImplementationt _DSAobjiNi i i ( t *( t _DSAt _slowmatht pubkey( t Random( t _fastmathc B s e Z d Z d d d d d g Z d Z d Z d Z d Z d
Z d Z d Z
d
Z d Z d Z
d Z d Z d Z d Z d Z d Z d Z d Z d Z RS( sl Class defining an actual DSA key.
:undocumented: __getstate__, __setstate__, __repr__, __getattr__
t yt gt pt qt xc C s | | _ | | _ d S( N( t implementationt key( t selfR R ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyt __init__s s c C sA | | i j o t | i | St d | i i | f d S( Ns %s object has no %r attribute( t keydatat getattrR t AttributeErrort __class__t __name__( R t attrname( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyt __getattr__w s c C s t i i | | | S( s Sign a piece of data with DSA.
:Parameter M: The piece of data to sign with DSA. It may
not be longer in bit size than the sub-group order (*q*).
:Type M: byte string or long
:Parameter K: A secret number, chosen randomly in the closed
range *[1,q-1]*.
:Type K: long (recommended) or byte string (not recommended)
:attention: selection of *K* is crucial for security. Generating a
random number larger than *q* and taking the modulus by *q* is
**not** secure, since smaller values will occur more frequently.
Generating a random number systematically smaller than *q-1*
(e.g. *floor((q-1)/8)* random bytes) is also **not** secure. In general,
it shall not be possible for an attacker to know the value of `any
bit of K`__.
:attention: The number *K* shall not be reused for any other
operation and shall be discarded immediately.
:attention: M must be a digest cryptographic hash, otherwise
an attacker may mount an existential forgery attack.
:Return: A tuple with 2 longs.
.. __: http://www.di.ens.fr/~pnguyen/pub_NgSh00.htm
( R t sign( R t Mt K( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyR s c C s t i i | | | S( sE Verify the validity of a DSA signature.
:Parameter M: The expected message.
:Type M: byte string or long
:Parameter signature: The DSA signature to verify.
:Type signature: A tuple with 2 longs as return by `sign`
:Return: True if the signature is correct, False otherwise.
( R t verify( R R t signature( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyR s c C s t d d S( Ns DSA cannot encrypt( t TypeError( R t cR ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyt _encrypt s c C s t d d S( Ns DSA cannot decrypt( R ( R R! ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyt _decrypt s c C s t d d S( Ns DSA cannot blind( R ( R t mt r( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyt _blind s c C s t d d S( Ns DSA cannot unblind( R ( R R$ R% ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyt _unblind s c C s | i i | | S( N( R t _sign( R R$ t k( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyR( s c C s" | \ } } | i i | | | S( N( R t _verify( R R$ t sigR% t s( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyR* s c C s
| i i S( N( R t has_private( R ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyR- s c C s
| i i S( N( R t size( R ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyR. s c C s t S( N( t False( R ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyt can_blind s c C s t S( N( R/ ( R ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyt can_encrypt s c C s t S( N( t True( R ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyt can_sign s c C s4 | i i | i i | i i | i i | i i f S( N( R R R R R R
R ( R ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/DSA.pyt publickey s c C sN h } xA | i D]6 } y t | i | | |