HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //proc/thread-self/root/usr/local/lib/python3.7/test/__pycache__/test_hashlib.cpython-37.opt-2.pyc
B

��g���@sXddlZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZmZmZddlmZeed�Zeddgd	�Zeddgd
�ZyddlZWnek
r�dZYnXe	�ed�ZyddlZWnek
r�dZYnXe	�ed�Zd
d�ZdZdd�ZGdd�de	j �Z!Gdd�de	j �Z"e#dk�rTe	�$�dS)�N)�	unhexlify)�support)�_4G�
bigmemtest�import_fresh_module)�
HTTPException�gettotalrefcount�hashlib�_hashlib)Zfresh)Zblockedzrequires _blake2zrequires _sha3cCs:d}d}x,|D]$}|||d?d@||d@7}qW|S)NZ0123456789abcdef����)�s�h�r�irr�-/usr/local/lib/python3.7/test/test_hashlib.py�hexstr,s

$rz(http://www.pythontest.net/hashlib/{}.txtc	cs�t�|�}yt�|�}Wn(ttfk
r@t�d�|���YnX|�NxF|D]>}|��}|�	d�sN|sjqN|�
d�}t�|d�|d<|VqNWWdQRXdS)NzCould not retrieve {}�#�,r)
�URL�formatrZopen_urlresource�OSErrorr�unittestZSkipTest�strip�
startswith�split�bytes�fromhex)�	hash_nameZurlZtestdata�line�partsrrr�read_vectors7s


r#csfeZdZdZddhZejdkp eZdd�Z	�fdd�Z
ed	d
��Ze
je�edkd�d
d���Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd�d"d#�Zd$d%�Zd&d'�Zed(d)��Z e!d*d+��Z"d�d-d.�Z#d/d0�Z$e!d1d2��Z%d3d4�Z&e!d5d6��Z'ed7d8��Z(d9d:�Z)d;d<�Z*d=d>�Z+e�e,j-e.d?kd@�e/e.d?dAd!dB�dCdD���Z0e�e,j-e.dAkd@�e/e.dAdAd!dB�dEdF���Z1dGdH�Z2dIdJ�Z3dKdL�Z4dMdN�Z5dOdP�Z6dQdR�Z7dSdT�Z8dUdV�Z9dWdX�Z:dYdZ�Z;d[d\�Z<d]d^�Z=d_d`�Z>dadb�Z?dcdd�Z@dedf�ZAdgdh�ZBdidj�ZCdkdl�ZDdmdn�ZEdodp�ZFdqdr�ZGedsdt��ZHedudv��ZIedwdx��ZJedydz��ZKed{d|��ZLed}d~��ZMedd���ZNed�d���ZOed�d���ZPed�d���ZQe!d�d���ZRe!d�d���ZSe!d�d���ZTe!d�d���ZUe!d�d���ZVe!d�d���ZWe!d�d���ZXe!d�d���ZYe!d�d���ZZe!d�d���Z[e!d�d���Z\e!d�d���Z]d�d��Z^e
j_d�d���Z`�ZaS)��HashLibTestCase)�md5�MD5�sha1ZSHA1�sha224ZSHA224�sha256ZSHA256�sha384ZSHA384�sha512ZSHA512�blake2b�blake2s�sha3_224�sha3_256�sha3_384�sha3_512�	shake_128�	shake_256r2r3�posixc
CsFy
t�|�Stk
r@}z|jr0t�d|�Wdd}~XYnXdS)Nz%Did a C extension fail to compile? %s)�	importlib�
import_module�ModuleNotFoundError�_warn_on_extension_import�warnings�warn)�selfZmodule_name�errorrrr�_conditional_import_moduleTs
 z*HashLibTestCase._conditional_import_modulecs�t�}x�jD]}|�|���qW��d�}|r@|�ddh�i�_x|D]}t��j|<qLWx>�j��D]0\}}|�tt	|��d|fdd�}|�|�qlW��d�}|�r��
t|d����
t|d��x4�j��D]&\}}t|d	|d�}	|	r�|�|	�q�W�fd
d�}
��d�}|�r*|
d
���d�}|�rB|
d���d�}
|
�rb|
d�|
d���d�}|�r�|
d�|
d�|�r�|
d�|
d���d�}|�r�|
d�|
d�|
d�|
d�|
d�|
d�tt
��j||�dS)N�_blake2r,r-c[s&|dkrtj|f|�Stj||f|�S)N)r	�new)�dataZ_alg�kwargsrrr�_test_algorithm_via_hashlib_newnszAHashLibTestCase.__init__.<locals>._test_algorithm_via_hashlib_newr
Zopenssl_md5Zopenssl_sha1Zopenssl_cs"ttd�|�}�j|�|�dS)N�__get_builtin_constructor)�getattrr	�constructors_to_test�add)�name�constructor)r;rr�add_builtin_constructorsz9HashLibTestCase.__init__.<locals>.add_builtin_constructor�_md5r%�_sha1r'�_sha256r(r)�_sha512r*r+�_sha3r.r/r0r1r2r3)�set�supported_hash_namesrF�lowerr=�updaterE�itemsrDr	�
assertTrue�hasattr�superr$�__init__)r;�argsrAZ
algorithms�	algorithmr>�constructorsrBr
rHrIrJrKrLrMrN)�	__class__)r;rrW]s`







zHashLibTestCase.__init__cCs|j��}tj�|�S)N)rE�values�	itertools�chain�
from_iterable)r;rZrrr�hash_constructors�s
z!HashLibTestCase.hash_constructorsNzRequire _hashlib modulecCsRt�td�}t�d�}|�}xtd�D]}|�d�q&W|j|�|ddd�dS)Nrr'�dr�
)Zdelta)rZ
get_attribute�sys�	c_hashlibr?�rangerWZassertAlmostEqual)r;rZ	sha1_hashZrefs_beforerrrr�test_refleaks_in_hash___init__�s
z.HashLibTestCase.test_refleaks_in_hash___init__cCsLt�dtd��}x6|jD],}||�}|j|jkr<|�d�q|��qWdS)N�brb�)�arrayrer`rG�shakes�	hexdigest)r;�a�cons�crrr�test_hash_array�szHashLibTestCase.test_hash_arraycCs"|�tjtdd�|jD���dS)Ncss|]}|��r|VqdS)N)�islower)�.0Z_algorrr�	<genexpr>�sz=HashLibTestCase.test_algorithms_guaranteed.<locals>.<genexpr>)�assertEqualr	�algorithms_guaranteedrOrP)r;rrr�test_algorithms_guaranteed�sz*HashLibTestCase.test_algorithms_guaranteedcCs|�ttj��tj��dS)N)rTrOr	rt�issubsetZalgorithms_available)r;rrr�test_algorithms_available�sz)HashLibTestCase.test_algorithms_availablecCs$|�ttjd�|�ttjd�dS)Nzspam spam spam spam spam�)�assertRaises�
ValueErrorr	r?�	TypeError)r;rrr�test_unknown_hash�sz!HashLibTestCase.test_unknown_hashc	Cs�ttd�}ttd�}|�t|d�yddl}Wntk
rL|�d�YnXdtjd<|�	�z|�t|d�Wddt
�kr�|tjd<ntjd=X|�t|d�|d�}|�||j
�|�t|�d	dg�dS)
NrCZ__builtin_constructor_cache�testrz_md5 module not availablerJr%�r&)rDr	ryrzrJ�ImportErrorZskipTestrc�modules�clear�localsr{ZassertIsr%rs�sorted)r;Zget_builtin_constructorZbuiltin_constructor_cacherJrHrrr�test_get_builtin_constructor�s(


z,HashLibTestCase.test_get_builtin_constructorcCs~xx|jD]n}|�}|j|jkrN|�|�d�t�|�t|�d��|�d��q|�|��t�|�t|���|���qWdS)Nrh)	r`rGrj�assertIsInstance�digestrrsrrk)r;rmrrrr�test_hexdigest�szHashLibTestCase.test_hexdigestcCs�d}x�|jD]�}|�}|j|jkr$qxf|j|jfD]V}|�ttf��|d�WdQRXx.|D]&}|�ttf��||�WdQRXq^Wq2WqWdS)N)i l��l
ll����l
i����)r`rGrjr�rkryrz�
OverflowError)r;Zlarge_sizesrmrr��lengthrrr�test_digest_length_overflow�s
z+HashLibTestCase.test_digest_length_overflowcCsnxh|jD]^}|�}|�|jt�|j|jkr>|�|j|j�n|�|j|j�|�|jt�	|j�j�qWdS)N)
r`r�rG�strrP�assertInZassertNotInrsr	r?)r;rmrrrr�test_name_attribute�sz#HashLibTestCase.test_name_attributec
Cs d}d}d}d}�x|jD]�}|�}|�|�|�|�|�|�|�|�|j|jkr^d}nd}|�}|�||||�|�|j|�|j|��|||||�}	|�|j|�|	j|��||||�}
|
j|�}|
��}|�|�|�|j|�|j|��|�|
j|�|�qWdS)Ns�aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbs~ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccsdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd)rhr)r`rRrGrjrsr��copy)
r;ZaasZbeesZceesZdeesrmZm1rXZm2Zm3Zm4Z	m4_digestZm4_copyrrr�test_large_updates0





z!HashLibTestCase.test_large_updateFcKs�t|�d}|��}|j|}|�t|�d�x�|D]�}||f|�}	|sP|	��n|	�|�}
|�|
|d|||
t|�|f�|s�|	��n|	�|�}
t�|�}|�|
|�|s4|�t|�|	j	�q4WdS)N�zrHash algorithm %s constructed using %s returned hexdigest %r for %d byte input data that should have hashed to %r.)
�lenrQrEZassertGreaterEqualrkrsr�rr�digest_size)r;rGr@rkZshakerAr�rZ�hash_object_constructor�mZcomputedr�rrr�check!s"


zHashLibTestCase.checkcCs*|j|}x|D]}|�t|d�qWdS)NZspam)rEryr{)r;Zalgorithm_namerZr�rrr�check_no_unicode6s

z HashLibTestCase.check_no_unicodecCs@|�d�|�d�|�d�|�d�|�d�|�d�dS)Nr%r'r(r)r*r+)r�)r;rrr�test_no_unicode<s




zHashLibTestCase.test_no_unicodecCs|�d�|�d�dS)Nr,r-)r�)r;rrr�test_no_unicode_blake2Ds
z&HashLibTestCase.test_no_unicode_blake2cCs@|�d�|�d�|�d�|�d�|�d�|�d�dS)Nr.r/r0r1r2r3)r�)r;rrr�test_no_unicode_sha3Is




z$HashLibTestCase.test_no_unicode_sha3rcCs�|j|}x�|D]�}|�}|�|j|�|�|j|�|rl|�t|�|��|�|�t|�|��d|�n,|�t|���|�|�t|���d|�|�|j|�|�|�	d�dt
|��qWdS)Nr��_r)rErs�
block_sizer�r�r�rkrGr�r�repr)r;rGr�r�Z
digest_lengthrZr�r�rrr�check_blocksize_nameRs

z$HashLibTestCase.check_blocksize_namecCsX|�ddd�|�ddd�|�ddd�|�ddd	�|�d
dd�|�d
dd�dS)Nr%�@rhr'�r(�r)� r*��0r+)r�)r;rrr�test_blocksize_nameesz#HashLibTestCase.test_blocksize_namecCs\|�ddd�|�ddd�|�ddd	�|�d
dd�|�d
ddd�|�dddd�dS)Nr.�r�r/�r�r0�hr�r1�Hr�r2�rr3)r�)r;rrr�test_blocksize_name_sha3msz(HashLibTestCase.test_blocksize_name_sha3cCs\|j|}xL|D]D}|�}|�||d�|�|j|�|�|j|�|�|j|�qWdS)Ni@)rErsZ_capacity_bitsZ
_rate_bitsZ_suffix)r;rGZcapacityZrate�suffixrZr�r�rrr�
check_sha3vs

zHashLibTestCase.check_sha3cCsd|�dddd�|�dddd�|�dd	d
d�|�ddd
d�|�dddd�|�dddd�dS)Nr.i�i��r/ii@r0ii@r1ii@r2�i@�r3)r�)r;rrr�test_extra_sha3szHashLibTestCase.test_extra_sha3cCs |�ddd�|�ddd�dS)Nr,r�r�r-r�)r�)r;rrr�test_blocksize_name_blake2�sz*HashLibTestCase.test_blocksize_name_blake2cCs|�ddd�dS)Nr%�Z d41d8cd98f00b204e9800998ecf8427e)r�)r;rrr�test_case_md5_0�szHashLibTestCase.test_case_md5_0cCs|�ddd�dS)Nr%sabcZ 900150983cd24fb0d6963f7d28e17f72)r�)r;rrr�test_case_md5_1�szHashLibTestCase.test_case_md5_1cCs|�ddd�dS)Nr%s>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789Z d174ab98d277d9f5a5611c2c9f419d9f)r�)r;rrr�test_case_md5_2�szHashLibTestCase.test_case_md5_2�z!test cannot run on 32-bit systemsrx)�sizeZmemuseZdry_runcCs|�dd|d�dS)Nr%�AZ c9af2dff37468ce5dfee8f2cfc0a9c6d)r�)r;r�rrr�test_case_md5_huge�sz"HashLibTestCase.test_case_md5_hugecCs|�dd|d�dS)Nr%r�Z 28138d306ff1b8281f1a9067e1a1a2b3)r�)r;r�rrr�test_case_md5_uintmax�sz%HashLibTestCase.test_case_md5_uintmaxcCs|�ddd�dS)Nr'r�Z(da39a3ee5e6b4b0d3255bfef95601890afd80709)r�)r;rrr�test_case_sha1_0�sz HashLibTestCase.test_case_sha1_0cCs|�ddd�dS)Nr'sabcZ(a9993e364706816aba3e25717850c26c9cd0d89d)r�)r;rrr�test_case_sha1_1�sz HashLibTestCase.test_case_sha1_1cCs|�ddd�dS)Nr's8abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqZ(84983e441c3bd26ebaae4aa1f95129e5e54670f1)r�)r;rrr�test_case_sha1_2�sz HashLibTestCase.test_case_sha1_2cCs|�dddd�dS)Nr'�ai@BZ(34aa973cd4c4daa4f61eeb2bdbad27316534016f)r�)r;rrr�test_case_sha1_3�sz HashLibTestCase.test_case_sha1_3cCs|�ddd�dS)Nr(r�Z8d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f)r�)r;rrr�test_case_sha224_0�sz"HashLibTestCase.test_case_sha224_0cCs|�ddd�dS)Nr(sabcZ823097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7)r�)r;rrr�test_case_sha224_1�sz"HashLibTestCase.test_case_sha224_1cCs|�ddd�dS)Nr(s8abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqZ875388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525)r�)r;rrr�test_case_sha224_2�sz"HashLibTestCase.test_case_sha224_2cCs|�dddd�dS)Nr(r�i@BZ820794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67)r�)r;rrr�test_case_sha224_3�sz"HashLibTestCase.test_case_sha224_3cCs|�ddd�dS)Nr)r�Z@e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855)r�)r;rrr�test_case_sha256_0�sz"HashLibTestCase.test_case_sha256_0cCs|�ddd�dS)Nr)sabcZ@ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad)r�)r;rrr�test_case_sha256_1�sz"HashLibTestCase.test_case_sha256_1cCs|�ddd�dS)Nr)s8abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqZ@248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1)r�)r;rrr�test_case_sha256_2�sz"HashLibTestCase.test_case_sha256_2cCs|�dddd�dS)Nr)r�i@BZ@cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0)r�)r;rrr�test_case_sha256_3�sz"HashLibTestCase.test_case_sha256_3cCs|�ddd�dS)Nr*r�Z`38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b)r�)r;rrr�test_case_sha384_0�sz"HashLibTestCase.test_case_sha384_0cCs|�ddd�dS)Nr*sabcZ`cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7)r�)r;rrr�test_case_sha384_1�sz"HashLibTestCase.test_case_sha384_1cCs|�ddd�dS)Nr*spabcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstuZ`09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039)r�)r;rrr�test_case_sha384_2�sz"HashLibTestCase.test_case_sha384_2cCs|�dddd�dS)Nr*r�i@BZ`9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985)r�)r;rrr�test_case_sha384_3�sz"HashLibTestCase.test_case_sha384_3cCs|�ddd�dS)Nr+r�Z�cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e)r�)r;rrr�test_case_sha512_0�sz"HashLibTestCase.test_case_sha512_0cCs|�ddd�dS)Nr+sabcZ�ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f)r�)r;rrr�test_case_sha512_1�sz"HashLibTestCase.test_case_sha512_1cCs|�ddd�dS)Nr+spabcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstuZ�8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909)r�)r;rrr�test_case_sha512_2sz"HashLibTestCase.test_case_sha512_2cCs|�dddd�dS)Nr+r�i@BZ�e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b)r�)r;rrr�test_case_sha512_3sz"HashLibTestCase.test_case_sha512_3cCsB|�|j|�x"t|d�D]}|d|d�qWd|d}|jt||d�|�|j|�x"t|d�D]}|d|d�qjWd|d}	|jt||	d�|�|j|�x td|d�D]}||d�q�W|jt|dd�|jt|dd�|jt||dd�|�|j|�x$t|d�D]}|d|d��qWd|d}
|jt||
d�|�|���|d	d����xtdd
�D]}||d��qxW|jt|dd�|jt|d
d�xtdd
�D]}||d��q�W|jt|dd�|jt|dd�|jt|d
d�xtdd
�D]}||d
��qW|jt|dd
�|jt|d
d
�x"td|d�D]}||d��qLW|jt|dd�|jt||dd�|dd�|dd�|jt	|dd�|jt	|dd�|dd�||d�|jt	|dd�|jt	||dd�|jt
|d	d�|jt
|d	d�|�t
|d�|d	d	d	d	dddd
ddddd�dS)Nrxr�)�salt)�person)r����r)�keyr�r�)�fanout)�depth)�
node_depth)�
inner_size)�	leaf_sizel��l)�node_offset)r@)�stringr�i�T)r�r�r�r�r�r�r�r�r�r��	last_node)rsZ	SALT_SIZEreryrzZPERSON_SIZEZMAX_DIGEST_SIZEZMAX_KEY_SIZErkr�r{)r;rHZ	salt_sizeZperson_sizeZkey_sizer�Z
max_offsetrr�r�r�rrr�check_blake2
s�



zHashLibTestCase.check_blake2cCs�dd�}|dd�}xd|D]\}xV|D]N}|||�}|||�}	|||d�}
|�|
���|||	|d�}|�|���q"WqW|��S)NcSsXd}d||@}d}t|�}x6t|�D]*}|||@}||}}|d?d@||<q&W|S)Nl��l�KZ=rx��)�	bytearrayre)r�Zseed�maskrlrg�outr�trrr�selftest_seq]s
z4HashLibTestCase.blake2_rfc7693.<locals>.selftest_seqr�)r�)r�r�)rRr�rk)r;rHZmd_lenZin_lenr�ZouterZoutlenZinlenZindatar�ZunkeyedZkeyedrrr�blake2_rfc7693\s





zHashLibTestCase.blake2_rfc7693cCsN|�tjddddd�ddddg}ddd	d
ddg}|�|�tj||�d
�dS)Nrhr�l����r�r�r�rr~r��r�iZ@c23a7800d98123bd10f506c61e29da5603d763b8bbad2e737f5e765a7bccd475)r�r	r,rsr�)r;Z
b2b_md_lenZ
b2b_in_lenrrr�test_blake2brszHashLibTestCase.test_blake2bcCs|�ddd�dS)Nr,r�Z�786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce)r�)r;rrr�test_case_blake2b_0{sz#HashLibTestCase.test_case_blake2b_0cCs|�ddd�dS)Nr,sabcZ�ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923)r�)r;rrr�test_case_blake2b_1�sz#HashLibTestCase.test_case_blake2b_1cCs*|jddddddddd	d
ddd
dd�dS)Nr,sfooZ 920568b0c5873b2f0ab67bedb6cf1b2brhsbarsbazsbingr�r~rr��r�T)r�r�r�r�r�r�r�r�r�r�r�)r�)r;rrr� test_case_blake2b_all_parameters�sz0HashLibTestCase.test_case_blake2b_all_parameterscCs8x2td�D]&\}}}t�|�}|jd|||d�q
WdS)Nr,)r�)r#rrr�)r;�msgr��mdrrr�test_blake2b_vectors�s
z$HashLibTestCase.test_blake2b_vectorscCsN|�tjddddd�ddddg}ddd	d
ddg}|�|�tj||�d
�dS)N�r�l���rhr�r�rr~r��Ar�iZ@6a411f08ce25adcdfb02aba641451cec53c598b24f4fc787fbdc88797f4c1dfe)r�r	r-rsr�)r;Z
b2s_md_lenZ
b2s_in_lenrrr�test_blake2s�szHashLibTestCase.test_blake2scCs|�ddd�dS)Nr-r�Z@69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9)r�)r;rrr�test_case_blake2s_0�sz#HashLibTestCase.test_case_blake2s_0cCs|�ddd�dS)Nr-sabcZ@508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982)r�)r;rrr�test_case_blake2s_1�sz#HashLibTestCase.test_case_blake2s_1cCs*|jddddddddd	d
ddd
dd�dS)Nr-sfooZ bf2a8f7fe3c555012a6f8046e646bc75rhsbarsbazsbingr�r~rr�r�r�T)r�r�r�r�r�r�r�r�r�r�r�)r�)r;rrr� test_case_blake2s_all_parameters�sz0HashLibTestCase.test_case_blake2s_all_parameterscCs8x2td�D]&\}}}t�|�}|jd|||d�q
WdS)Nr-)r�)r#rrr�)r;r�r�r�rrr�test_blake2s_vectors�s
z$HashLibTestCase.test_blake2s_vectorscCs|�ddd�dS)Nr.r�Z86b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7)r�)r;rrr�test_case_sha3_224_0�sz$HashLibTestCase.test_case_sha3_224_0cCs(x"td�D]\}}|�d||�q
WdS)Nr.)r#r�)r;r�r�rrr�test_case_sha3_224_vector�sz)HashLibTestCase.test_case_sha3_224_vectorcCs|�ddd�dS)Nr/r�Z@a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a)r�)r;rrr�test_case_sha3_256_0�sz$HashLibTestCase.test_case_sha3_256_0cCs(x"td�D]\}}|�d||�q
WdS)Nr/)r#r�)r;r�r�rrr�test_case_sha3_256_vector�sz)HashLibTestCase.test_case_sha3_256_vectorcCs|�ddd�dS)Nr0r�Z`0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004)r�)r;rrr�test_case_sha3_384_0�sz$HashLibTestCase.test_case_sha3_384_0cCs(x"td�D]\}}|�d||�q
WdS)Nr0)r#r�)r;r�r�rrr�test_case_sha3_384_vector�sz)HashLibTestCase.test_case_sha3_384_vectorcCs|�ddd�dS)Nr1r�Z�a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26)r�)r;rrr�test_case_sha3_512_0�sz$HashLibTestCase.test_case_sha3_512_0cCs(x"td�D]\}}|�d||�q
WdS)Nr1)r#r�)r;r�r�rrr�test_case_sha3_512_vector�sz)HashLibTestCase.test_case_sha3_512_vectorcCs$|�dddd�|�dddd�dS)Nr2r�Z@7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26TZ7f9c)r�)r;rrr�test_case_shake_128_0�sz%HashLibTestCase.test_case_shake_128_0cCs*x$td�D]\}}|�d||d�q
WdS)Nr2T)r#r�)r;r�r�rrr�test_case_shake128_vector�sz)HashLibTestCase.test_case_shake128_vectorcCs$|�dddd�|�dddd�dS)Nr3r�Z@46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fTZ46b9)r�)r;rrr�test_case_shake_256_0sz%HashLibTestCase.test_case_shake_256_0cCs*x$td�D]\}}|�d||d�q
WdS)Nr3T)r#r�)r;r�r�rrr�test_case_shake256_vectorsz)HashLibTestCase.test_case_shake256_vectorcCs�d}xL|jD]B}|�}|�d�|�d|�|�d�|d|�}|�d�qWt��}|�d�|�d|�|�d�|�|��d�t�d|�}|�|��d�dS)Ni�1�#�xZ cb1e1a2cbc80be75e19935d621fb9b21Z cfb767f225d58469c5de3632a8803958)r`rRr	r%rsrk)r;Zgil_minsizermr�rrr�test_gils



zHashLibTestCase.test_gilc	s�t���d}d}|d�t��|���}��fdd�}g}xZt|�D]N}t��d|}|�|d�|�|t|�d�tj||fd�}|�	|�qFWx|D]}|�
�q�Wx|D]}|��q�W|�|����dS)	Nr�sswineflui@
cs8d}x.|t��kr2���|||��||7}qWdS)Nr)r�rR)�
chunk_size�index)r@�hasherrr�hash_in_chunks1sz=HashLibTestCase.test_threaded_hashing.<locals>.hash_in_chunksrbr)�targetrX)r	r'rkrer�Z
assertGreaterrs�	threadingZThread�append�start�join)	r;Znum_threadsZ
smallest_dataZ
expected_hashr
ZthreadsZ	threadnumrZthreadr)r@r	r�test_threaded_hashing#s&


z%HashLibTestCase.test_threaded_hashing)F)rrN)b�__name__�
__module__�__qualname__rPrj�osrG�COMPILED_WITH_PYDEBUGr8r=rW�propertyr`rZ
refcount_testrZskipIfrdrfrorurwr|r�r�r�r�r�r�r�r��requires_blake2r��
requires_sha3r�r�r�r�r�r�r�r�r�r�rc�maxsizerrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrZreap_threadsr�
__classcell__rr)r[rr$Gs�	C		

 
	
				O		r$c	@sXeZdZdddddgZddddded	�fd
ddd
ded�fdddd
ded�fgZe�d�dfe�d�dfe�d�dfe�d�dfe�d�dfge�d�dfe�d�dfe�d�dfe�d�dfe�d�dfge�d �dfe�d!�dfe�d"�dfe�d#�d$fe�d%�dfgd&�Zd'd(�Z	d)d*�Z
e�e
ed+�d,�d-d.��Ze�e
ed/�d0�d1d2��ZdS)3�KDFTests)spasswordssaltrxN)spasswordssaltr�N)spasswordssaltiN)spasswordPASSWORDpasswords$saltSALTsaltSALTsaltSALTsaltSALTsaltir�)s	passwordssaltirhr�rhrxZ�77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3fede21442fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628cf35e20c38d18906spasswordsNaClir�Z�fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640s
pleaseletmeinsSodiumChloridei@Z�7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887Z(0c60c80f961f0e71f3a9b524af6012062fe037a6NZ(ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957Z(4b007901b765489abead49d926f721d065a429c1Z23d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038�Z 56fa6aa75548099dcc37d7f03425e0c3Z@120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17bZ@ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43Z@c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134aZP348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1c635518c7dac47e9�(Z 89b69d0516f829893c696226650a8687Z�867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d470a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fceZ�e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53cf76cab2868a39b9f7840edce4fef5a82be67335c77a6068e04112754f27ccf4eZ�d197b1b33db0143e018b12f3d1d1479e6cdebdcc97c5c0f87f6902e072f457b5143f30602641b3d55cd335988cb36b84376060ecd532e039b742a239434af2d5Z�8c0511f4c6e597c6ac6315d8f0362e225f3c501495ba23b868c005174dc4ee71115b59f9e60cd9532fa33e0f75aefe30225c583a186cd82bd4daea9724a3d3b8r�Z 9d9e9c4cd21fe4be24d5b8244c759665)r'r)r+c
Cs�x�|j��D]�\}}x�t|j�D]�\}}|\}}}}	||\}
}|rH|}	||||||	�}|�||
|||||	f�||t|�t|�||	�}||t|�t|�||	�}|�||
�|	dkr |||||�}|�||
||||f�q WqW|�t|dddd�|�t|dddd�|�t	|dddd�|�t	|dddd	�|�t	|ddddd�|�t	|ddddd	�|�
t	d
��|dddd�WdQRX|dddddd
�}|�||jddd�dS)Nssha1spassssaltrxr'�passr�rr�zunsupported hash type�unknownspassword)r �passwordr�Z
iterations�dklen)�pbkdf2_resultsrS�	enumerate�pbkdf2_test_vectorsrs�
memoryviewr�ryr{rzZassertRaisesRegex)
r;Zpbkdf2Zdigest_name�resultsrZvectorr r��roundsr!�expectedZoverwrite_dklenr�rrr�_test_pbkdf2_hmac�s:


zKDFTests._test_pbkdf2_hmaccCs|�tj�dS)N)r)�
py_hashlib�pbkdf2_hmac)r;rrr�test_pbkdf2_hmac_py�szKDFTests.test_pbkdf2_hmac_pyr+z   test requires OpenSSL > 1.0cCs|�tj�dS)N)r)rdr+)r;rrr�test_pbkdf2_hmac_c�szKDFTests.test_pbkdf2_hmac_c�scryptz   test requires OpenSSL > 1.1c

CsXx:|jD]0\}}}}}}tj|||||d�}|�||�qWtjdddddd�|�t��tjdddddd�WdQRX|�t��tjdddddd�WdQRX|�t��t�d�WdQRX|�t��t�dd�WdQRX|�t��tjdddddd	�WdQRXx>d
D]6}|�tttf��tjdd|ddd�WdQRX�qWx>dD]6}|�tttf��tjddd|dd�WdQRX�qVWx>dD]6}|�tttf��tjdddd|d�WdQRX�q�Wx@dD]8}|�tttf��tjddddd|d
�WdQRX�q�Wx@dD]8}	|�tttf��tjddddd|	d�WdQRX�qWdS)N)r��nr�pspasswordssaltr�r�rxr r�)r�)r�rrxN)r�rN)r�N)r�r/rr0�maxmem)r�r/rr0r!)�scrypt_test_vectorsr	r.rsryr{rzr�)
r;r r�r/rr0r(�resultr1r!rrr�test_scrypt�s>
$
$
$

zKDFTests.test_scrypt)rrrr$rr2rrr"r)r,r�
skipUnlessrUrdr-r4rrrrrHsL r�__main__)%riZbinasciirr	r5r]rrcrrr9r}rZtest.supportrrrZhttp.clientrrUrrdr*r>rr5rrNrrrr#ZTestCaser$rr�mainrrrr�<module>	sN