ó ñ1Mc@sédZddlmZmZmZmZddlZdefd„ƒYZej eƒd„Z ddd„ƒYZ d dd „ƒYZ d d „Z d dd„ƒYZddd„ƒYZejd„Zejd„Zejd„ZdS(sÃM2Crypto wrapper for OpenSSL EVP API. Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved. Portions Copyright (c) 2004-2007 Open Source Applications Foundation. Author: Heikki Toivonen iÿÿÿÿ(tErrtutiltBIOtRSANtEVPErrorcBseZRS((t__name__t __module__(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyR scCstj||||ƒS(s§ Derive a key from password using PBKDF2 algorithm specified in RFC 2898. @param password: Derive the key from this password. @type password: str @param salt: Salt. @type salt: str @param iter: Number of iterations to perform. @type iter: int @param keylen: Length of key to produce. @type keylen: int @return: Key. @rtype: str (tm2tpkcs5_pbkdf2_hmac_sha1(tpasswordtsalttitertkeylen((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pytpbkdf2st MessageDigestcBsAeZdZejZd„Zd„Zd„Zd„Z e Z RS(s Message Digest cCsett|dƒ}|dkr0td|f‚n|ƒ|_tjƒ|_tj|j|jƒdS(Nsunknown algorithm(tgetattrRtNonet ValueErrortmdt md_ctx_newtctxt digest_init(tselftalgoR((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyt__init__(s   cCs)t|ddƒr%|j|jƒndS(NR(RRtm2_md_ctx_freeR(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyt__del__0scCstj|j|ƒS(s Add data to be digested. @return: -1 for Python error, 1 for success, 0 for OpenSSL failure. (Rt digest_updateR(Rtdata((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pytupdate4scCstj|jƒS(N(Rt digest_finalR(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pytfinal<s( RRt__doc__Rt md_ctx_freeRRRRRtdigest(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyR"s     tHMACcBsGeZejZdd„Zd„Zd„Zd„Zd„Z e Z RS(tsha1cCshtt|dƒ}|dkr0td|f‚n|ƒ|_tjƒ|_tj|j||jƒdS(Nsunknown algorithm(RRRRRt hmac_ctx_newRt hmac_init(RtkeyRR((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRGs   cCs)t|ddƒr%|j|jƒndS(NR(RRtm2_hmac_ctx_freeR(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyROscCstj|j||jƒdS(N(RR&RR(RR'((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pytresetSscCstj|j|ƒdS(N(Rt hmac_updateR(RR((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRVscCstj|jƒS(N(Rt hmac_finalR(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRYs( RRRt hmac_ctx_freeR(RRR)RRR"(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyR#Cs      R$cCsFtt|dƒ}|dkr0td|f‚ntj|||ƒƒS(Nsunknown algorithm(RRRRthmac(R'RRR((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyR-^s tCiphercBsPeZejZdddddd„Zd„Zd„Zd„Zdd„Z RS( itmd5t12345678ic CsÛtt|dƒ} | dkr0td|f‚n| ƒ|_|r™tt|dƒ} | dkrrtd|f‚ntj|j| ƒ||||ƒ}ntjƒ|_tj|j|j|||ƒ|j | ƒ~dS(Nsunknown ciphersunknown message digest( RRRRtciphert bytes_to_keytcipher_ctx_newRt cipher_initt set_padding( RtalgR'tivtopt key_as_bytestdR titpaddingR1tkmd((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRis   ' cCs)t|ddƒr%|j|jƒndS(NR(RRtm2_cipher_ctx_freeR(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRxscCstj|j|ƒS(N(Rt cipher_updateR(RR((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyR|scCstj|jƒS(N(Rt cipher_finalR(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRscCstj|j|ƒS(N(Rtcipher_set_paddingR(RR<((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyR5‚s( RRRtcipher_ctx_freeR>RRRRR5(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyR.es     tPKeycBseZdZejZejZdddd„Z d„Z d„Z d„Z dd„Z d„Zd „Zd „ZeZeZd „Zd „Zd „Zdd„Zd„Zdejd„Zdejd„Zdejd„Zd„Zd„Zd„ZRS(s Public Key iR$cCsJ|dk r!||_||_ntjƒ|_d|_|j|ƒdS(Ni(Rtpkeyt_pyfreeRtpkey_newt _set_context(RRDRER((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRŽs     cCsNt|ddƒr%|j|jƒnt|ddƒrJ|j|jƒndS(NREiR(Rt m2_pkey_freeRDRRR(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyR—scCs|jS(N(RD(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyt_ptrscCsOtt|dƒ}|dkr0td|f‚n|ƒ|_tjƒ|_dS(Nsunknown message digest(RRRRRRR(RRtmda((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRG s   cCs|j|ƒdS(sƒ Reset internal message digest context. @type md: string @param md: The message digest algorithm. N(RG(RR((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyt reset_context§scCstj|j|jƒdS(s9 Initialise signing operation with self. N(Rt sign_initRR(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRL°scCstj|j|ƒdS(su Feed data to signing operation. @type data: string @param data: Data to be signed. N(Rt sign_updateR(RR((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRM¶scCstj|j|jƒS(s[ Return signature. @rtype: string @return: The signature. (Rt sign_finalRRD(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRN¿scCstj|j|jƒdS(sH Initialise signature verification operation with self. N(Rt verify_initRR(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyROÌscCstj|j|ƒS(sÄ Feed data to verification operation. @type data: string @param data: Data to be verified. @return: -1 on Python error, 1 for success, 0 for OpenSSL error (Rt verify_updateR(RR((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRPÒscCstj|j||jƒS(sç Return result of verification. @param sign: Signature to use for verification @rtype: int @return: Result of verification: 1 for success, 0 for failure, -1 on other error. (Rt verify_finalRRD(Rtsign((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRQÜs icCsO|r3tj|j|jƒ}|rKd|_qKntj|j|jƒ}|S(sò Assign the RSA key pair to self. @type rsa: M2Crypto.RSA.RSA @param rsa: M2Crypto.RSA.RSA object to be assigned to self. @type capture: boolean @param capture: If true (default), this PKey object will own the RSA object, meaning that once the PKey object gets deleted it is no longer safe to use the RSA object. @rtype: int @return: Return 1 for success and 0 for failure. i(Rtpkey_assign_rsaRDtrsaREt pkey_set1_rsa(RRTtcapturetret((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyt assign_rsaçs cCsCtj|jƒ}|dkr-tdƒ‚ntj|dƒ}|S(sd Return the underlying RSA key if that is what the EVP instance is holding. s&PKey instance is not holding a RSA keyiN(Rt pkey_get1_rsaRDRRRtRSA_pub(Rtrsa_ptrRT((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pytget_rsaþs  t aes_128_cbccCs%tj|dƒ}|j|||ƒS(s, Save the key pair to a file in PEM format. @type file: string @param file: Name of file to save key to. @type cipher: string @param cipher: Symmetric cipher to protect the key. The default cipher is 'aes_128_cbc'. If cipher is None, then the key is saved in the clear. @type callback: Python callable @param callback: A Python callable object that is invoked to acquire a passphrase with which to protect the key. The default is util.passphrase_callback. twb(Rtopenfilet save_key_bio(RtfileR1tcallbacktbio((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pytsave_key scCs||dkr(tj|j|jƒ|ƒStt|dƒ}|dkrVtd|‚ntj|j|jƒ|ƒ|ƒSdS(sN Save the key pair to the M2Crypto.BIO object 'bio' in PEM format. @type bio: M2Crypto.BIO @param bio: M2Crypto.BIO object to save key to. @type cipher: string @param cipher: Symmetric cipher to protect the key. The default cipher is 'aes_128_cbc'. If cipher is None, then the key is saved in the clear. @type callback: Python callable @param callback: A Python callable object that is invoked to acquire a passphrase with which to protect the key. The default is util.passphrase_callback. sno such cipher %sN(RRtpkey_write_pem_no_cipherRDRIRRtpkey_write_pem(RRcR1Rbtproto((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyR`s   cCs)tjƒ}|j|||ƒ|jƒS(sÙ Return key in PEM format in a string. @type cipher: string @param cipher: Symmetric cipher to protect the key. The default cipher is 'aes_128_cbc'. If cipher is None, then the key is saved in the clear. @type callback: Python callable @param callback: A Python callable object that is invoked to acquire a passphrase with which to protect the key. The default is util.passphrase_callback. (Rt MemoryBufferR`tread_all(RR1RbRc((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pytas_pem7s cCs+tj|jƒ}tj|ƒ}|jƒS(s6 Return key in DER format in a string (Rt pkey_as_derRDRRhRi(RtbufRc((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pytas_derIscCstj|jƒS(s6 Return the size of the key in bytes. (Rt pkey_sizeRD(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pytsizeQscCstj|jƒS(s3 Return the modulus in hex format. (Rtpkey_get_modulusRD(R((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyt get_modulusWsN( RRR Rt pkey_freeRHR!RRRRRIRGRKRLRMRNRRRORPRQRXR\Rtpassphrase_callbackRdR`RjRmRoRq(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyRC†s0            cCsƒtj|dƒ}|dkr6tjtjƒƒ‚ntj||ƒ}tj|ƒ|dkrvt tjƒƒ‚nt |dƒS(sj Load an M2Crypto.EVP.PKey from file. @type file: string @param file: Name of file containing the key in PEM format. @type callback: Python callable @param callback: A Python callable object that is invoked to acquire a passphrase with which to protect the key. @rtype: M2Crypto.EVP.PKey @return: M2Crypto.EVP.PKey object. triN( Rt bio_new_fileRRtBIOErrorRt get_errort pkey_read_pemtbio_freeRRC(RaRbRctcptr((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pytload_key^s   cCsFtj|jƒ|ƒ}|dkr9ttjƒƒ‚nt|dƒS(s‡ Load an M2Crypto.EVP.PKey from an M2Crypto.BIO object. @type bio: M2Crypto.BIO @param bio: M2Crypto.BIO object containing the key in PEM format. @type callback: Python callable @param callback: A Python callable object that is invoked to acquire a passphrase with which to protect the key. @rtype: M2Crypto.EVP.PKey @return: M2Crypto.EVP.PKey object. iN(RRxRIRRRRwRC(RcRbRz((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyt load_key_bious cCstj|ƒ}t||ƒS(sl Load an M2Crypto.EVP.PKey from a string. @type string: string @param string: String containing the key in PEM format. @type callback: Python callable @param callback: A Python callable object that is invoked to acquire a passphrase with which to protect the key. @rtype: M2Crypto.EVP.PKey @return: M2Crypto.EVP.PKey object. (RRhR|(tstringRbRc((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pytload_key_stringˆs(((((R tM2CryptoRRRRRt ExceptionRtevp_initR RR#R-R.RCRsR{R|R~(((s2/usr/lib/python2.7/vendor-packages/M2Crypto/EVP.pyts"   ! !Ø