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

📄 ida_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<!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++: ida.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>ida.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// ida.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 "ida.h"</span><a name="l00005"></a>00005 <a name="l00006"></a>00006 <span class="preprocessor">#include "algebra.h"</span><a name="l00007"></a>00007 <span class="preprocessor">#include "gf2_32.h"</span><a name="l00008"></a>00008 <span class="preprocessor">#include "<a class="code" href="polynomi_8h.html">polynomi.h</a>"</span><a name="l00009"></a>00009 <span class="preprocessor">#include &lt;functional&gt;</span><a name="l00010"></a>00010 <a name="l00011"></a>00011 <span class="preprocessor">#include "polynomi.cpp"</span><a name="l00012"></a>00012 <a name="l00013"></a>00013 ANONYMOUS_NAMESPACE_BEGIN<a name="l00014"></a>00014 <span class="keyword">static</span> <span class="keyword">const</span> CryptoPP::GF2_32 field;<a name="l00015"></a>00015 NAMESPACE_END<a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="keyword">using namespace </span>std;<a name="l00018"></a>00018 <a name="l00019"></a>00019 NAMESPACE_BEGIN(CryptoPP)<a name="l00020"></a>00020 <a name="l00021"></a>00021 void <a class="code" href="class_raw_i_d_a.html" title="base class for secret sharing and information dispersal">RawIDA</a>::IsolatedInitialize(const <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &amp;parameters)<a name="l00022"></a>00022 {<a name="l00023"></a>00023         <span class="keywordflow">if</span> (!parameters.GetIntValue(<span class="stringliteral">"RecoveryThreshold"</span>, m_threshold))<a name="l00024"></a>00024                 <span class="keywordflow">throw</span> <a class="code" href="class_invalid_argument.html" title="exception thrown when an invalid argument is detected">InvalidArgument</a>(<span class="stringliteral">"RawIDA: missing RecoveryThreshold argument"</span>);<a name="l00025"></a>00025 <a name="l00026"></a>00026         <span class="keywordflow">if</span> (m_threshold &lt;= 0)<a name="l00027"></a>00027                 <span class="keywordflow">throw</span> <a class="code" href="class_invalid_argument.html" title="exception thrown when an invalid argument is detected">InvalidArgument</a>(<span class="stringliteral">"RawIDA: RecoveryThreshold must be greater than 0"</span>);<a name="l00028"></a>00028 <a name="l00029"></a>00029         m_lastMapPosition = m_inputChannelMap.end();<a name="l00030"></a>00030         m_channelsReady = 0;<a name="l00031"></a>00031         m_channelsFinished = 0;<a name="l00032"></a>00032         m_w.New(m_threshold);<a name="l00033"></a>00033         m_y.New(m_threshold);<a name="l00034"></a>00034         m_inputQueues.reserve(m_threshold);<a name="l00035"></a>00035 <a name="l00036"></a>00036         m_outputChannelIds.clear();<a name="l00037"></a>00037         m_outputChannelIdStrings.clear();<a name="l00038"></a>00038         m_outputQueues.clear();<a name="l00039"></a>00039 <a name="l00040"></a>00040         word32 outputChannelID;<a name="l00041"></a>00041         <span class="keywordflow">if</span> (parameters.GetValue(<span class="stringliteral">"OutputChannelID"</span>, outputChannelID))<a name="l00042"></a>00042                 AddOutputChannel(outputChannelID);<a name="l00043"></a>00043         <span class="keywordflow">else</span><a name="l00044"></a>00044         {<a name="l00045"></a>00045                 <span class="keywordtype">int</span> nShares = parameters.GetIntValueWithDefault(<span class="stringliteral">"NumberOfShares"</span>, m_threshold);<a name="l00046"></a>00046                 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;nShares; i++)<a name="l00047"></a>00047                         AddOutputChannel(i);<a name="l00048"></a>00048         }<a name="l00049"></a>00049 }<a name="l00050"></a>00050 <a name="l00051"></a>00051 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> RawIDA::InsertInputChannel(word32 channelId)<a name="l00052"></a>00052 {<a name="l00053"></a>00053         <span class="keywordflow">if</span> (<a class="code" href="class_raw_i_d_a.html#2a6879cff90946155d76dbe5ed7d3dcb">m_lastMapPosition</a> != <a class="code" href="class_raw_i_d_a.html#0515815d1f31024c7ac45760303bd680">m_inputChannelMap</a>.end())<a name="l00054"></a>00054         {<a name="l00055"></a>00055                 <span class="keywordflow">if</span> (<a class="code" href="class_raw_i_d_a.html#2a6879cff90946155d76dbe5ed7d3dcb">m_lastMapPosition</a>-&gt;first == channelId)<a name="l00056"></a>00056                         <span class="keywordflow">goto</span> skipFind;<a name="l00057"></a>00057                 ++<a class="code" href="class_raw_i_d_a.html#2a6879cff90946155d76dbe5ed7d3dcb">m_lastMapPosition</a>;<a name="l00058"></a>00058                 <span class="keywordflow">if</span> (<a class="code" href="class_raw_i_d_a.html#2a6879cff90946155d76dbe5ed7d3dcb">m_lastMapPosition</a> != <a class="code" href="class_raw_i_d_a.html#0515815d1f31024c7ac45760303bd680">m_inputChannelMap</a>.end() &amp;&amp; <a class="code" href="class_raw_i_d_a.html#2a6879cff90946155d76dbe5ed7d3dcb">m_lastMapPosition</a>-&gt;first == channelId)<a name="l00059"></a>00059                         <span class="keywordflow">goto</span> skipFind;<a name="l00060"></a>00060         }<a name="l00061"></a>00061         <a class="code" href="class_raw_i_d_a.html#2a6879cff90946155d76dbe5ed7d3dcb">m_lastMapPosition</a> = <a class="code" href="class_raw_i_d_a.html#0515815d1f31024c7ac45760303bd680">m_inputChannelMap</a>.find(channelId);<a name="l00062"></a>00062 <a name="l00063"></a>00063 skipFind:<a name="l00064"></a>00064         <span class="keywordflow">if</span> (<a class="code" href="class_raw_i_d_a.html#2a6879cff90946155d76dbe5ed7d3dcb">m_lastMapPosition</a> == <a class="code" href="class_raw_i_d_a.html#0515815d1f31024c7ac45760303bd680">m_inputChannelMap</a>.end())<a name="l00065"></a>00065         {<a name="l00066"></a>00066                 <span class="keywordflow">if</span> (<a class="code" href="class_raw_i_d_a.html#a282d4933e80efe030fb96361e1ff419">m_inputChannelIds</a>.size() == <a class="code" href="class_raw_i_d_a.html#a2983c025ce40ed5b39aa41419cc8cbe">m_threshold</a>)<a name="l00067"></a>00067                         <span class="keywordflow">return</span> <a class="code" href="class_raw_i_d_a.html#a2983c025ce40ed5b39aa41419cc8cbe">m_threshold</a>;<a name="l00068"></a>00068 <a name="l00069"></a>00069                 <a class="code" href="class_raw_i_d_a.html#2a6879cff90946155d76dbe5ed7d3dcb">m_lastMapPosition</a> = <a class="code" href="class_raw_i_d_a.html#0515815d1f31024c7ac45760303bd680">m_inputChannelMap</a>.insert(InputChannelMap::value_type(channelId, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)<a class="code" href="class_raw_i_d_a.html#a282d4933e80efe030fb96361e1ff419">m_inputChannelIds</a>.size())).first;<a name="l00070"></a>00070                 <a class="code" href="class_raw_i_d_a.html#584a7b425d16b083cce42f5af573dc52">m_inputQueues</a>.push_back(<a class="code" href="class_message_queue.html" title="Message Queue.">MessageQueue</a>());<a name="l00071"></a>00071                 <a class="code" href="class_raw_i_d_a.html#a282d4933e80efe030fb96361e1ff419">m_inputChannelIds</a>.push_back(channelId);<a name="l00072"></a>00072 <a name="l00073"></a>00073                 <span class="keywordflow">if</span> (<a class="code" href="class_raw_i_d_a.html#a282d4933e80efe030fb96361e1ff419">m_inputChannelIds</a>.size() == <a class="code" href="class_raw_i_d_a.html#a2983c025ce40ed5b39aa41419cc8cbe">m_threshold</a>)<a name="l00074"></a>00074                         PrepareInterpolation();<a name="l00075"></a>00075         }<a name="l00076"></a>00076         <span class="keywordflow">return</span> <a class="code" href="class_raw_i_d_a.html#2a6879cff90946155d76dbe5ed7d3dcb">m_lastMapPosition</a>-&gt;second;<a name="l00077"></a>00077 }<a name="l00078"></a>00078 <a name="l00079"></a>00079 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> RawIDA::LookupInputChannel(word32 channelId)<span class="keyword"> const</span><a name="l00080"></a>00080 <span class="keyword"></span>{<a name="l00081"></a>00081         map&lt;word32, unsigned int&gt;::const_iterator it = <a class="code" href="class_raw_i_d_a.html#0515815d1f31024c7ac45760303bd680">m_inputChannelMap</a>.find(channelId);<a name="l00082"></a>00082         <span class="keywordflow">if</span> (it == <a class="code" href="class_raw_i_d_a.html#0515815d1f31024c7ac45760303bd680">m_inputChannelMap</a>.end())<a name="l00083"></a>00083                 <span class="keywordflow">return</span> <a class="code" href="class_raw_i_d_a.html#a2983c025ce40ed5b39aa41419cc8cbe">m_threshold</a>;<a name="l00084"></a>00084         <span class="keywordflow">else</span><a name="l00085"></a>00085                 <span class="keywordflow">return</span> it-&gt;second;<a name="l00086"></a>00086 }<a name="l00087"></a>00087 <a name="l00088"></a>00088 <span class="keywordtype">void</span> RawIDA::ChannelData(word32 channelId, <span class="keyword">const</span> byte *inString, <span class="keywordtype">size_t</span> length, <span class="keywordtype">bool</span> messageEnd)<a name="l00089"></a>00089 {<a name="l00090"></a>00090         <span class="keywordtype">int</span> i = InsertInputChannel(channelId);<a name="l00091"></a>00091         <span class="keywordflow">if</span> (i &lt; <a class="code" href="class_raw_i_d_a.html#a2983c025ce40ed5b39aa41419cc8cbe">m_threshold</a>)

⌨️ 快捷键说明

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