3 TeV @spddlmZmZmZddlmZddlmZmZm Z ddl m Z m Z ddl mZeje jGdddeZdS) )absolute_importdivisionprint_function)utils)InvalidSignatureUnsupportedAlgorithm_Reasons) constant_timemac)CBCc@s@eZdZd ddZejdZddZddZd 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_backendkeyZ_key _algorithmZ block_size_output_lengthZ_cipher_registrytyper _lib CMAC_CTX_newopenssl_assert_ffiZNULLgc CMAC_CTX_freeZ from_bufferZ CMAC_Initlen_ctx) selfZbackend algorithmctxregistryZadapterZ evp_cipherZkey_ptrresr!/usr/lib64/python3.6/cmac.py__init__s0    z_CMACContext.__init__rcCs,|jjj|j|t|}|jj|dkdS)Nr)rrZ CMAC_Updaterrr)rdatar r!r!r"update9sz_CMACContext.updatecCsd|jjjd|j}|jjjd|j}|jjj|j||}|jj|dkd|_|jjj|ddS)Nzunsigned char[]zsize_t *r) rrnewrrZ CMAC_Finalrrbuffer)rZbufZlengthr r!r!r"finalize=s z_CMACContext.finalizecCsV|jjj}|jjj||jjj}|jjj||j}|jj|dkt |j|j |dS)Nr)r) rrrrrrZ CMAC_CTX_copyrrr r)rZ copied_ctxr r!r!r"copyGs  z_CMACContext.copycCs |j}tj||stddS)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 MACContextobjectr r!r!r!r"s