Current File : //usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyc
�
�/�Oc@sadZdZdddgZddlmZddlTd
Zddd��YZd
d
d	�Z	d
S(s�HMAC (Hash-based Message Authentication Code) algorithm

HMAC is a MAC defined in RFC2104_ and FIPS-198_ and constructed using
a cryptograpic hash algorithm.
It is usually named *HMAC-X*, where *X* is the hash algorithm; for
instance *HMAC-SHA1* or *HMAC-MD5*.

The strength of an HMAC depends on:

 - the strength of the hash algorithm
 - the length and entropy of the secret key

An example of possible usage is the following:

    >>> from Crypto.Hash import HMAC
    >>>
    >>> secret = b'Swordfish'
    >>> h = HMAC.new(secret)
    >>> h.update(b'Hello')
    >>> print h.hexdigest()

.. _RFC2104: http://www.ietf.org/rfc/rfc2104.txt
.. _FIPS-198: http://csrc.nist.gov/publications/fips/fips198/fips-198a.pdf
s$Id$tnewtdigest_sizetHMACi����(tstrxor_c(t*cBsGeZdZdZddd�Zd�Zd�Zd�Zd�Z	RS(sClass that implements HMACcCsK|dkr!ddl}|}n||_|j�|_|j�|_y|j|_Wn)tk
r�t|jj	��|_nXy
|j
}Wntk
r�d}nXd}d}t|�|kr�|j|�j	�}n|td�|t|�}|jjt
||��|jjt
||��|rG|j|�ndS(s�Create a new HMAC object.

        :Parameters:
          key : byte string
            secret key for the MAC object.
            It must be long enough to match the expected security level of the
            MAC. However, there is no benefit in using keys longer than the
            `digest_size` of the underlying hash algorithm.
          msg : byte string
            The very first chunk of the message to authenticate.
            It is equivalent to an early call to `update()`. Optional.
        :Parameter digestmod:
            The hash algorithm the HMAC is based on.
            Default is `Crypto.Hash.MD5`.
        :Type digestmod:
            A hash module or object instantiated from `Crypto.Hash`
        i����Ni@i6i\i(tNonetMD5t	digestmodRtoutertinnerRtAttributeErrortlentdigestt
block_sizetbchrtupdateR(tselftkeytmsgRRt	blocksizetipadtopad((s6/usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyt__init__Rs.		



cCs|jj|�dS(s�Continue authentication of a message by consuming the next chunk of data.
        
        Repeated calls are equivalent to a single call with the concatenation
        of all the arguments. In other words:

           >>> m.update(a); m.update(b)
           
        is equivalent to:
        
           >>> m.update(a+b)

        :Parameters:
          msg : byte string
            The next chunk of the message being authenticated
        N(R	R(RR((s6/usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyR�scCsFttd��}|j|_|jj�|_|jj�|_|S(s!Return a copy ("clone") of the MAC object.

        The copy will have the same internal state as the original MAC
        object.
        This can be used to efficiently compute the MAC of strings that
        share a common initial substring.

        :Returns: An `HMAC` object
        t(RtbRR	tcopyR(Rtother((s6/usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyR�s

cCs/|jj�}|j|jj��|j�S(s}Return the **binary** (non-printable) MAC of the message that has
        been authenticated so far.

        This method does not change the state of the MAC object.
        You can continue updating the object after calling this function.
        
        :Return: A byte string of `digest_size` bytes. It may contain non-ASCII
         characters, including null bytes.
        (RRRR	R(Rth((s6/usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyR�s
cCs6djgt|j��D]}dt|�^q�S(sReturn the **printable** MAC of the message that has been
        authenticated so far.

        This method does not change the state of the MAC object.
        
        :Return: A string of 2* `digest_size` bytes. It contains only
         hexadecimal ASCII digits.
        Rs%02x(tjointtupleRtbord(Rtx((s6/usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyt	hexdigest�s		N(
t__name__t
__module__t__doc__RRRRRRR (((s6/usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyRJs1			cCst|||�S(s�Create a new HMAC object.

    :Parameters:
      key : byte string
        key for the MAC object.
        It must be long enough to match the expected security level of the
        MAC. However, there is no benefit in using keys longer than the
        `digest_size` of the underlying hash algorithm.
      msg : byte string
        The very first chunk of the message to authenticate.
        It is equivalent to an early call to `HMAC.update()`.
        Optional.
    :Parameter digestmod:
        The hash to use to implement the HMAC. Default is `Crypto.Hash.MD5`.
    :Type digestmod:
        A hash module or instantiated object from `Crypto.Hash`
    :Returns: An `HMAC` object
    (R(RRR((s6/usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyR�sN((
R#t__revision__t__all__tCrypto.Util.strxorRtCrypto.Util.py3compatRRRR(((s6/usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyt<module>9s
v