<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <meta name="generator" content="Doxygen 1.8.14"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>Crypto++: pssr.cpp Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td id="projectalign" style="padding-left: 0.5em;"> <div id="projectname">Crypto++  <span id="projectnumber">7.0</span> </div> <div id="projectbrief">Free C++ class library of cryptographic schemes</div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.14 --> <script type="text/javascript" src="menudata.js"></script> <script type="text/javascript" src="menu.js"></script> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ $(function() { initMenu('',false,false,'search.php','Search'); }); /* @license-end */</script> <div id="main-nav"></div> </div><!-- top --> <div class="header"> <div class="headertitle"> <div class="title">pssr.cpp</div> </div> </div><!--header--> <div class="contents"> <div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">// pssr.cpp - originally written and placed in the public domain by Wei Dai</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> </div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="preprocessor">#include "<a class="code" href="pch_8h.html">pch.h</a>"</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="preprocessor">#include "<a class="code" href="pssr_8h.html">pssr.h</a>"</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="preprocessor">#include "<a class="code" href="emsa2_8h.html">emsa2.h</a>"</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="preprocessor">#include "<a class="code" href="ripemd_8h.html">ripemd.h</a>"</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="preprocessor">#include "<a class="code" href="whrlpool_8h.html">whrlpool.h</a>"</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="preprocessor">#include "<a class="code" href="misc_8h.html">misc.h</a>"</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> </div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="preprocessor">#include <functional></span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> </div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> NAMESPACE_BEGIN(<a class="code" href="namespace_crypto_p_p.html">CryptoPP</a>)</div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> </div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="keyword">template</span><> <span class="keyword">const</span> byte <a class="code" href="class_e_m_s_a2_hash_id.html">EMSA2HashId<RIPEMD160>::id</a> = 0x31;</div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="keyword">template</span><> <span class="keyword">const</span> byte <a class="code" href="class_e_m_s_a2_hash_id.html">EMSA2HashId<RIPEMD128>::id</a> = 0x32;</div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="keyword">template</span><> <span class="keyword">const</span> byte <a class="code" href="class_e_m_s_a2_hash_id.html">EMSA2HashId<Whirlpool>::id</a> = 0x37;</div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> </div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="preprocessor">#ifndef CRYPTOPP_IMPORTS</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> </div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="keywordtype">size_t</span> PSSR_MEM_Base::MinRepresentativeBitLength(<span class="keywordtype">size_t</span> hashIdentifierLength, <span class="keywordtype">size_t</span> digestLength)<span class="keyword"> const</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="keyword"></span>{</div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span>  <span class="keywordtype">size_t</span> saltLen = SaltLen(digestLength);</div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span>  <span class="keywordtype">size_t</span> minPadLen = MinPadLen(digestLength);</div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span>  <span class="keywordflow">return</span> 9 + 8*(minPadLen + saltLen + digestLength + hashIdentifierLength);</div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> }</div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> </div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="keywordtype">size_t</span> PSSR_MEM_Base::MaxRecoverableLength(<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></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="keyword"></span>{</div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span>  <span class="keywordflow">if</span> (AllowRecovery())</div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span>  <span class="keywordflow">return</span> <a class="code" href="misc_8h.html#a30712a90999ad9d9152975f2e92d46b8">SaturatingSubtract</a>(representativeBitLength, MinRepresentativeBitLength(hashIdentifierLength, digestLength)) / 8;</div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span>  <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> }</div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> </div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="keywordtype">bool</span> PSSR_MEM_Base::IsProbabilistic()<span class="keyword"> const</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="keyword"></span>{</div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span>  <span class="keywordflow">return</span> SaltLen(1) > 0;</div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span> }</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> </div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="keywordtype">bool</span> PSSR_MEM_Base::AllowNonrecoverablePart()<span class="keyword"> const</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span> <span class="keyword"></span>{</div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>  <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span> }</div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span> </div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span> <span class="keywordtype">bool</span> PSSR_MEM_Base::RecoverablePartFirst()<span class="keyword"> const</span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> <span class="keyword"></span>{</div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span> }</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span> </div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span> <span class="keywordtype">void</span> PSSR_MEM_Base::ComputeMessageRepresentative(<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &rng,</div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  <span class="keyword">const</span> byte *recoverableMessage, <span class="keywordtype">size_t</span> recoverableMessageLength,</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  <a class="code" href="class_hash_transformation.html">HashTransformation</a> &hash, HashIdentifier hashIdentifier, <span class="keywordtype">bool</span> messageEmpty,</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  byte *representative, <span class="keywordtype">size_t</span> representativeBitLength)<span class="keyword"> const</span></div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span> <span class="keyword"></span>{</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength);</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  CRYPTOPP_UNUSED(messageEmpty), CRYPTOPP_UNUSED(hashIdentifier);</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  <a class="code" href="trap_8h.html#adf3b392588bc94cbeae9f415a78c7b95">CRYPTOPP_ASSERT</a>(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.<a class="code" href="class_hash_transformation.html#a9f42cc280bac76b884ad12615c0dabb5">DigestSize</a>()));</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span> </div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  <span class="keyword">const</span> <span class="keywordtype">size_t</span> u = hashIdentifier.second + 1;</div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  <span class="keyword">const</span> <span class="keywordtype">size_t</span> representativeByteLength = <a class="code" href="misc_8h.html#a7c5d30b17c9d4869fdc3458dd05c500d">BitsToBytes</a>(representativeBitLength);</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  <span class="keyword">const</span> <span class="keywordtype">size_t</span> digestSize = hash.<a class="code" href="class_hash_transformation.html#a9f42cc280bac76b884ad12615c0dabb5">DigestSize</a>();</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  <span class="keyword">const</span> <span class="keywordtype">size_t</span> saltSize = SaltLen(digestSize);</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  byte *<span class="keyword">const</span> h = representative + representativeByteLength - u - digestSize;</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span> </div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  <a class="code" href="class_sec_byte_block.html">SecByteBlock</a> digest(digestSize), salt(saltSize);</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  hash.<a class="code" href="class_hash_transformation.html#aa0b8c7a110d8968268fd02ec32b9a8e8">Final</a>(digest);</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  rng.<a class="code" href="class_random_number_generator.html#a497145546d24e6d4abaf10b7e0f1ba17">GenerateBlock</a>(salt, saltSize);</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span> </div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  <span class="comment">// compute H = hash of M'</span></div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  byte c[8];</div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  <a class="code" href="misc_8h.html#aef6a8d35198f71ff68811bacd599c664">PutWord</a>(<span class="keyword">false</span>, <a class="code" href="cryptlib_8h.html#aaeb92d42f5a6e27b8ba19f18d69d142baf0c3bb6c718cc7ff0bffef4e8f178c57">BIG_ENDIAN_ORDER</a>, c, (word32)SafeRightShift<29>(recoverableMessageLength));</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  <a class="code" href="misc_8h.html#aef6a8d35198f71ff68811bacd599c664">PutWord</a>(<span class="keyword">false</span>, <a class="code" href="cryptlib_8h.html#aaeb92d42f5a6e27b8ba19f18d69d142baf0c3bb6c718cc7ff0bffef4e8f178c57">BIG_ENDIAN_ORDER</a>, c+4, word32(recoverableMessageLength << 3));</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  hash.<a class="code" href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5">Update</a>(c, 8);</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  hash.<a class="code" href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5">Update</a>(recoverableMessage, recoverableMessageLength);</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  hash.<a class="code" href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5">Update</a>(digest, digestSize);</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  hash.<a class="code" href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5">Update</a>(salt, saltSize);</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  hash.<a class="code" href="class_hash_transformation.html#aa0b8c7a110d8968268fd02ec32b9a8e8">Final</a>(h);</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span> </div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <span class="comment">// compute representative</span></div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  GetMGF().<a class="code" href="class_mask_generating_function.html#a7ef49cae6b047a6be64909d63cfa41ba">GenerateAndMask</a>(hash, representative, representativeByteLength - u - digestSize, h, digestSize, <span class="keyword">false</span>);</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  byte *xorStart = representative + representativeByteLength - u - digestSize - salt.size() - recoverableMessageLength - 1;</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  xorStart[0] ^= 1;</div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  <span class="keywordflow">if</span> (recoverableMessage && recoverableMessageLength)</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  <a class="code" href="misc_8h.html#a6aaae7768600b9d735a5e1b8192035f8">xorbuf</a>(xorStart + 1, recoverableMessage, recoverableMessageLength);</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  <a class="code" href="misc_8h.html#a6aaae7768600b9d735a5e1b8192035f8">xorbuf</a>(xorStart + 1 + recoverableMessageLength, salt, salt.size());</div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  <span class="keywordflow">if</span> (hashIdentifier.first && hashIdentifier.second)</div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  {</div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  memcpy(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second);</div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  representative[representativeByteLength - 1] = 0xcc;</div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  }</div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  <span class="keywordflow">else</span></div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  {</div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  representative[representativeByteLength - 1] = 0xbc;</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  }</div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  <span class="keywordflow">if</span> (representativeBitLength % 8 != 0)</div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  representative[0] = (byte)<a class="code" href="misc_8h.html#a616a7f0365c4947b0c8a44606c525a62">Crop</a>(representative[0], representativeBitLength % 8);</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span> }</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span> </div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span> <a class="code" href="struct_decoding_result.html">DecodingResult</a> PSSR_MEM_Base::RecoverMessageFromRepresentative(</div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  <a class="code" href="class_hash_transformation.html">HashTransformation</a> &hash, HashIdentifier hashIdentifier, <span class="keywordtype">bool</span> messageEmpty,</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  byte *representative, <span class="keywordtype">size_t</span> representativeBitLength,</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  byte *recoverableMessage)<span class="keyword"> const</span></div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span> <span class="keyword"></span>{</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(messageEmpty), CRYPTOPP_UNUSED(hashIdentifier);</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  <a class="code" href="trap_8h.html#adf3b392588bc94cbeae9f415a78c7b95">CRYPTOPP_ASSERT</a>(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.<a class="code" href="class_hash_transformation.html#a9f42cc280bac76b884ad12615c0dabb5">DigestSize</a>()));</div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span> </div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  <span class="keyword">const</span> <span class="keywordtype">size_t</span> u = hashIdentifier.second + 1;</div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span>  <span class="keyword">const</span> <span class="keywordtype">size_t</span> representativeByteLength = <a class="code" href="misc_8h.html#a7c5d30b17c9d4869fdc3458dd05c500d">BitsToBytes</a>(representativeBitLength);</div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  <span class="keyword">const</span> <span class="keywordtype">size_t</span> digestSize = hash.<a class="code" href="class_hash_transformation.html#a9f42cc280bac76b884ad12615c0dabb5">DigestSize</a>();</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="keyword">const</span> <span class="keywordtype">size_t</span> saltSize = SaltLen(digestSize);</div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <span class="keyword">const</span> byte *<span class="keyword">const</span> h = representative + representativeByteLength - u - digestSize;</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span> </div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  <a class="code" href="class_sec_byte_block.html">SecByteBlock</a> digest(digestSize);</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  hash.<a class="code" href="class_hash_transformation.html#aa0b8c7a110d8968268fd02ec32b9a8e8">Final</a>(digest);</div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span> </div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  <a class="code" href="struct_decoding_result.html">DecodingResult</a> result(0);</div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  <span class="keywordtype">bool</span> &valid = result.isValidCoding;</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  <span class="keywordtype">size_t</span> &recoverableMessageLength = result.messageLength;</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span> </div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span>  valid = (representative[representativeByteLength - 1] == (hashIdentifier.second ? 0xcc : 0xbc)) && valid;</div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span> </div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  <span class="keywordflow">if</span> (hashIdentifier.first && hashIdentifier.second)</div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  valid = <a class="code" href="misc_8h.html#a8e14b85d64aa63e5ba80471716837c74">VerifyBufsEqual</a>(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second) && valid;</div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span> </div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span>  GetMGF().<a class="code" href="class_mask_generating_function.html#a7ef49cae6b047a6be64909d63cfa41ba">GenerateAndMask</a>(hash, representative, representativeByteLength - u - digestSize, h, digestSize);</div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span>  <span class="keywordflow">if</span> (representativeBitLength % 8 != 0)</div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span>  representative[0] = (byte)<a class="code" href="misc_8h.html#a616a7f0365c4947b0c8a44606c525a62">Crop</a>(representative[0], representativeBitLength % 8);</div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span> </div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  <span class="comment">// extract salt and recoverableMessage from DB = 00 ... || 01 || M || salt</span></div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  byte *salt = representative + representativeByteLength - u - digestSize - saltSize;</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  byte *M = <a class="code" href="misc_8h.html#ab29e4cf4553b1ff9f884df223a2abd6a">FindIfNot</a>(representative, salt-1, byte(0));</div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  recoverableMessageLength = salt-M-1;</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  <span class="keywordflow">if</span> (*M == 0x01 &&</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  (<span class="keywordtype">size_t</span>)(M - representative - (representativeBitLength % 8 != 0)) >= MinPadLen(digestSize) &&</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  recoverableMessageLength <= MaxRecoverableLength(representativeBitLength, hashIdentifier.second, digestSize))</div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  {</div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  <span class="keywordflow">if</span> (recoverableMessage)</div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span>  memcpy(recoverableMessage, M+1, recoverableMessageLength);</div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span>  }</div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span>  <span class="keywordflow">else</span></div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span>  {</div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span>  recoverableMessageLength = 0;</div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span>  valid = <span class="keyword">false</span>;</div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span>  }</div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span> </div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  <span class="comment">// verify H = hash of M'</span></div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  byte c[8];</div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  <a class="code" href="misc_8h.html#aef6a8d35198f71ff68811bacd599c664">PutWord</a>(<span class="keyword">false</span>, <a class="code" href="cryptlib_8h.html#aaeb92d42f5a6e27b8ba19f18d69d142baf0c3bb6c718cc7ff0bffef4e8f178c57">BIG_ENDIAN_ORDER</a>, c, (word32)SafeRightShift<29>(recoverableMessageLength));</div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span>  <a class="code" href="misc_8h.html#aef6a8d35198f71ff68811bacd599c664">PutWord</a>(<span class="keyword">false</span>, <a class="code" href="cryptlib_8h.html#aaeb92d42f5a6e27b8ba19f18d69d142baf0c3bb6c718cc7ff0bffef4e8f178c57">BIG_ENDIAN_ORDER</a>, c+4, word32(recoverableMessageLength << 3));</div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  hash.<a class="code" href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5">Update</a>(c, 8);</div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  hash.<a class="code" href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5">Update</a>(recoverableMessage, recoverableMessageLength);</div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span>  hash.<a class="code" href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5">Update</a>(digest, digestSize);</div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  hash.<a class="code" href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5">Update</a>(salt, saltSize);</div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  valid = hash.<a class="code" href="class_hash_transformation.html#a16c4aecd047015d513feef4ed5b929ba">Verify</a>(h) && valid;</div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span> </div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span>  <span class="keywordflow">if</span> (!AllowRecovery() && valid && recoverableMessageLength != 0)</div><div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  {<span class="keywordflow">throw</span> <a class="code" href="class_not_implemented.html">NotImplemented</a>(<span class="stringliteral">"PSSR_MEM: message recovery disabled"</span>);}</div><div class="line"><a name="l00157"></a><span class="lineno"> 157</span> </div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span>  <span class="keywordflow">return</span> result;</div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span> }</div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span> </div><div class="line"><a name="l00161"></a><span class="lineno"> 161</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00162"></a><span class="lineno"> 162</span> </div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span> NAMESPACE_END</div><div class="ttc" id="misc_8h_html_ab29e4cf4553b1ff9f884df223a2abd6a"><div class="ttname"><a href="misc_8h.html#ab29e4cf4553b1ff9f884df223a2abd6a">FindIfNot</a></div><div class="ttdeci">InputIt FindIfNot(InputIt first, InputIt last, const T &value)</div><div class="ttdoc">Finds first element not in a range. </div><div class="ttdef"><b>Definition:</b> <a href="misc_8h_source.html#l02540">misc.h:2540</a></div></div> <div class="ttc" id="misc_8h_html"><div class="ttname"><a href="misc_8h.html">misc.h</a></div><div class="ttdoc">Utility functions for the Crypto++ library. </div></div> <div class="ttc" id="ripemd_8h_html"><div class="ttname"><a href="ripemd_8h.html">ripemd.h</a></div><div class="ttdoc">Classes for RIPEMD message digest. </div></div> <div class="ttc" id="emsa2_8h_html"><div class="ttname"><a href="emsa2_8h.html">emsa2.h</a></div><div class="ttdoc">Classes and functions for various padding schemes used in public key algorithms. </div></div> <div class="ttc" id="class_random_number_generator_html_a497145546d24e6d4abaf10b7e0f1ba17"><div class="ttname"><a href="class_random_number_generator.html#a497145546d24e6d4abaf10b7e0f1ba17">RandomNumberGenerator::GenerateBlock</a></div><div class="ttdeci">virtual void GenerateBlock(byte *output, size_t size)</div><div class="ttdoc">Generate random array of bytes. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8cpp_source.html#l00317">cryptlib.cpp:317</a></div></div> <div class="ttc" id="misc_8h_html_a7c5d30b17c9d4869fdc3458dd05c500d"><div class="ttname"><a href="misc_8h.html#a7c5d30b17c9d4869fdc3458dd05c500d">BitsToBytes</a></div><div class="ttdeci">size_t BitsToBytes(size_t bitCount)</div><div class="ttdoc">Returns the number of 8-bit bytes or octets required for the specified number of bits. </div><div class="ttdef"><b>Definition:</b> <a href="misc_8h_source.html#l00790">misc.h:790</a></div></div> <div class="ttc" id="misc_8h_html_aef6a8d35198f71ff68811bacd599c664"><div class="ttname"><a href="misc_8h.html#aef6a8d35198f71ff68811bacd599c664">PutWord</a></div><div class="ttdeci">void PutWord(bool assumeAligned, ByteOrder order, byte *block, T value, const byte *xorBlock=NULL)</div><div class="ttdoc">Access a block of memory. </div><div class="ttdef"><b>Definition:</b> <a href="misc_8h_source.html#l02295">misc.h:2295</a></div></div> <div class="ttc" id="class_random_number_generator_html"><div class="ttname"><a href="class_random_number_generator.html">RandomNumberGenerator</a></div><div class="ttdoc">Interface for random number generators. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l01330">cryptlib.h:1330</a></div></div> <div class="ttc" id="class_sec_byte_block_html"><div class="ttname"><a href="class_sec_byte_block.html">SecByteBlock</a></div><div class="ttdoc">SecBlock<byte> typedef. </div><div class="ttdef"><b>Definition:</b> <a href="secblock_8h_source.html#l00822">secblock.h:822</a></div></div> <div class="ttc" id="class_e_m_s_a2_hash_id_html"><div class="ttname"><a href="class_e_m_s_a2_hash_id.html">EMSA2HashId</a></div><div class="ttdoc">EMSA2 hash identifier. </div><div class="ttdef"><b>Definition:</b> <a href="emsa2_8h_source.html#l00023">emsa2.h:23</a></div></div> <div class="ttc" id="struct_decoding_result_html"><div class="ttname"><a href="struct_decoding_result.html">DecodingResult</a></div><div class="ttdoc">Returns a decoding results. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l00252">cryptlib.h:252</a></div></div> <div class="ttc" id="class_mask_generating_function_html_a7ef49cae6b047a6be64909d63cfa41ba"><div class="ttname"><a href="class_mask_generating_function.html#a7ef49cae6b047a6be64909d63cfa41ba">MaskGeneratingFunction::GenerateAndMask</a></div><div class="ttdeci">virtual void GenerateAndMask(HashTransformation &hash, byte *output, size_t outputLength, const byte *input, size_t inputLength, bool mask=true) const =0</div><div class="ttdoc">Generate and apply mask. </div></div> <div class="ttc" id="class_not_implemented_html"><div class="ttname"><a href="class_not_implemented.html">NotImplemented</a></div><div class="ttdoc">A method was called which was not implemented. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l00220">cryptlib.h:220</a></div></div> <div class="ttc" id="misc_8h_html_a616a7f0365c4947b0c8a44606c525a62"><div class="ttname"><a href="misc_8h.html#a616a7f0365c4947b0c8a44606c525a62">Crop</a></div><div class="ttdeci">T Crop(T value, size_t bits)</div><div class="ttdoc">Truncates the value to the specified number of bits. </div><div class="ttdef"><b>Definition:</b> <a href="misc_8h_source.html#l00778">misc.h:778</a></div></div> <div class="ttc" id="pch_8h_html"><div class="ttname"><a href="pch_8h.html">pch.h</a></div><div class="ttdoc">Precompiled header file. </div></div> <div class="ttc" id="misc_8h_html_a30712a90999ad9d9152975f2e92d46b8"><div class="ttname"><a href="misc_8h.html#a30712a90999ad9d9152975f2e92d46b8">SaturatingSubtract</a></div><div class="ttdeci">T1 SaturatingSubtract(const T1 &a, const T2 &b)</div><div class="ttdoc">Performs a saturating subtract clamped at 0. </div><div class="ttdef"><b>Definition:</b> <a href="misc_8h_source.html#l00890">misc.h:890</a></div></div> <div class="ttc" id="cryptlib_8h_html_aaeb92d42f5a6e27b8ba19f18d69d142baf0c3bb6c718cc7ff0bffef4e8f178c57"><div class="ttname"><a href="cryptlib_8h.html#aaeb92d42f5a6e27b8ba19f18d69d142baf0c3bb6c718cc7ff0bffef4e8f178c57">BIG_ENDIAN_ORDER</a></div><div class="ttdoc">byte order is big-endian </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l00144">cryptlib.h:144</a></div></div> <div class="ttc" id="class_hash_transformation_html_a16c4aecd047015d513feef4ed5b929ba"><div class="ttname"><a href="class_hash_transformation.html#a16c4aecd047015d513feef4ed5b929ba">HashTransformation::Verify</a></div><div class="ttdeci">virtual bool Verify(const byte *digest)</div><div class="ttdoc">Verifies the hash of the current message. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l01151">cryptlib.h:1151</a></div></div> <div class="ttc" id="trap_8h_html_adf3b392588bc94cbeae9f415a78c7b95"><div class="ttname"><a href="trap_8h.html#adf3b392588bc94cbeae9f415a78c7b95">CRYPTOPP_ASSERT</a></div><div class="ttdeci">#define CRYPTOPP_ASSERT(exp)</div><div class="ttdoc">Debugging and diagnostic assertion. </div><div class="ttdef"><b>Definition:</b> <a href="trap_8h_source.html#l00060">trap.h:60</a></div></div> <div class="ttc" id="whrlpool_8h_html"><div class="ttname"><a href="whrlpool_8h.html">whrlpool.h</a></div><div class="ttdoc">Classes for the Whirlpool message digest. </div></div> <div class="ttc" id="class_hash_transformation_html_a9f42cc280bac76b884ad12615c0dabb5"><div class="ttname"><a href="class_hash_transformation.html#a9f42cc280bac76b884ad12615c0dabb5">HashTransformation::DigestSize</a></div><div class="ttdeci">virtual unsigned int DigestSize() const =0</div><div class="ttdoc">Provides the digest size of the hash. </div></div> <div class="ttc" id="misc_8h_html_a6aaae7768600b9d735a5e1b8192035f8"><div class="ttname"><a href="misc_8h.html#a6aaae7768600b9d735a5e1b8192035f8">xorbuf</a></div><div class="ttdeci">void xorbuf(byte *buf, const byte *mask, size_t count)</div><div class="ttdoc">Performs an XOR of a buffer with a mask. </div><div class="ttdef"><b>Definition:</b> <a href="misc_8cpp_source.html#l00032">misc.cpp:32</a></div></div> <div class="ttc" id="class_hash_transformation_html"><div class="ttname"><a href="class_hash_transformation.html">HashTransformation</a></div><div class="ttdoc">Interface for hash functions and data processing part of MACs. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l01065">cryptlib.h:1065</a></div></div> <div class="ttc" id="misc_8h_html_a8e14b85d64aa63e5ba80471716837c74"><div class="ttname"><a href="misc_8h.html#a8e14b85d64aa63e5ba80471716837c74">VerifyBufsEqual</a></div><div class="ttdeci">bool VerifyBufsEqual(const byte *buf1, const byte *buf2, size_t count)</div><div class="ttdoc">Performs a near constant-time comparison of two equally sized buffers. </div><div class="ttdef"><b>Definition:</b> <a href="misc_8cpp_source.html#l00100">misc.cpp:100</a></div></div> <div class="ttc" id="namespace_crypto_p_p_html"><div class="ttname"><a href="namespace_crypto_p_p.html">CryptoPP</a></div><div class="ttdoc">Crypto++ library namespace. </div></div> <div class="ttc" id="class_hash_transformation_html_aa0b8c7a110d8968268fd02ec32b9a8e8"><div class="ttname"><a href="class_hash_transformation.html#aa0b8c7a110d8968268fd02ec32b9a8e8">HashTransformation::Final</a></div><div class="ttdeci">virtual void Final(byte *digest)</div><div class="ttdoc">Computes the hash of the current message. </div><div class="ttdef"><b>Definition:</b> <a href="cryptlib_8h_source.html#l01095">cryptlib.h:1095</a></div></div> <div class="ttc" id="pssr_8h_html"><div class="ttname"><a href="pssr_8h.html">pssr.h</a></div><div class="ttdoc">Classes for probablistic signature schemes. </div></div> <div class="ttc" id="class_hash_transformation_html_aafabefaf445b65d3ba0d8e1c0294afe5"><div class="ttname"><a href="class_hash_transformation.html#aafabefaf445b65d3ba0d8e1c0294afe5">HashTransformation::Update</a></div><div class="ttdeci">virtual void Update(const byte *input, size_t length)=0</div><div class="ttdoc">Updates a hash with additional input. </div></div> </div><!-- fragment --></div><!-- contents --> <!-- start footer part --> <hr class="footer"/><address class="footer"><small> Generated on Sun Sep 16 2018 07:57:59 for Crypto++ by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.8.14 </small></address> </body> </html>