📄 pssr_8cpp-source.html
字号:
<a name="l00066"></a>00066 hash.<a class="code" href="class_hash_transformation.html#afabefaf445b65d3ba0d8e1c0294afe5" title="process more input">Update</a>(c, 8);<a name="l00067"></a>00067 hash.<a class="code" href="class_hash_transformation.html#afabefaf445b65d3ba0d8e1c0294afe5" title="process more input">Update</a>(recoverableMessage, recoverableMessageLength);<a name="l00068"></a>00068 hash.<a class="code" href="class_hash_transformation.html#afabefaf445b65d3ba0d8e1c0294afe5" title="process more input">Update</a>(digest, digestSize);<a name="l00069"></a>00069 hash.<a class="code" href="class_hash_transformation.html#afabefaf445b65d3ba0d8e1c0294afe5" title="process more input">Update</a>(salt, saltSize);<a name="l00070"></a>00070 hash.<a class="code" href="class_hash_transformation.html#a0b8c7a110d8968268fd02ec32b9a8e8" title="compute hash for current message, then restart for a new message">Final</a>(h);<a name="l00071"></a>00071 <a name="l00072"></a>00072 <span class="comment">// compute representative</span><a name="l00073"></a>00073 GetMGF().<a class="code" href="class_mask_generating_function.html#e60d7c6be0e656461d5793ec7d4ac504">GenerateAndMask</a>(hash, representative, representativeByteLength - u - digestSize, h, digestSize, <span class="keyword">false</span>);<a name="l00074"></a>00074 byte *xorStart = representative + representativeByteLength - u - digestSize - salt.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>() - recoverableMessageLength - 1;<a name="l00075"></a>00075 xorStart[0] ^= 1;<a name="l00076"></a>00076 xorbuf(xorStart + 1, recoverableMessage, recoverableMessageLength);<a name="l00077"></a>00077 xorbuf(xorStart + 1 + recoverableMessageLength, salt, salt.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>());<a name="l00078"></a>00078 memcpy(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second);<a name="l00079"></a>00079 representative[representativeByteLength - 1] = hashIdentifier.second ? 0xcc : 0xbc;<a name="l00080"></a>00080 <span class="keywordflow">if</span> (representativeBitLength % 8 != 0)<a name="l00081"></a>00081 representative[0] = (byte)Crop(representative[0], representativeBitLength % 8);<a name="l00082"></a>00082 }<a name="l00083"></a>00083 <a name="l00084"></a><a class="code" href="class_p_s_s_r___m_e_m___base.html#14c0f5b00cdb575748040bac100388e0">00084</a> <a class="code" href="struct_decoding_result.html" title="used to return decoding results">DecodingResult</a> <a class="code" href="class_p_s_s_r___m_e_m___base.html#14c0f5b00cdb575748040bac100388e0">PSSR_MEM_Base::RecoverMessageFromRepresentative</a>(<a name="l00085"></a>00085 <a class="code" href="class_hash_transformation.html" title="interface for hash functions and data processing part of MACs">HashTransformation</a> &hash, <a class="code" href="pubkey_8h.html#ef874ed3f2d212ac4629255c8ef86dd0">HashIdentifier</a> hashIdentifier, <span class="keywordtype">bool</span> messageEmpty,<a name="l00086"></a>00086 byte *representative, <span class="keywordtype">size_t</span> representativeBitLength,<a name="l00087"></a>00087 byte *recoverableMessage)<span class="keyword"> const</span><a name="l00088"></a>00088 <span class="keyword"></span>{<a name="l00089"></a>00089 assert(representativeBitLength >= <a class="code" href="class_p_s_s_r___m_e_m___base.html#5528c0fafed27d6d8603c28b13cf2f21">MinRepresentativeBitLength</a>(hashIdentifier.second, hash.<a class="code" href="class_hash_transformation.html#41faf8b1293a6c72390cb0c8bd668097" title="size of the hash returned by Final()">DigestSize</a>()));<a name="l00090"></a>00090 <a name="l00091"></a>00091 <span class="keyword">const</span> <span class="keywordtype">size_t</span> u = hashIdentifier.second + 1;<a name="l00092"></a>00092 <span class="keyword">const</span> <span class="keywordtype">size_t</span> representativeByteLength = BitsToBytes(representativeBitLength);<a name="l00093"></a>00093 <span class="keyword">const</span> <span class="keywordtype">size_t</span> digestSize = hash.<a class="code" href="class_hash_transformation.html#41faf8b1293a6c72390cb0c8bd668097" title="size of the hash returned by Final()">DigestSize</a>();<a name="l00094"></a>00094 <span class="keyword">const</span> <span class="keywordtype">size_t</span> saltSize = SaltLen(digestSize);<a name="l00095"></a>00095 <span class="keyword">const</span> byte *<span class="keyword">const</span> h = representative + representativeByteLength - u - digestSize;<a name="l00096"></a>00096 <a name="l00097"></a>00097 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> digest(digestSize);<a name="l00098"></a>00098 hash.<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="l00099"></a>00099 <a name="l00100"></a>00100 <a class="code" href="struct_decoding_result.html" title="used to return decoding results">DecodingResult</a> result(0);<a name="l00101"></a>00101 <span class="keywordtype">bool</span> &valid = result.<a class="code" href="struct_decoding_result.html#b88062318cd0e68b3061db351d3ba34d">isValidCoding</a>;<a name="l00102"></a>00102 <span class="keywordtype">size_t</span> &recoverableMessageLength = result.<a class="code" href="struct_decoding_result.html#f4496c82e5764175a27e36629e1cded7">messageLength</a>;<a name="l00103"></a>00103 <a name="l00104"></a>00104 valid = (representative[representativeByteLength - 1] == (hashIdentifier.second ? 0xcc : 0xbc)) && valid;<a name="l00105"></a>00105 valid = (memcmp(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second) == 0) && valid;<a name="l00106"></a>00106 <a name="l00107"></a>00107 GetMGF().<a class="code" href="class_mask_generating_function.html#e60d7c6be0e656461d5793ec7d4ac504">GenerateAndMask</a>(hash, representative, representativeByteLength - u - digestSize, h, digestSize);<a name="l00108"></a>00108 <span class="keywordflow">if</span> (representativeBitLength % 8 != 0)<a name="l00109"></a>00109 representative[0] = (byte)Crop(representative[0], representativeBitLength % 8);<a name="l00110"></a>00110 <a name="l00111"></a>00111 <span class="comment">// extract salt and recoverableMessage from DB = 00 ... || 01 || M || salt</span><a name="l00112"></a>00112 byte *salt = representative + representativeByteLength - u - digestSize - saltSize;<a name="l00113"></a>00113 byte *M = std::find_if(representative, salt-1, std::bind2nd(std::not_equal_to<byte>(), 0));<a name="l00114"></a>00114 recoverableMessageLength = salt-M-1;<a name="l00115"></a>00115 <span class="keywordflow">if</span> (*M == 0x01 <a name="l00116"></a>00116 && (<span class="keywordtype">size_t</span>)(M - representative - (representativeBitLength % 8 != 0)) >= MinPadLen(digestSize)<a name="l00117"></a>00117 && recoverableMessageLength <= <a class="code" href="class_p_s_s_r___m_e_m___base.html#2e7bfc7f3bbd54b3ff3be7210251ccb7">MaxRecoverableLength</a>(representativeBitLength, hashIdentifier.second, digestSize))<a name="l00118"></a>00118 {<a name="l00119"></a>00119 memcpy(recoverableMessage, M+1, recoverableMessageLength);<a name="l00120"></a>00120 }<a name="l00121"></a>00121 <span class="keywordflow">else</span><a name="l00122"></a>00122 {<a name="l00123"></a>00123 recoverableMessageLength = 0;<a name="l00124"></a>00124 valid = <span class="keyword">false</span>;<a name="l00125"></a>00125 }<a name="l00126"></a>00126 <a name="l00127"></a>00127 <span class="comment">// verify H = hash of M'</span><a name="l00128"></a>00128 byte c[8];<a name="l00129"></a>00129 PutWord(<span class="keyword">false</span>, <a class="code" href="cryptlib_8h.html#aeb92d42f5a6e27b8ba19f18d69d142bf0c3bb6c718cc7ff0bffef4e8f178c57">BIG_ENDIAN_ORDER</a>, c, (word32)SafeRightShift<29>(recoverableMessageLength));<a name="l00130"></a>00130 PutWord(<span class="keyword">false</span>, <a class="code" href="cryptlib_8h.html#aeb92d42f5a6e27b8ba19f18d69d142bf0c3bb6c718cc7ff0bffef4e8f178c57">BIG_ENDIAN_ORDER</a>, c+4, word32(recoverableMessageLength << 3));<a name="l00131"></a>00131 hash.<a class="code" href="class_hash_transformation.html#afabefaf445b65d3ba0d8e1c0294afe5" title="process more input">Update</a>(c, 8);<a name="l00132"></a>00132 hash.<a class="code" href="class_hash_transformation.html#afabefaf445b65d3ba0d8e1c0294afe5" title="process more input">Update</a>(recoverableMessage, recoverableMessageLength);<a name="l00133"></a>00133 hash.<a class="code" href="class_hash_transformation.html#afabefaf445b65d3ba0d8e1c0294afe5" title="process more input">Update</a>(digest, digestSize);<a name="l00134"></a>00134 hash.<a class="code" href="class_hash_transformation.html#afabefaf445b65d3ba0d8e1c0294afe5" title="process more input">Update</a>(salt, saltSize);<a name="l00135"></a>00135 valid = hash.<a class="code" href="class_hash_transformation.html#16c4aecd047015d513feef4ed5b929ba" title="verify that digest is a valid digest for the current message, then reinitialize the...">Verify</a>(h) && valid;<a name="l00136"></a>00136 <a name="l00137"></a>00137 <span class="keywordflow">if</span> (!AllowRecovery() && valid && recoverableMessageLength != 0)<a name="l00138"></a>00138 {<span class="keywordflow">throw</span> <a class="code" href="class_not_implemented.html" title="exception thrown by a class if a non-implemented method is called">NotImplemented</a>(<span class="stringliteral">"PSSR_MEM: message recovery disabled"</span>);}<a name="l00139"></a>00139 <a name="l00140"></a>00140 <span class="keywordflow">return</span> result;<a name="l00141"></a>00141 }<a name="l00142"></a>00142 <a name="l00143"></a>00143 <span class="preprocessor">#endif</span><a name="l00144"></a>00144 <span class="preprocessor"></span><a name="l00145"></a>00145 NAMESPACE_END</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Fri Jun 1 11:11:23 2007 for Crypto++ by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -