Files
C-Plus-Plus/df/d2c/elliptic__curve__key__exchange_8cpp.html
2023-01-22 19:44:10 +00:00

419 lines
42 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: ciphers/elliptic_curve_key_exchange.cpp File Reference</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="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.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/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.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 id="projectrow">
<td id="projectalign">
<div id="projectname">Algorithms_in_C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C++.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- 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');
/* @license-end */
</script>
<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:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</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">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('df/d2c/elliptic__curve__key__exchange_8cpp.html','../../'); initResizable(); });
/* @license-end */
</script>
<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="summary">
<a href="#nested-classes">Classes</a> &#124;
<a href="#namespaces">Namespaces</a> &#124;
<a href="#typedef-members">Typedefs</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle"><div class="title">elliptic_curve_key_exchange.cpp File Reference</div></div>
</div><!--header-->
<div class="contents">
<p>Implementation of <a href="https://cryptobook.nakov.com/asymmetric-key-ciphers/ecdh-key-exchange" target="_blank">Elliptic Curve Diffie Hellman Key Exchange</a>.
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;cassert&gt;</code><br />
<code>#include &lt;iostream&gt;</code><br />
<code>#include &quot;<a class="el" href="../../da/da3/uint256__t_8hpp_source.html">uint256_t.hpp</a>&quot;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for elliptic_curve_key_exchange.cpp:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d2/d83/elliptic__curve__key__exchange_8cpp__incl.svg" width="475" height="271"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="nested-classes" name="nested-classes"></a>
Classes</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/d45/structciphers_1_1elliptic__curve__key__exchange_1_1_point.html">ciphers::elliptic_curve_key_exchange::Point</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">Definition of struct <a class="el" href="../../d6/d45/structciphers_1_1elliptic__curve__key__exchange_1_1_point.html" title="Definition of struct Point.">Point</a>. <a href="../../d6/d45/structciphers_1_1elliptic__curve__key__exchange_1_1_point.html#details">More...</a><br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="namespaces" name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:d6/d4e/namespaceciphers"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/d4e/namespaceciphers.html">ciphers</a></td></tr>
<tr class="memdesc:d6/d4e/namespaceciphers"><td class="mdescLeft">&#160;</td><td class="mdescRight">Algorithms for encryption and decryption. <br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:df/d6b/namespaceciphers_1_1elliptic__curve__key__exchange"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d6b/namespaceciphers_1_1elliptic__curve__key__exchange.html">ciphers::elliptic_curve_key_exchange</a></td></tr>
<tr class="memdesc:df/d6b/namespaceciphers_1_1elliptic__curve__key__exchange"><td class="mdescLeft">&#160;</td><td class="mdescRight">namespace <a class="el" href="../../df/d6b/namespaceciphers_1_1elliptic__curve__key__exchange.html" title="namespace elliptic_curve_key_exchange">elliptic_curve_key_exchange</a> <br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="typedef-members" name="typedef-members"></a>
Typedefs</h2></td></tr>
<tr class="memitem:af0a6e3521629c25c2b5d620f26429830"><td class="memItemLeft" align="right" valign="top">typedef struct <a class="el" href="../../d6/d45/structciphers_1_1elliptic__curve__key__exchange_1_1_point.html">ciphers::elliptic_curve_key_exchange::Point</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d6b/namespaceciphers_1_1elliptic__curve__key__exchange.html#af0a6e3521629c25c2b5d620f26429830">ciphers::elliptic_curve_key_exchange::Point</a></td></tr>
<tr class="memdesc:af0a6e3521629c25c2b5d620f26429830"><td class="mdescLeft">&#160;</td><td class="mdescRight">Definition of struct <a class="el" href="../../d6/d45/structciphers_1_1elliptic__curve__key__exchange_1_1_point.html" title="Definition of struct Point.">Point</a>. <br /></td></tr>
<tr class="separator:af0a6e3521629c25c2b5d620f26429830"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ac00616a4e40d3cd5cfb4da87d9ff9af0"><td class="memItemLeft" align="right" valign="top"><a class="el" href="../../d1/d83/classuint256__t.html">uint256_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d6b/namespaceciphers_1_1elliptic__curve__key__exchange.html#ac00616a4e40d3cd5cfb4da87d9ff9af0">ciphers::elliptic_curve_key_exchange::exp</a> (<a class="el" href="../../d1/d83/classuint256__t.html">uint256_t</a> number, <a class="el" href="../../d1/d83/classuint256__t.html">uint256_t</a> <a class="el" href="../../df/def/power__for__huge__numbers_8cpp.html#ae249a2af508aa94266023ce8aa81426f">power</a>, const <a class="el" href="../../d1/d83/classuint256__t.html">uint256_t</a> &amp;mod)</td></tr>
<tr class="memdesc:ac00616a4e40d3cd5cfb4da87d9ff9af0"><td class="mdescLeft">&#160;</td><td class="mdescRight">This function calculates number raised to exponent power under modulo mod using <a href="https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/math/modular_exponentiation.cpp" target="_blank">Modular Exponentiation</a>. <br /></td></tr>
<tr class="separator:ac00616a4e40d3cd5cfb4da87d9ff9af0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:acc5fe9c2032fb7582c38a20d1fa69bcf"><td class="memItemLeft" align="right" valign="top"><a class="el" href="../../d8/dc8/struct_point.html">Point</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d6b/namespaceciphers_1_1elliptic__curve__key__exchange.html#acc5fe9c2032fb7582c38a20d1fa69bcf">ciphers::elliptic_curve_key_exchange::addition</a> (<a class="el" href="../../d8/dc8/struct_point.html">Point</a> a, <a class="el" href="../../d8/dc8/struct_point.html">Point</a> b, const <a class="el" href="../../d1/d83/classuint256__t.html">uint256_t</a> &amp;curve_a_coeff, <a class="el" href="../../d1/d83/classuint256__t.html">uint256_t</a> mod)</td></tr>
<tr class="memdesc:acc5fe9c2032fb7582c38a20d1fa69bcf"><td class="mdescLeft">&#160;</td><td class="mdescRight">Addition of points. <br /></td></tr>
<tr class="separator:acc5fe9c2032fb7582c38a20d1fa69bcf"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a17f3d667241b88115a95282cdd719cb2"><td class="memItemLeft" align="right" valign="top"><a class="el" href="../../d8/dc8/struct_point.html">Point</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d6b/namespaceciphers_1_1elliptic__curve__key__exchange.html#a17f3d667241b88115a95282cdd719cb2">ciphers::elliptic_curve_key_exchange::multiply</a> (const <a class="el" href="../../d8/dc8/struct_point.html">Point</a> &amp;a, const <a class="el" href="../../d1/d83/classuint256__t.html">uint256_t</a> &amp;curve_a_coeff, <a class="el" href="../../d1/d83/classuint256__t.html">uint256_t</a> p, const <a class="el" href="../../d1/d83/classuint256__t.html">uint256_t</a> &amp;mod)</td></tr>
<tr class="memdesc:a17f3d667241b88115a95282cdd719cb2"><td class="mdescLeft">&#160;</td><td class="mdescRight">multiply <a class="el" href="../../d6/d45/structciphers_1_1elliptic__curve__key__exchange_1_1_point.html" title="Definition of struct Point.">Point</a> and integer <br /></td></tr>
<tr class="separator:a17f3d667241b88115a95282cdd719cb2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a8800c8a84d77dadadb05ad5e83b77ef4"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d2c/elliptic__curve__key__exchange_8cpp.html#a8800c8a84d77dadadb05ad5e83b77ef4">uint128_t_tests</a> ()</td></tr>
<tr class="memdesc:a8800c8a84d77dadadb05ad5e83b77ef4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function to test the <a class="el" href="../../db/d9a/classuint128__t.html" title="class for 128-bit unsigned integer">uint128_t</a> header. <br /></td></tr>
<tr class="separator:a8800c8a84d77dadadb05ad5e83b77ef4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a37775d1724ffe404c088dabbc8da91ae"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d2c/elliptic__curve__key__exchange_8cpp.html#a37775d1724ffe404c088dabbc8da91ae">uint256_t_tests</a> ()</td></tr>
<tr class="memdesc:a37775d1724ffe404c088dabbc8da91ae"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function to test the <a class="el" href="../../d1/d83/classuint256__t.html" title="class for 256-bit unsigned integer">uint256_t</a> header. <br /></td></tr>
<tr class="separator:a37775d1724ffe404c088dabbc8da91ae"><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="../../df/d2c/elliptic__curve__key__exchange_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Function to test the provided algorithm above. <br /></td></tr>
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><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="../../df/d2c/elliptic__curve__key__exchange_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</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>Implementation of <a href="https://cryptobook.nakov.com/asymmetric-key-ciphers/ecdh-key-exchange" target="_blank">Elliptic Curve Diffie Hellman Key Exchange</a>. </p>
<p>The ECDH (Elliptic Curve DiffieHellman Key Exchange) is anonymous key agreement scheme, which allows two parties, each having an elliptic-curve publicprivate key pair, to establish a shared secret over an insecure channel. ECDH is very similar to the classical DHKE (DiffieHellman Key Exchange) algorithm, but it uses ECC point multiplication instead of modular exponentiations. ECDH is based on the following property of EC points: (a * G) * b = (b * G) * a If we have two secret numbers a and b (two private keys, belonging to Alice and Bob) and an ECC elliptic curve with generator point G, we can exchange over an insecure channel the values (a * G) and (b * G) (the public keys of Alice and Bob) and then we can derive a shared secret: secret = (a * G) * b = (b * G) * a. Pretty simple. The above equation takes the following form: alicePubKey * bobPrivKey = bobPubKey * alicePrivKey = secret </p><dl class="section author"><dt>Author</dt><dd><a href="https://github.com/AshishYUO" target="_blank">Ashish Daulatabad</a> </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<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&#160;</td>
<td class="paramname"></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>
<div class="fragment"><div class="line"><span class="lineno"> 320</span> {</div>
<div class="line"><span class="lineno"> 321</span> <a class="code hl_function" href="../../df/d2c/elliptic__curve__key__exchange_8cpp.html#a8800c8a84d77dadadb05ad5e83b77ef4">uint128_t_tests</a>(); <span class="comment">// running predefined 128-bit unsigned integer tests</span></div>
<div class="line"><span class="lineno"> 322</span> <a class="code hl_function" href="../../df/d2c/elliptic__curve__key__exchange_8cpp.html#a37775d1724ffe404c088dabbc8da91ae">uint256_t_tests</a>(); <span class="comment">// running predefined 256-bit unsigned integer tests</span></div>
<div class="line"><span class="lineno"> 323</span> <a class="code hl_function" href="../../df/d2c/elliptic__curve__key__exchange_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// running self-test implementations</span></div>
<div class="line"><span class="lineno"> 324</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 325</span>}</div>
<div class="ttc" id="aelliptic__curve__key__exchange_8cpp_html_a37775d1724ffe404c088dabbc8da91ae"><div class="ttname"><a href="../../df/d2c/elliptic__curve__key__exchange_8cpp.html#a37775d1724ffe404c088dabbc8da91ae">uint256_t_tests</a></div><div class="ttdeci">static void uint256_t_tests()</div><div class="ttdoc">Function to test the uint256_t header.</div><div class="ttdef"><b>Definition:</b> elliptic_curve_key_exchange.cpp:230</div></div>
<div class="ttc" id="aelliptic__curve__key__exchange_8cpp_html_a8800c8a84d77dadadb05ad5e83b77ef4"><div class="ttname"><a href="../../df/d2c/elliptic__curve__key__exchange_8cpp.html#a8800c8a84d77dadadb05ad5e83b77ef4">uint128_t_tests</a></div><div class="ttdeci">static void uint128_t_tests()</div><div class="ttdoc">Function to test the uint128_t header.</div><div class="ttdef"><b>Definition:</b> elliptic_curve_key_exchange.cpp:197</div></div>
<div class="ttc" id="aelliptic__curve__key__exchange_8cpp_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../df/d2c/elliptic__curve__key__exchange_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Function to test the provided algorithm above.</div><div class="ttdef"><b>Definition:</b> elliptic_curve_key_exchange.cpp:267</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../df/d2c/elliptic__curve__key__exchange_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="340" height="159"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</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">static void test </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Function to test the provided algorithm above. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 267</span> {</div>
<div class="line"><span class="lineno"> 268</span> <span class="comment">// demonstration of key exchange using curve secp112r1</span></div>
<div class="line"><span class="lineno"> 269</span> </div>
<div class="line"><span class="lineno"> 270</span> <span class="comment">// Equation of the form y^2 = (x^3 + ax + b) % P (here p is mod)</span></div>
<div class="line"><span class="lineno"> 271</span> <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a> a(<span class="stringliteral">&quot;4451685225093714772084598273548424&quot;</span>),</div>
<div class="line"><span class="lineno"> 272</span> b(<span class="stringliteral">&quot;2061118396808653202902996166388514&quot;</span>),</div>
<div class="line"><span class="lineno"> 273</span> mod(<span class="stringliteral">&quot;4451685225093714772084598273548427&quot;</span>);</div>
<div class="line"><span class="lineno"> 274</span> </div>
<div class="line"><span class="lineno"> 275</span> <span class="comment">// Generator value: is pre-defined for the given curve</span></div>
<div class="line"><span class="lineno"> 276</span> <a class="code hl_struct" href="../../d6/d45/structciphers_1_1elliptic__curve__key__exchange_1_1_point.html">ciphers::elliptic_curve_key_exchange::Point</a> ptr = {</div>
<div class="line"><span class="lineno"> 277</span> <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;188281465057972534892223778713752&quot;</span>),</div>
<div class="line"><span class="lineno"> 278</span> <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;3419875491033170827167861896082688&quot;</span>)};</div>
<div class="line"><span class="lineno"> 279</span> </div>
<div class="line"><span class="lineno"> 280</span> <span class="comment">// Shared key generation.</span></div>
<div class="line"><span class="lineno"> 281</span> <span class="comment">// For alice</span></div>
<div class="line"><span class="lineno"> 282</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;For alice:\n&quot;</span>;</div>
<div class="line"><span class="lineno"> 283</span> <span class="comment">// Alice&#39;s private key (can be generated randomly)</span></div>
<div class="line"><span class="lineno"> 284</span> <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a> alice_private_key(<span class="stringliteral">&quot;164330438812053169644452143505618&quot;</span>);</div>
<div class="line"><span class="lineno"> 285</span> <a class="code hl_struct" href="../../d6/d45/structciphers_1_1elliptic__curve__key__exchange_1_1_point.html">ciphers::elliptic_curve_key_exchange::Point</a> alice_public_key =</div>
<div class="line"><span class="lineno"> 286</span> <a class="code hl_function" href="../../df/def/power__for__huge__numbers_8cpp.html#aa141a7904f0c4668bac112d652a3acf9">multiply</a>(ptr, a, alice_private_key, mod);</div>
<div class="line"><span class="lineno"> 287</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;\tPrivate key: &quot;</span> &lt;&lt; alice_private_key &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;</div>
<div class="line"><span class="lineno"> 288</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;\tPublic Key: &quot;</span> &lt;&lt; alice_public_key &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><span class="lineno"> 289</span> </div>
<div class="line"><span class="lineno"> 290</span> <span class="comment">// For Bob</span></div>
<div class="line"><span class="lineno"> 291</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;For Bob:\n&quot;</span>;</div>
<div class="line"><span class="lineno"> 292</span> <span class="comment">// Bob&#39;s private key (can be generated randomly)</span></div>
<div class="line"><span class="lineno"> 293</span> <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a> bob_private_key(<span class="stringliteral">&quot;1959473333748537081510525763478373&quot;</span>);</div>
<div class="line"><span class="lineno"> 294</span> <a class="code hl_struct" href="../../d6/d45/structciphers_1_1elliptic__curve__key__exchange_1_1_point.html">ciphers::elliptic_curve_key_exchange::Point</a> bob_public_key =</div>
<div class="line"><span class="lineno"> 295</span> <a class="code hl_function" href="../../df/def/power__for__huge__numbers_8cpp.html#aa141a7904f0c4668bac112d652a3acf9">multiply</a>(ptr, a, bob_private_key, mod);</div>
<div class="line"><span class="lineno"> 296</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;\tPrivate key: &quot;</span> &lt;&lt; bob_private_key &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;</div>
<div class="line"><span class="lineno"> 297</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;\tPublic Key: &quot;</span> &lt;&lt; bob_public_key &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><span class="lineno"> 298</span> </div>
<div class="line"><span class="lineno"> 299</span> <span class="comment">// After public key exchange, create a shared key for communication.</span></div>
<div class="line"><span class="lineno"> 300</span> <span class="comment">// create shared key:</span></div>
<div class="line"><span class="lineno"> 301</span> <a class="code hl_struct" href="../../d6/d45/structciphers_1_1elliptic__curve__key__exchange_1_1_point.html">ciphers::elliptic_curve_key_exchange::Point</a> alice_shared_key = <a class="code hl_function" href="../../df/def/power__for__huge__numbers_8cpp.html#aa141a7904f0c4668bac112d652a3acf9">multiply</a>(</div>
<div class="line"><span class="lineno"> 302</span> bob_public_key, a,</div>
<div class="line"><span class="lineno"> 303</span> alice_private_key, mod),</div>
<div class="line"><span class="lineno"> 304</span> bob_shared_key = <a class="code hl_function" href="../../df/def/power__for__huge__numbers_8cpp.html#aa141a7904f0c4668bac112d652a3acf9">multiply</a>(</div>
<div class="line"><span class="lineno"> 305</span> alice_public_key, a,</div>
<div class="line"><span class="lineno"> 306</span> bob_private_key, mod);</div>
<div class="line"><span class="lineno"> 307</span> </div>
<div class="line"><span class="lineno"> 308</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Shared keys:\n&quot;</span>;</div>
<div class="line"><span class="lineno"> 309</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; alice_shared_key &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><span class="lineno"> 310</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; bob_shared_key &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><span class="lineno"> 311</span> </div>
<div class="line"><span class="lineno"> 312</span> <span class="comment">// Check whether shared keys are equal</span></div>
<div class="line"><span class="lineno"> 313</span> assert(alice_shared_key == bob_shared_key);</div>
<div class="line"><span class="lineno"> 314</span>}</div>
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
<div class="ttc" id="aclassuint256__t_html"><div class="ttname"><a href="../../d1/d83/classuint256__t.html">uint256_t</a></div><div class="ttdoc">class for 256-bit unsigned integer</div><div class="ttdef"><b>Definition:</b> uint256_t.hpp:33</div></div>
<div class="ttc" id="aendl_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a></div><div class="ttdeci">T endl(T... args)</div></div>
<div class="ttc" id="apower__for__huge__numbers_8cpp_html_aa141a7904f0c4668bac112d652a3acf9"><div class="ttname"><a href="../../df/def/power__for__huge__numbers_8cpp.html#aa141a7904f0c4668bac112d652a3acf9">multiply</a></div><div class="ttdeci">int multiply(int x, int res[], int res_size)</div><div class="ttdef"><b>Definition:</b> power_for_huge_numbers.cpp:25</div></div>
<div class="ttc" id="astructciphers_1_1elliptic__curve__key__exchange_1_1_point_html"><div class="ttname"><a href="../../d6/d45/structciphers_1_1elliptic__curve__key__exchange_1_1_point.html">ciphers::elliptic_curve_key_exchange::Point</a></div><div class="ttdoc">Definition of struct Point.</div><div class="ttdef"><b>Definition:</b> elliptic_curve_key_exchange.cpp:46</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../df/d2c/elliptic__curve__key__exchange_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg" width="175" height="86"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
<a id="a8800c8a84d77dadadb05ad5e83b77ef4" name="a8800c8a84d77dadadb05ad5e83b77ef4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8800c8a84d77dadadb05ad5e83b77ef4">&#9670;&#160;</a></span>uint128_t_tests()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">static void uint128_t_tests </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Function to test the <a class="el" href="../../db/d9a/classuint128__t.html" title="class for 128-bit unsigned integer">uint128_t</a> header. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 197</span> {</div>
<div class="line"><span class="lineno"> 198</span> <span class="comment">// 1st test: Operations test</span></div>
<div class="line"><span class="lineno"> 199</span> <a class="code hl_class" href="../../db/d9a/classuint128__t.html">uint128_t</a> a(<span class="stringliteral">&quot;122&quot;</span>), b(<span class="stringliteral">&quot;2312&quot;</span>);</div>
<div class="line"><span class="lineno"> 200</span> assert(a + b == 2434);</div>
<div class="line"><span class="lineno"> 201</span> assert(b - a == 2190);</div>
<div class="line"><span class="lineno"> 202</span> assert(a * b == 282064);</div>
<div class="line"><span class="lineno"> 203</span> assert(b / a == 18);</div>
<div class="line"><span class="lineno"> 204</span> assert(b % a == 116);</div>
<div class="line"><span class="lineno"> 205</span> assert((a &amp; b) == 8);</div>
<div class="line"><span class="lineno"> 206</span> assert((a | b) == 2426);</div>
<div class="line"><span class="lineno"> 207</span> assert((a ^ b) == 2418);</div>
<div class="line"><span class="lineno"> 208</span> assert((a &lt;&lt; 64) == <a class="code hl_class" href="../../db/d9a/classuint128__t.html">uint128_t</a>(<span class="stringliteral">&quot;2250502776992565297152&quot;</span>));</div>
<div class="line"><span class="lineno"> 209</span> assert((b &gt;&gt; 7) == 18);</div>
<div class="line"><span class="lineno"> 210</span> </div>
<div class="line"><span class="lineno"> 211</span> <span class="comment">// 2nd test: Operations test</span></div>
<div class="line"><span class="lineno"> 212</span> a = <a class="code hl_class" href="../../db/d9a/classuint128__t.html">uint128_t</a>(<span class="stringliteral">&quot;12321421424232142122&quot;</span>);</div>
<div class="line"><span class="lineno"> 213</span> b = <a class="code hl_class" href="../../db/d9a/classuint128__t.html">uint128_t</a>(<span class="stringliteral">&quot;23123212&quot;</span>);</div>
<div class="line"><span class="lineno"> 214</span> assert(a + b == <a class="code hl_class" href="../../db/d9a/classuint128__t.html">uint128_t</a>(<span class="stringliteral">&quot;12321421424255265334&quot;</span>));</div>
<div class="line"><span class="lineno"> 215</span> assert(a - b == <a class="code hl_class" href="../../db/d9a/classuint128__t.html">uint128_t</a>(<span class="stringliteral">&quot;12321421424209018910&quot;</span>));</div>
<div class="line"><span class="lineno"> 216</span> assert(a * b == <a class="code hl_class" href="../../db/d9a/classuint128__t.html">uint128_t</a>(<span class="stringliteral">&quot;284910839733861759501135864&quot;</span>));</div>
<div class="line"><span class="lineno"> 217</span> assert(a / b == 532859423865LL);</div>
<div class="line"><span class="lineno"> 218</span> assert(a % b == 3887742);</div>
<div class="line"><span class="lineno"> 219</span> assert((a &amp; b) == 18912520);</div>
<div class="line"><span class="lineno"> 220</span> assert((a | b) == <a class="code hl_class" href="../../db/d9a/classuint128__t.html">uint128_t</a>(<span class="stringliteral">&quot;12321421424236352814&quot;</span>));</div>
<div class="line"><span class="lineno"> 221</span> assert((a ^ b) == <a class="code hl_class" href="../../db/d9a/classuint128__t.html">uint128_t</a>(<span class="stringliteral">&quot;12321421424217440294&quot;</span>));</div>
<div class="line"><span class="lineno"> 222</span> assert((a &lt;&lt; 64) == <a class="code hl_class" href="../../db/d9a/classuint128__t.html">uint128_t</a>(<span class="stringliteral">&quot;227290107637132170748078080907806769152&quot;</span>));</div>
<div class="line"><span class="lineno"> 223</span>}</div>
<div class="ttc" id="aclassuint128__t_html"><div class="ttname"><a href="../../db/d9a/classuint128__t.html">uint128_t</a></div><div class="ttdoc">class for 128-bit unsigned integer</div><div class="ttdef"><b>Definition:</b> uint128_t.hpp:59</div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a37775d1724ffe404c088dabbc8da91ae" name="a37775d1724ffe404c088dabbc8da91ae"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a37775d1724ffe404c088dabbc8da91ae">&#9670;&#160;</a></span>uint256_t_tests()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">static void uint256_t_tests </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Function to test the <a class="el" href="../../d1/d83/classuint256__t.html" title="class for 256-bit unsigned integer">uint256_t</a> header. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 230</span> {</div>
<div class="line"><span class="lineno"> 231</span> <span class="comment">// 1st test: Operations test</span></div>
<div class="line"><span class="lineno"> 232</span> <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a> a(<span class="stringliteral">&quot;122&quot;</span>), b(<span class="stringliteral">&quot;2312&quot;</span>);</div>
<div class="line"><span class="lineno"> 233</span> assert(a + b == 2434);</div>
<div class="line"><span class="lineno"> 234</span> assert(b - a == 2190);</div>
<div class="line"><span class="lineno"> 235</span> assert(a * b == 282064);</div>
<div class="line"><span class="lineno"> 236</span> assert(b / a == 18);</div>
<div class="line"><span class="lineno"> 237</span> assert(b % a == 116);</div>
<div class="line"><span class="lineno"> 238</span> assert((a &amp; b) == 8);</div>
<div class="line"><span class="lineno"> 239</span> assert((a | b) == 2426);</div>
<div class="line"><span class="lineno"> 240</span> assert((a ^ b) == 2418);</div>
<div class="line"><span class="lineno"> 241</span> assert((a &lt;&lt; 64) == <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;2250502776992565297152&quot;</span>));</div>
<div class="line"><span class="lineno"> 242</span> assert((b &gt;&gt; 7) == 18);</div>
<div class="line"><span class="lineno"> 243</span> </div>
<div class="line"><span class="lineno"> 244</span> <span class="comment">// 2nd test: Operations test</span></div>
<div class="line"><span class="lineno"> 245</span> a = <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;12321423124513251424232142122&quot;</span>);</div>
<div class="line"><span class="lineno"> 246</span> b = <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;23124312431243243215354315132413213212&quot;</span>);</div>
<div class="line"><span class="lineno"> 247</span> assert(a + b == <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;23124312443564666339867566556645355334&quot;</span>));</div>
<div class="line"><span class="lineno"> 248</span> <span class="comment">// Since a &lt; b, the value is greater</span></div>
<div class="line"><span class="lineno"> 249</span> assert(a - b == <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;115792089237316195423570985008687907853246860353&quot;</span></div>
<div class="line"><span class="lineno"> 250</span> <span class="stringliteral">&quot;221642219366742944204948568846&quot;</span>));</div>
<div class="line"><span class="lineno"> 251</span> assert(a * b == <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;284924437928789743312147393953938013677909398222&quot;</span></div>
<div class="line"><span class="lineno"> 252</span> <span class="stringliteral">&quot;169728183872115864&quot;</span>));</div>
<div class="line"><span class="lineno"> 253</span> assert(b / a == <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;1876756621&quot;</span>));</div>
<div class="line"><span class="lineno"> 254</span> assert(b % a == <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;2170491202688962563936723450&quot;</span>));</div>
<div class="line"><span class="lineno"> 255</span> assert((a &amp; b) == <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;3553901085693256462344&quot;</span>));</div>
<div class="line"><span class="lineno"> 256</span> assert((a | b) == <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;23124312443564662785966480863388892990&quot;</span>));</div>
<div class="line"><span class="lineno"> 257</span> assert((a ^ b) == <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;23124312443564659232065395170132430646&quot;</span>));</div>
<div class="line"><span class="lineno"> 258</span> assert((a &lt;&lt; 128) == <a class="code hl_class" href="../../d1/d83/classuint256__t.html">uint256_t</a>(<span class="stringliteral">&quot;4192763024643754272961909047609369343091683&quot;</span></div>
<div class="line"><span class="lineno"> 259</span> <span class="stringliteral">&quot;376561852756163540549632&quot;</span>));</div>
<div class="line"><span class="lineno"> 260</span>}</div>
</div><!-- fragment -->
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_4d6e05837bf820fb089a8a8cdf2f42b7.html">ciphers</a></li><li class="navelem"><a class="el" href="../../df/d2c/elliptic__curve__key__exchange_8cpp.html">elliptic_curve_key_exchange.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.6 </li>
</ul>
</div>
</body>
</html>