ó
Õ{PXc           @` sÿ   d  d l  m Z m Z m Z d  d l m Z d  d l m 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 m Z d  d l m Z d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ e	 j e ƒ d e f d „  ƒ  Yƒ Z d S(   i    (   t   absolute_importt   divisiont   print_function(   t   Enum(   t   range(   t   utils(   t   AlreadyFinalizedt
   InvalidKeyt   UnsupportedAlgorithmt   _Reasons(   t   HMACBackend(   t   constant_timet   hashest   hmac(   t   KeyDerivationFunctiont   Modec           B` s   e  Z d  Z RS(   t   ctr(   t   __name__t
   __module__t   CounterMode(    (    (    sL   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/kbkdf.pyR      s   t   CounterLocationc           B` s   e  Z d  Z d Z RS(   t   before_fixedt   after_fixed(   R   R   t   BeforeFixedt
   AfterFixed(    (    (    sL   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/kbkdf.pyR      s   t	   KBKDFHMACc           B` s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C` s	  t  |
 t ƒ s$ t d t j ƒ ‚ n  t  | t j ƒ sK t d t j ƒ ‚ n  |
 j | ƒ so t d t j ƒ ‚ n  t  | t	 ƒ s t
 d ƒ ‚ n  t  | t ƒ s« t
 d ƒ ‚ n  | s· | rÌ |	 rÌ t d ƒ ‚ n  | d  k sè |  j | ƒ r÷ t d ƒ ‚ n  | d  k r|	 d  k rt d ƒ ‚ n  | d  k	 rIt  | t ƒ rIt
 d	 ƒ ‚ n  | d  k r^d
 } n  | d  k rsd
 } n  t  | t ƒ s“t  | t ƒ r¢t
 d ƒ ‚ n  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |
 |  _ t |  _ |	 |  _ d  S(   Ns.   Backend object does not implement HMACBackend.s5   Algorithm supplied is not a supported hash algorithm.s5   Algorithm supplied is not a supported hmac algorithm.s   mode must be of type Modes(   location must be of type CounterLocations9   When supplying fixed data, label and context are ignored.s   rlen must be between 1 and 4s   Please specify an llens   llen must be an integert    s'   label and context must be of type bytes(   t
   isinstanceR
   R   R	   t   BACKEND_MISSING_INTERFACER   t   HashAlgorithmt   UNSUPPORTED_HASHt   hmac_supportedR   t	   TypeErrorR   t
   ValueErrort   Nonet   _valid_byte_lengtht   intt   bytest
   _algorithmt   _modet   _lengtht   _rlent   _llent	   _locationt   _labelt   _contextt   _backendt   Falset   _usedt   _fixed_data(   t   selft	   algorithmt   modet   lengtht   rlent   llent   locationt   labelt   contextt   fixedt   backend(    (    sL   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/kbkdf.pyt   __init__   sT    												c         C` sZ   t  | t ƒ s t d ƒ ‚ n  t j d | ƒ } d t | ƒ k oM d k n sV t St S(   Ns   value must be of type inti   i   (   R   R$   R    R   t   int_to_bytest   lenR/   t   True(   R2   t   valuet	   value_bin(    (    sL   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/kbkdf.pyR#   \   s    "c         C` sm  |  j  r t ‚ n  t | t ƒ s0 t d ƒ ‚ n  t |  _  |  j |  j j } d g } t	 j
 d |  j ƒ } | t d t | ƒ d ƒ d k rž t d ƒ ‚ n  x¸ t d | d ƒ D]£ } t j | |  j d |  j ƒ} t	 j
 | |  j ƒ } |  j t j k r| j | ƒ n  | j |  j ƒ  ƒ |  j t j k rB| j | ƒ n  | j | j ƒ  ƒ q² Wd j | ƒ |  j  S(   Ns   key_material must be bytesR   i   i   i   s   There are too many iterations.R<   (   R0   R   R   R%   R    R@   R(   R&   t   digest_sizeR   R>   R)   t   powR?   R!   R   R   t   HMACR.   R+   R   R   t   updatet   _generate_fixed_inputR   t   appendt   finalizet   join(   R2   t   key_materialt   roundst   outputt   r_bint   it   ht   counter(    (    sL   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/kbkdf.pyt   derivee   s(    				#c         C` s]   |  j  r" t |  j  t ƒ r" |  j  St j |  j d |  j ƒ } d j |  j d |  j	 | g ƒ S(   Ni   R   t    (
   R1   R   R%   R   R>   R(   R*   RJ   R,   R-   (   R2   t   l(    (    sL   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/kbkdf.pyRG   Š   s    c         C` s(   t  j |  j | ƒ | ƒ s$ t ‚ n  d  S(   N(   R   t   bytes_eqRR   R   (   R2   RK   t   expected_key(    (    sL   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/kbkdf.pyt   verify’   s    (   R   R   R=   R#   RR   RG   RW   (    (    (    sL   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/kbkdf.pyR      s
   	=			%	N(   t
   __future__R    R   R   t   enumR   t	   six.movesR   t   cryptographyR   t   cryptography.exceptionsR   R   R   R	   t'   cryptography.hazmat.backends.interfacesR
   t   cryptography.hazmat.primitivesR   R   R   t"   cryptography.hazmat.primitives.kdfR   R   R   t   register_interfacet   objectR   (    (    (    sL   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/kbkdf.pyt   <module>   s   "