⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validat1_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="l00448"></a><a class="code" href="class_filter_tester.html#0efbbcddb3e7498c43429c8ac4ff9ec5">00448</a>         <span class="keywordtype">void</span> <a class="code" href="class_filter_tester.html#0efbbcddb3e7498c43429c8ac4ff9ec5">PutByte</a>(byte inByte)<a name="l00449"></a>00449         {<a name="l00450"></a>00450                 <span class="keywordflow">if</span> (<a class="code" href="class_filter_tester.html#3e682b1d1263042b724052d22fe7514a">counter</a> &gt;= <a class="code" href="class_filter_tester.html#8d1589ead4c76565940de6dce40eaab8">outputLen</a> || <a class="code" href="class_filter_tester.html#d91cd562a429625366ebb4c7c98310c8">validOutput</a>[<a class="code" href="class_filter_tester.html#3e682b1d1263042b724052d22fe7514a">counter</a>] != inByte)<a name="l00451"></a>00451                 {<a name="l00452"></a>00452                         std::cerr &lt;&lt; <span class="stringliteral">"incorrect output "</span> &lt;&lt; <a class="code" href="class_filter_tester.html#3e682b1d1263042b724052d22fe7514a">counter</a> &lt;&lt; <span class="stringliteral">", "</span> &lt;&lt; (word16)<a class="code" href="class_filter_tester.html#d91cd562a429625366ebb4c7c98310c8">validOutput</a>[<a class="code" href="class_filter_tester.html#3e682b1d1263042b724052d22fe7514a">counter</a>] &lt;&lt; <span class="stringliteral">", "</span> &lt;&lt; (word16)inByte &lt;&lt; <span class="stringliteral">"\n"</span>;<a name="l00453"></a>00453                         <a class="code" href="class_filter_tester.html#5009d4d3daa271c88c150c98c771be57">fail</a> = <span class="keyword">true</span>;<a name="l00454"></a>00454                         assert(<span class="keyword">false</span>);<a name="l00455"></a>00455                 }<a name="l00456"></a>00456                 <a class="code" href="class_filter_tester.html#3e682b1d1263042b724052d22fe7514a">counter</a>++;<a name="l00457"></a>00457         }<a name="l00458"></a><a class="code" href="class_filter_tester.html#5e5686836378a9fdadd9aa51f0405802">00458</a>         <span class="keywordtype">size_t</span> <a class="code" href="class_filter_tester.html#5e5686836378a9fdadd9aa51f0405802" title="input multiple bytes for blocking or non-blocking processing">Put2</a>(<span class="keyword">const</span> byte *inString, <span class="keywordtype">size_t</span> length, <span class="keywordtype">int</span> messageEnd, <span class="keywordtype">bool</span> blocking)<a name="l00459"></a>00459         {<a name="l00460"></a>00460                 <span class="keywordflow">while</span> (length--)<a name="l00461"></a>00461                         <a class="code" href="class_filter_tester.html#0efbbcddb3e7498c43429c8ac4ff9ec5">FilterTester::PutByte</a>(*inString++);<a name="l00462"></a>00462 <a name="l00463"></a>00463                 <span class="keywordflow">if</span> (messageEnd)<a name="l00464"></a>00464                         <span class="keywordflow">if</span> (<a class="code" href="class_filter_tester.html#3e682b1d1263042b724052d22fe7514a">counter</a> != <a class="code" href="class_filter_tester.html#8d1589ead4c76565940de6dce40eaab8">outputLen</a>)<a name="l00465"></a>00465                         {<a name="l00466"></a>00466                                 <a class="code" href="class_filter_tester.html#5009d4d3daa271c88c150c98c771be57">fail</a> = <span class="keyword">true</span>;<a name="l00467"></a>00467                                 assert(<span class="keyword">false</span>);<a name="l00468"></a>00468                         }<a name="l00469"></a>00469 <a name="l00470"></a>00470                 <span class="keywordflow">return</span> 0;<a name="l00471"></a>00471         }<a name="l00472"></a><a class="code" href="class_filter_tester.html#fe1314e659731306f57071b0c884ad9f">00472</a>         <span class="keywordtype">bool</span> <a class="code" href="class_filter_tester.html#fe1314e659731306f57071b0c884ad9f">GetResult</a>()<a name="l00473"></a>00473         {<a name="l00474"></a>00474                 <span class="keywordflow">return</span> !<a class="code" href="class_filter_tester.html#5009d4d3daa271c88c150c98c771be57">fail</a>;<a name="l00475"></a>00475         }<a name="l00476"></a>00476 <a name="l00477"></a><a class="code" href="class_filter_tester.html#d91cd562a429625366ebb4c7c98310c8">00477</a>         <span class="keyword">const</span> byte *<a class="code" href="class_filter_tester.html#d91cd562a429625366ebb4c7c98310c8">validOutput</a>;<a name="l00478"></a><a class="code" href="class_filter_tester.html#8d1589ead4c76565940de6dce40eaab8">00478</a>         <span class="keywordtype">size_t</span> <a class="code" href="class_filter_tester.html#8d1589ead4c76565940de6dce40eaab8">outputLen</a>, <a class="code" href="class_filter_tester.html#3e682b1d1263042b724052d22fe7514a">counter</a>;<a name="l00479"></a><a class="code" href="class_filter_tester.html#5009d4d3daa271c88c150c98c771be57">00479</a>         <span class="keywordtype">bool</span> <a class="code" href="class_filter_tester.html#5009d4d3daa271c88c150c98c771be57">fail</a>;<a name="l00480"></a>00480 };<a name="l00481"></a>00481 <a name="l00482"></a>00482 <span class="keywordtype">bool</span> TestFilter(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;bt, <span class="keyword">const</span> byte *in, <span class="keywordtype">size_t</span> inLen, <span class="keyword">const</span> byte *out, <span class="keywordtype">size_t</span> outLen)<a name="l00483"></a>00483 {<a name="l00484"></a>00484         <a class="code" href="class_filter_tester.html">FilterTester</a> *ft;<a name="l00485"></a>00485         bt.<a class="code" href="class_buffered_transformation.html#9f6cbec970dcb509b23a08fb28b3e055" title="add newAttachment to the end of attachment chain">Attach</a>(ft = <span class="keyword">new</span> <a class="code" href="class_filter_tester.html">FilterTester</a>(out, outLen));<a name="l00486"></a>00486 <a name="l00487"></a>00487         <span class="keywordflow">while</span> (inLen)<a name="l00488"></a>00488         {<a name="l00489"></a>00489                 <span class="keywordtype">size_t</span> randomLen = GlobalRNG().<a class="code" href="class_random_number_generator.html#c06c9f5e66f35d643e4192f231b8a4cd" title="generate a random 32 bit word in the range min to max, inclusive">GenerateWord32</a>(0, (word32)inLen);<a name="l00490"></a>00490                 bt.<a class="code" href="class_buffered_transformation.html#e70658b0d271f8e114ac6c3cc9774ede" title="input a byte for processing">Put</a>(in, randomLen);<a name="l00491"></a>00491                 in += randomLen;<a name="l00492"></a>00492                 inLen -= randomLen;<a name="l00493"></a>00493         }<a name="l00494"></a>00494         bt.<a class="code" href="class_buffered_transformation.html#20ae0ef2e4ff338b43849e541e9b940f">MessageEnd</a>();<a name="l00495"></a>00495         <span class="keywordflow">return</span> ft-&gt;<a class="code" href="class_filter_tester.html#fe1314e659731306f57071b0c884ad9f">GetResult</a>();<a name="l00496"></a>00496 }<a name="l00497"></a>00497 <a name="l00498"></a>00498 <span class="keywordtype">bool</span> ValidateDES()<a name="l00499"></a>00499 {<a name="l00500"></a>00500         cout &lt;&lt; <span class="stringliteral">"\nDES validation suite running...\n\n"</span>;<a name="l00501"></a>00501 <a name="l00502"></a>00502         <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a> valdata(<span class="stringliteral">"descert.dat"</span>, <span class="keyword">true</span>, <span class="keyword">new</span> <a class="code" href="class_hex_decoder.html" title="Decode base 16 data back to bytes.">HexDecoder</a>);<a name="l00503"></a>00503         <span class="keywordtype">bool</span> pass = BlockTransformationTest(<a class="code" href="class_fixed_rounds_cipher_factory.html">FixedRoundsCipherFactory&lt;DESEncryption, DESDecryption&gt;</a>(), valdata);<a name="l00504"></a>00504 <a name="l00505"></a>00505         cout &lt;&lt; <span class="stringliteral">"\nTesting EDE2, EDE3, and XEX3 variants...\n\n"</span>;<a name="l00506"></a>00506 <a name="l00507"></a>00507         <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a> valdata1(<span class="stringliteral">"3desval.dat"</span>, <span class="keyword">true</span>, <span class="keyword">new</span> <a class="code" href="class_hex_decoder.html" title="Decode base 16 data back to bytes.">HexDecoder</a>);<a name="l00508"></a>00508         pass = BlockTransformationTest(<a class="code" href="class_fixed_rounds_cipher_factory.html">FixedRoundsCipherFactory&lt;DES_EDE2_Encryption, DES_EDE2_Decryption&gt;</a>(), valdata1, 1) &amp;&amp; pass;<a name="l00509"></a>00509         pass = BlockTransformationTest(<a class="code" href="class_fixed_rounds_cipher_factory.html">FixedRoundsCipherFactory&lt;DES_EDE3_Encryption, DES_EDE3_Decryption&gt;</a>(), valdata1, 1) &amp;&amp; pass;<a name="l00510"></a>00510         pass = BlockTransformationTest(<a class="code" href="class_fixed_rounds_cipher_factory.html">FixedRoundsCipherFactory&lt;DES_XEX3_Encryption, DES_XEX3_Decryption&gt;</a>(), valdata1, 1) &amp;&amp; pass;<a name="l00511"></a>00511 <a name="l00512"></a>00512         <span class="keywordflow">return</span> pass;<a name="l00513"></a>00513 }<a name="l00514"></a>00514 <a name="l00515"></a>00515 <span class="keywordtype">bool</span> TestModeIV(<a class="code" href="class_symmetric_cipher.html" title="interface for one direction (encryption or decryption) of a stream cipher or cipher...">SymmetricCipher</a> &amp;e, <a class="code" href="class_symmetric_cipher.html" title="interface for one direction (encryption or decryption) of a stream cipher or cipher...">SymmetricCipher</a> &amp;d)<a name="l00516"></a>00516 {<a name="l00517"></a>00517         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> lastIV, iv(e.<a class="code" href="class_simple_keying_interface.html#c6da9a8d3c783014ab54a2a3ee9e676a" title="returns size of IVs used by this object">IVSize</a>());<a name="l00518"></a>00518         <a class="code" href="class_stream_transformation_filter.html" title="Filter Wrapper for StreamTransformation.">StreamTransformationFilter</a> filter(e, <span class="keyword">new</span> <a class="code" href="class_stream_transformation_filter.html" title="Filter Wrapper for StreamTransformation.">StreamTransformationFilter</a>(d));<a name="l00519"></a>00519         byte plaintext[20480];<a name="l00520"></a>00520 <a name="l00521"></a>00521         <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=1; i&lt;<span class="keyword">sizeof</span>(plaintext); i*=2)<a name="l00522"></a>00522         {<a name="l00523"></a>00523                 e.<a class="code" href="class_simple_keying_interface.html#917224bb6df7431d6469e7a10feac5fa" title="get a secure IV for the next message">GetNextIV</a>(GlobalRNG(), iv);<a name="l00524"></a>00524                 <span class="keywordflow">if</span> (iv == lastIV)<a name="l00525"></a>00525                         <span class="keywordflow">return</span> <span class="keyword">false</span>;<a name="l00526"></a>00526                 <span class="keywordflow">else</span><a name="l00527"></a>00527                         lastIV = iv;<a name="l00528"></a>00528 <a name="l00529"></a>00529                 e.<a class="code" href="class_simple_keying_interface.html#8ee3f5f9c00d193bf9d8fd8aa46ccbb2" title="resynchronize with an IV">Resynchronize</a>(iv);<a name="l00530"></a>00530                 d.<a class="code" href="class_simple_keying_interface.html#8ee3f5f9c00d193bf9d8fd8aa46ccbb2" title="resynchronize with an IV">Resynchronize</a>(iv);<a name="l00531"></a>00531 <a name="l00532"></a>00532                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length = STDMAX(GlobalRNG().GenerateWord32(0, i), (word32)e.<a class="code" href="class_stream_transformation.html#0b7c5bc41b9b5f6443ee32d65ebc044c" title="returns the minimum size of the last block, 0 indicating the last block is not special...">MinLastBlockSize</a>());<a name="l00533"></a>00533                 GlobalRNG().<a class="code" href="class_random_number_generator.html#497145546d24e6d4abaf10b7e0f1ba17" title="generate random array of bytes">GenerateBlock</a>(plaintext, length);<a name="l00534"></a>00534 <a name="l00535"></a>00535                 <span class="keywordflow">if</span> (!TestFilter(filter, plaintext, length, plaintext, length))<a name="l00536"></a>00536                         <span class="keywordflow">return</span> <span class="keyword">false</span>;<a name="l00537"></a>00537         }<a name="l00538"></a>00538 <a name="l00539"></a>00539         <span class="keywordflow">return</span> <span class="keyword">true</span>;<a name="l00540"></a>00540 }<a name="l00541"></a>00541 <a name="l00542"></a>00542 <span class="keywordtype">bool</span> ValidateCipherModes()<a name="l00543"></a>00543 {<a name="l00544"></a>00544         cout &lt;&lt; <span class="stringliteral">"\nTesting DES modes...\n\n"</span>;<a name="l00545"></a>00545         <span class="keyword">const</span> byte key[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};<a name="l00546"></a>00546         <span class="keyword">const</span> byte iv[] = {0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};<a name="l00547"></a>00547         <span class="keyword">const</span> byte plain[] = {  <span class="comment">// "Now is the time for all " without tailing 0</span><a name="l00548"></a>00548                 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,<a name="l00549"></a>00549                 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,<a name="l00550"></a>00550                 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20};<a name="l00551"></a>00551         <a class="code" href="class_block_cipher_final.html" title="_">DESEncryption</a> desE(key);<a name="l00552"></a>00552         <a class="code" href="class_block_cipher_final.html" title="_">DESDecryption</a> desD(key);<a name="l00553"></a>00553         <span class="keywordtype">bool</span> pass=<span class="keyword">true</span>, fail;<a name="l00554"></a>00554 <a name="l00555"></a>00555         {<a name="l00556"></a>00556                 <span class="comment">// from FIPS 81</span><a name="l00557"></a>00557                 <span class="keyword">const</span> byte encrypted[] = {<a name="l00558"></a>00558                         0x3f, 0xa4, 0x0e, 0x8a, 0x98, 0x4d, 0x48, 0x15,<a name="l00559"></a>00559                         0x6a, 0x27, 0x17, 0x87, 0xab, 0x88, 0x83, 0xf9,<a name="l00560"></a>00560                         0x89, 0x3d, 0x51, 0xec, 0x4b, 0x56, 0x3b, 0x53};<a name="l00561"></a>00561 <a name="l00562"></a>00562                 <a class="code" href="class_cipher_mode_final_template___external_cipher.html" title="_">ECB_Mode_ExternalCipher::Encryption</a> modeE(desE);<a name="l00563"></a>00563                 fail = !TestFilter(<a

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -