관리-도구
편집 파일: _mode_ccm.cpython-311.pyc
� O�Dg7_ � � � d Z dgZddlZddlmZ ddlmZmZmZ ddl m Z ddlmZ ddl mZ dd lmZ dd lmZ d� Z eddd �� � Z G d� de� � Zd� ZdS )z" Counter with CBC-MAC (CCM) mode. �CcmMode� N)� unhexlify)�byte_string�bord�_copy_bytes)�is_writeable_buffer)�strxor)� long_to_bytes)�BLAKE2s)�get_random_bytesc �$ � t dd| � � S )N�Enum� )�type)�enumss �y/builddir/build/BUILD/imunify360-venv-2.4.0/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Cipher/_mode_ccm.py�enumr 3 s � ����E�"�"�"� � � )�NOT_STARTED�PROCESSING_AUTH_DATA�PROCESSING_PLAINTEXTc �p � e Zd ZdZd� Zd� Zd� Zd� Zdd�Zdd �Z dd �Z d� Zd� Zd � Z d� Zd� Zdd�Zdd�ZdS )r a Counter with CBC-MAC (CCM). 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. This mode requires a nonce. The nonce shall never repeat for two different messages encrypted with the same key, but it does not need to be random. Note that there is a trade-off between the size of the nonce and the maximum size of a single message you can encrypt. It is important to use a large nonce if the key is reused across several messages and the nonce is chosen randomly. It is acceptable to us a short nonce if the key is only used a few times or if the nonce is taken from a counter. The following table shows the trade-off when the nonce is chosen at random. The column on the left shows how many messages it takes for the keystream to repeat **on average**. In practice, you will want to stop using the key way before that. +--------------------+---------------+-------------------+ | Avg. # of messages | nonce | Max. message | | before keystream | size | size | | repeats | (bytes) | (bytes) | +====================+===============+===================+ | 2^52 | 13 | 64K | +--------------------+---------------+-------------------+ | 2^48 | 12 | 16M | +--------------------+---------------+-------------------+ | 2^44 | 11 | 4G | +--------------------+---------------+-------------------+ | 2^40 | 10 | 1T | +--------------------+---------------+-------------------+ | 2^36 | 9 | 64P | +--------------------+---------------+-------------------+ | 2^32 | 8 | 16E | +--------------------+---------------+-------------------+ This mode is only available for ciphers that operate on 128 bits blocks (e.g. AES but not TDES). See `NIST SP800-38C`_ or RFC3610_. .. _`NIST SP800-38C`: http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C.pdf .. _RFC3610: https://tools.ietf.org/html/rfc3610 .. _AEAD: http://blog.cryptographyengineering.com/2012/05/how-to-choose-authenticated-encryption.html :undocumented: __init__ c �T � |j | _ t d d |� � | _ || _ t d d |� � | _ || _ || _ || _ || _ d | _ | j dk rt d� � �|dvrt d|z � � �|rdt |� � cxk rdk sn t d� � � | j j ||j fdd i|��| _ t j | _ d | _ g d �| _ d| _ d| _ g | _ dt |� � z } | j j || j j fd t1 j d|dz � � | j z i|��| _ | j � d � � | _ d ||fvr| � � � d S d S )N� zFCCM mode is only available for ciphers that operate on 128 bits blocks)� � � � � � r z@Parameter 'mac_len' must be even and in the range 4..16 (not %d)� � z<Length of parameter 'nonce' must be in the range 7..13 bytes�ivs ��update�encrypt�decrypt�digest�verifyr � �nonce�Br )� block_sizer r- �_factory�_key�_mac_len�_msg_len� _assoc_len�_cipher_params�_mac_tag� ValueError�len�new�MODE_CBC�_mac� MacStatusr �_mac_status�_t�_next�_cumul_assoc_len�_cumul_msg_len�_cache�MODE_CTR�struct�pack�_cipherr( �_s_0� _start_mac) �self�factory�keyr- �mac_len�msg_len� assoc_len� cipher_params�qs r �__init__zCcmMode.__init__t s) � � "�,���@� ��t�U�3�3�� �5��� ���d�C�0�0�� ��� ��� �#���+����� ��?�b� � �� @� A� A� A� �3�3�3�� @�BI�J� K� K� K� � :�!�s�5�z�z�/�/�/�/�R�/�/�/�/�� 9� :� :� :� &�D�M�%�c�&-�&6�7� 7�)5�7� )6�7� 7�� � %�0������*� *� *�� � !"������ ��� ��U���O��(�t�}�(��)-��)?�:� :�/5�{�3��A��/F�/F���/S�:� ,9�:� :��� �L�(�(��6�6�� � � �7�+�+�+��O�O������ ,�+r c � � | j t j k sJ �d | j | j fvsJ �t | j t � � sJ �dt | j � � z }d| j dk z d| j dz dz z z |dz z }t j d|� � | j z t | j |� � z }d}| j dk r:| j d k rd}n| j d k rd}d}nd }d}|t | j |� � z }| j � d|� � | j � d|� � d� | j � � }d| _ t j | _ | � |� � d S )Nr, �@ r r r r r. r i � l s ��r s ��)r= r<