ffddgZddlmZddlmZmZddlmZmZm Z ddl m Z m Z m Z e ddZd ZGd dZd d Zd S)newPKCS115_Cipher)Random) bytes_to_long long_to_bytes)bordis_bytes _copy_bytes)load_pycryptodome_raw_libc_size_t c_uint8_ptrzCrypto.Cipher._pkcs1_decodea7 int pkcs1_decode(const uint8_t *em, size_t len_em, const uint8_t *sentinel, size_t len_sentinel, size_t expected_pt_len, uint8_t *output); c rt|t|krtdtt |t t|t |t t|t |t |}|S)NzIncorrect output length)len ValueError_raw_pkcs1_decode pkcs1_decoder r )emsentinelexpected_pt_lenoutputrets z/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Cipher/PKCS1_v1_5.py _pkcs1_decoder*s 2ww#f++2333  ( (R)1#b''):):)4X)>)>)1#h--)@)@)1/)B)B)4V)<)<  > >C Jc2eZdZdZdZdZdZdZd dZdS) rzThis cipher can perform PKCS#1 v1.5 RSA encryption or decryption. Do not instantiate directly. Use :func:`Crypto.Cipher.PKCS1_v1_5.new` instead.c"||_||_dS)aJInitialize this PKCS#1 v1.5 cipher object. :Parameters: key : an RSA key object If a private half is given, both encryption and decryption are possible. If a public half is given, only encryption is possible. randfunc : callable Function that returns random bytes. N)_key _randfunc)selfkeyrandfuncs r__init__zPKCS115_Cipher.__init__;s !rc4|jS)z=Return True if this cipher object can be used for encryption.)r can_encryptrs rr$zPKCS115_Cipher.can_encryptIy$$&&&rc4|jS)z=Return True if this cipher object can be used for decryption.)r can_decryptr%s rr(zPKCS115_Cipher.can_decryptMr&rc||j}t|}||dz krtdg}t|||z dz kr]|d}t |ddkrH||t|||z dz k]d|}t|||z dz ksJd|zdztd d |z}t|}|j |}t||} | S) aProduce the PKCS#1 v1.5 encryption of a message. This function is named ``RSAES-PKCS1-V1_5-ENCRYPT``, and it is specified in `section 7.2.1 of RFC8017 `_. :param message: The message to encrypt, also known as plaintext. It can be of variable length, but not longer than the RSA modulus (in bytes) minus 11. :type message: bytes/bytearray/memoryview :Returns: A byte string, the ciphertext in which the message is encrypted. It is as long as the RSA modulus (in bytes). :Raises ValueError: If the RSA key length is not sufficiently long to deal with the given message. zPlaintext is too long.rrsN) r size_in_bytesrrrrappendjoinr r_encryptr) rmessagekmLenpsnew_byterem_intm_intcs rencryptzPKCS115_Cipher.encryptQs<* I # # % %7|| !b&==566 6 "ggTA%%~~a((HHQK  D(( IIh    "ggTA%% XXb\\2ww!d(Q,&&&& 2  '+dD'*J*J Jr"" ""6** % # #rrc|j}t||krtd|zt |}|j|}t ||}tt|}t|rt||kr$t|d||} | dkr|S|| dSt||||} || dS)aDecrypt a PKCS#1 v1.5 ciphertext. This is the function ``RSAES-PKCS1-V1_5-DECRYPT`` specified in `section 7.2.2 of RFC8017 `_. Args: ciphertext (bytes/bytearray/memoryview): The ciphertext that contains the message to recover. sentinel (any type): The object to return whenever an error is detected. expected_pt_len (integer): The length the plaintext is known to have, or 0 if unknown. Returns (byte string): It is either the original message or the ``sentinel`` (in case of an error). .. warning:: PKCS#1 v1.5 decryption is intrinsically vulnerable to timing attacks (see `Bleichenbacher's`__ attack). **Use PKCS#1 OAEP instead**. This implementation attempts to mitigate the risk with some constant-time constructs. However, they are not sufficient by themselves: the type of protocol you implement and the way you handle errors make a big difference. Specifically, you should make it very hard for the (malicious) party that submitted the ciphertext to quickly understand if decryption succeeded or not. To this end, it is recommended that your protocol only encrypts plaintexts of fixed length (``expected_pt_len``), that ``sentinel`` is a random byte string of the same length, and that processing continues for as long as possible even if ``sentinel`` is returned (i.e. in case of incorrect decryption). .. __: https://dx.doi.org/10.1007/BFb0055716 z/Ciphertext with incorrect length (not %d bytes)rrN) rr.rrr_decryptrbytes bytearrayr r) r ciphertextrrr3ct_intr8rrsizes rdecryptzPKCS115_Cipher.decryptsV I # # % % z??a  NQRRSS Sz** ""6**5! $ $y||$$!! %S]]Q%6%6 S/6BBDaxxdee}$R?FCCdee}rN)r) __name__ __module__ __qualname____doc__r"r$r(r:rBrrrr7swVV " " "'''''',,,\EEEEEErNc>| tj}t||S)aCreate a cipher for performing PKCS#1 v1.5 encryption or decryption. :param key: The key to use to encrypt or decrypt the message. This is a `Crypto.PublicKey.RSA` object. Decryption is only possible if *key* is a private RSA key. :type key: RSA key object :param randfunc: Function that return random bytes. The default is :func:`Crypto.Random.get_random_bytes`. :type randfunc: callable :returns: A cipher object `PKCS115_Cipher`. )rget_random_bytesr)r r!s rrrs" * #x ( ((r)N)__all__CryptorCrypto.Util.numberrrCrypto.Util.py3compatrr r Crypto.Util._raw_apir r r rrrrrGrrrOs. " #;;;;;;;;==========//////////.-.K   MMMMMMMM`))))))r