HEX
Server: Apache
System: Linux aura.ambarhosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
User: chicagos (1295)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //lib/python2.7/site-packages/rsa/key.pyc
�
N$�_c@s�dZddlZddlZddlmZddlZddlZddlZddl	Zddl
Zeje�Z
dZdefd��YZdefd��YZd	efd
��YZejjed�Zd�Zd
�Zeed�Zeded�Zdd	dgZedkr�ddlZyex^ed�D]PZej�\ZZ erbPneddkrxes�edkr@deGHq@q@WWne!k
r�dGHq�XdGHndS(sjRSA key generation code.

Create new keys with the newkeys() function. It will give you a PublicKey and a
PrivateKey object.

Loading and saving keys requires the pyasn1 module. This module is imported as
late as possible, such that other functionality will remain working in absence
of pyasn1.

.. note::

    Storing public and private keys via the `pickle` module is possible.
    However, it is insecure to load a key from an untrusted source.
    The pickle module is not secure against erroneous or maliciously
    constructed data. Never unpickle data received from an untrusted
    or unauthenticated source.

i����N(trangeitAbstractKeycBs�eZdZdZd�Zed��Zed��Zd�Zd�Z	edd	��Z
ed
��Zdd�Z
d�Zd
�ZRS(s0Abstract superclass for private and public keys.tntecCs||_||_dS(N(RR(tselfRR((s+/usr/lib/python2.7/site-packages/rsa/key.pyt__init__8s	cCsdS(s�Loads a key in PKCS#1 PEM format, implement in a subclass.

        :param keyfile: contents of a PEM-encoded file that contains
            the public key.
        :type keyfile: bytes

        :return: the loaded key
        :rtype: AbstractKey
        N((tclstkeyfile((s+/usr/lib/python2.7/site-packages/rsa/key.pyt_load_pkcs1_pem<scCsdS(s�Loads a key in PKCS#1 PEM format, implement in a subclass.

        :param keyfile: contents of a DER-encoded file that contains
            the public key.
        :type keyfile: bytes

        :return: the loaded key
        :rtype: AbstractKey
        N((RR((s+/usr/lib/python2.7/site-packages/rsa/key.pyt_load_pkcs1_derHscCsdS(s�Saves the key in PKCS#1 PEM format, implement in a subclass.

        :returns: the PEM-encoded key.
        :rtype: bytes
        N((R((s+/usr/lib/python2.7/site-packages/rsa/key.pyt_save_pkcs1_pemTscCsdS(s�Saves the key in PKCS#1 DER format, implement in a subclass.

        :returns: the DER-encoded key.
        :rtype: bytes
        N((R((s+/usr/lib/python2.7/site-packages/rsa/key.pyt_save_pkcs1_der[stPEMcCs6i|jd6|jd6}|j||�}||�S(sNLoads a key in PKCS#1 DER or PEM format.

        :param keyfile: contents of a DER- or PEM-encoded file that contains
            the key.
        :type keyfile: bytes
        :param format: the format of the file to load; 'PEM' or 'DER'
        :type format: str

        :return: the loaded key
        :rtype: AbstractKey
        RtDER(RR	t_assert_format_exists(RRtformattmethodstmethod((s+/usr/lib/python2.7/site-packages/rsa/key.pyt
load_pkcs1bs


cCsUy||SWnBtk
rPdjt|j���}td||f��nXdS(sBChecks whether the given file format exists in 'methods'.
        s, s%Unsupported format: %r, try one of %sN(tKeyErrortjointsortedtkeyst
ValueError(tfile_formatRtformats((s+/usr/lib/python2.7/site-packages/rsa/key.pyRxs
	cCs3i|jd6|jd6}|j||�}|�S(s�Saves the key in PKCS#1 DER or PEM format.

        :param format: the format to save; 'PEM' or 'DER'
        :type format: str
        :returns: the DER- or PEM-encoded key.
        :rtype: bytes
        RR
(R
RR(RRRR((s+/usr/lib/python2.7/site-packages/rsa/key.pyt
save_pkcs1�s
	

cCs!|t||j|j�|jS(s�Performs blinding on the message using random number 'r'.

        :param message: the message, as integer, to blind.
        :type message: int
        :param r: the random number to blind with.
        :type r: int
        :return: the blinded message.
        :rtype: int

        The blinding is such that message = unblind(decrypt(blind(encrypt(message))).

        See https://en.wikipedia.org/wiki/Blinding_%28cryptography%29
        (tpowRR(Rtmessagetr((s+/usr/lib/python2.7/site-packages/rsa/key.pytblind�scCs!tjj||j�||jS(s�Performs blinding on the message using random number 'r'.

        :param blinded: the blinded message, as integer, to unblind.
        :param r: the random number to unblind with.
        :return: the original message.

        The blinding is such that message = unblind(decrypt(blind(encrypt(message))).

        See https://en.wikipedia.org/wiki/Blinding_%28cryptography%29
        (trsatcommontinverseR(RtblindedR((s+/usr/lib/python2.7/site-packages/rsa/key.pytunblind�s(RR(t__name__t
__module__t__doc__t	__slots__RtclassmethodRR	R
RRtstaticmethodRRRR#(((s+/usr/lib/python2.7/site-packages/rsa/key.pyR3s				t	PublicKeycBs�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
ed
��Zd�Z
ed��Zd
�Zed��Zed��ZRS(s�Represents a public RSA key.

    This key is also known as the 'encryption key'. It contains the 'n' and 'e'
    values.

    Supports attributes as well as dictionary-like access. Attribute access is
    faster, though.

    >>> PublicKey(5, 3)
    PublicKey(5, 3)

    >>> key = PublicKey(5, 3)
    >>> key.n
    5
    >>> key['n']
    5
    >>> key.e
    3
    >>> key['e']
    3

    RRcCs
t||�S(N(tgetattr(Rtkey((s+/usr/lib/python2.7/site-packages/rsa/key.pyt__getitem__�scCsd|j|jfS(NsPublicKey(%i, %i)(RR(R((s+/usr/lib/python2.7/site-packages/rsa/key.pyt__repr__�scCs|j|jfS(s&Returns the key as tuple for pickling.(RR(R((s+/usr/lib/python2.7/site-packages/rsa/key.pyt__getstate__�scCs|\|_|_dS(sSets the key from tuple.N(RR(Rtstate((s+/usr/lib/python2.7/site-packages/rsa/key.pyt__setstate__�scCsE|dkrtSt|t�s#tS|j|jkoD|j|jkS(N(tNonetFalset
isinstanceR*RR(Rtother((s+/usr/lib/python2.7/site-packages/rsa/key.pyt__eq__�s
cCs||kS(N((RR5((s+/usr/lib/python2.7/site-packages/rsa/key.pyt__ne__�scCst|j|jf�S(N(thashRR(R((s+/usr/lib/python2.7/site-packages/rsa/key.pyt__hash__�scCseddlm}ddlm}|j|d|��\}}|dt|d�dt|d��S(	s�Loads a key in PKCS#1 DER format.

        :param keyfile: contents of a DER-encoded file that contains the public
            key.
        :return: a PublicKey object

        First let's construct a DER encoded key:

        >>> import base64
        >>> b64der = 'MAwCBQCNGmYtAgMBAAE='
        >>> der = base64.standard_b64decode(b64der)

        This loads the file:

        >>> PublicKey._load_pkcs1_der(der)
        PublicKey(2367317549, 65537)

        i����(tdecoder(t	AsnPubKeytasn1SpecRtmodulusRtpublicExponent(tpyasn1.codec.derR:trsa.asn1R;tdecodetint(RRR:R;tprivt_((s+/usr/lib/python2.7/site-packages/rsa/key.pyR	�scCs\ddlm}ddlm}|�}|jd|j�|jd|j�|j|�S(sxSaves the public key in PKCS#1 DER format.

        :returns: the DER-encoded public key.
        :rtype: bytes
        i����(tencoder(R;R=R>(R?RER@R;tsetComponentByNameRRtencode(RRER;tasn_key((s+/usr/lib/python2.7/site-packages/rsa/key.pyRs	cCs"tjj|d�}|j|�S(sOLoads a PKCS#1 PEM-encoded public key file.

        The contents of the file before the "-----BEGIN RSA PUBLIC KEY-----" and
        after the "-----END RSA PUBLIC KEY-----" lines is ignored.

        :param keyfile: contents of a PEM-encoded file that contains the public
            key.
        :return: a PublicKey object
        sRSA PUBLIC KEY(Rtpemtload_pemR	(RRtder((s+/usr/lib/python2.7/site-packages/rsa/key.pyRscCs|j�}tjj|d�S(s�Saves a PKCS#1 PEM-encoded public key file.

        :return: contents of a PEM-encoded file that contains the public key.
        :rtype: bytes
        sRSA PUBLIC KEY(RRRItsave_pem(RRK((s+/usr/lib/python2.7/site-packages/rsa/key.pyR
'scCs"tjj|d�}|j|�S(s�Loads a PKCS#1.5 PEM-encoded public key file from OpenSSL.

        These files can be recognised in that they start with BEGIN PUBLIC KEY
        rather than BEGIN RSA PUBLIC KEY.

        The contents of the file before the "-----BEGIN PUBLIC KEY-----" and
        after the "-----END PUBLIC KEY-----" lines is ignored.

        :param keyfile: contents of a PEM-encoded file that contains the public
            key, from OpenSSL.
        :type keyfile: bytes
        :return: a PublicKey object
        s
PUBLIC KEY(RRIRJtload_pkcs1_openssl_der(RRRK((s+/usr/lib/python2.7/site-packages/rsa/key.pytload_pkcs1_openssl_pem1scCs�ddlm}ddlm}ddlm}|j|d|��\}}|dd|jd�krztd	��n|j	|d
d�S(s�Loads a PKCS#1 DER-encoded public key file from OpenSSL.

        :param keyfile: contents of a DER-encoded file that contains the public
            key, from OpenSSL.
        :return: a PublicKey object
        :rtype: bytes

        i����(t
OpenSSLPubKey(R:(tunivR<theadertoids1.2.840.113549.1.1.1s7This is not a DER-encoded OpenSSL-compatible public keyR,i(
R@ROR?R:tpyasn1.typeRPRAtObjectIdentifiert	TypeErrorR	(RRROR:RPtkeyinfoRD((s+/usr/lib/python2.7/site-packages/rsa/key.pyRMDs(RR(R$R%R&R'R-R.R/R1R6R7R9R(R	RRR
RNRM(((s+/usr/lib/python2.7/site-packages/rsa/key.pyR*�s										
t
PrivateKeycBs�eZdZdZd	�Zd
�Zd�Zd�Zd
�Zd�Z	d�Z
d�Zd�Zd�Z
d�Zed��Zd�Zed��Zd�ZRS(sRepresents a private RSA key.

    This key is also known as the 'decryption key'. It contains the 'n', 'e',
    'd', 'p', 'q' and other values.

    Supports attributes as well as dictionary-like access. Attribute access is
    faster, though.

    >>> PrivateKey(3247, 65537, 833, 191, 17)
    PrivateKey(3247, 65537, 833, 191, 17)

    exp1, exp2 and coef will be calculated:

    >>> pk = PrivateKey(3727264081, 65537, 3349121513, 65063, 57287)
    >>> pk.exp1
    55063
    >>> pk.exp2
    10095
    >>> pk.coef
    50797

    RRtdtptqtexp1texp2tcoefcCsxtj|||�||_||_||_t||d�|_t||d�|_tj	j
||�|_dS(Ni(RRRXRYRZRBR[R\RR R!R](RRRRXRYRZ((s+/usr/lib/python2.7/site-packages/rsa/key.pyRus			cCs
t||�S(N(R+(RR,((s+/usr/lib/python2.7/site-packages/rsa/key.pyR-�scCsd|S(Ns-PrivateKey(%(n)i, %(e)i, %(d)i, %(p)i, %(q)i)((R((s+/usr/lib/python2.7/site-packages/rsa/key.pyR.�scCs4|j|j|j|j|j|j|j|jfS(s&Returns the key as tuple for pickling.(RRRXRYRZR[R\R](R((s+/usr/lib/python2.7/site-packages/rsa/key.pyR/�sc	Cs:|\|_|_|_|_|_|_|_|_dS(sSets the key from tuple.N(RRRXRYRZR[R\R](RR0((s+/usr/lib/python2.7/site-packages/rsa/key.pyR1�sc	Cs�|dkrtSt|t�s#tS|j|jko�|j|jko�|j|jko�|j|jko�|j|jko�|j	|j	ko�|j
|j
ko�|j|jkS(N(R2R3R4RWRRRXRYRZR[R\R](RR5((s+/usr/lib/python2.7/site-packages/rsa/key.pyR6�scCs||kS(N((RR5((s+/usr/lib/python2.7/site-packages/rsa/key.pyR7�sc	Cs:t|j|j|j|j|j|j|j|jf�S(N(	R8RRRXRYRZR[R\R](R((s+/usr/lib/python2.7/site-packages/rsa/key.pyR9�scCs\xItd�D];}tjj|jd�}tjj|j|�r
|Sq
Wtd��dS(Ni�isunable to find blinding factor(RRtrandnumtrandintRtprimetare_relatively_primetRuntimeError(RRDtblind_r((s+/usr/lib/python2.7/site-packages/rsa/key.pyt_get_blinding_factor�s
cCsL|j�}|j||�}tjj||j|j�}|j||�S(s�Decrypts the message using blinding to prevent side-channel attacks.

        :param encrypted: the encrypted message
        :type encrypted: int

        :returns: the decrypted message
        :rtype: int
        (RdRRtcoretdecrypt_intRXRR#(Rt	encryptedRcR"t	decrypted((s+/usr/lib/python2.7/site-packages/rsa/key.pytblinded_decrypt�s
cCsL|j�}|j||�}tjj||j|j�}|j||�S(s�Encrypts the message using blinding to prevent side-channel attacks.

        :param message: the message to encrypt
        :type message: int

        :returns: the encrypted message
        :rtype: int
        (RdRRRetencrypt_intRXRR#(RRRcR"Rg((s+/usr/lib/python2.7/site-packages/rsa/key.pytblinded_encrypt�s
c
Cs�ddlm}|j|�\}}|ddkrLtd|d��ntt|dd!�}||�}tt|dd!�\}}}	|j|j|jf|||	fkr�t	j
dt�n|S(	s4Loads a key in PKCS#1 DER format.

        :param keyfile: contents of a DER-encoded file that contains the private
            key.
        :type keyfile: bytes
        :return: a PrivateKey object

        First let's construct a DER encoded key:

        >>> import base64
        >>> b64der = 'MC4CAQACBQDeKYlRAgMBAAECBQDHn4npAgMA/icCAwDfxwIDANcXAgInbwIDAMZt'
        >>> der = base64.standard_b64decode(b64der)

        This loads the file:

        >>> PrivateKey._load_pkcs1_der(der)
        PrivateKey(3727264081, 65537, 3349121513, 65063, 57287)

        i����(R:is)Unable to read this file, version %s != 0iii	sYou have provided a malformed keyfile. Either the exponents or the coefficient are incorrect. Using the correct values instead.(R?R:RARtmapRBR[R\R]twarningstwarntUserWarning(
RRR:RCRDtas_intsR,R[R\R]((s+/usr/lib/python2.7/site-packages/rsa/key.pyR	�s'
csddlm�m�ddlm}d�jf��fd��Y}|�}|jdd�|jd|j�|jd	|j�|jd
|j	�|jd|j
�|jd|j�|jd
|j�|jd|j
�|jd|j�|j|�S(szSaves the private key in PKCS#1 DER format.

        :returns: the DER-encoded private key.
        :rtype: bytes
        i����(RPt	namedtype(REt
AsnPrivKeycs�eZ�j�jd�j���jd�j���jd�j���jd�j���jd�j���jd�j���jd�j���jd�j���jd�j���	ZRS(	tversionR=R>tprivateExponenttprime1tprime2t	exponent1t	exponent2tcoefficient(R$R%t
NamedTypest	NamedTypetIntegert
componentType((RqRP(s+/usr/lib/python2.7/site-packages/rsa/key.pyRrsRsiR=R>RtRuRvRwRxRy(RSRPRqR?REtSequenceRFRRRXRYRZR[R\R]RG(RRERrRH((RqRPs+/usr/lib/python2.7/site-packages/rsa/key.pyRs"	cCs"tjj|d�}|j|�S(sqLoads a PKCS#1 PEM-encoded private key file.

        The contents of the file before the "-----BEGIN RSA PRIVATE KEY-----" and
        after the "-----END RSA PRIVATE KEY-----" lines is ignored.

        :param keyfile: contents of a PEM-encoded file that contains the private
            key.
        :type keyfile: bytes
        :return: a PrivateKey object
        sRSA PRIVATE KEY(RRIRJR	(RRRK((s+/usr/lib/python2.7/site-packages/rsa/key.pyR)s
cCs|j�}tjj|d�S(s�Saves a PKCS#1 PEM-encoded private key file.

        :return: contents of a PEM-encoded file that contains the private key.
        :rtype: bytes
        sRSA PRIVATE KEY(RRRIRL(RRK((s+/usr/lib/python2.7/site-packages/rsa/key.pyR
9s(RRRXRYRZsexp1sexp2scoef(R$R%R&R'RR-R.R/R1R6R7R9RdRiRkR(R	RRR
(((s+/usr/lib/python2.7/site-packages/rsa/key.pyRW[s"											:	%c
s�|d�|d}||}||}tjd|�||�}tjd|�||�}��fd�}t}	x;|||�s�|	r�||�}n||�}|	}	q{Wt||�t||�fS(s%Returns a tuple of two different primes of nbits bits each.

    The resulting p * q has exacty 2 * nbits bits, and the returned p and q
    will not be equal.

    :param nbits: the number of bits in each of p and q.
    :param getprime_func: the getprime function, defaults to
        :py:func:`rsa.prime.getprime`.

        *Introduced in Python-RSA 3.1*

    :param accurate: whether to enable accurate mode or not.
    :returns: (p, q), where p > q

    >>> (p, q) = find_p_q(128)
    >>> from rsa import common
    >>> common.bit_size(p * q)
    256

    When not in accurate mode, the number of bits can be slightly less

    >>> (p, q) = find_p_q(128, accurate=False)
    >>> from rsa import common
    >>> common.bit_size(p * q) <= 256
    True
    >>> common.bit_size(p * q) > 240
    True

    iisfind_p_q(%i): Finding psfind_p_q(%i): Finding qcs:||krtS�stStjj||�}�|kS(s�Returns True iff p and q are acceptable:

            - p and q differ
            - (p * q) has the right nr of bits (when accurate=True)
        (R3tTrueRR tbit_size(RYRZt
found_size(taccuratet
total_bits(s+/usr/lib/python2.7/site-packages/rsa/key.pyt
is_acceptableqs(tlogtdebugR3tmaxtmin(
tnbitst
getprime_funcR�tshifttpbitstqbitsRYRZR�tchange_p((R�R�s+/usr/lib/python2.7/site-packages/rsa/key.pytfind_p_qDs 



c	Cs�|d|d}ytjj||�}WnJtjjk
rw}tjj|||jdd|||jf��nX|||dkr�td|||f��n||fS(s�Calculates an encryption and a decryption key given p, q and an exponent,
    and returns them as a tuple (e, d)

    :param p: the first large prime
    :param q: the second large prime
    :param exponent: the exponent for the key; only change this if you know
        what you're doing, as the exponent influences how difficult your
        private key can be cracked. A very common choice for e is 65537.
    :type exponent: int

    itmsgs;e (%d) and phi_n (%d) are not relatively prime (divider=%i)s6e (%d) and d (%d) are not mult. inv. modulo phi_n (%d)(RR R!tNotRelativePrimeErrorRXR(RYRZtexponenttphi_nRXtex((s+/usr/lib/python2.7/site-packages/rsa/key.pytcalculate_keys_custom_exponent�s
	cCst||t�S(s�Calculates an encryption and a decryption key given p and q, and
    returns them as a tuple (e, d)

    :param p: the first large prime
    :param q: the second large prime

    :return: tuple (e, d) with the encryption and decryption exponents.
    (R�tDEFAULT_EXPONENT(RYRZ((s+/usr/lib/python2.7/site-packages/rsa/key.pytcalculate_keys�s
cCsmxZtr\t|d||�\}}y t||d|�\}}PWqtk
rXqXqW||||fS(sWGenerate RSA keys of nbits bits. Returns (p, q, e, d).

    Note: this can take a long time, depending on the key size.

    :param nbits: the total number of bits in ``p`` and ``q``. Both ``p`` and
        ``q`` will use ``nbits/2`` bits.
    :param getprime_func: either :py:func:`rsa.prime.getprime` or a function
        with similar signature.
    :param exponent: the exponent for the key; only change this if you know
        what you're doing, as the exponent influences how difficult your
        private key can be cracked. A very common choice for e is 65537.
    :type exponent: int
    iR�(RR�R�R(R�R�R�R�RYRZRRX((s+/usr/lib/python2.7/site-packages/rsa/key.pytgen_keys�s	
icCs�|dkrtd��n|dkr:td|��n|dkr}ddlm}ddl}|j|jd|�}ntjj}t||d	|d
|�\}}}	}
||}t||	�t	||	|
||�fS(s�Generates public and private keys, and returns them as (pub, priv).

    The public key is also known as the 'encryption key', and is a
    :py:class:`rsa.PublicKey` object. The private key is also known as the
    'decryption key' and is a :py:class:`rsa.PrivateKey` object.

    :param nbits: the number of bits required to store ``n = p*q``.
    :param accurate: when True, ``n`` will have exactly the number of bits you
        asked for. However, this makes key generation much slower. When False,
        `n`` may have slightly less bits.
    :param poolsize: the number of processes to use to generate the prime
        numbers. If set to a number > 1, a parallel algorithm will be used.
        This requires Python 2.6 or newer.
    :param exponent: the exponent for the key; only change this if you know
        what you're doing, as the exponent influences how difficult your
        private key can be cracked. A very common choice for e is 65537.
    :type exponent: int

    :returns: a tuple (:py:class:`rsa.PublicKey`, :py:class:`rsa.PrivateKey`)

    The ``poolsize`` parameter was added in *Python-RSA 3.1* and requires
    Python 2.6 or newer.

    is
Key too smallisPool size (%i) should be >= 1i����(tparallelNtpoolsizeR�R�(
RRR�t	functoolstpartialtgetprimeR`R�R*RW(R�R�R�R�R�R�R�RYRZRRXR((s+/usr/lib/python2.7/site-packages/rsa/key.pytnewkeys�s'
R�t__main__idi
is%i timestAborteds
Doctests done("R&tloggingRmtrsa._compatRt	rsa.primeRtrsa.pemt
rsa.commontrsa.randnumtrsa.coret	getLoggerR$R�R�tobjectRR*RWR`R�RR�R�R�R�R�t__all__tdoctesttcountttestmodtfailurestteststKeyboardInterrupt(((s+/usr/lib/python2.7/site-packages/rsa/key.pyt<module>"s>���N		
5"