U q` @sLddlmZddlmZmZmZddlmZddlm Z Gddde Z dS))utils)InvalidSignatureUnsupportedAlgorithm_Reasons) constant_time)CBCc@s\eZdZdddZedZeddddZedd d Z ddd d Z edd ddZ dS) _CMACContextNc Cs||stdtj||_|j|_||_|jd|_ |dkr|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.)Zcmac_algorithm_supportedrrZUNSUPPORTED_CIPHER_backendkey_key _algorithm block_size_output_lengthZ_cipher_registrytyper_lib CMAC_CTX_newopenssl_assert_ffiZNULLgc CMAC_CTX_free from_bufferZ CMAC_Initlen_ctx) selfbackend algorithmctxregistryadapterZ evp_cipherZkey_ptrresr"P/tmp/pip-target-nv4zd3e_/lib/python/cryptography/hazmat/backends/openssl/cmac.py__init__s4   z_CMACContext.__init__r)datareturncCs,|jj|j|t|}|j|dkdS)Nr )r rZ CMAC_Updaterrr)rr%r!r"r"r#update6sz_CMACContext.update)r&cCsd|jjd|j}|jjd|j}|jj|j||}|j|dkd|_|jj|ddS)Nzunsigned char[]zsize_t *r ) r rnewrrZ CMAC_Finalrrbuffer)rbuflengthr!r"r"r#finalize:s z_CMACContext.finalizecCsV|jj}|jj||jjj}|jj||j}|j|dkt |j|j |dS)Nr )r) r rrrrrZ CMAC_CTX_copyrrrr)rZ copied_ctxr!r"r"r#copyDs z_CMACContext.copy) signaturer&cCs |}t||stddS)NzSignature did not match digest.)r,rZbytes_eqr)rr.digestr"r"r#verifyMs z_CMACContext.verify)N) __name__ __module__ __qualname__r$rZread_only_propertyrbytesr'r,r-r0r"r"r"r#rs  #   rN) Z cryptographyrZcryptography.exceptionsrrrZcryptography.hazmat.primitivesrZ,cryptography.hazmat.primitives.ciphers.modesrobjectrr"r"r"r#s