a oe @spddlmZddlZddlmZmZmZddlmZddl m Z ej r^ddl m Z ddlmZGdd d ZdS) ) annotationsN)InvalidSignatureUnsupportedAlgorithm_Reasons) constant_time)CBC)Backend)ciphersc@s\eZdZdddddddZddd d d Zdd d dZdd ddZdddddZdS) _CMACContextNrzciphers.BlockCipherAlgorithmNone)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_backendkeyZ_key _algorithmZ block_size_output_lengthZ_cipher_registrytyper_lib CMAC_CTX_newopenssl_assert_ffiZNULLgc CMAC_CTX_freeZ from_bufferZ CMAC_Initlen_ctx) selfr r ctxregistryZadapterZ evp_cipherZkey_ptrresr"JC:\Program Files\Certbot\pkgs\cryptography\hazmat\backends\openssl\cmac.py__init__s4   z_CMACContext.__init__bytes)datarcCs,|jj|j|t|}|j|dkdS)Nr)rrZ CMAC_Updaterrr)rr&r!r"r"r#update?sz_CMACContext.update)rcCsd|jjd|j}|jjd|j}|jj|j||}|j|dkd|_|jj|ddS)Nzunsigned char[]zsize_t *r) rrnewrrZ CMAC_Finalrrbuffer)rbuflengthr!r"r"r#finalizeCs 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#copyMs  z_CMACContext.copy) signaturercCs |}t||stddS)NzSignature did not match digest.)r,rZbytes_eqr)rr.Zdigestr"r"r#verifyVs z_CMACContext.verify)N)__name__ __module__ __qualname__r$r'r,r-r/r"r"r"r#r s (  r )Z __future__rtypingZcryptography.exceptionsrrrZcryptography.hazmat.primitivesrZ,cryptography.hazmat.primitives.ciphers.modesr TYPE_CHECKINGZ,cryptography.hazmat.backends.openssl.backendrr r r"r"r"r#s