o -&%a @sLddlmZddlmZmZmZddlmZddlm Z Gddde Z dS))utils)InvalidSignatureUnsupportedAlgorithm_Reasons) constant_time)CBCc@s\eZdZdddZedZdeddfddZdefd d Z dd d Z d eddfddZ dS) _CMACContextNc Cs||s tdtj||_|j|_||_|jd|_ |duro|jj }|t |t f}||j|t }|jj }|j||jjjk|jj||jj j}|jj|j}|jj ||t|j||jjj}|j|dk||_dS)Nz#This backend does not support CMAC.)cmac_algorithm_supportedrrUNSUPPORTED_CIPHER_backendkey_key _algorithm block_size_output_length_cipher_registrytyper_lib CMAC_CTX_newopenssl_assert_ffiNULLgc CMAC_CTX_free from_buffer CMAC_Initlen_ctx) selfbackend algorithmctxregistryadapter evp_cipherkey_ptrresr)K/usr/lib/python3/dist-packages/cryptography/hazmat/backends/openssl/cmac.py__init__s4    z_CMACContext.__init__rdatareturncCs,|jj|j|t|}|j|dkdS)Nr )r r CMAC_Updaterrr)r r,r(r)r)r*update6sz_CMACContext.updatecCsd|jjd|j}|jjd|j}|jj|j||}|j|dkd|_|jj|ddS)Nzunsigned char[]zsize_t *r ) r rnewrr CMAC_Finalrrbuffer)r buflengthr(r)r)r*finalize:s z_CMACContext.finalizecCsV|jj}|jj||jjj}|jj||j}|j|dkt |j|j |dS)Nr )r#) r rrrrr CMAC_CTX_copyrrrr)r copied_ctxr(r)r)r*copyDs  z_CMACContext.copy signaturecCs |}t||stddS)NzSignature did not match digest.)r5rbytes_eqr)r r9digestr)r)r*verifyMs z_CMACContext.verify)N)r-r) __name__ __module__ __qualname__r+rread_only_propertyr"bytesr/r5r8r<r)r)r)r*rs  #  rN) cryptographyrcryptography.exceptionsrrrcryptography.hazmat.primitivesr,cryptography.hazmat.primitives.ciphers.modesrobjectrr)r)r)r*s