Xc@sdZddlmZddlZddlZejeZddlZddl Z e j ddddl m Z ddl mZddlmZmZmZdd lmZdd lmZmZmZmZdd lmZd d dgZdZedZ dZ!d efdYZ"defdYZ#eepQedddd e#fdYZ$dZ%ee%dde#fdYZ&dS(stests for passlib.utils.scrypti(thexlifyNtignores .*using builtin scrypt backend.*(texc(t getrandbytes(tPYPYtut bascii_to_str(t classproperty(tTestCaset skipUnlesst TEST_MODEthb(tscrypttScryptEngineTesttBuiltinScryptTesttFastScryptTestcCstt|S(sreturn bytes as hex str(RR(tdata((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pythexstrscCsBt|d}|dks.||ks.ttjd||S(s%unpack bytes as list of uint32 valuesis<%dIN(tlentNonetAssertionErrortstructtunpack(Rt check_counttcount((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pytunpack_uint32_list#scCst|dr!|jd}nd}d}xIt||krx|tj|tjd|j7}|d7}q0W|| S(sr generate random reference bytes from specified seed. used to generate some predictable test vectors. tencodetasciitisdjdd}gtd|dD]}jd d ^qL}|j||j|t||dkr|`gtd|dD]}jd d ^q}|j||j|t|nd S( s/helper to check bmix() output against referenceR(R'ii R)iiiiNII(R,trangetbmixR-tlist(R(R1R2R3t_ttarget(R&R0R/(sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyt check_bmixis73 3s f7 ce 0b 65 3d 2d 72 a4 10 8c f5 ab e9 12 ff dd 77 76 16 db bb 27 a7 0e 82 04 f3 ae 2d 0f 6f ad 89 f6 8f 48 11 d1 e8 7b cc 3b d7 40 0a 9f fd 29 09 4f 01 84 63 95 74 f3 9a e5 a1 31 52 17 bc d7 89 49 91 44 72 13 bb 22 6c 25 b5 4d a8 63 70 fb cd 98 43 80 37 46 66 bb 8f fc b5 bf 40 c2 54 b0 67 d2 7c 51 ce 4a d5 fe d8 29 c9 0b 50 5a 57 1b 7f 4d 1c ad 6a 52 3c da 77 0e 67 bc ea af 7e 89 i s a4 1f 85 9c 66 08 cc 99 3b 81 ca cb 02 0c ef 05 04 4b 21 81 a2 fd 33 7d fd 7b 1c 63 96 68 2f 29 b4 39 31 68 e3 c9 e6 bc fe 6b c5 b7 a0 6d 96 ba e4 24 cc 10 2c 91 74 5c 24 ad 67 3d c7 61 8f 81 20 ed c9 75 32 38 81 a8 05 40 f6 4c 16 2d cd 3c 21 07 7c fe 5f 8d 5f e2 b1 a4 16 8f 95 36 78 b7 7d 3b 3d 80 3b 60 e4 ab 92 09 96 e5 9b 4d 53 b6 5d 2a 22 58 77 d5 ed f5 84 2c b9 f1 4e ef e4 25 is bmix with r=2isx ba240854954f4585f3d0573321f10beee96f12acdc1feb498131e40512934fd7 43e8139c17d0743c89d09ac8c3582c273c60ab85db63e410d049a9e17a42c6a1 6c7831b11bf370266afdaff997ae1286920dea1dedf0f4a1795ba710ba9017f1 a374400766f13ebd8969362de2d153965e9941bdde0768fa5b53e8522f116ce0 d14774afb88f46cd919cba4bc64af7fca0ecb8732d1fc2191e0d7d1b6475cb2e e3db789ee478d056c4eb6c6e28b99043602dbb8dfb60c6e048bf90719da8d57d 3c42250e40ab79a1ada6aae9299b9790f767f54f388d024a1465b30cbbe9eb89 002d4f5c215c4259fac4d083bac5fb0b47463747d568f40bb7fa87c42f0a1dc1 is bmix with r=3s 11ddd8cf60c61f59a6e5b128239bdc77b464101312c88bd1ccf6be6e75461b29 7370d4770c904d0b09c402573cf409bf2db47b91ba87d5a3de469df8fb7a003c 95a66af96dbdd88beddc8df51a2f72a6f588d67e7926e9c2b676c875da13161e b6262adac39e6b3003e9a6fbc8c1a6ecf1e227c03bc0af3e5f8736c339b14f84 c7ae5b89f5e16d0faf8983551165f4bb712d97e4f81426e6b78eb63892d3ff54 80bf406c98e479496d0f76d23d728e67d2a3d2cdbc4a932be6db36dc37c60209 a5ca76ca2d2979f995f73fe8182eefa1ce0ba0d4fc27d5b827cb8e67edd6552f 00a5b3ab6b371bd985a158e728011314eb77f32ade619b3162d7b5078a19886c 06f12bc8ae8afa46489e5b0239954d5216967c928982984101e4a88bae1f60ae 3f8a456e169a8a1c7450e7955b8a13a202382ae19d41ce8ef8b6a15eeef569a7 20f54c48e44cb5543dda032c1a50d5ddf2919030624978704eb8db0290052a1f 5d88989b0ef931b6befcc09e9d5162320e71e80b89862de7e2f0b6c67229b93f is bmix with r=4s 803fcf7362702f30ef43250f20bc6b1b8925bf5c4a0f5a14bbfd90edce545997 3047bd81655f72588ca93f5c2f4128adaea805e0705a35e14417101fdb1c498c 33bec6f4e5950d66098da8469f3fe633f9a17617c0ea21275185697c0e4608f7 e6b38b7ec71704a810424637e2c296ca30d9cbf8172a71a266e0393deccf98eb abc430d5f144eb0805308c38522f2973b7b6a48498851e4c762874497da76b88 b769b471fbfc144c0e8e859b2b3f5a11f51604d268c8fd28db55dff79832741a 1ac0dfdaff10f0ada0d93d3b1f13062e4107c640c51df05f4110bdda15f51b53 3a75bfe56489a6d8463440c78fb8c0794135e38591bdc5fa6cec96a124178a4a d1a976e985bfe13d2b4af51bd0fc36dd4cfc3af08efe033b2323a235205dc43d e57778a492153f9527338b3f6f5493a03d8015cd69737ee5096ad4cbe660b10f b75b1595ddc96e3748f5c9f61fba1ef1f0c51b6ceef8bbfcc34b46088652e6f7 edab61521cbad6e69b77be30c9c97ea04a4af359dafc205c7878cc9a6c5d122f 8d77f3cbe65ab14c3c491ef94ecb3f5d2c2dd13027ea4c3606262bb3c9ce46e7 dc424729dc75f6e8f06096c0ad8ad4d549c42f0cad9b33cb95d10fb3cadba27c 5f4bf0c1ac677c23ba23b64f56afc3546e62d96f96b58d7afc5029f8168cbab4 533fd29fc83c8d2a32b81923992e4938281334e0c3694f0ee56f8ff7df7dc4ae N(R*R&R+RR R%(R/R:R1R2R(((R&R0R/sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyt test_bmixas,     cCsddlm}ttd}ttd}|j|||ttd}ttd}|j|||dS(s salsa20()i(tsalsa20s 7e 87 9a 21 4f 3e c9 86 7c a9 40 e6 41 71 8f 26 ba ee 55 5b 8c 61 c1 b5 0d f8 46 11 6d cd 3b 1d ee 24 f3 19 df 9b 3d 85 14 12 1e 4b 5a c5 aa 32 76 02 1d 29 09 c7 48 29 ed eb c6 8d b8 b8 c2 5e s a4 1f 85 9c 66 08 cc 99 3b 81 ca cb 02 0c ef 05 04 4b 21 81 a2 fd 33 7d fd 7b 1c 63 96 68 2f 29 b4 39 31 68 e3 c9 e6 bc fe 6b c5 b7 a0 6d 96 ba e4 24 cc 10 2c 91 74 5c 24 ad 67 3d c7 61 8f 81 is f518dd4fb98883e0a87954c05cab867083bb8808552810752285a05822f56c16 9d4a2a0fd2142523d758c60b36411b682d53860514b871d27659042a5afa475d N(R*R<RR R-R7R5(R/R<R1R2((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyt test_salsas    (t__name__t __module__tdescriptionPrefixR4R;R=(((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyR :s $ t_CommonScryptTestc BseZdZedZdZdZddddddedfdd d d dded fd ddd ddedfd ddd ddedfgZ dZ dZ dZ dZ dZdZdZdZdZdZRS(s_ base class for testing various scrypt backends against same set of reference vectors. cCs d|jS(Ns*passlib.utils.scrypt.scrypt() <%s backend>(tbackend(tcls((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyR@0scCs6|jsttj|jtt|jdS(N(RBRt scrypt_modt _set_backendtsuperRAtsetUp(R/((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyRG8sRiii@s 77 d6 57 62 38 65 7b 20 3b 19 ca 42 c1 8a 04 97 f1 6b 48 44 e3 07 4a e8 df df fa 3f ed e2 14 42 fc d0 06 9d ed 09 48 f8 32 6a 75 3a 0f c8 1f 17 e8 d3 e0 fb 2e 0d 36 28 cf 35 e2 0c 38 d1 89 06 tpasswordtNaCliis fd ba be 1c 9d 34 72 00 78 56 e7 19 0d 01 e9 fe 7c 6a d7 cb c8 23 78 30 e7 73 76 63 4b 37 31 62 2e af 30 d9 2e 22 a3 88 6f f1 09 27 9d 98 30 da c7 27 af b9 4a 83 ee 6d 83 60 cb df a2 cc 06 40 t pleaseletmeintSodiumChloridei@s 70 23 bd cb 3a fd 73 48 46 1c 06 cd 81 fd 38 eb fd a8 fb ba 90 4f 8e 3e a9 b5 43 f6 54 5d a1 f2 d5 43 29 55 61 3f 0f cf 62 d4 97 05 24 2a 9a f9 e6 1e 85 dc 0d 65 1e 40 df cf 01 7b 45 57 58 87 is 21 01 cb 9b 6a 51 1a ae ad db be 09 cf 70 f8 81 ec 56 8d 57 4a 2f fd 4d ab e5 ee 98 20 ad aa 47 8e 56 fd 8f 4b a5 d0 9f fa 1c 6d 92 7c 40 f4 c3 37 30 40 49 e8 a9 52 fb cb f4 5c 6f a7 7a 41 a4 c Csx|jD]\}}}}}}}|dkrFtddrFq n|dkrg|jdkrgq ntjd||||||jtj|||||||q WdS(sreference vectorsitmaxtdefaulti@tbuiltins-scrypt reference vector: %r %r n=%r r=%r p=%rN(treference_vectorsR RBtlogtdebugR-RDR (R/tsecrettsaltR'R(R)tkeylentresult((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyttest_reference_vectorsms%cCs|jr"|jd|jn|j|_|j}tj}tdtjD}tj||j|j|s|jdnt j dddt j xht dD]Z}t||jdd }t||jdd }d |jd d>}|jd d }|jd d } |jd d } d} t} x|D]} tj| |jtj| | jtjttj||||| | }|jt|d | | dk rU|j|| dd| |||||| | gfqUqUWqWdS(s compare output to other backendss!already run under %r backend testcss$|]}tj|r|VqdS(N(RDt _has_backend(t.0tname((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pys ssno other backends foundRs (?i)using builtin scrypt backendtcategoryi ii@iiiitmsgs$%r output differs from others %r: %rN(t_already_tested_otherstskipTestRBR+RDtsettbackend_valuesREtdiscardtwarningstfilterwarningsRtPasslibSecurityWarningR5RR,Rt assertNotInt_scrypttaddRR R-R(R/R0torigt availableR8RRRSR'R(R)tkstprevioustbackendsRYRU((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyttest_other_backendss>         $ c Csdt_dt_|jttjddddddtj|j|jtj|jtjdddddd|jt tjd|jtj|jdS(sbackend managementtsiitxxxN( RRDRBRet assertRaisest TypeErrorR RER-t ValueError(R/((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyt test_backends  %cCsd}td}|j||dd}|j||dd}|j||d|j|dd|jt|d |jt|d d S( s'secret' parametercSs"ttj|dddddS(NRSii(RRDR (RR((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyt run_scryptss abc\u00defgt 05717106997bfe0da42cf4779a2f8bd8sabcÞfgsabcfgt 770825d10eeaaeaf98e8a3c40f9f441dRt ca1399e5fae5d3b9578dcd2b1faff6e2iN(RR-RoRpR(R/RstTEXTt TEXT_UTF8t TEXT_LATIN1((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyttest_secret_params  cCsd}td}|j||dd}|j||dd}|j||d|jt|d|jt|ddS( s'salt' parametercSs"ttjd|ddddS(NRRii(RRDR (RS((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyRsss abc\u00defgt a748ec0f4613929e9e5f03d1ab741d88sabcÞfgsabcfgt 91d056fb76fb6e9a7d1cdfffc0a16cd1iN(RR-RoRpR(R/RsRwRxRy((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyttest_salt_params  cCsd}|jt|d|jt|d|jt|d|j|dd|jt|d|jt|d|j|d d d S( s'n' (rounds) parametercSs"ttjdd|dddS(NRRRSii(RRDR (R'((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyRssiiiit dacf2bca255e2870e6636fa8c8957a66iiit 0272b8fc72bc54b1159340ed99425233N(RoRqR-(R/Rs((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyt test_n_params cCsddd}|jt|d|jt|d|j|dd|j|dd|j|dd |jt|d d d|jt|ddd dd S(s'r' (block size) parametericSs"ttjdd|||dS(NRRRSi(RRDR (R(R'R)((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyRssiiit 3d630447d9f065363b8a79b0b3670251R~it 114f05e985a903c27237b5578e763736iR)Ni@i@(RoRqR-(R/Rs((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyt test_r_paramscCsddd}|jt|d|jt|d|j|dd|j|dd|j|dd |jt|d d d|jt|ddd dd S(s'p' (parallelism) parametericSs"ttjdd|||dS(NRRRSi(RRDR (R)R'R(((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyRssiiit f2960ea8b7d48231fcec1b89b784a6faR~it 848a0eeb2b3543e7f543844d6ca79782iR(Ni@i@(RoRqR-(R/Rs((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyt test_p_param scCs|j}d}|jt|d|jt|d|j|dd|jdd }|jt||d||jt|dd S(s'keylen' parametercSs"ttjddddd|S(NRRRSi(RRDR (RT((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyRs siiitdai ii NiIIII(R+RoRqR-R,R(R/R0Rstksize((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyttest_keylen_params   N(R>R?t__doc__RR@RRBRGR RORVR\RlRrRzR}RRRR(((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyRA(s,      .      tminRMsskipped under current test modecBs eZdZdZdZRS(RNcCs0tt|jtjdddtjdS(NRs (?i)using builtin scrypt backendRZ(RFRRGRaRbRRc(R/((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyRG9scCs8tr|jdn|jtjtjddS(s%backend management -- missing backends'scrypt' backend is presentR N(t_can_import_scryptR]RoRtMissingBackendErrorRDRE(R/((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyttest_missing_backend>s (R>R?RBRGR(((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyR5s cCsCyddl}Wn,tk r>}dt|kr8tSnXtS(s%check if scrypt package is importableiNR (R t ImportErrortstrtFalsetTrue(R terr((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyRDss'scrypt' package not foundtScryptPackageTestcBseZdZdZRS(R cCs$tjd|jtjddS(s%backend management -- default backendRMR N(RDRER-RB(R/((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyttest_default_backendRs (R>R?RBR(((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyRNs('RtbinasciiRRtloggingt getLoggerR>RPRRaRbtpasslibRt passlib.utilsRtpasslib.utils.compatRRRtpasslib.utils.decorRtpasslib.tests.utilsRR R R tpasslib.cryptoR RDt__all__RRRR%R RARRR(((sD/usr/lib/python2.7/site-packages/passlib/tests/test_crypto_scrypt.pyts6    "