ó
BwLc           @   s`   d  Z  d Z d d g Z d d l Z d d l m Z d Z d d
 d „  ƒ  YZ d d d	 „ Z	 d S(   sé   HMAC (Keyed-Hashing for Message Authentication) Python module.

Implements the HMAC algorithm as described by RFC 2104.

This is just a copy of the Python 2.2 HMAC module, modified to work when
used on versions of Python before 2.2.
s   $Id$t   newt   digest_sizeiÿÿÿÿN(   t   strxor_ct   HMACc           B   sA   e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s_   RFC2104 HMAC class.

    This supports the API for Cryptographic Hash Functions (PEP 247).
    c         C   s*  | d k r! d d l } | } n  | |  _ | j ƒ  |  _ | j ƒ  |  _ y | j |  _ Wn) t k
 rƒ t |  j j	 ƒ  ƒ |  _ n Xd } d } d } t | ƒ | k rÀ | j | ƒ j	 ƒ  } n  | t
 d ƒ | t | ƒ } |  j j t | | ƒ ƒ |  j j t | | ƒ ƒ | r&|  j | ƒ n  d S(   sÝ   Create a new HMAC object.

        key:       key for the keyed hash object.
        msg:       Initial input for the hash, if provided.
        digestmod: A module supporting PEP 247. Defaults to the md5 module.
        iÿÿÿÿNi@   i6   i\   i    (   t   Nonet   MD5t	   digestmodR    t   outert   innerR   t   AttributeErrort   lent   digestt   chrt   updateR   (   t   selft   keyt   msgR   R   t	   blocksizet   ipadt   opad(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Hash/HMAC.pyt   __init__<   s(    		c         C   s   |  j  j | ƒ d S(   s8   Update this hashing object with the string msg.
        N(   R   R   (   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Hash/HMAC.pyR   _   s    c         C   s@   t  d ƒ } |  j | _ |  j j ƒ  | _ |  j j ƒ  | _ | S(   sy   Return a separate copy of this hashing object.

        An update to this copy won't affect the original object.
        t    (   R   R   R   t   copyR   (   R   t   other(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Hash/HMAC.pyR   d   s
    c         C   s/   |  j  j ƒ  } | j |  j j ƒ  ƒ | j ƒ  S(   sö   Return the hash value of this hashing object.

        This returns a string containing 8-bit data.  The object is
        not altered in any way by this function; you can continue
        updating the object after calling this function.
        (   R   R   R   R   R   (   R   t   h(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Hash/HMAC.pyR   o   s    c         C   sH   d j  g  t |  j ƒ  ƒ D]( } t j t t | ƒ ƒ d d ƒ ^ q ƒ S(   sK   Like digest(), but returns a string of hexadecimal digits instead.
        R   i   (   t   joint   tupleR   t   stringt   zfillt   hext   ord(   R   t   x(    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Hash/HMAC.pyt	   hexdigestz   s    	N(	   t   __name__t
   __module__t   __doc__R   R   R   R   R   R    (    (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Hash/HMAC.pyR   6   s   #			c         C   s   t  |  | | ƒ S(   sV  Create a new hashing object and return it.

    key: The starting key for the hash.
    msg: if available, will immediately be hashed into the object's starting
    state.

    You can now feed arbitrary strings into the object using its update()
    method, and can ask for the hash value at any time by calling its digest()
    method.
    (   R   (   R   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Hash/HMAC.pyR    €   s    (    (
   R#   t   __revision__t   __all__R   t   Crypto.Util.strxorR   R   R   R   R    (    (    (    s4   /usr/lib/python2.7/dist-packages/Crypto/Hash/HMAC.pyt   <module>(   s   J