U &.e@sdZddlZddlmZz ddlZWnek r@dZdZ Yn Xe ej Z ddl ZddlZ ddlZeddedDZeddedDZdZGdd d Zd d ZGd d d ejZe reZdddZddZdS)zqHMAC (Keyed-Hashing for Message Authentication) module. Implements the HMAC algorithm as described by RFC 2104. N)_compare_digestccs|]}|dAVqdS)\N.0xrr/usr/lib64/python3.8/hmac.py sr ccs|]}|dAVqdS)6Nrrrrrr sc@sReZdZdZdZdddZeddZd d Zd d Z d dZ ddZ ddZ dS)HMACz~RFC 2104 HMAC class. Also complies with RFC 4231. This supports the API for Cryptographic Hash Functions (PEP 247). @NcsVtrtdt|ttfs0tdt|js?rzHMAC.__init__..cs |SrrrrrrrAr block_sizez:block_size of %d seems too small; using our default of %d.zasz HMAC.namecCs trtd|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,r4r:hrrr_currentxs z HMAC._currentcCs|}|S)zReturn 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. )rEr4rCrrrr4sz HMAC.digestcCs|}|S)zKLike digest(), but returns a string of hexadecimal digits instead. )rE hexdigestrCrrrrFszHMAC.hexdigest)Nr) r' __module__ __qualname____doc__r1r=propertyr>r6rArEr4rFrrrrr s >    r cCsHt|tr|St|r"|d}t|tjs6td|jddS)Nrz6Only OpenSSL hashlib hashes are accepted in FIPS mode._-) r"r*lowerr(rZHASHr%r>replacerrrr_get_openssl_names  rOc@seZdZdddZdS) HMAC_opensslNcCsLt|ttfs tdt|jt|}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@rrrrrPsrPrcCs t|||S)aCreate 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<rrrrrsrcstdk r(ttr(tkr(t||Str6}n(ttrPd 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|Srrrr4rrrrzdigest..cs |SrrrrTrrrrrr r)r)r) _hashopensslr"r*_openssl_md_methsZ hmac_digestr(getattrr3r4r6r7r9r8)r;r<r4r)r,r+r1rrTrr4s,      r4)Nr)rIwarningsr/ _operatorrZcompare_digestrrU ImportErrorrV frozensetZopenssl_md_meth_namesZhashlibrrQr#ranger8r9r-r rOrPr rr4rrrrs*    u