/opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher
NameSizeModeActions
AES.py42180644editdlrm
AES.pyc35670644editdlrm
AES.pyo35670644editdlrm
ARC2.py49170644editdlrm
ARC2.pyc42650644editdlrm
ARC2.pyo42650644editdlrm
ARC4.py42660644editdlrm
ARC4.pyc40590644editdlrm
ARC4.pyo40590644editdlrm
blockalgo.py125960644editdlrm
blockalgo.pyc63070644editdlrm
blockalgo.pyo63070644editdlrm
Blowfish.py44600644editdlrm
Blowfish.pyc38100644editdlrm
Blowfish.pyo38100644editdlrm
CAST.py44980644editdlrm
CAST.pyc38470644editdlrm
CAST.pyo38470644editdlrm
DES.py44030644editdlrm
DES.pyc37380644editdlrm
DES.pyo37380644editdlrm
DES3.py51300644editdlrm
DES3.pyc44810644editdlrm
DES3.pyo44810644editdlrm
PKCS1_OAEP.py93730644editdlrm
PKCS1_OAEP.pyc86490644editdlrm
PKCS1_OAEP.pyo86490644editdlrm
PKCS1_v1_5.py91030644editdlrm
PKCS1_v1_5.pyc92800644editdlrm
PKCS1_v1_5.pyo92800644editdlrm
XOR.py27370644editdlrm
XOR.pyc25310644editdlrm
XOR.pyo25310644editdlrm
_AES.so631280755editdlrm
_ARC2.so449770755editdlrm
_ARC4.so280800755editdlrm
_Blowfish.so559630755editdlrm
_CAST.so571030755editdlrm
_DES.so889340755editdlrm
_DES3.so890560755editdlrm
_XOR.so284280755editdlrm
__init__.py34400644editdlrm
__init__.pyc26470644editdlrm
__init__.pyo26470644editdlrm
Edit: /opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.pyo (9280B)
Ñò Bd\Rc@s^dZdZddgZddklZddkTddkZdd d„ƒYZd „ZdS( s[RSA encryption protocol according to PKCS#1 v1.5 See RFC3447__ or the `original RSA Labs specification`__ . This scheme is more properly called ``RSAES-PKCS1-v1_5``. **If you are designing a new protocol, consider using the more robust PKCS#1 OAEP.** As an example, a sender may encrypt a message in this way: >>> from Crypto.Cipher import PKCS1_v1_5 >>> from Crypto.PublicKey import RSA >>> from Crypto.Hash import SHA >>> >>> message = 'To be encrypted' >>> h = SHA.new(message) >>> >>> key = RSA.importKey(open('pubkey.der').read()) >>> cipher = PKCS1_v1_5.new(key) >>> ciphertext = cipher.encrypt(message+h.digest()) At the receiver side, decryption can be done using the private part of the RSA key: >>> From Crypto.Hash import SHA >>> from Crypto import Random >>> >>> key = RSA.importKey(open('privkey.der').read()) >>> >>> dsize = SHA.digest_size >>> sentinel = Random.new().read(15+dsize) # Let's assume that average data length is 15 >>> >>> cipher = PKCS1_v1_5.new(key) >>> message = cipher.decrypt(ciphertext, sentinel) >>> >>> digest = SHA.new(message[:-dsize]).digest() >>> if digest==message[-dsize:]: # Note how we DO NOT look for the sentinel >>> print "Encryption was correct." >>> else: >>> print "Encryption was not correct." :undocumented: __revision__, __package__ .. __: http://www.ietf.org/rfc/rfc3447.txt .. __: http://www.rsa.com/rsalabs/node.asp?id=2125. s$Id$tnewtPKCS115_Cipheriÿÿÿÿ(tceil_div(t*NcBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(sAThis cipher can perform PKCS#1 v1.5 RSA encryption or decryption.cCs ||_dS(sInitialize 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. N(t_key(tselftkey((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.pyt__init__PscCs |iiƒS(s=Return True if this cipher object can be used for encryption.(Rt can_encrypt(R((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.pyRZscCs |iiƒS(s=Return True if this cipher object can be used for decryption.(Rt can_decrypt(R((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.pyR ^sc Csø|ii}tiii|iiƒ}t|dƒ}t|ƒ}||djot dƒ‚ndd d„ƒY}t t ||ƒ|||dƒƒƒ}t dƒ|t dƒ|}|ii|dƒd} t dƒ|t| ƒ| } | S( säProduce the PKCS#1 v1.5 encryption of a message. This function is named ``RSAES-PKCS1-V1_5-ENCRYPT``, and is specified in section 7.2.1 of RFC3447. For a complete example see `Crypto.Cipher.PKCS1_v1_5`. :Parameters: message : byte string 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. :Return: A byte string, the ciphertext in which the message is encrypted. It is as long as the RSA modulus (in bytes). :Raise ValueError: If the RSA key length is not sufficiently long to deal with the given message. ii sPlaintext is too long.tnonZeroRandBytecBseZd„Zd„ZRS(cSs ||_dS(N(trf(RR ((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.pyRƒscSs2x+t|ƒdjo|idƒd}qW|S(Nii(tbordR (Rtc((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.pyt__call__„s(t__name__t __module__RR(((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.pyR ‚s iti((Rt _randfunctCryptotUtiltnumbertsizetnRtlent ValueErrorttobytestmaptbtbchrtencrypt( RtmessagetrandFunctmodBitstktmLenR tpstemtmR ((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.pyRbs  )cCsÊtiii|iiƒ}t|dƒ}t|ƒ|jotdƒ‚n|ii |ƒ}t dƒ|t|ƒ|}|i t dƒdƒ}|i t dƒƒ p |djo|S||dS(sÏ Decrypt a PKCS#1 v1.5 ciphertext. This function is named ``RSAES-PKCS1-V1_5-DECRYPT``, and is specified in section 7.2.2 of RFC3447. For a complete example see `Crypto.Cipher.PKCS1_v1_5`. :Parameters: ct : byte string The ciphertext that contains the message to recover. sentinel : any type The object to return to indicate that an error was detected during decryption. :Return: A byte string. It is either the original message or the ``sentinel`` (in case of an error). :Raise ValueError: If the ciphertext length is incorrect :Raise TypeError: If the RSA key has no private half. :attention: You should **never** let the party who submitted the ciphertext know that this function returned the ``sentinel`` value. Armed with such knowledge (for a fair amount of carefully crafted but invalid ciphertexts), an attacker is able to recontruct the plaintext of any other encryption that were carried out with the same RSA public key (see `Bleichenbacher's`__ attack). In general, it should not be possible for the other party to distinguish whether processing at the server side failed because the value returned was a ``sentinel`` as opposed to a random, invalid message. In fact, the second option is not that unlikely: encryption done according to PKCS#1 v1.5 embeds no good integrity check. There is roughly one chance in 2^16 for a random ciphertext to be returned as a valid message (although random looking). It is therefore advisabled to: 1. Select as ``sentinel`` a value that resembles a plausable random, invalid message. 2. Not report back an error as soon as you detect a ``sentinel`` value. Put differently, you should not explicitly check if the returned value is the ``sentinel`` or not. 3. Cover all possible errors with a single, generic error indicator. 4. Embed into the definition of ``message`` (at the protocol level) a digest (e.g. ``SHA-1``). It is recommended for it to be the rightmost part ``message``. 5. Where possible, monitor the number of errors due to ciphertexts originating from the same party, and slow down the rate of the requests from such party (or even blacklist it altogether). **If you are designing a new protocol, consider using the more robust PKCS#1 OAEP.** .. __: http://www.bell-labs.com/user/bleichen/papers/pkcs.ps is!Ciphertext with incorrect length.iiRi i(RRRRRRRRRtdecryptRtfindt startswithR(RtcttsentinelR!R"R&R%tsep((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.pyR's7$(RRt__doc__RRR RR'(((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.pyRMs    .cCs t|ƒS(s=Return a cipher object `PKCS115_Cipher` that can be used to perform PKCS#1 v1.5 encryption or decryption. :Parameters: key : RSA key object 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. (R(R((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.pyRØs (( R-t __revision__t__all__tCrypto.Util.numberRtCrypto.Util.py3compatRRR(((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.pytDs   ‹