o
    ™¨Êh  ã                   @   sp   d dl mZmZmZ d dlmZ d dlmZmZm	Z	 d dl
mZmZ d dlmZ e ej¡G dd„ deƒƒZdS )	é    )Úabsolute_importÚdivisionÚprint_function)Úutils)ÚInvalidSignatureÚUnsupportedAlgorithmÚ_Reasons)Úconstant_timeÚmac)ÚCBCc                   @   s@   e Zd Zddd„Ze d¡Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dS )Ú_CMACContextNc                 C   sÚ   |  |¡stdtjƒ‚|| _|j| _|| _|jd | _	|d u rh| jj
}|t|ƒtf }|| j|tƒ}| jj ¡ }| j || jjjk¡ | jj || jjj¡}| jj || jt| jƒ|| jjj¡}| j |dk¡ || _d S )Nz#This backend does not support CMAC.é   é   )Úcmac_algorithm_supportedr   r   ÚUNSUPPORTED_CIPHERÚ_backendÚkeyÚ_keyÚ
_algorithmÚ
block_sizeÚ_output_lengthÚ_cipher_registryÚtyper   Ú_libÚCMAC_CTX_newÚopenssl_assertÚ_ffiÚNULLÚgcÚCMAC_CTX_freeÚ	CMAC_InitÚlenÚ_ctx)ÚselfÚbackendÚ	algorithmÚctxÚregistryÚadapterÚ
evp_cipherÚres© r+   ú[/var/www/html/env/lib/python3.10/site-packages/cryptography/hazmat/backends/openssl/cmac.pyÚ__init__   s*   
ÿ
þ
z_CMACContext.__init__r   c                 C   s,   | j j | j|t|ƒ¡}| j  |dk¡ d S )Nr   )r   r   ÚCMAC_Updater"   r!   r   )r#   Údatar*   r+   r+   r,   Úupdate1   s   z_CMACContext.updatec                 C   sd   | j j d| j¡}| j j d| j¡}| j j | j||¡}| j  |dk¡ d | _| j j |¡d d … S )Nzunsigned char[]zsize_t *r   )	r   r   Únewr   r   Ú
CMAC_Finalr"   r   Úbuffer)r#   ÚbufÚlengthr*   r+   r+   r,   Úfinalize5   s   ÿz_CMACContext.finalizec                 C   sV   | j j ¡ }| j j || j jj¡}| j j || j¡}| j  |dk¡ t	| j | j
|d�S )Nr   )r&   )r   r   r   r   r   r   ÚCMAC_CTX_copyr"   r   r   r   )r#   Ú
copied_ctxr*   r+   r+   r,   ÚcopyA   s   
ÿÿ
ÿz_CMACContext.copyc                 C   s    |   ¡ }t ||¡stdƒ‚d S )NzSignature did not match digest.)r6   r	   Úbytes_eqr   )r#   Ú	signatureÚdigestr+   r+   r,   ÚverifyN   s   ÿz_CMACContext.verify)N)Ú__name__Ú
__module__Ú__qualname__r-   r   Úread_only_propertyr%   r0   r6   r9   r=   r+   r+   r+   r,   r      s    

r   N)Ú
__future__r   r   r   Úcryptographyr   Úcryptography.exceptionsr   r   r   Úcryptography.hazmat.primitivesr	   r
   Ú,cryptography.hazmat.primitives.ciphers.modesr   Úregister_interfaceÚ
MACContextÚobjectr   r+   r+   r+   r,   Ú<module>   s   
