Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/Cryptodome/Hash/__pycache__/BLAKE2b.cpython-39.pyc
Ðазад
a b�h�$ � @ sr d dl mZ d dlmZmZ d dlmZ d dlmZm Z m Z mZmZm Z mZ edd�ZG dd� de�Zd d � ZdS )� )� unhexlify)�bord�tobytes)�get_random_bytes)�load_pycryptodome_raw_lib�VoidPointer�SmartPointer�create_string_buffer�get_raw_buffer�c_size_t�c_uint8_ptrzCryptodome.Hash._BLAKE2ba� int blake2b_init(void **state, const uint8_t *key, size_t key_size, size_t digest_size); int blake2b_destroy(void *state); int blake2b_update(void *state, const uint8_t *buf, size_t len); int blake2b_digest(const void *state, uint8_t digest[64]); int blake2b_copy(const void *src, void *dst); c @ sL e Zd ZdZdZdd� Zdd� Zdd� Zd d � Zdd� Z d d� Z dd� ZdS )�BLAKE2b_Hasha� A BLAKE2b 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 C s� || _ || _d| _|dv r,|s,dt|� | _t� }t�|�� t |�t t|��t |��}|rftd| ��t |�� tj�| _|r�| �|� d S )NF)� � �0 r z1.3.6.1.4.1.1722.12.2.1.z$Error %d while instantiating BLAKE2b)�digest_size�_update_after_digest�_digest_done�str�oidr �_raw_blake2b_libZblake2b_initZ address_ofr r �len� ValueErrorr �getZblake2b_destroy�_state�update)�self�data�key�digest_bytes�update_after_digest�state�result� r$ ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/Cryptodome/Hash/BLAKE2b.py�__init__L s$ ��zBLAKE2b_Hash.__init__c C sH | j r| jstd��t�| j�� t|�tt |���}|rDt d| ��| S )z�Continue hashing of a message by consuming the next chunk of data. Args: data (bytes/bytearray/memoryview): The next chunk of the message being hashed. z8You can only call 'digest' or 'hexdigest' on this objectz#Error %d while hashing BLAKE2b data)r r � TypeErrorr Zblake2b_updater r r r r r )r r r# r$ r$ r% r f s �zBLAKE2b_Hash.updatec C sB t d�}t�| j�� |�}|r*td| ��d| _t|�d| j� 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 r z&Error %d while creating BLAKE2b digestTN) r r Zblake2b_digestr r r r r r )r Zbfrr# r$ r$ r% �digestx s �zBLAKE2b_Hash.digestc C s d� dd� t| �� �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 |� �qS )z%02x)r )�.0�xr$ r$ r% � <listcomp>� � z*BLAKE2b_Hash.hexdigest.<locals>.<listcomp>)�join�tupler( )r r$ r$ r% � hexdigest� s zBLAKE2b_Hash.hexdigestc C sD t d�}td||d�}td|| �� d�}|�� |�� kr@td��dS )a` Verify that a given **binary** MAC (computed by another party) is valid. Args: mac_tag (bytes/bytearray/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. � � )�digest_bitsr r zMAC check failedN)r �newr( r )r Zmac_tag�secretZmac1Zmac2r$ r$ r% �verify� s zBLAKE2b_Hash.verifyc C s | � tt|��� dS )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)r6 r r )r Zhex_mac_tagr$ r$ r% � hexverify� s zBLAKE2b_Hash.hexverifyc K s( d|vrd|vr| j |d<