wec@sddlmZddlmZmZmZddlmZddlm Z m Z ddl m Z m Z m Z defdYZd Zd S( i(t unhexlify(tbordttobytestis_bytes(tget_random_bytesi(t cSHAKE128tSHA3_256(t_bytepadt _encode_strt _right_encodet KMAC_HashcBsMeZdZdZdZdZdZdZdZdZ RS(s[A KMAC hash object. Do not instantiate directly. Use the :func:`new` function. c Csod||_||_d|_ttt||}|j||d|_|rk|jj |ndS(Ns2.16.840.1.101.3.4.2.tKMAC( toidt digest_sizetNonet_macRRRt_newt_cshaketupdate( tselftdatatkeytmac_lentcustomt oid_varianttcshaketratet partial_newX((s9/usr/lib64/python2.7/site-packages/Crypto/Hash/KMAC128.pyt__init__.s   cCs,|jrtdn|jj||S(sAuthenticate the next chunk of message. Args: data (bytes/bytearray/memoryview): The next chunk of the message to authenticate. s8You can only call 'digest' or 'hexdigest' on this object(Rt TypeErrorRR(RR((s9/usr/lib64/python2.7/site-packages/Crypto/Hash/KMAC128.pyR=s cCsH|jsA|jjt|jd|jj|j|_n|jS(sReturn the **binary** (non-printable) MAC tag of the message. :return: The MAC tag. Binary form. :rtype: byte string i(RRRR R tread(R((s9/usr/lib64/python2.7/site-packages/Crypto/Hash/KMAC128.pytdigestKs cCs6djgt|jD]}dt|^qS(sReturn the **printable** MAC tag of the message. :return: The MAC tag. Hexadecimal encoded. :rtype: string ts%02x(tjointtupleRR(Rtx((s9/usr/lib64/python2.7/site-packages/Crypto/Hash/KMAC128.pyt hexdigestXscCsctd}tj||}tj||j}|j|jkr_tdndS(s`Verify that a given **binary** MAC (computed by another party) is valid. Args: mac_tag (bytes/bytearray/memoryview): the expected MAC of the message. Raises: ValueError: if the MAC does not match. It means that the message has been tampered with or that the MAC key is incorrect. isMAC check failedN(RRtnewRt ValueError(Rtmac_tagtsecrettmac1tmac2((s9/usr/lib64/python2.7/site-packages/Crypto/Hash/KMAC128.pytverifyas cCs|jtt|dS(snVerify that a given **printable** MAC (computed by another party) is valid. Args: hex_mac_tag (string): the expected MAC of the message, as a hexadecimal string. Raises: ValueError: if the MAC does not match. It means that the message has been tampered with or that the MAC key is incorrect. N(R+RR(Rt hex_mac_tag((s9/usr/lib64/python2.7/site-packages/Crypto/Hash/KMAC128.pyt hexverifyus cKs&d|kr|j|ds f