ó
Õ{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 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(    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   _int_to_u32be   s    c         C` s_   |  j  d } | | k r1 t d j |    n  | d  k pI t | t  s[ t d   n  d  S(   Ni   i    i   s)   Can not derive keys larger than {0} bits.s   otherinfo must be bytes.I       Iĸĸĸĸ    (   t   digest_sizet
   ValueErrort   formatt   Nonet
   isinstancet   bytest	   TypeError(   t	   algorithmt   lengtht	   otherinfot
   max_length(    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   _common_args_checks   s    c         C` sū   t  |  t  s t d   n  d g } d } d } xw | | k rŽ |   } | j t |   | j |   | j |  | j | j    | t | d  7} | d 7} q6 Wd j |  |  S(   Ns   key_material must be bytes.t    i    i   iĸĸĸĸ(	   R   R   R   t   updateR   t   appendt   finalizet   lent   join(   t   key_materialR   t   auxfnR   t   outputt   outlent   countert   h(    (    sP   /usr/lib/python2.7/dist-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   R   R	   R   R   t   BACKEND_MISSING_INTERFACEt   _backendt   Falset   _used(   t   selfR   R   R   t   backend(    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   __init__8   s    				c         C` s   t  j |  j |  j  S(   N(   R   t   HashR,   R0   (   R3   (    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   _hashI   s    c         C` s7   |  j  r t  n  t |  _  t | |  j |  j |  j  S(   N(   R2   R   t   TrueR*   R-   R7   R.   (   R3   R$   (    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   deriveL   s
    			c         C` s(   t  j |  j |  |  s$ t  n  d  S(   N(   R
   t   bytes_eqR9   R   (   R3   R$   t   expected_key(    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   verifyS   s    (   t   __name__t
   __module__R5   R7   R9   R<   (    (    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyR+   6   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 p^ t | t  sp t d   n  | d  k r d | j } n  | |  _	 t | t
  sđ t d t j   n  | |  _ t |  _ d  S(   NR   s   salt must be bytes.t    s.   Backend object does not implement HMACBackend.(   R   R,   R-   R.   R   R   R   R   t
   block_sizet   _saltR   R   R   R/   R0   R1   R2   (   R3   R   R   t   saltR   R4   (    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyR5   Z   s"    					c         C` s   t  j |  j |  j |  j  S(   N(   R   t   HMACRB   R,   R0   (   R3   (    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   _hmacq   s    c         C` s7   |  j  r t  n  t |  _  t | |  j |  j |  j  S(   N(   R2   R   R8   R*   R-   RE   R.   (   R3   R$   (    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyR9   t   s
    			c         C` s(   t  j |  j |  |  s$ t  n  d  S(   N(   R
   R:   R9   R   (   R3   R$   R;   (    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyR<   {   s    (   R=   R>   R5   RE   R9   R<   (    (    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyR?   X   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?   (    (    (    sP   /usr/lib/python2.7/dist-packages/cryptography/hazmat/primitives/kdf/concatkdf.pyt   <module>   s   "			!