σ 9(Zc@`sΚddlmZmZmZddlmZddlmZmZm Z ddl m Z ddl m Z eje jƒeje jƒeje jƒeje jƒdefd„ƒYƒƒƒƒZdS( i(tabsolute_importtdivisiontprint_function(tutils(t InvalidTagtUnsupportedAlgorithmt_Reasons(tciphers(tmodest_CipherContextcB`sYeZdZdZd„Zd„Zd„Zd„Zd„Zd„Z e j dƒZ RS( iic C`sξ||_||_||_||_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} nit|tjƒr|j} nKt|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(dk r9|jj j&||jj j)t#|j(ƒ|j(ƒ} |jj!| dkƒ|j(|_q||j|j*kr||jj j+r||jj j, r|t-dƒ‚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.is_delayed passing of GCM tag requires OpenSSL >= 1.0.2. To use this feature please update OpenSSL(0t_backendt_ciphert_modet _operationtNonet_tagt isinstanceRtBlockCipherAlgorithmt block_sizet_block_size_bytest_libtEVP_CIPHER_CTX_newt_ffitgctEVP_CIPHER_CTX_freet_cipher_registryttypetKeyErrorRtformattnameRtUNSUPPORTED_CIPHERtNULLRtModeWithInitializationVectortinitialization_vectort ModeWithTweakttweakt ModeWithNoncetnoncetEVP_CipherInit_extopenssl_asserttEVP_CIPHER_CTX_set_key_lengthtlentkeytGCMtEVP_CIPHER_CTX_ctrltEVP_CTRL_AEAD_SET_IVLENttagtEVP_CTRL_AEAD_SET_TAGt_DECRYPTt"CRYPTOGRAPHY_OPENSSL_LESS_THAN_102tCRYPTOGRAPHY_IS_LIBRESSLtNotImplementedErrortEVP_CIPHER_CTX_set_paddingt_ctx( tselftbackendtciphertmodet operationtctxtregistrytadaptert evp_ciphertiv_noncetres((sR/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/backends/openssl/ciphers.pyt__init__sŠ                         cC`s=tt|ƒ|jdƒ}|j||ƒ}t|| ƒS(Ni(t bytearrayR)Rt update_intotbytes(R6tdatatbuftn((sR/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/backends/openssl/ciphers.pytupdatevscC`sΠt|ƒt|ƒ|jdkrLtdjt|ƒ|jdƒƒ‚n|jjjd|jjj|ƒƒ}|jjjdƒ}|jj j |j |||t|ƒƒ}|jj |dkƒ|dS(Nis2buffer must be at least {0} bytes for this payloadsunsigned char *sint *i( R)Rt ValueErrorRR Rtcastt from_buffertnewRtEVP_CipherUpdateR5R'(R6RERFtoutlenR@((sR/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/backends/openssl/ciphers.pyRC{s#  cC`sKt|jtjƒr%|jdƒn|j|jkrjt|jtjƒrj|jdkrjt dƒ‚n|j j j d|jƒ}|j j j dƒ}|j jj|j||ƒ}|dkra|j jƒ}| rψt|jtjƒrψt‚n|j j|dj|j jj|j jjƒpN|dj|j jj|j jjƒƒt dƒ‚nt|jtjƒr|j|jkr|j j j d|jƒ}|j jj|j|j jj|j|ƒ}|j j|dkƒ|j j j|ƒ|_n|j jj|jƒ}|j j|dkƒ|j j j|ƒ|d S(Nts4Authentication tag must be provided when decrypting.sunsigned char[]sint *isFThe length of the provided data is not a multiple of the block length.i(RR RR+RHR R0tModeWithAuthenticationTagR.RRIR RRLRRtEVP_CipherFinal_exR5t_consume_errorsRR't_lib_reason_matcht ERR_LIB_EVPt'EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTHt_ENCRYPTR,tEVP_CTRL_AEAD_GET_TAGtbufferRtEVP_CIPHER_CTX_cleanup(R6RFRNR@terrorsttag_buf((sR/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/backends/openssl/ciphers.pytfinalize‹sF           cC`s‡|jjjr.|jjj r.tdƒ‚n|jjj|j|jjjt|ƒ|ƒ}|jj |dkƒ||_ |j ƒS(NsUfinalize_with_tag requires OpenSSL >= 1.0.2. To use this method please update OpenSSLi( R RR1R2R3R,R5R/R)R'RR\(R6R.R@((sR/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/backends/openssl/ciphers.pytfinalize_with_tagΔs   cC`sb|jjjdƒ}|jjj|j|jjj||t|ƒƒ}|jj|dkƒdS(Nsint *i( R RRLRRMR5RR)R'(R6RERNR@((sR/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/backends/openssl/ciphers.pytauthenticate_additional_dataΥs 'R( t__name__t __module__RVR0RARHRCR\R]R^Rtread_only_propertyR.(((sR/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/backends/openssl/ciphers.pyR s a   9  N(t __future__RRRt cryptographyRtcryptography.exceptionsRRRtcryptography.hazmat.primitivesRt&cryptography.hazmat.primitives.ciphersRtregister_interfacet CipherContexttAEADCipherContexttAEADEncryptionContexttAEADDecryptionContexttobjectR (((sR/tmp/pip-build-wDUJoH/cryptography/cryptography/hazmat/backends/openssl/ciphers.pyts