File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Hash/__pycache__/Poly1305.cpython-310.pyc
Back
o ;j� � @ s� d dl mZ d dlmZmZmZ d dlmZ d dlm Z d dl mZmZm Z mZmZmZmZ edd�ZG dd � d e�Zd d� ZdS ) � )� unhexlify)�bord�tobytes�_copy_bytes)�BLAKE2s)�get_random_bytes)�load_pycryptodome_raw_lib�VoidPointer�SmartPointer�create_string_buffer�get_raw_buffer�c_size_t�c_uint8_ptrzCryptodome.Hash._poly1305a� int poly1305_init(void **state, const uint8_t *r, size_t r_len, const uint8_t *s, size_t s_len); int poly1305_destroy(void *state); int poly1305_update(void *state, const uint8_t *in, size_t len); int poly1305_digest(const void *state, uint8_t *digest, size_t len); c @ sL e Zd ZdZdZdd� Zdd� Zdd� Zd d � Zdd� Z d d� Z dd� ZdS )�Poly1305_MACz�An Poly1305 MAC 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 � c C s� t |�dkr td��t |�dkrtd��d | _t� }t�|�� t|�tt |��t|�tt |���}|r9td| ��t |� � tj�| _|rK| � |� d S d S )Nr z Parameter r is not 16 bytes longz Parameter s is not 16 bytes longz%Error %d while instantiating Poly1305)�len� ValueError�_mac_tagr � _raw_poly1305Z poly1305_initZ address_ofr r r �getZpoly1305_destroy�_state�update)�self�r�s�data�state�result� r �L/opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Hash/Poly1305.py�__init__? s( ���zPoly1305_MAC.__init__c C sB | j rtd��t�| j�� t|�tt|���}|rt d| ��| S )z�Authenticate the next chunk of message. Args: data (byte string/byte array/memoryview): The next chunk of data z8You can only call 'digest' or 'hexdigest' on this objectz$Error %d while hashing Poly1305 data) r � TypeErrorr Zpoly1305_updater r r r r r )r r r r r r r V s �zPoly1305_MAC.updatec C s t � �)N)�NotImplementedError�r r r r �copyg s zPoly1305_MAC.copyc C sP | j r| j S td�}t�| j�� |tt|���}|r td| ��t |�| _ | j S )z�Return the **binary** (non-printable) MAC tag of the message authenticated so far. :return: The MAC tag digest, computed over the data processed so far. Binary form. :rtype: byte string r z'Error %d while creating Poly1305 digest) r r r Zpoly1305_digestr r r r r r )r Zbfrr r r r �digestj s � zPoly1305_MAC.digestc C s d� dd� t| �� �D ��S )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 � c S s g | ]}d t |� �qS )z%02x)r )�.0�xr r r � <listcomp>� s �z*Poly1305_MAC.hexdigest.<locals>.<listcomp>)�join�tupler% r# r r r � hexdigest� s �zPoly1305_MAC.hexdigestc C sH t d�}tjd||d�}tjd|| �� d�}|�� |�� kr"td��dS )ah Verify that a given **binary** MAC (computed by another party) is valid. Args: mac_tag (byte string/byte string/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 � )Zdigest_bits�keyr zMAC check failedN)r r �newr% r )r Zmac_tagZsecretZmac1Zmac2r r r �verify� s �zPoly1305_MAC.verifyc C s | � tt|��� dS )a~ 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)r0 r r )r Zhex_mac_tagr r r � hexverify� s zPoly1305_MAC.hexverifyN)�__name__� __module__�__qualname__�__doc__�digest_sizer r r$ r% r, r0 r1 r r r r r 5 s r c K s� | � dd�}t|d�std��| � dd�}|du rtd��| � dd�}| � dd�}| r3td t| � ��|�||�\}}}t|||�}tdd|�|_|S ) a� Create a new Poly1305 MAC object. Args: key (bytes/bytearray/memoryview): The 32-byte key for the Poly1305 object. cipher (module from ``Cryptodome.Cipher``): The cipher algorithm to use for deriving the Poly1305 key pair *(r, s)*. It can only be ``Cryptodome.Cipher.AES`` or ``Cryptodome.Cipher.ChaCha20``. nonce (bytes/bytearray/memoryview): Optional. The non-repeatable value to use for the MAC of this message. It must be 16 bytes long for ``AES`` and 8 or 12 bytes for ``ChaCha20``. If not passed, a random nonce is created; you will find it in the ``nonce`` attribute of the new object. data (bytes/bytearray/memoryview): Optional. The very first chunk of the message to authenticate. It is equivalent to an early call to ``update()``. Returns: A :class:`Poly1305_MAC` object �cipherN�_derive_Poly1305_key_pairz*Parameter 'cipher' must be AES or ChaCha20r. zYou must pass a parameter 'key'�noncer zUnknown parameters: ) �pop�hasattrr r! �strr8 r r r9 )�kwargsr7 Z cipher_keyr9 r r r Znew_macr r r r/ � s r/ N)�binasciir ZCryptodome.Util.py3compatr r r ZCryptodome.Hashr ZCryptodome.Randomr ZCryptodome.Util._raw_apir r r r r r r r �objectr r/ r r r r �<module> s $�{
| ver. 1.4 |
Github
|
.
| PHP 8.2.30 | Generation time: 0 |
proxy
|
phpinfo
|
Settings