σ θb‹Xc@`sΰddlmZmZmZddlmZddlmZmZm Z ddl m Z ddl m Z eje jƒeje jƒeje jƒdefd„ƒYƒƒƒZeje jƒdefd „ƒYƒZd S( i(tabsolute_importtdivisiontprint_function(tutils(t InvalidTagtUnsupportedAlgorithmt_Reasons(tciphers(tmodest_CipherContextcB`sGeZdZdZd„Zd„Zd„Zd„Zej dƒZ RS(iic C`sf||_||_||_||_d|_t|jtjƒrX|jj d|_ n d|_ |jj j ƒ}|jj j||jj jƒ}|jj}y |t|ƒt|ƒf}WnAtk rtdj|j|rξ|jn|ƒtjƒ‚nX||j||ƒ}||jj jkratdj|j|rL|jn|ƒtjƒ‚nt|tjƒr|j} n-t|tjƒr|j} n|jj j} |jj j|||jj j|jj j|jj j|ƒ} |jj| dkƒ|jj j |t!|j"ƒƒ} |jj| dkƒt|tj#ƒrτ|jj j$||jj j%t!| ƒ|jj jƒ} |jj| dkƒ||j&krτ|jj j$||jj j't!|j(ƒ|j(ƒ} |jj| dkƒqτn|jj j||jj j|jj j|j"| |ƒ} |jj| dkƒ|jj j)|dƒ||_*dS(Niis8cipher {0} in {1} mode is not supported by this backend.i(+t_backendt_ciphert_modet _operationtNonet_tagt isinstanceRtBlockCipherAlgorithmt block_sizet_block_size_bytest_libtEVP_CIPHER_CTX_newt_ffitgctEVP_CIPHER_CTX_freet_cipher_registryttypetKeyErrorRtformattnameRtUNSUPPORTED_CIPHERtNULLRtModeWithInitializationVectortinitialization_vectort ModeWithNoncetnoncetEVP_CipherInit_extopenssl_asserttEVP_CIPHER_CTX_set_key_lengthtlentkeytGCMtEVP_CIPHER_CTX_ctrltEVP_CTRL_GCM_SET_IVLENt_DECRYPTtEVP_CTRL_GCM_SET_TAGttagtEVP_CIPHER_CTX_set_paddingt_ctx( tselftbackendtciphertmodet operationtctxtregistrytadaptert evp_ciphertiv_noncetres((sR/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/ciphers.pyt__init__sv                       cC`s™|jjjdt|ƒ|jdƒ}|jjjdƒ}|jjj|j|||t|ƒƒ}|jj|dkƒ|jjj |ƒ|d S(Nsunsigned char[]isint *i( R RtnewR'RRtEVP_CipherUpdateR0R%tbuffer(R1tdatatbuftoutlenR;((sR/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/ciphers.pytupdategscC`s&t|jtjƒr%|jdƒn|jjjd|jƒ}|jjjdƒ}|jj j |j ||ƒ}|dkr<|jj ƒ}| r³t|jtjƒr³t ‚n|jj|dd|jj j|jj j|jj jfkp)|dd|jj j|jj j|jj jfkƒtdƒ‚nt|jtjƒrέ|j|jkrέ|jjjd|jƒ}|jj j|j |jj j|j|ƒ}|jj|dkƒ|jjj|ƒ|_n|jj j|j ƒ}|jj|dkƒ|jjj|ƒ|d S(Ntsunsigned char[]sint *iisFThe length of the provided data is not a multiple of the block length.(RR RR)RCR RR=RRtEVP_CipherFinal_exR0t_consume_errorsRR%t ERR_LIB_EVPtEVP_F_EVP_ENCRYPTFINAL_EXt'EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTHtEVP_F_EVP_DECRYPTFINAL_EXt ValueErrorR t_ENCRYPTR*tEVP_CTRL_GCM_GET_TAGR?RtEVP_CIPHER_CTX_cleanup(R1RARBR;terrorsttag_buf((sR/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/ciphers.pytfinalizeps@            cC`sb|jjjdƒ}|jjj|j|jjj||t|ƒƒ}|jj|dkƒdS(Nsint *i( R RR=RR>R0RR'R%(R1R@RBR;((sR/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/ciphers.pytauthenticate_additional_data’s 'R( t__name__t __module__RLR,R<RCRQRRRtread_only_propertyR.(((sR/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/ciphers.pyR s S 2 t_AESCTRCipherContextcB`s)eZdZd„Zd„Zd„ZRS(s― This is needed to provide support for AES CTR mode in OpenSSL 1.0.0. It can be removed when we drop 1.0.0 support (RHEL 6.4 is the only thing that ships it). cC`s½||_|jjjdƒ|_|jjj|jt|jƒd|jƒ}|jj|dkƒ|jjjddƒ|_ |jjjd|j ƒ|_ |jjjddƒ|_ dS(Ns AES_KEY *iisunsigned char[]isunsigned char[16]sunsigned int *( R RR=t_keyRtAES_set_encrypt_keyR(R'R%t_ecountR#t_noncet_num(R1R2R3R4R;((sR/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/ciphers.pyR<³s  "cC`si|jjjdt|ƒƒ}|jjj||t|ƒ|j|j|j|j ƒ|jjj |ƒS(Nsunsigned char[]( R RR=R'RtAES_ctr128_encryptRWRZRYR[R?(R1R@RA((sR/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/ciphers.pyRCΏs  cC`s(d|_d|_d|_d|_dS(NRD(RRWRYRZR[(R1((sR/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/ciphers.pyRQΗs     (RSRTt__doc__R<RCRQ(((sR/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/ciphers.pyRV¬s N(t __future__RRRt cryptographyRtcryptography.exceptionsRRRtcryptography.hazmat.primitivesRt&cryptography.hazmat.primitives.ciphersRtregister_interfacet CipherContexttAEADCipherContexttAEADEncryptionContexttobjectR RV(((sR/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/ciphers.pytsœ