a ‚oeÛ ã@spddlmZddlZddlmZmZmZddlmZddl m Z ej r^ddl m Z ddlmZGdd „d ƒZdS) é)Ú annotationsN)ÚInvalidSignatureÚUnsupportedAlgorithmÚ_Reasons)Ú constant_time)ÚCBC)ÚBackend)Úciphersc@s\eZdZdddddœdd„Zddd œd d „Zdd œd d„Zdd œdd„Zdddœdd„ZdS)Ú _CMACContextNrzciphers.BlockCipherAlgorithmÚNone)ÚbackendÚ algorithmÚreturnc 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Ú_backendÚkeyZ_keyÚ _algorithmZ block_sizeÚ_output_lengthZ_cipher_registryÚtyperÚ_libÚ CMAC_CTX_newÚopenssl_assertÚ_ffiZNULLÚgcÚ CMAC_CTX_freeZ from_bufferZ CMAC_InitÚlenÚ_ctx) Úselfr r ÚctxÚregistryZadapterZ evp_cipherZkey_ptrÚres©r"úJC:\Program Files\Certbot\pkgs\cryptography\hazmat\backends\openssl\cmac.pyÚ__init__s4 þ  ûz_CMACContext.__init__Úbytes)ÚdatarcCs,|jj |j|t|ƒ¡}|j |dk¡dS)Nr)rrZ CMAC_Updaterrr)rr&r!r"r"r#Úupdate?sz_CMACContext.update)rcCsd|jj d|j¡}|jj d|j¡}|jj |j||¡}|j |dk¡d|_|jj |¡dd…S)Nzunsigned char[]zsize_t *r) rrÚnewrrZ CMAC_FinalrrÚbuffer)rÚbufÚlengthr!r"r"r#ÚfinalizeCs z_CMACContext.finalizecCsV|jj ¡}|jj ||jjj¡}|jj ||j¡}|j |dk¡t |j|j |d�S)Nr)r) rrrrrrZ CMAC_CTX_copyrrr r)rZ copied_ctxr!r"r"r#ÚcopyMs  ÿz_CMACContext.copy)Ú signaturercCs | ¡}t ||¡stdƒ‚dS)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__rÚtypingZcryptography.exceptionsrrrZcryptography.hazmat.primitivesrZ,cryptography.hazmat.primitives.ciphers.modesrÚ TYPE_CHECKINGZ,cryptography.hazmat.backends.openssl.backendrr r r"r"r"r#Ús