File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Cipher/__pycache__/_mode_kwp.cpython-310.pyc
Back
o ;jc � @ sb d dl Z d dlmZ d dlmZ ddlmZmZ G dd� de�Z ded ee ef d e fdd�ZdS ) � N)� ModuleType)�Union� )�W� W_inversec @ s^ e Zd ZdZdedeeef fdd�Zdeeef defdd �Z d eeef defdd�Z d S )�KWPModea Key Wrap with Padding (KWP) mode. This is a deterministic Authenticated Encryption (AE) mode for protecting cryptographic keys. See `NIST SP800-38F`_. It provides both confidentiality and authenticity, and it designed so that any bit of the ciphertext depends on all bits of the plaintext. This mode is only available for ciphers that operate on 128 bits blocks (e.g., AES). .. _`NIST SP800-38F`: http://csrc.nist.gov/publications/nistpubs/800-38F/SP-800-38F.pdf :undocumented: __init__ �factory�keyc C s: |j | _ | j dkr td��|| _|�||j�| _d| _d S )N� zXKey Wrap with Padding mode is only available for ciphers that operate on 128 bits blocksF)� block_size� ValueError�_factory�newZMODE_ECB�_cipher�_done)�selfr r � r �O/opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Cipher/_mode_kwp.py�__init__ s zKWPMode.__init__� plaintext�returnc C s� | j rtd��t|�dkrtd��t|�dkrtd��dt|� d }|d| }dt�d t|�� }t|�dkrC| j�|| �}|S t| j|| �}|S ) z�Encrypt and authenticate (wrap) a cryptographic key. Args: plaintext: The cryptographic key to wrap. Returns: The wrapped key. �(The cipher cannot be used more than oncer z%The plaintext must be at least 1 bytel zThe plaintext is too long� � � �YY��>I)r r �len�struct�packr Zencryptr )r r �padlenZpaddedZAIV�resr r r �seal'