Files
C-Plus-Plus/d8/d7a/sha1_8cpp.html
2025-07-09 10:53:16 +00:00

617 lines
50 KiB
HTML

<!-- HTML header for doxygen 1.12.0-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.14.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>TheAlgorithms/C++: hashing/sha1.cpp File Reference</title>
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
<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>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpack-3rd-party/doxygen-awesome-css@2.2.0-1/doxygen-awesome-darkmode-toggle.js"></script>
<script type="text/javascript">
DoxygenAwesomeDarkModeToggle.init()
</script>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<script type="text/javascript" src="../../cookie.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript">
window.MathJax = {
options: {
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process'
},
loader: {
load: ['[tex]/ams']
},
tex: {
macros: {},
packages: ['base','configmacros','ams']
}
};
</script>
<script type="text/javascript" id="MathJax-script" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../doxygen-awesome.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 id="projectrow">
<td id="projectlogo"><img alt="Logo" src="../../project_logo.png"/></td>
<td id="projectalign">
<div id="projectname">TheAlgorithms/C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">All the algorithms implemented in C++</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.14.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
</script>
<script type="text/javascript">
$(function() { codefold.init(); });
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('../../',true,false,'search.php','Search',true);
$(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(function(){initNavTree('d8/d7a/sha1_8cpp.html','../../',''); });
</script>
<div id="container">
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="headertitle"><div class="title">sha1.cpp File Reference</div></div>
</div><!--header-->
<div class="contents">
<p>Simple C++ implementation of the <a href="https://en.wikipedia.org/wiki/SHA-1" target="_blank">SHA-1 Hashing Algorithm</a>
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;algorithm&gt;</code><br />
<code>#include &lt;array&gt;</code><br />
<code>#include &lt;cassert&gt;</code><br />
<code>#include &lt;cstdint&gt;</code><br />
<code>#include &lt;cstring&gt;</code><br />
<code>#include &lt;iostream&gt;</code><br />
<code>#include &lt;string&gt;</code><br />
<code>#include &lt;vector&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for sha1.cpp:</div>
<div class="dyncontent">
<div class="center"><div class="zoom"><iframe scrolling="no" loading="lazy" frameborder="0" src="../../d3/d4c/sha1_8cpp__incl.svg" width="100%" height="383"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div></div>
</div>
</div>
<p><a href="../../d8/d7a/sha1_8cpp_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 id="header-namespaces" class="groupheader"><a id="namespaces" name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:hashing" id="r_hashing"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/d0c/namespacehashing.html">hashing</a></td></tr>
<tr class="memdesc:d6/d0c/namespacehashing"><td class="mdescLeft">&#160;</td><td class="mdescRight">Used for assert. <br /></td></tr>
<tr class="memitem:SHA" id="r_SHA"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../de/dd3/namespace_s_h_a.html">SHA</a></td></tr>
<tr class="memdesc:de/dd3/namespace_s_h_a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Functions for the <a href="https://en.wikipedia.org/wiki/SHA-1" target="_blank">SHA-1</a> algorithm implementation. <br /></td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 id="header-func-members" class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:acf6bd970f29a68702bdbdfe8338e45e0" id="r_acf6bd970f29a68702bdbdfe8338e45e0"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#acf6bd970f29a68702bdbdfe8338e45e0">hashing::sha1::leftRotate32bits</a> (uint32_t n, std::size_t rotate)</td></tr>
<tr class="memdesc:acf6bd970f29a68702bdbdfe8338e45e0"><td class="mdescLeft">&#160;</td><td class="mdescRight">Rotates the bits of a 32-bit unsigned integer. <br /></td></tr>
<tr class="memitem:aada0803ef851d831b7a290a924e3c228" id="r_aada0803ef851d831b7a290a924e3c228"><td class="memItemLeft" align="right" valign="top">std::string&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#aada0803ef851d831b7a290a924e3c228">hashing::sha1::sig2hex</a> (void *sig)</td></tr>
<tr class="memdesc:aada0803ef851d831b7a290a924e3c228"><td class="mdescLeft">&#160;</td><td class="mdescRight">Transforms the 160-bit SHA-1 signature into a 40 char hex string. <br /></td></tr>
<tr class="memitem:a7be3471f7e489d7d0df42b97a48bf141" id="r_a7be3471f7e489d7d0df42b97a48bf141"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a7be3471f7e489d7d0df42b97a48bf141">hashing::sha1::hash_bs</a> (const void *input_bs, uint64_t input_size)</td></tr>
<tr class="memdesc:a7be3471f7e489d7d0df42b97a48bf141"><td class="mdescLeft">&#160;</td><td class="mdescRight">The SHA-1 algorithm itself, taking in a bytestring. <br /></td></tr>
<tr class="memitem:a2397f2444a05e4d1487c67e215410d3c" id="r_a2397f2444a05e4d1487c67e215410d3c"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a2397f2444a05e4d1487c67e215410d3c">hashing::sha1::hash</a> (const std::string &amp;message)</td></tr>
<tr class="memdesc:a2397f2444a05e4d1487c67e215410d3c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Converts the string to bytestring and calls the main algorithm. <br /></td></tr>
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d" id="r_aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Self-test implementations of well-known SHA-1 hashes. <br /></td></tr>
<tr class="memitem:ac9e1a11f44135b890dd10a00e73b5661" id="r_ac9e1a11f44135b890dd10a00e73b5661"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ac9e1a11f44135b890dd10a00e73b5661">interactive</a> ()</td></tr>
<tr class="memdesc:ac9e1a11f44135b890dd10a00e73b5661"><td class="mdescLeft">&#160;</td><td class="mdescRight">Puts user in a loop where inputs can be given and SHA-1 hash will be computed and printed. <br /></td></tr>
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4" id="r_ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <br /></td></tr>
</table>
<a name="details" id="details"></a><h2 id="header-details" class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Simple C++ implementation of the <a href="https://en.wikipedia.org/wiki/SHA-1" target="_blank">SHA-1 Hashing Algorithm</a> </p>
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/tGautot" target="_blank">tGautot</a> </dd></dl>
<p><a href="https://en.wikipedia.org/wiki/SHA-1" target="_blank">SHA-1</a> is a cryptographic hash function that was developped by the <a href="https://en.wikipedia.org/wiki/National_Security_Agency" target="_blank">NSA</a> 1995. SHA-1 is not considered secure since around 2010.</p>
<h3 class="doxsection"><a class="anchor" id="autotoc_md84"></a>
Algorithm</h3>
<p>The first step of the algorithm is to pad the message for its length to be a multiple of 64 (bytes). This is done by first adding 0x80 (10000000) and then only zeroes until the last 8 bytes must be filled, where then the 64 bit size of the input will be added</p>
<p>Once this is done, the algo breaks down this padded message into 64 bytes chunks. Each chunk is used for one <em>round</em>, a round breaks the chunk into 16 blocks of 4 bytes. These 16 blocks are then extended to 80 blocks using <a class="el" href="../../d7/d47/namespace_x_o_r.html" title="Functions for XOR cipher algorithm.">XOR</a> operations on existing blocks (see code for more details). The algorithm will then update its 160-bit state (here represented used 5 32-bits integer) using partial hashes computed using special functions on the blocks previously built. Please take a look at the <a href="https://en.wikipedia.org/wiki/SHA-1#SHA-1_pseudocode" target="_blank">wikipedia article</a> for more precision on these operations </p><dl class="section note"><dt>Note</dt><dd>This is a simple implementation for a byte string but some implmenetations can work on bytestream, messages of unknown length. </dd></dl>
<p class="definition">Definition in file <a class="el" href="../../d8/d7a/sha1_8cpp_source.html">sha1.cpp</a>.</p>
</div><a name="doc-func-members" id="doc-func-members"></a><h2 id="header-doc-func-members" class="groupheader">Function Documentation</h2>
<a id="a2397f2444a05e4d1487c67e215410d3c" name="a2397f2444a05e4d1487c67e215410d3c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2397f2444a05e4d1487c67e215410d3c">&#9670;&#160;</a></span>hash()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void * hashing::sha1::hash </td>
<td>(</td>
<td class="paramtype">const std::string &amp;</td> <td class="paramname"><span class="paramname"><em>message</em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Converts the string to bytestring and calls the main algorithm. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">message</td><td>Plain character message to hash </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>void* Pointer to the SHA-1 signature </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d8/d7a/sha1_8cpp_source.html#l00211">211</a> of file <a class="el" href="../../d8/d7a/sha1_8cpp_source.html">sha1.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 211</span> {</div>
<div class="line"><span class="lineno"> 212</span> <span class="keywordflow">return</span> <a class="code hl_function" href="#a7be3471f7e489d7d0df42b97a48bf141">hash_bs</a>(&amp;message[0], message.size());</div>
<div class="line"><span class="lineno"> 213</span>}</div>
<div class="ttc" id="asha1_8cpp_html_a7be3471f7e489d7d0df42b97a48bf141"><div class="ttname"><a href="#a7be3471f7e489d7d0df42b97a48bf141">hashing::sha1::hash_bs</a></div><div class="ttdeci">void * hash_bs(const void *input_bs, uint64_t input_size)</div><div class="ttdoc">The SHA-1 algorithm itself, taking in a bytestring.</div><div class="ttdef"><b>Definition</b> <a href="../../d8/d7a/sha1_8cpp_source.html#l00084">sha1.cpp:84</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a7be3471f7e489d7d0df42b97a48bf141" name="a7be3471f7e489d7d0df42b97a48bf141"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7be3471f7e489d7d0df42b97a48bf141">&#9670;&#160;</a></span>hash_bs()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void * hashing::sha1::hash_bs </td>
<td>(</td>
<td class="paramtype">const void *</td> <td class="paramname"><span class="paramname"><em>input_bs</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint64_t</td> <td class="paramname"><span class="paramname"><em>input_size</em></span>&#160;)</td>
</tr>
</table>
</div><div class="memdoc">
<p>The SHA-1 algorithm itself, taking in a bytestring. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">input_bs</td><td>The bytestring to hash </td></tr>
<tr><td class="paramname">input_size</td><td>The size (in BYTES) of the input </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>void* Pointer to the 160-bit signature </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d8/d7a/sha1_8cpp_source.html#l00084">84</a> of file <a class="el" href="../../d8/d7a/sha1_8cpp_source.html">sha1.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 84</span> {</div>
<div class="line"><span class="lineno"> 85</span> <span class="keyword">auto</span>* input = <span class="keyword">static_cast&lt;</span><span class="keyword">const </span>uint8_t*<span class="keyword">&gt;</span>(input_bs);</div>
<div class="line"><span class="lineno"> 86</span> </div>
<div class="line"><span class="lineno"> 87</span> <span class="comment">// Step 0: The initial 160-bit state</span></div>
<div class="line"><span class="lineno"> 88</span> uint32_t h0 = 0x67452301, a = 0;</div>
<div class="line"><span class="lineno"> 89</span> uint32_t h1 = 0xEFCDAB89, b = 0;</div>
<div class="line"><span class="lineno"> 90</span> uint32_t h2 = 0x98BADCFE, c = 0;</div>
<div class="line"><span class="lineno"> 91</span> uint32_t h3 = 0x10325476, d = 0;</div>
<div class="line"><span class="lineno"> 92</span> uint32_t h4 = 0xC3D2E1F0, e = 0;</div>
<div class="line"><span class="lineno"> 93</span> </div>
<div class="line"><span class="lineno"> 94</span> <span class="comment">// Step 1: Processing the bytestring</span></div>
<div class="line"><span class="lineno"> 95</span> <span class="comment">// First compute the size the padded message will have</span></div>
<div class="line"><span class="lineno"> 96</span> <span class="comment">// so it is possible to allocate the right amount of memory</span></div>
<div class="line"><span class="lineno"> 97</span> uint64_t padded_message_size = 0;</div>
<div class="line"><span class="lineno"> 98</span> <span class="keywordflow">if</span> (input_size % 64 &lt; 56) {</div>
<div class="line"><span class="lineno"> 99</span> padded_message_size = input_size + 64 - (input_size % 64);</div>
<div class="line"><span class="lineno"> 100</span> } <span class="keywordflow">else</span> {</div>
<div class="line"><span class="lineno"> 101</span> padded_message_size = input_size + 128 - (input_size % 64);</div>
<div class="line"><span class="lineno"> 102</span> }</div>
<div class="line"><span class="lineno"> 103</span> </div>
<div class="line"><span class="lineno"> 104</span> <span class="comment">// Allocate the memory for the padded message</span></div>
<div class="line"><span class="lineno"> 105</span> std::vector&lt;uint8_t&gt; padded_message(padded_message_size);</div>
<div class="line"><span class="lineno"> 106</span> </div>
<div class="line"><span class="lineno"> 107</span> <span class="comment">// Beginning of the padded message is the original message</span></div>
<div class="line"><span class="lineno"> 108</span> std::copy(input, input + input_size, padded_message.begin());</div>
<div class="line"><span class="lineno"> 109</span> </div>
<div class="line"><span class="lineno"> 110</span> <span class="comment">// Afterwards comes a single 1 bit and then only zeroes</span></div>
<div class="line"><span class="lineno"> 111</span> padded_message[input_size] = 1 &lt;&lt; 7; <span class="comment">// 10000000</span></div>
<div class="line"><span class="lineno"> 112</span> <span class="keywordflow">for</span> (uint64_t i = input_size; i % 64 != 56; i++) {</div>
<div class="line"><span class="lineno"> 113</span> <span class="keywordflow">if</span> (i == input_size) {</div>
<div class="line"><span class="lineno"> 114</span> <span class="keywordflow">continue</span>; <span class="comment">// pass first iteration</span></div>
<div class="line"><span class="lineno"> 115</span> }</div>
<div class="line"><span class="lineno"> 116</span> padded_message[i] = 0;</div>
<div class="line"><span class="lineno"> 117</span> }</div>
<div class="line"><span class="lineno"> 118</span> </div>
<div class="line"><span class="lineno"> 119</span> <span class="comment">// We then have to add the 64-bit size of the message in bits (hence the</span></div>
<div class="line"><span class="lineno"> 120</span> <span class="comment">// times 8) in the last 8 bytes</span></div>
<div class="line"><span class="lineno"> 121</span> uint64_t input_bitsize = input_size * 8;</div>
<div class="line"><span class="lineno"> 122</span> <span class="keywordflow">for</span> (uint8_t i = 0; i &lt; 8; i++) {</div>
<div class="line"><span class="lineno"> 123</span> padded_message[padded_message_size - 8 + i] =</div>
<div class="line"><span class="lineno"> 124</span> (input_bitsize &gt;&gt; (56 - 8 * i)) &amp; 0xFF;</div>
<div class="line"><span class="lineno"> 125</span> }</div>
<div class="line"><span class="lineno"> 126</span> </div>
<div class="line"><span class="lineno"> 127</span> <span class="comment">// Already allocate memory for blocks</span></div>
<div class="line"><span class="lineno"> 128</span> std::array&lt;uint32_t, 80&gt; blocks{};</div>
<div class="line"><span class="lineno"> 129</span> </div>
<div class="line"><span class="lineno"> 130</span> <span class="comment">// Rounds</span></div>
<div class="line"><span class="lineno"> 131</span> <span class="keywordflow">for</span> (uint64_t chunk = 0; chunk * 64 &lt; padded_message_size; chunk++) {</div>
<div class="line"><span class="lineno"> 132</span> <span class="comment">// First, build 16 32-bits blocks from the chunk</span></div>
<div class="line"><span class="lineno"> 133</span> <span class="keywordflow">for</span> (uint8_t bid = 0; bid &lt; 16; bid++) {</div>
<div class="line"><span class="lineno"> 134</span> blocks[bid] = 0;</div>
<div class="line"><span class="lineno"> 135</span> </div>
<div class="line"><span class="lineno"> 136</span> <span class="comment">// Having to build a 32-bit word from 4-bit words</span></div>
<div class="line"><span class="lineno"> 137</span> <span class="comment">// Add each and shift them to the left</span></div>
<div class="line"><span class="lineno"> 138</span> <span class="keywordflow">for</span> (uint8_t cid = 0; cid &lt; 4; cid++) {</div>
<div class="line"><span class="lineno"> 139</span> blocks[bid] = (blocks[bid] &lt;&lt; 8) +</div>
<div class="line"><span class="lineno"> 140</span> padded_message[chunk * 64 + bid * 4 + cid];</div>
<div class="line"><span class="lineno"> 141</span> }</div>
<div class="line"><span class="lineno"> 142</span> </div>
<div class="line"><span class="lineno"> 143</span> <span class="comment">// Extend the 16 32-bit words into 80 32-bit words</span></div>
<div class="line"><span class="lineno"> 144</span> <span class="keywordflow">for</span> (uint8_t i = 16; i &lt; 80; i++) {</div>
<div class="line"><span class="lineno"> 145</span> blocks[i] =</div>
<div class="line"><span class="lineno"> 146</span> <a class="code hl_function" href="#acf6bd970f29a68702bdbdfe8338e45e0">leftRotate32bits</a>(blocks[i - 3] ^ blocks[i - 8] ^</div>
<div class="line"><span class="lineno"> 147</span> blocks[i - 14] ^ blocks[i - 16],</div>
<div class="line"><span class="lineno"> 148</span> 1);</div>
<div class="line"><span class="lineno"> 149</span> }</div>
<div class="line"><span class="lineno"> 150</span> }</div>
<div class="line"><span class="lineno"> 151</span> </div>
<div class="line"><span class="lineno"> 152</span> a = h0;</div>
<div class="line"><span class="lineno"> 153</span> b = h1;</div>
<div class="line"><span class="lineno"> 154</span> c = h2;</div>
<div class="line"><span class="lineno"> 155</span> d = h3;</div>
<div class="line"><span class="lineno"> 156</span> e = h4;</div>
<div class="line"><span class="lineno"> 157</span> </div>
<div class="line"><span class="lineno"> 158</span> <span class="comment">// Main &quot;hashing&quot; loop</span></div>
<div class="line"><span class="lineno"> 159</span> <span class="keywordflow">for</span> (uint8_t i = 0; i &lt; 80; i++) {</div>
<div class="line"><span class="lineno"> 160</span> uint32_t F = 0, <a class="code hl_function" href="../../d4/d18/composite__simpson__rule_8cpp.html#a2f67508d5f392b0321772169342c98ad">g</a> = 0;</div>
<div class="line"><span class="lineno"> 161</span> <span class="keywordflow">if</span> (i &lt; 20) {</div>
<div class="line"><span class="lineno"> 162</span> F = (b &amp; c) | ((~b) &amp; d);</div>
<div class="line"><span class="lineno"> 163</span> <a class="code hl_function" href="../../d4/d18/composite__simpson__rule_8cpp.html#a2f67508d5f392b0321772169342c98ad">g</a> = 0x5A827999;</div>
<div class="line"><span class="lineno"> 164</span> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (i &lt; 40) {</div>
<div class="line"><span class="lineno"> 165</span> F = b ^ c ^ d;</div>
<div class="line"><span class="lineno"> 166</span> <a class="code hl_function" href="../../d4/d18/composite__simpson__rule_8cpp.html#a2f67508d5f392b0321772169342c98ad">g</a> = 0x6ED9EBA1;</div>
<div class="line"><span class="lineno"> 167</span> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (i &lt; 60) {</div>
<div class="line"><span class="lineno"> 168</span> F = (b &amp; c) | (b &amp; d) | (c &amp; d);</div>
<div class="line"><span class="lineno"> 169</span> <a class="code hl_function" href="../../d4/d18/composite__simpson__rule_8cpp.html#a2f67508d5f392b0321772169342c98ad">g</a> = 0x8F1BBCDC;</div>
<div class="line"><span class="lineno"> 170</span> } <span class="keywordflow">else</span> {</div>
<div class="line"><span class="lineno"> 171</span> F = b ^ c ^ d;</div>
<div class="line"><span class="lineno"> 172</span> <a class="code hl_function" href="../../d4/d18/composite__simpson__rule_8cpp.html#a2f67508d5f392b0321772169342c98ad">g</a> = 0xCA62C1D6;</div>
<div class="line"><span class="lineno"> 173</span> }</div>
<div class="line"><span class="lineno"> 174</span> </div>
<div class="line"><span class="lineno"> 175</span> <span class="comment">// Update the accumulators</span></div>
<div class="line"><span class="lineno"> 176</span> uint32_t temp = <a class="code hl_function" href="#acf6bd970f29a68702bdbdfe8338e45e0">leftRotate32bits</a>(a, 5) + F + e + <a class="code hl_function" href="../../d4/d18/composite__simpson__rule_8cpp.html#a2f67508d5f392b0321772169342c98ad">g</a> + blocks[i];</div>
<div class="line"><span class="lineno"> 177</span> e = d;</div>
<div class="line"><span class="lineno"> 178</span> d = c;</div>
<div class="line"><span class="lineno"> 179</span> c = <a class="code hl_function" href="#acf6bd970f29a68702bdbdfe8338e45e0">leftRotate32bits</a>(b, 30);</div>
<div class="line"><span class="lineno"> 180</span> b = a;</div>
<div class="line"><span class="lineno"> 181</span> a = temp;</div>
<div class="line"><span class="lineno"> 182</span> }</div>
<div class="line"><span class="lineno"> 183</span> <span class="comment">// Update the state with this chunk&#39;s hash</span></div>
<div class="line"><span class="lineno"> 184</span> h0 += a;</div>
<div class="line"><span class="lineno"> 185</span> h1 += b;</div>
<div class="line"><span class="lineno"> 186</span> h2 += c;</div>
<div class="line"><span class="lineno"> 187</span> h3 += d;</div>
<div class="line"><span class="lineno"> 188</span> h4 += e;</div>
<div class="line"><span class="lineno"> 189</span> }</div>
<div class="line"><span class="lineno"> 190</span> </div>
<div class="line"><span class="lineno"> 191</span> <span class="comment">// Build signature from state</span></div>
<div class="line"><span class="lineno"> 192</span> <span class="comment">// Note, any type could be used for the signature</span></div>
<div class="line"><span class="lineno"> 193</span> <span class="comment">// uint8_t was used to make the 20 bytes obvious</span></div>
<div class="line"><span class="lineno"> 194</span> <span class="keyword">auto</span>* sig = <span class="keyword">new</span> uint8_t[20];</div>
<div class="line"><span class="lineno"> 195</span> <span class="keywordflow">for</span> (uint8_t i = 0; i &lt; 4; i++) {</div>
<div class="line"><span class="lineno"> 196</span> sig[i] = (h0 &gt;&gt; (24 - 8 * i)) &amp; 0xFF;</div>
<div class="line"><span class="lineno"> 197</span> sig[i + 4] = (h1 &gt;&gt; (24 - 8 * i)) &amp; 0xFF;</div>
<div class="line"><span class="lineno"> 198</span> sig[i + 8] = (h2 &gt;&gt; (24 - 8 * i)) &amp; 0xFF;</div>
<div class="line"><span class="lineno"> 199</span> sig[i + 12] = (h3 &gt;&gt; (24 - 8 * i)) &amp; 0xFF;</div>
<div class="line"><span class="lineno"> 200</span> sig[i + 16] = (h4 &gt;&gt; (24 - 8 * i)) &amp; 0xFF;</div>
<div class="line"><span class="lineno"> 201</span> }</div>
<div class="line"><span class="lineno"> 202</span> </div>
<div class="line"><span class="lineno"> 203</span> <span class="keywordflow">return</span> sig;</div>
<div class="line"><span class="lineno"> 204</span>}</div>
<div class="ttc" id="acomposite__simpson__rule_8cpp_html_a2f67508d5f392b0321772169342c98ad"><div class="ttname"><a href="../../d4/d18/composite__simpson__rule_8cpp.html#a2f67508d5f392b0321772169342c98ad">numerical_methods::simpson_method::g</a></div><div class="ttdeci">double g(double x)</div><div class="ttdoc">Another test function.</div><div class="ttdef"><b>Definition</b> <a href="../../d4/d18/composite__simpson__rule_8cpp_source.html#l00115">composite_simpson_rule.cpp:115</a></div></div>
<div class="ttc" id="asha1_8cpp_html_acf6bd970f29a68702bdbdfe8338e45e0"><div class="ttname"><a href="#acf6bd970f29a68702bdbdfe8338e45e0">hashing::sha1::leftRotate32bits</a></div><div class="ttdeci">uint32_t leftRotate32bits(uint32_t n, std::size_t rotate)</div><div class="ttdoc">Rotates the bits of a 32-bit unsigned integer.</div><div class="ttdef"><b>Definition</b> <a href="../../d8/d7a/sha1_8cpp_source.html#l00058">sha1.cpp:58</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="ac9e1a11f44135b890dd10a00e73b5661" name="ac9e1a11f44135b890dd10a00e73b5661"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ac9e1a11f44135b890dd10a00e73b5661">&#9670;&#160;</a></span>interactive()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void interactive </td>
<td>(</td>
<td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel static">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Puts user in a loop where inputs can be given and SHA-1 hash will be computed and printed. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d8/d7a/sha1_8cpp_source.html#l00275">275</a> of file <a class="el" href="../../d8/d7a/sha1_8cpp_source.html">sha1.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 275</span> {</div>
<div class="line"><span class="lineno"> 276</span> <span class="keywordflow">while</span> (<span class="keyword">true</span>) {</div>
<div class="line"><span class="lineno"> 277</span> std::string input;</div>
<div class="line"><span class="lineno"> 278</span> std::cout &lt;&lt; <span class="stringliteral">&quot;Enter a message to be hashed (Ctrl-C to exit): &quot;</span></div>
<div class="line"><span class="lineno"> 279</span> &lt;&lt; std::endl;</div>
<div class="line"><span class="lineno"> 280</span> std::getline(std::cin, input);</div>
<div class="line"><span class="lineno"> 281</span> <span class="keywordtype">void</span>* sig = <a class="code hl_function" href="#a2397f2444a05e4d1487c67e215410d3c">hashing::sha1::hash</a>(input);</div>
<div class="line"><span class="lineno"> 282</span> std::cout &lt;&lt; <span class="stringliteral">&quot;Hash is: &quot;</span> &lt;&lt; <a class="code hl_function" href="#aada0803ef851d831b7a290a924e3c228">hashing::sha1::sig2hex</a>(sig) &lt;&lt; std::endl;</div>
<div class="line"><span class="lineno"> 283</span> </div>
<div class="line"><span class="lineno"> 284</span> <span class="keywordflow">while</span> (<span class="keyword">true</span>) {</div>
<div class="line"><span class="lineno"> 285</span> std::cout &lt;&lt; <span class="stringliteral">&quot;Want to enter another message? (y/n) &quot;</span>;</div>
<div class="line"><span class="lineno"> 286</span> std::getline(std::cin, input);</div>
<div class="line"><span class="lineno"> 287</span> <span class="keywordflow">if</span> (input.compare(<span class="stringliteral">&quot;y&quot;</span>) == 0) {</div>
<div class="line"><span class="lineno"> 288</span> <span class="keywordflow">break</span>;</div>
<div class="line"><span class="lineno"> 289</span> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (input.compare(<span class="stringliteral">&quot;n&quot;</span>) == 0) {</div>
<div class="line"><span class="lineno"> 290</span> <span class="keywordflow">return</span>;</div>
<div class="line"><span class="lineno"> 291</span> }</div>
<div class="line"><span class="lineno"> 292</span> }</div>
<div class="line"><span class="lineno"> 293</span> }</div>
<div class="line"><span class="lineno"> 294</span>}</div>
<div class="ttc" id="asha1_8cpp_html_a2397f2444a05e4d1487c67e215410d3c"><div class="ttname"><a href="#a2397f2444a05e4d1487c67e215410d3c">hashing::sha1::hash</a></div><div class="ttdeci">void * hash(const std::string &amp;message)</div><div class="ttdoc">Converts the string to bytestring and calls the main algorithm.</div><div class="ttdef"><b>Definition</b> <a href="../../d8/d7a/sha1_8cpp_source.html#l00211">sha1.cpp:211</a></div></div>
<div class="ttc" id="asha1_8cpp_html_aada0803ef851d831b7a290a924e3c228"><div class="ttname"><a href="#aada0803ef851d831b7a290a924e3c228">hashing::sha1::sig2hex</a></div><div class="ttdeci">std::string sig2hex(void *sig)</div><div class="ttdoc">Transforms the 160-bit SHA-1 signature into a 40 char hex string.</div><div class="ttdef"><b>Definition</b> <a href="../../d8/d7a/sha1_8cpp_source.html#l00067">sha1.cpp:67</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="acf6bd970f29a68702bdbdfe8338e45e0" name="acf6bd970f29a68702bdbdfe8338e45e0"></a>
<h2 class="memtitle"><span class="permalink"><a href="#acf6bd970f29a68702bdbdfe8338e45e0">&#9670;&#160;</a></span>leftRotate32bits()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint32_t hashing::sha1::leftRotate32bits </td>
<td>(</td>
<td class="paramtype">uint32_t</td> <td class="paramname"><span class="paramname"><em>n</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">std::size_t</td> <td class="paramname"><span class="paramname"><em>rotate</em></span>&#160;)</td>
</tr>
</table>
</div><div class="memdoc">
<p>Rotates the bits of a 32-bit unsigned integer. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">n</td><td>Integer to rotate </td></tr>
<tr><td class="paramname">rotate</td><td>How many bits for the rotation </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>uint32_t The rotated integer </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d8/d7a/sha1_8cpp_source.html#l00058">58</a> of file <a class="el" href="../../d8/d7a/sha1_8cpp_source.html">sha1.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 58</span> {</div>
<div class="line"><span class="lineno"> 59</span> <span class="keywordflow">return</span> (n &lt;&lt; rotate) | (n &gt;&gt; (32 - rotate));</div>
<div class="line"><span class="lineno"> 60</span>}</div>
</div><!-- fragment -->
</div>
</div>
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">&#9670;&#160;</a></span>main()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int main </td>
<td>(</td>
<td class="paramtype">void</td> <td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Main function. </p>
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d8/d7a/sha1_8cpp_source.html#l00300">300</a> of file <a class="el" href="../../d8/d7a/sha1_8cpp_source.html">sha1.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 300</span> {</div>
<div class="line"><span class="lineno"> 301</span> <a class="code hl_function" href="#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// run self-test implementations</span></div>
<div class="line"><span class="lineno"> 302</span> </div>
<div class="line"><span class="lineno"> 303</span> <span class="comment">// Launch interactive mode where user can input messages and see</span></div>
<div class="line"><span class="lineno"> 304</span> <span class="comment">// their hash</span></div>
<div class="line"><span class="lineno"> 305</span> <a class="code hl_function" href="#ac9e1a11f44135b890dd10a00e73b5661">interactive</a>();</div>
<div class="line"><span class="lineno"> 306</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 307</span>}</div>
<div class="ttc" id="asha1_8cpp_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Self-test implementations of well-known SHA-1 hashes.</div><div class="ttdef"><b>Definition</b> <a href="../../d8/d7a/sha1_8cpp_source.html#l00221">sha1.cpp:221</a></div></div>
<div class="ttc" id="asha1_8cpp_html_ac9e1a11f44135b890dd10a00e73b5661"><div class="ttname"><a href="#ac9e1a11f44135b890dd10a00e73b5661">interactive</a></div><div class="ttdeci">static void interactive()</div><div class="ttdoc">Puts user in a loop where inputs can be given and SHA-1 hash will be computed and printed.</div><div class="ttdef"><b>Definition</b> <a href="../../d8/d7a/sha1_8cpp_source.html#l00275">sha1.cpp:275</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="aada0803ef851d831b7a290a924e3c228" name="aada0803ef851d831b7a290a924e3c228"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aada0803ef851d831b7a290a924e3c228">&#9670;&#160;</a></span>sig2hex()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">std::string hashing::sha1::sig2hex </td>
<td>(</td>
<td class="paramtype">void *</td> <td class="paramname"><span class="paramname"><em>sig</em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Transforms the 160-bit SHA-1 signature into a 40 char hex string. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">sig</td><td>The SHA-1 signature (Expected 20 bytes) </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>std::string The hex signature </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d8/d7a/sha1_8cpp_source.html#l00067">67</a> of file <a class="el" href="../../d8/d7a/sha1_8cpp_source.html">sha1.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 67</span> {</div>
<div class="line"><span class="lineno"> 68</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* hexChars = <span class="stringliteral">&quot;0123456789abcdef&quot;</span>;</div>
<div class="line"><span class="lineno"> 69</span> <span class="keyword">auto</span>* intsig = <span class="keyword">static_cast&lt;</span>uint8_t*<span class="keyword">&gt;</span>(sig);</div>
<div class="line"><span class="lineno"> 70</span> std::string hex = <span class="stringliteral">&quot;&quot;</span>;</div>
<div class="line"><span class="lineno"> 71</span> <span class="keywordflow">for</span> (uint8_t i = 0; i &lt; 20; i++) {</div>
<div class="line"><span class="lineno"> 72</span> hex.push_back(hexChars[(intsig[i] &gt;&gt; 4) &amp; 0xF]);</div>
<div class="line"><span class="lineno"> 73</span> hex.push_back(hexChars[(intsig[i]) &amp; 0xF]);</div>
<div class="line"><span class="lineno"> 74</span> }</div>
<div class="line"><span class="lineno"> 75</span> <span class="keywordflow">return</span> hex;</div>
<div class="line"><span class="lineno"> 76</span>}</div>
</div><!-- fragment -->
</div>
</div>
<a id="aa8dca7b867074164d5f45b0f3851269d" name="aa8dca7b867074164d5f45b0f3851269d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa8dca7b867074164d5f45b0f3851269d">&#9670;&#160;</a></span>test()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void test </td>
<td>(</td>
<td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel static">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Self-test implementations of well-known SHA-1 hashes. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d8/d7a/sha1_8cpp_source.html#l00221">221</a> of file <a class="el" href="../../d8/d7a/sha1_8cpp_source.html">sha1.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 221</span> {</div>
<div class="line"><span class="lineno"> 222</span> <span class="comment">// Hashes empty string and stores signature</span></div>
<div class="line"><span class="lineno"> 223</span> <span class="keywordtype">void</span>* sig = <a class="code hl_function" href="#a2397f2444a05e4d1487c67e215410d3c">hashing::sha1::hash</a>(<span class="stringliteral">&quot;&quot;</span>);</div>
<div class="line"><span class="lineno"> 224</span> std::cout &lt;&lt; <span class="stringliteral">&quot;Hashing empty string&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"><span class="lineno"> 225</span> <span class="comment">// Prints signature hex representation</span></div>
<div class="line"><span class="lineno"> 226</span> std::cout &lt;&lt; <a class="code hl_function" href="#aada0803ef851d831b7a290a924e3c228">hashing::sha1::sig2hex</a>(sig) &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><span class="lineno"> 227</span> <span class="comment">// Test with cassert wether sig is correct from expected value</span></div>
<div class="line"><span class="lineno"> 228</span> assert(<a class="code hl_function" href="#aada0803ef851d831b7a290a924e3c228">hashing::sha1::sig2hex</a>(sig).<a class="code hl_function" href="../../d4/d7a/shell__sort2_8cpp.html#a7eb77daed2cf1513f6d68c47a1c2db1c">compare</a>(</div>
<div class="line"><span class="lineno"> 229</span> <span class="stringliteral">&quot;da39a3ee5e6b4b0d3255bfef95601890afd80709&quot;</span>) == 0);</div>
<div class="line"><span class="lineno"> 230</span> </div>
<div class="line"><span class="lineno"> 231</span> <span class="comment">// Hashes &quot;The quick brown fox jumps over the lazy dog&quot; and stores signature</span></div>
<div class="line"><span class="lineno"> 232</span> <span class="keywordtype">void</span>* sig2 =</div>
<div class="line"><span class="lineno"> 233</span> <a class="code hl_function" href="#a2397f2444a05e4d1487c67e215410d3c">hashing::sha1::hash</a>(<span class="stringliteral">&quot;The quick brown fox jumps over the lazy dog&quot;</span>);</div>
<div class="line"><span class="lineno"> 234</span> std::cout &lt;&lt; <span class="stringliteral">&quot;Hashing The quick brown fox jumps over the lazy dog&quot;</span></div>
<div class="line"><span class="lineno"> 235</span> &lt;&lt; std::endl;</div>
<div class="line"><span class="lineno"> 236</span> <span class="comment">// Prints signature hex representation</span></div>
<div class="line"><span class="lineno"> 237</span> std::cout &lt;&lt; <a class="code hl_function" href="#aada0803ef851d831b7a290a924e3c228">hashing::sha1::sig2hex</a>(sig2) &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><span class="lineno"> 238</span> <span class="comment">// Test with cassert wether sig is correct from expected value</span></div>
<div class="line"><span class="lineno"> 239</span> assert(<a class="code hl_function" href="#aada0803ef851d831b7a290a924e3c228">hashing::sha1::sig2hex</a>(sig2).<a class="code hl_function" href="../../d4/d7a/shell__sort2_8cpp.html#a7eb77daed2cf1513f6d68c47a1c2db1c">compare</a>(</div>
<div class="line"><span class="lineno"> 240</span> <span class="stringliteral">&quot;2fd4e1c67a2d28fced849ee1bb76e7391b93eb12&quot;</span>) == 0);</div>
<div class="line"><span class="lineno"> 241</span> </div>
<div class="line"><span class="lineno"> 242</span> <span class="comment">// Hashes &quot;The quick brown fox jumps over the lazy dog.&quot; (notice the</span></div>
<div class="line"><span class="lineno"> 243</span> <span class="comment">// additional period) and stores signature</span></div>
<div class="line"><span class="lineno"> 244</span> <span class="keywordtype">void</span>* sig3 =</div>
<div class="line"><span class="lineno"> 245</span> <a class="code hl_function" href="#a2397f2444a05e4d1487c67e215410d3c">hashing::sha1::hash</a>(<span class="stringliteral">&quot;The quick brown fox jumps over the lazy dog.&quot;</span>);</div>
<div class="line"><span class="lineno"> 246</span> std::cout &lt;&lt; <span class="stringliteral">&quot;Hashing &quot;</span></div>
<div class="line"><span class="lineno"> 247</span> <span class="stringliteral">&quot;The quick brown fox jumps over the lazy dog.&quot;</span></div>
<div class="line"><span class="lineno"> 248</span> &lt;&lt; std::endl;</div>
<div class="line"><span class="lineno"> 249</span> <span class="comment">// Prints signature hex representation</span></div>
<div class="line"><span class="lineno"> 250</span> std::cout &lt;&lt; <a class="code hl_function" href="#aada0803ef851d831b7a290a924e3c228">hashing::sha1::sig2hex</a>(sig3) &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><span class="lineno"> 251</span> <span class="comment">// Test with cassert wether sig is correct from expected value</span></div>
<div class="line"><span class="lineno"> 252</span> assert(<a class="code hl_function" href="#aada0803ef851d831b7a290a924e3c228">hashing::sha1::sig2hex</a>(sig3).<a class="code hl_function" href="../../d4/d7a/shell__sort2_8cpp.html#a7eb77daed2cf1513f6d68c47a1c2db1c">compare</a>(</div>
<div class="line"><span class="lineno"> 253</span> <span class="stringliteral">&quot;408d94384216f890ff7a0c3528e8bed1e0b01621&quot;</span>) == 0);</div>
<div class="line"><span class="lineno"> 254</span> </div>
<div class="line"><span class="lineno"> 255</span> <span class="comment">// Hashes &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&quot;</span></div>
<div class="line"><span class="lineno"> 256</span> <span class="comment">// and stores signature</span></div>
<div class="line"><span class="lineno"> 257</span> <span class="keywordtype">void</span>* sig4 = <a class="code hl_function" href="#a2397f2444a05e4d1487c67e215410d3c">hashing::sha1::hash</a>(</div>
<div class="line"><span class="lineno"> 258</span> <span class="stringliteral">&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&quot;</span>);</div>
<div class="line"><span class="lineno"> 259</span> std::cout</div>
<div class="line"><span class="lineno"> 260</span> &lt;&lt; <span class="stringliteral">&quot;Hashing &quot;</span></div>
<div class="line"><span class="lineno"> 261</span> <span class="stringliteral">&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&quot;</span></div>
<div class="line"><span class="lineno"> 262</span> &lt;&lt; std::endl;</div>
<div class="line"><span class="lineno"> 263</span> <span class="comment">// Prints signature hex representation</span></div>
<div class="line"><span class="lineno"> 264</span> std::cout &lt;&lt; <a class="code hl_function" href="#aada0803ef851d831b7a290a924e3c228">hashing::sha1::sig2hex</a>(sig4) &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line"><span class="lineno"> 265</span> <span class="comment">// Test with cassert wether sig is correct from expected value</span></div>
<div class="line"><span class="lineno"> 266</span> assert(<a class="code hl_function" href="#aada0803ef851d831b7a290a924e3c228">hashing::sha1::sig2hex</a>(sig4).<a class="code hl_function" href="../../d4/d7a/shell__sort2_8cpp.html#a7eb77daed2cf1513f6d68c47a1c2db1c">compare</a>(</div>
<div class="line"><span class="lineno"> 267</span> <span class="stringliteral">&quot;761c457bf73b14d27e9e9265c46f4b4dda11f940&quot;</span>) == 0);</div>
<div class="line"><span class="lineno"> 268</span>}</div>
<div class="ttc" id="ashell__sort2_8cpp_html_a7eb77daed2cf1513f6d68c47a1c2db1c"><div class="ttname"><a href="../../d4/d7a/shell__sort2_8cpp.html#a7eb77daed2cf1513f6d68c47a1c2db1c">compare</a></div><div class="ttdeci">int compare(const void *a, const void *b)</div><div class="ttdef"><b>Definition</b> <a href="../../d4/d7a/shell__sort2_8cpp_source.html#l00087">shell_sort2.cpp:87</a></div></div>
</div><!-- fragment -->
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<div id="page-nav" class="page-nav-panel">
<div id="page-nav-resize-handle"></div>
<div id="page-nav-tree">
<div id="page-nav-contents">
</div><!-- page-nav-contents -->
</div><!-- page-nav-tree -->
</div><!-- page-nav -->
</div><!-- container -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a href="../../dir_ece9b94c107bbaa1dd68197a8c9983b9.html">hashing</a></li><li class="navelem"><a href="../../d8/d7a/sha1_8cpp.html">sha1.cpp</a></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.14.0 </li>
</ul>
</div>
</body>
</html>