
    pܧi                       S SK Jr  S SKrS SKrS SKJr  S SKJr  S SK	J
r
Jr  S SKJr  S SKJr   " S S	\R"                  S
9r\r\R)                  \R*                  R$                  5         " S S\R"                  S
9r\r\R)                  \R*                  R,                  5        \R*                  R0                  r\R*                  R2                  r S       SS jjrSS jrSS jrSS jrSS jrSS jrSS jr Sr!SS jr"g)    )annotationsN)gcd)openssl)_serializationhashes)AsymmetricPadding)utilsc                  .   \ rS rSr\R
                  S
S j5       r\\R
                  SS j5       5       r\R
                  SS j5       r	\R
                          SS j5       r
\R
                  SS j5       r\R
                          SS j5       rSrg	)RSAPrivateKey   c                    g)z#
Decrypts the provided ciphertext.
N )self
ciphertextpaddings      O/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pydecryptRSAPrivateKey.decrypt           c                    gz'
The bit length of the public modulus.
Nr   r   s    r   key_sizeRSAPrivateKey.key_size   r   r   c                    g)z4
The RSAPublicKey associated with this private key.
Nr   r   s    r   
public_keyRSAPrivateKey.public_key   r   r   c                    g)z
Signs the data.
Nr   )r   datar   	algorithms       r   signRSAPrivateKey.sign%   r   r   c                    g)z
Returns an RSAPrivateNumbers.
Nr   r   s    r   private_numbersRSAPrivateKey.private_numbers0   r   r   c                    gz&
Returns the key serialized as bytes.
Nr   )r   encodingformatencryption_algorithms       r   private_bytesRSAPrivateKey.private_bytes6   r   r   r   N)r   bytesr   r   returnr.   r/   int)r/   RSAPublicKey)r    r.   r   r   r!   +asym_utils.Prehashed | hashes.HashAlgorithmr/   r.   )r/   RSAPrivateNumbers)r)   _serialization.Encodingr*   z_serialization.PrivateFormatr+   z)_serialization.KeySerializationEncryptionr/   r.   )__name__
__module____qualname____firstlineno__abcabstractmethodr   propertyr   r   r"   r%   r,   __static_attributes__r   r   r   r   r      s     
   
 	 
 	 # ?	
 
  	 
 	) - H	
 
 r   r   )	metaclassc                  f   \ rS rSr\R
                  SS j5       r\\R
                  SS j5       5       r\R
                  SS j5       r	\R
                        SS j5       r
\R
                            SS j5       r\R
                          SS j5       r\R
                  SS j5       rS	rg
)r2   F   c                    g)z
Encrypts the given plaintext.
Nr   )r   	plaintextr   s      r   encryptRSAPublicKey.encryptG   r   r   c                    gr   r   r   s    r   r   RSAPublicKey.key_sizeM   r   r   c                    g)z
Returns an RSAPublicNumbers
Nr   r   s    r   public_numbersRSAPublicKey.public_numbersT   r   r   c                    gr(   r   )r   r)   r*   s      r   public_bytesRSAPublicKey.public_bytesZ   r   r   c                    g)z%
Verifies the signature of the data.
Nr   )r   	signaturer    r   r!   s        r   verifyRSAPublicKey.verifyd   r   r   c                    g)z0
Recovers the original data from the signature.
Nr   )r   rN   r   r!   s       r   recover_data_from_signature(RSAPublicKey.recover_data_from_signaturep   r   r   c                    g)z
Checks equality.
Nr   )r   others     r   __eq__RSAPublicKey.__eq__{   r   r   r   N)rB   r.   r   r   r/   r.   r0   )r/   RSAPublicNumbers)r)   r5   r*   z_serialization.PublicFormatr/   r.   )
rN   r.   r    r.   r   r   r!   r3   r/   None)rN   r.   r   r   r!   zhashes.HashAlgorithm | Noner/   r.   )rU   objectr/   bool)r6   r7   r8   r9   r:   r;   rC   r<   r   rH   rK   rO   rR   rV   r=   r   r   r   r2   r2   F   s0    
   
 	 
 	) , 
	  			 	 #		
 ?	 
	 	 	 # /	
 
  	 r   r2   c                V    [        X5        [        R                  R                  X5      $ N)_verify_rsa_parametersrust_opensslrsagenerate_private_key)public_exponentr   backends      r   ra   ra      s#    
 ?500KKr   c                H    U S;  a  [        S5      eUS:  a  [        S5      eg )N)   i  zopublic_exponent must be either 3 (for legacy compatibility) or 65537. Almost everyone should choose 65537 here!i   z$key_size must be at least 1024-bits.)
ValueError)rb   r   s     r   r^   r^      s6    j(?
 	

 $?@@ r   c                h    Su  p#XpTUS:  a#  [        XE5      u  pgX&U-  -
  nXWX84u  pEp#US:  a  M#  X!-  $ )zG
Modular Multiplicative Inverse. Returns x such that: (x*e) mod m == 1
)   r   r   )divmod)	emx1x2abqrxns	            r   _modinvrs      sL     FBq
a%a|b&[R|b a% 6Mr   c                    [        X5      $ )z>
Compute the CRT (q ** -1) % p value from RSA primes p and q.
)rs   )prp   s     r   rsa_crt_iqmprv      s     1=r   c                    XS-
  -  $ )z[
Compute the CRT private_exponent % (p - 1) value from the RSA
private_exponent (d) and p.
rh   r   )private_exponentru   s     r   rsa_crt_dmp1ry          
 1u%%r   c                    XS-
  -  $ )z[
Compute the CRT private_exponent % (q - 1) value from the RSA
private_exponent (d) and q.
rh   r   )rx   rp   s     r   rsa_crt_dmq1r|      rz   r   c                T    US-
  US-
  -  [        US-
  US-
  5      -  n[        X5      $ )z
Compute the RSA private_exponent (d) given the public exponent (e)
and the RSA primes p and q.

This uses the Carmichael totient function to generate the
smallest possible working value of the private exponent.
rh   )r   rs   )rj   ru   rp   lambda_ns       r   rsa_recover_private_exponentr      s5    " A!a% CAq1u$55H1r   i  c                   X!-  S-
  nUnUS-  S:X  a  US-  nUS-  S:X  a  M  SnSnU(       dr  U[         :  ah  UnXs:  aI  [        XgU 5      nUS:w  a+  XS-
  :w  a#  [        USU 5      S:X  a  [        US-   U 5      n	SnOUS-  nXs:  a  MI  US-  nU(       d  U[         :  a  Mh  U(       d  [        S5      e[	        U W	5      u  pUS:X  d   e[        X4SS9u  pX4$ )z
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.
rh      r   FTz2Unable to compute factors p and q from exponent d.)reverse)_MAX_RECOVERY_ATTEMPTSpowr   rf   ri   sorted)nrj   dktottspottedrn   kcandru   rp   rq   s               r   rsa_recover_prime_factorsr      s    519D 	A
a%1*F a%1* G	A!44hqQ<DqyT!e_T1aA1E q!$FA h 	
Q !44 MNN!Q<DA6M61&$'DA6Mr   r]   )rb   r1   r   r1   rc   z
typing.Anyr/   r   )rb   r1   r   r1   r/   rY   )rj   r1   rk   r1   r/   r1   )ru   r1   rp   r1   r/   r1   )rx   r1   ru   r1   r/   r1   )rx   r1   rp   r1   r/   r1   )rj   r1   ru   r1   rp   r1   r/   r1   )r   r1   rj   r1   r   r1   r/   ztuple[int, int])#
__future__r   r:   typingmathr   "cryptography.hazmat.bindings._rustr   r_   cryptography.hazmat.primitivesr   r   *cryptography.hazmat.primitives._asymmetricr   )cryptography.hazmat.primitives.asymmetricr	   
asym_utilsABCMetar   RSAPrivateKeyWithSerializationregisterr`   r2   RSAPublicKeyWithSerializationr4   rX   ra   r^   rs   rv   ry   r|   r   r   r   r   r   r   <module>r      s  
 # 
   F A H I.ckk .b "/    |''55 69S[[ 9x !-    l&&33 4 $$66 ##44  LLL L 	LA
&& 0  (r   