ff)ddlmZddlmZddlmZmZmZmZm Z m Z m Z m Z m Z eddZdZGddeZd Zd Zd Zd Zd S))get_random_bytes) _copy_bytes) load_pycryptodome_raw_libcreate_string_bufferget_raw_buffer VoidPointer SmartPointerc_size_t c_uint8_ptrc_ulongis_writeable_bufferzCrypto.Cipher._chacha20a int chacha20_init(void **pState, const uint8_t *key, size_t keySize, const uint8_t *nonce, size_t nonceSize); int chacha20_destroy(void *state); int chacha20_encrypt(void *state, const uint8_t in[], uint8_t out[], size_t len); int chacha20_seek(void *state, unsigned long block_high, unsigned long block_low, unsigned offset); int hchacha20( const uint8_t key[32], const uint8_t nonce16[16], uint8_t subkey[32]); c&t|dksJt|dksJtd}tt |t |t |}|rt d|z|S)N z,Error %d when deriving subkey with HChaCha20)len bytearray_raw_chacha20_lib hchacha20r ValueError)keynoncesubkeyresults x/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Cipher/ChaCha20.py _HChaCha20rBs s88r>>>> u::     r]]F  ( (C  E""F##%%FRG&PQQQ Mc8eZdZdZdZdZd dZdZd dZdZ dS) ChaCha20CipherzChaCha20 (or XChaCha20) cipher object. Do not create it directly. Use :py:func:`new` instead. :var nonce: The nonce with length 8, 12 or 24 bytes :vartype nonce: bytes c tdd||_t|dkr-t||dd}d|ddz}d|_nd|_|j}d|_t |_t |j t|tt||tt|}|rtd||jfzt|jtj|_dS) z\Initialize a ChaCha20/XChaCha20 cipher object See also `new()` at the module level.Nr XChaCha20ChaCha20)encryptdecryptz"Error %d instantiating a %s cipher)rrrr_name_nextr_stater chacha20_init address_ofr r rr getchacha20_destroy)selfrrrs r__init__zChaCha20Cipher.__init__\s4 !tU33  u::  S%*--C%*,E$DJJ#DJJE+ !mm "00 ..00#C(( S** U,, ..  RAVEIZEQQRR R"4;??#4#4#4#EGG rNcld|jvrtdd|_|||S)aEncrypt a piece of data. Args: plaintext(bytes/bytearray/memoryview): The data to encrypt, of any size. Keyword Args: output(bytes/bytearray/memoryview): The location where the ciphertext is written to. If ``None``, the ciphertext is returned. Returns: If ``output`` is ``None``, the ciphertext is returned as ``bytes``. Otherwise, ``None``. r%z-Cipher object can only be used for decryption)r%)r( TypeError_encrypt)r. plaintextoutputs rr%zChaCha20Cipher.encrypt|s; DJ & &KLL L! }}Y///rc *|tt|}n_|}t|stdt|t|krt dt|zt |jt|t|tt|}|rt d||j fz|t|SdS)zEncrypt without FSM checksNz4output must be a bytearray or a writeable memoryviewz9output must have the same length as the input (%d bytes)z!Error %d while encrypting with %s) rrr r1rrchacha20_encryptr)r,r r r'r)r.r3r4 ciphertextrs rr2zChaCha20Cipher._encrypts >-c)nn==JJJ&v.. X VWWW9~~V,, "025i.."ABBB#33)-):):)4Y)?)?)4Z)@)@)1#i..)A)A CC  Y@FDJCWWXX X >!*-- -4rcd|jvrtdd|_ |||S#t$r5}tt |ddd}~wwxYw)aDecrypt a piece of data. Args: ciphertext(bytes/bytearray/memoryview): The data to decrypt, of any size. Keyword Args: output(bytes/bytearray/memoryview): The location where the plaintext is written to. If ``None``, the plaintext is returned. Returns: If ``output`` is ``None``, the plaintext is returned as ``bytes``. Otherwise, ``None``. r&z-Cipher object can only be used for encryption)r&encdecN)r(r1r2rstrreplace)r.r7r4es rr&zChaCha20Cipher.decrypts DJ & &KLL L!  ;==V44 4 ; ; ;SVV^^E599:: : ;s7 A60A11A6ct|d\}}|dz}|dz }t|jt |t ||}|rt d||jfzdS)zSeek to a certain position in the key stream. Args: position (integer): The absolute position within the key stream, in bytes. @lrzError %d while seeking with %sN)divmodr chacha20_seekr)r,r rr')r.positionoffset block_low block_highrs rseekzChaCha20Cipher.seeks"(B//&z) ^ "00151B1B181D1D181C1C17 33  V=@TTUU U V Vr)N) __name__ __module__ __qualname____doc__ block_sizer/r%r2r&rFrrrrRsJGGG@0000$8;;;;,VVVVVrrc\t|dkrtd|tdx}}n>t|dkrd|z}n%t|dkr|}ntdt||d }|dd |d d|fS) zrDerive a tuple (r, s, nonce) for a Poly1305 MAC. If nonce is ``None``, a new 12-byte nonce is generated. rz-Poly1305 with ChaCha20 requires a 32-byte keyN r"z6Poly1305 with ChaCha20 requires an 8- or 12-byte nonce)rrs r)rrrnewr%)rr padded_noncerss r_derive_Poly1305_key_pairrSs  3xx2~~HIII }/333 uu Uq+U2 Ur   QRRR L ) ) ) 1 1, ? ?B crc7BrssGU ""rc  |d}n$#t$r}td|zd}~wwxYw|dd}|td}t |dkrt dt |dvrt d |rtd t |zt||S) a}Create a new ChaCha20 or XChaCha20 cipher Keyword Args: key (bytes/bytearray/memoryview): The secret key to use. It must be 32 bytes long. nonce (bytes/bytearray/memoryview): A mandatory value that must never be reused for any other encryption done with this key. For ChaCha20, it must be 8 or 12 bytes long. For XChaCha20, it must be 24 bytes long. If not provided, 8 bytes will be randomly generated (you can find them back in the ``nonce`` attribute). :Return: a :class:`Crypto.Cipher.ChaCha20.ChaCha20Cipher` object rzMissing parameter %sNrrOrz,ChaCha20/XChaCha20 key must be 32 bytes long)rOrNr!z:Nonce must be 8/12 bytes(ChaCha20) or 24 bytes (XChaCha20)zUnknown parameters: )popKeyErrorr1rrrr;r)kwargsrr=rs rrPrPs(4jj 444.23334 JJw % %E } ## 3xx2~~GHHH 5zz$$UVVV >.V<=== #u % %%s 949rrN) Crypto.RandomrCrypto.Util.py3compatrCrypto.Util._raw_apirrrrr r r r r rrobjectrrSrPrKkey_sizerLrrr]s1>+*****------7777777777777777777777.-.G2    AVAVAVAVAVVAVAVAVH###:&&&&&&R  r