3 Te @stddlmZmZmZddlmZddlmZmZm Z ddl m Z m Z m Z eje jeje jGdddeZdS))absolute_importdivisionprint_function)utils)InvalidSignatureUnsupportedAlgorithm_Reasons) constant_timehashesmacc@s@eZdZd ddZejdZddZddZd d Z d d Z dS) _HMACContextNcCs||_||_|dkr|jjj}|jj||jjjk|jjj||jjj}|jj |}||jjjkrzt dj |j t j|jjj|}|jjj||t|||jjj}|jj|dk||_||_dS)Nz*{} is not a supported hash on this backendr) _algorithm_backend_libCryptography_HMAC_CTX_newopenssl_assert_ffiNULLgcCryptography_HMAC_CTX_freeZ_evp_md_from_algorithmrformatnamerZUNSUPPORTED_HASH from_bufferZ HMAC_Init_exlen_ctx_key)selfZbackendkey algorithmctxZevp_mdZkey_ptrresr!/usr/lib64/python3.6/hmac.py__init__s&  z_HMACContext.__init__r cCsp|jjj}|jj||jjjk|jjj||jjj}|jjj||j }|jj|dkt |j|j |j |dS)Nr)r) rrrrrrrrZ HMAC_CTX_copyrr rr)rZ copied_ctxr r!r!r"copy1s z_HMACContext.copycCs:|jjj|}|jjj|j|t|}|jj|dkdS)Nr)rrrrZ HMAC_Updaterrr)rdataZdata_ptrr r!r!r"update=sz_HMACContext.updatecCsz|jjjd|jjj}|jjjd}|jjj|j||}|jj|dk|jj|d|jj k|jjj |d|dS)Nzunsigned char[]zunsigned int *r) rrnewrZEVP_MAX_MD_SIZEZ HMAC_FinalrrrZ digest_sizebuffer)rZbufZoutlenr r!r!r"finalizeBsz_HMACContext.finalizecCs |j}tj||stddS)NzSignature did not match digest.)r)r Zbytes_eqr)rZ signatureZdigestr!r!r"verifyLs z_HMACContext.verify)N) __name__ __module__ __qualname__r#rZread_only_propertyrr$r&r)r*r!r!r!r"r s     r N)Z __future__rrrZ cryptographyrZcryptography.exceptionsrrrZcryptography.hazmat.primitivesr r r Zregister_interfaceZ MACContextZ HashContextobjectr r!r!r!r"s