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

📄 pssr_8h-source.html

📁 Crypto++是一个非常强大的密码学库,主要是功能全
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Crypto++: pssr.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.2 --><div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Compound&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Compound&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div><h1>pssr.h</h1><div class="fragment"><pre>00001 <span class="preprocessor">#ifndef CRYPTOPP_PSSR_H</span>00002 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_PSSR_H</span>00003 <span class="preprocessor"></span>00004 <span class="preprocessor">#include "<a class="code" href="pubkey_8h.html">pubkey.h</a>"</span>00005 <span class="preprocessor">#include &lt;functional&gt;</span>00006 00007 NAMESPACE_BEGIN(CryptoPP)00008 00009 <span class="comment">// TODO: implement standard variant of PSSR</span>00010 <span class="keyword">template</span> &lt;<span class="keyword">class</span> H, <span class="keyword">class</span> MGF=P1363_MGF1&lt;H&gt; &gt;00011 <span class="keyword">class </span>PSSR : <span class="keyword">public</span> <a class="code" href="class_signature_encoding_method_with_recovery.html">SignatureEncodingMethodWithRecovery</a>00012 {00013 <span class="keyword">public</span>:00014         PSSR(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> representativeBitLen);00015         PSSR(<span class="keyword">const</span> byte *representative, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> representativeBitLen);00016         ~PSSR() {}00017         <span class="keywordtype">void</span> Update(<span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length);00018         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> DigestSize()<span class="keyword"> const </span>{<span class="keywordflow">return</span> BitsToBytes(representativeBitLen);}00019         <span class="keywordtype">void</span> Restart() {h.Restart();}00020         <span class="keywordtype">void</span> Encode(<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &amp;rng, byte *representative);00021         <span class="keywordtype">bool</span> Verify(<span class="keyword">const</span> byte *representative);00022         <a class="code" href="struct_decoding_result.html">DecodingResult</a> Decode(byte *message);00023         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> MaximumRecoverableLength()<span class="keyword"> const </span>{<span class="keywordflow">return</span> MaximumRecoverableLength(representativeBitLen);}00024         <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> MaximumRecoverableLength(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> representativeBitLen);00025         <span class="keyword">static</span> <span class="keywordtype">bool</span> AllowLeftoverMessage() {<span class="keywordflow">return</span> <span class="keyword">true</span>;}00026 00027 <span class="keyword">protected</span>:00028         <span class="keyword">static</span> <span class="keywordtype">void</span> EncodeRepresentative(byte *representative, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> representativeBitLen, <span class="keyword">const</span> byte *w, <span class="keyword">const</span> byte *seed, <span class="keyword">const</span> byte *m1, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m1Len);00029         <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> DecodeRepresentative(<span class="keyword">const</span> byte *representative, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> representativeBitLen, byte *w, byte *seed, byte *m1);00030 00031         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> representativeBitLen, m1Len;00032         H h;00033         <a class="code" href="class_sec_block.html">SecByteBlock</a> m1, w, seed;00034 };00035 00036 <span class="keyword">template</span> &lt;<span class="keyword">class</span> H, <span class="keyword">class</span> MGF&gt;00037 PSSR&lt;H,MGF&gt;::PSSR(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> representativeBitLen)00038         : representativeBitLen(representativeBitLen), m1Len(0)00039         , m1(MaximumRecoverableLength()), w(H::DIGESTSIZE), seed(H::DIGESTSIZE)00040 {00041 }00042 00043 <span class="keyword">template</span> &lt;<span class="keyword">class</span> H, <span class="keyword">class</span> MGF&gt;00044 PSSR&lt;H,MGF&gt;::PSSR(<span class="keyword">const</span> byte *representative, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> representativeBitLen)00045         : representativeBitLen(representativeBitLen), m1Len(0)00046         , m1(MaximumRecoverableLength()), w(H::DIGESTSIZE), seed(H::DIGESTSIZE)00047 {00048         m1Len = DecodeRepresentative(representative, representativeBitLen, w, seed, m1);00049         h.Update(m1, m1Len);00050 }00051 00052 <span class="keyword">template</span> &lt;<span class="keyword">class</span> H, <span class="keyword">class</span> MGF&gt;00053 <span class="keywordtype">void</span> PSSR&lt;H,MGF&gt;::Update(<span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00054 {00055         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m1LenInc = STDMIN(length, MaximumRecoverableLength() - m1Len);00056         memcpy(m1+m1Len, input, m1LenInc);00057         m1Len += m1LenInc;00058         h.Update(input, length);00059 }00060 00061 <span class="keyword">template</span> &lt;<span class="keyword">class</span> H, <span class="keyword">class</span> MGF&gt;00062 <span class="keywordtype">void</span> PSSR&lt;H,MGF&gt;::Encode(<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &amp;rng, byte *representative)00063 {00064         rng.<a class="code" href="class_random_number_generator.html#_x917_r_n_ga4">GenerateBlock</a>(seed, seed.size());00065         h.Update(seed, seed.size());00066         h.Final(w);00067         EncodeRepresentative(representative, representativeBitLen, w, seed, m1, m1Len);00068 }00069 00070 <span class="keyword">template</span> &lt;<span class="keyword">class</span> H, <span class="keyword">class</span> MGF&gt;00071 <span class="keywordtype">bool</span> PSSR&lt;H,MGF&gt;::Verify(<span class="keyword">const</span> byte *representative)00072 {00073         <a class="code" href="class_sec_block.html">SecByteBlock</a> m1r(MaximumRecoverableLength()), wr(H::DIGESTSIZE);00074         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m1rLen = DecodeRepresentative(representative, representativeBitLen, wr, seed, m1r);00075         h.Update(seed, seed.size());00076         h.Final(w);00077         <span class="keywordflow">return</span> m1Len==m1rLen &amp;&amp; memcmp(m1, m1r, m1Len)==0 &amp;&amp; w==wr;00078 }00079 00080 <span class="keyword">template</span> &lt;<span class="keyword">class</span> H, <span class="keyword">class</span> MGF&gt;00081 <a class="code" href="struct_decoding_result.html">DecodingResult</a> PSSR&lt;H,MGF&gt;::Decode(byte *message)00082 {00083         <a class="code" href="class_sec_block.html">SecByteBlock</a> wh(H::DIGESTSIZE);00084         h.Update(seed, seed.size());00085         h.Final(wh);00086         <span class="keywordflow">if</span> (wh == w)00087         {00088                 memcpy(message, m1, m1Len);00089                 <span class="keywordflow">return</span> <a class="code" href="struct_decoding_result.html">DecodingResult</a>(m1Len);00090         }00091         <span class="keywordflow">else</span>00092                 <span class="keywordflow">return</span> <a class="code" href="struct_decoding_result.html">DecodingResult</a>();00093 }00094 00095 <span class="keyword">template</span> &lt;<span class="keyword">class</span> H, <span class="keyword">class</span> MGF&gt;00096 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> PSSR&lt;H,MGF&gt;::MaximumRecoverableLength(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> paddedLength)00097 {00098         <span class="keywordflow">return</span> paddedLength/8 &gt; 1+2*H::DIGESTSIZE ? paddedLength/8-1-2*H::DIGESTSIZE : 0;00099 }00100 00101 <span class="keyword">template</span> &lt;<span class="keyword">class</span> H, <span class="keyword">class</span> MGF&gt;00102 <span class="keywordtype">void</span> PSSR&lt;H,MGF&gt;::EncodeRepresentative(byte *pssrBlock, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pssrBlockLen, <span class="keyword">const</span> byte *w, <span class="keyword">const</span> byte *seed, <span class="keyword">const</span> byte *m1, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m1Len)00103 {00104         assert (m1Len &lt;= MaximumRecoverableLength(pssrBlockLen));00105 00106         <span class="comment">// convert from bit length to byte length</span>00107         <span class="keywordflow">if</span> (pssrBlockLen % 8 != 0)00108         {00109                 pssrBlock[0] = 0;00110                 pssrBlock++;00111         }00112         pssrBlockLen /= 8;00113 00114         <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> hLen = H::DIGESTSIZE;00115         <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> wLen = hLen, seedLen = hLen, dbLen = pssrBlockLen-wLen-seedLen;00116         byte *<span class="keyword">const</span> maskedSeed = pssrBlock+wLen;00117         byte *<span class="keyword">const</span> maskedDB = pssrBlock+wLen+seedLen;00118 00119         memcpy(pssrBlock, w, wLen);00120         memcpy(maskedSeed, seed, seedLen);00121         memset(maskedDB, 0, dbLen-m1Len-1);00122         maskedDB[dbLen-m1Len-1] = 0x01;00123         memcpy(maskedDB+dbLen-m1Len, m1, m1Len);00124 00125         MGF::GenerateAndMask(maskedSeed, seedLen+dbLen, w, wLen);00126 }00127 00128 <span class="keyword">template</span> &lt;<span class="keyword">class</span> H, <span class="keyword">class</span> MGF&gt;00129 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> PSSR&lt;H,MGF&gt;::DecodeRepresentative(<span class="keyword">const</span> byte *pssrBlock, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pssrBlockLen, byte *w, byte *seed, byte *m1)00130 {00131         <span class="comment">// convert from bit length to byte length</span>00132         <span class="keywordflow">if</span> (pssrBlockLen % 8 != 0)00133         {00134                 <span class="keywordflow">if</span> (pssrBlock[0] != 0)00135                         <span class="keywordflow">return</span> 0;00136                 pssrBlock++;00137         }00138         pssrBlockLen /= 8;00139 00140         <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> hLen = H::DIGESTSIZE;00141         <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> wLen = hLen, seedLen = hLen, dbLen = pssrBlockLen-wLen-seedLen;00142 00143         <span class="keywordflow">if</span> (pssrBlockLen &lt; 2*hLen+1)00144                 <span class="keywordflow">return</span> 0;00145 00146         memcpy(w, pssrBlock, wLen);00147         <a class="code" href="class_sec_block.html">SecByteBlock</a> t(pssrBlock+wLen, pssrBlockLen-wLen);00148         byte *<span class="keyword">const</span> maskedSeed = t;00149         byte *<span class="keyword">const</span> maskedDB = t+seedLen;00150 00151         MGF::GenerateAndMask(maskedSeed, seedLen+dbLen, w, wLen);00152         memcpy(seed, maskedSeed, seedLen);00153 00154         <span class="comment">// DB = 00 ... || 01 || M</span>00155 00156         byte *M = std::find_if(maskedDB, maskedDB+dbLen, std::bind2nd(std::not_equal_to&lt;byte&gt;(), 0));00157         <span class="keywordflow">if</span> (M!=maskedDB+dbLen &amp;&amp; *M == 0x01)00158         {00159                 M++;00160                 memcpy(m1, M, maskedDB+dbLen-M);00161                 <span class="keywordflow">return</span> maskedDB+dbLen-M;00162         }00163         <span class="keywordflow">else</span>00164                 <span class="keywordflow">return</span> 0;00165 }00166 00167 NAMESPACE_END00168 00169 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:22 2003 for Crypto++ by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.2 </small></address></body></html>

⌨️ 快捷键说明

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