σ
Υ{PXc           @` s  d  d l  m Z m Z m Z d  d l Z d  d l m Z d  d l Z d  d l m	 Z	 d  d l
 m Z m Z d  d l m Z e j e j  d e f d     Y Z e j e j  d	 e f d
     Y Z e j e j  d e f d     Y Z e Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d Z d   Z d e f d     YZ  d e f d     YZ! d S(   i    (   t   absolute_importt   divisiont   print_functionN(   t   gcd(   t   utils(   t   UnsupportedAlgorithmt   _Reasons(   t
   RSABackendt   RSAPrivateKeyc           B` sb   e  Z e j d     Z e j d    Z e j d    Z e j d    Z e j d    Z	 RS(   c         C` s   d S(   sN   
        Returns an AsymmetricSignatureContext used for signing data.
        N(    (   t   selft   paddingt	   algorithm(    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   signer   s    c         C` s   d S(   s3   
        Decrypts the provided ciphertext.
        N(    (   R	   t
   ciphertextR
   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   decrypt   s    c         C` s   d S(   s7   
        The bit length of the public modulus.
        N(    (   R	   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   key_size   s    c         C` s   d S(   sD   
        The RSAPublicKey associated with this private key.
        N(    (   R	   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt
   public_key%   s    c         C` s   d S(   s!   
        Signs the data.
        N(    (   R	   t   dataR
   R   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   sign+   s    (
   t   __name__t
   __module__t   abct   abstractmethodR   R   t   abstractpropertyR   R   R   (    (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyR      s
   t   RSAPrivateKeyWithSerializationc           B` s,   e  Z e j d     Z e j d    Z RS(   c         C` s   d S(   s/   
        Returns an RSAPrivateNumbers.
        N(    (   R	   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   private_numbers4   s    c         C` s   d S(   s6   
        Returns the key serialized as bytes.
        N(    (   R	   t   encodingt   formatt   encryption_algorithm(    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   private_bytes:   s    (   R   R   R   R   R   R   (    (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyR   2   s   t   RSAPublicKeyc           B` st   e  Z e j d     Z e j d    Z e j d    Z e j d    Z e j d    Z	 e j d    Z
 RS(   c         C` s   d S(   sY   
        Returns an AsymmetricVerificationContext used for verifying signatures.
        N(    (   R	   t	   signatureR
   R   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   verifierC   s    c         C` s   d S(   s/   
        Encrypts the given plaintext.
        N(    (   R	   t	   plaintextR
   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   encryptI   s    c         C` s   d S(   s7   
        The bit length of the public modulus.
        N(    (   R	   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyR   O   s    c         C` s   d S(   s-   
        Returns an RSAPublicNumbers
        N(    (   R	   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   public_numbersU   s    c         C` s   d S(   s6   
        Returns the key serialized as bytes.
        N(    (   R	   R   R   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   public_bytes[   s    c         C` s   d S(   s5   
        Verifies the signature of the data.
        N(    (   R	   R   R   R
   R   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   verifya   s    (   R   R   R   R   R    R"   R   R   R#   R$   R%   (    (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyR   A   s   c         C` sA   t  | t  s$ t d t j   n  t |  |  | j |  |  S(   Ns-   Backend object does not implement RSABackend.(   t
   isinstanceR   R   R   t   BACKEND_MISSING_INTERFACEt   _verify_rsa_parameterst   generate_rsa_private_key(   t   public_exponentR   t   backend(    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   generate_private_keyk   s    c         C` sY   |  d k  r t  d   n  |  d @d k r: t  d   n  | d k  rU t  d   n  d  S(   Ni   s   public_exponent must be >= 3.i   i    s   public_exponent must be odd.i   s#   key_size must be at least 512-bits.(   t
   ValueError(   R*   R   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyR(   v   s    c         C` sd  | d k  r t  d   n  |  | k r6 t  d   n  | | k rQ t  d   n  | | k rl t  d   n  | | k r t  d   n  | | k r’ t  d   n  | | k r½ t  d   n  | d k  sΥ | | k rδ t  d	   n  | d
 @d k rt  d   n  | d
 @d k r"t  d   n  | d
 @d k rAt  d   n  |  | | k r`t  d   n  d  S(   Ni   s   modulus must be >= 3.s   p must be < modulus.s   q must be < modulus.s   dmp1 must be < modulus.s   dmq1 must be < modulus.s   iqmp must be < modulus.s#   private_exponent must be < modulus.s+   public_exponent must be >= 3 and < modulus.i   i    s   public_exponent must be odd.s   dmp1 must be odd.s   dmq1 must be odd.s   p*q must equal modulus.(   R-   (   t   pt   qt   private_exponentt   dmp1t   dmq1t   iqmpR*   t   modulus(    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   _check_private_key_components   s0    c         C` se   | d k  r t  d   n  |  d k  s3 |  | k rB t  d   n  |  d @d k ra t  d   n  d  S(   Ni   s   n must be >= 3.s   e must be >= 3 and < n.i   i    s   e must be odd.(   R-   (   t   et   n(    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   _check_public_key_components¨   s    c         C` s   d \ } } } } |  | } } xl | d k r t  | |  \ } }	 | | | | | | }
 } | |	 | | |
 | f \ } } } } } } q" W| | S(   sO   
    Modular Multiplicative Inverse. Returns x such that: (x*e) mod m == 1
    i   i    (   i   i    i    i   (   t   divmod(   R6   t   mt   x1t   y1t   x2t   y2t   at   bR/   t   rt   xnt   yn(    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   _modinv³   s    .c         C` s   t  | |   S(   sF   
    Compute the CRT (q ** -1) % p value from RSA primes p and q.
    (   RD   (   R.   R/   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   rsa_crt_iqmpΐ   s    c         C` s   |  | d S(   sg   
    Compute the CRT private_exponent % (p - 1) value from the RSA
    private_exponent (d) and p.
    i   (    (   R0   R.   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   rsa_crt_dmp1Η   s    c         C` s   |  | d S(   sg   
    Compute the CRT private_exponent % (q - 1) value from the RSA
    private_exponent (d) and q.
    i   (    (   R0   R/   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   rsa_crt_dmq1Ο   s    iθ  c         C` sO  | | d } | } x | d d k r4 | d } q Wt  } d } x§ | rκ | t k  rκ | } x} | | k  rά t | | |   } | d k rΟ | |  d k rΟ t | d |   d k rΟ t | d |   }	 t } Pn  | d 9} q` W| d 7} qD W| s t d   n  t |  |	  \ }
 } | d k s't  t |	 |
 f d t \ }	 }
 |	 |
 f S(   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.
    i   i   i    s2   Unable to compute factors p and q from exponent d.t   reverse(	   t   Falset   _MAX_RECOVERY_ATTEMPTSt   powR   t   TrueR-   R9   t   AssertionErrort   sorted(   R7   R6   t   dt   ktott   tt   spottedR?   t   kt   candR.   R/   RA   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   rsa_recover_prime_factorsέ   s,    4t   RSAPrivateNumbersc           B` s   e  Z d    Z e j d  Z e j d  Z e j d  Z e j d  Z e j d  Z	 e j d  Z
 e j d  Z d   Z d	   Z d
   Z d   Z RS(   c         C` sβ   t  | t j  sr t  | t j  sr t  | t j  sr t  | t j  sr t  | t j  sr t  | t j  r t d   n  t  | t  s t d   n  | |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 | |  _ d  S(   NsN   RSAPrivateNumbers p, q, d, dmp1, dmq1, iqmp arguments must all be an integers.sF   RSAPrivateNumbers public_numbers must be an RSAPublicNumbers instance.(   R&   t   sixt   integer_typest	   TypeErrort   RSAPublicNumberst   _pt   _qt   _dt   _dmp1t   _dmq1t   _iqmpt   _public_numbers(   R	   R.   R/   RO   R1   R2   R3   R#   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   __init__	  s$    						R[   R\   R]   R^   R_   R`   Ra   c         C` s   | j  |   S(   N(   t   load_rsa_private_numbers(   R	   R+   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   private_key.  s    c         C` s   t  | t  s t S|  j | j k o |  j | j k o |  j | j k o |  j | j k o |  j | j k o |  j | j k o |  j	 | j	 k S(   N(
   R&   RV   t   NotImplementedR.   R/   RO   R1   R2   R3   R#   (   R	   t   other(    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   __eq__1  s    c         C` s   |  | k S(   N(    (   R	   Rf   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   __ne__?  s    c         C` s4   t  |  j |  j |  j |  j |  j |  j |  j f  S(   N(   t   hashR.   R/   RO   R1   R2   R3   R#   (   R	   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   __hash__B  s    (   R   R   Rb   R   t   read_only_propertyR.   R/   RO   R1   R2   R3   R#   Rd   Rg   Rh   Rj   (    (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRV     s   				RZ   c           B` s\   e  Z d    Z e j d  Z e j d  Z d   Z d   Z d   Z	 d   Z
 d   Z RS(   c         C` sK   t  | t j  s& t  | t j  r5 t d   n  | |  _ | |  _ d  S(   Ns,   RSAPublicNumbers arguments must be integers.(   R&   RW   RX   RY   t   _et   _n(   R	   R6   R7   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRb   O  s
    	Rl   Rm   c         C` s   | j  |   S(   N(   t   load_rsa_public_numbers(   R	   R+   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyR   \  s    c         C` s   d j  |   S(   Ns$   <RSAPublicNumbers(e={0.e}, n={0.n})>(   R   (   R	   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   __repr___  s    c         C` s5   t  | t  s t S|  j | j k o4 |  j | j k S(   N(   R&   RZ   Re   R6   R7   (   R	   Rf   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRg   b  s    c         C` s   |  | k S(   N(    (   R	   Rf   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRh   h  s    c         C` s   t  |  j |  j f  S(   N(   Ri   R6   R7   (   R	   (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRj   k  s    (   R   R   Rb   R   Rk   R6   R7   R   Ro   Rg   Rh   Rj   (    (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyRZ   N  s   	
				("   t
   __future__R    R   R   R   t	   fractionsR   RW   t   cryptographyR   t   cryptography.exceptionsR   R   t'   cryptography.hazmat.backends.interfacesR   t   add_metaclasst   ABCMetat   objectR   R   R   t   RSAPublicKeyWithSerializationR,   R(   R5   R8   RD   RE   RF   RG   RJ   RU   RV   RZ   (    (    (    sQ   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.pyt   <module>   s2    &			'						+F