o
    Þý°jƒ  ã                   @   sZ   d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 eddƒZG dd„ deƒZdd„ Zd	S )
é    ©Úbord)Úload_pycryptodome_raw_libÚVoidPointerÚSmartPointerÚcreate_string_bufferÚget_raw_bufferÚc_size_tÚc_uint8_ptrÚc_ubytezCryptodome.Hash._keccakaö  
                        int keccak_init(void **state,
                                        size_t capacity_bytes,
                                        uint8_t rounds);
                        int keccak_destroy(void *state);
                        int keccak_absorb(void *state,
                                          const uint8_t *in,
                                          size_t len);
                        int keccak_squeeze(const void *state,
                                           uint8_t *out,
                                           size_t len,
                                           uint8_t padding);
                        int keccak_digest(void *state,
                                          uint8_t *digest,
                                          size_t len,
                                          uint8_t padding);
                        int keccak_copy(const void *src, void *dst);
                        int keccak_reset(void *state);
                        c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚKeccak_Hashz¿A Keccak hash object.
    Do not instantiate directly.
    Use the :func:`new` function.

    :ivar digest_size: the size in bytes of the resulting hash
    :vartype digest_size: integer
    c                 C   sv   || _ || _d| _d| _tƒ }t | ¡ t| j d ƒt	dƒ¡}|r't
d| ƒ‚t| ¡ tjƒ| _|r9|  |¡ d S d S )NFé   é   é   z#Error %d while instantiating keccak)Údigest_sizeÚ_update_after_digestÚ_digest_doneÚ_paddingr   Ú_raw_keccak_libÚkeccak_initÚ
address_ofr	   r   Ú
ValueErrorr   ÚgetÚkeccak_destroyÚ_stateÚupdate)ÚselfÚdataÚdigest_bytesÚupdate_after_digestÚstateÚresult© r"   ú‰/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/Cryptodome/Hash/keccak.pyÚ__init__E   s"   
þÿÿzKeccak_Hash.__init__c                 C   sH   | j r
| js
tdƒ‚t | j ¡ t|ƒtt	|ƒƒ¡}|r"t
d| ƒ‚| S )z¼Continue 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 updating keccak)r   r   Ú	TypeErrorr   Úkeccak_absorbr   r   r
   r	   Úlenr   )r   r   r!   r"   r"   r#   r   X   s   
þzKeccak_Hash.updatec                 C   sJ   d| _ t| jƒ}t | j ¡ |t| jƒt| j	ƒ¡}|r!t
d| ƒ‚t|ƒS )zçReturn 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
        TzError %d while squeezing keccak)r   r   r   r   Úkeccak_digestr   r   r	   r   r   r   r   )r   Úbfrr!   r"   r"   r#   Údigesti   s   
ýzKeccak_Hash.digestc                 C   s   d  dd„ |  ¡ D ƒ¡S )zÝReturn 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                 S   s   g | ]}d t |ƒ ‘qS )z%02xr   )Ú.0Úxr"   r"   r#   Ú
<listcomp>„   s    z)Keccak_Hash.hexdigest.<locals>.<listcomp>)Újoinr*   )r   r"   r"   r#   Ú	hexdigest|   s   zKeccak_Hash.hexdigestc                 K   s(   d|vrd|vr| j |d< tdi |¤ŽS )z"Create a fresh Keccak hash object.r   Údigest_bitsNr"   )r   Únew)r   Úkwargsr"   r"   r#   r2   †   s   
zKeccak_Hash.newN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   r   r*   r0   r2   r"   r"   r"   r#   r   <   s    
r   c                  K   sª   |   dd¡}|   dd¡}|   dd¡}|   dd¡}d||fvr"tdƒ‚d||fkr,td	ƒ‚|dur9|d
vr8tdƒ‚n|dvrAtdƒ‚|d }| rOtdt| ƒ ƒ‚t|||ƒS )ao  Create a new hash object.

    Args:
        data (bytes/bytearray/memoryview):
            The very first chunk of the message to hash.
            It is equivalent to an early call to :meth:`Keccak_Hash.update`.
        digest_bytes (integer):
            The size of the digest, in bytes (28, 32, 48, 64).
        digest_bits (integer):
            The size of the digest, in bits (224, 256, 384, 512).
        update_after_digest (boolean):
            Whether :meth:`Keccak.digest` can be followed by another
            :meth:`Keccak.update` (default: ``False``).

    :Return: A :class:`Keccak_Hash` hash object
    r   Nr   Fr   r1   z*Only one digest parameter must be provided)NNz&Digest size (bits, bytes) not provided)é   é    é0   é@   z('digest_bytes' must be: 28, 32, 48 or 64)éà   é   i€  i   z,'digest_bytes' must be: 224, 256, 384 or 512é   zUnknown parameters: )Úpopr%   r   Ústrr   )r3   r   r   r   r1   r"   r"   r#   r2   �   s$   ÿr2   N)ÚCryptodome.Util.py3compatr   ÚCryptodome.Util._raw_apir   r   r   r   r   r	   r
   r   r   Úobjectr   r2   r"   r"   r"   r#   Ú<module>   s   (ÿS