U +MbE#@s~ddlmZmZmZmZmZmZmZddlm Z ddl m Z ddl m Z ddZdZdZd Zd ZGd d d eZdddZd S)) VoidPointer SmartPointercreate_string_bufferget_raw_bufferc_size_t c_uint8_ptrc_ubyte) long_to_bytes)bchr)_raw_keccak_libcCs$|dkr dSt|}|tt|S)Nr)r r len)xSrA/tmp/pip-target-t616c12r/lib/python/Crypto/Hash/KangarooTwelve.py_length_encode*src@sReZdZdZddZddZddZdd Zd d Zd d Z ddZ dddZ dS)K12_XOFzeA KangarooTwelve hash object. Do not instantiate directly. Use the :func:`new` function. cCs^|dkr d}|tt||_t|_d|_||_d|_d|_ d|_ d|_ |rZ| |dS)Nr) rr_custom SHORT_MSG_state_padding_create_keccak_hash1_length1_hash2_length2_ctrupdateselfdatacustomrrr__init__?s zK12_XOF.__init__cCs@t}t|tdtd}|r0td|t|tj S)N z+Error %d while instantiating KangarooTwelve) rr Z keccak_initZ address_ofrr ValueErrorrgetZkeccak_destroy)r%stateresultrrrrVs zK12_XOF._create_keccakcCs2t|t|tt|}|r.td|dS)Nz,Error %d while updating KangarooTwelve state)r Z keccak_absorbr,rrrr+)r%r&hash_objr.rrr_update`s  zK12_XOF._updatecCs<t|}t||t|t|}|r4td|t|S)Nz-Error %d while extracting from KangarooTwelve)rr Zkeccak_squeezer,rrr+r)r%r/lengthpaddingZbfrr.rrr_squeezehs zK12_XOF._squeezecCs"t|}|rtd|dS)Nz-Error %d while resetting KangarooTwelve state)r Z keccak_resetr,r+)r%r/r.rrr_resetts zK12_XOF._resetc Cs|jtkrtd|jtkrZ|jt|}|t|jdkrT||_|||j|St |_|jt krt |}|jdks|t t t|d|j}||d||j|j|7_|jdkr|S|jdkst d}|||j|jd7_| |_d|_d|_t|_|||dS|jtks.t d}t|}t |}||krt |d|j|}|||||j|j||7_|}|jdkrB||jdd } || |j|jd7_||jd|_|jd7_qB|S) aHash the next piece of data. .. note:: For better performance, submit chunks with a length multiple of 8192 bytes. Args: data (byte string/byte array/memoryview): The next chunk of the message to hash. z/You cannot call 'update' after the first 'read'i Nsrr r) )r SQUEEZING TypeErrorrrrrr0r LONG_MSG_S0 memoryviewAssertionErrorminrr r!r" LONG_MSG_SXr#r3r4) r%r&Z next_lengthZdata_memZdtcdividerindexZlen_dataZ new_indexcv_irrrr#zsV        zK12_XOF.updatecCsd}|jtkr*||j|jd|_t|_|jtkrR||jd}|jt ksRt |jt kr|sl||j|j dkr| |j dd}|||j|jd7_||j d|_ |jd7_t|jdd}|||jd |_t|_| |j||jS) ad Produce more bytes of the digest. .. note:: You cannot use :meth:`update` anymore after the first call to :meth:`read`. Args: length (integer): the amount of bytes this method must return :return: the next piece of XOF output (of the given length) :rtype: byte string FTrr)r6r s)rrr0rrrr7r9r#r=r;r!r3r rr4r"r)r%r1Zcustom_was_consumedr@trailerrrrreads0       z K12_XOF.readNrcCst|||S)N)typer$rrrnewsz K12_XOF.new)Nr) __name__ __module__ __qualname____doc__r(rr0r3r4r#rDrFrrrrr9s  I0rNcCs t||S)agReturn a fresh instance of a KangarooTwelve object. Args: data (bytes/bytearray/memoryview): Optional. The very first chunk of the message to hash. It is equivalent to an early call to :meth:`update`. custom (bytes): Optional. A customization byte string. :Return: A :class:`K12_XOF` object )r)r&r'rrrrFsrF)NN)ZCrypto.Util._raw_apirrrrrrrZCrypto.Util.numberr ZCrypto.Util.py3compatr Zkeccakr rrr9r=r7objectrrFrrrrs$    ?