Ë
    (üàg)  ã                   ó†   — 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y)é    )Ú	unhexlify)ÚBLAKE2s)Ústrxor)Úlong_to_bytesÚbytes_to_long)ÚbordÚtobytesÚ_copy_bytes)Úget_random_bytesNc                 óh   — t        | «      dz  |z  }t        |t        | «      «      t        | «       d  S )Né   )r   r   Úlen)ÚbsÚxor_lsbÚnums      úN/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/Crypto/Hash/CMAC.pyÚ_shift_bytesr   $   s4   € Ü˜Ó Ñ! WÑ
,€CÜ˜œc "›gÓ&¬¨B« x yÐ1Ð1ó    c                   óD   — e Zd ZdZdZd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zy)Ú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                 ój  — || _         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                  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| j7                  |«       y y )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ˆŒ	Ø!ˆŒØ+ˆÔØ )× 4Ñ 4Ð4ˆÔ˜2ØˆŒØ$7ˆÔ!ð �Š7ØˆHØ*ˆD�NØ�2ŠXØˆHØ+ˆD�Näð 8Ø:<ñ=ó >ð >ð ˜r‘\ˆ
Ø!�I—M‘M #Ø"+×"4Ñ"4ñ9à$(×$7Ñ$7ñ9ˆŒ	ð �I‰I×Ñ˜jÓ)ˆÜ��!‘‹:˜ÒÜ# A xÓ0ˆD�Hä# A“ˆDŒHÜ�—‘˜‘Ó˜tÒ#Ü# D§H¡H¨hÓ7ˆD�Hä# D§H¡HÓ-ˆDŒHð "�I—M‘M #Ø"+×"4Ñ"4Ø",ñ9ð %)×$7Ñ$7ñ9ˆŒ	ô   “mˆŒØˆŒð #ˆŒð ˆŒð ˆŒáØ�K‰K˜Õð r   c                 ó¨  — | j                   �| j                  st        d«      ‚| xj                  t	        |«      z  c_        | j
                  }| j                  dkD  r¡t        || j                  z
  t	        |«      «      }|d| | j                  | j                  | j                  |z    | xj                  |z  c_        | j                  |k  r| S t        |«      |d }| j                  | j                  «       d| _        t	        |«      |z  }|dkD  r)| j                  |d|  «       || d | j                  d| n| j                  |«       || _        | 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   s%  € ð �=‰=Ð$¨T×-FÒ-FÜÐRÓSÐSà�Šœ3˜s›8Ñ#�Ø×Ñˆà�=‰=˜1ÒÜ˜˜dŸm™mÑ+¬S°«XÓ6ˆFØ>AÀ'À6¸lˆD�K‰K˜Ÿ™ d§m¡m°FÑ&:Ð;Ø�MŠM˜VÑ#�Mà�}‰}˜rÒ!Ø�ä˜S“/ & 'Ð*ˆCØ�L‰L˜Ÿ™Ô%ØˆDŒMä�S“˜B‘ˆØ�AŠ:Ø�L‰L˜˜X˜v˜g˜Ô'Ø#&¨ w x =ˆD�K‰K˜˜Ñ à�L‰L˜ÔØˆŒØˆr   c                 ó   — | j                   }t        |«      |z  dk(  sJ ‚t        |«      dk(  ry| j                  j                  |«      }t        |«      |k(  r| j                  }n
|| dz  |  }|| d | _        t        ||| d «      | _        y)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ÒØà�Y‰Y×Ñ˜zÓ*ˆÜˆz‹?˜bÒ ØŸ-™-‰Kà˜b˜S ™U B 3˜-ˆKØ˜B˜3˜4˜ˆŒÜ˜{¨J¸°s°tÐ,<Ó=ˆ�r   c                 ój  — | j                  t        «      }| j                  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¡YØ%)§]¡]×%;Ñ%;Ø%)§]¡]ñ<ð (,×':Ñ':ñ<ˆŒð —[‘[¡�^ˆŒ
Ø—}‘}¡QÐ'ˆŒØˆ
r   c                 óV  — | j                   }| j                  �| j                  s| j                  S | j                  | j                  kD  rt        d«      ‚| j                  dk(  r0| j                  dkD  r!t        | j                  | j                  «      }n^| j                  dd }dd|| j                  z
  dz
  z  z   || j                  d t        t        | j                  |«      | 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Ò-FØ—=‘=Ð à�?‰?˜TŸ^™^Ò+ÜÐ=Ó>Ð>à�=‰=˜AÒ $§/¡/°AÒ"5ä˜Ÿ™ t§x¡xÓ0‰Bð —k‘k¡!�nˆGØ&-°¸2ÀÇÁÑ;MÐPQÑ;QÑ0RÑ&RˆG�D—M‘M�NÐ#Üœ˜tŸ}™}¨gÓ6¸¿¹ÓAˆBàŸ	™	×)Ñ)¨"Ó-Ð.?¨t×/?Ñ/?Ð@ˆŒà�}‰}Ðr   c           	      ó�   — dj                  t        | j                  «       «      D �cg c]  }dt        |«      z  ‘Œ c}«      S c c}w )zÓ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
        Ú z%02x)ÚjoinÚtuplerW   r   )r7   Úxs     r   Ú	hexdigestzCMAC.hexdigestÕ   sD   € ð �w‰wÜ!& t§{¡{£}Ó!5ö7Øð ¤ a£Ó(ò 7ó 8ð 	8ùò 7s   §Ac                 óî   — t        d«      }t        j                  d||¬«      }t        j                  d|| j                  «       ¬«      }|j                  «       |j                  «       k7  rt	        d«      ‚y)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à   s]   € ô " "Ó%ˆä�{‰{ s°¸WÔEˆÜ�{‰{ s°¸T¿[¹[»]ÔKˆà�;‰;‹=˜DŸK™K›MÒ)ÜÐ/Ó0Ð0ð *r   c                 óJ   — | j                  t        t        |«      «      «       y)al  Verify that a given **printable** MAC (computed by another party)
        is valid.

        Args:
          hex_mac_tag (string): the expected MAC of the message, as a hexadecimal string.

        Raises:
            ValueError: if the MAC does not match. It means that the message
                has been tampered with or that the MAC key is incorrect.
        N)rf   r   r	   )r7   Úhex_mac_tags     r   Ú	hexverifyzCMAC.hexverifyô   s   € ð 	�‰”Iœg kÓ2Ó3Õ4r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rA   r6   rE   rP   rW   r]   rf   ri   © r   r   r   r   )   s8   „ ñð €Kò:òx òD>ò"ò*ò<	8ò1ó(5r   r   c                 óä   — |€t        d«      ‚|€i n
t        |«      }|€|j                  }|dk  rt        d«      ‚||j                  kD  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
    z%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´T¸-Ó5H€Mà€Ø×&Ñ&ˆà�‚{ÜÐGÓHÐHà�×%Ñ%Ò%ÜÐYÐ\e×\pÑ\pÑpÓ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(   rn   r   r   ú<module>ry      sF   ðõ. å Ý %ß ;ß <Ñ <Ý *ð €ó2ô
W5ˆ6ô W5ðt DHØ!ô/%r   