Your IP : 3.14.255.237


Current Path : /lib64/python2.7/site-packages/M2Crypto/
Upload File :
Current File : //lib64/python2.7/site-packages/M2Crypto/RSA.pyo

�

�1Mc@s"dZddlZddlZddlZddlZddlZdefd��YZeje�ej	Z	ej
Z
ejZejZddd��YZ
de
fd��YZd	�Zejd
�Zed�Zejd�Zejd
�Zejd�Zd�Zd�Zd�ZdS(scM2Crypto wrapper for OpenSSL RSA API.

Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved.i����NtRSAErrorcBseZRS((t__name__t
__module__(((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyRstRSAcBs
eZdZejZdd�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zdejd�Zdejd
�ZeZdejd�Zd�Zd�Zd�Zd�Zd�Zddd�Zddd�Zdd�Zdd�ZRS(s
    RSA Key Pair.
    icCs||_||_dS(N(trsat_pyfree(tselfRR((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyt__init__s	cCs)t|dd�r%|j|j�ndS(NRi(tgetattrtm2_rsa_freeR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyt__del__scCstj|j�d>S(Ni(tm2trsa_sizeR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyt__len__"scCsB|dkrtj|j�S|dkr8tj|j�St�dS(Ntetn(Rt	rsa_get_eRt	rsa_get_ntAttributeError(Rtname((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyt__getattr__%s
cCs"tj|j�tj|j�fS(N(RRRR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytpub-scCstj|j||�S(N(Rtrsa_public_encryptR(Rtdatatpadding((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytpublic_encrypt1scCstj|j||�S(N(Rtrsa_public_decryptR(RRR((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytpublic_decrypt5scCstj|j||�S(N(Rtrsa_private_encryptR(RRR((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytprivate_encrypt9scCstj|j||�S(N(Rtrsa_private_decryptR(RRR((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytprivate_decrypt=staes_128_cbccCs�|dkr(tj|j|j�|�Stt|d�}|dkrVtd|�n	|�}tj|j|j�||�SdS(sR
        Save the key pair to an M2Crypto.BIO.BIO object in PEM format.

        @type bio: M2Crypto.BIO.BIO
        @param bio: M2Crypto.BIO.BIO object to save key to.

        @type cipher: string
        @param cipher: Symmetric cipher to protect the key. The default
        cipher is 'aes_128_cbc'. If cipher is None, then the key is saved
        in the clear.

        @type callback: Python callable
        @param callback: A Python callable object that is invoked
        to acquire a passphrase with which to protect the key.
        The default is util.passphrase_callback.
        snot such cipher %sN(tNoneRtrsa_write_key_no_cipherRt_ptrRRt
rsa_write_key(Rtbiotciphertcallbacktciph((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytsave_key_bioAs	cCs%tj|d�}|j|||�S(s+
        Save the key pair to a file in PEM format.

        @type file: string
        @param file: Name of file to save key to.

        @type cipher: string
        @param cipher: Symmetric cipher to protect the key. The default
        cipher is 'aes_128_cbc'. If cipher is None, then the key is saved
        in the clear.

        @type callback: Python callable
        @param callback: A Python callable object that is invoked
        to acquire a passphrase with which to protect the key.
        The default is util.passphrase_callback.
        twb(tBIOtopenfileR)(RtfileR&R'R%((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytsave_key\scCs)tj�}|j|||�|j�S(sB
        Returns the key(pair) as a string in PEM format.
        (R+tMemoryBufferR)tread(RR&R'R%((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytas_pemrscCstj|j|j��S(s�
        Save the key pair to an M2Crypto.BIO.BIO object in DER format.

        @type bio: M2Crypto.BIO.BIO
        @param bio: M2Crypto.BIO.BIO object to save key to.
        (Rtrsa_write_key_derRR#(RR%((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytsave_key_der_biozscCstj|d�}|j|�S(s�
        Save the key pair to a file in DER format.

        @type file: str
        @param file: Filename to save key to
        R*(R+R,R3(RR-R%((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytsave_key_der�scCstj|j|j��S(s�
        Save the public key to an M2Crypto.BIO.BIO object in PEM format.

        @type bio: M2Crypto.BIO.BIO
        @param bio: M2Crypto.BIO.BIO object to save key to.
        (Rtrsa_write_pub_keyRR#(RR%((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytsave_pub_key_bio�scCs+tj|d�}tj|j|j��S(s�
        Save the public key to a file in PEM format.

        @type file: string
        @param file: Name of file to save key to.
        R*(R+R,RR5RR#(RR-R%((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytsave_pub_key�scCstj|j�S(N(Rt
rsa_check_keyR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyt	check_key�stsha1icCsbtt|d�}|dkr1tdt��ntj|j||�|�}|j|tj�S(s�
        Signs a digest with the private key using RSASSA-PSS
        
        @requires: OpenSSL 0.9.7h or later.

        @type digest: str
        @param digest: A digest created by using the digest method

        @type salt_length: int
        @param salt_length: The length of the salt to use
        
        @type algo: str
        @param algo: The hash algorithm to use

        @return: a string which is the signature
        snot such hash algorithm %sN(	RRR!t
ValueErrort	hash_algotrsa_padding_add_pkcs1_pssRRt
no_padding(Rtdigesttalgotsalt_lengththasht	signature((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytsign_rsassa_pss�s
cCsett|d�}|dkr1tdt��n|j|tj�}tj|j|||�|�S(s
        Verifies the signature RSASSA-PSS

        @requires: OpenSSL 0.9.7h or later.

        @type data: str
        @param data: Data that has been signed

        @type signature: str
        @param signature: The signature signed with RSASSA-PSS
        
        @type salt_length: int
        @param salt_length: The length of the salt that was used

        @type algo: str
        @param algo: The hash algorithm to use

        @return: 1 or 0, depending on whether the signature was
        verified or not.  
        snot such hash algorithm %sN(	RRR!R;R<RR>trsa_verify_pkcs1_pssR(RRRCR@RARBtplain_signature((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytverify_rsassa_pss�s
cCsJttd|d�}|dkr4td|f�ntj|j||�S(st
        Signs a digest with the private key

        @type digest: str
        @param digest: A digest created by using the digest method

        @type algo: str
        @param algo: The method that created the digest.
        Legal values are 'sha1','sha224', 'sha256', 'ripemd160', 
        and 'md5'.
        
        @return: a string which is the signature
        tNID_sunknown algorithmN(RRR!R;trsa_signR(RR?R@tdigest_type((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytsign�scCsMttd|d�}|dkr4td|f�ntj|j|||�S(s

        Verifies the signature with the public key

        @type data: str
        @param data: Data that has been signed

        @type signature: str
        @param signature: The signature signed with the private key

        @type algo: str
        @param algo: The method use to create digest from the data 
        before it was signed.  Legal values are 'sha1','sha224',
        'sha256', 'ripemd160', and 'md5'.

        @return: True or False, depending on whether the signature was
        verified.  
        RHsunknown algorithmN(RRR!R;t
rsa_verifyR(RRRCR@RJ((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytverify�s(RRt__doc__Rtrsa_freeR	RR
R
RRRRRRtutiltpassphrase_callbackR)R.tsave_pemR1R3R4R6R7R9RDRGRKRM(((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyRs0												
			
	tRSA_pubcBsDeZdZd�Zd�Zd�Zd�Zd�Zd�ZRS(s0
    Object interface to an RSA public key.
    cCs)|dkrtd�n
||j|<dS(NRRs0use factory function new_pub_key() to set (e, n)(RR(Rt__dict__(RRtvalue((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyt__setattr__s	cGs
td�dS(Ns!RSA_pub object has no private key(R(Rtargv((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyRscGs
td�dS(Ns!RSA_pub object has no private key(R(RRW((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyRscOs
|j|�S(s*
        Save public key to file.
        (R7(RR-targstkw((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyR.scOs
|j|�S(s)
        Save public key to BIO.
        (R6(RR%RXRY((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyR)scCstj|j�S(N(Rtrsa_check_pub_keyR(R((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyR9)s(	RRRNRVRRR.R)R9(((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyRSs					
cCsttjtj���dS(N(RRterr_reason_error_stringt
err_get_error(((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyt	rsa_error-scCs1ddddg}|j||�|j�dS(s)
    Default callback for gen_key().
    t.t+t*s
N(twritetflush(tpRtouttch((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytkeygen_callback1scCsttj|||�d�S(s�
    Generate an RSA key pair.

    @type bits: int
    @param bits: Key length, in bits.

    @type e: int
    @param e: The RSA public exponent.

    @type callback: Python callable
    @param callback: A Python callable object that is invoked
    during key generation; its usual purpose is to provide visual
    feedback. The default callback is keygen_callback.

    @rtype: M2Crypto.RSA.RSA
    @return: M2Crypto.RSA.RSA object.
    i(RRtrsa_generate_key(tbitsRR'((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytgen_key:scCstj|�}t||�S(s�
    Load an RSA key pair from file.

    @type file: string
    @param file: Name of file containing RSA public key in PEM format.

    @type callback: Python callable
    @param callback: A Python callable object that is invoked
    to acquire a passphrase with which to unlock the key.
    The default is util.passphrase_callback.

    @rtype: M2Crypto.RSA.RSA
    @return: M2Crypto.RSA.RSA object.
    (R+R,tload_key_bio(R-R'R%((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytload_keyOscCs;tj|j�|�}|dkr.t�nt|d�S(s�
    Load an RSA key pair from an M2Crypto.BIO.BIO object.

    @type bio: M2Crypto.BIO.BIO
    @param bio: M2Crypto.BIO.BIO object containing RSA key pair in PEM
    format.

    @type callback: Python callable
    @param callback: A Python callable object that is invoked
    to acquire a passphrase with which to unlock the key.
    The default is util.passphrase_callback.

    @rtype: M2Crypto.RSA.RSA
    @return: M2Crypto.RSA.RSA object.
    iN(Rtrsa_read_keyR#R!R]R(R%R'R((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyRjbs
cCstj|�}t||�S(s�
    Load an RSA key pair from a string.

    @type string: string
    @param string: String containing RSA key pair in PEM format.

    @type callback: Python callable
    @param callback: A Python callable object that is invoked
    to acquire a passphrase with which to unlock the key.
    The default is util.passphrase_callback.

    @rtype: M2Crypto.RSA.RSA
    @return: M2Crypto.RSA.RSA object.
    (R+R/Rj(tstringR'R%((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytload_key_stringxscCstj|�}t|�S(s�
    Load an RSA public key from file.

    @type file: string
    @param file: Name of file containing RSA public key in PEM format.

    @rtype: M2Crypto.RSA.RSA_pub
    @return: M2Crypto.RSA.RSA_pub object.
    (R+R,tload_pub_key_bio(R-R%((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytload_pub_key�s
cCs8tj|j��}|dkr+t�nt|d�S(s
    Load an RSA public key from an M2Crypto.BIO.BIO object.

    @type bio: M2Crypto.BIO.BIO
    @param bio: M2Crypto.BIO.BIO object containing RSA public key in PEM
    format.

    @rtype: M2Crypto.RSA.RSA_pub
    @return: M2Crypto.RSA.RSA_pub object.
    iN(Rtrsa_read_pub_keyR#R!R]RS(R%R((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyRo�s
cCsE|\}}tj�}tj||�tj||�t|d�S(s�
    Instantiate an RSA_pub object from an (e, n) tuple.

    @type e: string
    @param e: The RSA public exponent; it is a string in OpenSSL's MPINT 
    format - 4-byte big-endian bit-count followed by the appropriate 
    number of bits.

    @type n: string
    @param n: The RSA composite of primes; it is a string in OpenSSL's MPINT 
    format - 4-byte big-endian bit-count followed by the appropriate 
    number of bits.

    @rtype: M2Crypto.RSA.RSA_pub
    @return: M2Crypto.RSA.RSA_pub object.
    i(Rtrsa_newt	rsa_set_et	rsa_set_nRS(t.0RRR((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pytnew_pub_key�s
	((RNtsysRPR+tErrRt	ExceptionRtrsa_initR>t
pkcs1_paddingtsslv23_paddingtpkcs1_oaep_paddingRRSR]tstdoutRfRiRQRkRjRnRpRoRv(((s2/usr/lib64/python2.7/site-packages/M2Crypto/RSA.pyt<module>s&0
				�'