관리-도구
편집 파일: _mode_siv.cpython-311.pyc
� O�Dg�6 � � � d Z dgZddlmZmZ ddlmZmZ ddlm Z ddl mZmZ ddl mZ ddlmZ dd lmZ G d � de� � Zd� ZdS ) z- Synthetic Initialization Vector (SIV) mode. �SivMode� )�hexlify� unhexlify)�bord�_copy_bytes)� is_buffer)� long_to_bytes� bytes_to_long)�_S2V)�BLAKE2s)�get_random_bytesc �X � e Zd ZdZd� Zd� Zd� Zd� Zd� Zd� Z d� Z d � Zd � Zdd�Z dd �ZdS )r a� Synthetic Initialization Vector (SIV). This is an Authenticated Encryption with Associated Data (`AEAD`_) mode. It provides both confidentiality and authenticity. The header of the message may be left in the clear, if needed, and it will still be subject to authentication. The decryption step tells the receiver if the message comes from a source that really knowns the secret key. Additionally, decryption detects if any part of the message - including the header - has been modified or corrupted. Unlike other AEAD modes such as CCM, EAX or GCM, accidental reuse of a nonce is not catastrophic for the confidentiality of the message. The only effect is that an attacker can tell when the same plaintext (and same associated data) is protected with the same key. The length of the MAC is fixed to the block size of the underlying cipher. The key size is twice the length of the key of the underlying cipher. This mode is only available for AES ciphers. +--------------------+---------------+-------------------+ | Cipher | SIV MAC size | SIV key length | | | (bytes) | (bytes) | +====================+===============+===================+ | AES-128 | 16 | 32 | +--------------------+---------------+-------------------+ | AES-192 | 16 | 48 | +--------------------+---------------+-------------------+ | AES-256 | 16 | 64 | +--------------------+---------------+-------------------+ See `RFC5297`_ and the `original paper`__. .. _RFC5297: https://tools.ietf.org/html/rfc5297 .. _AEAD: http://blog.cryptographyengineering.com/2012/05/how-to-choose-authenticated-encryption.html .. __: http://www.cs.ucdavis.edu/~rogaway/papers/keywrap.pdf :undocumented: __init__ c �0 � |j | _ || _ || _ t |� � dvrt dt |� � z � � �|�Wt |� � st d� � �t |� � dk rt d� � �t d d |� � | _ t |� � dz }d | _ t |d |� || j �� � | _ ||d � | _ |j |d |� |j fi |�� g d�| _ d S ) N)� �0 �@ zIncorrect key length (%d bytes)z?When provided, the nonce must be bytes, bytearray or memoryviewr z*When provided, the nonce must be non-empty� )� ciphermod� cipher_params��update�encrypt�decrypt�digest�verify)� block_size�_factory�_cipher_params�len� ValueErrorr � TypeErrorr �nonce�_mac_tagr �_kdf�_subkey_cipher�new�MODE_ECB�_next)�self�factory�keyr"