/opt/imunify360/venv/lib/python3.11/site-packages/Crypto/Cipher
NameSizeModeActions
__pycache__/-0755rm
AES.py89180644editdlrm
AES.pyi37160644editdlrm
ARC2.py70100644editdlrm
ARC2.pyi9800644editdlrm
ARC4.py51160644editdlrm
ARC4.pyi4130644editdlrm
Blowfish.py59640644editdlrm
Blowfish.pyi10160644editdlrm
CAST.py60710644editdlrm
CAST.pyi9810644editdlrm
ChaCha20.py107360644editdlrm
ChaCha20.pyi7880644editdlrm
ChaCha20_Poly1305.py115610644editdlrm
ChaCha20_Poly1305.pyi11060644editdlrm
DES.py59470644editdlrm
DES.pyi9610644editdlrm
DES3.py69250644editdlrm
DES3.pyi10310644editdlrm
PKCS1_OAEP.py88270644editdlrm
PKCS1_OAEP.pyi11790644editdlrm
PKCS1_v1_5.py81410644editdlrm
PKCS1_v1_5.pyi6860644editdlrm
Salsa20.py63490644editdlrm
Salsa20.pyi7510644editdlrm
_ARC4.abi3.so159440755editdlrm
_chacha20.abi3.so160640755editdlrm
_EKSBlowfish.py52050644editdlrm
_EKSBlowfish.pyi2660644editdlrm
_mode_cbc.py108880644editdlrm
_mode_cbc.pyi6870644editdlrm
_mode_ccm.py243750644editdlrm
_mode_ccm.pyi16000644editdlrm
_mode_cfb.py107210644editdlrm
_mode_cfb.pyi7270644editdlrm
_mode_ctr.py158120644editdlrm
_mode_ctr.pyi8000644editdlrm
_mode_eax.py144530644editdlrm
_mode_eax.pyi15450644editdlrm
_mode_ecb.py83090644editdlrm
_mode_ecb.pyi5920644editdlrm
_mode_gcm.py212970644editdlrm
_mode_gcm.pyi15410644editdlrm
_mode_ocb.py199350644editdlrm
_mode_ocb.pyi12310644editdlrm
_mode_ofb.py102090644editdlrm
_mode_ofb.pyi6910644editdlrm
_mode_openpgp.py70530644editdlrm
_mode_openpgp.pyi5560644editdlrm
_mode_siv.py139770644editdlrm
_mode_siv.pyi12610644editdlrm
_pkcs1_decode.abi3.so159600755editdlrm
_raw_aes.abi3.so327200755editdlrm
_raw_aesni.abi3.so203840755editdlrm
_raw_arc2.abi3.so201680755editdlrm
_raw_blowfish.abi3.so242480755editdlrm
_raw_cast.abi3.so285840755editdlrm
_raw_cbc.abi3.so159360755editdlrm
_raw_cfb.abi3.so162320755editdlrm
_raw_ctr.abi3.so162800755editdlrm
_raw_des.abi3.so492480755editdlrm
_raw_des3.abi3.so492560755editdlrm
_raw_ecb.abi3.so157840755editdlrm
_raw_eksblowfish.abi3.so324560755editdlrm
_raw_ocb.abi3.so202960755editdlrm
_raw_ofb.abi3.so159440755editdlrm
_Salsa20.abi3.so160880755editdlrm
__init__.py28440644editdlrm
__init__.pyi00644editdlrm
Edit: /opt/imunify360/venv/lib/python3.11/site-packages/Crypto/Cipher/PKCS1_OAEP.py (8827B)
# -*- coding: utf-8 -*- # # Cipher/PKCS1_OAEP.py : PKCS#1 OAEP # # =================================================================== # The contents of this file are dedicated to the public domain. To # the extent that dedication to the public domain is not available, # everyone is granted a worldwide, perpetual, royalty-free, # non-exclusive license to exercise all rights associated with the # contents of this file for any purpose whatsoever. # No rights are reserved. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # =================================================================== from Crypto.Signature.pss import MGF1 import Crypto.Hash.SHA1 from Crypto.Util.py3compat import bord, _copy_bytes import Crypto.Util.number from Crypto.Util.number import ceil_div, bytes_to_long, long_to_bytes from Crypto.Util.strxor import strxor from Crypto import Random class PKCS1OAEP_Cipher: """Cipher object for PKCS#1 v1.5 OAEP. Do not create directly: use :func:`new` instead.""" def __init__(self, key, hashAlgo, mgfunc, label, randfunc): """Initialize this PKCS#1 OAEP 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. hashAlgo : hash object The hash function to use. This can be a module under `Crypto.Hash` or an existing hash object created from any of such modules. If not specified, `Crypto.Hash.SHA1` is used. mgfunc : callable A mask generation function that accepts two parameters: a string to use as seed, and the lenth of the mask to generate, in bytes. If not specified, the standard MGF1 consistent with ``hashAlgo`` is used (a safe choice). label : bytes/bytearray/memoryview A label to apply to this particular encryption. If not specified, an empty string is used. Specifying a label does not improve security. randfunc : callable A function that returns random bytes. :attention: Modify the mask generation function only if you know what you are doing. Sender and receiver must use the same one. """ self._key = key if hashAlgo: self._hashObj = hashAlgo else: self._hashObj = Crypto.Hash.SHA1 if mgfunc: self._mgf = mgfunc else: self._mgf = lambda x,y: MGF1(x,y,self._hashObj) self._label = _copy_bytes(None, None, label) self._randfunc = randfunc def can_encrypt(self): """Legacy function to check if you can call :meth:`encrypt`. .. deprecated:: 3.0""" return self._key.can_encrypt() def can_decrypt(self): """Legacy function to check if you can call :meth:`decrypt`. .. deprecated:: 3.0""" return self._key.can_decrypt() def encrypt(self, message): """Encrypt a message with PKCS#1 OAEP. :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 2, minus twice the hash output size. For instance, if you use RSA 2048 and SHA-256, the longest message you can encrypt is 190 byte long. :type message: bytes/bytearray/memoryview :returns: The ciphertext, as large as the RSA modulus. :rtype: bytes :raises ValueError: if the message is too long. """ # See 7.1.1 in RFC3447 modBits = Crypto.Util.number.size(self._key.n) k = ceil_div(modBits, 8) # Convert from bits to bytes hLen = self._hashObj.digest_size mLen = len(message) # Step 1b ps_len = k - mLen - 2 * hLen - 2 if ps_len < 0: raise ValueError("Plaintext is too long.") # Step 2a lHash = self._hashObj.new(self._label).digest() # Step 2b ps = b'\x00' * ps_len # Step 2c db = lHash + ps + b'\x01' + _copy_bytes(None, None, message) # Step 2d ros = self._randfunc(hLen) # Step 2e dbMask = self._mgf(ros, k-hLen-1) # Step 2f maskedDB = strxor(db, dbMask) # Step 2g seedMask = self._mgf(maskedDB, hLen) # Step 2h maskedSeed = strxor(ros, seedMask) # Step 2i em = b'\x00' + maskedSeed + maskedDB # Step 3a (OS2IP) em_int = bytes_to_long(em) # Step 3b (RSAEP) m_int = self._key._encrypt(em_int) # Step 3c (I2OSP) c = long_to_bytes(m_int, k) return c def decrypt(self, ciphertext): """Decrypt a message with PKCS#1 OAEP. :param ciphertext: The encrypted message. :type ciphertext: bytes/bytearray/memoryview :returns: The original message (plaintext). :rtype: bytes :raises ValueError: if the ciphertext has the wrong length, or if decryption fails the integrity check (in which case, the decryption key is probably wrong). :raises TypeError: if the RSA key has no private half (i.e. you are trying to decrypt using a public key). """ # See 7.1.2 in RFC3447 modBits = Crypto.Util.number.size(self._key.n) k = ceil_div(modBits,8) # Convert from bits to bytes hLen = self._hashObj.digest_size # Step 1b and 1c if len(ciphertext) != k or k