ff?,ddlZddlZddlZddlZddlmZmZddlmZddl m Z ddl m Z ddl mZmZGddejZGd d eZGd d eZGd dejZGddeZGddeZGddejZGddeZGddeZGddejZGddeZGddeZifdZed krddlZd!Zej d"#dSdS)$N) unhexlifyhexlify)tobytes)strxor_c)list_test_cases)BLAKE2bBLAKE2sc\eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdS) Blake2Testc|j|j}|jj|jfD]}td|jdzdD],}||}||j|dz-td|jdzD])}||}||j|*|d|j}||jd}||||dd|j |}||j|jdS) N digest_bits digest_bytes)datarA5)rkeyr) BLAKE2newmax_bitsrange assertEqual digest_size max_bytesdigestupdate)selfhnew_funcdbitshobjdbytesdigest1digest2s /builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/SelfTest/Hash/test_BLAKE2.pytest_new_positivezBlake2Test.test_new_positive.s KOO O 6 6 . G GHq$-!"3Q77 ? ?xE222  !15A:>>>>4>A#566 ; ;xV444  !16::::hG$.IIIPPRRGhDN;;;BB7KKRRTTG   Wg . . . H$Dt~ F F F F Fuuww )4>:::::c|j|j}|jj|jfD]}|t||j|j|t |d|t ||jdz|t |d|t |d|t ||jdz|t||jd |t||jd dS) Nr )rrrrrstringrr)rr)rrr assertRaises TypeErrorr ValueError)r!r"r#s r)test_new_negativezBlake2Test.test_new_negativeDsj KOO O 6 6 . . .H   i+/>*.-  9 9 9   j(  C C C   j(+/>A+=  ? ? ?   j(  B B B   j(  C C C   j(*.-!*;  = = =   i+/>"+  - - -   i+/>#,  . . . . . .r+c|jd}|t ||jdS)Nsabcr)rrrrlenr)r!rs r)test_default_digest_sizez#Blake2Test.test_default_digest_sizeYsGf--4466 Vdn55555r+cddg}|j|j}||d|d|}|j|j}||d|dz|||dS)Ns s,rrr)rrrr rr)r!piecesr"rs r) test_updatezBlake2Test.test_update]s/ KOOO 8 8 ""6!9--- KOOO 8 8 VAY&''' V,,,,,r+c|j|j}|t|jddS)Nrr/)rrrr1r2r )r!r"s r)test_update_negativezBlake2Test.test_update_negativefs9 KOOO 8 8 )QXy99999r+c|j|j}|}||||t |tddS)Nrsdigest)rrrrr assertTrue isinstancetype)r!r"rs r) test_digestzBlake2Test.test_digestjsn KOOO 8 8 V,,,  64 ??;;<<<<>>>>r+c|j|jd}|}||t |d}|t|j|dS)N4r0)rrrrverifyrr1r3)r!r"rM wrong_macs r) test_verifyzBlake2Test.test_verifysf KOOTO B Bhhjj  S#&&  *ah :::::r+c|j|jd}|}|||t |jddS)NrPr04556)rrrrL hexverifyr1r3)r!r"rMs r)test_hexverifyzBlake2Test.test_hexverifysZ KOOTO B Bkkmm C *ak6:::::r+c d|jzdz}|jD]}|j||j|t |dzz|j|d|tfdd|j fD]*}||jvr |tfd+dS) Nz1.3.6.1.4.1.1722.12.2..r rssecret)rrcjSNoidr"sr)z%Blake2Test.test_oid.. aer+cjSr\r]r_sr)r`z%Blake2Test.test_oid..rar+) oid_variantdigest_bits_oidrrrr^strr1AttributeErrorr)r!prefixrr"s @r)test_oidzBlake2Test.test_oids)D,<.get_mv_rosd## #r+c:tt|Sr\)rvrnr6s r) get_mv_rwz-Blake2Test.test_memoryview..get_mv_rwsioo.. .r+rlrmr)rrreadonlyrrr ) r!rrrwryget_mvkey_mvdata_mvrqrrs r)test_memoryviewzBlake2Test.test_memoryviewsr $ $ $ / / /!), 7 7FVC[[FfTllGd44Bg6::B# %% $rr   RYY[["))++ 6 6 6fTllG""B""B IIdOOO IIg   # &%   RYY[["))++ 6 6 6 61 7 7r+N)__name__ __module__ __qualname__r*r4r8r;r=rBrJrNrTrXrhrsr~r+r)r r ,s;;;,...*666---:::===+++" ? ? ?;;;;;; === 3336#7#7#7#7#7r+r c"eZdZeZdZdZdZdZdS) Blake2bTest@)rDir1N) rrrrrrrrdrcrr+r)rr' FHI*OKKKr+rc"eZdZeZdZdZdZdZdS) Blake2sTestrD )rrD2N) rrrr rrrrdrcrr+r)rrrr+rc eZdZdZdZdZdS)Blake2OfficialTestVectorc 0d}g}t|d5}t|D]\}}|dks|dr3t jd|z|}|st d|z|dr0tt|d}nd}|dkr|} d }|d kr|} d }|} d}| | | | f dddn #1swxYwY|S) Ninrt#z%s: ([0-9A-Fa-f]*)&Incorrect test vector format (line %d)rr+rhash) open enumeratestrip startswithrematchr3grouprrappend) r!test_vector_fileexpected test_vectorstest_vector_fd line_numberlineres bin_value input_datarresults r) _load_testsz$Blake2OfficialTestVector._load_tests s "D ) ) C^%.~%>%> C C! T::<<2%%)=)=%h4x?FF4$%M'2&344499Q<<$ )'#))A,,*?*? @ @II #It##!*J$HH&&#C%HH&F#H ''S&(ABBBB/ C C C C C C C C C C C C C C C C2sC)D  DDcd|jf}|jdz}d|jz|_ ddl}n:#t$r-t jd|jztg|_YdSwxYwtj |j }tj tj j |g|R|}|||_dS)NHashz -test.txt%s testsr'Warning: skipping extended tests for %s)namelower descriptionpycryptodome_test_vectors ImportErrorwarningswarn UserWarningrospathdirname__file__joinrr! dir_comps file_namerinit_dirfull_file_names r)setUpzBlake2OfficialTestVector.setUp(sTY' IOO%% 3 % 1  , , , , ,    MCdiO& ( ( ( "D  FF   7??#<#EFFbgl8&Hi&H&H&H)TT ,,^<<s;3A21A2c|jD]d\}}}|j||j}|||||edS)N)rr)rrrrr rr)r!rrrrMs r)runTestz Blake2OfficialTestVector.runTest:sq)-): 3 3 %Zf+//c/GGC JJz " " "   SZZ\\6 2 2 2 2 3 3r+Nrrrrrrrr+r)rrsA<===$33333r+rceZdZeZdZdZdS)Blake2bOfficialTestVectorrrNrrrrrrrrr+r)rrA F DIIIr+rceZdZeZdZdZdS)Blake2sOfficialTestVectorr rNrrrr rrrrr+r)rrJrr+rc eZdZdZdZdZdS)Blake2TestVector1c g}t|d5}t|D]\}}|dks|dr3t jd|}|st d|z|tt| d dddn #1swxYwY|S)Nrrrzdigest: ([0-9A-Fa-f]*)rr) rrrrrrr3rrrr)r!rrrrrrs r)rzBlake2TestVector1._load_testsUs7 "D ) ) F^%.~%>%> F F! T::<<2%%)=)=%h7>>4$%M'2&3444##Igciill.C.C$D$DEEEE F F F F F F F F F F F F F F F FsB/CCCcd|jf}d}d|jz|_ ddl}n:#t$r-t jd|jzt g|_YdSwxYwtj |j }tj tj j |g|R|}| ||_dS)Nrztv1.txtrrrrrrrrrrrrrrrrrrs r)rzBlake2TestVector1.setUpcTY'  % 1  , , , , ,    MCdiO& ( ( ( "D  FF   7??#<#EFFbgl8&Hi&H&H&H)TT ,,^<<!3AAc>|jD]}t|}d}tdD]I}|j|}||||z}J|||dS)Nr+dr)rr7rrrr rr)r!tvr next_data_r"s r)rzBlake2TestVector1.runTestts# - -Br77LI3ZZ 3 3KOOO>>###HHJJ2   QXXZZ , , , , - -r+Nrrr+r)rrSsA   ===" - - - - -r+rceZdZeZdZdS)Blake2bTestVector1rN)rrrrrrrr+r)rr F DDDr+rceZdZeZdZdS)Blake2sTestVector1r N)rrrr rrrr+r)rrrr+rc eZdZdZdZdZdS)Blake2TestVector2c g}t|d5}t|D]\}}|dks|dr3t jd|}|st d|zt|d}tt|d}| ||f dddn #1swxYwY|S)Nrrrz"digest\(([0-9]+)\): ([0-9A-Fa-f]*)rr) rrrrrrr3intrrrr) r!rrrrrrkey_sizers r)rzBlake2TestVector2._load_testssC "D ) ) 8^%.~%>%> 8 8! T::<<2%%)=)=%hDdKK4$%M'2&3444syy||,,"7399Q<<#8#899##Xv$67777 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8sCC55C9<C9cd|jf}d}d|jz|_ ddl}n:#t$r-t jd|jzt g|_YdSwxYwtj |j }tj tj j |g|R|}| ||_dS)Nrztv2.txtrrrrrs r)rzBlake2TestVector2.setUprrc8|jD]\}}d}tdD]R}|j|jd|z}||||z}S|||dS)Nr+rrr0)rrrrrr rr)r!rrrrr"s r)rzBlake2TestVector2.runTests $ 1 1 1 HfI3ZZ 3 3KOO(,x$99###HHJJ2   QXXZZ 0 0 0 0 1 1r+Nrrr+r)rrsA   ===" 1 1 1 1 1r+rceZdZeZdZdZdS)Blake2bTestVector2rrNrrr+r)rrrr+rceZdZeZdZdZdS)Blake2sTestVector2r rNrrr+r)rrrr+rcg}|ttz }|t|t |t |tt z }|t|t|t|Sr\) rrrrrrrrrr)configtestss r) get_testsrs E _[ ) ))E LL*,,--- LL#%%&&& LL#%%&&& _[ ) ))E LL*,,--- LL#%%&&& LL#%%&&& Lr+__main__cBtjtSr\)unittest TestSuiterrr+r)suiters!)++...r+r) defaultTest)!rrrrbinasciirrCrypto.Util.py3compatrCrypto.Util.strxorrCrypto.SelfTest.st_commonr Crypto.Hashrr TestCaser rrrrrrrrrrrrrrmainrr+r)rs> ''''''''))))))''''''555555((((((((77777"777D     *        *   6363636363x0636363r 8 8*-*-*-*-*-)*-*-*-Z**+1+1+1+1+1)+1+1+1\**      zOOO///HMg&&&&&& r+