i7_ 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_stringbord_copy_bytes)is_writeable_buffer)strxor)
long_to_bytes)BLAKE2s)get_random_bytesc $ t dd| S )NEnum )type)enumss y/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Cipher/_mode_ccm.pyenumr 3 s E""" )NOT_STARTEDPROCESSING_AUTH_DATAPROCESSING_PLAINTEXTc p e Zd ZdZd Zd Zd Zd ZddZdd Z dd
Z
d Zd Zd
Z
d Zd ZddZddZdS )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