tL d Z dgZddlZddlmZmZmZmZmZm Z m Z mZ ddlm Z ddlmZmZ ddlmZ edd Z G d de Zd ZdS )z Counter (CTR) mode. CtrMode N)load_pycryptodome_raw_libVoidPointercreate_string_bufferget_raw_bufferSmartPointerc_size_tc_uint8_ptris_writeable_buffer)get_random_bytes)_copy_bytes is_native_int) long_to_byteszCrypto.Cipher._raw_ctra int CTR_start_operation(void *cipher, uint8_t initialCounterBlock[], size_t initialCounterBlock_len, size_t prefix_len, unsigned counter_len, unsigned littleEndian, void **pResult); int CTR_encrypt(void *ctrState, const uint8_t *in, uint8_t *out, size_t data_len); int CTR_decrypt(void *ctrState, const uint8_t *in, uint8_t *out, size_t data_len); int CTR_stop_operation(void *ctrState);c ( e Zd ZdZd ZddZddZdS )r a* *CounTeR (CTR)* mode. This mode is very similar to ECB, in that encryption of one block is done independently of all other blocks. Unlike ECB, the block *position* contributes to the encryption and no information leaks about symbol frequency. Each message block is associated to a *counter* which must be unique across all messages that get encrypted with the same key (not just within the same message). The counter is as big as the block size. Counters can be generated in several ways. The most straightword one is to choose an *initial counter block* (which can be made public, similarly to the *IV* for the other modes) and increment its lowest **m** bits by one (modulo *2^m*) for each block. In most cases, **m** is chosen to be half the block size. See `NIST SP800-38A`_, Section 6.5 (for the mode) and Appendix B (for how to manage the *initial counter block*). .. _`NIST SP800-38A` : http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf :undocumented: __init__ c x t | ||z k rt d|| | _ t | _ t | t | t t | t | ||| j }|rt d|z t | j t j | _ | t | | _ ddg| _ dS )aB Create a new block cipher, configured in CTR mode. :Parameters: block_cipher : C pointer A smart pointer to the low-level block cipher instance. initial_counter_block : bytes/bytearray/memoryview The initial plaintext to use to generate the key stream. It is as large as the cipher block, and it embeds the initial value of the counter. This value must not be reused. It shall contain a nonce or a random component. Reusing the *initial counter block* for encryptions performed with the same key compromises confidentiality. prefix_len : integer The amount of bytes at the beginning of the counter block that never change. counter_len : integer The length in bytes of the counter embedded in the counter block. little_endian : boolean True if the counter in the counter block is an integer encoded in little endian mode. If False, it is big endian. Nz)Error %X while instantiating the CTR modeencryptdecrypt)lenr noncer _stateraw_ctr_libCTR_start_operationgetr r address_of ValueErrorr CTR_stop_operationrelease block_size_next)selfblock_cipherinitial_counter_block prefix_lencounter_len little_endianresults y/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Cipher/_mode_ctr.py__init__zCtrMode.__init__Y s. @ $%%k)AAA$T:7LMMDJA!mm001A1A1C1C1<=R1S1S19#>S:T:T1U1U19*1E1E1<1>151G1G1I1I K K 'H%&