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

📄 validat3_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>Crypto++: validat3.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.2 --><div class="tabs">  <ul>    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>    <li><a href="namespaces.html"><span>Namespaces</span></a></li>    <li><a href="classes.html"><span>Classes</span></a></li>    <li class="current"><a href="files.html"><span>Files</span></a></li>  </ul></div><div class="tabs">  <ul>    <li><a href="files.html"><span>File&nbsp;List</span></a></li>    <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>  </ul></div><h1>validat3.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// validat3.cpp - written and placed in the public domain by Wei Dai</span><a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="preprocessor">#include "pch.h"</span><a name="l00004"></a>00004 <span class="preprocessor">#include "validate.h"</span><a name="l00005"></a>00005 <a name="l00006"></a>00006 <span class="preprocessor">#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1</span><a name="l00007"></a>00007 <span class="preprocessor"></span><span class="preprocessor">#include "smartptr.h"</span><a name="l00008"></a>00008 <span class="preprocessor">#include "crc.h"</span><a name="l00009"></a>00009 <span class="preprocessor">#include "adler32.h"</span><a name="l00010"></a>00010 <span class="preprocessor">#include "md2.h"</span><a name="l00011"></a>00011 <span class="preprocessor">#include "md4.h"</span><a name="l00012"></a>00012 <span class="preprocessor">#include "md5.h"</span><a name="l00013"></a>00013 <span class="preprocessor">#include "sha.h"</span><a name="l00014"></a>00014 <span class="preprocessor">#include "tiger.h"</span><a name="l00015"></a>00015 <span class="preprocessor">#include "ripemd.h"</span><a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="preprocessor">#include "hmac.h"</span><a name="l00018"></a>00018 <span class="preprocessor">#include "ttmac.h"</span><a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="preprocessor">#include "<a class="code" href="integer_8h.html">integer.h</a>"</span><a name="l00021"></a>00021 <span class="preprocessor">#include "pwdbased.h"</span><a name="l00022"></a>00022 <span class="preprocessor">#include "filters.h"</span><a name="l00023"></a>00023 <span class="preprocessor">#include "hex.h"</span><a name="l00024"></a>00024 <span class="preprocessor">#include "files.h"</span><a name="l00025"></a>00025 <a name="l00026"></a>00026 <span class="preprocessor">#include &lt;iostream&gt;</span><a name="l00027"></a>00027 <span class="preprocessor">#include &lt;iomanip&gt;</span><a name="l00028"></a>00028 <a name="l00029"></a>00029 USING_NAMESPACE(CryptoPP)<a name="l00030"></a>00030 USING_NAMESPACE(std)<a name="l00031"></a>00031 <a name="l00032"></a><a class="code" href="struct_hash_test_tuple.html">00032</a> struct <a class="code" href="struct_hash_test_tuple.html">HashTestTuple</a><a name="l00033"></a>00033 {<a name="l00034"></a><a class="code" href="struct_hash_test_tuple.html#7d6758dc69a19fd83ba1226d50b830d0">00034</a>         HashTestTuple(<span class="keyword">const</span> <span class="keywordtype">char</span> *input, <span class="keyword">const</span> <span class="keywordtype">char</span> *output, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> repeatTimes=1)<a name="l00035"></a>00035                 : input((byte *)input), output((byte *)output), inputLen(strlen(input)), repeatTimes(repeatTimes) {}<a name="l00036"></a>00036         <a name="l00037"></a><a class="code" href="struct_hash_test_tuple.html#fa515f851fca4eda7e680a978af2e562">00037</a>         HashTestTuple(<span class="keyword">const</span> <span class="keywordtype">char</span> *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> inputLen, <span class="keyword">const</span> <span class="keywordtype">char</span> *output, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> repeatTimes)<a name="l00038"></a>00038                 : input((byte *)input), output((byte *)output), inputLen(inputLen), repeatTimes(repeatTimes) {}<a name="l00039"></a>00039 <a name="l00040"></a><a class="code" href="struct_hash_test_tuple.html#123c8dac86390344a56fb2a7ad8a4e06">00040</a>         <span class="keyword">const</span> byte *input, *output;<a name="l00041"></a><a class="code" href="struct_hash_test_tuple.html#8be9305641d4be19bec31c8c3e33065d">00041</a>         <span class="keywordtype">size_t</span> inputLen;<a name="l00042"></a><a class="code" href="struct_hash_test_tuple.html#8cbb11493f22b3d626945f587b0a649a">00042</a>         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> repeatTimes;<a name="l00043"></a>00043 };<a name="l00044"></a>00044 <a name="l00045"></a>00045 <span class="keywordtype">bool</span> HashModuleTest(<a class="code" href="class_hash_transformation.html" title="interface for hash functions and data processing part of MACs">HashTransformation</a> &amp;md, <span class="keyword">const</span> <a class="code" href="struct_hash_test_tuple.html">HashTestTuple</a> *testSet, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> testSetSize)<a name="l00046"></a>00046 {<a name="l00047"></a>00047         <span class="keywordtype">bool</span> pass=<span class="keyword">true</span>, fail;<a name="l00048"></a>00048         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> digest(md.<a class="code" href="class_hash_transformation.html#41faf8b1293a6c72390cb0c8bd668097" title="size of the hash returned by Final()">DigestSize</a>());<a name="l00049"></a>00049 <a name="l00050"></a>00050         <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;testSetSize; i++)<a name="l00051"></a>00051         {<a name="l00052"></a>00052                 <span class="keywordtype">unsigned</span> j;<a name="l00053"></a>00053 <a name="l00054"></a>00054                 <span class="keywordflow">for</span> (j=0; j&lt;testSet[i].<a class="code" href="struct_hash_test_tuple.html#8cbb11493f22b3d626945f587b0a649a">repeatTimes</a>; j++)<a name="l00055"></a>00055                         md.<a class="code" href="class_hash_transformation.html#afabefaf445b65d3ba0d8e1c0294afe5" title="process more input">Update</a>(testSet[i].<a class="code" href="struct_hash_test_tuple.html#5a32fe3ce744ed09b7dd9db3dd374754">input</a>, testSet[i].<a class="code" href="struct_hash_test_tuple.html#8be9305641d4be19bec31c8c3e33065d">inputLen</a>);<a name="l00056"></a>00056                 md.<a class="code" href="class_hash_transformation.html#a0b8c7a110d8968268fd02ec32b9a8e8" title="compute hash for current message, then restart for a new message">Final</a>(digest);<a name="l00057"></a>00057                 fail = memcmp(digest, testSet[i].output, md.<a class="code" href="class_hash_transformation.html#41faf8b1293a6c72390cb0c8bd668097" title="size of the hash returned by Final()">DigestSize</a>()) != 0;<a name="l00058"></a>00058                 pass = pass &amp;&amp; !fail;<a name="l00059"></a>00059 <a name="l00060"></a>00060                 cout &lt;&lt; (fail ? <span class="stringliteral">"FAILED   "</span> : <span class="stringliteral">"passed   "</span>);<a name="l00061"></a>00061                 <span class="keywordflow">for</span> (j=0; j&lt;md.<a class="code" href="class_hash_transformation.html#41faf8b1293a6c72390cb0c8bd668097" title="size of the hash returned by Final()">DigestSize</a>(); j++)<a name="l00062"></a>00062                         cout &lt;&lt; setw(2) &lt;&lt; setfill(<span class="charliteral">'0'</span>) &lt;&lt; hex &lt;&lt; (int)digest[j];<a name="l00063"></a>00063                 cout &lt;&lt; <span class="stringliteral">"   \""</span> &lt;&lt; (<span class="keywordtype">char</span> *)testSet[i].input &lt;&lt; <span class="charliteral">'\"'</span>;<a name="l00064"></a>00064                 <span class="keywordflow">if</span> (testSet[i].repeatTimes != 1)<a name="l00065"></a>00065                         cout &lt;&lt; <span class="stringliteral">" repeated "</span> &lt;&lt; dec &lt;&lt; testSet[i].<a class="code" href="struct_hash_test_tuple.html#8cbb11493f22b3d626945f587b0a649a">repeatTimes</a> &lt;&lt; <span class="stringliteral">" times"</span>;<a name="l00066"></a>00066                 cout  &lt;&lt; endl;<a name="l00067"></a>00067         }<a name="l00068"></a>00068 <a name="l00069"></a>00069         <span class="keywordflow">return</span> pass;<a name="l00070"></a>00070 }<a name="l00071"></a>00071 <a name="l00072"></a>00072 <span class="keywordtype">bool</span> ValidateCRC32()<a name="l00073"></a>00073 {<a name="l00074"></a>00074         <a class="code" href="struct_hash_test_tuple.html">HashTestTuple</a> testSet[] = <a name="l00075"></a>00075         {<a name="l00076"></a>00076                 <a class="code" href="struct_hash_test_tuple.html">HashTestTuple</a>(<span class="stringliteral">""</span>, <span class="stringliteral">"\x00\x00\x00\x00"</span>),<a name="l00077"></a>00077                 <a class="code" href="struct_hash_test_tuple.html">HashTestTuple</a>(<span class="stringliteral">"a"</span>, <span class="stringliteral">"\x43\xbe\xb7\xe8"</span>),<a name="l00078"></a>00078                 <a class="code" href="struct_hash_test_tuple.html">HashTestTuple</a>(<span class="stringliteral">"abc"</span>, <span class="stringliteral">"\xc2\x41\x24\x35"</span>),<a name="l00079"></a>00079                 <a class="code" href="struct_hash_test_tuple.html">HashTestTuple</a>(<span class="stringliteral">"message digest"</span>, <span class="stringliteral">"\x7f\x9d\x15\x20"</span>),<a name="l00080"></a>00080                 <a class="code" href="struct_hash_test_tuple.html">HashTestTuple</a>(<span class="stringliteral">"abcdefghijklmnopqrstuvwxyz"</span>, <span class="stringliteral">"\xbd\x50\x27\x4c"</span>),

⌨️ 快捷键说明

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