§
    m:Rfo(  ã                   óŽ   — d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
mZmZ d dlmZ dZdd„Z G d	„ d
e¦  «        Z	 	 dd„ZdS )é    )Ú	unhexlify)ÚBLAKE2s)Ústrxor)Úlong_to_bytesÚbytes_to_long)ÚbordÚtobytesÚ_copy_bytes)Úget_random_bytesNc                 ó’   — t          | ¦  «        dz  |z  }t          |t          | ¦  «        ¦  «        t          | ¦  «         d …         S )Né   )r   r   Úlen)ÚbsÚxor_lsbÚnums      úC/var/www/bsim/venv/lib/python3.11/site-packages/Crypto/Hash/CMAC.pyÚ_shift_bytesr   $   s@   € Ý˜ÑÔ Ñ! WÑ
,€CÝ˜�c "™gœgÑ&Ô&­¨B©¬ x y yÔ1Ð1ó    c                   óF   — e Zd ZdZdZd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ ZdS )Ú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  — || _         t          d d |¦  «        | _        || _        || _        |j        x| _        }d | _        || _        |dk    r
d}d| _	        n"|dk    r
d}d| _	        nt          d|z  ¦  «        ‚d|z  }	 |j        ||j        fi | j        ¤Ž| _        | j                             |	¦  «        }
t          |
d	         ¦  «        d
z  rt!          |
|¦  «        | _        nt!          |
¦  «        | _        t          | j        d	         ¦  «        d
z  rt!          | j        |¦  «        | _        nt!          | j        ¦  «        | _         |j        ||j        |	fi | j        ¤Ž| _        t+          |¦  «        | _        d	| _        |	| _        d | _        d	| _        |r|                      |¦  «         d S d S )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Úencryptr   r   Ú_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__3   sò  € ð #ˆÔå  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˜ÑÔÐÐÐð	ð 	r   c                 ó¤  — | j         �| j        st          d¦  «        ‚| xj        t	          |¦  «        z  c_        | j        }| j        dk    r›t          || j        z
  t	          |¦  «        ¦  «        }|d|…         | j        | j        | j        |z   …<   | xj        |z  c_        | j        |k     r| S t          |¦  «        |d…         }|  
                    | j        ¦  «         d| _        t	          |¦  «        |z  }|dk    r4|  
                    |d| …         ¦  «         || d…         | j        d|…<   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'   r5   r   r#   r2   Úminr1   Ú
memoryviewÚ_update)r7   r9   r   ÚfillerÚremains        r   r6   zCMAC.updateo   sL  € ð Œ=Ð$¨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˜ÑÔÐØˆŒØˆr   c                 óR  — | j         }t          |¦  «        |z  dk    sJ ‚t          |¦  «        dk    rdS | j                             |¦  «        }t          |¦  «        |k    r| j        }n|| dz  | …         }|| d…         | _        t          ||| d…         ¦  «        | _        dS )z,Update a block aligned to the block boundaryr   Né   )r#   r   r/   r+   r3   r   r4   )r7   Ú
data_blockr   ÚctÚsecond_lasts        r   rE   z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Ô,<Ñ=Ô=ˆŒˆˆr   c                 ó,  — |                       t          ¦  «        }| j                             ¦   «         |_         | j        j        | j        | j        j        | j        fi | j	        ¤Ž|_
        | j        dd…         |_        | j        dd…         |_        |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(   r   r.   r3   r!   r/   r1   )r7   Úobjs     r   rP   z	CMAC.copy¢   s�   € ð �lŠl�4Ñ Ô ˆØ”}×)Ò)Ñ+Ô+ˆŒØ$�4”=Ô$ T¤YØ%)¤]Ô%;Ø%)¤]ð<ð <ð (,Ô':ð<ð <ˆŒð ”[   ”^ˆŒ
Ø”} Q Q QÔ'ˆŒØˆ
r   c                 óè  — | j         }| j        �| j        s| j        S | j        | j        k    rt          d¦  «        ‚| j        dk    r&| j        dk    rt          | j        | j	        ¦  «        }nT| j
        dd…         }dd|| j        z
  dz
  z  z   || j        d…<   t          t          | j        |¦  «        | j        ¦  «        }| j                             |¦  «        d| j        …         | _        | j        S )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
        NzMAC is unsafe for this messager   ó   €r   r   )r#   r$   r%   r5   r&   Ú
ValueErrorr2   r   r4   r,   r1   r3   r-   r*   r+   r   )r7   r   ÚptÚpartials       r   ÚdigestzCMAC.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Ô/?Ð.?Ô@ˆŒàŒ}Ðr   c                 ó~   — 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 | ]}d t          |¦  «        z  ‘ŒS )z%02x)r   )Ú.0Úxs     r   ú
<listcomp>z"CMAC.hexdigest.<locals>.<listcomp>Ý   s3   € ð 7ð 7ð 7Øð ¥ a¡¤Ñ(ð 7ð 7ð 7r   )ÚjoinÚtuplerW   )r7   s    r   Ú	hexdigestzCMAC.hexdigestÕ   sF   € ð �wŠwð 7ð 7Ý!& t§{¢{¡}¤}Ñ!5Ô!5ð7ñ 7ô 7ñ 8ô 8ð 	8r   c                 ó  — t          d¦  «        }t          j        d||¬¦  «        }t          j        d||                      ¦   «         ¬¦  «        }|                     ¦   «         |                     ¦   «         k    rt	          d¦  «        ‚dS )ag  Verify 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   ÚdatazMAC check failedN)r   r   r(   rW   rT   )r7   Úmac_tagÚsecretÚmac1Úmac2s        r   ÚverifyzCMAC.verifyà   sw   € õ " "Ñ%Ô%ˆåŒ{ s°¸WÐEÑEÔEˆÝŒ{ s°¸T¿[º[¹]¼]ÐKÑKÔKˆà�;Š;‰=Œ=˜DŸKšK™MœMÒ)Ð)ÝÐ/Ñ0Ô0Ð0ð *Ð)r   c                 ód   — |                       t          t          |¦  «        ¦  «        ¦  «         dS )rY   N)rj   r   r	   )r7   Úhex_mac_tags     r   Ú	hexverifyzCMAC.hexverifyô   s,   € ð 	�Š•I�g kÑ2Ô2Ñ3Ô3Ñ4Ô4Ð4Ð4Ð4r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rA   r6   rE   rP   rW   ra   rj   rm   © r   r   r   r   )   sŸ   € € € € € ðð ð €Kð:ð :ð :ðx ð  ð  ðD>ð >ð >ð"ð ð ð*ð ð ð<	8ð 	8ð 	8ð1ð 1ð 1ð(5ð 5ð 5ð 5ð 5r   r   Fc                 óò   — |€t          d¦  «        ‚|€i nt          |¦  «        }|€|j        }|dk     rt          d¦  «        ‚||j        k    rt          d|j        z  ¦  «        ‚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"   rT   r   )r8   r9   r:   r;   r<   r=   s         r   r(   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.numberr   r   ÚCrypto.Util.py3compatr   r	   r
   ÚCrypto.Randomr   r   r   Úobjectr   r(   rr   r   r   ú<module>r}      sû   ðð. Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ø *Ð *Ð *Ð *Ð *Ð *ð €ð2ð 2ð 2ð 2ð
S5ð S5ð S5ð S5ð S5ˆ6ñ S5ô S5ð S5ðl DHØ!ð/%ð /%ð /%ð /%ð /%ð /%r   