Your IP : 3.145.202.209


Current Path : /lib64/python2.7/site-packages/M2Crypto/
Upload File :
Current File : //lib64/python2.7/site-packages/M2Crypto/DSA.pyc

�

�1Mc@s�dZddlZddlZddlZddlZdefd��YZeje�ddd��YZdefd��YZ	ej
d	�Zd
�Zej
d�Zej
d�Zej
d
�Zej
d�Zej
d�Zej
d�ZdS(s�
    M2Crypto wrapper for OpenSSL DSA API.

    Copyright (c) 1999-2003 Ng Pheng Siong. All rights reserved.

    Portions created by Open Source Applications Foundation (OSAF) are
    Copyright (C) 2004 OSAF. All Rights Reserved.
i����NtDSAErrorcBseZRS((t__name__t
__module__(((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyR
stDSAcBs�eZdZejZdd�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zdejd�Zdejd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(sA
    This class is a context supporting DSA key and parameter
    values, signing and verifying.
    
    Simple example::
    
        from M2Crypto import EVP, DSA, util
        
        message = 'Kilroy was here!'
        md = EVP.MessageDigest('sha1')
        md.update(message)        
        digest = md.final()
        
        dsa = DSA.gen_params(1024)
        dsa.gen_key()
        r, s = dsa.sign(digest)
        good = dsa.verify(digest, r, s)
        if good:
            print '  ** success **'
        else:
            print '  ** verification failed **'
    icCs1tj|�std��||_||_dS(sI
        Use one of the factory functions to create an instance.
        s'dsa' type errorN(tm2tdsa_type_checktAssertionErrortdsat_pyfree(tselfRR((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyt__init__,s	cCs)t|dd�r%|j|j�ndS(NRi(tgetattrtm2_dsa_freeR(R	((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyt__del__4scCs.tj|j�std��tj|j�S(sp
        Return the key length.
    
        @rtype:   int
        @return:  the DSA key length in bits
        s'dsa' type error(RRRRt
dsa_keylen(R	((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyt__len__8scCsW|d	krMttd|f�}tj|j�s@td��||j�St�dS(
s5
        Return specified DSA parameters and key values.
    
        @type  name: str
        @param name: name of variable to be returned.  Must be 
                     one of 'p', 'q', 'g', 'pub', 'priv'.
        @rtype:      str
        @return:     value of specified variable (a "byte string")
        tptqtgtpubtprivs
dsa_get_%ss'dsa' type errorN(RRRRR(RRRRRtAttributeError(R	tnametmethod((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyt__getattr__Bs


cCsG|dkrtd��n(|d	kr6td��n
||j|<dS(
NRRRsset (p, q, g) via set_params()RRs"generate (pub, priv) via gen_key()(RRR(spubspriv(Rt__dict__(R	Rtvalue((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyt__setattr__Ss
cCs=tj|j|�tj|j|�tj|j|�dS(s�
        Set new parameters.
        
        @warning: This does not change the private key, so it may be
                  unsafe to use this method. It is better to use
                  gen_params function to create a new DSA object.
        N(Rt	dsa_set_pRt	dsa_set_qt	dsa_set_g(R	RRR((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyt
set_params[scCs2tj|j�std��tj|j�dS(s&
        Generate a key pair.
        s'dsa' type errorN(RRRRtdsa_gen_key(R	((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pytgen_keygscCs;tj|d�}tj|j|j��}|j�|S(s�
        Save the DSA parameters to a file.
    
        @type  filename: str
        @param filename: Save the DSA parameters to this file.
        @return:         1 (true) if successful
        twb(tBIOtopenfileRtdsa_write_params_bioRt_ptrtclose(R	tfilenametbiotret((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pytsave_paramsns
cCstj|j|j��S(s�
        Save DSA parameters to a BIO object.
    
        @type  bio: M2Crypto.BIO object
        @param bio: Save DSA parameters to this object.
        @return:    1 (true) if successful
        (RR%RR&(R	R)((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pytsave_params_bio{staes_128_cbccCs5tj|d�}|j|||�}|j�|S(sU
        Save the DSA key pair to a file.
    
        @type  filename: str
        @param filename: Save the DSA key pair to this file.
        @type  cipher:   str
        @param cipher:   name of symmetric key algorithm and mode
                         to encrypt the private key.
        @return:         1 (true) if successful
        R"(R#R$tsave_key_bioR'(R	R(tciphertcallbackR)R*((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pytsave_key�s
cCs�|dkr(tj|j|j�|�Stt|d�}|dkrYtd|��n	|�}tj|j|j�||�SdS(s[
        Save DSA key pair to a BIO object.
    
        @type  bio:    M2Crypto.BIO object
        @param bio:    Save DSA parameters to this object.
        @type  cipher: str
        @param cipher: name of symmetric key algorithm and mode
                       to encrypt the private key.
        @return:       1 (true) if successful
        sno such cipher: %sN(tNoneRtdsa_write_key_bio_no_cipherRR&RRtdsa_write_key_bio(R	R)R/R0tciph((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyR.�s	cCs/tj|d�}|j|�}|j�|S(s�
        Save the DSA public key (with parameters) to a file.
    
        @type  filename: str
        @param filename: Save DSA public key (with parameters) 
                         to this file.
        @return:         1 (true) if successful
        R"(R#R$tsave_pub_key_bioR'(R	R(R)R*((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pytsave_pub_key�s	
cCstj|j|j��S(s�
        Save DSA public key (with parameters) to a BIO object.
    
        @type  bio: M2Crypto.BIO object
        @param bio: Save DSA public key (with parameters) 
                    to this object.
        @return:  1 (true) if successful
        (Rtdsa_write_pub_key_bioRR&(R	R)((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyR6�s	cCs+|j�std��tj|j|�S(sK
        Sign the digest.
    
        @type  digest: str
        @param digest: SHA-1 hash of message (same as output 
                       from MessageDigest, a "byte string")
        @rtype:        tuple
        @return:       DSA signature, a tuple of two values, r and s,
                       both "byte strings".
        skey is not initialised(t	check_keyRRtdsa_signR(R	tdigest((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pytsign�scCs1|j�std��tj|j|||�S(s
        Verify a newly calculated digest against the signature 
        values r and s.
    
        @type  digest: str
        @param digest: SHA-1 hash of message (same as output 
                       from MessageDigest, a "byte string")
        @type  r:      str
        @param r:      r value of the signature, a "byte string"
        @type  s:      str
        @param s:      s value of the signature, a "byte string"
        @rtype:        int
        @return:       1 (true) if verify succeeded, 0 if failed
        skey is not initialised(R9RRt
dsa_verifyR(R	R;trts((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pytverify�scCs+|j�std��tj|j|�S(Nskey is not initialised(R9RRt
dsa_sign_asn1R(R	R;((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyt	sign_asn1�scCs.|j�std��tj|j||�S(Nskey is not initialised(R9RRtdsa_verify_asn1R(R	R;tblob((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pytverify_asn1�scCs.tj|j�std��tj|j�S(s�
        Check to be sure the DSA object has a valid private key.
    
        @rtype:   int
        @return:  1 (true) if a valid private key
        s'dsa' type error(RRRRt
dsa_check_key(R	((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyR9�s(RRt__doc__Rtdsa_freeRR
R
RRRRR!R+R,tutiltpassphrase_callbackR1R.R7R6R<R@RBRER9(((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyRs,			
					
	
						tDSA_pubcBs8eZdZd�ZeZd�ZejZej	Z
RS(s�
    This class is a DSA context that only supports a public key 
    and verification.  It does NOT support a private key or 
    signing.
    
    cGstd��dS(Ns!DSA_pub object has no private key(R(R	targv((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyR<scCstj|j�S(N(Rtdsa_check_pub_keyR(R	((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyR9s(RRRGR<RBR9RR7R1R6R.(((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyRK�s			cCs:tj||�}|dkr-td��nt|d�S(s�
    Factory function that generates DSA parameters and 
    instantiates a DSA object from the output.

    @type  bits: int
    @param bits: The length of the prime to be generated. If 
                 'bits' < 512, it is set to 512.
    @type  callback: function
    @param callback: A Python callback object that will be 
                 invoked during parameter generation; it usual 
                 purpose is to provide visual feedback.
    @rtype:   DSA
    @return:  instance of DSA.
    s!problem generating DSA parametersiN(Rtdsa_generate_parametersR2RR(tbitsR0R((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyt
gen_paramsscCsItj�}tj||�tj||�tj||�t|d�S(s8
    Factory function that instantiates a DSA object with DSA
    parameters.

    @type  p: str
    @param p: value of p, a "byte string"
    @type  q: str
    @param q: value of q, a "byte string"
    @type  g: str
    @param g: value of g, a "byte string"
    @rtype:   DSA
    @return:  instance of DSA.
    i(Rtdsa_newRRRR(RRRR((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyR&s
cCs,tj|�}t||�}|j�|S(s
    Factory function that instantiates a DSA object with DSA 
    parameters from a file.

    @type  file:     str
    @param file:     Names the file (a path) that contains the PEM 
                     representation of the DSA parameters. 
    @type  callback: A Python callable
    @param callback: A Python callback object that will be 
                     invoked if the DSA parameters file is 
                     passphrase-protected.
    @rtype:          DSA
    @return:         instance of DSA.
    (R#R$tload_params_bioR'(tfileR0R)R*((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pytload_params:s
cCs@tj|j�|�}|dkr3td��nt|d�S(s
    Factory function that instantiates a DSA object with DSA
    parameters from a M2Crypto.BIO object.

    @type  bio:      M2Crypto.BIO object
    @param bio:      Contains the PEM representation of the DSA 
                     parameters. 
    @type  callback: A Python callable
    @param callback: A Python callback object that will be 
                     invoked if the DSA parameters file is 
                     passphrase-protected.
    @rtype:          DSA
    @return:         instance of DSA.
    sproblem loading DSA parametersiN(Rtdsa_read_paramsR&R2RR(R)R0R((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyRROscCs,tj|�}t||�}|j�|S(s�
    Factory function that instantiates a DSA object from a
    PEM encoded DSA key pair.

    @type  file:     str
    @param file:     Names the file (a path) that contains the PEM 
                     representation of the DSA key pair. 
    @type  callback: A Python callable
    @param callback: A Python callback object that will be 
                     invoked if the DSA key pair is 
                     passphrase-protected.
    @rtype:          DSA
    @return:         instance of DSA.
    (R#R$tload_key_bioR'(RSR0R)R*((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pytload_keyds
cCs:tj|j�|�}|s-td��nt|d�S(s�
    Factory function that instantiates a DSA object from a
    PEM encoded DSA key pair.

    @type  bio:      M2Crypto.BIO object
    @param bio:      Contains the PEM representation of the DSA 
                     key pair. 
    @type  callback: A Python callable
    @param callback: A Python callback object that will be 
                     invoked if the DSA key pair is 
                     passphrase-protected.
    @rtype:          DSA
    @return:         instance of DSA.
    sproblem loading DSA key pairi(Rtdsa_read_keyR&RR(R)R0R((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyRVyscCs,tj|�}t||�}|j�|S(sg
    Factory function that instantiates a DSA_pub object using
    a DSA public key contained in PEM file.  The PEM file 
    must contain the parameters in addition to the public key.

    @type  file:     str
    @param file:     Names the file (a path) that contains the PEM 
                     representation of the DSA public key. 
    @type  callback: A Python callable
    @param callback: A Python callback object that will be 
                     invoked should the DSA public key be 
                     passphrase-protected.
    @rtype:          DSA_pub
    @return:         instance of DSA_pub.
    (R#R$tload_pub_key_bioR'(RSR0R)R*((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pytload_pub_key�s
cCs:tj|j�|�}|s-td��nt|d�S(se
    Factory function that instantiates a DSA_pub object using
    a DSA public key contained in PEM format.  The PEM 
    must contain the parameters in addition to the public key.

    @type  bio:      M2Crypto.BIO object
    @param bio:      Contains the PEM representation of the DSA 
                     public key (with params). 
    @type  callback: A Python callable
    @param callback: A Python callback object that will be 
                     invoked should the DSA public key be 
                     passphrase-protected.
    @rtype:          DSA_pub
    @return:         instance of DSA_pub.
    sproblem loading DSA public keyi(Rtdsa_read_pub_keyR&RRK(R)R0tdsapub((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyRY�s((RGtsysRIR#Rt	ExceptionRtdsa_initRRKtgenparam_callbackRPRRJRTRRRWRVRZRY(((s2/usr/lib64/python2.7/site-packages/M2Crypto/DSA.pyt<module>s$
�