U
    çe¨]4	  ã                   @   sH   d dl mZmZmZ d dlmZ d dlmZ dZdZ	G dd„ de
ƒZdS )	é    )Úabsolute_importÚdivisionÚprint_function)ÚInvalidSignature)Úconstant_timeé   é    c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú_Poly1305Contextc                 C   sà   || _ | j j |¡}| j j | j jj| j jj|t|ƒ¡}| j  || j jjk¡ | j j 	|| j jj
¡| _| j j ¡ }| j  || j jjk¡ | j j 	|| j jj¡| _| j j | j| j jj| j jj| j jj| j¡}| j  |dk¡ d S )Né   )Ú_backendÚ_ffiÚfrom_bufferÚ_libZEVP_PKEY_new_raw_private_keyZNID_poly1305ZNULLÚlenÚopenssl_assertÚgcZEVP_PKEY_freeZ	_evp_pkeyZCryptography_EVP_MD_CTX_newZCryptography_EVP_MD_CTX_freeÚ_ctxZEVP_DigestSignInit)ÚselfZbackendÚkeyZkey_ptrZevp_pkeyZctxÚres© r   úO/usr/lib/python3/dist-packages/cryptography/hazmat/backends/openssl/poly1305.pyÚ__init__   s6      þ ÿ ÿ   þz_Poly1305Context.__init__c                 C   s:   | j j |¡}| j j | j|t|ƒ¡}| j  |dk¡ d S )Nr   )r   r   r   r   ZEVP_DigestSignUpdater   r   r   )r   ÚdataZdata_ptrr   r   r   r   Úupdate*   s      ÿz_Poly1305Context.updatec                 C   sp   | j j dt¡}| j j d¡}| j j | j||¡}| j  |dk¡ | j  |d tk¡ | j j |¡d |d … S )Nzunsigned char[]zsize_t *r   )	r   r   ÚnewÚ_POLY1305_TAG_SIZEr   ZEVP_DigestSignFinalr   r   Úbuffer)r   ZbufZoutlenr   r   r   r   Úfinalize1   s    z_Poly1305Context.finalizec                 C   s    |   ¡ }t ||¡stdƒ‚d S )Nz!Value did not match computed tag.)r   r   Zbytes_eqr   )r   ÚtagZmacr   r   r   Úverify9   s    z_Poly1305Context.verifyN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r    r   r   r   r   r	      s   r	   N)Z
__future__r   r   r   Zcryptography.exceptionsr   Zcryptography.hazmat.primitivesr   r   Z_POLY1305_KEY_SIZEÚobjectr	   r   r   r   r   Ú<module>   s
   