
    ¿ig$                         d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZmZ  edd          Z G d de          Zd	 Zd
S )    )	unhexlify)bordtobytes)get_random_bytes)load_pycryptodome_raw_libVoidPointerSmartPointercreate_string_bufferget_raw_bufferc_size_tc_uint8_ptrzCryptodome.Hash._BLAKE2sa  
                        int blake2s_init(void **state,
                                         const uint8_t *key,
                                         size_t key_size,
                                         size_t digest_size);
                        int blake2s_destroy(void *state);
                        int blake2s_update(void *state,
                                           const uint8_t *buf,
                                           size_t len);
                        int blake2s_digest(const void *state,
                                           uint8_t digest[32]);
                        int blake2s_copy(const void *src, void *dst);
                        c                   @    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
S )BLAKE2s_Hasha  A BLAKE2s hash object.
    Do not instantiate directly. Use the :func:`new` function.

    :ivar oid: ASN.1 Object ID
    :vartype oid: string

    :ivar block_size: the size in bytes of the internal message block,
                      input to the compression function
    :vartype block_size: integer

    :ivar digest_size: the size in bytes of the resulting hash
    :vartype digest_size: integer
        c           	         || _         || _        d| _        |dv r|sdt          |          z   | _        t                      }t                              |                                t          |          t          t          |                    t          |                    }|rt          d|z            t          |                                t          j                  | _        |r|                     |           d S d S )NF)         r   z1.3.6.1.4.1.1722.12.2.2.z$Error %d while instantiating BLAKE2s)digest_size_update_after_digest_digest_donestroidr   _raw_blake2s_libblake2s_init
address_ofr   r   len
ValueErrorr	   getblake2s_destroy_stateupdate)selfdatakeydigest_bytesupdate_after_digeststateresults          S/var/www/html/afkarena/venv/lib/python3.11/site-packages/Cryptodome/Hash/BLAKE2s.py__init__zBLAKE2s_Hash.__init__L   s    ($7!! +++C+1C4E4EEDH!..u/?/?/A/A/:3/?/?/7C/A/A/7/E/E1 1
  	NCfLMMM"599;;#3#CE E 	KK	 	    c           	         | j         r| j        st          d          t                              | j                                        t          |          t          t          |                              }|rt          d|z            | S )zContinue hashing of a message by consuming the next chunk of data.

        Args:
            data (byte string/byte array/memoryview): The next chunk of the message being hashed.
        z8You can only call 'digest' or 'hexdigest' on this objectz#Error %d while hashing BLAKE2s data)r   r   	TypeErrorr   blake2s_updater!   r   r   r   r   r   )r#   r$   r)   s      r*   r"   zBLAKE2s_Hash.updatef   s      	XT%> 	XVWWW!001B1B1<T1B1B19#d))1D1DF F  	MBVKLLLr,   c                     t          d          }t                              | j                                        |          }|rt          d|z            d| _        t          |          d| j                 S )zReturn the **binary** (non-printable) digest of the message that has been hashed so far.

        :return: The hash digest, computed over the data processed so far.
                 Binary form.
        :rtype: byte string
        r   z&Error %d while creating BLAKE2s digestTN)	r
   r   blake2s_digestr!   r   r   r   r   r   )r#   bfrr)   s      r*   digestzBLAKE2s_Hash.digestx   sx     #2&&!001B1B146 6 	PENOOO c""#4D$4#455r,   c                 ~    d                     d t          |                                           D                       S )zReturn the **printable** digest of the message that has been hashed so far.

        :return: The hash digest, 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*BLAKE2s_Hash.hexdigest.<locals>.<listcomp>   s#    GGGQa(GGGr,   )jointupler3   )r#   s    r*   	hexdigestzBLAKE2s_Hash.hexdigest   s5     wwGG%2F2FGGGHHHr,   c                    t          d          }t          d||          }t          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_bitsr%   r$   zMAC check failedN)r   newr3   r   )r#   mac_tagsecretmac1mac2s        r*   verifyzBLAKE2s_Hash.verify   ss     ""%%sW===sT[[]]CCC;;==DKKMM))/000 *)r,   c                 d    |                      t          t          |                               dS )an  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)rE   r   r   )r#   hex_mac_tags     r*   	hexverifyzBLAKE2s_Hash.hexverify   s,     	Igk223344444r,   c                 >    d|vrd|vr
| j         |d<   t          di |S )zQReturn a new instance of a BLAKE2s hash object.
        See :func:`new`.
        r&   r?    )r   r@   )r#   kwargss     r*   r@   zBLAKE2s_Hash.new   s6    
 ''M,G,G%)%5F>"}}V}}r,   N)__name__
__module____qualname____doc__
block_sizer+   r"   r3   r<   rE   rH   r@   rJ   r,   r*   r   r   :   s          J  4  $6 6 6&I I I1 1 1*5 5 5    r,   r   c                  Z   |                      dd          }|                      dd          }|                      dd          }|                      dd          }d||fvrt          d          d||fk    rd	}|d
|cxk    rd	k    sn t          d          n)d|cxk    rdk    rn n|dz  rt          d          |dz  }|                      dd          }t          |          d	k    rt          d          | rt          dt	          |           z             t          ||||          S )a  Create a new hash object.

    Args:
        data (byte string/byte array/memoryview):
            Optional. The very first chunk of the message to hash.
            It is equivalent to an early call to :meth:`BLAKE2s_Hash.update`.
        digest_bytes (integer):
            Optional. The size of the digest, in bytes (1 to 32). Default is 32.
        digest_bits (integer):
            Optional and alternative to ``digest_bytes``.
            The size of the digest, in bits (8 to 256, in steps of 8).
            Default is 256.
        key (byte string):
            Optional. The key to use to compute the MAC (1 to 64 bytes).
            If not specified, no key will be used.
        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:`BLAKE2s_Hash` hash object
    r$   Nr'   Fr&   r?   z*Only one digest parameter must be provided)NNr      z!'digest_bytes' not in range 1..32      z2'digest_bits' not in range 8..256, with steps of 8r%   r,   z"BLAKE2s key cannot exceed 32 byteszUnknown parameters: )popr.   r   r   r   r   )rK   r$   r'   r&   r?   r%   s         r*   r@   r@      su   2 ::fd##D **%:EBB::nd33L**]D11KL+...DEEEk222\''''R''''@AAA ( [''''C'''''[1_' / 0 0 0"a'
**UC
 
 C
3xx"}}=>>> >.V<===c<1DEEEr,   N)binasciir   Cryptodome.Util.py3compatr   r   Cryptodome.Randomr   Cryptodome.Util._raw_apir   r   r	   r
   r   r   r   r   objectr   r@   rJ   r,   r*   <module>r[      s  >       3 3 3 3 3 3 3 3 . . . . . ./ / / / / / / / / / / / / / / / / / -,-G   H H H H H6 H H HV2F 2F 2F 2F 2Fr,   