📄 pssr_8cpp-source.html
字号:
<!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++: pssr.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 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 List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul></div><h1>pssr.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// pssr.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 "pssr.h"</span><a name="l00005"></a>00005 <span class="preprocessor">#include <functional></span><a name="l00006"></a>00006 <a name="l00007"></a>00007 NAMESPACE_BEGIN(CryptoPP)<a name="l00008"></a>00008 <a name="l00009"></a>00009 <span class="comment">// more in dll.cpp</span><a name="l00010"></a><a class="code" href="class_e_m_s_a2_hash_id.html#3812e1130882d395a21f2caadbc430d0">00010</a> template<> const byte <a class="code" href="class_e_m_s_a2_hash_id.html">EMSA2HashId</a><<a class="code" href="class_r_i_p_e_m_d160.html" title="RIPEMD-160">RIPEMD160</a>>::<span class="keywordtype">id</span> = 0x31;<a name="l00011"></a><a class="code" href="class_e_m_s_a2_hash_id.html#e4def0f4d9434ffefdb661f014d06a55">00011</a> template<> const byte <a class="code" href="class_e_m_s_a2_hash_id.html">EMSA2HashId</a><<a class="code" href="class_r_i_p_e_m_d128.html">RIPEMD128</a>>::<span class="keywordtype">id</span> = 0x32;<a name="l00012"></a><a class="code" href="class_e_m_s_a2_hash_id.html#f90a9e588b81965966636c10fff777eb">00012</a> template<> const byte <a class="code" href="class_e_m_s_a2_hash_id.html">EMSA2HashId</a><<a class="code" href="class_whirlpool.html" title="Whirlpool">Whirlpool</a>>::<span class="keywordtype">id</span> = 0x37;<a name="l00013"></a>00013 <a name="l00014"></a>00014 <span class="preprocessor">#ifndef CRYPTOPP_IMPORTS</span><a name="l00015"></a>00015 <span class="preprocessor"></span><a name="l00016"></a><a class="code" href="class_p_s_s_r___m_e_m___base.html#5528c0fafed27d6d8603c28b13cf2f21">00016</a> <span class="keywordtype">size_t</span> <a class="code" href="class_p_s_s_r___m_e_m___base.html#5528c0fafed27d6d8603c28b13cf2f21">PSSR_MEM_Base::MinRepresentativeBitLength</a>(<span class="keywordtype">size_t</span> hashIdentifierLength, <span class="keywordtype">size_t</span> digestLength)<span class="keyword"> const</span><a name="l00017"></a>00017 <span class="keyword"></span>{<a name="l00018"></a>00018 <span class="keywordtype">size_t</span> saltLen = SaltLen(digestLength);<a name="l00019"></a>00019 <span class="keywordtype">size_t</span> minPadLen = MinPadLen(digestLength);<a name="l00020"></a>00020 <span class="keywordflow">return</span> 9 + 8*(minPadLen + saltLen + digestLength + hashIdentifierLength);<a name="l00021"></a>00021 }<a name="l00022"></a>00022 <a name="l00023"></a><a class="code" href="class_p_s_s_r___m_e_m___base.html#2e7bfc7f3bbd54b3ff3be7210251ccb7">00023</a> <span class="keywordtype">size_t</span> <a class="code" href="class_p_s_s_r___m_e_m___base.html#2e7bfc7f3bbd54b3ff3be7210251ccb7">PSSR_MEM_Base::MaxRecoverableLength</a>(<span class="keywordtype">size_t</span> representativeBitLength, <span class="keywordtype">size_t</span> hashIdentifierLength, <span class="keywordtype">size_t</span> digestLength)<span class="keyword"> const</span><a name="l00024"></a>00024 <span class="keyword"></span>{<a name="l00025"></a>00025 <span class="keywordflow">if</span> (AllowRecovery())<a name="l00026"></a>00026 <span class="keywordflow">return</span> SaturatingSubtract(representativeBitLength, <a class="code" href="class_p_s_s_r___m_e_m___base.html#5528c0fafed27d6d8603c28b13cf2f21">MinRepresentativeBitLength</a>(hashIdentifierLength, digestLength)) / 8;<a name="l00027"></a>00027 <span class="keywordflow">return</span> 0;<a name="l00028"></a>00028 }<a name="l00029"></a>00029 <a name="l00030"></a><a class="code" href="class_p_s_s_r___m_e_m___base.html#d7a9498143b8ff3b8fbc1f9fcfcc7dfe">00030</a> <span class="keywordtype">bool</span> <a class="code" href="class_p_s_s_r___m_e_m___base.html#d7a9498143b8ff3b8fbc1f9fcfcc7dfe">PSSR_MEM_Base::IsProbabilistic</a>()<span class="keyword"> const </span><a name="l00031"></a>00031 <span class="keyword"></span>{<a name="l00032"></a>00032 <span class="keywordflow">return</span> SaltLen(1) > 0;<a name="l00033"></a>00033 }<a name="l00034"></a>00034 <a name="l00035"></a><a class="code" href="class_p_s_s_r___m_e_m___base.html#ec480d4e3e8d2d16e5f594f4ee9072cb">00035</a> <span class="keywordtype">bool</span> <a class="code" href="class_p_s_s_r___m_e_m___base.html#ec480d4e3e8d2d16e5f594f4ee9072cb">PSSR_MEM_Base::AllowNonrecoverablePart</a>()<span class="keyword"> const</span><a name="l00036"></a>00036 <span class="keyword"></span>{<a name="l00037"></a>00037 <span class="keywordflow">return</span> <span class="keyword">true</span>;<a name="l00038"></a>00038 }<a name="l00039"></a>00039 <a name="l00040"></a><a class="code" href="class_p_s_s_r___m_e_m___base.html#d500166ff433ddfb922c56e35fae49bd">00040</a> <span class="keywordtype">bool</span> <a class="code" href="class_p_s_s_r___m_e_m___base.html#d500166ff433ddfb922c56e35fae49bd">PSSR_MEM_Base::RecoverablePartFirst</a>()<span class="keyword"> const</span><a name="l00041"></a>00041 <span class="keyword"></span>{<a name="l00042"></a>00042 <span class="keywordflow">return</span> <span class="keyword">false</span>;<a name="l00043"></a>00043 }<a name="l00044"></a>00044 <a name="l00045"></a><a class="code" href="class_p_s_s_r___m_e_m___base.html#c25933c8c029cfac784567f28e16a3a3">00045</a> <span class="keywordtype">void</span> <a class="code" href="class_p_s_s_r___m_e_m___base.html#c25933c8c029cfac784567f28e16a3a3">PSSR_MEM_Base::ComputeMessageRepresentative</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <a name="l00046"></a>00046 <span class="keyword">const</span> byte *recoverableMessage, <span class="keywordtype">size_t</span> recoverableMessageLength,<a name="l00047"></a>00047 <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="l00048"></a>00048 byte *representative, <span class="keywordtype">size_t</span> representativeBitLength)<span class="keyword"> const</span><a name="l00049"></a>00049 <span class="keyword"></span>{<a name="l00050"></a>00050 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="l00051"></a>00051 <a name="l00052"></a>00052 <span class="keyword">const</span> <span class="keywordtype">size_t</span> u = hashIdentifier.second + 1;<a name="l00053"></a>00053 <span class="keyword">const</span> <span class="keywordtype">size_t</span> representativeByteLength = BitsToBytes(representativeBitLength);<a name="l00054"></a>00054 <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="l00055"></a>00055 <span class="keyword">const</span> <span class="keywordtype">size_t</span> saltSize = SaltLen(digestSize);<a name="l00056"></a>00056 byte *<span class="keyword">const</span> h = representative + representativeByteLength - u - digestSize;<a name="l00057"></a>00057 <a name="l00058"></a>00058 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> digest(digestSize), salt(saltSize);<a name="l00059"></a>00059 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="l00060"></a>00060 rng.<a class="code" href="class_random_number_generator.html#497145546d24e6d4abaf10b7e0f1ba17" title="generate random array of bytes">GenerateBlock</a>(salt, saltSize);<a name="l00061"></a>00061 <a name="l00062"></a>00062 <span class="comment">// compute H = hash of M'</span><a name="l00063"></a>00063 byte c[8];<a name="l00064"></a>00064 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="l00065"></a>00065 PutWord(<span class="keyword">false</span>, <a class="code" href="cryptlib_8h.html#aeb92d42f5a6e27b8ba19f18d69d142bf0c3bb6c718cc7ff0bffef4e8f178c57">BIG_ENDIAN_ORDER</a>, c+4, word32(recoverableMessageLength << 3));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -