3 ꅭhV �@spddlmZmZmZddlmZddlmZmZm Z ddl m Z m Z ddl mZeje j�Gdd�de��ZdS) �)�absolute_import�division�print_function)�utils)�InvalidSignature�UnsupportedAlgorithm�_Reasons)� constant_time�mac)�CBCc@s@eZdZd dd�Zejd�Zdd�Zdd�Zd d �Z d d �Z dS)� _CMACContextNc Cs�|j|�stdtj��||_|j|_||_|jd|_ |dkr�|jj }|t |�t f}||j|t �}|jj j�}|jj||jjjk�|jjj||jj j�}|jjj|j�}|jj j||t|j�||jjj�}|jj|dk�||_dS)Nz#This backend does not support CMAC.��)Zcmac_algorithm_supportedrrZUNSUPPORTED_CIPHER�_backend�keyZ_key� _algorithmZ block_size�_output_lengthZ_cipher_registry�typer �_lib� CMAC_CTX_new�openssl_assert�_ffiZNULL�gc� CMAC_CTX_freeZ from_bufferZ CMAC_Init�len�_ctx) �selfZbackend� algorithm�ctx�registryZadapterZ evp_cipherZkey_ptr�res�r!�/usr/lib64/python3.6/cmac.py�__init__s0    z_CMACContext.__init__rcCs,|jjj|j|t|��}|jj|dk�dS)Nr)rrZ CMAC_Updaterrr)r�datar r!r!r"�update9sz_CMACContext.updatecCsd|jjjd|j�}|jjjd|j�}|jjj|j||�}|jj|dk�d|_|jjj|�dd�S)Nzunsigned char[]zsize_t *r) rr�newrrZ CMAC_Finalrr�buffer)rZbufZlengthr r!r!r"�finalize=s z_CMACContext.finalizecCsV|jjj�}|jjj||jjj�}|jjj||j�}|jj|dk�t |j|j |d�S)Nr)r) rrrrrrZ CMAC_CTX_copyrrr r)rZ copied_ctxr r!r!r"�copyGs  z_CMACContext.copycCs |j�}tj||�std��dS)NzSignature did not match digest.)r(r Zbytes_eqr)rZ signatureZdigestr!r!r"�verifyPs z_CMACContext.verify)N) �__name__� __module__� __qualname__r#rZread_only_propertyrr%r(r)r*r!r!r!r"r s  #   r N)Z __future__rrrZ cryptographyrZcryptography.exceptionsrrrZcryptography.hazmat.primitivesr r Z,cryptography.hazmat.primitives.ciphers.modesr Zregister_interfaceZ MACContext�objectr r!r!r!r"�s