AlkantarClanX12

Your IP : 18.117.73.18


Current Path : /opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Hash/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Hash/__pycache__/CMAC.cpython-311.pyc

�

f��fo(���ddlmZddlmZddlmZddlmZmZddl	m
Z
mZmZddl
mZdZd
d�ZGd	�d
e��Z		dd�ZdS)�)�	unhexlify)�BLAKE2s)�strxor)�
long_to_bytes�
bytes_to_long)�bord�tobytes�_copy_bytes)�get_random_bytesNc��t|��dz|z}t|t|����t|��d�S)N�)rr�len)�bs�xor_lsb�nums   �r/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Hash/CMAC.py�_shift_bytesr$s@�������!�W�
,�C���c�"�g�g�&�&��B���x�y�y�1�1�c�F�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�ZdS)�CMACz�A CMAC hash object.
    Do not instantiate directly. Use the :func:`new` function.

    :ivar digest_size: the size in bytes of the resulting MAC tag
    :vartype digest_size: integer
    Nc�h�||_tdd|��|_||_||_|jx|_}d|_||_|dkr
d}d|_	n"|dkr
d}d|_	ntd|z���d|z}	|j||jfi|j��|_
|j
�|	��}
t|
d	��d
zrt!|
|��|_nt!|
��|_t|jd	��d
zrt!|j|��|_nt!|j��|_|j||j|	fi|j��|_t+|��|_d	|_|	|_d|_d	|_|r|�|��dSdS)N��i��l�zACMAC requires a cipher with a block size of 8 or 16 bytes, not %d�r�)�digest_sizer
�_key�_factory�_cipher_params�
block_size�_block_size�_mac_tag�_update_after_digest�	_max_size�	TypeError�new�MODE_ECB�_ecb�encryptrr�_k1�_k2�MODE_CBC�_cbc�	bytearray�_cache�_cache_n�_last_ct�_last_pt�
_data_size�update)�self�key�msg�	ciphermod�
cipher_params�mac_len�update_after_digestr�const_Rb�
zero_block�Ls           r�__init__z
CMAC.__init__3s���#�����d�C�0�0��	�!��
�+��� )� 4�4���2���
�$7��!���7�7��H�*�D�N�N�
�2�X�X��H�+�D�N�N��8�:<�=�>�>�
>��r�\�
�!�I�M�#�"+�"4�9�9�$(�$7�9�9��	�
�I���j�)�)����!��:�:���	'�#�A�x�0�0�D�H�H�#�A���D�H��������t�#�	.�#�D�H�h�7�7�D�H�H�#�D�H�-�-�D�H�"�I�M�#�"+�"4�",�9�9�%)�$7�9�9��	� ��m�m�����
�#��
���
�����	��K�K�������	�	rc��|j�|jstd���|xjt	|��z
c_|j}|jdkr�t||jz
t	|����}|d|�|j|j|j|z�<|xj|z
c_|j|kr|St|��|d�}|�
|j��d|_t	|��|z}|dkr4|�
|d|���||d�|jd|�<n|�
|��||_|S)z�Authenticate the next chunk of message.

        Args:
            data (byte string/byte array/memoryview): The next chunk of data
        Nz4update() cannot be called after digest() or verify()r)r$r%r'r5rr#r2�minr1�
memoryview�_update)r7r9r�filler�remains     rr6zCMAC.updateosL���=�$�T�-F�$��R�S�S�S����3�s�8�8�#���
�
���=�1�����d�m�+�S��X�X�6�6�F�>A�'�6�'�l�D�K��
�d�m�F�&:�:�;��M�M�V�#�M�M��}�r�!�!����S�/�/�&�'�'�*�C��L�L���%�%�%��D�M��S���B����A�:�:��L�L��X�v�g�X��'�'�'�#&��w�x�x�=�D�K���� � ��L�L�������
��rc�R�|j}t|��|zdksJ�t|��dkrdS|j�|��}t|��|kr|j}n||dz|�}||d�|_t|||d���|_dS)z,Update a block aligned to the block boundaryrN�)r#rr/r+r3rr4)r7�
data_blockr�ct�second_lasts     rrEzCMAC._update�s����
���:����#�q�(�(�(�(��z�?�?�a����F�
�Y�
�
�z�
*�
*���z�?�?�b� � ��-�K�K��b�S��U�B�3�Y�-�K��B�3�4�4���
��{�J��s�t�t�,<�=�=��
�
�
rc�,�|�t��}|j���|_|jj|j|jj|jfi|j	��|_
|jdd�|_|jdd�|_|S)a+Return a copy ("clone") of the CMAC object.

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

        :return: An :class:`CMAC`
        N)�__new__r�__dict__�copyr r(rr.r3r!r/r1)r7�objs  rrPz	CMAC.copy�s����l�l�4� � ���}�)�)�+�+���$�4�=�$�T�Y�%)�]�%;�%)�]�<�<�(,�':�<�<����[����^��
��}�Q�Q�Q�'����
rc���|j}|j�|js|jS|j|jkrtd���|jdkr&|jdkrt|j|j	��}nT|j
dd�}dd||jz
dz
zz||jd�<tt|j|��|j��}|j
�|��d|j�|_|jS)z�Return the **binary** (non-printable) MAC tag of the message
        that has been authenticated so far.

        :return: The MAC tag, computed over the data processed so far.
                 Binary form.
        :rtype: byte string
        NzMAC is unsafe for this messager��rr
)r#r$r%r5r&�
ValueErrorr2rr4r,r1r3r-r*r+r)r7r�pt�partials    r�digestzCMAC.digest�s����
���=�$�T�-F�$��=� ��?�T�^�+�+��=�>�>�>��=�A���$�/�A�"5�"5���
�t�x�0�0�B�B��k�!�!�!�n�G�&-��2��
�;M�PQ�;Q�0R�&R�G�D�M�N�N�#���t�}�g�6�6���A�A�B��	�)�)�"�-�-�.?�t�/?�.?�@��
��}�rc�~�d�d�t|�����D����S)��Return the **printable** MAC tag of the message authenticated so far.

        :return: The MAC tag, computed over the data processed so far.
                 Hexadecimal encoded.
        :rtype: string
        �c�2�g|]}dt|��z��S)z%02x)r)�.0�xs  r�
<listcomp>z"CMAC.hexdigest.<locals>.<listcomp>�s3��7�7�7����a���(�7�7�7r)�join�tuplerW)r7s r�	hexdigestzCMAC.hexdigest�sF���w�w�7�7�!&�t�{�{�}�}�!5�!5�7�7�7�8�8�	8rc��td��}tjd||���}tjd||������}|���|���krt	d���dS)agVerify that a given **binary** MAC (computed by another party)
        is valid.

        Args:
          mac_tag (byte string/byte array/memoryview): the expected MAC of the message.

        Raises:
            ValueError: if the MAC does not match. It means that the message
                has been tampered with or that the MAC key is incorrect.
        r�)�digest_bitsr8�datazMAC check failedN)rrr(rWrT)r7�mac_tag�secret�mac1�mac2s     r�verifyzCMAC.verify�sw��"�"�%�%���{�s��W�E�E�E���{�s��T�[�[�]�]�K�K�K���;�;�=�=�D�K�K�M�M�)�)��/�0�0�0�*�)rc�d�|�tt|������dS)rYN)rjrr	)r7�hex_mac_tags  r�	hexverifyzCMAC.hexverify�s,��	
���I�g�k�2�2�3�3�4�4�4�4�4r)
�__name__�
__module__�__qualname__�__doc__rrAr6rErPrWrarjrm�rrrr)s����������K�:�:�:�x � � �D>�>�>�"���*���<	8�	8�	8�1�1�1�(5�5�5�5�5rrFc���|�td���|�int|��}|�|j}|dkrtd���||jkrtd|jz���t	||||||��S)a
Create a new MAC object.

    Args:
        key (byte string/byte array/memoryview):
            key for the CMAC object.
            The key must be valid for the underlying cipher algorithm.
            For instance, it must be 16 bytes long for AES-128.
        ciphermod (module):
            A cipher module from :mod:`Crypto.Cipher`.
            The cipher's block size has to be 128 bits,
            like :mod:`Crypto.Cipher.AES`, to reduce the probability
            of collisions.
        msg (byte string/byte array/memoryview):
            Optional. The very first chunk of the message to authenticate.
            It is equivalent to an early call to `CMAC.update`. Optional.
        cipher_params (dict):
            Optional. A set of parameters to use when instantiating a cipher
            object.
        mac_len (integer):
            Length of the MAC, in bytes.
            It must be at least 4 bytes long.
            The default (and recommended) length matches the size of a cipher block.
        update_after_digest (boolean):
            Optional. By default, a hash object cannot be updated anymore after
            the digest is computed. When this flag is ``True``, such check
            is no longer enforced.
    Returns:
        A :class:`CMAC` object
    Nz%ciphermod must be specified (try AES)�z,MAC tag length must be at least 4 bytes longz>MAC tag length cannot be larger than a cipher block (%d) bytes)r'�dictr"rTr)r8r9r:r;r<r=s      rr(r(�s���@���?�@�@�@�'�/�B�B�T�-�5H�5H�M����&����{�{��G�H�H�H���%�%�%��Y�\e�\p�p�q�q�q���S�)�]�G�#�%�%�%r)r)NNNNF)�binasciir�Crypto.Hashr�Crypto.Util.strxorr�Crypto.Util.numberrr�Crypto.Util.py3compatrr	r
�
Crypto.Randomrrr�objectrr(rrrr�<module>r}s���.������������%�%�%�%�%�%�;�;�;�;�;�;�;�;�<�<�<�<�<�<�<�<�<�<�*�*�*�*�*�*���2�2�2�2�
S5�S5�S5�S5�S5�6�S5�S5�S5�lDH�!�/%�/%�/%�/%�/%�/%r