ó
/<õ\c           @` sæ  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l	 m
 Z
 d e f d „  ƒ  YZ 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 j e j ƒ d e f d „  ƒ  Yƒ Z e j e j ƒ d e f d „  ƒ  Yƒ Z e Z e j e ƒ d e f d „  ƒ  Yƒ Z e j e ƒ d e f d „  ƒ  Yƒ Z e j e ƒ d e f d „  ƒ  Yƒ Z e j e ƒ d e f d „  ƒ  Yƒ Z e j e ƒ d e f d „  ƒ  Yƒ Z e j e ƒ d e f d „  ƒ  Yƒ Z e j e ƒ d e f d „  ƒ  Yƒ Z e j e ƒ d e f d  „  ƒ  Yƒ Z e j e ƒ d! e f d" „  ƒ  Yƒ Z e j e ƒ d# e f d$ „  ƒ  Yƒ Z e j e ƒ d% e f d& „  ƒ  Yƒ Z  e j e ƒ d' e f d( „  ƒ  Yƒ Z! e j e ƒ d) e f d* „  ƒ  Yƒ Z" e j e ƒ d+ e f d, „  ƒ  Yƒ Z# e j e ƒ d- e f d. „  ƒ  Yƒ Z$ e j e ƒ d/ e f d0 „  ƒ  Yƒ Z% e j e ƒ d1 e f d2 „  ƒ  Yƒ Z& e j e ƒ d3 e f d4 „  ƒ  Yƒ Z' e j e ƒ d5 e f d6 „  ƒ  Yƒ Z( i e% d7 6e" d8 6e% d9 6e$ d: 6e" d; 6e! d< 6e  d= 6e# d> 6e d? 6e d@ 6e dA 6e dB 6e dC 6e dD 6e dE 6e dF 6e dG 6e dH 6e& dI 6e' dJ 6e( dK 6Z) e j e ƒ dL e f dM „  ƒ  Yƒ Z* dN „  Z+ dO „  Z, dP e f dQ „  ƒ  YZ- dR e f dS „  ƒ  YZ. dT e f dU „  ƒ  YZ/ i e% e j% 6e$ e j$ 6e# e j# 6e" e j" 6e! e j! 6e  e j  6e& e j0 6e' e j1 6e( e j2 6e e j 6e e j 6e e j 6e e j 6e e j 6e e j 6e e j 6e e j 6e e j 6e e j 6Z3 dV „  Z4 d S(W   i    (   t   absolute_importt   divisiont   print_functionN(   t   utils(   t   ObjectIdentifiert   EllipticCurveOIDc           B` sì   e  Z e d  ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z	 e d ƒ Z
 e d ƒ Z e d	 ƒ Z e d
 ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z RS(   s   1.2.840.10045.3.1.1s   1.3.132.0.33s   1.3.132.0.10s   1.2.840.10045.3.1.7s   1.3.132.0.34s   1.3.132.0.35s   1.3.36.3.3.2.8.1.1.7s   1.3.36.3.3.2.8.1.1.11s   1.3.36.3.3.2.8.1.1.13s   1.3.132.0.1s   1.3.132.0.15s   1.3.132.0.26s   1.3.132.0.27s   1.3.132.0.16s   1.3.132.0.17s   1.3.132.0.36s   1.3.132.0.37s   1.3.132.0.38s   1.3.132.0.39(   t   __name__t
   __module__R   t	   SECP192R1t	   SECP224R1t	   SECP256K1t	   SECP256R1t	   SECP384R1t	   SECP521R1t   BRAINPOOLP256R1t   BRAINPOOLP384R1t   BRAINPOOLP512R1t	   SECT163K1t	   SECT163R2t	   SECT233K1t	   SECT233R1t	   SECT283K1t	   SECT283R1t	   SECT409K1t	   SECT409R1t	   SECT571K1t	   SECT571R1(    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR      s&   t   EllipticCurvec           B` s,   e  Z e j d  „  ƒ Z e j d „  ƒ Z RS(   c         C` s   d S(   s8   
        The name of the curve. e.g. secp256r1.
        N(    (   t   self(    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   name(   t    c         C` s   d S(   s<   
        Bit size of a secret scalar for the curve.
        N(    (   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   key_size.   R   (   R   R   t   abct   abstractpropertyR   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   &   s   t   EllipticCurveSignatureAlgorithmc           B` s   e  Z e j d  „  ƒ Z RS(   c         C` s   d S(   s@   
        The digest algorithm used with this signature.
        N(    (   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt	   algorithm7   R   (   R   R   R    R!   R#   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR"   5   s   t   EllipticCurvePrivateKeyc           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(   sN   
        Returns an AsymmetricSignatureContext used for signing data.
        N(    (   R   t   signature_algorithm(    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   signer@   R   c         C` s   d S(   s}   
        Performs a key exchange operation using the provided algorithm with the
        provided peer's public key.
        N(    (   R   R#   t   peer_public_key(    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   exchangeF   R   c         C` s   d S(   sB   
        The EllipticCurvePublicKey for this private key.
        N(    (   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt
   public_keyM   R   c         C` s   d S(   s8   
        The EllipticCurve that this key is on.
        N(    (   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   curveS   R   c         C` s   d S(   s<   
        Bit size of a secret scalar for the curve.
        N(    (   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   Y   R   c         C` s   d S(   s    
        Signs the data
        N(    (   R   t   dataR%   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   sign_   R   (   R   R   R    t   abstractmethodR&   R(   R)   R!   R*   R   R,   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR$   >   s   t(   EllipticCurvePrivateKeyWithSerializationc           B` s,   e  Z e j d  „  ƒ Z e j d „  ƒ Z RS(   c         C` s   d S(   s9   
        Returns an EllipticCurvePrivateNumbers.
        N(    (   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   private_numbersh   R   c         C` s   d S(   s6   
        Returns the key serialized as bytes.
        N(    (   R   t   encodingt   formatt   encryption_algorithm(    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   private_bytesn   R   (   R   R   R    R-   R/   R3   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR.   f   s   t   EllipticCurvePublicKeyc           B` sƒ   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
 e d „  ƒ Z RS(   c         C` s   d S(   sQ   
        Returns an AsymmetricVerificationContext used for signing data.
        N(    (   R   t	   signatureR%   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   verifierw   R   c         C` s   d S(   s8   
        The EllipticCurve that this key is on.
        N(    (   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR*   }   R   c         C` s   d S(   s<   
        Bit size of a secret scalar for the curve.
        N(    (   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   ƒ   R   c         C` s   d S(   s8   
        Returns an EllipticCurvePublicNumbers.
        N(    (   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   public_numbers‰   R   c         C` s   d S(   s6   
        Returns the key serialized as bytes.
        N(    (   R   R0   R1   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   public_bytes   R   c         C` s   d S(   s5   
        Verifies the signature of the data.
        N(    (   R   R5   R+   R%   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   verify•   R   c         C` s–   t  j d | ƒ t | t ƒ s. t d ƒ ‚ n  t | ƒ d k rO t d ƒ ‚ n  t j | d ƒ d
 k rv t d ƒ ‚ n  d d	 l	 m
 } | j | | ƒ S(   NR+   s'   curve must be an EllipticCurve instancei    s%   data must not be an empty byte stringi   i   i   s%   Unsupported elliptic curve point type(   t   backend(   i   i   i   (   R   t   _check_bytest
   isinstanceR   t	   TypeErrort   lent
   ValueErrort   sixt
   indexbytest,   cryptography.hazmat.backends.openssl.backendR:   t    load_elliptic_curve_public_bytes(   t   clsR*   R+   R:   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   from_encoded_point›   s    (   R   R   R    R-   R6   R!   R*   R   R7   R8   R9   t   classmethodRE   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR4   u   s   R   c           B` s   e  Z d  Z d Z RS(   t	   sect571r1i:  (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   ¯   s   R   c           B` s   e  Z d  Z d Z RS(   t	   sect409r1i™  (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   µ   s   R   c           B` s   e  Z d  Z d Z RS(   t	   sect283r1i  (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   »   s   R   c           B` s   e  Z d  Z d Z RS(   t	   sect233r1ié   (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   Á   s   R   c           B` s   e  Z d  Z d Z RS(   t	   sect163r2i£   (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   Ç   s   R   c           B` s   e  Z d  Z d Z RS(   t	   sect571k1i;  (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   Í   s   R   c           B` s   e  Z d  Z d Z RS(   t	   sect409k1i™  (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   Ó   s   R   c           B` s   e  Z d  Z d Z RS(   t	   sect283k1i  (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   Ù   s   R   c           B` s   e  Z d  Z d Z RS(   t	   sect233k1ié   (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   ß   s   R   c           B` s   e  Z d  Z d Z RS(   t	   sect163k1i£   (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   å   s   R   c           B` s   e  Z d  Z d Z RS(   t	   secp521r1i	  (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   ë   s   R   c           B` s   e  Z d  Z d Z RS(   t	   secp384r1i€  (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   ñ   s   R   c           B` s   e  Z d  Z d Z RS(   t	   secp256r1i   (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   ÷   s   R
   c           B` s   e  Z d  Z d Z RS(   t	   secp256k1i   (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR
   ý   s   R	   c           B` s   e  Z d  Z d Z RS(   t	   secp224r1ià   (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR	     s   R   c           B` s   e  Z d  Z d Z RS(   t	   secp192r1iÀ   (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   	  s   t   BrainpoolP256R1c           B` s   e  Z d  Z d Z RS(   t   brainpoolP256r1i   (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyRW     s   t   BrainpoolP384R1c           B` s   e  Z d  Z d Z RS(   t   brainpoolP384r1i€  (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyRY     s   t   BrainpoolP512R1c           B` s   e  Z d  Z d Z RS(   t   brainpoolP512r1i   (   R   R   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR[     s   t
   prime192v1t
   prime256v1RV   RU   RS   RR   RQ   RT   RP   RO   RN   RM   RL   RK   RJ   RI   RH   RG   RX   RZ   R\   t   ECDSAc           B` s    e  Z d  „  Z e j d ƒ Z RS(   c         C` s   | |  _  d  S(   N(   t
   _algorithm(   R   R#   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   __init__@  s    R`   (   R   R   Ra   R   t   read_only_propertyR#   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR_   >  s   	c         C` s   | j  |  ƒ S(   N(   t#   generate_elliptic_curve_private_key(   R*   R:   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   generate_private_keyF  s    c         C` sj   t  |  t j ƒ s! t d ƒ ‚ n  |  d k r< t d ƒ ‚ n  t  | t ƒ sZ t d ƒ ‚ n  | j |  | ƒ S(   Ns&   private_value must be an integer type.i    s)   private_value must be a positive integer.s/   curve must provide the EllipticCurve interface.(   R<   R@   t   integer_typesR=   R?   R   t!   derive_elliptic_curve_private_key(   t   private_valueR*   R:   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   derive_private_keyJ  s    t   EllipticCurvePublicNumbersc           B` sƒ   e  Z d  „  Z d „  Z d „  Z e 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` sr   t  | t j ƒ s& t  | t j ƒ r5 t d ƒ ‚ n  t  | t ƒ sS t d ƒ ‚ n  | |  _ | |  _ | |  _ d  S(   Ns   x and y must be integers.s/   curve must provide the EllipticCurve interface.(   R<   R@   Re   R=   R   t   _yt   _xt   _curve(   R   t   xt   yR*   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyRa   X  s    		c         C` s   | j  |  ƒ S(   N(   t"   load_elliptic_curve_public_numbers(   R   R:   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR)   f  s    c         C` sW   t  j d t j d d ƒ|  j j d d } d t j |  j | ƒ t j |  j | ƒ S(   NsÑ   encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding.t
   stackleveli   i   i   s   (	   t   warningst   warnR   t   DeprecatedIn25R*   R   t   int_to_bytesRm   Rn   (   R   t   byte_length(    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   encode_pointi  s    	c         C` s×   t  | t ƒ s t d ƒ ‚ n  t j d t j d d ƒ| j d ƒ rÇ | j d d } t	 | ƒ d | d k r¸ t j
 | d | d !d	 ƒ } t j
 | | d d	 ƒ } |  | | | ƒ St d
 ƒ ‚ n t d ƒ ‚ d  S(   Ns'   curve must be an EllipticCurve instances   Support for unsafe construction of public numbers from encoded data will be removed in a future version. Please use EllipticCurvePublicKey.from_encoded_pointRp   i   s   i   i   i   t   bigs(   Invalid elliptic curve point data lengths%   Unsupported elliptic curve point type(   R<   R   R=   Rq   Rr   R   Rs   t
   startswithR   R>   t   int_from_bytesR?   (   RD   R*   R+   Ru   Rm   Rn   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyRE   y  s    	Rl   Rk   Rj   c         C` se   t  | t ƒ s t S|  j | j k od |  j | j k od |  j j | j j k od |  j j | j j k S(   N(   R<   Ri   t   NotImplementedRm   Rn   R*   R   R   (   R   t   other(    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   __eq__–  s    c         C` s   |  | k S(   N(    (   R   R{   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   __ne__¡  s    c         C` s(   t  |  j |  j |  j j |  j j f ƒ S(   N(   t   hashRm   Rn   R*   R   R   (   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   __hash__¤  s    c         C` s   d j  |  ƒ S(   NsC   <EllipticCurvePublicNumbers(curve={0.curve.name}, x={0.x}, y={0.y}>(   R1   (   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   __repr__§  s    (   R   R   Ra   R)   Rv   RF   RE   R   Rb   R*   Rm   Rn   R|   R}   R   R€   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyRi   W  s   						t   EllipticCurvePrivateNumbersc           B` sS   e  Z d  „  Z d „  Z e j d ƒ Z e j d ƒ Z d „  Z d „  Z	 d „  Z
 RS(   c         C` sU   t  | t j ƒ s! t d ƒ ‚ n  t  | t ƒ s? t d ƒ ‚ n  | |  _ | |  _ d  S(   Ns!   private_value must be an integer.s>   public_numbers must be an EllipticCurvePublicNumbers instance.(   R<   R@   Re   R=   Ri   t   _private_valuet   _public_numbers(   R   Rg   R7   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyRa   ¯  s    	c         C` s   | j  |  ƒ S(   N(   t#   load_elliptic_curve_private_numbers(   R   R:   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   private_key¼  s    R‚   Rƒ   c         C` s5   t  | t ƒ s t S|  j | j k o4 |  j | j k S(   N(   R<   R   Rz   Rg   R7   (   R   R{   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR|   Â  s    c         C` s   |  | k S(   N(    (   R   R{   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR}   Ë  s    c         C` s   t  |  j |  j f ƒ S(   N(   R~   Rg   R7   (   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   Î  s    (   R   R   Ra   R…   R   Rb   Rg   R7   R|   R}   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR   ®  s   					t   ECDHc           B` s   e  Z RS(    (   R   R   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyR†   Ò  s   c         C` s0   y t  |  SWn t k
 r+ t d ƒ ‚ n Xd  S(   NsC   The provided object identifier has no matching elliptic curve class(   t   _OID_TO_CURVEt   KeyErrort   LookupError(   t   oid(    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   get_curve_for_oidí  s
    (5   t
   __future__R    R   R   R    Rq   R@   t   cryptographyR   t   cryptography.hazmat._oidR   t   objectR   t   add_metaclasst   ABCMetaR   R"   R$   R.   R4   t'   EllipticCurvePublicKeyWithSerializationt   register_interfaceR   R   R   R   R   R   R   R   R   R   R   R   R   R
   R	   R   RW   RY   R[   t   _CURVE_TYPESR_   Rd   Rh   Ri   R   R†   R   R   R   R‡   R‹   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyt   <module>   sÒ   '6
		W$

















