σ 9(Zc@`s§ddlmZmZmZddlZyddlmZWn!ek r_ddlmZnXddl Z ddl m Z ddl m Z mZddlmZe jejƒdefd„ƒYƒZe jejƒd efd „ƒYƒZe jejƒd efd „ƒYƒZeZd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZdZ d„Z!defd„ƒ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/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pytsignerscC`sdS(s3 Decrypts the provided ciphertext. N((R t ciphertextR ((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pytdecryptscC`sdS(s7 The bit length of the public modulus. N((R ((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pytkey_size#scC`sdS(sD The RSAPublicKey associated with this private key. N((R ((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyt public_key)scC`sdS(s! Signs the data. N((R tdataR R ((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pytsign/s( t__name__t __module__tabctabstractmethodR RtabstractpropertyRRR(((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyRs tRSAPrivateKeyWithSerializationcB`s,eZejd„ƒZejd„ƒZRS(cC`sdS(s/ Returns an RSAPrivateNumbers. N((R ((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pytprivate_numbers8scC`sdS(s6 Returns the key serialized as bytes. N((R tencodingtformattencryption_algorithm((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyt private_bytes>s(RRRRRR(((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyR6st 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/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pytverifierGscC`sdS(s/ Encrypts the given plaintext. N((R t plaintextR ((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pytencryptMscC`sdS(s7 The bit length of the public modulus. N((R ((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyRSscC`sdS(s- Returns an RSAPublicNumbers N((R ((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pytpublic_numbersYscC`sdS(s6 Returns the key serialized as bytes. N((R RR((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyt public_bytes_scC`sdS(s5 Verifies the signature of the data. N((R RRR R ((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pytverifyes( RRRRR R"RRR#R$R%(((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyREs 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/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pytgenerate_private_keyos  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/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyR(zs   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/tmp/pip-build-wDUJoH/cryptography/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/tmp/pip-build-wDUJoH/cryptography/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/tmp/pip-build-wDUJoH/cryptography/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/tmp/pip-build-wDUJoH/cryptography/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/tmp/pip-build-wDUJoH/cryptography/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/tmp/pip-build-wDUJoH/cryptography/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/tmp/pip-build-wDUJoH/cryptography/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/tmp/pip-build-wDUJoH/cryptography/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/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyt private_key2scC`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/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyt__eq__5scC`s ||k S(N((R Rf((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyt__ne__CscC`s4t|j|j|j|j|j|j|jfƒS(N(thashR.R/ROR1R2R3R#(R ((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyt__hash__Fs(RRRbRtread_only_propertyR.R/ROR1R2R3R#RdRgRhRj(((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyRV s    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/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyRbSs  RlRmcC`s |j|ƒS(N(tload_rsa_public_numbers(R R+((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyR`scC`s dj|ƒS(Ns$(R(R ((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyt__repr__cscC`s5t|tƒstS|j|jko4|j|jkS(N(R&RZReR6R7(R Rf((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyRgfscC`s ||k S(N((R Rf((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyRhlscC`st|j|jfƒS(N(RiR6R7(R ((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyRjos( RRRbRRkR6R7RRoRgRhRj(((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyRZRs     ($t __future__RRRRtmathRt ImportErrort fractionsRWt cryptographyRtcryptography.exceptionsRRt'cryptography.hazmat.backends.interfacesRt add_metaclasstABCMetatobjectRRRtRSAPublicKeyWithSerializationR,R(R5R8RDRERFRGRJRURVRZ(((sS/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/primitives/asymmetric/rsa.pyts8    & '    +F