a b @sdddlZddlmZmZmZddlmZddlmZej rRddlm Z ddl m Z GdddZ dS) N)InvalidSignatureUnsupportedAlgorithm_Reasons) constant_time)CBC)ciphers)Backendc@s\eZdZdddddddZedddd Zed d d Zdd d dZeddddZdS) _CMACContextNrzciphers.BlockCipherAlgorithm)backend algorithmreturnc Cs||stdtj||_|j|_||_|jd|_ |dur|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) selfr r ctxregistryadapterZ evp_cipherZkey_ptrresr$P/tmp/pip-target-98j97qn4/lib/python/cryptography/hazmat/backends/openssl/cmac.py__init__s4   z_CMACContext.__init__)datar cCs,|jj|j|t|}|j|dkdS)Nr)rrZ CMAC_Updaterrr)rr'r#r$r$r%update=sz_CMACContext.update)r cCsd|jjd|j}|jjd|j}|jj|j||}|j|dkd|_|jj|ddS)Nzunsigned char[]zsize_t *r) rrnewrrZ CMAC_Finalrrbuffer)rbuflengthr#r$r$r%finalizeAs z_CMACContext.finalizecCsV|jj}|jj||jjj}|jj||j}|j|dkt |j|j |dS)Nr)r ) rrrrrrZ CMAC_CTX_copyrrr r)rZ copied_ctxr#r$r$r%copyKs  z_CMACContext.copy) signaturer cCs |}t||stddS)NzSignature did not match digest.)r-rZbytes_eqr)rr/digestr$r$r%verifyTs z_CMACContext.verify)N) __name__ __module__ __qualname__r&bytesr(r-r.r1r$r$r$r%r s (  r )typingZcryptography.exceptionsrrrZcryptography.hazmat.primitivesrZ,cryptography.hazmat.primitives.ciphers.modesr TYPE_CHECKINGrZ,cryptography.hazmat.backends.openssl.backendrr r$r$r$r%s