ok

Mini Shell

Direktori : /opt/alt/python38/lib64/python3.8/site-packages/Crypto/Hash/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/site-packages/Crypto/Hash/__pycache__/HMAC.cpython-38.pyc

U

��_��@sFdZdZdddgZddlmZddlTdZGd	d�d�Zdd
d�ZdS)a�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
z$Id$�new�digest_size�HMAC�)�strxor_c)�*Nc@s>eZdZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�Z	dS)rzClass that implements HMACNcCs�|dkrddlm}|}||_|��|_|��|_z|j|_Wn$tk
rbt|j�	��|_YnXz
|j
}Wntk
r�d}YnXd}d}t|�|kr�|�|��	�}|td�|t|�}|j�t
||��|j�t
||��|r�|�|�dS)a�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`
        N�)�MD5�@�6�\r)�r�	digestmodr�outer�innerr�AttributeError�len�digestZ
block_sizeZbchr�updater)�self�key�msgr
rZ	blocksizeZipadZopad�r�/HMAC.py�__init__Rs.



z
HMAC.__init__cCs|j�|�dS)a�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)rr)rrrrrr�szHMAC.updatecCs0ttd��}|j|_|j��|_|j��|_|S)a!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
        r)r�br
r�copyr)r�otherrrrr�s

z	HMAC.copycCs"|j��}|�|j���|��S)a}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.
        )rrrrr)r�hrrrr�s

zHMAC.digestcCsd�dd�t|���D��S)aReturn 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.
        rcSsg|]}dt|��qS)z%02x)Zbord)�.0�xrrr�
<listcomp>�s�z"HMAC.hexdigest.<locals>.<listcomp>)�join�tupler)rrrr�	hexdigest�s	

�zHMAC.hexdigest)NN)
�__name__�
__module__�__qualname__�__doc__rrrrrr#rrrrrJs
1cCst|||�S)a�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
rrrr�s)NN)	r'Z__revision__�__all__ZCrypto.Util.strxorrZCrypto.Util.py3compatrrrrrrr�<module>"s
v

Zerion Mini Shell 1.0