File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Cipher/__pycache__/_mode_gcm.cpython-310.pyc
Back
o ;j]S � @ s� d Z dgZddlmZ ddlmZmZ ddlmZ ddl m Z mZ ddlm Z ddlmZ dd lmZmZmZmZmZmZmZ dd lmZ dZdd � Zdd� Ze� Zdd� Ze� ZG dd� de�Z dd� Z!e!ddd�Z"G dd� de�Z#dd� Z$dS )z Galois/Counter Mode (GCM). �GcmMode� )� unhexlify)�bord�_copy_bytes)� is_buffer)� long_to_bytes� bytes_to_long)�BLAKE2s)�get_random_bytes)�load_pycryptodome_raw_lib�VoidPointer�create_string_buffer�get_raw_buffer�SmartPointer�c_size_t�c_uint8_ptr)� _cpu_featuresa` int ghash_%imp%(uint8_t y_out[16], const uint8_t block_data[], size_t len, const uint8_t y_in[16], const void *exp_key); int ghash_expand_%imp%(const uint8_t h[16], void **ghash_tables); int ghash_destroy_%imp%(void *ghash_tables); c sl ddl m} d}|d|�}z� �fdd�|D �}W n ty' d gd }Y nw tt||��}|di |��S ) Nr )� namedtuple)�ghash�ghash_expand� ghash_destroyZ _GHash_Impc s g | ]}t � |d � ��qS )�_)�getattr��.0�x��lib�postfix� �O/opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Cipher/_mode_gcm.py� <listcomp>H s z_build_impl.<locals>.<listcomp>� r )�collectionsr �AttributeError�dict�zip)r r r �funcsZ GHASH_ImpZ imp_funcs�paramsr r r �_build_implB s �r) c C s$ t �dd�} td| �}t|d�}|S )N�%imp%ZportablezCryptodome.Hash._ghash_portable)�_ghash_api_template�replacer r) �Zapir �resultr r r �_get_ghash_portableO s r/ c C sL t �� sdS zt�dd�} td| �}t|d�}W |S ty% d}Y |S w )z4Return None if CLMUL implementation is not availableNr* ZclmulzCryptodome.Hash._ghash_clmul)r Z have_clmulr+ r, r r) �OSErrorr- r r r �_get_ghash_clmulW s ��r1 c @ s( e Zd ZdZdd� Zdd� Zdd� ZdS ) �_GHASHa GHASH function defined in NIST SP 800-38D, Algorithm 2. If X_1, X_2, .. X_m are the blocks of input data, the function computes: X_1*H^{m} + X_2*H^{m-1} + ... + X_m*H in the Galois field GF(2^256) using the reducing polynomial (x^128 + x^7 + x^2 + x + 1). c C sf t |�dksJ �|| _t� | _|�t|�| j�� �}|r"td| ��t| j� � |j �| _td�| _d S )N� z&Error %d while expanding the GHASH key) �len�ghash_cr �_exp_keyr r Z address_of� ValueErrorr �getr r �_last_y)�selfZsubkeyr5 r. r r r �__init__r s � �z_GHASH.__init__c C sR t |�d dks J �| j�| jt|�tt |��| j| j�� �}|r'td| ��| S )Nr3 r zError %d while updating GHASH) r4 r5 r r9 r r r6 r8 r7 )r: Z block_datar. r r r �update� s �z _GHASH.updatec C s t | j�S �N)r r9 �r: r r r �digest� s z _GHASH.digestN)�__name__� __module__�__qualname__�__doc__r; r<