Documentation for 0931d530ae

This commit is contained in:
github-actions
2023-01-22 19:44:10 +00:00
parent a448f64699
commit b48f6e8671
2457 changed files with 9513 additions and 8691 deletions

View File

@@ -3,7 +3,7 @@
<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.9.5"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: hashing/md5.cpp File Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
@@ -41,7 +41,7 @@ MathJax.Hub.Config({
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.5 -->
<!-- Generated by Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
@@ -132,50 +132,50 @@ Namespaces</h2></td></tr>
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:add2bf982d5dd64a45d13cba52c2b371d"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d96/md5_8cpp.html#add2bf982d5dd64a45d13cba52c2b371d">hashing::md5::leftRotate32bits</a> (uint32_t n, <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/types/size_t.html">std::size_t</a> rotate)</td></tr>
<tr class="memdesc:add2bf982d5dd64a45d13cba52c2b371d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Rotates the bits of a 32-bit unsigned integer. <a href="../../d5/d96/md5_8cpp.html#add2bf982d5dd64a45d13cba52c2b371d">More...</a><br /></td></tr>
<tr class="memdesc:add2bf982d5dd64a45d13cba52c2b371d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Rotates the bits of a 32-bit unsigned integer. <br /></td></tr>
<tr class="separator:add2bf982d5dd64a45d13cba52c2b371d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af8e96bde0183c4b0a7ff04668f11e446"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d96/md5_8cpp.html#af8e96bde0183c4b0a7ff04668f11e446">hashing::md5::isBigEndian</a> ()</td></tr>
<tr class="memdesc:af8e96bde0183c4b0a7ff04668f11e446"><td class="mdescLeft">&#160;</td><td class="mdescRight">Checks whether integers are stored as big endian or not. <a href="../../d5/d96/md5_8cpp.html#af8e96bde0183c4b0a7ff04668f11e446">More...</a><br /></td></tr>
<tr class="memdesc:af8e96bde0183c4b0a7ff04668f11e446"><td class="mdescLeft">&#160;</td><td class="mdescRight">Checks whether integers are stored as big endian or not. <br /></td></tr>
<tr class="separator:af8e96bde0183c4b0a7ff04668f11e446"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a694712c9665051ba52b686387b87a689"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d96/md5_8cpp.html#a694712c9665051ba52b686387b87a689">hashing::md5::toLittleEndian32</a> (uint32_t n)</td></tr>
<tr class="memdesc:a694712c9665051ba52b686387b87a689"><td class="mdescLeft">&#160;</td><td class="mdescRight">Sets 32-bit integer to little-endian if needed. <a href="../../d5/d96/md5_8cpp.html#a694712c9665051ba52b686387b87a689">More...</a><br /></td></tr>
<tr class="memdesc:a694712c9665051ba52b686387b87a689"><td class="mdescLeft">&#160;</td><td class="mdescRight">Sets 32-bit integer to little-endian if needed. <br /></td></tr>
<tr class="separator:a694712c9665051ba52b686387b87a689"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6be48c1e6e742f9bd329f501d61dcaef"><td class="memItemLeft" align="right" valign="top">uint64_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d96/md5_8cpp.html#a6be48c1e6e742f9bd329f501d61dcaef">hashing::md5::toLittleEndian64</a> (uint64_t n)</td></tr>
<tr class="memdesc:a6be48c1e6e742f9bd329f501d61dcaef"><td class="mdescLeft">&#160;</td><td class="mdescRight">Sets 64-bit integer to little-endian if needed. <a href="../../d5/d96/md5_8cpp.html#a6be48c1e6e742f9bd329f501d61dcaef">More...</a><br /></td></tr>
<tr class="memdesc:a6be48c1e6e742f9bd329f501d61dcaef"><td class="mdescLeft">&#160;</td><td class="mdescRight">Sets 64-bit integer to little-endian if needed. <br /></td></tr>
<tr class="separator:a6be48c1e6e742f9bd329f501d61dcaef"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aaee69c6136a841043f956de32116e348"><td class="memItemLeft" align="right" valign="top"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d96/md5_8cpp.html#aaee69c6136a841043f956de32116e348">hashing::md5::sig2hex</a> (void *sig)</td></tr>
<tr class="memdesc:aaee69c6136a841043f956de32116e348"><td class="mdescLeft">&#160;</td><td class="mdescRight">Transforms the 128-bit <a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> signature into a 32 char hex string. <a href="../../d5/d96/md5_8cpp.html#aaee69c6136a841043f956de32116e348">More...</a><br /></td></tr>
<tr class="memdesc:aaee69c6136a841043f956de32116e348"><td class="mdescLeft">&#160;</td><td class="mdescRight">Transforms the 128-bit <a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> signature into a 32 char hex string. <br /></td></tr>
<tr class="separator:aaee69c6136a841043f956de32116e348"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a5341431cef7fcfc33794326e1deb2425"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d96/md5_8cpp.html#a5341431cef7fcfc33794326e1deb2425">hashing::md5::hash_bs</a> (const void *input_bs, uint64_t input_size)</td></tr>
<tr class="memdesc:a5341431cef7fcfc33794326e1deb2425"><td class="mdescLeft">&#160;</td><td class="mdescRight">The <a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> algorithm itself, taking in a bytestring. <a href="../../d5/d96/md5_8cpp.html#a5341431cef7fcfc33794326e1deb2425">More...</a><br /></td></tr>
<tr class="memdesc:a5341431cef7fcfc33794326e1deb2425"><td class="mdescLeft">&#160;</td><td class="mdescRight">The <a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> algorithm itself, taking in a bytestring. <br /></td></tr>
<tr class="separator:a5341431cef7fcfc33794326e1deb2425"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a88705fab5f92adf3427b4cf76ff33edb"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d96/md5_8cpp.html#a88705fab5f92adf3427b4cf76ff33edb">hashing::md5::hash</a> (const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> &amp;message)</td></tr>
<tr class="memdesc:a88705fab5f92adf3427b4cf76ff33edb"><td class="mdescLeft">&#160;</td><td class="mdescRight">Converts the string to bytestring and calls the main algorithm. <a href="../../d5/d96/md5_8cpp.html#a88705fab5f92adf3427b4cf76ff33edb">More...</a><br /></td></tr>
<tr class="memdesc:a88705fab5f92adf3427b4cf76ff33edb"><td class="mdescLeft">&#160;</td><td class="mdescRight">Converts the string to bytestring and calls the main algorithm. <br /></td></tr>
<tr class="separator:a88705fab5f92adf3427b4cf76ff33edb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d96/md5_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Self-test implementations of well-known <a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> hashes. <a href="../../d5/d96/md5_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">More...</a><br /></td></tr>
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Self-test implementations of well-known <a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> hashes. <br /></td></tr>
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ac9e1a11f44135b890dd10a00e73b5661"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d96/md5_8cpp.html#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 <a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> hash will be computed and printed. <a href="../../d5/d96/md5_8cpp.html#ac9e1a11f44135b890dd10a00e73b5661">More...</a><br /></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 <a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> hash will be computed and printed. <br /></td></tr>
<tr class="separator:ac9e1a11f44135b890dd10a00e73b5661"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d96/md5_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <a href="../../d5/d96/md5_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <br /></td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >Simple C++ implementation of the <a href="https://en.wikipedia.org/wiki/MD5" target="_blank">MD5 Hashing Algorithm</a> </p>
<div class="textblock"><p>Simple C++ implementation of the <a href="https://en.wikipedia.org/wiki/MD5" target="_blank">MD5 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>The <a href="https://en.wikipedia.org/wiki/MD5" target="_blank">MD5 Algorithm</a> is a hashing algorithm which was designed in 1991 by <a href="https://en.wikipedia.org/wiki/Ron_Rivest" target="_blank">Ronal Rivest</a>.</p>
<p ><a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> is one of the most used hashing algorithm there is. Some of its use cases are:</p><ol type="1">
<p><a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> is one of the most used hashing algorithm there is. Some of its use cases are:</p><ol type="1">
<li>Providing checksum for downloaded software</li>
<li>Store salted password</li>
</ol>
<p >However <a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> has be know to be cryptographically weak for quite some time, yet it is still widely used. This weakness was exploited by the <a href="https://en.wikipedia.org/wiki/Flame_(malware)" target="_blank">Flame Malware</a> in 2012</p>
<p>However <a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> has be know to be cryptographically weak for quite some time, yet it is still widely used. This weakness was exploited by the <a href="https://en.wikipedia.org/wiki/Flame_(malware)" target="_blank">Flame Malware</a> in 2012</p>
<h3><a class="anchor" id="autotoc_md82"></a>
Algorithm</h3>
<p >First of all, all values are expected to be in [little endian] (<a href="https://en.wikipedia.org/wiki/Endianness">https://en.wikipedia.org/wiki/Endianness</a>). This is especially important when using part of the bytestring as an integer.</p>
<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. During these rounds the algorithm will update its 128 bit state (represented by 4 ints: A,B,C,D) For more precisions on these operations please see the <a href="https://en.wikipedia.org/wiki/MD5#Algorithm" target="_blank">Wikipedia aritcle</a>. The signature given by <a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> is its 128 bit state once all rounds are done. </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>First of all, all values are expected to be in [little endian] (<a href="https://en.wikipedia.org/wiki/Endianness">https://en.wikipedia.org/wiki/Endianness</a>). This is especially important when using part of the bytestring as an integer.</p>
<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. During these rounds the algorithm will update its 128 bit state (represented by 4 ints: A,B,C,D) For more precisions on these operations please see the <a href="https://en.wikipedia.org/wiki/MD5#Algorithm" target="_blank">Wikipedia aritcle</a>. The signature given by <a class="el" href="../../dd/d43/namespace_m_d5.html" title="Functions for the MD5 algorithm implementation.">MD5</a> is its 128 bit state once all rounds are done. </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>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a88705fab5f92adf3427b4cf76ff33edb" name="a88705fab5f92adf3427b4cf76ff33edb"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a88705fab5f92adf3427b4cf76ff33edb">&#9670;&#160;</a></span>hash()</h2>
@@ -250,7 +250,7 @@ Here is the call graph for this function:</div>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>void* Pointer to the 128-bit signature </dd></dl>
<p >Values of K are pseudo-random and used to "salt" each round The values can be obtained by the following python code </p><div class="fragment"><div class="line"><span class="keyword">from</span> math <span class="keyword">import</span> floor, sin</div>
<p>Values of K are pseudo-random and used to "salt" each round The values can be obtained by the following python code </p><div class="fragment"><div class="line"><span class="keyword">from</span> math <span class="keyword">import</span> floor, sin</div>
<div class="line"> </div>
<div class="line"><span class="keywordflow">for</span> i <span class="keywordflow">in</span> range(64):</div>
<div class="line"> print(floor(2**32 * abs(sin(i+1))))</div>
@@ -821,7 +821,7 @@ Here is the call graph for this function:</div>
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_ece9b94c107bbaa1dd68197a8c9983b9.html">hashing</a></li><li class="navelem"><a class="el" href="../../d5/d96/md5_8cpp.html">md5.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.9.5 </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.9.6 </li>
</ul>
</div>
</body>