U ¨Ãq`Dã@sPddlmZdZdZdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dS)é)Ú InvalidTagécCsrddlm}m}m}t||ƒr"dSt||ƒrFd t|jƒd¡ d¡St||ƒsTt ‚d t|jƒd¡ d¡SdS)Nr)ÚAESCCMÚAESGCMÚChaCha20Poly1305schacha20-poly1305z aes-{}-ccméÚasciiz aes-{}-gcm) Ú+cryptography.hazmat.primitives.ciphers.aeadrrrÚ isinstanceÚformatÚlenÚ_keyÚencodeÚAssertionError)Úcipherrrr©rúP/tmp/pip-target-nv4zd3e_/lib/python/cryptography/hazmat/backends/openssl/aead.pyÚ_aead_cipher_name s  rc Cst|j |¡}| ||jjk¡|j ¡}|j ||jj¡}|j |||jj|jj|jjt |t kƒ¡} | | dk¡|j  |t |ƒ¡} | | dk¡|j  ||jjt |ƒ|jj¡} | | dk¡|tkrð|j  ||jjt |ƒ|¡} | | dk¡n4| d¡r$|j  ||jj||jj¡} | | dk¡|j |¡} |j |¡} |j ||jj|jj| | t |t kƒ¡} | | dk¡|S)Nrs-ccm)Ú_libZEVP_get_cipherbynameÚopenssl_assertÚ_ffiÚNULLZEVP_CIPHER_CTX_newÚgcZEVP_CIPHER_CTX_freeZEVP_CipherInit_exÚintÚ_ENCRYPTZEVP_CIPHER_CTX_set_key_lengthr ÚEVP_CIPHER_CTX_ctrlZEVP_CTRL_AEAD_SET_IVLENÚ_DECRYPTZEVP_CTRL_AEAD_SET_TAGÚendswithÚ from_buffer) ÚbackendÚ cipher_nameÚkeyÚnonceÚtagZtag_lenZ operationZ evp_cipherÚctxÚresZ nonce_ptrZkey_ptrrrrÚ _aead_setupsd   úüÿ ÿ   úr&cCs:|j d¡}|j ||jj||jj|¡}| |dk¡dS©Núint *r)rÚnewrÚEVP_CipherUpdaterr)rr$Zdata_lenZintptrr%rrrÚ _set_lengthMs ÿr+cCs:|j d¡}|j ||jj||t|ƒ¡}| |dk¡dSr')rr)rr*rr r)rr$Úassociated_dataÚoutlenr%rrrÚ _process_aadUs ÿr.cCs^|j d¡}|j dt|ƒ¡}|j ||||t|ƒ¡}| |dk¡|j ||d¡dd…S)Nr(úunsigned char[]r)rr)r rr*rÚbuffer)rr$Údatar-Úbufr%rrrÚ _process_data]s  r3cCsêddlm}t|ƒ}t|||j|d|tƒ}t||ƒrDt||t|ƒƒt |||ƒt |||ƒ} |j   d¡} |j  ||j j| ¡} | | dk¡| | ddk¡|j   d|¡} |j  ||j j|| ¡} | | dk¡|j  | ¡dd…} | | S)Nr©rr(r/)r rrr&r rr r+r r.r3rr)rÚEVP_CipherFinal_exrrrZEVP_CTRL_AEAD_GET_TAGr0)rrr"r1r,Ú tag_lengthrr r$Úprocessed_datar-r%Ztag_bufr#rrrÚ_encryptes: ÿ    ÿr8cCs2ddlm}t|ƒ|krt‚|| d…}|d| …}t|ƒ}t|||j|||tƒ} t||ƒrpt || t|ƒƒt || |ƒt||ƒrì|j   d¡} |j   dt|ƒ¡} |j  | | | |t|ƒ¡} | dkrÐ| ¡t‚|j  | | d¡dd…} nBt|| |ƒ} |j   d¡} |j  | |j j| ¡} | dkr.| ¡t‚| S)Nrr4r(r/r)r rr rrr&r rr r+r.rr)rr*Z_consume_errorsr0r3r5r)rrr"r1r,r6rr#r r$r-r2r%r7rrrÚ_decryptsB  ÿ       r9N) Zcryptography.exceptionsrrrrr&r+r.r3r8r9rrrrÚs 0