σ ΐb‹Xc@`sddlmZmZmZddlZddlmZddlZddlm Z ddl m Z m Z ddl mZejejƒdefd„ƒYƒZejejƒd efd „ƒYƒZejejƒd efd „ƒYƒZeZd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZdZd„Zdefd„ƒYZ defd„ƒYZ!dS(i(tabsolute_importtdivisiontprint_functionN(tgcd(tutils(tUnsupportedAlgorithmt_Reasons(t RSABackendt RSAPrivateKeycB`sbeZejd„ƒZejd„ƒZejd„ƒZejd„ƒZejd„ƒZ 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,eZejd„ƒZejd„ƒZRS(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`steZejd„ƒZejd„ƒZejd„ƒZejd„ƒZejd„ƒZ ejd„ƒZ 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|tƒs$tdtjƒ‚nt||ƒ|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|dkrtdƒ‚n|d@dkr:tdƒ‚n|dkrUtdƒ‚ndS(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|dkrtdƒ‚n||kr6tdƒ‚n||krQtdƒ‚n||krltdƒ‚n||kr‡tdƒ‚n||kr’tdƒ‚n||kr½tdƒ‚n|dksΥ||krδtd ƒ‚n|d @d krtd ƒ‚n|d @d kr"td ƒ‚n|d @d krAtdƒ‚n|||kr`tdƒ‚ndS(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_componentss0       cC`se|dkrtdƒ‚n|dks3||krBtdƒ‚n|d@dkratdƒ‚ndS(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_components¨s  c C`s–d\}}}}||}}xl|dkrt||ƒ\}} ||||||} } || ||| | 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_modinv³s .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_iqmpΐscC`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_dmp1ΗscC`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_dmq1Οsiθc C`sO||d}|}x|ddkr4|d}qWt}d}x§| rκ|tkrκ|}x}||krάt|||ƒ}|dkrΟ||dkrΟt|d|ƒdkrΟt|d|ƒ} t}Pn|d9}q`W|d7}qDW|stdƒ‚nt|| ƒ\} } | dks't‚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-R9tAssertionErrortsorted( R7R6tdtktottttspottedR?tktcandR.R/RA((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pytrsa_recover_prime_factorsέs,4tRSAPrivateNumberscB`sžeZd„ZejdƒZejdƒZejdƒZejdƒZejdƒZ ejdƒZ ejdƒZ d„Z d „Z d „Zd „ZRS( cC`sβt|tjƒ srt|tjƒ srt|tjƒ srt|tjƒ srt|tjƒ srt|tjƒ rtdƒ‚nt|tƒsŸtdƒ‚n||_||_||_||_||_ ||_ ||_ 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/ROR1R2R3R#((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt__init__ s$        R[R\R]R^R_R`RacC`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`st|tƒstS|j|jkoŽ|j|jkoŽ|j|jkoŽ|j|jkoŽ|j|jkoŽ|j|jkoŽ|j |j kS(N( R&RVtNotImplementedR.R/ROR1R2R3R#(R tother((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt__eq__1scC`s ||k S(N((R Rf((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt__ne__?scC`s4t|j|j|j|j|j|j|jfƒS(N(thashR.R/ROR1R2R3R#(R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt__hash__Bs(RRRbRtread_only_propertyR.R/ROR1R2R3R#RdRgRhRj(((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRVs    RZcB`s\eZd„ZejdƒZejdƒZd„Zd„Zd„Z d„Z d„Z RS(cC`sKt|tjƒ s&t|tjƒ r5tdƒ‚n||_||_dS(Ns,RSAPublicNumbers arguments must be integers.(R&RWRXRYt_et_n(R R6R7((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRbOs  RlRmcC`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|tƒstS|j|jko4|j|jkS(N(R&RZReR6R7(R Rf((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRgbscC`s ||k S(N((R Rf((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRhhscC`st|j|jfƒS(N(RiR6R7(R ((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRjks( RRRbRRkR6R7RRoRgRhRj(((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRZNs     ("t __future__RRRRt fractionsRRWt cryptographyRtcryptography.exceptionsRRt'cryptography.hazmat.backends.interfacesRt add_metaclasstABCMetatobjectRRRtRSAPublicKeyWithSerializationR,R(R5R8RDRERFRGRJRURVRZ(((sS/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyts2   & '    +F