/usr/lib/python2.6/site-packages/rsa
NameSizeModeActions
asn1.py17810644editdlrm
asn1.pyc16530644editdlrm
asn1.pyo16530644editdlrm
bigfile.py51850644editdlrm
bigfile.pyc47860644editdlrm
bigfile.pyo47860644editdlrm
cli.py121850644editdlrm
cli.pyc133190644editdlrm
cli.pyo133190644editdlrm
common.py46400644editdlrm
common.pyc42350644editdlrm
common.pyo42350644editdlrm
core.py16560644editdlrm
core.pyc14850644editdlrm
core.pyo14850644editdlrm
key.py228670644editdlrm
key.pyc239860644editdlrm
key.pyo239860644editdlrm
parallel.py22990644editdlrm
parallel.pyc20980644editdlrm
parallel.pyo20980644editdlrm
pem.py35370644editdlrm
pem.pyc28430644editdlrm
pem.pyo28430644editdlrm
pkcs1.py122300644editdlrm
pkcs1.pyc111730644editdlrm
pkcs1.pyo111260644editdlrm
prime.py45600644editdlrm
prime.pyc36640644editdlrm
prime.pyo36180644editdlrm
randnum.py26430644editdlrm
randnum.pyc20740644editdlrm
randnum.pyo20740644editdlrm
transform.py68920644editdlrm
transform.pyc58560644editdlrm
transform.pyo58560644editdlrm
util.py30590644editdlrm
util.pyc25200644editdlrm
util.pyo24490644editdlrm
varblock.py54060644editdlrm
varblock.pyc48560644editdlrm
varblock.pyo48560644editdlrm
_compat.py38900644editdlrm
_compat.pyc36550644editdlrm
_compat.pyo36550644editdlrm
_version133.py117640644editdlrm
_version133.pyc136390644editdlrm
_version133.pyo136390644editdlrm
_version200.py151230644editdlrm
_version200.pyc152640644editdlrm
_version200.pyo152640644editdlrm
__init__.py14760644editdlrm
__init__.pyc11120644editdlrm
__init__.pyo11120644editdlrm
Edit: /usr/lib/python2.6/site-packages/rsa/key.pyo (23986B)
Ñò |~úVc@s¸dZddkZddklZddkZddkZddkZddkZddk Zei e ƒZ dZ defd„ƒYZdefd„ƒYZd efd „ƒYZeiied „Zd „Zd „Zee d„Zede d„Zdd dgZe djo›ddkZykxdedƒD]VZeiƒ\ZZ eoPneoeddjp edjo deGHq5q5WWne!j o 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(tbit AbstractKeycBs\eZdZd Zd„Zedd„ƒZed„ƒZdd„Z d„Z d „Z RS( s0Abstract superclass for private and public keys.tntecCs||_||_dS(N(RR(tselfRR((s+/usr/lib/python2.6/site-packages/rsa/key.pyt__init__6s tPEMcCs6h|id6|id6}|i||ƒ}||ƒS(sLoads a key in PKCS#1 DER or PEM format. :param keyfile: contents of a DER- or PEM-encoded file that contains the public key. :param format: the format of the file to load; 'PEM' or 'DER' :return: a PublicKey object RtDER(t_load_pkcs1_pemt_load_pkcs1_dert_assert_format_exists(tclstkeyfiletformattmethodstmethod((s+/usr/lib/python2.6/site-packages/rsa/key.pyt load_pkcs1:s   cCsWy ||SWnDtj o8dit|iƒƒƒ}td||fƒ‚nXdS(sBChecks whether the given file format exists in 'methods'. s, s%Unsupported format: %r, try one of %sN(tKeyErrortjointsortedtkeyst ValueError(t file_formatRtformats((s+/usr/lib/python2.6/site-packages/rsa/key.pyR Ms   cCs3h|id6|id6}|i||ƒ}|ƒS(s«Saves the public key in PKCS#1 DER or PEM format. :param format: the format to save; 'PEM' or 'DER' :returns: the DER- or PEM-encoded public key. RR(t_save_pkcs1_pemt_save_pkcs1_derR (RR RR((s+/usr/lib/python2.6/site-packages/rsa/key.pyt save_pkcs1Ys   cCs!|t||i|iƒ|iS(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.6/site-packages/rsa/key.pytblindhscCs!tii||iƒ||iS(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.6/site-packages/rsa/key.pytunblindys (RR( t__name__t __module__t__doc__t __slots__Rt classmethodRt staticmethodR RRR#(((s+/usr/lib/python2.6/site-packages/rsa/key.pyR1s   t PublicKeycBs˜eZdZdZd„Zd„Zd„Zd„Zd„Zd„Z e d „ƒZ d „Z e d „ƒZ d „Ze d „ƒZe d„ƒ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 accesss 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.6/site-packages/rsa/key.pyt __getitem__¢scCsd|i|ifS(NsPublicKey(%i, %i)(RR(R((s+/usr/lib/python2.6/site-packages/rsa/key.pyt__repr__¥scCs|i|ifS(s&Returns the key as tuple for pickling.(RR(R((s+/usr/lib/python2.6/site-packages/rsa/key.pyt __getstate__¨scCs|\|_|_dS(sSets the key from tuple.N(RR(Rtstate((s+/usr/lib/python2.6/site-packages/rsa/key.pyt __setstate__¬scCsJ|djotSt|tƒptS|i|ijo|i|ijS(N(tNonetFalset isinstanceR*RR(Rtother((s+/usr/lib/python2.6/site-packages/rsa/key.pyt__eq__°s  cCs ||j S(N((RR5((s+/usr/lib/python2.6/site-packages/rsa/key.pyt__ne__¹sc Cseddkl}ddkl}|i|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.derR8trsa.asn1R9tdecodetint(R R R8R9tprivt_((s+/usr/lib/python2.6/site-packages/rsa/key.pyR ¼scCs\ddkl}ddkl}|ƒ}|id|iƒ|id|iƒ|i|ƒS(sbSaves the public key in PKCS#1 DER format. @returns: the DER-encoded public key. iÿÿÿÿ(tencoder(R9R;R<(R=RCR>R9tsetComponentByNameRRtencode(RRCR9tasn_key((s+/usr/lib/python2.6/site-packages/rsa/key.pyR×s  cCs"tii|dƒ}|i|ƒ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 (R R tder((s+/usr/lib/python2.6/site-packages/rsa/key.pyRçs cCs|iƒ}tii|dƒS(sƒSaves a PKCS#1 PEM-encoded public key file. :return: contents of a PEM-encoded file that contains the public key. sRSA PUBLIC KEY(RRRGtsave_pem(RRI((s+/usr/lib/python2.6/site-packages/rsa/key.pyRös cCs"tii|dƒ}|i|ƒ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. :return: a PublicKey object s PUBLIC KEY(RRGRHtload_pkcs1_openssl_der(R R RI((s+/usr/lib/python2.6/site-packages/rsa/key.pytload_pkcs1_openssl_pemÿscCs‘ddkl}ddkl}ddkl}|i|d|ƒƒ\}}|dd|idƒjotd ƒ‚n|i |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 iÿÿÿÿ(t OpenSSLPubKey(R8(tunivR:theadertoids1.2.840.113549.1.1.1s7This is not a DER-encoded OpenSSL-compatible public keyR,i( R>RMR=R8t pyasn1.typeRNR?tObjectIdentifiert TypeErrorR (R R RMR8RNtkeyinfoRB((s+/usr/lib/python2.6/site-packages/rsa/key.pyRKs (RR(R$R%R&R'R-R.R/R1R6R7R(R RRRRLRK(((s+/usr/lib/python2.6/site-packages/rsa/key.pyR*ˆs       t PrivateKeycBsžeZdZdZdddd „Zd „Zd „Zd „Zd „Z d„Z d„Z d„Z d„Z ed„ƒZd„Zed„ƒZd„ZRS(s;Represents 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 accesss is faster, though. >>> PrivateKey(3247, 65537, 833, 191, 17) PrivateKey(3247, 65537, 833, 191, 17) exp1, exp2 and coef can be given, but if None or omitted they will be calculated: >>> pk = PrivateKey(3727264081, 65537, 3349121513, 65063, 57287, exp2=4) >>> pk.exp1 55063 >>> pk.exp2 # this is of course not a correct value, but it is the one we passed. 4 >>> pk.coef 50797 If you give exp1, exp2 or coef, they will be used as-is: >>> pk = PrivateKey(1, 2, 3, 4, 5, 6, 7, 8) >>> pk.exp1 6 >>> pk.exp2 7 >>> pk.coef 8 RRtdtptqtexp1texp2tcoefc CsÆti|||ƒ||_||_||_|djot||dƒ|_n ||_|djot||dƒ|_n ||_|djot i i ||ƒ|_ n ||_ dS(Ni( RRRVRWRXR2R@RYRZRR R!R[( RRRRVRWRXRYRZR[((s+/usr/lib/python2.6/site-packages/rsa/key.pyRKs        cCs t||ƒS(N(R+(RR,((s+/usr/lib/python2.6/site-packages/rsa/key.pyR-ascCsd|S(Ns-PrivateKey(%(n)i, %(e)i, %(d)i, %(p)i, %(q)i)((R((s+/usr/lib/python2.6/site-packages/rsa/key.pyR.dscCs4|i|i|i|i|i|i|i|ifS(s&Returns the key as tuple for pickling.(RRRVRWRXRYRZR[(R((s+/usr/lib/python2.6/site-packages/rsa/key.pyR/gsc Cs:|\|_|_|_|_|_|_|_|_dS(sSets the key from tuple.N(RRRVRWRXRYRZR[(RR0((s+/usr/lib/python2.6/site-packages/rsa/key.pyR1kscCs¼|djotSt|tƒptS|i|ijo‚|i|ijoo|i|ijo\|i|ijoI|i|ijo6|i |i jo#|i |i jo|i |i jS(N( R2R3R4RURRRVRWRXRYRZR[(RR5((s+/usr/lib/python2.6/site-packages/rsa/key.pyR6os cCs ||j S(N((RR5((s+/usr/lib/python2.6/site-packages/rsa/key.pyR7scCsYtii|idƒ}|i||ƒ}tii||i|iƒ}|i||ƒ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 i( RtrandnumtrandintRRtcoret decrypt_intRVR#(Rt encryptedtblind_rR"t decrypted((s+/usr/lib/python2.6/site-packages/rsa/key.pytblinded_decrypt‚s cCsYtii|idƒ}|i||ƒ}tii||i|iƒ}|i||ƒ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 i( RR\R]RRR^t encrypt_intRVR#(RRRaR"R`((s+/usr/lib/python2.6/site-packages/rsa/key.pytblinded_encrypt’s cCsuddkl}|i|ƒ\}}|ddjotd|dƒ‚ntd„|dd!Dƒƒ}||ŒS(sLoads a key in PKCS#1 DER format. :param keyfile: contents of a DER-encoded file that contains the private key. :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ÿÿÿÿ(R8is)Unable to read this file, version %s != 0cssx|]}t|ƒVqWdS(N(R@(t.0tx((s+/usr/lib/python2.6/site-packages/rsa/key.pys Ës ii (R=R8R?Rttuple(R R R8RARBtas_ints((s+/usr/lib/python2.6/site-packages/rsa/key.pyR ¡s csddkl‰l‰ddkl}dˆif‡‡fd†ƒY}|ƒ}|iddƒ|id|iƒ|id |iƒ|id |i ƒ|id |i ƒ|id |i ƒ|id |i ƒ|id|i ƒ|id|iƒ|i|ƒS(sdSaves the private key in PKCS#1 DER format. @returns: the DER-encoded private key. iÿÿÿÿ(RNt namedtype(RCt AsnPrivKeyc sÑeZˆiˆidˆiƒƒˆidˆiƒƒˆidˆiƒƒˆidˆiƒƒˆidˆiƒƒˆidˆiƒƒˆidˆiƒƒˆidˆiƒƒˆidˆiƒƒƒ ZRS( tversionR;R<tprivateExponenttprime1tprime2t exponent1t exponent2t coefficient(R$R%t NamedTypest NamedTypetIntegert componentType((RNRj(s+/usr/lib/python2.6/site-packages/rsa/key.pyRk×sRliR;R<RmRnRoRpRqRr(RQRNRjR=RCtSequenceRDRRRVRWRXRYRZR[RE(RRCRkRF((RjRNs+/usr/lib/python2.6/site-packages/rsa/key.pyRÎs" cCs(tii|tdƒƒ}|i|ƒS(sTLoads 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. :return: a PrivateKey object sRSA PRIVATE KEY(RRGRHRR (R R RI((s+/usr/lib/python2.6/site-packages/rsa/key.pyRòs cCs%|iƒ}tii|tdƒƒS(s…Saves a PKCS#1 PEM-encoded private key file. :return: contents of a PEM-encoded file that contains the private key. sRSA PRIVATE KEY(RRRGRJR(RRI((s+/usr/lib/python2.6/site-packages/rsa/key.pyRs (RRRVRWRXsexp1sexp2scoefN(R$R%R&R'R2RR-R.R/R1R6R7RcReR(R RRR(((s+/usr/lib/python2.6/site-packages/rsa/key.pyRU's         - $c sÖ|d‰|d}||}||}tid|ƒ||ƒ}tid|ƒ||ƒ}‡‡fd†}t} x?|||ƒp.| o||ƒ}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>||jotSˆptStii||ƒ}ˆ|jS(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(RWRXt found_size(t total_bitstaccurate(s+/usr/lib/python2.6/site-packages/rsa/key.pyt is_acceptable8s  (tlogtdebugR3tmaxtmin( tnbitst getprime_funcR|tshifttpbitstqbitsRWRXR}tchange_p((R|R{s+/usr/lib/python2.6/site-packages/rsa/key.pytfind_p_q s"        cCs“|d|d}ytii||ƒ}Wn)tj otd||fƒ‚nX|||djotd|||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 is.e (%d) and phi_n (%d) are not relatively primes6e (%d) and d (%d) are not mult. inv. modulo phi_n (%d)(RR R!R(RWRXtexponenttphi_nRV((s+/usr/lib/python2.6/site-packages/rsa/key.pytcalculate_keys_custom_exponentYs 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(RWRX((s+/usr/lib/python2.6/site-packages/rsa/key.pytcalculate_keysus cCsqx^toVt|d||ƒ\}}y t||d|ƒ\}}PWqtj oqXqW||||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‰(RxRˆR‹R(R‚RƒR|R‰RWRXRRV((s+/usr/lib/python2.6/site-packages/rsa/key.pytgen_keys‚s ic Cså|djotdƒ‚n|djotd|ƒ‚n|djo8ddkl}ddk}|i|id|ƒ}n tii}t||d |d |ƒ\}}} } ||} t| | ƒt | | | ||ƒfS( sGenerates 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‰( RRRt functoolstpartialtgetprimetprimeRŽR*RU( R‚R|RR‰RR‘RƒRWRXRRVR((s+/usr/lib/python2.6/site-packages/rsa/key.pytnewkeysžs     '  R•t__main__idi is%i timestAborteds Doctests done("R&tloggingt rsa._compatRt rsa.primeRtrsa.pemt rsa.commont rsa.randnumtrsa.coret getLoggerR$R~RŒtobjectRR*RUR”R“RxRˆR‹RRŽR•t__all__tdoctesttrangetcountttestmodtfailurestteststKeyboardInterrupt(((s+/usr/lib/python2.6/site-packages/rsa/key.pyt"s>      WŸäN  5   %