bXc@`sddlmZmZmZddlZddlmZddlZddlm Z ddl m Z m Z ddl mZejejdefdYZejejd efd YZejejd efd YZeZd ZdZdZdZdZdZdZdZdZdZdefdYZ defdYZ!dS(i(tabsolute_importtdivisiontprint_functionN(tgcd(tutils(tUnsupportedAlgorithmt_Reasons(t RSABackendt RSAPrivateKeycB`sbeZejdZejdZejdZejdZejdZ RS(cC`sdS(sN Returns an AsymmetricSignatureContext used for signing data. N((tselftpaddingt algorithm((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pytsignerscC`sdS(s3 Decrypts the provided ciphertext. N((R t ciphertextR ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pytdecryptscC`sdS(s7 The bit length of the public modulus. N((R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pytkey_sizescC`sdS(sD The RSAPublicKey associated with this private key. N((R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt public_key%scC`sdS(s! Signs the data. N((R tdataR R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pytsign+s( t__name__t __module__tabctabstractmethodR RtabstractpropertyRRR(((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRs tRSAPrivateKeyWithSerializationcB`s,eZejdZejdZRS(cC`sdS(s/ Returns an RSAPrivateNumbers. N((R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pytprivate_numbers4scC`sdS(s6 Returns the key serialized as bytes. N((R tencodingtformattencryption_algorithm((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt private_bytes:s(RRRRRR(((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyR2st RSAPublicKeycB`steZejdZejdZejdZejdZejdZ ejdZ RS(cC`sdS(sY Returns an AsymmetricVerificationContext used for verifying signatures. N((R t signatureR R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pytverifierCscC`sdS(s/ Encrypts the given plaintext. N((R t plaintextR ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pytencryptIscC`sdS(s7 The bit length of the public modulus. N((R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyROscC`sdS(s- Returns an RSAPublicNumbers N((R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pytpublic_numbersUscC`sdS(s6 Returns the key serialized as bytes. N((R RR((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt public_bytes[scC`sdS(s5 Verifies the signature of the data. N((R RRR R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pytverifyas( RRRRR R"RRR#R$R%(((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRAs cC`sAt|ts$tdtjnt|||j||S(Ns-Backend object does not implement RSABackend.(t isinstanceRRRtBACKEND_MISSING_INTERFACEt_verify_rsa_parameterstgenerate_rsa_private_key(tpublic_exponentRtbackend((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pytgenerate_private_keyks  cC`sY|dkrtdn|d@dkr:tdn|dkrUtdndS(Nispublic_exponent must be >= 3.iispublic_exponent must be odd.is#key_size must be at least 512-bits.(t ValueError(R*R((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyR(vs   cC`sd|dkrtdn||kr6tdn||krQtdn||krltdn||krtdn||krtdn||krtdn|dks||krtd n|d @d krtd n|d @d kr"td n|d @d krAtdn|||kr`tdndS(Nismodulus must be >= 3.sp must be < modulus.sq must be < modulus.sdmp1 must be < modulus.sdmq1 must be < modulus.siqmp must be < modulus.s#private_exponent must be < modulus.s+public_exponent must be >= 3 and < modulus.iispublic_exponent must be odd.sdmp1 must be odd.sdmq1 must be odd.sp*q must equal modulus.(R-(tptqtprivate_exponenttdmp1tdmq1tiqmpR*tmodulus((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt_check_private_key_componentss0       cC`se|dkrtdn|dks3||krBtdn|d@dkratdndS(Nisn must be >= 3.se must be >= 3 and < n.iise must be odd.(R-(tetn((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt_check_public_key_componentss  c C`sd\}}}}||}}xl|dkrt||\}} ||||||} } || ||| | f\}}}}}}q"W||S(sO Modular Multiplicative Inverse. Returns x such that: (x*e) mod m == 1 ii(iiii(tdivmod( R6tmtx1ty1tx2ty2tatbR/trtxntyn((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt_modinvs .cC`s t||S(sF Compute the CRT (q ** -1) % p value from RSA primes p and q. (RD(R.R/((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt rsa_crt_iqmpscC`s ||dS(sg Compute the CRT private_exponent % (p - 1) value from the RSA private_exponent (d) and p. i((R0R.((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt rsa_crt_dmp1scC`s ||dS(sg Compute the CRT private_exponent % (q - 1) value from the RSA private_exponent (d) and q. i((R0R/((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt rsa_crt_dmq1sic C`s=||d}|}x|ddkr4|d}qWt}d}x| r|tkr|}x}||krt|||}|dkr||dkrt|d|dkrt|d|} t}Pn|d9}q`W|d7}qDW|stdnt|| \} } t| | fdt\} } | | fS(s Compute factors p and q from the private exponent d. We assume that n has no more than two factors. This function is adapted from code in PyCrypto. iiis2Unable to compute factors p and q from exponent d.treverse(tFalset_MAX_RECOVERY_ATTEMPTStpowRtTrueR-R9tsorted( R7R6tdtktottttspottedR?tktcandR.R/RA((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pytrsa_recover_prime_factorss*4tRSAPrivateNumberscB`seZdZejdZejdZejdZejdZejdZ ejdZ ejdZ dZ d Z d Zd ZRS( cC`st|tj srt|tj srt|tj srt|tj srt|tj srt|tj rtdnt|tstdn||_||_||_||_||_ ||_ ||_ dS(NsNRSAPrivateNumbers p, q, d, dmp1, dmq1, iqmp arguments must all be an integers.sFRSAPrivateNumbers public_numbers must be an RSAPublicNumbers instance.( R&tsixt integer_typest TypeErrortRSAPublicNumberst_pt_qt_dt_dmp1t_dmq1t_iqmpt_public_numbers(R R.R/RNR1R2R3R#((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt__init__ s$        RZR[R\R]R^R_R`cC`s |j|S(N(tload_rsa_private_numbers(R R+((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt private_key.scC`st|tstS|j|jko|j|jko|j|jko|j|jko|j|jko|j|jko|j |j kS(N( R&RUtNotImplementedR.R/RNR1R2R3R#(R tother((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt__eq__1scC`s ||k S(N((R Re((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt__ne__?scC`s4t|j|j|j|j|j|j|jfS(N(thashR.R/RNR1R2R3R#(R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt__hash__Bs(RRRaRtread_only_propertyR.R/RNR1R2R3R#RcRfRgRi(((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRUs    RYcB`s\eZdZejdZejdZdZdZdZ dZ dZ RS(cC`sKt|tj s&t|tj r5tdn||_||_dS(Ns,RSAPublicNumbers arguments must be integers.(R&RVRWRXt_et_n(R R6R7((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRaOs  RkRlcC`s |j|S(N(tload_rsa_public_numbers(R R+((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyR\scC`s dj|S(Ns$(R(R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt__repr___scC`s5t|tstS|j|jko4|j|jkS(N(R&RYRdR6R7(R Re((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRfbscC`s ||k S(N((R Re((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRghscC`st|j|jfS(N(RhR6R7(R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRiks( RRRaRRjR6R7RRnRfRgRi(((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRYNs     ("t __future__RRRRt fractionsRRVt cryptographyRtcryptography.exceptionsRRt'cryptography.hazmat.backends.interfacesRt add_metaclasstABCMetatobjectRRRtRSAPublicKeyWithSerializationR,R(R5R8RDRERFRGRJRTRURY(((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyts2   & '    +F