ff-ddlZddlmZmZddlmZddlmZddlm Z ddl m Z m Z Gddej ZGd d eZGd d eZGd dej ZifdZedkrdZejddSdS)N) unhexlifyhexlify)tobytes)strxor_c)list_test_cases)KMAC128KMAC256cbeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdS)KMACTestc@|jj|dd|jdzzi|S)NkeyX)KMACnewminimum_key_bits)selfargskwargss /builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/SelfTest/Hash/test_KMAC.pyrz KMACTest.new s-ty}tV)>!)C!DVvVVVc2d}|}|jj|jfD]}t|jdD]*}|||}||j|+||d}||d}||||d|d ||}||j|jdS) N XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXr mac_len)r datar Ag)rr custom) rrrange minimum_bytes assertEqual digest_sizedigestupdate default_bytes)rr hnew_funcdbyteshobjdigest1digest2s rtest_new_positivezKMACTest.test_new_positives) HHJJ qu, 6 6H 2G<< ; ;xC888  !16::::h3W555<<>>Gh3'''..w77>>@@G   Wg . . . H$C 5 5 5 5 5uuu~~ )4+=>>>>>rcV|}|jj|jfD]}|t|dd|t|d|jdz |t |d|t |ddS)Nrrrstringrr)rr assertRaises ValueErrorr$ TypeError)rr*r+s rtest_new_negativezKMACTest.test_new_negative$s HHJJ qu, . .H   j(&'  ) ) )   j(&*&81&<  > > >   i"+  - - -   i#,  . . . . . .rc|d}|t||jdS)Nsabcr4)rr'r%lenr))rr's rtest_default_digest_sizez!KMACTest.test_default_digest_size1sFv&&--// Vd&899999rcddg}|}||d|d|}|}||d|dz|||dS)Ns s,rr2)rr(r'r%)rpiecesr*r's r test_updatezKMACTest.test_update5s/ HHJJ ""6!9--- HHJJ VAY&''' V,,,,,rcp|}|t|jddS)Nr3)rr5r7r()rr*s rtest_update_negativezKMACTest.test_update_negative>s/ HHJJ )QXy99999rc|}|}||||t |t ddS)Nsdigest)rr'r% assertTrue isinstancetype)rr*r's r test_digestzKMACTest.test_digestBsd HHJJ V,,,  64 ??;;<<<<>>>>rc|}|}||t|d}|t |j|dS)N)rr'verifyrr5r6)rr*rN wrong_macs r test_verifyzKMACTest.test_verify_sZ HHJJhhjj  S#&&  *ah :::::rc|}|}|||t|jddS)N4556)rrM hexverifyr5r6)rr*rNs rtest_hexverifyzKMACTest.test_hexverifyfsN HHJJkkmm C *ak6:::::rcxd|jz}|}||j|dS)Nz2.16.840.1.101.3.4.2.) oid_variantrr%oid)rr[r*s rtest_oidzKMACTest.test_oidls:%(88 HHJJ $$$$$rcd}d}t|}t|}|j||}|j||}d|dd<d|dd<|||t|}|}|}||||d|dd<|||dS)N 00000000000000000000000000000000rr r2) bytearrayrrr%r'r()rr rkey_badata_bah1h2s rtest_bytearrayzKMACTest.test_bytearrayrs3D// Y]]#] . . Y]]V] 4 4rr   biikk222D// XXZZ XXZZ $ '  biikk22222rcd}d}d}d}||fD]E}||}||}|j||}|j||} |jsd|dd<d|dd<||| ||}|}|} ||| ||jsd|dd<||| GdS)Nr^r_c t|SN) memoryviewr4s r get_mv_roz+KMACTest.test_memoryview..get_mv_rosd## #rc:tt|Srj)rkrbr4s r get_mv_rwz+KMACTest.test_memoryview..get_mv_rwsioo.. .rr`rar2)rrreadonlyr%r'r() rr rrlrnget_mvkey_mvdata_mvrerfs rtest_memoryviewzKMACTest.test_memoryviewsj $ $ $ / / /!), 7 7FVC[[FfTllGDc22BG88B# %% $rr   RYY[["))++ 6 6 6fTllGBB IIdOOO IIg   # &%   RYY[["))++ 6 6 6 61 7 7rN)__name__ __module__ __qualname__rr0r8r;r>r@rErKrOrTrXr\rgrsrrr r sWWW???( . . .:::---:::===555 ? ? ?;;;;;; %%% 3336#7#7#7#7#7rr c"eZdZeZdZdZdZdZdS) KMAC128Testr@19N) rtrurvrrrr$r)rZrwrrryry( DMMKKKrryc"eZdZeZdZdZdZdZdS) KMAC256Testrr{20N) rtrurvr rrr$r)rZrwrrrrr}rrc reZdZdddddefdddddefdd dd d efdddd d efdd dddefdd dddefgZdZdZdS)NISTExampleTestVectorsz^40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5Fz 00 01 02 03z^E5 78 0B 0D 3E A6 F7 D3 A4 29 C5 70 6A A4 3A 00FA DB D7 D4 96 28 83 9E 31 87 24 3F 45 6E E1 4EzSample #1 NISTzMy Tagged Applicationz^3B 1F BA 96 3C D8 B0 B5 9E 8C 1A 6D 71 88 8B 7143 65 1A F8 BA 0A 70 70 C0 97 9E 28 11 32 4A A5zSample #2 NISTaK00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9FA0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AFB0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BFC0 C1 C2 C3 C4 C5 C6 C7z^1F 5B 4E 6C CA 02 20 9E 0D CB 5C A6 35 B8 9A 15E2 71 EC C7 60 07 1D FD 80 5F AA 38 F9 72 92 30zSample #3 NISTz20 C5 70 C3 13 46 F7 03 C9 AC 36 C6 1C 03 CB 64C3 97 0D 0C FC 78 7E 9B 79 59 9D 27 3A 68 D2 F7F6 9D 4C C3 DE 9D 10 4A 35 16 89 F2 7C F6 F5 951F 01 03 F3 3F 4F 24 87 10 24 D9 C2 77 73 A8 DDzSample #4 NISTz75 35 8C F3 9E 41 49 4E 94 97 07 92 7C EE 0A F20A 3F F5 53 90 4C 86 B0 8F 21 CC 41 4B CF D6 9158 9D 27 CF 5E 15 36 9C BB FF 8B 9A 4C 2E B1 7800 85 5D 02 35 FF 63 5D A8 25 33 EC 6B 75 9B 69zSample #5 NISTzB5 86 18 F7 1F 92 E1 D5 6C 1B 8C 55 DD D7 CD 188B 97 B4 CA 4D 99 83 1E B2 69 9A 83 7D A2 E4 D970 FB AC FD E5 00 33 AE A5 85 F1 A2 70 85 10 C32D 07 88 08 01 BD 18 28 98 FE 47 68 76 FC 89 65zSample #6 NISTc ^g}|jD]\}}}}}}t|ddt|dd|t|dd||f}||||_dS)N r) test_datarreplaceencodeappend) rtdr rr"rNtextmodulenis rsetUpzNISTExampleTestVectors.setUp7s 48N   0CvsD&#++c2..//$,,sB//00 #++c2..// B IIbMMMMrc |jD][\}}}}}}||||t|}|}||||\dS)N)rr r"r)rI)rrr:r'r%) rr rr"rNrrr*mac_tags rrunTestzNISTExampleTestVectors.runTestEst48N 5 5 0CvsD& #fc#hh OOAhhjjG   Wct  4 4 4 4 5 5rN)rtrurvrr rrrrwrrrrs  >   >    >  # >    > & $ >  ) . >  # >    > &  >  - 2 > & $ >  - _gIR   55555rrcg}|ttz }|ttz }|t |Srj)rryrrr)configtestss r get_testsrMsI E _[ ) ))E _[ ) ))E LL'))*** Lr__main__cBtjtSrj)unittest TestSuiterrwrrsuiterXs!)++...rr) defaultTest)rbinasciirrCrypto.Util.py3compatrCrypto.Util.strxorrCrypto.SelfTest.st_commonr Crypto.Hashrr TestCaser ryrrrrtrmainrwrrrs''''''''))))))''''''555555((((((((e7e7e7e7e7x e7e7e7P     (        (   55555X.555D z///HMg&&&&&&r