B \Úæ`Íã@sdddlmZmZmZddlmZdZdZdd„Zdd„Z dd „Z d d „Z d d „Z dd„Z dd„ZdS)é)Úabsolute_importÚdivisionÚprint_function)Ú 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-{0}-ccméÚasciiz aes-{0}-gcm) Ú+cryptography.hazmat.primitives.ciphers.aeadrrr Ú isinstanceÚformatÚlenÚ_keyÚencodeÚAssertionError)Úcipherrrr ©rú\/opt/alt/python37/lib64/python3.7/site-packages/cryptography/hazmat/backends/openssl/aead.pyÚ_aead_cipher_names  rc CsB|j |¡}| ||jjk¡|j ¡}|j ||jj¡}|j |||jj|jj|jjt |t kƒ¡} | | dk¡|j  |t |ƒ¡} | | dk¡|j  ||jjt |ƒ|jj¡} | | dk¡|tkrð|j  ||jjt |ƒ|¡} | | dk¡n|j  ||jj||jj¡} |j ||jj|jj||t |t kƒ¡} | | dk¡|S)Nr)Ú_libZEVP_get_cipherbynameÚopenssl_assertÚ_ffiÚNULLZEVP_CIPHER_CTX_newZgcZEVP_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) ÚbackendÚ cipher_nameÚkeyÚnonceÚtagZtag_lenZ operationZ evp_cipherÚctxÚresrrrÚ _aead_setups@   r&cCs:|j d¡}|j ||jj||jj|¡}| |dk¡dS)Nzint *r)rÚnewrÚEVP_CipherUpdaterr)rr$Zdata_lenZintptrr%rrrÚ _set_lengthEs r)cCs:|j d¡}|j ||jj||t|ƒ¡}| |dk¡dS)Nzint *r)rr'rr(rrr)rr$Úassociated_dataÚoutlenr%rrrÚ _process_aadQs r,cCs^|j d¡}|j dt|ƒ¡}|j ||||t|ƒ¡}| |dk¡|j ||d¡dd…S)Nzint *zunsigned char[]r)rr'rrr(rÚbuffer)rr$Údatar+Úbufr%rrrÚ _process_dataYs  r0cCsê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)rzint *zunsigned char[])r rrr&rrr r)rr,r0rr'rÚEVP_CipherFinal_exrrrZEVP_CTRL_AEAD_GET_TAGr-)rrr"r.r*Ú tag_lengthrr r$Úprocessed_datar+r%Ztag_bufr#rrrÚ_encryptas$     r4cCs2ddlm}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)Nr)rzint *zunsigned char[]r)r rrrrr&rrr r)r,rr'rr(Z_consume_errorsr-r0r1r)rrr"r.r*r2rr#r r$r+r/r%r3rrrÚ_decrypt|s4         r5N)Z __future__rrrZcryptography.exceptionsrrrrr&r)r,r0r4r5rrrrÚs  *