ó
Õ{PXc           @` sÞ   d  d l  m Z m Z m Z d  d l Z d  d l m Z d  d l m Z m	 Z	 m
 Z
 m Z d  d l m Z d  d l m Z m Z d  d l m Z e j e ƒ d e f d	 „  ƒ  Yƒ Z e j e ƒ d
 e f d „  ƒ  Yƒ Z d S(   i    (   t   absolute_importt   divisiont   print_functionN(   t   utils(   t   AlreadyFinalizedt
   InvalidKeyt   UnsupportedAlgorithmt   _Reasons(   t   HMACBackend(   t   constant_timet   hmac(   t   KeyDerivationFunctiont   HKDFc           B` s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C` s«   t  | t ƒ s$ t d t j ƒ ‚ n  | |  _ | d  k pE t  | t ƒ sW t d ƒ ‚ n  | d  k rz d |  j j	 d } n  | |  _
 | |  _ t |  j | | | ƒ |  _ d  S(   Ns.   Backend object does not implement HMACBackend.s   salt must be bytes.t    i   (   t
   isinstanceR   R   R   t   BACKEND_MISSING_INTERFACEt
   _algorithmt   Nonet   bytest	   TypeErrort   digest_sizet   _saltt   _backendt
   HKDFExpandt   _hkdf_expand(   t   selft	   algorithmt   lengtht   saltt   infot   backend(    (    sK   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/hkdf.pyt   __init__   s    			c         C` s8   t  j |  j |  j d |  j ƒ} | j | ƒ | j ƒ  S(   NR   (   R
   t   HMACR   R   R   t   updatet   finalize(   R   t   key_materialt   h(    (    sK   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/hkdf.pyt   _extract)   s    !c         C` s7   t  | t ƒ s t d ƒ ‚ n  |  j j |  j | ƒ ƒ S(   Ns   key_material must be bytes.(   R   R   R   R   t   deriveR%   (   R   R#   (    (    sK   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/hkdf.pyR&   .   s    c         C` s(   t  j |  j | ƒ | ƒ s$ t ‚ n  d  S(   N(   R	   t   bytes_eqR&   R   (   R   R#   t   expected_key(    (    sK   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/hkdf.pyt   verify4   s    (   t   __name__t
   __module__R   R%   R&   R)   (    (    (    sK   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/hkdf.pyR      s   			R   c           B` s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C` sÉ   t  | t ƒ s$ t d t j ƒ ‚ n  | |  _ | |  _ d | j d } | | k rk t d j	 | ƒ ƒ ‚ n  | |  _
 | d  k pŒ t  | t ƒ sž t d ƒ ‚ n  | d  k r³ d } n  | |  _ t |  _ d  S(   Ns.   Backend object does not implement HMACBackend.iÿ   i   s+   Can not derive keys larger than {0} octets.s   info must be bytes.t    (   R   R   R   R   R   R   R   R   t
   ValueErrort   formatt   _lengthR   R   R   t   _infot   Falset   _used(   R   R   R   R   R   t
   max_length(    (    sK   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/hkdf.pyR   ;   s$    					c         C` s¿   d g } d } x™ |  j  j t | ƒ d |  j k  rª t j | |  j  d |  j ƒ} | j | d ƒ | j |  j ƒ | j t	 j
 | ƒ ƒ | j | j ƒ  ƒ | d 7} q Wd j | ƒ |  j  S(   NR,   i   R   iÿÿÿÿ(   R   R   t   lenR/   R
   R    R   R!   R0   t   sixt   int2bytet   appendR"   t   join(   R   R#   t   outputt   counterR$   (    (    sK   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/hkdf.pyt   _expandZ   s    	&c         C` sF   t  | t ƒ s t d ƒ ‚ n  |  j r0 t ‚ n  t |  _ |  j | ƒ S(   Ns   key_material must be bytes.(   R   R   R   R2   R   t   TrueR;   (   R   R#   (    (    sK   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/hkdf.pyR&   h   s    			c         C` s(   t  j |  j | ƒ | ƒ s$ t ‚ n  d  S(   N(   R	   R'   R&   R   (   R   R#   R(   (    (    sK   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/hkdf.pyR)   r   s    (   R*   R+   R   R;   R&   R)   (    (    (    sK   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/hkdf.pyR   9   s   			
(   t
   __future__R    R   R   R5   t   cryptographyR   t   cryptography.exceptionsR   R   R   R   t'   cryptography.hazmat.backends.interfacesR   t   cryptography.hazmat.primitivesR	   R
   t"   cryptography.hazmat.primitives.kdfR   t   register_interfacet   objectR   R   (    (    (    sK   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/hkdf.pyt   <module>   s   "&