File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Hash/__pycache__/KMAC128.cpython-310.pyc
Back
o ;jE � @ sl d dl mZ d dlmZmZmZ d dlmZ ddlm Z m Z ddl mZmZm Z G dd� de�Zd d � ZdS )� )� unhexlify)�bord�tobytes�is_bytes)�get_random_bytes� )� cSHAKE128�SHA3_256)�_bytepad�_encode_str� _right_encodec @ sH e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� Zdd � Z dd� Z dS )� KMAC_Hashz[A KMAC hash object. Do not instantiate directly. Use the :func:`new` function. c C sP d| | _ || _d | _ttt|��|�}|�||d�| _|r&| j�|� d S d S )Nz2.16.840.1.101.3.4.2.s KMAC) �oid�digest_size�_macr r r Z_new�_cshake�update) �self�data�key�mac_len�customZoid_variantZcshakeZrateZpartial_newX� r �K/opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Hash/KMAC128.py�__init__. s �zKMAC_Hash.__init__c C s | j rtd��| j�|� | S )z�Authenticate the next chunk of message. Args: data (bytes/bytearray/memoryview): The next chunk of the message to authenticate. z8You can only call 'digest' or 'hexdigest' on this object)r � TypeErrorr r )r r r r r r = s zKMAC_Hash.updatec C s2 | j s| j�t| jd �� | j�| j�| _ | j S )z�Return the **binary** (non-printable) MAC tag of the message. :return: The MAC tag. Binary form. :rtype: byte string � )r r r r r �read�r r r r �digestK s zKMAC_Hash.digestc C s d� dd� t| �� �D ��S )z�Return the **printable** MAC tag of the message. :return: The MAC tag. Hexadecimal encoded. :rtype: string � c S s g | ]}d t |� �qS )z%02x)r )�.0�xr r r � <listcomp>_ s z'KMAC_Hash.hexdigest.<locals>.<listcomp>)�join�tupler r r r r � hexdigestX s zKMAC_Hash.hexdigestc C sD t d�}t�|| �}t�|| �� �}|�� |�� 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. � zMAC check failedN)r r �newr � ValueError)r Zmac_tagZsecretZmac1Zmac2r r r �verifya s �zKMAC_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)r* r r )r Zhex_mac_tagr r r � hexverifyu s zKMAC_Hash.hexverifyc K s d|vr | j |d<