ó
/<õ\c           @` 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 d  d l m Z m Z m Z d  d l m Z d	 „  Z d
 „  Z d „  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   HashBackend(   t   constant_timet   hashest   hmac(   t   KeyDerivationFunctionc         C` s   t  j d |  ƒ S(   Ns   >I(   t   structt   pack(   t   n(    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   _int_to_u32be   s    c         C` sT   |  j  d } | | k r1 t d j | ƒ ƒ ‚ n  | d  k	 rP t j d | ƒ n  d  S(   Ni   i    i   s(   Can not derive keys larger than {} bits.t	   otherinfoI       Iÿÿÿÿ    (   t   digest_sizet
   ValueErrort   formatt   NoneR   t   _check_bytes(   t	   algorithmt   lengthR   t
   max_length(    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   _common_args_checks   s    c         C` s°   t  j d |  ƒ d g } d } d } xw | | k rž | ƒ  } | j t | ƒ ƒ | j |  ƒ | j | ƒ | j | j ƒ  ƒ | t | d ƒ 7} | d 7} q( Wd j | ƒ |  S(   Nt   key_materialt    i    i   iÿÿÿÿ(   R   t   _check_bytesliket   updateR   t   appendt   finalizet   lent   join(   R   R   t   auxfnR   t   outputt   outlent   countert   h(    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   _concatkdf_derive"   s    		t   ConcatKDFHashc           B` s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C` s€   t  | | | ƒ | |  _ | |  _ | |  _ |  j d  k rF d |  _ n  t | t ƒ sj t d t j	 ƒ ‚ n  | |  _
 t |  _ d  S(   NR   s.   Backend object does not implement HashBackend.(   R   t
   _algorithmt   _lengtht
   _otherinfoR   t
   isinstanceR	   R   R   t   BACKEND_MISSING_INTERFACEt   _backendt   Falset   _used(   t   selfR   R   R   t   backend(    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   __init__6   s    				c         C` s   t  j |  j |  j ƒ S(   N(   R   t   HashR+   R0   (   R3   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   _hashG   s    c         C` s7   |  j  r t ‚ n  t |  _  t | |  j |  j |  j ƒ S(   N(   R2   R   t   TrueR)   R,   R7   R-   (   R3   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   deriveJ   s
    			c         C` s(   t  j |  j | ƒ | ƒ s$ t ‚ n  d  S(   N(   R
   t   bytes_eqR9   R   (   R3   R   t   expected_key(    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   verifyQ   s    (   t   __name__t
   __module__R5   R7   R9   R<   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyR*   4   s   			t   ConcatKDFHMACc           B` s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C` sµ   t  | | | ƒ | |  _ | |  _ | |  _ |  j d  k rF d |  _ n  | d  k rb d | j } n t j d | ƒ | |  _ t	 | t
 ƒ sŸ t d t j ƒ ‚ n  | |  _ t |  _ d  S(   NR   s    t   salts.   Backend object does not implement HMACBackend.(   R   R+   R,   R-   R   t
   block_sizeR   R   t   _saltR.   R   R   R   R/   R0   R1   R2   (   R3   R   R   R@   R   R4   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyR5   X   s     					c         C` s   t  j |  j |  j |  j ƒ S(   N(   R   t   HMACRB   R+   R0   (   R3   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   _hmacp   s    c         C` s7   |  j  r t ‚ n  t |  _  t | |  j |  j |  j ƒ S(   N(   R2   R   R8   R)   R,   RD   R-   (   R3   R   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyR9   s   s
    			c         C` s(   t  j |  j | ƒ | ƒ s$ t ‚ n  d  S(   N(   R
   R:   R9   R   (   R3   R   R;   (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyR<   z   s    (   R=   R>   R5   RD   R9   R<   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyR?   V   s   			(   t
   __future__R    R   R   R   t   cryptographyR   t   cryptography.exceptionsR   R   R   R   t'   cryptography.hazmat.backends.interfacesR   R	   t   cryptography.hazmat.primitivesR
   R   R   t"   cryptography.hazmat.primitives.kdfR   R   R   R)   t   register_interfacet   objectR*   R?   (    (    (    sK   lib/python2.7/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   <module>   s   "			!