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

📄 validat2_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++: validat2.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>validat2.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// validat2.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 <a name="l00005"></a>00005 <span class="preprocessor">#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1</span><a name="l00006"></a>00006 <span class="preprocessor"></span><span class="preprocessor">#include "blumshub.h"</span><a name="l00007"></a>00007 <span class="preprocessor">#include "<a class="code" href="rsa_8h.html" title="This file contains classes that implement the RSA ciphers and signature schemes as...">rsa.h</a>"</span><a name="l00008"></a>00008 <span class="preprocessor">#include "md2.h"</span><a name="l00009"></a>00009 <span class="preprocessor">#include "elgamal.h"</span><a name="l00010"></a>00010 <span class="preprocessor">#include "nr.h"</span><a name="l00011"></a>00011 <span class="preprocessor">#include "<a class="code" href="dsa_8h.html">dsa.h</a>"</span><a name="l00012"></a>00012 <span class="preprocessor">#include "<a class="code" href="dh_8h.html">dh.h</a>"</span><a name="l00013"></a>00013 <span class="preprocessor">#include "<a class="code" href="mqv_8h.html">mqv.h</a>"</span><a name="l00014"></a>00014 <span class="preprocessor">#include "<a class="code" href="luc_8h.html">luc.h</a>"</span><a name="l00015"></a>00015 <span class="preprocessor">#include "<a class="code" href="xtrcrypt_8h.html" title=""The XTR public key system" by Arjen K.">xtrcrypt.h</a>"</span><a name="l00016"></a>00016 <span class="preprocessor">#include "<a class="code" href="rabin_8h.html">rabin.h</a>"</span><a name="l00017"></a>00017 <span class="preprocessor">#include "<a class="code" href="rw_8h.html" title="This file contains classes that implement the Rabin-Williams signature schemes as...">rw.h</a>"</span><a name="l00018"></a>00018 <span class="preprocessor">#include "<a class="code" href="eccrypto_8h.html">eccrypto.h</a>"</span><a name="l00019"></a>00019 <span class="preprocessor">#include "ecp.h"</span><a name="l00020"></a>00020 <span class="preprocessor">#include "ec2n.h"</span><a name="l00021"></a>00021 <span class="preprocessor">#include "asn.h"</span><a name="l00022"></a>00022 <span class="preprocessor">#include "rng.h"</span><a name="l00023"></a>00023 <span class="preprocessor">#include "files.h"</span><a name="l00024"></a>00024 <span class="preprocessor">#include "hex.h"</span><a name="l00025"></a>00025 <span class="preprocessor">#include "oids.h"</span><a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="esign_8h.html" title="This file contains classes that implement the ESIGN signature schemes as defined...">esign.h</a>"</span><a name="l00027"></a>00027 <span class="preprocessor">#include "osrng.h"</span><a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="preprocessor">#include &lt;iostream&gt;</span><a name="l00030"></a>00030 <span class="preprocessor">#include &lt;iomanip&gt;</span><a name="l00031"></a>00031 <a name="l00032"></a>00032 <span class="preprocessor">#include "validate.h"</span><a name="l00033"></a>00033 <a name="l00034"></a>00034 USING_NAMESPACE(CryptoPP)<a name="l00035"></a>00035 USING_NAMESPACE(std)<a name="l00036"></a>00036 <a name="l00037"></a><a class="code" href="class_fixed_r_n_g.html">00037</a> class <a class="code" href="class_fixed_r_n_g.html">FixedRNG</a> : public <a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a><a name="l00038"></a>00038 {<a name="l00039"></a>00039 <span class="keyword">public</span>:<a name="l00040"></a><a class="code" href="class_fixed_r_n_g.html#5189d8e0044f74c44ab433eb69a9b95d">00040</a>         <a class="code" href="class_fixed_r_n_g.html">FixedRNG</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;source) : m_source(source) {}<a name="l00041"></a>00041 <a name="l00042"></a><a class="code" href="class_fixed_r_n_g.html#93c800795dea0f52681dc6d4d7f254eb">00042</a>         <span class="keywordtype">void</span> GenerateBlock(byte *output, <span class="keywordtype">size_t</span> size)<a name="l00043"></a>00043         {<a name="l00044"></a>00044                 m_source.Get(output, size);<a name="l00045"></a>00045         }<a name="l00046"></a>00046 <a name="l00047"></a>00047 <span class="keyword">private</span>:<a name="l00048"></a>00048         <a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;m_source;<a name="l00049"></a>00049 };<a name="l00050"></a>00050 <a name="l00051"></a>00051 <span class="keywordtype">bool</span> ValidateBBS()<a name="l00052"></a>00052 {<a name="l00053"></a>00053         cout &lt;&lt; <span class="stringliteral">"\nBlumBlumShub validation suite running...\n\n"</span>;<a name="l00054"></a>00054 <a name="l00055"></a>00055         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> p(<span class="stringliteral">"212004934506826557583707108431463840565872545889679278744389317666981496005411448865750399674653351"</span>);<a name="l00056"></a>00056         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> q(<span class="stringliteral">"100677295735404212434355574418077394581488455772477016953458064183204108039226017738610663984508231"</span>);<a name="l00057"></a>00057         <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> seed(<span class="stringliteral">"63239752671357255800299643604761065219897634268887145610573595874544114193025997412441121667211431"</span>);<a name="l00058"></a>00058         <a class="code" href="class_blum_blum_shub.html" title="BlumBlumShub with factorization of the modulus.">BlumBlumShub</a> bbs(p, q, seed);<a name="l00059"></a>00059         <span class="keywordtype">bool</span> pass = <span class="keyword">true</span>, fail;<a name="l00060"></a>00060         <span class="keywordtype">int</span> j;<a name="l00061"></a>00061 <a name="l00062"></a>00062         <span class="keyword">const</span> byte output1[] = {<a name="l00063"></a>00063                 0x49,0xEA,0x2C,0xFD,0xB0,0x10,0x64,0xA0,0xBB,0xB9,<a name="l00064"></a>00064                 0x2A,0xF1,0x01,0xDA,0xC1,0x8A,0x94,0xF7,0xB7,0xCE};<a name="l00065"></a>00065         <span class="keyword">const</span> byte output2[] = {<a name="l00066"></a>00066                 0x74,0x45,0x48,0xAE,0xAC,0xB7,0x0E,0xDF,0xAF,0xD7,<a name="l00067"></a>00067                 0xD5,0x0E,0x8E,0x29,0x83,0x75,0x6B,0x27,0x46,0xA1};<a name="l00068"></a>00068 <a name="l00069"></a>00069         byte buf[20];<a name="l00070"></a>00070 <a name="l00071"></a>00071         bbs.GenerateBlock(buf, 20);<a name="l00072"></a>00072         fail = memcmp(output1, buf, 20) != 0;<a name="l00073"></a>00073         pass = pass &amp;&amp; !fail;<a name="l00074"></a>00074 <a name="l00075"></a>00075         cout &lt;&lt; (fail ? <span class="stringliteral">"FAILED    "</span> : <span class="stringliteral">"passed    "</span>);<a name="l00076"></a>00076         <span class="keywordflow">for</span> (j=0;j&lt;20;j++)<a name="l00077"></a>00077                 cout &lt;&lt; setw(2) &lt;&lt; setfill(<span class="charliteral">'0'</span>) &lt;&lt; hex &lt;&lt; (<span class="keywordtype">int</span>)buf[j];<a name="l00078"></a>00078         cout &lt;&lt; endl;<a name="l00079"></a>00079 <a name="l00080"></a>00080         bbs.Seek(10);<a name="l00081"></a>00081         bbs.GenerateBlock(buf, 10);<a name="l00082"></a>00082         fail = memcmp(output1+10, buf, 10) != 0;<a name="l00083"></a>00083         pass = pass &amp;&amp; !fail;<a name="l00084"></a>00084 <a name="l00085"></a>00085         cout &lt;&lt; (fail ? <span class="stringliteral">"FAILED    "</span> : <span class="stringliteral">"passed    "</span>);<a name="l00086"></a>00086         <span class="keywordflow">for</span> (j=0;j&lt;10;j++)<a name="l00087"></a>00087                 cout &lt;&lt; setw(2) &lt;&lt; setfill(<span class="charliteral">'0'</span>) &lt;&lt; hex &lt;&lt; (<span class="keywordtype">int</span>)buf[j];<a name="l00088"></a>00088         cout &lt;&lt; endl;<a name="l00089"></a>00089 <a name="l00090"></a>00090         bbs.Seek(1234567);<a name="l00091"></a>00091         bbs.GenerateBlock(buf, 20);

⌨️ 快捷键说明

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