ff'dZdgZddlmZddlmZmZmZmZm Z m Z m Z m Z ddl mZeddZGddeZd Zd S) z Output Feedback (CFB) mode. OfbMode) _copy_bytes)load_pycryptodome_raw_lib VoidPointercreate_string_bufferget_raw_buffer SmartPointerc_size_t c_uint8_ptris_writeable_buffer)get_random_byteszCrypto.Cipher._raw_ofba int OFB_start_operation(void *cipher, const uint8_t iv[], size_t iv_len, void **pResult); int OFB_encrypt(void *ofbState, const uint8_t *in, uint8_t *out, size_t data_len); int OFB_decrypt(void *ofbState, const uint8_t *in, uint8_t *out, size_t data_len); int OFB_stop_operation(void *state); c(eZdZdZdZddZddZdS)ra*Output FeedBack (OFB)*. This mode is very similar to CBC, but it transforms the underlying block cipher into a stream cipher. The keystream is the iterated block encryption of the previous ciphertext block. An Initialization Vector (*IV*) is required. See `NIST SP800-38A`_ , Section 6.4. .. _`NIST SP800-38A` : http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf :undocumented: __init__ c Ft|_t|t |t t||j}|rtd|zt|jtj |_| t||_ tdd||_ |j|_ ddg|_dS)aSCreate a new block cipher, configured in OFB mode. :Parameters: block_cipher : C pointer A smart pointer to the low-level block cipher instance. iv : bytes/bytearray/memoryview The initialization vector to use for encryption or decryption. It is as long as the cipher block. **The IV must be a nonce, to to be reused for any other message**. It shall be a nonce or a random value. Reusing the *IV* for encryptions performed with the same key compromises confidentiality. z)Error %d while instantiating the OFB modeNencryptdecrypt)r_state raw_ofb_libOFB_start_operationgetr r len address_of ValueErrorr OFB_stop_operationrelease block_sizerivIV_next)self block_cipherrresults y/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Cipher/_mode_ofb.py__init__zOfbMode.__init__Is $"mm 001A1A1C1C1>> c.encrypt(a) + c.encrypt(b) is equivalent to: >>> c.encrypt(a+b) This function does not add any padding to the plaintext. :Parameters: plaintext : bytes/bytearray/memoryview The piece of data to encrypt. It can be of any length. :Keywords: output : bytearray/memoryview The location where the ciphertext must be written to. If ``None``, the ciphertext is returned. :Return: If ``output`` is ``None``, the ciphertext is returned as ``bytes``. Otherwise, ``None``. rz*encrypt() cannot be called after decrypt()N4output must be a bytearray or a writeable memoryview9output must have the same length as the input (%d bytes)z%Error %d while encrypting in OFB mode) r TypeErrorrrr rr OFB_encryptrrr r r)r plaintextoutput ciphertextr!s r"rzOfbMode.encryptys.B DJ & &HII I[ >-c)nn==JJJ&v.. X VWWW9~~V,, "025i.."ABBB(():):)4Y)?)?)4Z)@)@)1#i..)A)ACC  ODvMNN N >!*-- -4r$c \d|jvrtddg|_|tt|}n_|}t |stdt|t|krt dt|zt |j t|t|tt|}|rt d|z|t|SdS)aDecrypt data with the key and the parameters set at initialization. A cipher object is stateful: once you have decrypted a message you cannot decrypt (or encrypt) another message with the same object. The data to decrypt can be broken up in two or more pieces and `decrypt` can be called multiple times. That is, the statement: >>> c.decrypt(a) + c.decrypt(b) is equivalent to: >>> c.decrypt(a+b) This function does not remove any padding from the plaintext. :Parameters: ciphertext : bytes/bytearray/memoryview The piece of data to decrypt. It can be of any length. :Keywords: output : bytearray/memoryview The location where the plaintext is written to. If ``None``, the plaintext is returned. :Return: If ``output`` is ``None``, the plaintext is returned as ``bytes``. Otherwise, ``None``. rz*decrypt() cannot be called after encrypt()Nr&r'z%Error %d while decrypting in OFB mode) rr(rrr rr OFB_decryptrrr r r)rr,r+r*r!s r"rzOfbMode.decrypts.B DJ & &HII I[ >,S__==III&v.. X VWWW:#f++-- "025i.."ABBB(():):)4Z)@)@)4Y)?)?)1#j//)B)BDD  ODvMNN N >!),, ,4r$)N)__name__ __module__ __qualname____doc__r#rrr$r"rr7sW".,.,.,`;;;;z;;;;;;r$c ||}|dd}|dd}d||fkrt|j}||t dn|}t ||jkrt d|jz|rt dt|zt||S)aInstantiate a cipher object that performs OFB encryption/decryption. :Parameters: factory : module The underlying block cipher, a module from ``Crypto.Cipher``. :Keywords: iv : bytes/bytearray/memoryview The IV to use for OFB. IV : bytes/bytearray/memoryview Alias for ``iv``. Any other keyword will be passed to the underlying block cipher. See the relevant documentation for details (at least ``key`` will need to be present). rNr)NNz*You must either use 'iv' or 'IV', not bothz.Incorrect IV length (it must be %d bytes long)zUnknown parameters for OFB: %s) _create_base_cipherpopr rr(rrstrr)factorykwargs cipher_staterrs r"_create_ofb_cipherr;s&..v66L D$  B D$  BBx g0 1 1 ~ >HII I  2ww'$$$I"#$$ $H83v;;FGGG < $ $$r$N)r2__all__Crypto.Util.py3compatrCrypto.Util._raw_apirrrrr r r r Crypto.Randomr robjectrr;r3r$r"rAs . +------77777777777777777777 +*****''(@C** $zzzzzfzzzz&%&%&%&%&%r$