U &Ì.eªã@sÞdZddlZddlmZz ddlZWnek r@dZdZ Yn Xe ej ƒZ ddl ZddlZ ddlZedd„edƒDƒƒZedd„edƒDƒƒZdZGdd „d ƒZd d „ZGd d „d ejƒZe  ¡rÈeZddd„Zdd„ZdS)zqHMAC (Keyed-Hashing for Message Authentication) module. Implements the HMAC algorithm as described by RFC 2104. éN)Ú_compare_digestccs|]}|dAVqdS)é\N©©Ú.0Úxrrú/usr/lib64/python3.8/hmac.pyÚ sr éccs|]}|dAVqdS)é6Nrrrrrr sc@sReZdZdZdZddd„Zedd„ƒZd d „Zd d „Z d d„Z dd„Z dd„Z dS)ÚHMACz~RFC 2104 HMAC class. Also complies with RFC 4231. This supports the API for Cryptographic Hash Functions (PEP 247). é@NÚcsVt ¡rtdƒ‚t|ttfƒs0tdt|ƒjƒ‚ˆs?rzHMAC.__init__..cs ˆ |¡Sr©rrrrrrArÚ block_sizeéz:block_size of %d seems too small; using our default of %d.ézasz HMAC.namecCs t ¡rtdƒ‚|j |¡dS)z,Feed data from msg into this hashing object.z'hmac.HMAC is not available in FIPS modeN)rr r!r,r6)r:r<rrrr6esz HMAC.updatecCs:|j |j¡}|j|_|j|_|j ¡|_|j ¡|_|S)zyReturn a separate copy of this hashing object. An update to this copy won't affect the original object. )Ú __class__Ú__new__r)r-r,Úcopyr+)r:ÚotherrrrrAks   z HMAC.copycCs|j ¡}| |j ¡¡|S)zwReturn a hash object for the current state. To be used only internally with digest() and hexdigest(). )r+rAr6r,r4©r:ÚhrrrÚ_currentxs z HMAC._currentcCs| ¡}| ¡S)zïReturn the hash value of this hashing object. This returns the hmac value as bytes. The object is not altered in any way by this function; you can continue updating the object after calling this function. )rEr4rCrrrr4�sz HMAC.digestcCs| ¡}| ¡S)zKLike digest(), but returns a string of hexadecimal digits instead. )rEÚ hexdigestrCrrrrF‹szHMAC.hexdigest)Nr) r'Ú __module__Ú __qualname__Ú__doc__r1r=Úpropertyr>r6rArEr4rFrrrrr s >    r cCsHt|tƒr| ¡St|ƒr"|dƒ}t|tjƒs6tdƒ‚|j ¡ dd¡S)Nrz6Only OpenSSL hashlib hashes are accepted in FIPS mode.Ú_ú-) r"r*Úlowerr(rZHASHr%r>ÚreplacerrrrÚ_get_openssl_name‘s  ÿrOc@seZdZddd„ZdS)Ú HMAC_opensslNcCsLt|ttfƒs tdt|ƒjƒ‚t|ƒ}tjj |||d�}|rH|  |¡|S)Nrr) r"r#r$r%r&r'rOÚ _hmacopensslr r@r6)Úclsr;r<rr>Úresultrrrr@žs zHMAC_openssl.__new__)NN)r'rGrHr@rrrrrP�srPrcCs t|||ƒS)aáCreate a new hashing object and return it. key: bytes or buffer, The starting key for the hash. msg: bytes or buffer, Initial input for the hash, or None. digestmod: A hash name suitable for hashlib.new(). *OR* A hashlib constructor returning a new hash object. *OR* A module supporting PEP 247. Required as of 3.8, despite its position after the optional msg argument. Passing it as a keyword argument is recommended, though not required for legacy API reasons. You can now feed arbitrary bytes into the object using its update() method, and can ask for the hash value at any time by calling its digest() or hexdigest() methods. )r )r;r<rrrrr­srcsâtdk r(tˆtƒr(ˆtkr(t ||ˆ¡Stˆƒr6ˆ}n(tˆtƒrPd ‡fdd„ }nd ‡fdd„ }|ƒ}|ƒ}t|ddƒ}t|ƒ|krŽ||ƒ ¡}|d|t|ƒ}|  |  t ¡¡|  |  t ¡¡|  |¡|  | ¡¡| ¡S) aJFast inline implementation of HMAC. key: bytes or buffer, The key for the keyed hash object. msg: bytes or buffer, Input message. digest: A hash name suitable for hashlib.new() for best performance. *OR* A hashlib constructor returning a new hash object. *OR* A module supporting PEP 247. Nrcs t ˆ|¡Srrr©r4rrrÑrzdigest..cs ˆ |¡SrrrrTrrrÓrrr r)r)r) Ú _hashopensslr"r*Ú_openssl_md_methsZ hmac_digestr(Úgetattrr3r4r6r7r9r8)r;r<r4r)r,r+r1rrTrr4Ás, ÿÿ     r4)Nr)rIÚwarningsr/Ú _operatorrZcompare_digestrrUÚ ImportErrorrVÚ frozensetZopenssl_md_meth_namesZhashlibrrQr#Úranger8r9r-r rOrPr rr4rrrrÚs*    u