/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey
NameSizeModeActions
DSA.py136950644editdlrm
DSA.pyc148070644editdlrm
DSA.pyo148070644editdlrm
ElGamal.py132120644editdlrm
ElGamal.pyc133430644editdlrm
ElGamal.pyo133430644editdlrm
pubkey.py82210644editdlrm
pubkey.pyc90980644editdlrm
pubkey.pyo90980644editdlrm
RSA.py298970644editdlrm
RSA.pyc267950644editdlrm
RSA.pyo267950644editdlrm
_DSA.py34730644editdlrm
_DSA.pyc33370644editdlrm
_DSA.pyo33370644editdlrm
_fastmath.so1166670755editdlrm
_RSA.py27620644editdlrm
_RSA.pyc19750644editdlrm
_RSA.pyo18900644editdlrm
_slowmath.py64210644editdlrm
_slowmath.pyc65730644editdlrm
_slowmath.pyo61370644editdlrm
__init__.py18760644editdlrm
__init__.pyc10990644editdlrm
__init__.pyo10990644editdlrm
Edit: /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyc (13343B)
Ñò Bd\Rc@sƒdZdZddddgZddkTddklZdefd „ƒYZd d „Z d „Z de fd „ƒYZ e Z d S(sP ElGamal public-key algorithm (randomized encryption and signature). Signature algorithm ------------------- The security of the ElGamal signature scheme is based (like DSA) on the discrete logarithm problem (DLP_). Given a cyclic group, a generator *g*, and an element *h*, it is hard to find an integer *x* such that *g^x = h*. The group is the largest multiplicative sub-group of the integers modulo *p*, with *p* prime. The signer holds a value *x* (*0>> from Crypto import Random >>> from Crypto.Random import random >>> from Crypto.PublicKey import ElGamal >>> from Crypto.Util.number import GCD >>> from Crypto.Hash import SHA >>> >>> message = "Hello" >>> key = ElGamal.generate(1024, Random.new().read) >>> h = SHA.new(message).digest() >>> while 1: >>> k = random.StrongRandom().randint(1,key.p-1) >>> if GCD(k,key.p-1)==1: break >>> sig = key.sign(h,k) >>> ... >>> if key.verify(h,sig): >>> print "OK" >>> else: >>> print "Incorrect signature" .. _DLP: http://www.cosic.esat.kuleuven.be/publications/talk-78.pdf .. _CDH: http://en.wikipedia.org/wiki/Computational_Diffie%E2%80%93Hellman_assumption .. _ECRYPT: http://www.ecrypt.eu.org/documents/D.SPA.17.pdf s$Id$tgeneratet constructterrort ElGamalobjiÿÿÿÿ(t*(tnumbercBseZRS((t__name__t __module__(((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyRsscCs÷tƒ}|o|dƒnxKtt|d|ƒƒ}d|d|_ti|id|ƒoPq!q!|o|dƒnxtid|i|ƒ|_d}t|id|iƒdjo d}n|o)t|i||iƒdjo d}n|o.t |id|iƒddjo d}nti |i|iƒ}|o+t |id|ƒddjo d}n|oPq„q„|o|dƒntid|id|ƒ|_ |o|d ƒnt|i|i |iƒ|_ |S( s'Randomly generate a fresh, new ElGamal key. The key will be safe for use for both encryption and signature (although it should be used for **only one** purpose). :Parameters: bits : int Key length, or size (in bits) of the modulus *p*. Recommended value is 2048. randfunc : callable Random number generation function; it should accept a single integer N and return a string of random data N bytes long. progress_func : callable Optional function that will be called with a short string containing the key parameter currently being generated; it's useful for interactive applications where a user is waiting for a key to be generated. :attention: You should always use a cryptographically secure random number generator, such as the one defined in the ``Crypto.Random`` module; **don't** just use the current time and the ``random`` module. :Return: An ElGamal key object (`ElGamalobj`). sp iitrandfuncsg iisx sy ( RtbignumtgetPrimetpRtisPrimetgetRandomRangetgtpowtdivmodtinversetxty(tbitsRt progress_functobjtqtsafetginv((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyRws>  & + ( cCsntƒ}t|ƒdjotdƒ‚nx;tt|ƒƒD]'}|i|}t||||ƒq?W|S(s*Construct an ElGamal key from a tuple of valid ElGamal components. The modulus *p* must be a prime. The following conditions must apply: - 1 < g < p-1 - g^{p-1} = 1 mod p - 1 < x < p-1 - g^x = y mod p :Parameters: tup : tuple A tuple of long integers, with 3 or 4 items in the following order: 1. Modulus (*p*). 2. Generator (*g*). 3. Public key (*y*). 4. Private key (*x*). Optional. :Return: An ElGamal key object (`ElGamalobj`). iis%argument for construct() wrong length(ii(Rtlent ValueErrortrangetkeydatatsetattr(ttupRtitfield((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyRÁs  cBsƒeZdZddddgZd„Zd„Zd„Zd„Zd „Zd „Z d „Z d „Z d „Z d„Z d„ZRS(siClass defining an ElGamal key. :undocumented: __getstate__, __setstate__, __repr__, __getattr__ R RRRcCsti|||ƒS(sREncrypt a piece of data with ElGamal. :Parameter plaintext: The piece of data to encrypt with ElGamal. It must be numerically smaller than the module (*p*). :Type plaintext: byte string or long :Parameter K: A secret number, chosen randomly in the closed range *[1,p-2]*. :Type K: long (recommended) or byte string (not recommended) :Return: A tuple with two items. Each item is of the same type as the plaintext (string or long). :attention: selection of *K* is crucial for security. Generating a random number larger than *p-1* and taking the modulus by *p-1* is **not** secure, since smaller values will occur more frequently. Generating a random number systematically smaller than *p-1* (e.g. *floor((p-1)/8)* random bytes) is also **not** secure. In general, it shall not be possible for an attacker to know the value of any bit of K. :attention: The number *K* shall not be reused for any other operation and shall be discarded immediately. (tpubkeytencrypt(tselft plaintexttK((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyR#õscCsti||ƒS(sPDecrypt a piece of data with ElGamal. :Parameter ciphertext: The piece of data to decrypt with ElGamal. :Type ciphertext: byte string, long or a 2-item tuple as returned by `encrypt` :Return: A byte string if ciphertext was a byte string or a tuple of byte strings. A long otherwise. (R"tdecrypt(R$t ciphertext((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyR's cCsti|||ƒS(s„Sign a piece of data with ElGamal. :Parameter M: The piece of data to sign with ElGamal. It may not be longer in bit size than *p-1*. :Type M: byte string or long :Parameter K: A secret number, chosen randomly in the closed range *[1,p-2]* and such that *gcd(k,p-1)=1*. :Type K: long (recommended) or byte string (not recommended) :attention: selection of *K* is crucial for security. Generating a random number larger than *p-1* and taking the modulus by *p-1* is **not** secure, since smaller values will occur more frequently. Generating a random number systematically smaller than *p-1* (e.g. *floor((p-1)/8)* random bytes) is also **not** secure. In general, it shall not be possible for an attacker to know the value of any bit of K. :attention: The number *K* shall not be reused for any other operation and shall be discarded immediately. :attention: M must be be a cryptographic hash, otherwise an attacker may mount an existential forgery attack. :Return: A tuple with 2 longs. (R"tsign(R$tMR&((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyR)scCsti|||ƒS(sNVerify the validity of an ElGamal signature. :Parameter M: The expected message. :Type M: byte string or long :Parameter signature: The ElGamal signature to verify. :Type signature: A tuple with 2 longs as return by `sign` :Return: True if the signature is correct, False otherwise. (R"tverify(R$R*t signature((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyR+9s cCsEt|i||iƒ}|t|i||iƒ|i}||fS(N(RRR R(R$R*R&tatb((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyt_encryptFs#cCsat|dƒptdƒ‚nt|d|i|iƒ}|dt||iƒ|i}|S(NRs(Private key not available in this objectii(thasattrt TypeErrorRRR R(R$R*taxR%((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyt_decryptKs !cCsÀt|dƒptdƒ‚n|id}t||ƒdjotdƒ‚nt|i||iƒ}||i||}x|djo||}qƒW|t||ƒ|}||fS(NRs(Private key not available in this objectisBad K value: GCD(K,p-1)!=1i( R0R1R tGCDRRRRR(R$R*R&tp1R-ttR.((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyt_signRs  cCs |ddjp|d|idjodSt|i|d|iƒ}|t|d|d|iƒ|i}t|i||iƒ}||jodSdS(Nii(R RRR(R$R*tsigtv1tv2((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyt_verify^s)( cCsti|iƒdS(Ni(RtsizeR (R$((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyR<hscCst|dƒodSdSdS(NRii(R0(R$((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyt has_privatekscCst|i|i|ifƒS(N(RR RR(R$((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyt publickeyqs(RRt__doc__RR#R'R)R+R/R3R7R;R<R=R>(((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pyRâs       N(R?t __revision__t__all__tCrypto.PublicKey.pubkeyt Crypto.UtilRt ExceptionRtNoneRRR"Rtobject(((sK/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/ElGamal.pytjs  J !“